AddFeedSheet.qml 5.9 KB

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