0.9.1-2 for extras-devel
[feedingit] / psa_harmattan / feedingit / qml / AddFeed.qml
1 import QtQuick 1.0
2 import com.nokia.meego 1.0
3 import "feedSearch.js" as FeedJS
4
5 Page {
6     id: addFeedPage
7     tools: tabTools
8     anchors.margins: UiConstants.DefaultMargin
9     anchors.fill: parent
10
11     TabGroup {
12         id: tabGroup
13         anchors.fill: parent
14         currentTab: searchTab
15
16         Item {
17             id: searchTab
18             anchors.fill: parent
19
20             Column {
21                 spacing: 10
22
23                 Text {
24                     id: searchText
25                     font.pixelSize: 22
26                     color: "white"
27                     text: "Search for feeds"
28                 }
29
30                 TextInputClear {
31                     id: searchInput
32                     placeHolder: "Enter a search term"
33                 }
34
35                 Button {
36                     id: searchButton
37                     text: "Search"
38                     onClicked: FeedJS.keywordSearch(searchInput.text)
39                 }
40             }
41
42             SelectionDialog {
43                      id: searchDialog
44                      titleText: "Select feed:"
45                      //model: []
46                      onSelectedIndexChanged: {
47                          if (selectedIndex>=0) {
48                              var feedTitle = searchDialog.model.get(searchDialog.selectedIndex).name;
49                              var feedUrl = searchDialog.model.get(searchDialog.selectedIndex).url;
50                              //controller.addFeed(feedTitle,feedUrl,1);
51                              categoryDialog.confirmCategory(feedTitle, feedUrl);
52                              console.log("Adding feed "+feedTitle+" at " +feedUrl);
53                          }
54                      }
55             }
56
57         } //searchTab
58
59         Item {
60             id: urlTab
61
62             Column {
63                 Text {
64                     id: urlText
65                     font.pixelSize: 22
66                     color: "white"
67                     text: "Enter the feed URL"
68                 }
69
70                 TextInputClear {
71                     id: urlInput
72                     placeHolder: "Feed URL"
73                     width: parent.width
74                 }
75
76                 Button {
77                     id: urlButton
78                     text: "Add"
79                     onClicked: {
80                         console.log("Adding "+urlInput.text)
81                         //controller.addFeed("",urlInput.text,1);
82                         categoryDialog.confirmCategory("", urlInput.text);
83                     }
84                     width: 150
85                 }
86             }
87
88         } //urlTab
89
90         Item {
91             id: opmlTab
92
93             Column {
94                 Text {
95                     id: opmlText
96                     font.pixelSize: 22
97                     color: "white"
98                     text: "Enter the OPML filename in MyDocs folder"
99                 }
100
101                 TextInputClear {
102                     id: opmlInput
103                     placeHolder: "OPML filename"
104                     width: parent.width
105                 }
106
107                 Button {
108                     id: opmlButton
109                     text: "Import"
110                     onClicked: {
111                         console.log("Importing "+opmlInput.text)
112                         //controller.addFeed("",urlInput.text,1);
113                         var num = controller.importOpml(opmlInput.text)
114                         banner.text=qsTr("Successfully imported "+num+" feeds.")
115                         banner.open()
116                     }
117                     width: 150
118                 }
119             }
120
121         } //opmlTab
122
123         Item {
124             id: categoryTab
125
126             Column {
127                 Text {
128                     id: categoryText
129                     font.pixelSize: 22
130                     color: "white"
131                     text: "Enter the category name"
132                 }
133
134                 TextInputClear {
135                     id: categoryInput
136                     placeHolder: "name"
137                     width: parent.width
138                 }
139
140                 Button {
141                     id: categoryButton
142                     text: "Add"
143                     onClicked: {
144                         if (categoryInput.text != "") {
145                             controller.addCategory(categoryInput.text)
146                             categoryDialog.reload()
147                             window.categoryReloadRequest()
148                         }
149                     }
150                     width: 150
151                 }
152             }
153
154         } //categoryTab
155
156         ToolBarLayout {
157             id: tabTools
158             ToolIcon {
159                 iconId: "toolbar-back"
160                 onClicked: {
161                     if (tabGroup.currentTab.depth > 1) {
162                         tabGroup.currentTab.pop()
163                     } else {
164                         pageStack.pop()
165                     }
166                     window.feedReloadRequest()
167                     window.categoryReloadRequest()
168                 }
169             }
170             ButtonRow {
171                 TabButton {
172                     text: "Search"
173                     tab: searchTab
174                 }
175                 TabButton {
176                     text: "URL"
177                     tab: urlTab
178                 }
179                 TabButton {
180                     text: "Import"
181                     tab: opmlTab
182                 }
183                 TabButton {
184                     text: "Categories"
185                     tab: categoryTab
186                 }
187             }
188
189         }
190     }
191
192     SelectionDialog {
193              id: categoryDialog
194              titleText: "Select category:"
195              property string feedTitle
196              property string feedUrl
197
198              //property variant listModel: ListModel {}
199
200              function createListModel() {
201                  var listModel = Qt.createQmlObject('import QtQuick 1.0; ListModel {}', categoryDialog);
202                  for (var i=0;i<categories.count;i++) {
203                      listModel.append({"name": categories.get(i).title, "catid": categories.get(i).catid });
204                  }
205                  model = listModel
206                  //console.log(listModel.count)
207              }
208
209              function confirmCategory(title, url) {
210                  //categoryDialog.selectedIndex = -1;
211                  createListModel();
212                  feedTitle = title
213                  feedUrl = url
214                  open();
215              }
216
217              function reload() {
218                  //categories.reload()
219                  categories.xml = controller.getCategoryXml()
220              }
221
222              //model: []
223              //model: categories
224
225              XmlListModel {
226                  id: categories
227                  xml: controller.getCategoryXml()
228                  query: "/xml/category"
229                  XmlRole { name: "title"; query: "catname/string()" }
230                  XmlRole { name: "catid"; query: "catid/string()"; isKey: true }
231              }
232
233              onSelectedIndexChanged: {
234                  if (selectedIndex>=0) {
235                      controller.addFeed(feedTitle,feedUrl,categoryDialog.model.get(categoryDialog.selectedIndex).catid);
236                      console.log("Adding feed "+feedTitle+" at " +feedUrl + " in " + categoryDialog.model.get(categoryDialog.selectedIndex).catid);
237                  }
238                  categoryDialog.selectedIndex = -1;
239              }
240     }
241 }