0.9beta
[feedingit] / src / qml / FeedingIt.qml
1 import Qt 4.7
2 import "common" as Common
3 // Depends on qt4-declarative-qmlviewer
4
5 Item {
6     width: 640
7     height: 480
8     id: screen
9
10     Rectangle {
11         id: container
12         anchors.fill: parent; color: "#343434";
13
14         function modulo(x,y) {
15             // Fixes modulo for negative numbers
16             return ((x%y)+y)%y;
17         }
18
19         function categoryClicked(catid) {
20             feedsItem.catid = catid;
21             categoriesItem.isShown = false;
22             feedsItem.visible = true;
23         }
24
25         function feedClicked(feedid) {
26             articlesItem.feedid = feedid;
27             articlesItem.visible = true;
28         }
29
30         function articleClicked(articleid, index) {
31             // Assign the articleId for the current, next and previous article to the associated variables
32             // Note the modulo, so it goes around
33             articleDisplay.articleindex = modulo(index,articlesItem.count)
34             articleDisplay.nextArticle = articlesItem.getArticleid(modulo(index+1,articlesItem.count))
35             articleDisplay.prevArticle = articlesItem.getArticleid(modulo(index-1,articlesItem.count))
36             articleDisplay.articleid = articleid
37             articleDisplay.visible = true;
38         }
39
40         function backClicked() {
41             if (articleDisplay.visible) {
42                 // We're viewing an article, and going back to article listing
43                 articleDisplay.visible = false;
44                 articleDisplay.articleid = "";
45                 articleDisplay.value = 1;
46                 articlesItem.reload()
47                 return;
48             }
49             if (articlesItem.visible) {
50                 // Viewing articles, going back to feeds
51                 //articlesItem.feedid = "";
52                 feedsItem.reload();
53                 articlesItem.visible = false;
54                 //articlesItem.reload();
55                 return;
56             }
57             if (feedsItem.visible) {
58                 // Viewing feeds, going back to categories
59                 //feedsItem.catid = "";
60                 feedsItem.visible = false;
61                 //feedsItem.reload();
62                 categoriesItem.isShown = true;
63                 return;
64             }
65             if (!feedsItem.visible) {
66                 // Viewing categories, quitting
67                 Qt.quit();
68             }
69         }
70
71         Common.Menu {
72             id: config
73             z: 5
74             property string hideReadFeeds : "False"
75             property string hideReadArticles : "False"
76
77             property bool isShown: false;
78
79             //width: parent.width; height: parent.height;
80
81             //height: 0
82             states: State {
83                 name: "shown"; when: config.isShown == true
84                 PropertyChanges { target: config; y: 66 }
85             }
86
87             transitions: Transition {
88                 NumberAnimation { properties: "y"; duration: 300; easing.type: "InOutQuad" }
89             }
90
91         }
92
93         Common.ConfirmationMessage {
94             id: confirmationMessage;
95             visible: false
96             onOkClicked: { var doc = new XMLHttpRequest();
97                 console.log(articlesItem.url+"&markAllAsRead=True")
98                 var url = articlesItem.url+"&markAllAsRead=True"
99                 console.log(url)
100                 doc.open("GET", url);
101                 doc.send();
102                 var xmlDoc=doc.responseXML;
103                 articlesItem.reload();
104                 feedsItem.reload()
105                 visible=false
106             }
107             onCancelClicked: visible=false
108         }
109
110         Common.ToolBar {
111             id: toolBar; z: 7
112             height: 66; anchors.top: parent.top; width: parent.width; opacity: 0.9
113             button1Label: qsTr("Config"); button2Label: qsTr("Back")
114             nextLabel: qsTr("Next"); prevLabel: qsTr("Previous")
115             markAllLabel: qsTr("Mark All As Read"); zoomLabel: qsTr("Zoom")
116             taskSwitcherLabel: qsTr("Task Switch")
117             onButton1Clicked: config.isShown = !config.isShown;
118             onButton2Clicked: container.backClicked()
119             onPrevClicked: container.articleClicked(articleDisplay.prevArticle, articleDisplay.articleindex-1)
120             onNextClicked: container.articleClicked(articleDisplay.nextArticle, articleDisplay.articleindex+1)
121             onMarkAllClicked: {
122                 confirmationMessage.text = qsTr("Do you want to mark all items as read?");
123                 confirmationMessage.visible = true;
124             }
125             onZoomClicked: { articleDisplay.zoomEnabled = !articleDisplay.zoomEnabled; }
126             onTaskSwitcherClicked: {
127                 var doc = new XMLHttpRequest();
128                 var url = "http://localhost:8000/task"
129                 doc.open("GET", url);
130                 doc.send();
131                 //var xmlDoc=doc.responseXML;
132             }
133
134             states: [ State {
135                 name: "navButtons"; when: articleDisplay.articleid != ""
136                 PropertyChanges { target: toolBar; nextVisible: true; }
137                 PropertyChanges { target: toolBar; prevVisible: true; }
138                 PropertyChanges { target: toolBar; zoomVisible: true; }
139             },
140                 State {
141                     name: "feedButtons"; when: (articleDisplay.articleid == "")&&(articlesItem.feedid!="")
142                     PropertyChanges { target: toolBar; markAllVisible: true; }
143                 }
144             ]
145         }
146
147         Item {
148             id: views
149             //x: 2;
150             //y:66;
151             width: parent.width // - 4
152             anchors.top: toolBar.bottom; anchors.bottom: parent.bottom
153
154             Categories {
155                 // Loads the categoryList view and delegate
156                 id: categoriesItem
157                 property bool isShown: true;
158
159                 states: State {
160                     name: "shown"; when: categoriesItem.isShown == false
161                     PropertyChanges { target: categoriesItem; x: -screen.width }
162                 }
163
164                 transitions: Transition {
165                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
166                 }
167
168             }
169
170             Feeds {
171
172                 // Loads the feedList view and delegate
173                 id: feedsItem;
174                 property string hideReadFeeds: config.hideReadFeeds
175                 visible: false;
176
177                 states: [
178                     State { name: "articlesShown"; when: articlesItem.visible; PropertyChanges { target: feedsItem; x: -parent.width } },
179                     State { name: "shown"; when: feedsItem.visible; PropertyChanges { target: feedsItem; x: 0 } }
180                 ]
181
182                 transitions: Transition {
183                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
184                 }
185
186             }
187
188             Articles {
189                 // Loads the articleLost view and delegate
190                 id: articlesItem;
191                 property string hideReadArticles: config.hideReadArticles
192                 visible: false;
193
194                 states: [
195                     State { name: "shown"; when: articleDisplay.visible; PropertyChanges { target: articlesItem; x: -parent.width }
196                     },
197                     State { name: "articleShown"; when: articlesItem.visible; PropertyChanges { target: articlesItem; x: 0 }
198                     }
199                 ]
200
201                 transitions: Transition {
202                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
203                 }
204             }
205
206             ArticleDisplay{
207                 // Loads the WebView
208                 id: articleDisplay;
209                 //anchors.top: toolBar.bottom;
210                 //anchors.bottom: screen.bottom;
211                 height: parent.height;
212                 visible: false;
213                 property string feedid: articlesItem.feedid;
214                 property string articleid: "";
215                 property int articleindex: 0;
216                 property string nextArticle: "";
217                 property string prevArticle: "";
218                 property string url: (articleid == "") ? "" : "http://localhost:8000/html/" + articleDisplay.feedid + "/" + articleDisplay.articleid;
219
220                 gradient: Gradient {
221                     GradientStop {
222                         position: 0.00;
223                         color: "#ffffff";
224                     }
225                     GradientStop {
226                         position: 1.00;
227                         color: "#ffffff";
228                     }
229                 }
230
231                 states: State { name: "shown"; when: articleDisplay.visible; PropertyChanges { target: articleDisplay; x: 0 }
232                     }
233
234                 transitions: Transition {
235                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
236                 }
237         }
238         }
239     }
240 }