RenameSheet.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 NewsBlur 1.0
  25. import "../../../../shared/qml/UIConstants.js" as UIConstants
  26. import "../../../../shared/qml" as Shared
  27. CommonNewsBlurSheet {
  28. id: root
  29. property string __originalName: ""
  30. acceptButtonText: qsTr("Rename")
  31. rejectButtonText: qsTr("Cancel")
  32. busyText: qsTr("Renaming")
  33. function updateAcceptButtonStatus() {
  34. root.acceptButton.enabled = nameField.text.length;
  35. }
  36. Connections {
  37. target: root.service
  38. onItemRenamingFinished: root.onItemRenamingFinished(result)
  39. }
  40. function onItemRenamingFinished(result) {
  41. if((result == NewsBlurEnum.SreNoError)
  42. || result == NewsBlurEnum.SreAborted) {
  43. root.close();
  44. return;
  45. }
  46. root.busy = false;
  47. if(result == NewsBlurEnum.SreNetworkError)
  48. root.showMessage(qsTr("Network error"));
  49. else if(root.pageItem.itemType == NewsBlurItem.FeedItem)
  50. root.showMessage(qsTr("Failed to rename the feed"));
  51. else
  52. root.showMessage(qsTr("Failed to rename the folder"));
  53. }
  54. onAccepted: {
  55. var newName = nameField.text.trim();
  56. if(newName.length) {
  57. if(newName != root.__originalName) {
  58. root.busy = true;
  59. root.open();
  60. root.service.renameItem(root.pageItem, newName);
  61. } else {
  62. root.open();
  63. root.showMessage(qsTr("A different name please"));
  64. }
  65. } else {
  66. root.open();
  67. root.showMessage(qsTr("Name please"));
  68. }
  69. }
  70. onRejected: {
  71. if(root.busy) {
  72. root.open();
  73. root.service.abortItemRename(root.pageItem);
  74. }
  75. }
  76. onPageItemChanged: {
  77. if(root.pageItem) {
  78. nameField.text = pageItem.title;
  79. root.__originalName = pageItem.title
  80. }
  81. }
  82. contentItem: Column {
  83. anchors.fill: parent
  84. anchors.leftMargin: UIConstants.DEFAULT_MARGIN
  85. anchors.rightMargin: UIConstants.DEFAULT_MARGIN
  86. spacing: UIConstants.DEFAULT_HALF_MARGIN
  87. Label {
  88. text: qsTr("Name")
  89. font.family: UIConstants.FONT_FAMILY_LIGHT
  90. }
  91. Shared.TextField {
  92. id: nameField
  93. width: parent.width
  94. inputMethodHints: Qt.ImhNoPredictiveText
  95. onTextChanged: root.updateAcceptButtonStatus();
  96. platformSipAttributes: SipAttributes {
  97. actionKeyEnabled: root.acceptButton.enabled
  98. actionKeyLabel: root.acceptButtonText
  99. actionKeyHighlighted: true
  100. }
  101. Keys.onReturnPressed: {
  102. if(root.acceptButton.enabled) {
  103. root.accept();
  104. }
  105. }
  106. }
  107. Connections {
  108. target: root
  109. onStatusChanged: {
  110. if(root.status == DialogStatus.Open) {
  111. nameField.forceActiveFocus();
  112. nameField.platformOpenSoftwareInputPanel();
  113. }
  114. }
  115. }
  116. }
  117. }