[sailfish][Refactoring] AddSubscription; inlined ComboBoxList
This commit is contained in:
parent
d1968b6033
commit
95c91f1131
3 changed files with 97 additions and 123 deletions
|
|
@ -26,48 +26,79 @@ 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
|
||||
|
||||
ListModel {
|
||||
id: allCategories
|
||||
SilicaFlickable {
|
||||
contentHeight: content.height
|
||||
contentWidth: parent.width
|
||||
anchors.fill: parent
|
||||
|
||||
function load(categories) {
|
||||
if (!categories || !categories.length) {
|
||||
return
|
||||
Column {
|
||||
id: content
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
margins: Theme.paddingMedium
|
||||
}
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
DialogHeader {
|
||||
acceptText: qsTr("Add subscription")
|
||||
}
|
||||
|
||||
var ttrss = rootWindow.getTTRSS()
|
||||
TextField {
|
||||
id: feed
|
||||
label: qsTr("Feed address")
|
||||
placeholderText: label
|
||||
focus: true
|
||||
width: parent.width
|
||||
|
||||
for(var i = 0; i < categories.length; ++i) {
|
||||
var title = ttrss.html_entity_decode(categories[i].title, 'ENT_QUOTES')
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhUrlCharactersOnly
|
||||
EnterKey.enabled: text || inputMethodComposing
|
||||
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
||||
EnterKey.onClicked: root.accept()
|
||||
}
|
||||
|
||||
if (categories[i].id === ttrss.constants['categories']['UNCATEGORIZED']) {
|
||||
title = constant.uncategorizedCategory
|
||||
ComboBox {
|
||||
id: categoryChooser
|
||||
label: qsTr("Category")
|
||||
|
||||
menu: ContextMenu {
|
||||
Repeater {
|
||||
model: allCategories
|
||||
MenuItem {
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allCategories.append({
|
||||
name: title,
|
||||
value: parseInt(categories[i].id),
|
||||
});
|
||||
}
|
||||
categoryChooser.startTimer()
|
||||
}
|
||||
}
|
||||
onCurrentIndexChanged: {
|
||||
var index = categoryChooser.currentIndex
|
||||
root.selected = allCategories.get(index).value
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
categoryModel.getAllCategories(function(successful, errorMessage,
|
||||
categories) {
|
||||
if (successful) {
|
||||
allCategories.load(categories)
|
||||
categoryChooser.startTimer()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO make use of errorMessage
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
|
|
@ -77,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
|
||||
initialId: root.categoryId
|
||||
|
||||
onCurrentIndexChanged: {
|
||||
root.selectedId = model.get(categoryChooser.currentIndex).id
|
||||
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,61 +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 {
|
||||
id: box
|
||||
|
||||
property int initialId
|
||||
property alias model: repeater.model
|
||||
|
||||
function getInitialId() {
|
||||
for (var i = 0; i < model.count; i++) {
|
||||
if (repeater.model.get(i).id === initialId) {
|
||||
box.currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function startTimer() {
|
||||
timer.start()
|
||||
}
|
||||
|
||||
menu: ContextMenu {
|
||||
Repeater {
|
||||
id: repeater
|
||||
MenuItem {
|
||||
text: model.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 500
|
||||
repeat: false
|
||||
triggeredOnStart: false
|
||||
onTriggered: getInitialId()
|
||||
}
|
||||
}
|
||||
|
|
@ -105,13 +105,16 @@ 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) {
|
||||
ttrss.subscribe(dialog.selected, dialog.src, function(result) {
|
||||
switch (result) {
|
||||
case 0:
|
||||
notification.show(qsTr('Already subscribed to Feed'))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue