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