psa: using 2 flickables
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / debian / feedingit / usr / share / 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                         window.feedReloadRequest();
250                         pageStack.pop();
251                     }
252                 }
253
254                 ToolIcon {
255                     platformIconId: "toolbar-view-menu"
256                     anchors.right: (parent === undefined) ? undefined : parent.right
257                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
258                 }
259             }
260             Connections {
261                  target: window
262                  onArticlesReloadRequest: flipper.reload()
263              }
264         }
265     }
266
267     Component {
268         id: articleViewPage
269         Page {
270             tools: articleTools
271             property string feedid: window.feedid
272
273
274             Articles {
275                 id: articlePage
276                 property string mainArticleId: window.articleid;
277             }
278
279             ToolBarLayout {
280                 id: articleTools
281                 visible: false
282                 ToolIcon { iconId: "toolbar-back";
283                     onClicked: {
284                         window.articlesReloadRequest();
285                         pageStack.pop();
286                     }
287                 }
288
289                 ToolIcon {
290                     platformIconId: "toolbar-previous"
291                     onClicked: articlePage.prev();
292                 }
293
294                 ToolIcon {
295                     platformIconId: "toolbar-share"
296                     onClicked: {
297                         controller.share(window.feedid, articlePage.mainArticleId);
298                     }
299                 }
300
301                 ToolIcon {
302                     platformIconId: "toolbar-next"
303                     onClicked: articlePage.next()
304                 }
305
306 //                ToolIcon {
307 //                    platformIconId: "toolbar-view-menu"
308 //                    anchors.right: (parent === undefined) ? undefined : parent.right
309 //                    onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
310 //                }
311             }
312 //            Connections {
313 //                 target: window
314 //                 onArticlesReloadRequest: flipper.reload()
315 //             }
316         }
317     }
318
319     Component {
320         id: addFeedPage
321         AddFeed {
322             id: addFeedItem
323
324             Connections {
325                  target: window
326                  onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
327              }
328         }
329     }
330
331     Component {
332         id: settingsPage
333         SettingsPage {
334             id: settingsItem
335             tools: commonTools
336         }
337     }
338
339     Settings {
340         id: settings
341     }
342
343     Rectangle {
344         id: banner
345         x: 10
346         width: parent.width - 20
347         height: bannerText.height + 20
348         y: 50
349         z:8
350
351         visible: false
352         radius: 4
353         border.color: "white"
354         color: "black"
355
356         Text {
357             id: bannerText
358             anchors.centerIn: parent
359             font.pixelSize: 24
360             //text: "Test"
361             color: "white"
362             wrapMode: Text.WordWrap;
363         }
364
365         Timer {
366             id: bannerTimer
367             interval: 3000
368             repeat: false
369             running: false
370             onTriggered: banner.visible = false
371         }
372
373         function show(str) {
374             bannerText.text = str;
375             banner.visible = true
376             bannerTimer.start()
377         }
378
379         MouseArea {
380             anchors.fill: parent
381             onClicked: {
382                 bannerTimer.stop()
383                 banner.visible= false
384             }
385         }
386
387         //text: "This is an info banner with no icon"
388     }
389
390 //    Item {
391 //        AutomaticUpdate {
392 //            id: autoUpdate
393 //        }
394
395 //        Connections {
396 //            target: settings
397 //            onAutoUpdateEnabledChanged: {
398 //                if (!settings.autoUpdateEnabled) {
399 //                    autoUpdate.stop();
400 //                } else {
401 //                    autoUpdate.start();
402 //                }
403 //            }
404 //        }
405 //    }
406 }