RenameSheet.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Róbert Márki
  4. **
  5. ** This file is part of Web Feeds.
  6. **
  7. ** Web Feeds is free software: you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation, either version 3 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** Web Feeds is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with Web Feeds. If not, see <http://www.gnu.org/licenses/>.
  19. ****************************************************************************/
  20. import QtQuick 1.1
  21. import com.nokia.meego 1.0
  22. import com.nokia.extras 1.1
  23. import WebFeeds 1.0
  24. import GoogleReader 1.0
  25. import "../../../../shared/qml/UIConstants.js" as UIConstants
  26. import "../../../../shared/qml" as Shared
  27. Shared.CommonSheet {
  28. id: root
  29. property string __originalName: ""
  30. acceptButtonText: qsTr("Rename")
  31. rejectButtonText: qsTr("Cancel")
  32. title: (root.pageItem.itemType != GoogleReaderItem.ItFeedItem) ?
  33. (root.pageItem.itemType != GoogleReaderItem.ItTagItem ? qsTr("Rename folder")
  34. : qsTr("Rename tag"))
  35. : qsTr("Rename subscription")
  36. busyText: qsTr("Renaming")
  37. onStatusChanged: {
  38. if((root.status == DialogStatus.Open)
  39. && (root.__originalName.length == 0)) {
  40. nameField.text = pageItem.title;
  41. root.__originalName = pageItem.title
  42. }
  43. }
  44. function updateAcceptButtonStatus() {
  45. root.acceptButton.enabled = nameField.text.length;
  46. }
  47. onAccepted: {
  48. var newName = nameField.text.trim();
  49. if(newName.length) {
  50. if(newName != root.__originalName) {
  51. root.busy = true;
  52. root.open();
  53. root.pageItem.service.renameItem(root.pageItem, newName);
  54. } else {
  55. root.open();
  56. root.showMessage(qsTr("A different name please"));
  57. }
  58. } else {
  59. root.open();
  60. root.showMessage(qsTr("Name please"));
  61. }
  62. }
  63. onRejected: {
  64. if(root.busy) {
  65. root.open();
  66. root.pageItem.service.abortItemRename(root.pageItem);
  67. }
  68. }
  69. Connections {
  70. target: root.pageItem.service
  71. onItemRenamingFinished: {
  72. if((result == GoogleReaderEnum.ErrNoError)
  73. || (result == GoogleReaderEnum.ErrAborted)) {
  74. root.close();
  75. return;
  76. }
  77. root.busy = false;
  78. if(result == GoogleReaderEnum.ErrNetworkError)
  79. root.showMessage(qsTr("Network error"));
  80. else
  81. root.showMessage((root.pageItem.itemType != GoogleReaderItem.ItFeedItem) ?
  82. (root.pageItem.itemType != GoogleReaderItem.ItTagItem ? qsTr("Failed to rename the folder")
  83. : qsTr("Failed to rename the tag"))
  84. : qsTr("Failed to rename the subscription"));
  85. }
  86. }
  87. RegExpValidator{
  88. id: tagNameValidator
  89. regExp: /[^\"\<\>\?\&\/\\\^\,]*/
  90. }
  91. RegExpValidator{
  92. id: feedNameValidator
  93. regExp: /.*/
  94. }
  95. contentItem: Column {
  96. anchors.fill: parent
  97. anchors.leftMargin: UIConstants.DEFAULT_MARGIN
  98. anchors.rightMargin: UIConstants.DEFAULT_MARGIN
  99. spacing: UIConstants.DEFAULT_HALF_MARGIN
  100. Label {
  101. text: qsTr("Name")
  102. font.family: UIConstants.FONT_FAMILY_LIGHT
  103. }
  104. Shared.TextField {
  105. id: nameField
  106. width: parent.width
  107. inputMethodHints: Qt.ImhNoPredictiveText
  108. onTextChanged: root.updateAcceptButtonStatus();
  109. validator: (root.pageItem.itemType == GoogleReaderItem.ItTagItem) ? tagNameValidator : feedNameValidator
  110. platformSipAttributes: SipAttributes {
  111. actionKeyEnabled: root.acceptButton.enabled
  112. actionKeyLabel: root.acceptButtonText
  113. actionKeyHighlighted: true
  114. }
  115. Keys.onReturnPressed: {
  116. if(root.acceptButton.enabled) {
  117. root.accept();
  118. }
  119. }
  120. }
  121. Connections {
  122. target: root
  123. onStatusChanged: {
  124. if(root.status == DialogStatus.Open) {
  125. nameField.forceActiveFocus();
  126. nameField.platformOpenSoftwareInputPanel();
  127. }
  128. }
  129. }
  130. }
  131. }