diff --git a/harbour-wallaread.pro b/harbour-wallaread.pro index 9a1e39c..1ca7b1b 100644 --- a/harbour-wallaread.pro +++ b/harbour-wallaread.pro @@ -54,4 +54,6 @@ DISTFILES += \ qml/types/ServerSettings.qml \ rpm/harbour-wallaread.changes \ qml/pages/ServerPageShowDialog.qml \ - qml/types/ServerPageShowPreferences.qml + qml/types/ServerPageShowPreferences.qml \ + qml/types/ServerPageSortPreferences.qml \ + qml/pages/ServerPageSortDialog.qml diff --git a/qml/js/WallaBase.js b/qml/js/WallaBase.js index c3bb6d4..19d2100 100644 --- a/qml/js/WallaBase.js +++ b/qml/js/WallaBase.js @@ -23,7 +23,7 @@ .import QtQuick.LocalStorage 2.0 as Storage /* - Exposed variable + Exposed variables */ var ArticlesFilter = { @@ -32,6 +32,12 @@ var ArticlesFilter = { Starred: 4 } +var ArticlesSort = { + Created: 1, + Updated: 2, + Domain: 3 +} + /* Timer management, used for the various setTimeout() calls */ @@ -380,7 +386,7 @@ function syncDeletedArticles( props, cb ) ); } -function getArticles( serverId, cb, filter ) +function getArticles( serverId, cb, filter, sortOrder, sortAsc ) { var db = getDatabase(); @@ -389,6 +395,7 @@ function getArticles( serverId, cb, filter ) var articles = new Array var err = null; var where = ""; + var order = ""; if ( filter & ArticlesFilter.Read ) where += " AND archived=1"; @@ -398,8 +405,22 @@ function getArticles( serverId, cb, filter ) if ( filter & ArticlesFilter.Starred ) where += " AND starred=1"; + if ( sortOrder === ArticlesSort.Created ) + order = " ORDER BY created"; + else if ( sortOrder === ArticlesSort.Updated ) + order = " ORDER BY updated" + else if ( sortOrder === ArticlesSort.Domain ) + order = " ORDER BY domain" + + if ( order.length > 0 ) { + if ( sortAsc ) + order += " ASC" + else + order += " DESC" + } + try { - var res = tx.executeSql( "SELECT * FROM articles WHERE server=?" + where, [ serverId ] ); + var res = tx.executeSql( "SELECT * FROM articles WHERE server=?" + where + order, [ serverId ] ); for ( var i = 0; i < res.rows.length; ++i ) { articles.push( res.rows[i] ); } diff --git a/qml/models/ArticlesModel.qml b/qml/models/ArticlesModel.qml index 8990410..72459de 100644 --- a/qml/models/ArticlesModel.qml +++ b/qml/models/ArticlesModel.qml @@ -30,6 +30,8 @@ ListModel { property bool showAll: false property bool showRead: false property bool showStarred: false + property int sortOrder: WallaBase.ArticlesSort.Created + property bool sortAsc: true signal error( string message ) @@ -48,7 +50,7 @@ ListModel { filter |= WallaBase.ArticlesFilter.Starred } - WallaBase.getArticles( serverId, onArticlesLoaded, filter ) + WallaBase.getArticles( serverId, onArticlesLoaded, filter, sortOrder, sortAsc ) } function onArticlesLoaded( articles, err ) { diff --git a/qml/pages/ServerPage.qml b/qml/pages/ServerPage.qml index 75706ce..40cf2dd 100644 --- a/qml/pages/ServerPage.qml +++ b/qml/pages/ServerPage.qml @@ -32,7 +32,6 @@ Page { property int serverId property alias server: server - property alias showPreferences: showPreferences Server { id: server @@ -51,6 +50,10 @@ Page { id: showPreferences } + ServerPageSortPreferences { + id: sortPreferences + } + ArticlesModel { id: articlesModel @@ -273,6 +276,18 @@ Page { model: articlesModel PullDownMenu { + MenuItem { + text: qsTr( "Sort: " ) + sortPreferences.getVisibleDescription() + onClicked: { + var dlg = pageStack.push( Qt.resolvedUrl( "ServerPageSortDialog.qml" ), { preferences: sortPreferences } ) + dlg.accepted.connect ( function() { + articlesModel.sortOrder = sortPreferences.sortOrder + articlesModel.sortAsc = sortPreferences.sortAsc + serverPage.updateArticlesList() + } ) + } + } + MenuItem { text: qsTr( "Show: " ) + showPreferences.getVisibleDescription() onClicked: { diff --git a/qml/pages/ServerPageSortDialog.qml b/qml/pages/ServerPageSortDialog.qml new file mode 100644 index 0000000..0fce319 --- /dev/null +++ b/qml/pages/ServerPageSortDialog.qml @@ -0,0 +1,89 @@ +/* + * WallaRead - A Wallabag 2+ client for SailfishOS + * © 2017 Grégory Oestreicher + * + * This file is part of WallaRead. + * + * WallaRead is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WallaRead is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WallaRead. If not, see . + * + */ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +import "../js/WallaBase.js" as WallaBase + +Dialog { + id: serverSortDialog + allowedOrientations: Orientation.All + canAccept: true + + property variant preferences + + Component.onCompleted: { + if ( preferences.sortOrder === WallaBase.ArticlesSort.Created ) + sortComboBox.currentIndex = 0 + else if ( preferences.sortOrder === WallaBase.ArticlesSort.Updated ) + sortComboBox.currentIndex = 1 + else if ( preferences.sortOrder === WallaBase.ArticlesSort.Domain ) + sortComboBox.currentIndex = 2 + } + + onDone: { + if ( result === DialogResult.Accepted ) { + if ( sortComboBox.currentItem.text === "Created" ) + preferences.sortOrder = WallaBase.ArticlesSort.Created + else if ( sortComboBox.currentItem.text === "Updated" ) + preferences.sortOrder = WallaBase.ArticlesSort.Updated + else if ( sortComboBox.currentItem.text === "Domain" ) + preferences.sortOrder = WallaBase.ArticlesSort.Domain + + preferences.sortAsc = sortAscSwitch.checked + } + } + + SilicaFlickable { + anchors.fill: parent + contentHeight: column.height + width: parent.width + + Column { + id: column + width: parent.width + + DialogHeader { + acceptText: qsTr( "Sort view" ) + } + + ComboBox { + id: sortComboBox + width: parent.width + label: qsTr( "Sort order" ) + + menu: ContextMenu { + MenuItem { text: "Created" } + MenuItem { text: "Updated" } + MenuItem { text: "Domain" } + } + } + + TextSwitch { + id: sortAscSwitch + width: parent.width + checked: preferences.sortAsc + text: qsTr( "Sort Ascending" ) + } + } + } +} diff --git a/qml/types/ServerPageSortPreferences.qml b/qml/types/ServerPageSortPreferences.qml new file mode 100644 index 0000000..f425edd --- /dev/null +++ b/qml/types/ServerPageSortPreferences.qml @@ -0,0 +1,49 @@ +/* + * WallaRead - A Wallabag 2+ client for SailfishOS + * © 2017 Grégory Oestreicher + * + * This file is part of WallaRead. + * + * WallaRead is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WallaRead is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WallaRead. If not, see . + * + */ + +import QtQuick 2.0 + +import "../js/WallaBase.js" as WallaBase + +QtObject { + property int sortOrder: WallaBase.ArticlesSort.Created + property bool sortAsc: true + + function getVisibleDescription() { + var ret = "" + + if ( sortOrder === WallaBase.ArticlesSort.Created ) + ret = qsTr( "Created" ) + else if ( sortOrder === WallaBase.ArticlesSort.Updated ) + ret = qsTr( "Updated" ) + else if ( sortOrder === WallaBase.ArticlesSort.Domain ) + ret = qsTr( "Domain" ) + + ret += " " + + if ( sortAsc ) + ret += "asc." + else + ret += "desc." + + return ret + } +} diff --git a/translations/harbour-wallaread-fr.ts b/translations/harbour-wallaread-fr.ts index 45174cb..f9746a8 100644 --- a/translations/harbour-wallaread-fr.ts +++ b/translations/harbour-wallaread-fr.ts @@ -60,22 +60,6 @@ Deleting Suppression - - Show unstarred articles - Afficher les articles hors favoris - - - Show only starred articles - Seulement afficher les articles en favoris - - - Show unread articles - Afficher les articles non lus - - - Show read articles - Afficher les articles lus - Article URL URL de l'article @@ -88,6 +72,10 @@ Show: Afficher : + + Sort: + Tri : + ServerPageShowDialog @@ -123,6 +111,36 @@ tous + + ServerPageSortDialog + + Sort view + Trier la liste + + + Sort order + Ordre de tri + + + Sort Ascending + Trier par ordre croissant + + + + ServerPageSortPreferences + + Created + Création + + + Updated + Modification + + + Domain + Domaine + + ServerSettings diff --git a/translations/harbour-wallaread.ts b/translations/harbour-wallaread.ts index d3555c2..9cdb145 100644 --- a/translations/harbour-wallaread.ts +++ b/translations/harbour-wallaread.ts @@ -52,22 +52,6 @@ Article URL - - Show unstarred articles - - - - Show only starred articles - - - - Show unread articles - - - - Show read articles - - Refresh @@ -88,6 +72,10 @@ Show: + + Sort: + + ServerPageShowDialog @@ -123,6 +111,36 @@ + + ServerPageSortDialog + + Sort view + + + + Sort order + + + + Sort Ascending + + + + + ServerPageSortPreferences + + Created + + + + Updated + + + + Domain + + + ServerSettings