~popey/ubuntu-rssreader-app/fix-1306821

« back to all changes in this revision

Viewing changes to listview/FeedListPage.qml

  • Committer: Roman Shchekin
  • Date: 2013-07-25 19:49:25 UTC
  • mto: (25.1.1 ubuntu-rssreader-app)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: mrqtros@gmail.com-20130725194925-j4h0vzthckkau9il
List view comeback prepare.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import QtQuick.XmlListModel 2.0
 
3
 
 
4
import Ubuntu.Components 0.1
 
5
import Ubuntu.Components.ListItems 0.1 as ListItems
 
6
import Ubuntu.Components.Popups 0.1
 
7
 
 
8
import "../databasemodule_v2.js" as DB
 
9
 
 
10
Page {
 
11
    id: pageItself
 
12
 
 
13
    function reloadPageContent() {
 
14
        feedList.model = null // Sections are not recreated without this line.
 
15
        feedListModel.clear()
 
16
 
 
17
        /* Append feeds with topics.
 
18
                 */
 
19
        var allFeeds = DB.loadFeeds()
 
20
        var tags = DB.loadTags()
 
21
 
 
22
        for (var i = 0; i < tags.rows.length; i++) {
 
23
            var curTag = tags.rows.item(i) // TMP
 
24
            var feedsByTag = DB.loadFeedsFromTag(curTag.id)
 
25
 
 
26
            for (var j = 0; j < feedsByTag.rows.length; j++) {
 
27
                var curFeed = feedsByTag.rows.item(j)
 
28
                feedListModel.append({"tagName":curTag.name,
 
29
                                          "tagId" : curTag.id,
 
30
                                          "feedName" : curFeed.title,
 
31
                                          "feedId" : curFeed.id,
 
32
                                          "feedSource": curFeed.source,
 
33
                                          "feedDescription" : curFeed.description,
 
34
                                          "isSelected" : false })
 
35
            }
 
36
        }
 
37
 
 
38
        /* Append rest of feeds.
 
39
                 */
 
40
        var feedsWithoutTopic = DB.loadFeedsWithoutTopic()
 
41
 
 
42
        for (var j = 0; j < feedsWithoutTopic.rows.length; j++) {
 
43
            var curFeed = feedsWithoutTopic.rows.item(j)
 
44
 
 
45
            feedListModel.append({"tagName": i18n.tr("No topic"),
 
46
                                      "tagId" : 0,
 
47
                                      "feedName" : curFeed.title,
 
48
                                      "feedId" : curFeed.id,
 
49
                                      "feedSource": curFeed.source,
 
50
                                      "feedDescription" : curFeed.description,
 
51
                                      "isSelected" : false })
 
52
        }
 
53
 
 
54
        feedList.model = feedListModel
 
55
    }
 
56
 
 
57
    ListModel {
 
58
        id: feedListModel
 
59
    }
 
60
 
 
61
    ListView {
 
62
        id: feedList
 
63
 
 
64
        clip: true
 
65
        anchors.fill: parent
 
66
        model: feedListModel
 
67
 
 
68
        header: ListItems.Subtitled {
 
69
            text: i18n.tr("All news")
 
70
            subText: i18n.tr("View news from all channels")
 
71
            progression: true
 
72
            visible: feedListModel.count != 0
 
73
 
 
74
            onClicked: {
 
75
                pageStack.push(articleListPage, {"updateData" : {"isAll" : true} })
 
76
            }
 
77
        } // header
 
78
 
 
79
        delegate: ListItems.Subtitled {
 
80
            text: (model.feedName == "")? model.feedSource : model.feedName
 
81
            subText: (model.feedDescription !== undefined)? model.feedDescription : ""
 
82
            progression: true
 
83
 
 
84
            onPressAndHold: {
 
85
                feedList.currentIndex = model.index
 
86
                PopupUtils.open(popoverComponent, feedList)
 
87
            }
 
88
 
 
89
            onClicked: {
 
90
                console.log("Show news in feed:", model.feedSource)
 
91
                pageStack.push(articleListPage, {"updateData" : {"isAll":false, "feedId" : model.feedId} })
 
92
                // pageItself.feedSelected({"isAll":false, "feedId":model.id})
 
93
            }
 
94
        } // delegate
 
95
 
 
96
        section {
 
97
            property: "tagId"
 
98
            criteria: ViewSection.FullString
 
99
            delegate: ListItems.Header {
 
100
                // height: units.gu(5)
 
101
                Component.onCompleted: {
 
102
                    var s = section
 
103
                    for (var i = 0; i < feedListModel.count; i++) {
 
104
                        if (feedListModel.get(i).tagId == s) {
 
105
                            text = feedListModel.get(i).tagName
 
106
                            break
 
107
                        }
 
108
                    }
 
109
                }
 
110
            }
 
111
        } // section
 
112
 
 
113
    } // ListView
 
114
 
 
115
    tools: mainCommonToolbar
 
116
 
 
117
    Component {
 
118
        id: popoverComponent
 
119
 
 
120
        /* This new popover works like context menu.
 
121
         * Actions can be reused in toolbar.
 
122
         */
 
123
        ActionSelectionPopover {
 
124
            id: popover
 
125
            actions: ActionList {
 
126
                id: popoverActionsList
 
127
                Action {
 
128
                    id: nameActionUpdate
 
129
                    text: i18n.tr("Update")
 
130
                    onTriggered: {
 
131
                        //                        var data = feedListModel.get(feedList.currentIndex)
 
132
                        //                        var feedUrl = data.feedSource
 
133
                        //                        console.log("UPDATE STARTED FOR FEED:", data.feedSource, data.feedId)
 
134
                        //                        pageItself.currentTask = {"operation" : "update", "source" : feedUrl, "feedId" : data.feedId}
 
135
                        //                        thinXmlHttpRequestWraper.loadXml(feedUrl)
 
136
                    }
 
137
                }
 
138
 
 
139
                Action {
 
140
                    text: i18n.tr("Edit")
 
141
                    onTriggered: {
 
142
                        var data = feedListModel.get(feedList.currentIndex)
 
143
                        console.log("START EDIT ", data.source, data.status)
 
144
                        if (data.status == '0') {
 
145
                            console.log("EDIT ABORT")
 
146
                            return
 
147
                        }
 
148
 
 
149
                        PopupUtils.open(popoverSheetComponent, tools, {"isForEdit":true, "itemData" : data})
 
150
                    }
 
151
                }
 
152
 
 
153
                Action {
 
154
                    text: i18n.tr("Open site")
 
155
                    onTriggered: {
 
156
                        Qt.openUrlExternally(feedListModel.get(feedList.currentIndex).feedSource)
 
157
                    }
 
158
                }
 
159
 
 
160
                Action {
 
161
                    text: i18n.tr("Remove")
 
162
                    onTriggered: {
 
163
                        var id = feedListModel.get(feedList.currentIndex).feedId
 
164
                        var dbResult = DB.deleteFeed(id)
 
165
                        if (dbResult.rowsAffected > 0) {
 
166
                            DB.clearArticles(id)
 
167
                            feedListModel.remove(feedList.currentIndex)
 
168
                        }
 
169
                    }
 
170
                }
 
171
 
 
172
                Action {
 
173
                    text: i18n.tr("Remove all")
 
174
                    onTriggered: {
 
175
                        //DB2.dropTable()
 
176
                        //feedListModel.clear()
 
177
                    }
 
178
                }
 
179
            } // ActionList
 
180
        } // ActionSelectionPopover
 
181
    } // Popover component
 
182
 
 
183
    Label {
 
184
        id: lblEmptyBase
 
185
 
 
186
        text: i18n.tr("There are no RSS feeds to show")
 
187
        anchors.centerIn: parent
 
188
        visible: feedListModel.count == 0
 
189
        fontSize: "large"
 
190
    }
 
191
} // Page