AddFeedSheet.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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" as Shared
  26. import "../../../../shared/qml/UIConstants.js" as UIConstants
  27. import "../delegates" as Delegates
  28. Shared.CommonSheet {
  29. id: root
  30. property variant service
  31. acceptButtonText: qsTr("Subscribe")
  32. rejectButtonText: qsTr("Cancel")
  33. title: qsTr("Subscribe to feed")
  34. busyText: qsTr("Subscribing")
  35. Connections {
  36. target: root.service
  37. onFeedAddingFinished: root.onFeedAddingFinished(result)
  38. }
  39. function onFeedAddingFinished(result) {
  40. if((result == GoogleReaderEnum.ErrNoError)
  41. || (result == GoogleReaderEnum.ErrAborted)) {
  42. root.close();
  43. return;
  44. }
  45. root.busy = false;
  46. if(result == GoogleReaderEnum.ErrNetworkError)
  47. root.showMessage(qsTr("Network error"));
  48. else
  49. root.showMessage(qsTr("Failed to subscribe to feed"));
  50. }
  51. onAccepted: {
  52. root.busy = true;
  53. root.open();
  54. root.service.addFeed(addressField.text);
  55. }
  56. onRejected: {
  57. if(root.busy) {
  58. root.open();
  59. root.service.abortAddFeed(root.pageItem);
  60. }
  61. }
  62. contentItem: Column {
  63. anchors.fill: parent
  64. spacing: 0
  65. Column {
  66. anchors.left: parent.left
  67. anchors.right: parent.right
  68. anchors.leftMargin: UIConstants.DEFAULT_MARGIN
  69. anchors.rightMargin: UIConstants.DEFAULT_MARGIN
  70. spacing: UIConstants.DEFAULT_HALF_MARGIN
  71. Label {
  72. text: qsTr("Address")
  73. font.family: UIConstants.FONT_FAMILY_LIGHT
  74. }
  75. Shared.TextField {
  76. id: addressField
  77. width: parent.width
  78. property bool suggestionsDisabled: false
  79. placeholderText: qsTr("Enter the address or search terms")
  80. onTextChanged: {
  81. root.acceptButton.enabled = addressField.text.length;
  82. if((addressField.text.length > 0) && !addressField.suggestionsDisabled)
  83. searchTimer.restart();
  84. }
  85. platformSipAttributes: SipAttributes {
  86. actionKeyEnabled: root.acceptButton.enabled
  87. actionKeyLabel: root.acceptButtonText
  88. actionKeyHighlighted: true
  89. }
  90. Keys.onReturnPressed: {
  91. if(root.acceptButton.enabled)
  92. root.accept();
  93. }
  94. Timer {
  95. id: searchTimer
  96. interval: 1000;
  97. onTriggered: {
  98. suggestionsBusyIndicator.visible = true;
  99. var searchTerms = addressField.text;
  100. searchTerms.trim();
  101. root.service.findFeeds(searchTerms);
  102. }
  103. }
  104. Connections {
  105. target: root.service
  106. onFeedSearchFinished: {
  107. suggestionsBusyIndicator.visible = false;
  108. if(result == GoogleReaderEnum.ErrNoError) {
  109. suggestionsModel.clear();
  110. for(var i = 0; i < titles.length; ++i)
  111. suggestionsModel.append({"title": titles[i], "url": urls[i]});
  112. } else if(result == GoogleReaderEnum.ErrNetworkError) {
  113. root.showMessage(qsTr("Network error"));
  114. } else {
  115. root.showMessage(qsTr("Failed to retrieve the suggestions"));
  116. }
  117. }
  118. }
  119. }
  120. Shared.LabeledSeparator {
  121. text: qsTr("Suggestions")
  122. }
  123. }
  124. ListView {
  125. id: suggestionsListView
  126. height: root.height - mapToItem(root, 0, 0).y
  127. width: parent.width
  128. clip: true
  129. cacheBuffer: 100 * UIConstants.DEFAULT_DELEGATE_HEIGHT
  130. model: ListModel {id: suggestionsModel}
  131. delegate: Delegates.AddFeedSheetDelegate {
  132. id: suggestionsDelegate
  133. titleColor: (addressField.text == model.subtitle) ? UIConstants.HIGHLIGHT_COLOR : "black"
  134. onReleased: {
  135. addressField.suggestionsDisabled = true;
  136. addressField.text = model.url
  137. addressField.selectAll();
  138. addressField.suggestionsDisabled = false;
  139. }
  140. }
  141. BusyIndicator {
  142. id: suggestionsBusyIndicator
  143. anchors.centerIn: parent
  144. style: BusyIndicatorStyle { size: "large"}
  145. visible: false
  146. running: true
  147. }
  148. }
  149. ScrollDecorator {
  150. flickableItem: suggestionsListView
  151. }
  152. Connections {
  153. target: root
  154. onStatusChanged: {
  155. if(root.status == DialogStatus.Open) {
  156. addressField.forceActiveFocus();
  157. addressField.platformOpenSoftwareInputPanel();
  158. }
  159. }
  160. }
  161. }
  162. }