59e82764db5831fea533bb83b130669a5701926c
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / 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         console.log("Total: "+total)
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: 0.0.9"
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(articlesPage)
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: articlesPage
230         Page {
231             tools: articleTools
232             property string feedid: window.feedid
233             ArticleViewer {
234                 id: flipper
235             }
236
237             ToolBarLayout {
238                 id: articleTools
239                 visible: false
240                 ToolIcon { iconId: "toolbar-back";
241                     onClicked: {
242                         myArticlesMenu.close();
243                         if (flipper.articleShown) {
244                             flipper.reload()
245                             flipper.articleShown = false;
246                         } else {
247                             window.feedReloadRequest();
248                             pageStack.pop();
249                         }
250                     }
251                 }
252
253                 ToolIcon {
254                     platformIconId: "toolbar-previous"
255                     visible: flipper.articleShown
256                     //anchors.right: (parent === undefined) ? undefined : parent.right
257                     onClicked: flipper.prev();
258                 }
259
260                 ToolIcon {
261                     platformIconId: "toolbar-next"
262                     visible: flipper.articleShown
263                     //anchors.right: (parent === undefined) ? undefined : parent.right
264                     onClicked: flipper.next()
265                 }
266
267                 ToolIcon {
268                     platformIconId: "toolbar-view-menu"
269                     anchors.right: (parent === undefined) ? undefined : parent.right
270                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
271                 }
272             }
273             Connections {
274                  target: window
275                  onArticlesReloadRequest: flipper.reload()
276              }
277         }
278     }
279
280     Component {
281         id: addFeedPage
282         AddFeed {
283             id: addFeedItem
284
285             Connections {
286                  target: window
287                  onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
288              }
289         }
290     }
291
292     Component {
293         id: settingsPage
294         SettingsPage {
295             id: settingsItem
296             tools: commonTools
297         }
298     }
299
300     Settings {
301         id: settings
302     }
303
304     Rectangle {
305         id: banner
306         x: 10
307         width: parent.width - 20
308         height: bannerText.height + 20
309         y: 50
310         z:8
311
312         visible: false
313         radius: 4
314         border.color: "white"
315         color: "black"
316
317         Text {
318             id: bannerText
319             anchors.centerIn: parent
320             font.pixelSize: 24
321             //text: "Test"
322             color: "white"
323             wrapMode: Text.WordWrap;
324         }
325
326         Timer {
327             id: bannerTimer
328             interval: 3000
329             repeat: false
330             running: false
331             onTriggered: banner.visible = false
332         }
333
334         function show(str) {
335             bannerText.text = str;
336             banner.visible = true
337             bannerTimer.start()
338         }
339
340         MouseArea {
341             anchors.fill: parent
342             onClicked: {
343                 bannerTimer.stop()
344                 banner.visible= false
345             }
346         }
347
348         //text: "This is an info banner with no icon"
349     }
350
351     Item {
352         AutomaticUpdate {
353             id: autoUpdate
354         }
355
356         Connections {
357             target: settings
358             onAutoUpdateEnabledChanged: {
359                 if (!settings.autoUpdateEnabled) {
360                     autoUpdate.stop();
361                 } else {
362                     autoUpdate.start();
363                 }
364             }
365         }
366     }
367 }