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