6b25fd94e33c9851b7a41af03dea63878daf6fed
[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
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                 }
85             }
86
87         } //searchTab
88
89         ToolBarLayout {
90             id: tabTools
91             ToolIcon {
92                 iconId: "toolbar-back"
93                 onClicked: tabGroup.currentTab.depth > 1 ? tabGroup.currentTab.pop() : pageStack.pop()
94             }
95             ButtonRow {
96                 TabButton {
97                     text: "Search"
98                     tab: searchTab
99                 }
100                 TabButton {
101                     text: "URL"
102                     tab: urlTab
103                 }
104             }
105         }
106     }
107
108     SelectionDialog {
109              id: categoryDialog
110              titleText: "Select category:"
111              property string feedTitle
112              property string feedUrl
113
114              //property variant listModel: ListModel {}
115
116              function createListModel() {
117                  var listModel = Qt.createQmlObject('import QtQuick 1.0; ListModel {}', categoryDialog);
118                  for (var i=0;i<categories.count;i++) {
119                      listModel.append({"name": categories.get(i).title, "catid": categories.get(i).catid });
120                  }
121                  model = listModel
122                  //console.log(listModel.count)
123              }
124
125              function confirmCategory(title, url) {
126                  //categoryDialog.selectedIndex = -1;
127                  createListModel();
128                  feedTitle = title
129                  feedUrl = url
130                  open();
131              }
132
133              //model: []
134              //model: categories
135
136              XmlListModel {
137                  id: categories
138                  xml: controller.getCategoryXml()
139                  query: "/xml/category"
140                  XmlRole { name: "title"; query: "catname/string()" }
141                  XmlRole { name: "catid"; query: "catid/string()"; isKey: true }
142              }
143
144              onSelectedIndexChanged: {
145                  if (selectedIndex>=0) {
146                      controller.addFeed(feedTitle,feedUrl,categoryDialog.model.get(categoryDialog.selectedIndex).catid);
147                      console.log("Adding feed "+feedTitle+" at " +feedUrl + " in " + categoryDialog.model.get(categoryDialog.selectedIndex).catid);
148                  }
149                  categoryDialog.selectedIndex = -1;
150              }
151     }
152 }