123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /****************************************************************************
- **
- ** Copyright (C) 2012 Róbert Márki
- **
- ** This file is part of Web Feeds.
- **
- ** Web Feeds 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.
- **
- ** Web Feeds 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 Web Feeds. If not, see <http://www.gnu.org/licenses/>.
- ****************************************************************************/
- import QtQuick 1.1
- import com.nokia.meego 1.0
- import com.nokia.extras 1.1
- import WebFeeds 1.0
- import NewsBlur 1.0
- import "../../../../shared/qml" as Shared
- import "../../../../shared/qml/UIConstants.js" as UIConstants
- import "../delegates" as Delegates
- CommonNewsBlurSheet {
- id: root
- acceptButtonText: qsTr("Add")
- rejectButtonText: qsTr("Cancel")
- title: qsTr("Add feed")
- busyText: qsTr("Adding feed")
- Connections {
- target: root.service
- onFeedAddingFinished: root.onFeedAddingFinished(result)
- }
- function onFeedAddingFinished(result) {
- if((result == NewsBlurEnum.SreNoError)
- || (result == NewsBlurEnum.SreAborted)) {
- root.close();
- return;
- }
- root.busy = false;
- if(result == NewsBlurEnum.SreNetworkError)
- root.showMessage(qsTr("Network error"));
- else
- root.showMessage(qsTr("Failed to add the feed"));
- }
- onAccepted: {
- root.busy = true;
- root.open();
- root.service.addFeed(root.pageItem, addressField.text);
- }
- onRejected: {
- if(root.busy) {
- root.open();
- root.service.abortAddFeed(root.pageItem);
- }
- }
- contentItem: Column {
- anchors.fill: parent
- spacing: 0
- Column {
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.leftMargin: UIConstants.DEFAULT_MARGIN
- anchors.rightMargin: UIConstants.DEFAULT_MARGIN
- spacing: UIConstants.DEFAULT_HALF_MARGIN
- Label {
- text: qsTr("Address")
- font.family: UIConstants.FONT_FAMILY_LIGHT
- }
- Shared.TextField {
- id: addressField
- width: parent.width
- property bool suggestionsDisabled: false
- placeholderText: qsTr("Enter the address or search terms")
- onTextChanged: {
- root.acceptButton.enabled = addressField.text.length;
- if((addressField.text.length > 0) && !addressField.suggestionsDisabled)
- searchTimer.restart();
- }
- platformSipAttributes: SipAttributes {
- actionKeyEnabled: root.acceptButton.enabled
- actionKeyLabel: root.acceptButtonText
- actionKeyHighlighted: true
- }
- Keys.onReturnPressed: {
- if(root.acceptButton.enabled)
- root.accept();
- }
- Timer {
- id: searchTimer
- interval: 1000;
- onTriggered: {
- suggestionsBusyIndicator.visible = true;
- root.service.findFeeds(addressField.text);
- }
- }
- Connections {
- target: root.service
- onFeedsFound: {
- suggestionsBusyIndicator.visible = false;
- if(result == NewsBlurEnum.SreNoError) {
- suggestionsModel.clear();
- for(var i = 0; i < labels.length; ++i)
- suggestionsModel.append({"title": labels[i], "subtitle": urls[i]});
- } else if(result == NewsBlurEnum.SreNetworkError) {
- root.showMessage(qsTr("Network error"));
- } else if(result != NewsBlurEnum.SreResponseResultFalse){
- root.showMessage(qsTr("Failed to retrieve the suggestions"));
- }
- }
- }
- }
- Shared.LabeledSeparator {
- text: qsTr("Suggestions")
- }
- }
- ListView {
- id: suggestionsListView
- height: root.height - mapToItem(root, 0, 0).y
- width: parent.width
- clip: true
- cacheBuffer: 100 * UIConstants.DEFAULT_DELEGATE_HEIGHT
- model: ListModel {id: suggestionsModel}
- delegate: Delegates.AddFeedSheetDelegate {
- id: suggestionsDelegate
- onReleased: {
- addressField.suggestionsDisabled = true;
- addressField.text = model.subtitle
- addressField.selectAll();
- addressField.suggestionsDisabled = false;
- }
- }
- BusyIndicator {
- id: suggestionsBusyIndicator
- anchors.centerIn: parent
- style: BusyIndicatorStyle { size: "large"}
- visible: false
- running: true
- }
- }
- ScrollDecorator {
- flickableItem: suggestionsListView
- }
- Connections {
- target: root
- onStatusChanged: {
- if(root.status == DialogStatus.Open) {
- addressField.forceActiveFocus();
- addressField.platformOpenSoftwareInputPanel();
- }
- }
- }
- }
- }
|