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