689217915b77fbd9e9d4e9f3baae61913ef3aa8a
[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-next"
261                     visible: flipper.articleShown
262                     //anchors.right: (parent === undefined) ? undefined : parent.right
263                     onClicked: flipper.next()
264                 }
265
266                 ToolIcon {
267                     platformIconId: "toolbar-view-menu"
268                     anchors.right: (parent === undefined) ? undefined : parent.right
269                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
270                 }
271             }
272             Connections {
273                  target: window
274                  onArticlesReloadRequest: flipper.reload()
275              }
276         }
277     }
278
279     Component {
280         id: addFeedPage
281         AddFeed {
282             id: addFeedItem
283
284             Connections {
285                  target: window
286                  onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
287              }
288         }
289     }
290
291     Component {
292         id: settingsPage
293         SettingsPage {
294             id: settingsItem
295             tools: commonTools
296         }
297     }
298
299     Settings {
300         id: settings
301     }
302
303     Rectangle {
304         id: banner
305         x: 10
306         width: parent.width - 20
307         height: bannerText.height + 20
308         y: 50
309         z:8
310
311         visible: false
312         radius: 4
313         border.color: "white"
314         color: "black"
315
316         Text {
317             id: bannerText
318             anchors.centerIn: parent
319             font.pixelSize: 24
320             //text: "Test"
321             color: "white"
322             wrapMode: Text.WordWrap;
323         }
324
325         Timer {
326             id: bannerTimer
327             interval: 3000
328             repeat: false
329             running: false
330             onTriggered: banner.visible = false
331         }
332
333         function show(str) {
334             bannerText.text = str;
335             banner.visible = true
336             bannerTimer.start()
337         }
338
339         MouseArea {
340             anchors.fill: parent
341             onClicked: {
342                 bannerTimer.stop()
343                 banner.visible= false
344             }
345         }
346
347         //text: "This is an info banner with no icon"
348     }
349
350     Item {
351         AutomaticUpdate {
352             id: autoUpdate
353         }
354
355         Connections {
356             target: settings
357             onAutoUpdateEnabledChanged: {
358                 if (!settings.autoUpdateEnabled) {
359                     autoUpdate.stop();
360                 } else {
361                     autoUpdate.start();
362                 }
363             }
364         }
365     }
366 }