From 11e665b13784d8c0c02db04b407a0158b66ae957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Oestreicher?= Date: Mon, 27 Feb 2017 15:09:47 +0100 Subject: [PATCH] Offer an option to prevent downloading archived articles --- qml/js/WallaBase.js | 35 ++++++++++++++++++++++++---- qml/pages/ServerSettingsDialog.qml | 10 +++++++- qml/types/Server.qml | 5 +++- qml/types/ServerSettings.qml | 3 +++ translations/harbour-wallaread-fr.ts | 4 ++++ translations/harbour-wallaread.ts | 4 ++++ 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/qml/js/WallaBase.js b/qml/js/WallaBase.js index 800d331..c3bb6d4 100644 --- a/qml/js/WallaBase.js +++ b/qml/js/WallaBase.js @@ -95,7 +95,7 @@ function getServer( id, cb ) function( tx ) { var server = null; 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 ) { err = qsTr( "Server not found in the configuration" ); } @@ -145,14 +145,15 @@ function addNewServer( props ) db.transaction( function( tx ) { // 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.url, props.user, props.password, props.clientId, - props.clientSecret + props.clientSecret, + props.fetchUnread ? 1 : 0 ] ); } @@ -172,7 +173,8 @@ function updateServer( id, props ) "user=?, " + "password=?, " + "clientId=?, " + - "clientSecret=? " + + "clientSecret=?, " + + "fetchUnread=? " + "WHERE id=?", [ props.name, @@ -181,6 +183,7 @@ function updateServer( id, props ) props.password, props.clientId, props.clientSecret, + props.fetchUnread ? 1 : 0, id ] ); @@ -587,6 +590,9 @@ function downloadArticles( props, cb ) url += "/"; url += "api/entries.json"; 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"; var articles = new Array; @@ -805,9 +811,14 @@ function checkDatabaseStatus( db ) if ( db.version === "" ) { 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" ) { _updateSchema_v3( db ); } + else if ( db.version === "0.3" ) { + _updateSchema_v4( db ) + } } function createLatestDatabase( db ) @@ -825,7 +836,8 @@ function createLatestDatabase( db ) "password TEXT NOT NULL, " + "clientId 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" ); 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" ); } ); } diff --git a/qml/pages/ServerSettingsDialog.qml b/qml/pages/ServerSettingsDialog.qml index 20615c2..ec5540a 100644 --- a/qml/pages/ServerSettingsDialog.qml +++ b/qml/pages/ServerSettingsDialog.qml @@ -49,7 +49,8 @@ Dialog { user: userField.text, password: passwordField.text, clientId: clientIdField.text, - clientSecret: clientSecretField.text + clientSecret: clientSecretField.text, + fetchUnread: fetchUnreadSwitch.checked } if ( serverId === -1 ) @@ -132,6 +133,13 @@ Dialog { text: serverSettings.clientSecret inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhSensitiveData } + + TextSwitch { + id: fetchUnreadSwitch + width: parent.width + checked: serverSettings.fetchUnread + text: qsTr( "Fetch unread/archived articles" ) + } } } } diff --git a/qml/types/Server.qml b/qml/types/Server.qml index 4a49350..2baa0be 100644 --- a/qml/types/Server.qml +++ b/qml/types/Server.qml @@ -35,6 +35,7 @@ Item { property string refreshToken property string tokenType property int tokenExpiry: 0 + property bool fetchUnread: false signal articlesDownloaded( var list ) signal connected @@ -53,6 +54,7 @@ Item { refreshToken = null tokenType = null tokenExpiry = 0 + fetchUnread = false } } @@ -68,6 +70,7 @@ Item { name = props.name url = props.url lastSync = props.lastSync + fetchUnread = props.fetchUnread === 1 } } @@ -128,7 +131,7 @@ Item { } else { 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 ) } } diff --git a/qml/types/ServerSettings.qml b/qml/types/ServerSettings.qml index adbc07b..2dea583 100644 --- a/qml/types/ServerSettings.qml +++ b/qml/types/ServerSettings.qml @@ -31,6 +31,7 @@ QtObject { property string password property string clientId property string clientSecret + property bool fetchUnread signal error( string message ) @@ -46,6 +47,7 @@ QtObject { password = null clientId = null clientSecret = null + fetchUnread = false } } @@ -60,6 +62,7 @@ QtObject { password = props.password clientId = props.clientId clientSecret = props.clientSecret + fetchUnread = props.fetchUnread !== 0 } } } diff --git a/translations/harbour-wallaread-fr.ts b/translations/harbour-wallaread-fr.ts index 2ed3250..3c9c0dc 100644 --- a/translations/harbour-wallaread-fr.ts +++ b/translations/harbour-wallaread-fr.ts @@ -126,6 +126,10 @@ Client Secret Secret du client + + Fetch unread/archived articles + Télécharger les articles lus / archivés + ServersPage diff --git a/translations/harbour-wallaread.ts b/translations/harbour-wallaread.ts index b7e5b91..75a475d 100644 --- a/translations/harbour-wallaread.ts +++ b/translations/harbour-wallaread.ts @@ -126,6 +126,10 @@ Client Secret + + Fetch unread/archived articles + + ServersPage