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