68edc8cc19c65ca33e980a11556cd07a4a273b40
[feedingit] / psa_harmattan / feedingit / qml / main.qml
1 import QtQuick 1.0
2 import com.nokia.meego 1.0
3 import com.nokia.extras 1.0
4
5 PageStackWindow {
6     id: window
7     initialPage: categoryPage
8
9     signal longPressCategory(string catid)
10     signal longPressFeed(string key)
11     signal categoryReloadRequest()
12     signal feedReloadRequest()
13     property string feedid
14     property string catid
15
16     Component.onCompleted: theme.inverted= true
17
18     onLongPressFeed: {
19         unsubscribeFeedMenu.key = key
20         unsubscribeFeedMenu.open()
21     }
22
23     onLongPressCategory: {
24         unsubscribeCategoryMenu.catid = catid
25         unsubscribeCategoryMenu.open()
26     }
27
28     ToolBarLayout {
29         id: commonTools
30         visible: false
31         ToolIcon { iconId: "toolbar-back"; onClicked: { myMenu.close(); pageStack.pop(); }
32             visible: pageStack.depth>1 }
33         ToolIcon {
34             platformIconId: "toolbar-view-menu"
35             anchors.right: (parent === undefined) ? undefined : parent.right
36             onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
37         }
38     }
39
40     Menu {
41         id: myMenu
42         visualParent: pageStack
43         MenuLayout {
44             MenuItem { text: qsTr("Settings"); onClicked: {}  }
45             MenuItem { text: qsTr("Export Feeds"); onClicked: { var file=controller.exportOpml(); banner.text=qsTr("Feeds exported as "+file); banner.open() }  }
46             MenuItem { text: qsTr("Invert Theme"); onClicked: { theme.inverted = !theme.inverted }  }
47             MenuItem { text: qsTr("Add Feeds"); onClicked: { pageStack.push(addFeedPage)  } }
48             MenuItem { text: qsTr("Update All Categories"); onClicked: controller.updateAll(); }
49             MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
50         }
51     }
52
53     Menu {
54         id: myFeedsMenu
55         visualParent: pageStack
56         MenuLayout {
57             MenuItem { text: qsTr("Update All Feeds"); onClicked: controller.updateCategory(catid); }
58             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
59         }
60     }
61
62     Menu {
63         id: myArticlesMenu
64         visualParent: pageStack
65         MenuLayout {
66             MenuItem { text: qsTr("Mark All As Read"); onClicked: controller.markAllAsRead(feedid); }
67             MenuItem { text: qsTr("Update Feed"); onClicked: controller.updateFeed(feedid); }
68             //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
69         }
70     }
71
72     Menu {
73         id: unsubscribeFeedMenu
74         visualParent: pageStack
75         property string key
76         MenuLayout {
77             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
78             MenuItem { text: qsTr("Delete");
79                 onClicked: {
80                     feedConfirm.open()
81                     unsubscribeFeedMenu.close()
82                 }
83             }
84         }
85         QueryDialog {
86             id: feedConfirm
87             //icon: "common/images/feedingit.png"
88             //titleText: "Delete Feed?"
89             message: "Delete this feed?"
90             acceptButtonText: "OK"
91             rejectButtonText: "Cancel"
92             onAccepted: {
93                 controller.removeFeed(unsubscribeFeedMenu.key);
94                 window.feedReloadRequest()
95             }
96         }
97     }
98
99     Menu {
100         id: unsubscribeCategoryMenu
101         visualParent: pageStack
102         property string catid
103         MenuLayout {
104             //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
105             MenuItem { text: qsTr("Delete");
106                 onClicked: {
107                     categoryConfirm.open()
108                     unsubscribeFeedMenu.close()
109                 }
110             }
111         }
112         QueryDialog {
113             id: categoryConfirm
114             //icon: "common/images/feedingit.png"
115             //titleText: "Delete Feed?"
116             message: "Delete this category?"
117             acceptButtonText: "OK"
118             rejectButtonText: "Cancel"
119             onAccepted: {
120                 controller.removeCategory(unsubscribeCategoryMenu.catid);
121                 window.categoryReloadRequest()
122             }
123         }
124     }
125
126     QueryDialog {
127         id: query
128         icon: "common/images/feedingit.png"
129         titleText: "Feedingit RSS Reader"
130         message: "Version: 0.0.9"
131         +"<br><br>FeedingIt RSS Reader.<br>"
132         +"<br>&copy; 2011 feedingit.marcoz.org"
133         +"<br>http://feedingit.marcoz.org"
134         acceptButtonText: "OK"
135     }
136
137     Component {
138         id: categoryPage
139         Page {
140             tools: commonTools
141             Categories {
142                 id: categoriesItem
143                 onCategoryClicked: {
144                     window.catid = cat
145                     pageStack.push(feedsPage)
146                 }
147
148             }
149             Connections {
150                 target: window
151                 onCategoryReloadRequest: {
152                     console.log("category reloaded")
153                     categoriesItem.reload()
154                 }
155             }
156         }
157     }
158
159     Component {
160         id: feedsPage
161
162         Page {
163             tools: feedsTools
164             anchors.fill: parent
165             property string catid: window.catid
166             Feeds {
167                 id: feedsItem
168                 onFeedClicked: {
169                     window.feedid = feedid
170                     pageStack.push(articlesPage)
171                 }
172
173             }
174             ToolBarLayout {
175                 id: feedsTools
176                 visible: false
177                 ToolIcon { iconId: "toolbar-back";
178                     onClicked: {
179                         myArticlesMenu.close();
180                         window.categoryReloadRequest()
181                         pageStack.pop();
182                     }
183                 }
184                 ToolIcon {
185                     platformIconId: "toolbar-view-menu"
186                     anchors.right: (parent === undefined) ? undefined : parent.right
187                     onClicked: (myFeedsMenu.status == DialogStatus.Closed) ? myFeedsMenu.open() : myFeedsMenu.close()
188                 }
189             }
190             Connections {
191                  target: window
192                  onFeedReloadRequest: feedsItem.reload()
193              }
194         }
195     }
196
197     Component {
198         id: articlesPage
199         Page {
200             tools: articleTools
201             property string feedid: window.feedid
202             ArticleViewer {
203                 id: flipper
204             }
205
206             ToolBarLayout {
207                 id: articleTools
208                 visible: false
209                 ToolIcon { iconId: "toolbar-back";
210                     onClicked: {
211                         myArticlesMenu.close();
212                         if (flipper.articleShown) {
213                             flipper.articleShown = false;
214                             flipper.reload()
215                         } else {
216                             window.feedReloadRequest();
217                             pageStack.pop();
218                         }
219                     }
220                 }
221
222                 ToolIcon {
223                     platformIconId: "toolbar-previous"
224                     visible: flipper.articleShown
225                     //anchors.right: (parent === undefined) ? undefined : parent.right
226                     onClicked: flipper.prev();
227                 }
228
229                 ToolIcon {
230                     platformIconId: "toolbar-next"
231                     visible: flipper.articleShown
232                     //anchors.right: (parent === undefined) ? undefined : parent.right
233                     onClicked: flipper.next()
234                 }
235
236                 ToolIcon {
237                     platformIconId: "toolbar-view-menu"
238                     anchors.right: (parent === undefined) ? undefined : parent.right
239                     onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
240                 }
241             }
242         }
243     }
244
245     Component {
246         id: addFeedPage
247         AddFeed {}
248     }
249
250     Settings {
251         id: settings
252     }
253
254     InfoBanner {
255         id: banner
256         //text: "This is an info banner with no icon"
257     }
258 }