~nskaggs/ubuntu-rssreader-app/fix-debian-control

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
import QtQuick 2.0
import QtQuick.XmlListModel 2.0

import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItems
import Ubuntu.Components.Popups 0.1

import "../databasemodule_v2.js" as DB
import "../."

Page {
    id: pageItself
    objectName: "feedlistpage"
    property var updatingFeed: null
    property bool isDirty: false

    function reloadPageContent() {
        feedList.model = null // Sections are not recreated without this line.
        feedListModel.clear()

        /* Append feeds with topics.
                 */
        var allFeeds = DB.loadFeeds()
        var tags = DB.loadTags()

        for (var i = 0; i < tags.rows.length; i++) {
            var curTag = tags.rows.item(i) // TMP
            var feedsByTag = DB.loadFeedsFromTag(curTag.id)

            for (var j = 0; j < feedsByTag.rows.length; j++) {
                var curFeed = feedsByTag.rows.item(j)
                feedListModel.append({"tagName":curTag.name,
                                         "tagId" : curTag.id,
                                         "feedName" : curFeed.title,
                                         "feedId" : curFeed.id,
                                         "feedSource": curFeed.source,
                                         "feedDescription" : curFeed.description,
                                         "feedLink" : curFeed.link })
            }
        }

        /* Append rest of feeds.
                 */
        var feedsWithoutTopic = DB.loadFeedsWithoutTopic()

        for (var j = 0; j < feedsWithoutTopic.rows.length; j++) {
            var curFeed = feedsWithoutTopic.rows.item(j)

            feedListModel.append({"tagName": i18n.tr("No topic"),
                                     "tagId" : 0,
                                     "feedName" : curFeed.title,
                                     "feedId" : curFeed.id,
                                     "feedSource": curFeed.source,
                                     "feedDescription" : curFeed.description,
                                     "feedLink" : curFeed.link })
        }

        feedList.model = feedListModel
    }

    ListModel {
        id: feedListModel
    }

    ListView {
        id: feedList

        clip: true
        anchors.fill: parent
        model: feedListModel

        header: ListItems.Subtitled {
            text: i18n.tr("All articles")
            subText: i18n.tr("View news from all channels")
            progression: true
            icon: Qt.resolvedUrl("../rssreader64.png")
            iconFrame: true
            visible: feedListModel.count != 0

            onClicked: {
                pageStack.push(articleListPage, {"updateData" : {"isAll" : true, "title" : text} })
            }
        } // header

        delegate: ListItems.Subtitled {
            text: (model.feedName == "")? model.feedSource : model.feedName
            subText: (model.feedDescription !== undefined)? model.feedDescription : ""
            progression: true
            icon: Qt.resolvedUrl("../rssreader64.png")
            iconFrame: true

            onPressAndHold: {
                feedList.currentIndex = model.index
                PopupUtils.open(popoverComponent, feedList.currentItem)
            }

            onClicked: {
                console.log("Show news in feed:", model.feedSource)
                pageStack.push(articleListPage, {"updateData" : {"isAll":false,
                                       "feedId" : model.feedId,
                                       "title" : model.feedName} })
                // pageItself.feedSelected({"isAll":false, "feedId":model.id})
            }
        } // delegate

        section {
            property: "tagId"
            criteria: ViewSection.FullString
            delegate: ListItems.Header {
                height: units.gu(5)
                text: textBySection()
                function textBySection() {
                    var s = section
                    for (var i = 0; i < feedListModel.count; i++) {
                        if (feedListModel.get(i).tagId == s) {
                            return feedListModel.get(i).tagName
                        }
                    }
                    return ""
                }
            }
        } // section

    } // ListView

    tools: mainCommonToolbar

    Component {
        id: popoverComponent

        /* This new popover works like context menu.
         * Actions can be reused in toolbar.
         */
        ActionSelectionPopover {
            id: popover
            actions: ActionList {
                id: popoverActionsList
                Action {
                    id: nameActionUpdate
                    text: i18n.tr("Update")
                    onTriggered: {
                        if (updatingFeed != null) {
                            console.log("TODO ALREADY UPDATING")
                            return
                        }

                        updatingFeed = feedListModel.get(feedList.currentIndex)
                        var feedUrl = updatingFeed.feedSource
                        console.log("UPDATE STARTED FOR FEED:", updatingFeed.feedName, updatingFeed.feedSource)
                        googleFeedApi.loadFeed(feedUrl)
                    }
                }

                Action {
                    text: i18n.tr("Edit")
                    onTriggered: {
                        console.log("EDIT TODO")
                        //                        var data = feedListModel.get(feedList.currentIndex)
                        //                        console.log("START EDIT ", data.source, data.status)
                        //                        if (data.status == '0') {
                        //                            console.log("EDIT ABORT")
                        //                            return
                        //                        }

                        //                        PopupUtils.open(popoverSheetComponent, tools, {"isForEdit":true, "itemData" : data})
                    }
                }

                Action {
                    text: i18n.tr("Open site")
                    onTriggered: {
                        var link = feedListModel.get(feedList.currentIndex).feedLink
                        console.log("SITE LINK", link)
                        Qt.openUrlExternally(link)
                    }
                }

                Action {
                    text: i18n.tr("Remove")
                    onTriggered: {
                        var id = feedListModel.get(feedList.currentIndex).feedId
                        var dbResult = DB.deleteFeed(id)
                        if (dbResult.rowsAffected > 0) {
                            DB.clearArticles(id)
                            feedListModel.remove(feedList.currentIndex)
                        }
                    }
                }

                // To dangerous without confirm dialog.
//                Action {
//                    text: i18n.tr("Remove all")
//                    onTriggered: {
//                        //DB2.dropTable()
//                        //feedListModel.clear()
//                    }
//                }
            } // ActionList
        } // ActionSelectionPopover
    } // Popover component

    Label {
        id: lblEmptyBase

        text: i18n.tr("There are no RSS feeds to show")
        anchors.centerIn: parent
        visible: feedListModel.count == 0
        fontSize: "large"
    }

    // -------------------------------------       GOOGLE API

    Connections {
        target: googleFeedApi

        onLoadResult: {
            if (result.responseStatus !== 200) {
                // TODO Handle error
                console.log(JSON.stringify(result))
                return
            }

            xmlnetwork.updateFeedInfo(updatingFeed.feedId, updatingFeed.feedLink, result.responseData)
            var f = result.responseData.feed
            updatingFeed.feedDescription = f.description
            updatingFeed.feedName = f.title

            updatingFeed = null
        }
    }

    GoogleFeedApi {
        id: googleFeedApi
    }

    // -------------------------------------       GOOGLE API
} // Page