Merge branch 'add-subscription' of git://github.com/michael-k/ttrss into michael-k-add-subscription
This commit is contained in:
commit
49985d6c72
5 changed files with 222 additions and 156 deletions
|
|
@ -95,6 +95,13 @@ ListModel {
|
|||
updateFinished()
|
||||
}
|
||||
|
||||
function getAllCategories(callback) {
|
||||
var ttrss = rootWindow.getTTRSS();
|
||||
ttrss.getAllCategories(function(successful, errorMessage, categories) {
|
||||
callback(successful, errorMessage, categories)
|
||||
})
|
||||
}
|
||||
|
||||
function getTotalUnreadItems() {
|
||||
if (root.count <= 0) {
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -432,6 +432,70 @@ function process_updateCategories(callback, httpreq) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories from server. Excludes special categories except for
|
||||
* `Uncategorized`.
|
||||
* @param {function} A callback function with parameters boolean (indicating
|
||||
* success), string (an optional error message), and array (the categories
|
||||
* as objects).
|
||||
*/
|
||||
function getAllCategories(callback) {
|
||||
if(responsesPending['allcategories']) {
|
||||
return;
|
||||
}
|
||||
|
||||
// needs to be logged in
|
||||
if(!state['token']) {
|
||||
requestsPending['allcategories'] = true;
|
||||
processPendingRequests(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
responsesPending['allcategories'] = true;
|
||||
|
||||
var params = {
|
||||
'op': 'getCategories',
|
||||
'sid': state['token'],
|
||||
'unread_only': false
|
||||
}
|
||||
|
||||
networkCall(params, function(http) { process_getAllCategories(callback, http) });
|
||||
}
|
||||
|
||||
/** @private */
|
||||
function process_getAllCategories(callback, httpreq) {
|
||||
var response = process_readyState(httpreq);
|
||||
|
||||
responsesPending['allcategories'] = false;
|
||||
|
||||
if (!response.successful) {
|
||||
trace(1, "Get all categories: " + response.errorMessage);
|
||||
if (callback) {
|
||||
callback(false, response.errorMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var categories = []
|
||||
|
||||
for(var i = 0; i < response.content.length; i++) {
|
||||
var cat = response.content[i];
|
||||
|
||||
if (cat.id < 0) {
|
||||
// Exclude special categories
|
||||
continue;
|
||||
}
|
||||
|
||||
categories.push(cat);
|
||||
}
|
||||
|
||||
if(!processPendingRequests(callback) && callback) {
|
||||
// This action is complete (as there's no other requests to do)
|
||||
// Fire callback saying all ok
|
||||
callback(true, "", categories);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the feeds of a category.
|
||||
* @param {int} The id of the category whose feeds should be updated.
|
||||
|
|
|
|||
|
|
@ -26,31 +26,81 @@ import "../../models" 1.0
|
|||
Dialog {
|
||||
id: root
|
||||
|
||||
property int categoryId
|
||||
property int selectedId
|
||||
property alias src: feedAddress.text
|
||||
property int initial
|
||||
property int selected: initial
|
||||
property alias src: feed.text
|
||||
|
||||
canAccept: feedAddress.text && allCategories.count > 0 && root.selectedId >= 0
|
||||
acceptDestinationAction: PageStackAction.Pop
|
||||
canAccept: feed.text && allCategories.count > 0 && root.selected >= 0
|
||||
|
||||
CategoryModel {
|
||||
id: allCategories
|
||||
SilicaFlickable {
|
||||
contentHeight: content.height
|
||||
contentWidth: parent.width
|
||||
anchors.fill: parent
|
||||
|
||||
onUpdateFinished: {
|
||||
// we need to use the timer as the repeater might not have filled
|
||||
// the contextmenu of the combobox yet
|
||||
categoryChooser.startTimer()
|
||||
Column {
|
||||
id: content
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
margins: Theme.paddingMedium
|
||||
}
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
DialogHeader {
|
||||
acceptText: qsTr("Add subscription")
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: feed
|
||||
label: qsTr("Feed address")
|
||||
placeholderText: label
|
||||
focus: true
|
||||
width: parent.width
|
||||
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhUrlCharactersOnly
|
||||
EnterKey.enabled: text || inputMethodComposing
|
||||
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
||||
EnterKey.onClicked: root.accept()
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: categoryChooser
|
||||
label: qsTr("Category")
|
||||
|
||||
menu: ContextMenu {
|
||||
Repeater {
|
||||
model: allCategories
|
||||
MenuItem {
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCurrentIndexChanged: {
|
||||
var index = categoryChooser.currentIndex
|
||||
root.selected = allCategories.get(index).value
|
||||
}
|
||||
|
||||
function setInitialIndex() {
|
||||
timer.start()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 200
|
||||
onTriggered: {
|
||||
for (var i = 0; i < allCategories.count; i++) {
|
||||
if (allCategories.get(i).value === root.initial) {
|
||||
categoryChooser.currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
var oldShowAll = settings.showAll
|
||||
var ttrss = rootWindow.getTTRSS()
|
||||
ttrss.setShowAll(true)
|
||||
allCategories.update()
|
||||
ttrss.setShowAll(oldShowAll)
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
visible: network.loading
|
||||
running: visible
|
||||
|
|
@ -58,39 +108,40 @@ Dialog {
|
|||
size: BusyIndicatorSize.Large
|
||||
}
|
||||
|
||||
Column {
|
||||
width: parent.width
|
||||
ListModel {
|
||||
id: allCategories
|
||||
|
||||
DialogHeader {
|
||||
acceptText: qsTr("Add subscription")
|
||||
Component.onCompleted: {
|
||||
categoryModel.getAllCategories(function(successful, errorMessage,
|
||||
categories) {
|
||||
if (successful) {
|
||||
allCategories.load(categories)
|
||||
}
|
||||
// TODO make use of errorMessage
|
||||
})
|
||||
}
|
||||
TextField {
|
||||
id: feedAddress
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
focus: true
|
||||
label: qsTr("Feed address:")
|
||||
placeholderText: label
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhUrlCharactersOnly
|
||||
EnterKey.enabled: text || inputMethodComposing
|
||||
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
||||
EnterKey.onClicked: root.accept()
|
||||
}
|
||||
ComboBoxList {
|
||||
id: categoryChooser
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
label: qsTr("Category:")
|
||||
model: allCategories
|
||||
initialValue: root.categoryId
|
||||
|
||||
onCurrentIndexChanged: {
|
||||
root.selectedId = allCategories.get(categoryChooser.currentIndex).categoryId
|
||||
function load(categories) {
|
||||
if (!categories || !categories.length) {
|
||||
return
|
||||
}
|
||||
|
||||
var ttrss = rootWindow.getTTRSS()
|
||||
|
||||
for(var i = 0; i < categories.length; ++i) {
|
||||
var title = ttrss.html_entity_decode(categories[i].title,
|
||||
'ENT_QUOTES')
|
||||
|
||||
if (categories[i].id === ttrss.constants['categories']['UNCATEGORIZED']) {
|
||||
title = constant.uncategorizedCategory
|
||||
}
|
||||
|
||||
allCategories.append({
|
||||
name: title,
|
||||
value: parseInt(categories[i].id),
|
||||
});
|
||||
}
|
||||
categoryChooser.setInitialIndex()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* This file is part of TTRss, a Tiny Tiny RSS Reader App
|
||||
* for MeeGo Harmattan and Sailfish OS.
|
||||
* Copyright (C) 2012–2014 Hauke Schade
|
||||
*
|
||||
* TTRss 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* TTRss 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 TTRss; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
|
||||
* http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
|
||||
ComboBox {
|
||||
property int initialValue
|
||||
property alias model: repeater.model
|
||||
|
||||
function getInitialValue() {
|
||||
for (var i = 0; i < model.count; i++) {
|
||||
if (repeater.model.get(i).value === initialValue) {
|
||||
box.currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function startTimer() {
|
||||
timer.start()
|
||||
}
|
||||
|
||||
id: box
|
||||
menu: ContextMenu {
|
||||
Repeater {
|
||||
id: repeater
|
||||
MenuItem {
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 500
|
||||
repeat: false
|
||||
triggeredOnStart: false
|
||||
onTriggered: getInitialValue()
|
||||
}
|
||||
}
|
||||
|
|
@ -105,58 +105,62 @@ Page {
|
|||
}
|
||||
|
||||
function add_subscription() {
|
||||
var params = {
|
||||
initial: feedsPage.category.categoryId
|
||||
}
|
||||
var dialog = pageStack.push(Qt.resolvedUrl("AddSubscription.qml"),
|
||||
{ categoryId: feedsPage.category.categoryId })
|
||||
params)
|
||||
|
||||
dialog.accepted.connect(function() {
|
||||
var ttrss = rootWindow.getTTRSS()
|
||||
|
||||
ttrss.subscribe(dialog.selectedId, dialog.src, function(result) {
|
||||
switch (result) {
|
||||
case 0:
|
||||
notification.show(qsTr('Already subscribed to Feed'))
|
||||
break
|
||||
case 1:
|
||||
//notification.show(qsTr('Feed added'))
|
||||
|
||||
// During categoryModel.update() the elements in
|
||||
// categoryModel will be removed and therefore
|
||||
// feedsPage.category and feeds.category become
|
||||
// null.
|
||||
//
|
||||
// The following code sets both
|
||||
// feedsPage.category and feedModel.category
|
||||
// back to its previous value.
|
||||
var catId = feedsPage.category.categoryId;
|
||||
function tmp() {
|
||||
feedsPage.category = categoryModel.getItemForId(catId);
|
||||
feedModel.category = feedsPage.category
|
||||
feedModel.update()
|
||||
categoryModel.updateFinished.disconnect(tmp)
|
||||
}
|
||||
categoryModel.updateFinished.connect(tmp)
|
||||
|
||||
categoryModel.update()
|
||||
break
|
||||
case 2:
|
||||
notification.show(qsTr('Invalid URL'))
|
||||
break
|
||||
case 3:
|
||||
notification.show(qsTr('URL content is HTML, no feeds available'))
|
||||
break
|
||||
case 4:
|
||||
notification.show(qsTr('URL content is HTML which contains multiple feeds'))
|
||||
break
|
||||
case 5:
|
||||
notification.show(qsTr('Couldn\'t download the URL content'))
|
||||
break
|
||||
case 5:
|
||||
notification.show(qsTr('Content is an invalid XML'))
|
||||
break
|
||||
default:
|
||||
notification.show(qsTr('An error occurred while subscribing to the feed'))
|
||||
}
|
||||
})
|
||||
ttrss.subscribe(dialog.selected, dialog.src, subscribed)
|
||||
})
|
||||
|
||||
function subscribed(result) {
|
||||
switch (result) {
|
||||
case 0:
|
||||
notification.show(qsTr('Already subscribed to Feed'))
|
||||
break
|
||||
case 1:
|
||||
//notification.show(qsTr('Feed added'))
|
||||
|
||||
// During categoryModel.update() the elements in
|
||||
// categoryModel will be removed and therefore
|
||||
// feedsPage.category and feeds.category become
|
||||
// null.
|
||||
//
|
||||
// The following code sets both
|
||||
// feedsPage.category and feedModel.category
|
||||
// back to its previous value.
|
||||
var catId = feedsPage.category.categoryId;
|
||||
function tmp() {
|
||||
feedsPage.category = categoryModel.getItemForId(catId);
|
||||
feedModel.category = feedsPage.category
|
||||
feedModel.update()
|
||||
categoryModel.updateFinished.disconnect(tmp)
|
||||
}
|
||||
categoryModel.updateFinished.connect(tmp)
|
||||
|
||||
categoryModel.update()
|
||||
break
|
||||
case 2:
|
||||
notification.show(qsTr('Invalid URL'))
|
||||
break
|
||||
case 3:
|
||||
notification.show(qsTr('URL content is HTML, no feeds available'))
|
||||
break
|
||||
case 4:
|
||||
notification.show(qsTr('URL content is HTML which contains multiple feeds'))
|
||||
break
|
||||
case 5:
|
||||
notification.show(qsTr('Couldn\'t download the URL content'))
|
||||
break
|
||||
case 5:
|
||||
notification.show(qsTr('Content is an invalid XML'))
|
||||
break
|
||||
default:
|
||||
notification.show(qsTr('An error occurred while subscribing to the feed'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue