973bbdb763979d697c16fa1192165a35fa3a7ab9
[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 addFileSignal(string fullname, string filename)
13
14     property string feedid
15     property string catid
16
17     function addFileNotification(fullname, filename) {
18         window.addFileSignal(fullname,filename)
19     }
20
21     onLongPressFeed: {
22         unsubscribeFeedMenu.key = key
23         unsubscribeFeedMenu.open()
24     }
25
26     onLongPressCategory: {
27         unsubscribeCategoryMenu.catid = catid
28         unsubscribeCategoryMenu.open()
29     }
30
31     ToolBarLayout {
32         id: commonTools
33         visible: false
34         ToolIcon { iconId: "toolbar-back"; onClicked: { myMenu.close(); pageStack.pop(); }
35             visible: pageStack.depth>1 }
36         ToolIcon {
37             platformIconId: "toolbar-view-menu"
38             anchors.right: (parent === undefined) ? undefined : parent.right
39             onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
40         }
41     }
42
43     Menu {
44         id: myMenu
45         visualParent: pageStack
46         MenuLayout {
47             MenuItem { text: qsTr("Settings"); onClicked: {pageStack.push(settingsPage)}  }
48             MenuItem { text: qsTr("Manage Subscriptions"); onClicked: { pageStack.push(addFeedPage)  } }
49             MenuItem { text: qsTr("Update All Categories"); onClicked: controller.updateAll(); }
50             MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
51         }
52     }
53
54     Menu {
55         id: myFeedsMenu
56         visualParent: pageStack
57         MenuLayout {
58             MenuItem { text: qsTr("Update All Feeds"); onClicked: controller.updateCategory(catid); }
59             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
60         }
61     }
62
63     Menu {
64         id: myArticlesMenu
65         visualParent: pageStack
66         MenuLayout {
67             MenuItem { text: qsTr("Mark All As Read"); onClicked: controller.markAllAsRead(feedid); }
68             MenuItem { text: qsTr("Update Feed"); onClicked: controller.updateFeed(feedid); }
69             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
70         }
71     }
72
73     Menu {
74         id: unsubscribeFeedMenu
75         visualParent: pageStack
76         property string key
77         MenuLayout {
78             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
79             MenuItem { text: qsTr("Delete");
80                 onClicked: {
81                     feedConfirm.open()
82                     unsubscribeFeedMenu.close()
83                 }
84             }
85         }
86         QueryDialog {
87             id: feedConfirm
88             //icon: "common/images/feedingit.png"
89             //titleText: "Delete Feed?"
90             message: "Delete this feed?"
91             acceptButtonText: "OK"
92             rejectButtonText: "Cancel"
93             onAccepted: {
94                 controller.removeFeed(unsubscribeFeedMenu.key);
95                 window.feedReloadRequest()
96             }
97         }
98     }
99
100     Menu {
101         id: unsubscribeCategoryMenu
102         visualParent: pageStack
103         property string catid
104         MenuLayout {
105             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
106             MenuItem { text: qsTr("Delete");
107                 onClicked: {
108                     categoryConfirm.open()
109                     unsubscribeFeedMenu.close()
110                 }
111             }
112         }
113         QueryDialog {
114             id: categoryConfirm
115             //icon: "common/images/feedingit.png"
116             //titleText: "Delete Feed?"
117             message: "Delete this category?"
118             acceptButtonText: "OK"
119             rejectButtonText: "Cancel"
120             onAccepted: {
121                 controller.removeCategory(unsubscribeCategoryMenu.catid);
122                 window.categoryReloadRequest()
123             }
124         }
125     }
126
127     QueryDialog {
128         id: query
129         icon: "common/images/feedingit.png"
130         titleText: "Feedingit RSS Reader"
131         message: "Version: 0.0.9"
132         +"<br><br>FeedingIt RSS Reader.<br>"
133         +"<br>&copy; 2011 feedingit.marcoz.org"
134         +"<br>http://feedingit.marcoz.org"
135         acceptButtonText: "OK"
136     }
137
138     Component {
139         id: categoryPage
140         Page {
141             tools: commonTools
142             Categories {
143                 id: categoriesItem
144                 onCategoryClicked: {
145                     window.catid = cat
146                     pageStack.push(feedsPage)
147                 }
148
149             }
150             Connections {
151                 target: window
152                 onCategoryReloadRequest: {
153                     console.log("category reloaded")
154                     categoriesItem.reload()
155                 }
156             }
157         }
158     }
159
160     Component {
161         id: feedsPage
162
163         Page {
164             tools: feedsTools
165             anchors.fill: parent
166             property string catid: window.catid
167             Feeds {
168                 id: feedsItem
169                 onFeedClicked: {
170                     window.feedid = feedid
171                     pageStack.push(articlesPage)
172                 }
173
174             }
175             ToolBarLayout {
176                 id: feedsTools
177                 visible: false
178                 ToolIcon { iconId: "toolbar-back";
179                     onClicked: {
180                         myArticlesMenu.close();
181                         window.categoryReloadRequest()
182                         pageStack.pop();
183                     }
184                 }
185                 ToolIcon {
186                     platformIconId: "toolbar-view-menu"
187                     anchors.right: (parent === undefined) ? undefined : parent.right
188                     onClicked: (myFeedsMenu.status == DialogStatus.Closed) ? myFeedsMenu.open() : myFeedsMenu.close()
189                 }
190             }
191             Connections {
192                  target: window
193                  onFeedReloadRequest: feedsItem.reload()
194              }
195         }
196     }
197
198     Component {
199         id: articlesPage
200         Page {
201             tools: articleTools
202             property string feedid: window.feedid
203             ArticleViewer {
204                 id: flipper
205             }
206
207             ToolBarLayout {
208                 id: articleTools
209                 visible: false
210                 ToolIcon { iconId: "toolbar-back";
211                     onClicked: {
212                         myArticlesMenu.close();
213                         if (flipper.articleShown) {
214                             flipper.articleShown = false;
215                             flipper.reload()
216                         } else {
217                             window.feedReloadRequest();
218                             pageStack.pop();
219                         }
220                     }
221                 }
222
223                 ToolIcon {
224                     platformIconId: "toolbar-previous"
225                     visible: flipper.articleShown
226                     //anchors.right: (parent === undefined) ? undefined : parent.right
227                     onClicked: flipper.prev();
228                 }
229
230                 ToolIcon {
231                     platformIconId: "toolbar-next"
232                     visible: flipper.articleShown
233                     //anchors.right: (parent === undefined) ? undefined : parent.right
234                     onClicked: flipper.next()
235                 }
236
237                 ToolIcon {
238                     platformIconId: "toolbar-view-menu"
239                     anchors.right: (parent === undefined) ? undefined : parent.right
240                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
241                 }
242             }
243         }
244     }
245
246     Component {
247         id: addFeedPage
248         AddFeed {
249             id: addFeedItem
250
251             Connections {
252                  target: window
253                  onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
254              }
255         }
256     }
257
258     Component {
259         id: settingsPage
260         SettingsPage {
261             id: settingsItem
262             tools: commonTools
263         }
264     }
265
266     Settings {
267         id: settings
268     }
269
270     Rectangle {
271         id: banner
272         x: 10
273         width: parent.width - 20
274         height: bannerText.height + 20
275         y: 50
276         z:8
277
278         visible: false
279         radius: 4
280         border.color: "white"
281         color: "black"
282
283         Text {
284             id: bannerText
285             anchors.centerIn: parent
286             font.pixelSize: 24
287             //text: "Test"
288             color: "white"
289             wrapMode: Text.WordWrap;
290         }
291
292         Timer {
293             id: bannerTimer
294             interval: 3000
295             repeat: false
296             running: false
297             onTriggered: banner.visible = false
298         }
299
300         function show(str) {
301             bannerText.text = str;
302             banner.visible = true
303             bannerTimer.start()
304         }
305
306         MouseArea {
307             anchors.fill: parent
308             onClicked: {
309                 bannerTimer.stop()
310                 banner.visible= false
311             }
312         }
313
314         //text: "This is an info banner with no icon"
315     }
316 }