9bb29b479c43d23a3c2fc675ef08159b24073ad7
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / qml / ArticleViewer.qml
1 import Qt 4.7
2 import com.nokia.meego 1.0
3
4 Item {
5     id: articleViewer
6     //width: 480; height: 360;
7     width: parent.width; height: parent.height;
8     property string feedid: parent.feedid
9     //property string feedid: "61ac1458d761423344998dc76770e36e" //articlesItem.feedid;
10     //property string hideReadArticles: "";
11     property alias articleShown: articleView.visible;
12     property bool zoomEnabled: false;
13     property bool vertPanningEnabled: true
14
15     function modulo(x,y) {
16         // Fixes modulo for negative numbers
17         return ((x%y)+y)%y;
18     }
19
20     function reload() {
21         articles.xml = articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid);
22         articles.reload()
23     }
24
25     function next() {
26         if (articleView.visible) {
27             //articleView.positionViewAtIndex(modulo(articleView.currentIndex+1, articleView.count), ListView.Contain);
28             articleView.incrementCurrentIndex();
29         }
30     }
31
32     function prev() {
33         if (articleView.visible) {
34             //articleView.positionViewAtIndex(modulo(articleView.currentIndex-1, articleView.count), ListView.Contain);
35             articleView.decrementCurrentIndex();
36         }
37     }
38
39     function markAllAsRead() {
40         if (feedid!="") {
41             controller.markAllAsRead(feedid)
42             articles.reload();
43         }
44     }
45
46     function viewArticle(articleid) {
47         var index = 0;
48         for (var i=0; i<articleList.count; ++i) {
49             if (articles.get(0).articleid==articleid) {
50                 index = i;
51             }
52         }
53         articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true;
54     }
55
56     ListView {
57         id: articleList; /*model: visualModel.parts.list;*/ z: 6
58         model: articles
59         delegate: listing
60         width: parent.width;
61         height: updateBarFeeds.visible? parent.height-updateBarFeeds.height : parent.height;
62         /*x: 0;*/
63         cacheBuffer: 100;
64         flickDeceleration: 1500
65         visible: articles.status==XmlListModel.Ready
66     }
67
68     ListView {
69         id: articleView;
70         model: articles;
71         delegate: viewer
72         orientation: ListView.Horizontal
73         width: parent.width;
74         height: updateBarFeeds.visible? parent.height-updateBarFeeds.height : parent.height;
75         visible: false; z:8
76         //onCurrentIndexChanged: photosGridView.positionViewAtIndex(currentIndex, GridView.Contain)
77         highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
78         //cacheBuffer: 5;
79         onMovementStarted: articleViewer.vertPanningEnabled=false;
80         onMovementEnded: articleViewer.vertPanningEnabled=true;
81         highlightMoveDuration: 300;
82     }
83
84     ProgressBar {
85         id: updateBar
86         minimumValue: 0
87         maximumValue: 100
88         value: window.updateProgressValue
89         visible: window.isUpdateInProgress
90         width: parent.width
91         anchors.bottom: parent.bottom
92     }
93
94     Rectangle {
95         id: noArticle
96         //width: parent.width; height: parent.height;
97         color: "black"
98         opacity: 0.8
99
100         //anchors.centerIn: parent;
101         anchors.fill: parent
102         visible: false;
103         z:8;
104         Text {
105             id: noText; color: "#ffffff"; anchors.centerIn: parent; text: qsTr("No articles available");
106             font.pixelSize: settings.mainTextSize
107         }
108
109         BusyIndicator {
110                      id: loadingIndicator
111                      anchors.centerIn: parent;
112                      running: visible
113                      visible: false
114                      platformStyle: BusyIndicatorStyle { size: "large" }
115         }
116
117         MouseArea {
118             // Disable clicks when this item is visible
119             anchors.fill: parent
120             enabled: parent.visible
121         }
122
123         states: [ State {
124             name: "noArticle"; when: articles.count==0 && articles.status==XmlListModel.Ready
125             PropertyChanges { target: noArticle; visible: true; }
126             PropertyChanges { target: loadingImage; visible: false; }
127             PropertyChanges { target: noText; visible: true; }
128             }, State {
129             name: "loading"; when: articles.status != XmlListModel.Ready
130             PropertyChanges { target: noArticle; visible: true; }
131             PropertyChanges { target: noText; visible: false; }
132             PropertyChanges { target: loadingIndicator; visible: true; }
133             }
134         ]
135     }
136
137     Rectangle {
138         id: reloading
139         visible: articles.status != XmlListModel.Ready
140
141
142     }
143
144     Component {
145             id: listing;
146
147             Item {
148                 width: articleViewer.width; height: backRect.height + 3
149                 id: listItem
150
151                 Rectangle {
152                     id: backRect; color: settings.backColour; opacity: index % 2 ? 0.2 : 0.4;
153                     height: articleText.height + 22; width: listItem.width;
154                     y: 1
155                 }
156                 Text {
157                     id: articleText
158                     anchors.verticalCenter: backRect.verticalCenter
159                     x: 3
160                     width: listItem.width - 6;
161
162                     anchors.margins: 5
163                     verticalAlignment: Text.AlignVCenter;
164                     text: title;
165                     color: (unread=="True") ? settings.mainTextColour : settings.secondaryTextColour;
166
167                      wrapMode: Text.WordWrap; font.bold: false;
168                     font.pixelSize: settings.mainTextSize
169                 }
170                 MouseArea { anchors.fill: listItem;
171                     onClicked: { articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true; }
172                 }
173             }
174
175     }
176
177     Component {
178         id: viewer
179         Item {
180             id: flipItem;
181             width: articleViewer.width; height: articleViewer.height;
182
183             //property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: "";
184             property string html: controller.getArticle(articleViewer.feedid, articleid)
185             ArticleDisplay {
186                 zoomEnabled: articleViewer.zoomEnabled;
187                 property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
188
189                 states: [ State {
190                         name: 'articleIsRead';
191                     when: articleView.visible && articleView.currentIndex == index;
192                     StateChangeScript {
193                         name: "myScript"
194                         script: {
195                             //flipItem.url=path;
196                             controller.setEntryRead(articleViewer.feedid, articleid)
197                         }
198                     }
199                     }
200                 ]
201             }
202         }
203     }
204
205     XmlListModel {
206         id: articles
207
208         //source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
209         xml: articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid)
210         query: "/xml/article"
211
212         XmlRole { name: "title"; query: "title/string()" }
213         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
214         XmlRole { name: "path"; query: "path/string()" }
215         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
216     }
217
218 }