psa: added article list and display font settings
[feedingit] / psa_harmattan / feedingit / 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 getCurrentArticleId() {
47         var object = articleView.model.get(articleView.currentIndex)
48         return object.articleid
49     }
50
51     ListView {
52         id: articleList; /*model: visualModel.parts.list;*/ z: 6
53         model: articles
54         delegate: listing
55         width: parent.width;
56         height: updateBarArticles.visible? parent.height-updateBarArticles.height : parent.height;
57         /*x: 0;*/
58         cacheBuffer: 100;
59         flickDeceleration: 1500
60         visible: articles.status==XmlListModel.Ready
61         clip: true
62     }
63
64     ListView {
65         id: articleView;
66         property int webviewFontSize: settings.webviewFontSize
67         model: articles;
68         delegate: viewer
69         orientation: ListView.Horizontal
70         width: parent.width;
71         height: updateBarArticles.visible? parent.height-updateBarArticles.height : parent.height;
72         visible: false; z:8
73         onCurrentIndexChanged: articleView.positionViewAtIndex(currentIndex, ListView.Contain)
74         highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
75         //cacheBuffer: 5;
76         onMovementStarted: articleViewer.vertPanningEnabled=false;
77         onMovementEnded: articleViewer.vertPanningEnabled=true;
78         highlightMoveDuration: 300;
79         clip: true
80     }
81
82     ProgressBar {
83         id: updateBarArticles
84         minimumValue: 0
85         maximumValue: 100
86         value: window.updateProgressValue
87         visible: window.isUpdateInProgress
88         width: parent.width
89         anchors.bottom: parent.bottom
90     }
91
92     Rectangle {
93         id: noArticle
94         //width: parent.width; height: parent.height;
95         color: "black"
96         opacity: 0.8
97
98         //anchors.centerIn: parent;
99         anchors.fill: parent
100         visible: false;
101         z:8;
102         Text {
103             id: noText; color: "#ffffff"; anchors.centerIn: parent; text: qsTr("No articles available");
104             font.pixelSize: settings.mainTextSize
105         }
106
107         BusyIndicator {
108                      id: loadingIndicator
109                      anchors.centerIn: parent;
110                      running: visible
111                      visible: false
112                      platformStyle: BusyIndicatorStyle { size: "large" }
113         }
114
115         MouseArea {
116             // Disable clicks when this item is visible
117             anchors.fill: parent
118             enabled: parent.visible
119         }
120
121         states: [ State {
122             name: "noArticle"; when: articles.count==0 && articles.status==XmlListModel.Ready
123             PropertyChanges { target: noArticle; visible: true; }
124             PropertyChanges { target: loadingImage; visible: false; }
125             PropertyChanges { target: noText; visible: true; }
126             }, State {
127             name: "loading"; when: articles.status != XmlListModel.Ready
128             PropertyChanges { target: noArticle; visible: true; }
129             PropertyChanges { target: noText; visible: false; }
130             PropertyChanges { target: loadingIndicator; visible: true; }
131             }
132         ]
133     }
134
135     Rectangle {
136         id: reloading
137         visible: articles.status != XmlListModel.Ready
138
139
140     }
141
142     Component {
143             id: listing;
144
145             Item {
146                 width: articleViewer.width; height: backRect.height + 3
147                 id: listItem
148
149                 Rectangle {
150                     id: backRect; color: settings.backColour; opacity: index % 2 ? 0.2 : 0.4;
151                     height: articleText.height + 22; width: listItem.width;
152                     y: 1
153                 }
154                 Text {
155                     id: articleText
156                     anchors.verticalCenter: backRect.verticalCenter
157                     x: 3
158                     width: listItem.width - 6;
159
160                     anchors.margins: 5
161                     verticalAlignment: Text.AlignVCenter;
162                     text: title;
163                     color: (unread=="True") ? settings.mainTextColour : settings.secondaryTextColour;
164
165                      wrapMode: Text.WordWrap; font.bold: false;
166                     font.pointSize: settings.articleListingTextSize
167                 }
168                 MouseArea { anchors.fill: listItem;
169                     onClicked: { articleView.currentIndex = index; articleView.visible = true; }
170                 }
171             }
172
173     }
174
175     Component {
176         id: viewer
177         Item {
178             id: flipItem;
179             width: articleDisplay.width;
180             height: articleView.height;
181
182             //property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: "";
183             property string html: controller.getArticle(articleViewer.feedid, articleid)
184             ArticleDisplay {
185                 id: 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 }