psa: fix typo
[feedingit] / src / qml / ArticleViewer.qml
1 import Qt 4.7
2
3 Item {
4     id: articleViewer
5     //width: 480; height: 360;
6     width: parent.width; height: parent.height;
7     //property string feedid: "61ac1458d761423344998dc76770e36e" //articlesItem.feedid;
8     //property string hideReadArticles: "";
9     property alias articleShown: articleView.visible;
10     property bool zoomEnabled: false;
11     property bool vertPanningEnabled: true
12
13     function modulo(x,y) {
14         // Fixes modulo for negative numbers
15         return ((x%y)+y)%y;
16     }
17
18     function reload() {
19         articles.reload()
20     }
21
22     function next() {
23         if (articleView.visible) {
24             //articleView.positionViewAtIndex(modulo(articleView.currentIndex+1, articleView.count), ListView.Contain);
25             articleView.incrementCurrentIndex();
26         }
27     }
28
29     function prev() {
30         if (articleView.visible) {
31             //articleView.positionViewAtIndex(modulo(articleView.currentIndex-1, articleView.count), ListView.Contain);
32             articleView.decrementCurrentIndex();
33         }
34     }
35
36     function markAllAsRead() {
37         if (feedid!="") {
38             var doc = new XMLHttpRequest();
39             //console.log(articlesItem.url+"&markAllAsRead=True")
40             var url = "http://localhost:8000/articles/" + feedid + "?markAllAsRead=True"
41             console.log(url)
42             doc.open("GET", url);
43             doc.send();
44             articles.reload();
45         }
46     }
47
48     function viewArticle(articleid) {
49         var index = 0;
50         for (var i=0; i<articleList.count; ++i) {
51             if (articles.get(0).articleid==articleid) {
52                 index = i;
53             }
54         }
55         articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true;
56     }
57
58     ListView {
59         id: articleList; model: visualModel.parts.list; z: 6
60         width: parent.width; height: parent.height; /*x: 0;*/
61         cacheBuffer: 100;
62         flickDeceleration: 1500
63     }
64
65     ListView {
66         id: articleView; model: visualModel.parts.flip; orientation: ListView.Horizontal
67         width: parent.width; height: parent.height; visible: false; z:8
68         //onCurrentIndexChanged: photosGridView.positionViewAtIndex(currentIndex, GridView.Contain)
69         highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
70         //cacheBuffer: 5;
71         onMovementStarted: articleViewer.vertPanningEnabled=false;
72         onMovementEnded: articleViewer.vertPanningEnabled=true;
73         highlightMoveDuration: 300;
74     }
75
76     Rectangle {
77         id: noArticle
78         //width: parent.width; height: parent.height;
79         //color: "#000000"
80         anchors.centerIn: parent;
81         visible: false;
82         z:8;
83         Text { id: noText; color: "#ffffff"; anchors.centerIn: parent; text: qsTr("No articles available"); }
84         Image { id: loadingImage; anchors.centerIn: parent; source: "common/images/loading.png";
85             height: 96; width: 96;
86             NumberAnimation on rotation {
87                 from: 0; to: 360; running: (loadingImage.visible == true); loops: Animation.Infinite; duration: 900
88             }
89         }
90
91         states: [ State {
92             name: "noArticle"; when: articles.count==0 && articles.status==XmlListModel.Ready
93             PropertyChanges { target: noArticle; visible: true; }
94             PropertyChanges { target: loadingImage; visible: false; }
95             PropertyChanges { target: noText; visible: true; }
96             }, State {
97             name: "loading"; when: articles.count==0 && articles.status != XmlListModel.Ready
98             PropertyChanges { target: noArticle; visible: true; }
99             PropertyChanges { target: noText; visible: false; }
100             PropertyChanges { target: loadingImage; visible: true; }
101             }
102         ]
103     }
104
105     VisualDataModel {
106         id: visualModel;
107         delegate: Package {
108                         id: packageItem
109                         Item { id: flipItem; Package.name: 'flip';  width: articleViewer.width; height: articleViewer.height;
110
111                             property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: ""; //http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid : "";
112                             ArticleDisplay {
113                                 zoomEnabled: articleViewer.zoomEnabled;
114                                 property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
115
116                                 states: [ State {
117                                         name: 'articleIsRead';
118                                     when: articleView.visible && articleView.currentIndex == index;
119                                     StateChangeScript {
120                                         name: "myScript"
121                                         script: {
122                                             flipItem.url=path; //"http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid;
123                                             var doc = new XMLHttpRequest();
124                                             var url = "http://localhost:8000/read/" + articleViewer.feedid + "/" + articleid;
125                                             //console.log(url)
126                                             doc.open("GET", url);
127                                             doc.send();
128                                             //var xmlDoc=doc.responseXML;
129                                         }
130                                     }
131                                     }, State {
132                                         name: 'articleIsClose'; when: articleView.visible && Math.abs(articleView.currentIndex-index)<2;
133                                         StateChangeScript {
134                                             script: { flipItem.url=path; } //"http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid;}
135                                         }
136                                     }
137                                 ]
138                             }
139                         }
140
141                         Item { Package.name: 'list';
142                                 id: wrapper; width: articleViewer.width; height: 86
143                                 Item {
144                                     id: moveMe
145                                     Rectangle { id: backRect; color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: 84; width: wrapper.width; y: 1 }
146                                     Text {
147                                         anchors.fill: backRect
148                                         anchors.margins: 5
149                                         verticalAlignment: Text.AlignVCenter; text: title; color: (unread=="True") ? "white" : "#7b97fd";
150                                         width: wrapper.width; wrapMode: Text.WordWrap; font.bold: false;
151                                     }
152                                 }
153                                 MouseArea { anchors.fill: wrapper;
154                                     onClicked: { articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true; }
155                                 }
156                         }
157                     }
158         model: articles
159     }
160
161     XmlListModel {
162         id: articles
163
164         source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
165         query: "/xml/article"
166
167         XmlRole { name: "title"; query: "title/string()" }
168         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
169         XmlRole { name: "path"; query: "path/string()" }
170         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
171     }
172
173
174 }