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