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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/*
license GPL v3 ...........
description of this file:
a page for viewing a user selected RSS feed ;
*/
import QtQuick 2.0
import QtQuick.XmlListModel 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import Ubuntu.Components.Popups 0.1
import "./dateutils.js" as DateUtils
import "databasemodule_v2.js" as DB
Page {
id: page_feed
property string rssModelUrl: ""
property string rssTitle: ""
property int rssIndex: 0
property var rssModel
property var rssItem: null
property bool preventIndexChangeHandler: false
onRssIndexChanged: {
rssListview.currentIndex = rssIndex
rssListview.positionViewAtIndex(rssListview.currentIndex, ListView.Center)
}
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 (rssModel != model && index !== 0)
preventIndexChangeHandler = true
rssModel = model
rssIndex = index
}
function reloadPageContent() {
}
tools: ToolbarItems {
id: toolbar
ToolbarButton {
id: readingOptionsButton
/* QtRoS - Set visibility to true in line below to see options popup.
* There are no guides on dark and light theme yet, as on font size.
* So it is just logic for storing settings without any visual effects.
*/
visible: false
action: Action {
text: i18n.tr("Options")
iconSource: Qt.resolvedUrl("./icons_tmp/settings.svg")
onTriggered:
{
PopupUtils.open(readingOptionsPopoverComponent, readingOptionsButton)
}
}
}
ToolbarButton {
action: Action {
text: rssItem == null ? "" : (rssItem.favourite == "0" ? i18n.tr("Save") : i18n.tr("Unsave"))
iconSource: {
if (rssItem == null || rssItem.favourite == "0")
return Qt.resolvedUrl("./icons_tmp/favorite-unselected.svg")
else return Qt.resolvedUrl("./icons_tmp/favorite-selected.svg")
}
onTriggered: {
var fav = (rssItem.favourite == "0" ? "1" : "0")
var dbResult = DB.updateArticleFavourite(rssItem.id, fav)
if (dbResult.rowsAffected == 1) {
rssItem.favourite = fav
var dbResult1 = DB.updateArticleStatus(rssItem.id, "0")
if (dbResult1.rowsAffected == 1) {
rssItem.status = "0"
}
mainView.refreshSavedTab()
}
}
}
}
ToolbarButton {
action: Action {
text: i18n.tr("Open site")
iconSource: Qt.resolvedUrl("./icons_tmp/go-to.svg")
onTriggered:
{
console.log("Open site", rssListview.model.get(rssListview.currentIndex).link)
Qt.openUrlExternally(rssListview.model.get(rssListview.currentIndex).link)
}
}
}
}
Component {
id: readingOptionsPopoverComponent
Popover {
id: readingOptionsPopover
Component.onCompleted: {
// var useDarkTheme = DB.getUseDarkTheme()
// console.log("USE DARK", useDarkTheme)
fontSizeSlider.value = optionsKeeper.fontSize()
buttonRow.updateButtonsState()
}
Column {
id: contentColumn
anchors {
left: parent.left
top: parent.top
right: parent.right
}
ListItem.Empty {
Row {
id: buttonRow
property bool useDark: false
spacing: units.gu(2)
anchors.centerIn: parent
Button {
text: "Dark"
width: units.gu(14)
gradient: buttonRow.useDark ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
onClicked: {
optionsKeeper.setUseDarkTheme(true)
buttonRow.updateButtonsState()
}
}
Button {
text: "Light"
width: units.gu(14)
gradient: buttonRow.useDark ? UbuntuColors.greyGradient : UbuntuColors.orangeGradient
onClicked: {
optionsKeeper.setUseDarkTheme(false)
buttonRow.updateButtonsState()
}
}
function updateButtonsState() {
useDark = optionsKeeper.useDarkTheme()
}
}
}
ListItem.Empty {
showDivider: false
Label {
id: lblLess
text: "A"
fontSize: "small"
color: "black" // TODO TEMP
anchors {
left: parent.left
leftMargin: units.gu(2)
verticalCenter: parent.verticalCenter
}
}
Slider {
id: fontSizeSlider
anchors {
right: lblMore.left
rightMargin: units.gu(1)
left: lblLess.right
leftMargin: units.gu(1)
verticalCenter: parent.verticalCenter
}
minimumValue: 0
maximumValue: 2
onValueChanged: {
var res
if (value < maximumValue / 3)
res = 0
else if (value < maximumValue / 3 * 2)
res = 1
else res = 2
optionsKeeper.setFontSize(res)
}
function formatValue(v) {
if (v < maximumValue / 3)
return i18n.tr("Small")
else if (v < maximumValue / 3 * 2)
return i18n.tr("Mid")
else return i18n.tr("Large")
}
} // SLider
Label {
id: lblMore
text: "A"
fontSize: "large"
color: "black" // TODO TEMP
anchors {
right: parent.right
rightMargin: units.gu(2)
verticalCenter: parent.verticalCenter
}
}
} // ListItem.Empty
}
}
} // Component
////////////////////////////////////////////// a listview to show the RSS content
ListView {
id: rssListview
width: parent.width
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(2)
anchors.top: parent.top
anchors.topMargin: units.gu(2)
snapMode: ListView.SnapOneItem
cacheBuffer: 90
boundsBehavior: Flickable.StopAtBounds
orientation: ListView.Horizontal
contentHeight: parent.width * count
model: rssModel
delegate: xmlDelegate
highlightFollowsCurrentItem: true
highlightRangeMode: ListView.StrictlyEnforceRange
onCurrentIndexChanged: {
console.log("ListView onCurrentIndexChanged", currentIndex, preventIndexChangeHandler)
if (preventIndexChangeHandler) {
preventIndexChangeHandler = false
return
}
rssItem = rssModel.get(currentIndex)
rssTitle = rssItem.feed_name
if (rssItem.status != "1") {
var dbResult = DB.updateArticleStatus(rssItem.id, "1")
if (dbResult.rowsAffected == 1) {
rssItem.status = "1"
}
}
}
}
////////////////////////////////////////////// delegate for ListView
Component {
id: xmlDelegate
Flickable {
id: scrollArea
clip: true
width: rssListview.width
height: rssListview.height
contentWidth: width
contentHeight: innerAreaColumn.height
Column {
id: innerAreaColumn
spacing: units.gu(2)
width: parent.width
Label {
id: label_time
text: DateUtils.formatRelativeTime(i18n, pubdate)
fontSize: "small"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
}
Label {
fontSize: "large"
text: title
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Label {
text: content
linkColor: UbuntuColors.orange // Temporary. Mb bad color, but better than dark blue.
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
clip: true
}
Label {
id: label_feedname
text: rssTitle
fontSize: "small"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.gu(4)
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
}
} // Flickable
} // Component
}
|