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