Offer an option to prevent downloading archived articles

pull/1/head
Grégory Oestreicher 2017-02-27 15:09:47 +01:00
parent 115d52f94a
commit 11e665b137
6 changed files with 54 additions and 7 deletions

View File

@ -95,7 +95,7 @@ function getServer( id, cb )
function( tx ) { function( tx ) {
var server = null; var server = null;
try { try {
var res = tx.executeSql( "SELECT id, name, url, lastSync FROM servers WHERE id=?", [ id ] ); var res = tx.executeSql( "SELECT id, name, url, lastSync, fetchUnread FROM servers WHERE id=?", [ id ] );
if ( res.rows.length === 0 ) { if ( res.rows.length === 0 ) {
err = qsTr( "Server not found in the configuration" ); err = qsTr( "Server not found in the configuration" );
} }
@ -145,14 +145,15 @@ function addNewServer( props )
db.transaction( db.transaction(
function( tx ) { function( tx ) {
// TODO: try/catch here when error management is in place in the UI // TODO: try/catch here when error management is in place in the UI
tx.executeSql( "INSERT INTO servers(name, url, user, password, clientId, clientSecret) VALUES(?, ?, ?, ?, ?, ?)", tx.executeSql( "INSERT INTO servers(name, url, user, password, clientId, clientSecret, fetchUnread) VALUES(?, ?, ?, ?, ?, ?, ?)",
[ [
props.name, props.name,
props.url, props.url,
props.user, props.user,
props.password, props.password,
props.clientId, props.clientId,
props.clientSecret props.clientSecret,
props.fetchUnread ? 1 : 0
] ]
); );
} }
@ -172,7 +173,8 @@ function updateServer( id, props )
"user=?, " + "user=?, " +
"password=?, " + "password=?, " +
"clientId=?, " + "clientId=?, " +
"clientSecret=? " + "clientSecret=?, " +
"fetchUnread=? " +
"WHERE id=?", "WHERE id=?",
[ [
props.name, props.name,
@ -181,6 +183,7 @@ function updateServer( id, props )
props.password, props.password,
props.clientId, props.clientId,
props.clientSecret, props.clientSecret,
props.fetchUnread ? 1 : 0,
id id
] ]
); );
@ -587,6 +590,9 @@ function downloadArticles( props, cb )
url += "/"; url += "/";
url += "api/entries.json"; url += "api/entries.json";
url += "?since=" + props.since; url += "?since=" + props.since;
// We only use the archive flag to filter out read articles
if ( 'archive' in props && props.archive === 0 )
url += '&archive=' + props.archive
url += "&perPage=10"; url += "&perPage=10";
var articles = new Array; var articles = new Array;
@ -805,9 +811,14 @@ function checkDatabaseStatus( db )
if ( db.version === "" ) { if ( db.version === "" ) {
createLatestDatabase( db ); createLatestDatabase( db );
} }
// _updateSchema_v* will take care of calling the relevant update methods
// to bring the database to the latest version
else if ( db.version === "0.2" ) { else if ( db.version === "0.2" ) {
_updateSchema_v3( db ); _updateSchema_v3( db );
} }
else if ( db.version === "0.3" ) {
_updateSchema_v4( db )
}
} }
function createLatestDatabase( db ) function createLatestDatabase( db )
@ -825,7 +836,8 @@ function createLatestDatabase( db )
"password TEXT NOT NULL, " + "password TEXT NOT NULL, " +
"clientId TEXT NOT NULL, " + "clientId TEXT NOT NULL, " +
"clientSecret TEXT NOT NULL, " + "clientSecret TEXT NOT NULL, " +
"lastSync INTEGER DEFAULT 0" + "lastSync INTEGER DEFAULT 0," +
"fetchUnread INTEGER DEFAULT 0" +
")" ")"
); );
@ -898,6 +910,19 @@ function _updateSchema_v3( db )
tx.executeSql( "ALTER TABLE articles_next RENAME TO articles" ); tx.executeSql( "ALTER TABLE articles_next RENAME TO articles" );
db.changeVersion( db.version, "0.3" ); db.changeVersion( db.version, "0.3" );
_updateSchema_v4( db )
}
);
}
function _updateSchema_v4( db )
{
db.transaction(
function( tx ) {
tx.executeSql( "ALTER TABLE servers ADD COLUMN fetchUnread INTEGER DEFAULT 0" );
tx.executeSql( "UPDATE servers SET fetchUnread=0" );
db.changeVersion( db.version, "0.4" );
} }
); );
} }

View File

@ -49,7 +49,8 @@ Dialog {
user: userField.text, user: userField.text,
password: passwordField.text, password: passwordField.text,
clientId: clientIdField.text, clientId: clientIdField.text,
clientSecret: clientSecretField.text clientSecret: clientSecretField.text,
fetchUnread: fetchUnreadSwitch.checked
} }
if ( serverId === -1 ) if ( serverId === -1 )
@ -132,6 +133,13 @@ Dialog {
text: serverSettings.clientSecret text: serverSettings.clientSecret
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhSensitiveData inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhSensitiveData
} }
TextSwitch {
id: fetchUnreadSwitch
width: parent.width
checked: serverSettings.fetchUnread
text: qsTr( "Fetch unread/archived articles" )
}
} }
} }
} }

View File

@ -35,6 +35,7 @@ Item {
property string refreshToken property string refreshToken
property string tokenType property string tokenType
property int tokenExpiry: 0 property int tokenExpiry: 0
property bool fetchUnread: false
signal articlesDownloaded( var list ) signal articlesDownloaded( var list )
signal connected signal connected
@ -53,6 +54,7 @@ Item {
refreshToken = null refreshToken = null
tokenType = null tokenType = null
tokenExpiry = 0 tokenExpiry = 0
fetchUnread = false
} }
} }
@ -68,6 +70,7 @@ Item {
name = props.name name = props.name
url = props.url url = props.url
lastSync = props.lastSync lastSync = props.lastSync
fetchUnread = props.fetchUnread === 1
} }
} }
@ -128,7 +131,7 @@ Item {
} }
else { else {
console.debug( "Downloading articles changes since last sync" ) console.debug( "Downloading articles changes since last sync" )
var props = { url: url, since: lastSync, accessToken: accessToken } var props = { url: url, since: lastSync, accessToken: accessToken, archive: fetchUnread ? 1 : 0 }
WallaBase.downloadArticles( props, onGetUpdatedArticlesDone ) WallaBase.downloadArticles( props, onGetUpdatedArticlesDone )
} }
} }

View File

@ -31,6 +31,7 @@ QtObject {
property string password property string password
property string clientId property string clientId
property string clientSecret property string clientSecret
property bool fetchUnread
signal error( string message ) signal error( string message )
@ -46,6 +47,7 @@ QtObject {
password = null password = null
clientId = null clientId = null
clientSecret = null clientSecret = null
fetchUnread = false
} }
} }
@ -60,6 +62,7 @@ QtObject {
password = props.password password = props.password
clientId = props.clientId clientId = props.clientId
clientSecret = props.clientSecret clientSecret = props.clientSecret
fetchUnread = props.fetchUnread !== 0
} }
} }
} }

View File

@ -126,6 +126,10 @@
<source>Client Secret</source> <source>Client Secret</source>
<translation>Secret du client</translation> <translation>Secret du client</translation>
</message> </message>
<message>
<source>Fetch unread/archived articles</source>
<translation>Télécharger les articles lus / archivés</translation>
</message>
</context> </context>
<context> <context>
<name>ServersPage</name> <name>ServersPage</name>

View File

@ -126,6 +126,10 @@
<source>Client Secret</source> <source>Client Secret</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Fetch unread/archived articles</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ServersPage</name> <name>ServersPage</name>