psa: adding toggle to show/hide specific feed on Event Feed stream
[feedingit] / psa_harmattan / feedingit / qml / main.qml
1 import QtQuick 1.0
2 import com.nokia.meego 1.0
3
4 PageStackWindow {
5     id: window
6     initialPage: categoryPage
7
8     signal longPressCategory(string catid)
9     signal longPressFeed(string key)
10     signal categoryReloadRequest()
11     signal feedReloadRequest()
12     signal articlesReloadRequest()
13     signal addFileSignal(string fullname, string filename)
14
15     property string articleid
16     property string feedid
17     property string catid
18
19     property bool isUpdateInProgress: false
20     property int updateProgressValue: 0
21
22     function addFileNotification(fullname, filename) {
23         window.addFileSignal(fullname,filename)
24     }
25
26     function updateStarted() {
27         banner.show(qsTr("Update Started"))
28         updateProgressValue = 0
29         isUpdateInProgress = true
30     }
31
32     function updateFinished() {
33         categoryReloadRequest()
34         feedReloadRequest()
35         banner.show(qsTr("Updated Completed"))
36         isUpdateInProgress = false
37     }
38
39     function updateProgress(total, completed) {
40         if (total>0) {
41             updateProgressValue = Math.round(100*completed/total);
42         } else {
43             updateProgressValue = 0
44         }
45     }
46
47     onLongPressFeed: {
48         unsubscribeFeedMenu.key = key
49         unsubscribeFeedMenu.open()
50     }
51
52     onLongPressCategory: {
53         unsubscribeCategoryMenu.catid = catid
54         unsubscribeCategoryMenu.open()
55     }
56
57     ToolBarLayout {
58         id: commonTools
59         visible: false
60         ToolIcon { iconId: "toolbar-back"; onClicked: { myMenu.close(); pageStack.pop(); }
61             visible: pageStack.depth>1 }
62         ToolIcon {
63             platformIconId: "toolbar-view-menu"
64             anchors.right: (parent === undefined) ? undefined : parent.right
65             onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
66         }
67     }
68
69     Menu {
70         id: myMenu
71         visualParent: pageStack
72         MenuLayout {
73             MenuItem { text: qsTr("Settings"); onClicked: {pageStack.push(settingsPage)}  }
74             MenuItem { text: qsTr("Manage Subscriptions"); onClicked: { pageStack.push(addFeedPage)  } }
75             MenuItem { text: qsTr("Update All Categories"); onClicked: controller.updateAll(); }
76             MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
77         }
78     }
79
80     Menu {
81         id: myFeedsMenu
82         visualParent: pageStack
83         MenuLayout {
84             MenuItem { text: qsTr("Update All Feeds"); onClicked: controller.updateCategory(catid); }
85             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
86         }
87     }
88
89     Menu {
90         id: myArticlesMenu
91         visualParent: pageStack
92         MenuLayout {
93             MenuItem { text: qsTr("Mark All As Read"); onClicked: {
94                     controller.markAllAsRead(feedid);
95                     articlesReloadRequest()
96                 }
97             }
98             MenuItem { text: qsTr("Update Feed"); onClicked: controller.updateFeed(feedid); }
99             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
100         }
101     }
102
103     Menu {
104         id: unsubscribeFeedMenu
105         visualParent: pageStack
106         property string key
107         MenuLayout {
108             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
109             MenuItem {
110                 text: controller.getFeedEventStatus(key) ? qsTr("Show on Event Feed"): qsTr("Do not show on Event Feed")
111                 onClicked: {
112                     controller.switchEventFeedStatus(key)
113                     text = controller.getFeedEventStatus(key) ? qsTr("Show on Event Feed"): qsTr("Do not show on Event Feed")
114                     unsubscribeFeedMenu.close()
115                 }
116             }
117             MenuItem { text: qsTr("Delete");
118                 onClicked: {
119                     feedConfirm.open()
120                     unsubscribeFeedMenu.close()
121                 }
122             }
123         }
124         QueryDialog {
125             id: feedConfirm
126             //icon: "common/images/feedingit.png"
127             //titleText: "Delete Feed?"
128             message: "Delete this feed?"
129             acceptButtonText: "OK"
130             rejectButtonText: "Cancel"
131             onAccepted: {
132                 controller.removeFeed(unsubscribeFeedMenu.key);
133                 window.feedReloadRequest()
134             }
135         }
136     }
137
138     Menu {
139         id: unsubscribeCategoryMenu
140         visualParent: pageStack
141         property string catid
142         MenuLayout {
143             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
144             MenuItem { text: qsTr("Delete");
145                 onClicked: {
146                     categoryConfirm.open()
147                     unsubscribeFeedMenu.close()
148                 }
149             }
150         }
151         QueryDialog {
152             id: categoryConfirm
153             //icon: "common/images/feedingit.png"
154             //titleText: "Delete Feed?"
155             message: "Delete this category?"
156             acceptButtonText: "OK"
157             rejectButtonText: "Cancel"
158             onAccepted: {
159                 controller.removeCategory(unsubscribeCategoryMenu.catid);
160                 window.categoryReloadRequest()
161             }
162         }
163     }
164
165     QueryDialog {
166         id: query
167         icon: "common/images/feedingit.png"
168         titleText: "Feedingit RSS Reader"
169         message: "Version: n9-0.1.0"
170         +"<br><br>FeedingIt RSS Reader.<br>"
171         +"<br>&copy; 2011 feedingit.marcoz.org"
172         +"<br>http://feedingit.marcoz.org"
173         acceptButtonText: "OK"
174     }
175
176     Component {
177         id: categoryPage
178         Page {
179             tools: commonTools
180             Categories {
181                 id: categoriesItem
182                 onCategoryClicked: {
183                     window.catid = cat
184                     pageStack.push(feedsPage)
185                 }
186
187             }
188             Connections {
189                 target: window
190                 onCategoryReloadRequest: {
191                     console.log("category reloaded")
192                     categoriesItem.reload()
193                 }
194             }
195         }
196     }
197
198     Component {
199         id: feedsPage
200
201         Page {
202             tools: feedsTools
203             anchors.fill: parent
204             property string catid: window.catid
205             Feeds {
206                 id: feedsItem
207                 onFeedClicked: {
208                     window.feedid = feedid
209                     pageStack.push(articlesListPage)
210                 }
211
212             }
213             ToolBarLayout {
214                 id: feedsTools
215                 visible: false
216                 ToolIcon { iconId: "toolbar-back";
217                     onClicked: {
218                         myArticlesMenu.close();
219                         window.categoryReloadRequest()
220                         pageStack.pop();
221                     }
222                 }
223                 ToolIcon {
224                     platformIconId: "toolbar-view-menu"
225                     anchors.right: (parent === undefined) ? undefined : parent.right
226                     onClicked: (myFeedsMenu.status == DialogStatus.Closed) ? myFeedsMenu.open() : myFeedsMenu.close()
227                 }
228             }
229             Connections {
230                  target: window
231                  onFeedReloadRequest: feedsItem.reload()
232              }
233         }
234     }
235
236     Component {
237         id: articlesListPage
238         Page {
239             tools: articleListTools
240             property string feedid: window.feedid
241
242             ArticleViewer {
243                 id: flipper
244
245                 onOpenArticle: {
246                     window.articleid = articleid
247                     pageStack.push(articleViewPage)
248                 }
249             }
250
251             ToolBarLayout {
252                 id: articleListTools
253                 visible: false
254                 ToolIcon { iconId: "toolbar-back";
255                     onClicked: {
256                         myArticlesMenu.close();
257                         window.feedReloadRequest();
258                         pageStack.pop();
259                     }
260                 }
261
262                 ToolIcon {
263                     platformIconId: "toolbar-view-menu"
264                     anchors.right: (parent === undefined) ? undefined : parent.right
265                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
266                 }
267             }
268             Connections {
269                  target: window
270                  onArticlesReloadRequest: flipper.reload()
271              }
272         }
273     }
274
275     Component {
276         id: articleViewPage
277         Page {
278             tools: articleTools
279             property string feedid: window.feedid
280
281
282             Articles {
283                 id: articlePage
284                 property string mainArticleId: window.articleid;
285             }
286
287             ToolBarLayout {
288                 id: articleTools
289                 visible: false
290                 ToolIcon { iconId: "toolbar-back";
291                     onClicked: {
292                         window.articlesReloadRequest();
293                         pageStack.pop();
294                     }
295                 }
296
297                 ToolIcon {
298                     platformIconId: "toolbar-previous"
299                     onClicked: articlePage.prev();
300                 }
301
302                 ToolIcon {
303                     platformIconId: "toolbar-share"
304                     onClicked: {
305                         controller.share(window.feedid, articlePage.mainArticleId);
306                     }
307                 }
308
309                 ToolIcon {
310                     platformIconId: "toolbar-next"
311                     onClicked: articlePage.next()
312                 }
313
314 //                ToolIcon {
315 //                    platformIconId: "toolbar-view-menu"
316 //                    anchors.right: (parent === undefined) ? undefined : parent.right
317 //                    onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
318 //                }
319             }
320 //            Connections {
321 //                 target: window
322 //                 onArticlesReloadRequest: flipper.reload()
323 //             }
324         }
325     }
326
327     Component {
328         id: addFeedPage
329         AddFeed {
330             id: addFeedItem
331
332             Connections {
333                  target: window
334                  onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
335              }
336         }
337     }
338
339     Component {
340         id: settingsPage
341         SettingsPage {
342             id: settingsItem
343             tools: commonTools
344         }
345     }
346
347     Settings {
348         id: settings
349     }
350
351     Rectangle {
352         id: banner
353         x: 10
354         width: parent.width - 20
355         height: bannerText.height + 20
356         y: 50
357         z:8
358
359         visible: false
360         radius: 4
361         border.color: "white"
362         color: "black"
363
364         Text {
365             id: bannerText
366             anchors.centerIn: parent
367             font.pixelSize: 24
368             //text: "Test"
369             color: "white"
370             wrapMode: Text.WordWrap;
371         }
372
373         Timer {
374             id: bannerTimer
375             interval: 3000
376             repeat: false
377             running: false
378             onTriggered: banner.visible = false
379         }
380
381         function show(str) {
382             bannerText.text = str;
383             banner.visible = true
384             bannerTimer.start()
385         }
386
387         MouseArea {
388             anchors.fill: parent
389             onClicked: {
390                 bannerTimer.stop()
391                 banner.visible= false
392             }
393         }
394
395         //text: "This is an info banner with no icon"
396     }
397
398 //    Item {
399 //        AutomaticUpdate {
400 //            id: autoUpdate
401 //        }
402
403 //        Connections {
404 //            target: settings
405 //            onAutoUpdateEnabledChanged: {
406 //                if (!settings.autoUpdateEnabled) {
407 //                    autoUpdate.stop();
408 //                } else {
409 //                    autoUpdate.start();
410 //                }
411 //            }
412 //        }
413 //    }
414 }