~qqworini/ubuntu-rssreader-app/alpha-3

« back to all changes in this revision

Viewing changes to ubuntu-rssreader-app.qml

  • Committer: Tarmac
  • Author(s): Roman Shchekin
  • Date: 2013-08-01 16:18:40 UTC
  • mfrom: (25.1.1 ubuntu-rssreader-app)
  • Revision ID: tarmac-20130801161840-1vsr2c3uzswz98ha
New network engine and view mode.

Approved by Svenn-Arne Dragly, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import Ubuntu.Components.ListItems 0.1 as ListItem
5
5
import Ubuntu.Components.Popups 0.1
6
6
import "./feeds"
 
7
import "./listview"
7
8
 
8
9
import "./databasemodule_v2.js" as DB
 
10
import "./imgSeparator.js" as ImageUtils
9
11
 
10
12
MainView {
11
13
    // objectName for functional testing purposes (autopilot-qt5)
40
42
            DB.addFeedTag(3, 3) ;
41
43
            refresh() ;
42
44
        }
43
 
 
44
 
        //else repeater.reloadTabs() ;     // load tabs from db
45
45
    }
46
46
 
47
47
    function refresh()             //  download all articles
48
48
    {
49
49
        var feeds = DB.loadFeeds();
50
 
        console.log(JSON.stringify(feeds));
51
 
        console.log(JSON.stringify(feeds.rows.item(0)));
52
50
        var feedarray = [] ;
53
51
        for (var i=0; i< feeds.rows.length; i++)
54
52
        {
55
 
            //            console.log(JSON.stringify(feeds.rows.item(i)));
56
53
            feedarray.push(feeds.rows.item(i));
57
54
        }
58
 
        //        console.log(JSON.stringify(feedarray));
59
55
        xmlnetwork.addFeedList(feedarray);
60
56
    }
61
57
 
67
63
 
68
64
    PageStack {
69
65
        id: pageStack
 
66
 
 
67
        property bool isListView: false // TODO use options.
 
68
 
70
69
        anchors.fill: parent
71
70
 
72
71
        Component.onCompleted:
73
72
        {
74
 
            push(tabs);                      // use tabs as first page
 
73
            if (isListView)
 
74
                push(feedListPage)
 
75
            else push(tabs);                      // use tabs as first page
75
76
            // push(editFeedsPage);
76
77
        }
77
78
 
78
79
        onCurrentPageChanged: {
79
 
            console.log("onCurrentPageChanged", currentPage.title)
80
 
            currentPage.reloadPageContent()
 
80
            if (currentPage != null) {
 
81
                console.log("onCurrentPageChanged", currentPage.title)
 
82
                currentPage.reloadPageContent()
 
83
            }
 
84
        }
 
85
 
 
86
        ToolbarItems {
 
87
            id: mainCommonToolbar
 
88
 
 
89
            back: ToolbarButton {
 
90
                action: Action {
 
91
                    text:  i18n.tr("Refresh")
 
92
                    iconSource: Qt.resolvedUrl("./icons_tmp/reload.svg")
 
93
                    onTriggered:
 
94
                    {
 
95
                        refresh();
 
96
                        toolbar.opened = false;
 
97
                    }
 
98
                }
 
99
            }
 
100
 
 
101
            ToolbarButton {
 
102
                action: Action {
 
103
                    id: changeModeAction
 
104
 
 
105
                    text:  pageStack.isListView ? i18n.tr("Shorts") : i18n.tr("List view")
 
106
                    iconSource: pageStack.isListView ? Qt.resolvedUrl("./icons_tmp/view-fullscreen.svg") : Qt.resolvedUrl("./icons_tmp/view-fullscreen.svg")
 
107
                    onTriggered: {
 
108
                        if (pageStack.isListView) {
 
109
                            pageStack.pop()
 
110
                            pageStack.push(tabs)
 
111
                        } else {
 
112
                            pageStack.pop()
 
113
                            pageStack.push(feedListPage)
 
114
                        }
 
115
 
 
116
                        pageStack.isListView = !pageStack.isListView
 
117
                        mainCommonToolbar.opened = false
 
118
                    }
 
119
                }
 
120
            }
 
121
 
 
122
            ToolbarButton {
 
123
                id: addReadsBtn
 
124
                action: Action {
 
125
                    text:  i18n.tr("Add reads")
 
126
                    iconSource: Qt.resolvedUrl("./icons_tmp/add.svg")
 
127
                    onTriggered: {
 
128
                        // pageStack.push(editFeedsPage)
 
129
                        PopupUtils.open(addReadsPopoverComp, addReadsBtn)
 
130
                    }
 
131
                }
 
132
            }
 
133
 
 
134
            ToolbarButton {
 
135
                action: Action {
 
136
                    text:  i18n.tr("Edit topics")
 
137
                    iconSource: Qt.resolvedUrl("./icons_tmp/edit.svg")
 
138
                    onTriggered: {
 
139
                        pageStack.push(editFeedsPage)
 
140
                    }
 
141
                }
 
142
            }
 
143
        }
 
144
 
 
145
        /* Temporary here - TODO move to separate file.
 
146
         */
 
147
        function updateFeedInfo(feedId, feedLink, responseData) {
 
148
            var entries = responseData.feed.entries
 
149
            var f = responseData.feed
 
150
 
 
151
            // TODO MB NO NEED
 
152
            DB.updateFeedByXml(feedId, f.feedUrl === f.link ? feedLink : f.link, // Sometimes google fails and sends site link equal to feed url.
 
153
                               f.description, f.title)
 
154
            console.log(" -------- UPDATE INFO -------- ")
 
155
            console.log(f.title, f.link, f.feedUrl, f.description)
 
156
 
 
157
            DB.clearArticles(feedId)
 
158
 
 
159
            // TODO TEMP SLOW SOLUTION
 
160
            // Later must replace it with adapted addArticles
 
161
            for (var i = 0; i < entries.length; i++) {
 
162
                var e = entries[i]
 
163
                var dbResult = DB.addArticle(e.title, e.content, e.link, e.contentSnippet, e.publishedDate,
 
164
                              Qt.md5(e.content + e.publishedDate), feedId)
 
165
 
 
166
                if (dbResult.error)
 
167
                    continue
 
168
 
 
169
                // -------  TODO naive solution of getting image ----------
 
170
                var imageFound = false
 
171
                if (e.mediaGroups) {
 
172
                    // console.log("MEDIA GROUPS FOUND")
 
173
                    var cont = e.mediaGroups[0].contents[0]
 
174
                    if (cont.type === "image/jpeg" || cont.type === "image/png" ||
 
175
                            cont.type === "image/jpeg" || cont.type === "image/pjpeg" ||
 
176
                            cont.type === "image/svg+xml") {
 
177
                        DB.updateArticleImage(dbResult.articleId, cont.url)
 
178
                        imageFound = true
 
179
                    }
 
180
                }
 
181
 
 
182
                if (!imageFound) {
 
183
                    var image = ImageUtils.getFirstImage(e.content)
 
184
                    if (image != null) {
 
185
                        DB.updateArticleImage(dbResult.articleId, image)
 
186
                    }
 
187
                }
 
188
 
 
189
                // -------------------------------------------------------
 
190
            }
81
191
        }
82
192
 
83
193
        Page {
90
200
 
91
201
            }
92
202
 
93
 
            tools: ToolbarItems {
94
 
                id: toolbar
95
 
 
96
 
                back: ToolbarButton {
97
 
                    action: Action {
98
 
                        text:  i18n.tr("Refresh")
99
 
                        iconSource: Qt.resolvedUrl("./icons_tmp/reload.svg")
100
 
                        onTriggered:
101
 
                        {
102
 
                            refresh();
103
 
                            toolbar.opened = false;
104
 
                        }
105
 
                    }
106
 
                }
107
 
 
108
 
                ToolbarButton {
109
 
                    action: Action {
110
 
                        text:  i18n.tr("List view")
111
 
                        iconSource: Qt.resolvedUrl("./icons_tmp/view-fullscreen.svg")
112
 
                        onTriggered: {
113
 
                            console.log("NOT IMPLEMENTED")
114
 
                        }
115
 
                    }
116
 
                }
117
 
 
118
 
                ToolbarButton {
119
 
                    id: addReadsBtn
120
 
                    action: Action {
121
 
                        text:  i18n.tr("Add reads")
122
 
                        iconSource: Qt.resolvedUrl("./icons_tmp/add.svg")
123
 
                        onTriggered: {
124
 
                            // pageStack.push(editFeedsPage)
125
 
                            PopupUtils.open(addReadsPopoverComp, addReadsBtn)
126
 
                        }
127
 
                    }
128
 
                }
129
 
 
130
 
                ToolbarButton {
131
 
                    action: Action {
132
 
                        text:  i18n.tr("Edit topics")
133
 
                        iconSource: Qt.resolvedUrl("./icons_tmp/edit.svg")
134
 
                        onTriggered: {
135
 
                            pageStack.push(editFeedsPage)
136
 
                        }
137
 
                    }
138
 
                }
139
 
            }
 
203
            tools: mainCommonToolbar
140
204
 
141
205
            Component.onCompleted: shorts_view.reload() ;
142
206
 
188
252
                            }
189
253
                        }
190
254
                    } // ActionList
191
 
                }
192
 
            }
193
 
        }
 
255
                } // ActionSelectionPopover
 
256
            } // Component
 
257
        } // Page "Shorts"
194
258
 
195
259
 
196
260
        // ************************************************************* ////////////////////////////////////
210
274
            flickable: null
211
275
        } // Page
212
276
 
 
277
        // ************************************************************* ////////////////////////////////////
 
278
 
213
279
        ManageTopicsPage {
214
280
            id: manageTopicsPage
215
281
            flickable: null
222
288
        AppendFeedPage {
223
289
            id: appendFeedPage
224
290
 
225
 
            title: "Append feed"
 
291
            title: i18n.tr("Append feed")
226
292
            flickable: null
227
293
            visible: false
228
294
        }
234
300
            id: chooseTopicPage
235
301
        }
236
302
 
237
 
        // independent page for viewing one RSS feed
238
 
        RssFeedPage
239
 
        {
 
303
        // ************************************************************* ////////////////////////////////////
 
304
 
 
305
        RssFeedPage {
240
306
            id: feed_page
241
307
            visible: false
242
308
        }
 
309
 
 
310
        // ************************************************************* ////////////////////////////////////
 
311
 
 
312
        FeedListPage {
 
313
            id: feedListPage
 
314
 
 
315
            title: i18n.tr("Feeds")
 
316
            flickable: null
 
317
            visible: false
 
318
        }
 
319
 
 
320
        // ************************************************************* ////////////////////////////////////
 
321
 
 
322
        ArticleListPage {
 
323
            id: articleListPage
 
324
 
 
325
            title: i18n.tr("Articles")
 
326
            flickable: null
 
327
            visible: false
 
328
        }
243
329
    }
244
330
 
245
331
    XmlNetwork         //  all download and xml parse functions here