1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
license GPL v3 ...........
description of this file:
a page for viewing a user selected RSS feed ;
*/
import QtQuick 2.3
import QtQuick.XmlListModel 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Popups 1.0
import "./dateutils.js" as DateUtils
import "databasemodule_v2.js" as DB
Item {
id: articleViewRoot
signal articleStatusChanged(int tagId, int articleId, string status)
signal articleFavouriteChanged(var article, string favourite)
property bool showEmptyPlaceholder: true
property bool isEmbeddedMode: false // Deprecated for now.
property string feedTitle: ""
property var articleModel: null
property var modelItem: null
property bool __preventIndexChangeHandler: false
function setFeed(model, index) {
/* Setting new model and not-null index will cause two change events instead of one.
* Settings "preventIndexChangeHandler" to true helps to avoid it.
*/
if (articleModel != model && index !== 0)
__preventIndexChangeHandler = true
articleModel = model
setNewIndex(index)
}
function setNewIndex(rssIndex) {
rssListview.currentIndex = rssIndex
rssListview.positionViewAtIndex(rssListview.currentIndex, ListView.Center)
}
function showNextArticle() {
var index = rssListview.currentIndex + 1
if (index < rssListview.model.count) {
rssListview.currentIndex = index
}
}
function showPrevArticle() {
var index = rssListview.currentIndex - 1
if (index >= 0) {
rssListview.currentIndex = index
}
}
////////////////////////////////////////////// a listview to show the RSS content
ListView {
id: rssListview
property int contentFontSize: optionsKeeper.fontSize()
property bool contentDarkTheme: optionsKeeper.useDarkTheme()
width: parent.width
anchors {
bottom: parent.bottom
bottomMargin: units.gu(1)
top: parent.top
topMargin: units.gu(1)
}
model: articleModel
delegate: xmlDelegate
snapMode: ListView.SnapOneItem
cacheBuffer: 90 // value in pixels, for what?
// boundsBehavior: Flickable.StopAtBounds
orientation: ListView.Horizontal
contentHeight: parent.width * count
highlightFollowsCurrentItem: true
highlightMoveVelocity: 1000
highlightRangeMode: ListView.StrictlyEnforceRange
clip: true
onCurrentIndexChanged: {
console.log("ListView onCurrentIndexChanged", currentIndex, __preventIndexChangeHandler)
if (__preventIndexChangeHandler) {
__preventIndexChangeHandler = false
return
}
if (articleModel == null || articleModel.get == undefined) {
console.log("---- Stange behavior ----")
console.trace()
return
}
if (articleModel.count == 0) // It is normal bevaviour.
return
modelItem = articleModel.get(currentIndex)
feedTitle = modelItem.feed_name
if (modelItem.status != "1") {
var dbResult = DB.updateArticleStatus(modelItem.id, "1")
if (dbResult.rowsAffected == 1) {
articleStatusChanged(modelItem.tagId, modelItem.id, "1")
}
}
}
Label {
// We want to show it only when view isn't initialized.
visible: !articleModel && articleViewRoot.showEmptyPlaceholder
anchors.centerIn: parent
text: i18n.tr("Select article")
fontSize: "large"
}
}
////////////////////////////////////////////// delegate for ListView
Component {
id: xmlDelegate
Flickable {
id: scrollArea
objectName: "articleview_flickable"
clip: true
width: rssListview.width
height: rssListview.height
contentWidth: width
contentHeight: innerAreaColumn.height
Column {
id: innerAreaColumn
spacing: units.gu(2)
width: parent.width
property int mediaDownloadInProgress: 0
function mediaDownloaded() {
mediaDownloadInProgress = mediaDownloadInProgress - 1
}
Row {
width: parent.width - units.gu(4)
height: labelTime.paintedHeight
anchors.horizontalCenter: parent.horizontalCenter
spacing: units.gu(1)
Image {
id: imgFavourite
anchors.verticalCenter: labelTime.verticalCenter
fillMode: Image.PreserveAspectCrop
source: Qt.resolvedUrl("./icons_tmp/favorite-selected.svg")
sourceSize.height: modelItem == null ? 0 : (modelItem.favourite == "1" ? units.gu(2) : 0)
visible: modelItem == null ? false : (modelItem.favourite == "1")
smooth: true
}
Label {
id: labelTime
text: DateUtils.formatRelativeTime(i18n, pubdate)
fontSize: "small"
width: parent.width - units.gu(3)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
}
Label {
objectName: "articleviewitem_title"
fontSize: "large"
text: model.title
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Label {
// fontSize: "large"
color: "grey"
text: model.author ? model.author : ""
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
visible: text !== "" && text !== '""'
}
Label {
text: model.content
fontSize: {
switch(rssListview.contentFontSize) {
case 0:
return "small"
case 1:
return "medium"
case 2:
return "large"
}
}
color: rssListview.contentDarkTheme ? "lightgray" : "white" // TODO design needed
linkColor: "white"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
clip: true
onLinkActivated: Qt.openUrlExternally(model.link)
}
Label {
id: label_feedname
text: model.feed_name ? model.feed_name : ""
fontSize: "small"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
} // Column
} // Flickable
} // Component
Component {
id: readingOptionsPopoverComponent
ReadingOptions { }
} // Comp
}
|