Adding wip version for meego harmattan
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / debian / feedingit / usr / share / feedingit / qml / FeedingIt.qml
1 import Qt 4.7
2 import "common" as Common
3 // Depends on qt4-declarative-qmlviewer
4
5 Item {
6     width: 480
7     height: 640
8     anchors.fill: parent
9     id: screen
10
11     Rectangle {
12         id: container
13         anchors.fill: parent; color: "#343434";
14         anchors.centerIn: parent
15         //transformOrigin: Item.Center
16         property bool editMode: false
17         property bool inPortrait: width < height
18
19         function categoryClicked(catid) {
20             feedsItem.catid = catid;
21             feedsItem.reload();
22             categoriesItem.isShown = false;
23             feedsItem.visible = true;
24         }
25
26         function feedClicked(feedid, updating) {
27             flipper.feedid = feedid;
28             flipper.reload();
29             toolBar.feedUpdating = updating;
30             flipper.visible = true;
31         }
32
33         function backClicked() {
34             if (flipper.visible && flipper.articleShown) {
35                 // We're viewing an article, and going back to article listing
36                 flipper.articleShown = false;
37                 flipper.reload()
38                 //flipper.articleid = "";
39                 //flipper.value = 1;
40                 //articlesItem.reload()
41                 return;
42             }
43             if (flipper.visible) {
44                 feedsItem.reload();
45                 toolBar.feedUpdating = false;
46                 flipper.visible = false;
47                 flipper.feedid = "";
48                 flipper.reload();
49                 return;
50             }
51
52             if (feedsItem.visible) {
53                 // Viewing feeds, going back to categories
54                 //feedsItem.catid = "";
55                 feedsItem.visible = false;
56                 //feedsItem.reload();
57                 categoriesItem.isShown = true;
58                 return;
59             }
60             if (!feedsItem.visible) {
61                 // Viewing categories, quitting
62                 Qt.quit();
63             }
64         }
65
66         function categoryDeleted(catid) {
67             confirmationMessage.catid=catid;
68             confirmationMessage.state="deleteCat";
69         }
70
71         function feedDeleted(catid, feedid) {
72             confirmationMessage.catid=catid;
73             confirmationMessage.feedid=feedid;
74             confirmationMessage.state="deleteFeed";
75         }
76
77         function feedEdit(feedname, feedid, url) {
78             addFeed.feedEdit = true;
79             addFeed.feedName = feedname;
80             addFeed.feedUrl = url;
81             addFeed.visible = true;
82         }
83
84         function addCategory(categoryName) {
85                 controller.addCategory(categoryName)
86             categoriesItem.reload();
87             addCat.visible=false;
88         }
89
90         function addFeed(catid, feedName, feedURL) {
91                 controller.addFeed(feedName, feedURL, catid)
92             var doc = new XMLHttpRequest();
93             feedsItem.reload();
94             addFeedDialog.visible=false;
95         }
96
97         function updateClicked(feedid) {
98             controller.updateFeed(feedid);
99         }
100
101         function updateAllClicked() {
102             controller.updateAll();
103         }
104
105         Common.Menu {
106             id: config
107             z: 5
108             property string hideReadFeeds : "False"
109             property string hideReadArticles : "False"
110
111             property bool isShown: false;
112
113             //width: parent.width; height: parent.height;
114
115             //height: 0
116             states: State {
117                 name: "shown"; when: config.isShown == true
118                 PropertyChanges { target: config; y: 66 }
119             }
120
121             transitions: Transition {
122                 NumberAnimation { properties: "y"; duration: 300; easing.type: "InOutQuad" }
123             }
124
125         }
126
127         Common.ConfirmationMessage {
128             id: confirmationMessage;
129             property string catid: "";
130             property string feedid: "";
131
132             function action() {
133                 if (state=="markAll") {
134                     flipper.markAllAsRead();
135                     state="hidden"
136                     feedsItem.reload()
137                     return;
138                 }
139                 if (state=="deleteCat") {
140                     var doc = new XMLHttpRequest();
141                     var url = "http://localhost:8000/deleteCat/"+catid
142                     doc.open("GET", url);
143                     doc.send();
144                     categoriesItem.reload();
145                     state="hidden";
146                     return;
147                 }
148                 if (state=="deleteFeed") {
149                     var doc = new XMLHttpRequest();
150                     var url = "http://localhost:8000/deleteFeed/"+catid+"/"+feedid
151                     doc.open("GET", url);
152                     doc.send();
153                     feedsItem.reload();
154                     state="hidden";
155                     return;
156                 }
157             }
158             visible: false
159             onOkClicked: action()
160             onCancelClicked: visible=false
161             state: "hidden"
162             states: [ State {name: "markAll";
163                     PropertyChanges { target: confirmationMessage; text: qsTr("Do you want to mark all items as read?") }
164                     PropertyChanges { target: confirmationMessage; visible: true; }
165
166                 }, State {name: "deleteCat";
167                     PropertyChanges { target: confirmationMessage; text: qsTr("Do you want to delete this category?") }
168                     PropertyChanges { target: confirmationMessage; visible: true; }
169                 }, State {name: "deleteFeed";
170                     PropertyChanges { target: confirmationMessage; text: qsTr("Do you want to delete this feed and all its articles?") }
171                     PropertyChanges { target: confirmationMessage; visible: true; }
172                 }, State {name: "hidden";
173                     PropertyChanges { target: confirmationMessage; visible: false; }
174                 }
175             ]
176
177         }
178
179         Common.ToolBar {
180             id: toolBar; z: 7
181             height: 66; anchors.top: parent.top; width: parent.width; opacity: 0.9
182             menuLabel: qsTr("Config"); backLabel: qsTr("Back")
183             nextLabel: qsTr("Next"); prevLabel: qsTr("Previous")
184             markAllLabel: qsTr("Mark All As Read"); zoomLabel: qsTr("Zoom")
185             taskSwitcherLabel: qsTr("Task Switch")
186             onMenuClicked: config.isShown = !config.isShown;
187             onBackClicked: container.backClicked()
188             onPrevClicked: flipper.prev();
189             onNextClicked: flipper.next();
190             onMarkAllClicked: {
191                 confirmationMessage.state = "markAll";
192             }
193             onZoomClicked: { flipper.zoomEnabled = !flipper.zoomEnabled; }
194             onTaskSwitcherClicked: {
195                 var doc = new XMLHttpRequest();
196                 var url = "http://localhost:8000/task"
197                 doc.open("GET", url);
198                 doc.send();
199             }
200             onAddClicked: {
201                 if (feedsItem.visible) {
202                     addFeedDialog.feedName="";
203                     addFeedDialog.catid = feedsItem.catid;
204                     addFeedDialog.visible = true;
205                     return;
206                 }
207                 if (categoriesItem.visible) {
208                     addCat.catName="";
209                     addCat.visible=true;
210                     return;
211                 }
212             }
213             onUpdateClicked: {
214                 if (flipper.visible) {
215                     toolBar.feedUpdating = true
216                     container.updateClicked(flipper.feedid);
217                 } else {
218                     container.updateAllClicked();
219                 }
220             }
221
222             states: [ State {
223                 name: "navButtons"; when: flipper.articleShown
224                 PropertyChanges { target: toolBar; nextVisible: !container.inPortrait; }
225                 PropertyChanges { target: toolBar; prevVisible: !container.inPortrait; }
226                 //PropertyChanges { target: toolBar; zoomVisible: true; }
227                 PropertyChanges { target: toolBar; addVisible: false; }
228             },
229                 State {
230                     name: "feedButtons"; when: (flipper.visible)&&(!flipper.articleShown)
231                     PropertyChanges { target: toolBar; markAllVisible: true; }
232                     PropertyChanges { target: toolBar; addVisible: false; }
233                     PropertyChanges { target: toolBar; updateVisible: true; }
234                 },
235                 State {
236                     name: "quitButton"; when: (!feedsItem.visible)
237                     PropertyChanges { target: toolBar; quitVisible: true;}
238                     PropertyChanges { target: toolBar; updateVisible: true; }
239                     //PropertyChanges { target: toolBar; addVisible: true; }
240                 }
241             ]
242         }
243
244         Item {
245             id: views
246             //x: 2;
247             //y:66;
248             width: parent.width // - 4
249             height: parent.height-toolBar.height;
250             anchors.top: toolBar.bottom; anchors.bottom: parent.bottom
251             y: toolBar.height;
252
253             Common.AddCat {
254                 visible: false;
255                 id: addCat
256                 width: parent.width;
257                 height: parent.height;
258                 z: 10;
259             }
260
261             Common.AddFeed {
262                 visible: false;
263                 id: addFeedDialog
264                 width: parent.width;
265                 height: parent.height;
266                 z: 10;
267             }
268
269             Timer {
270                 function checkUpdates() {
271                         if (categoriesItem.visible && !feedsItem.visible) {
272                             var doc = new XMLHttpRequest();
273                             var url = "http://localhost:8000/isUpdating/"
274                             doc.onreadystatechange = function() {
275                                 if (doc.readyState == XMLHttpRequest.DONE) {
276                                     var xmlDoc = doc.responseXML.documentElement;
277                                     //var els = xmlDoc.getElementsByTagName("updating");
278                                     var isUpdating = xmlDoc.firstChild.firstChild.nodeValue;
279
280                                     //console.log(isUpdating);
281                                     if (isUpdating=="True") {
282                                             toolBar.feedUpdating = true;
283                                     } else {
284                                         if (toolBar.feedUpdating) {
285                                             // We changed from updating to not updating, so we reload the listing
286                                             toolBar.feedUpdating = false;
287                                             categoriesItem.reload();
288                                         }
289                                     }
290                                     var commands = xmlDoc.lastChild.childNodes;
291                                     for (var ii = 0; ii < commands.length; ++ii) {
292                                         // process the commands
293                                         var command = commands[ii].attributes[0].value; //("c")
294                                         //console.log(command)
295                                         if (command=="openFeed") {
296                                             // Open feed feed
297                                             var catid = commands[ii].attributes[1].value;
298                                             var feedid = commands[ii].firstChild.nodeValue;
299                                             if (!flipper.visible) {
300                                                 container.categoryClicked(catid);
301                                                 container.feedClicked(feedid,false);
302                                                 console.log("feedid: " + feedid);
303                                             }
304                                         }
305                                         if (command=="openArticle") {
306                                             // Open feed and article
307                                             var catid = commands[ii].attributes[1].value;
308                                             var feedid = commands[ii].attributes[2].value; //("key");
309                                             var articleid = commands[ii].firstChild.nodeValue;
310                                             if (!flipper.visible) {
311                                                 container.categoryClicked(catid);
312                                                 container.feedClicked(feedid,false);
313                                                 flipper.viewArticle(articleid)
314                                             }
315                                         }
316                                         if (command=="addFeed") {
317                                             // Open the addFeed dialog
318                                             var url = commands[ii].firstChild.nodeValue;
319                                             //console.log("add: "+url)
320
321                                         }
322                                     }
323
324                                 }
325                             }
326                             doc.open("GET", url);
327                             doc.send();
328                             //categoriesItem.reload()
329                         }
330                         if (feedsItem.visible && !flipper.visible) {
331                             //feedsItem.reload()
332                         }
333                         if (flipper.visible) {
334                             var doc = new XMLHttpRequest();
335                             var url = "http://localhost:8000/isUpdating/" + flipper.feedid
336                             doc.onreadystatechange = function() {
337                                 if (doc.readyState == XMLHttpRequest.DONE) {
338                                     var xmlDoc = doc.responseXML.documentElement;
339                                     var isUpdating = xmlDoc.firstChild.firstChild.nodeValue;
340                                     //console.log(isUpdating);
341                                     if (isUpdating=="True") {
342                                             toolBar.feedUpdating = true;
343                                     } else {
344                                         if (toolBar.feedUpdating) {
345                                             // We changed from updating to not updating, so we reload the listing
346                                             toolBar.feedUpdating = false;
347                                             flipper.reload();
348                                         }
349                                     }
350                                 }
351                             }
352                             doc.open("GET", url);
353                             doc.send();
354
355                             //flipper.reload()
356                         }
357                     }
358                 interval: 2000; running: false; repeat: true
359                 onTriggered: checkUpdates();
360             }
361
362             Categories {
363                 // Loads the categoryList view and delegate
364                 id: categoriesItem
365                 property bool isShown: true;
366                 inEditMode: container.editMode;
367
368                 states: State {
369                     name: "shown"; when: categoriesItem.isShown == false
370                     PropertyChanges { target: categoriesItem; x: -screen.width }
371                 }
372
373                 transitions: Transition {
374                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
375                 }
376
377             }
378
379             Feeds {
380
381                 // Loads the feedList view and delegate
382                 id: feedsItem;
383                 property string hideReadFeeds: config.hideReadFeeds
384                 visible: false;
385                 inEditMode: container.editMode;
386
387                 states: [
388                     State { name: "articlesShown"; when: flipper.visible; PropertyChanges { target: feedsItem; x: -parent.width } },
389                     State { name: "shown"; when: feedsItem.visible; PropertyChanges { target: feedsItem; x: 0 } }
390                 ]
391
392                 transitions: Transition {
393                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
394                 }
395
396             }
397
398             ArticleViewer {
399                 id: flipper
400                 visible: false;
401                 property string hideReadArticles: config.hideReadArticles
402                 property string feedid: ""
403                 x: parent.width
404
405                 states: State { name: "shown"; when: flipper.visible; PropertyChanges { target: flipper; x: 0 }
406                     }
407
408                 transitions: Transition {
409                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
410                 }
411             }
412         }
413
414 //        Text {
415 //            x: container.width/2
416 //            y:container.height/2
417 //            text: runtime.orientation;
418 //        }
419
420 }
421 }