123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /****************************************************************************
- **
- ** 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 GoogleReader 1.0
- import "../../../../shared/qml/UIConstants.js" as UIConstants
- import "../../../../shared/qml" as Shared
- Shared.CommonSheet {
- id: root
- property string __originalName: ""
- acceptButtonText: qsTr("Rename")
- rejectButtonText: qsTr("Cancel")
- title: (root.pageItem.itemType != GoogleReaderItem.ItFeedItem) ?
- (root.pageItem.itemType != GoogleReaderItem.ItTagItem ? qsTr("Rename folder")
- : qsTr("Rename tag"))
- : qsTr("Rename subscription")
- busyText: qsTr("Renaming")
- onStatusChanged: {
- if((root.status == DialogStatus.Open)
- && (root.__originalName.length == 0)) {
- nameField.text = pageItem.title;
- root.__originalName = pageItem.title
- }
- }
- function updateAcceptButtonStatus() {
- root.acceptButton.enabled = nameField.text.length;
- }
- onAccepted: {
- var newName = nameField.text.trim();
- if(newName.length) {
- if(newName != root.__originalName) {
- root.busy = true;
- root.open();
- root.pageItem.service.renameItem(root.pageItem, newName);
- } else {
- root.open();
- root.showMessage(qsTr("A different name please"));
- }
- } else {
- root.open();
- root.showMessage(qsTr("Name please"));
- }
- }
- onRejected: {
- if(root.busy) {
- root.open();
- root.pageItem.service.abortItemRename(root.pageItem);
- }
- }
- Connections {
- target: root.pageItem.service
- onItemRenamingFinished: {
- if((result == GoogleReaderEnum.ErrNoError)
- || (result == GoogleReaderEnum.ErrAborted)) {
- root.close();
- return;
- }
- root.busy = false;
- if(result == GoogleReaderEnum.ErrNetworkError)
- root.showMessage(qsTr("Network error"));
- else
- root.showMessage((root.pageItem.itemType != GoogleReaderItem.ItFeedItem) ?
- (root.pageItem.itemType != GoogleReaderItem.ItTagItem ? qsTr("Failed to rename the folder")
- : qsTr("Failed to rename the tag"))
- : qsTr("Failed to rename the subscription"));
- }
- }
- RegExpValidator{
- id: tagNameValidator
- regExp: /[^\"\<\>\?\&\/\\\^\,]*/
- }
- RegExpValidator{
- id: feedNameValidator
- regExp: /.*/
- }
- contentItem: Column {
- anchors.fill: parent
- anchors.leftMargin: UIConstants.DEFAULT_MARGIN
- anchors.rightMargin: UIConstants.DEFAULT_MARGIN
- spacing: UIConstants.DEFAULT_HALF_MARGIN
- Label {
- text: qsTr("Name")
- font.family: UIConstants.FONT_FAMILY_LIGHT
- }
- Shared.TextField {
- id: nameField
- width: parent.width
- inputMethodHints: Qt.ImhNoPredictiveText
- onTextChanged: root.updateAcceptButtonStatus();
- validator: (root.pageItem.itemType == GoogleReaderItem.ItTagItem) ? tagNameValidator : feedNameValidator
- platformSipAttributes: SipAttributes {
- actionKeyEnabled: root.acceptButton.enabled
- actionKeyLabel: root.acceptButtonText
- actionKeyHighlighted: true
- }
- Keys.onReturnPressed: {
- if(root.acceptButton.enabled) {
- root.accept();
- }
- }
- }
- Connections {
- target: root
- onStatusChanged: {
- if(root.status == DialogStatus.Open) {
- nameField.forceActiveFocus();
- nameField.platformOpenSoftwareInputPanel();
- }
- }
- }
- }
- }
|