~ubuntu-branches/ubuntu/vivid/gpodder/vivid

« back to all changes in this revision

Viewing changes to share/gpodder/ui/qml/Subscribe.qml

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2014-07-26 20:43:14 UTC
  • mfrom: (5.2.33 sid)
  • Revision ID: package-import@ubuntu.com-20140726204314-kz4v2tyeeg7oj43y
Tags: 3.8.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
    function show() {
15
15
        searchInput.text = ''
16
 
        searchResultsListModel.source = ''
 
16
        searchResultsListModel.clear();
17
17
        resultsSheet.reject();
 
18
        directoryButtons.reloadOptions();
18
19
    }
19
20
 
20
21
    function search() {
25
26
            subscribe.subscribe([q]);
26
27
        } else {
27
28
            /* Search the web directory */
28
 
            searchResultsListModel.searchFor(q);
 
29
            searchResultsListModel.search(q);
29
30
            resultsSheet.open();
30
31
        }
31
32
    }
79
80
        }
80
81
    }
81
82
 
82
 
    Item {
 
83
    ListView {
83
84
        id: directoryButtons
84
 
 
85
 
        anchors.fill: parent
86
 
        anchors.bottomMargin: Config.listItemHeight
87
 
 
88
 
        Row {
89
 
            visible: parent.height > 200
90
 
            anchors.centerIn: parent
91
 
            spacing: Config.largeSpacing * 3
92
 
 
93
 
            Image {
94
 
                source: 'artwork/directory-toplist.png'
95
 
 
96
 
                SelectableItem {
97
 
                    property string modelData: 'http://gpodder.org/directory/toplist.xml'
98
 
                    anchors.fill: parent
99
 
                    onSelected: {
100
 
                        searchResultsListModel.source = item;
101
 
                        resultsSheet.open();
102
 
                    }
103
 
                }
104
 
 
105
 
                Label {
106
 
                    anchors.top: parent.bottom
107
 
                    anchors.horizontalCenter: parent.horizontalCenter
108
 
                    font.pixelSize: 30
109
 
                    color: 'white'
110
 
                    text: _('Toplist')
111
 
                }
112
 
            }
113
 
 
114
 
            Image {
115
 
                source: 'artwork/directory-examples.png'
116
 
 
117
 
                SelectableItem {
118
 
                    property string modelData: controller.myGpoEnabled?('http://' + controller.myGpoUsername + ':' + controller.myGpoPassword + '@gpodder.net/subscriptions/' + controller.myGpoUsername + '.xml'):('http://gpodder.org/directory/examples.xml')
119
 
                    anchors.fill: parent
120
 
                    onSelected: {
121
 
                        searchResultsListModel.source = item;
122
 
                        resultsSheet.open();
123
 
                    }
124
 
                }
125
 
 
126
 
                Label {
127
 
                    anchors.top: parent.bottom
128
 
                    anchors.horizontalCenter: parent.horizontalCenter
129
 
                    font.pixelSize: 30
130
 
                    color: 'white'
131
 
                    text: controller.myGpoEnabled?_('My gpodder.net'):_('Examples')
132
 
                }
 
85
        visible: topBar.visible
 
86
        clip: true
 
87
 
 
88
        anchors {
 
89
            left: parent.left
 
90
            right: parent.right
 
91
            top: topBar.bottom
 
92
            bottom: parent.bottom
 
93
            topMargin: Config.smallSpacing
 
94
        }
 
95
 
 
96
        model: ListModel { id: directoryButtonsModel }
 
97
 
 
98
        function doAction(action) {
 
99
            if (action === 'toplist') {
 
100
                searchResultsListModel.loadJson('https://gpodder.net/toplist/50.json');
 
101
                resultsSheet.open();
 
102
            } else if (action === 'mygpo') {
 
103
                if (controller.myGpoEnabled) {
 
104
                    searchResultsListModel.loadJson('https://' + controller.myGpoUsername + ':' + controller.myGpoPassword + '@gpodder.net/subscriptions/' + controller.myGpoUsername + '.json');
 
105
                    resultsSheet.open();
 
106
                }
 
107
            } else if (action === 'suggestions') {
 
108
                if (controller.myGpoEnabled) {
 
109
                    searchResultsListModel.loadJson('https://' + controller.myGpoUsername + ':' + controller.myGpoPassword + '@gpodder.net/suggestions/50.json');
 
110
                    resultsSheet.open();
 
111
                }
 
112
            } else {
 
113
                // Assume action is a URL
 
114
                searchResultsListModel.loadJson(action);
 
115
                resultsSheet.open();
 
116
            }
 
117
        }
 
118
 
 
119
        Component.onCompleted: {
 
120
            reloadOptions();
 
121
        }
 
122
 
 
123
        function reloadOptions() {
 
124
            directoryButtonsModel.clear();
 
125
            directoryButtonsModel.append({label: _('Most-subscribed on gpodder.net'), action: 'toplist'});
 
126
 
 
127
            if (controller.myGpoEnabled) {
 
128
                directoryButtonsModel.append({label: _('Your subscriptions on gpodder.net'), action: 'mygpo'});
 
129
                directoryButtonsModel.append({label: _('Recommended by gpodder.net for you'), action: 'suggestions'});
 
130
            }
 
131
 
 
132
            var result = new XMLHttpRequest();
 
133
            result.onreadystatechange = function() {
 
134
                if (result.readyState == XMLHttpRequest.DONE) {
 
135
                    var data = JSON.parse(result.responseText);
 
136
                    data.sort(function (a, b) {
 
137
                        // Sort by usage count, descending
 
138
                        return b.usage - a.usage;
 
139
                    });
 
140
                    for (var i=0; i<data.length; i++) {
 
141
                        directoryButtonsModel.append({label: data[i].tag, action: 'https://gpodder.net/api/2/tag/' + data[i].tag + '/50.json'});
 
142
                    }
 
143
                }
 
144
            };
 
145
            result.open('GET', 'https://gpodder.net/api/2/tags/50.json');
 
146
            result.send();
 
147
        }
 
148
 
 
149
        delegate: SelectableItem {
 
150
            property variant modelData: undefined
 
151
 
 
152
            Label {
 
153
                text: label
 
154
 
 
155
                anchors {
 
156
                    left: parent.left
 
157
                    right: parent.right
 
158
                    verticalCenter: parent.verticalCenter
 
159
                    margins: Config.smallSpacing
 
160
                }
 
161
 
 
162
                elide: Text.ElideRight
 
163
            }
 
164
 
 
165
            onSelected: {
 
166
                directoryButtons.doAction(action);
133
167
            }
134
168
        }
135
169
    }
136
170
 
137
 
    Label {
 
171
    ScrollScroll {
 
172
        flickable: directoryButtons
138
173
        visible: directoryButtons.visible
139
 
        anchors.right: parent.right
140
 
        anchors.bottom: parent.bottom
141
 
        anchors.margins: Config.largeSpacing
142
 
        font.pixelSize: 20
143
 
        color: 'white'
144
 
        text: '<em>' + _('powered by gpodder.net') + '</em>'
145
174
    }
146
175
 
 
176
 
147
177
    Sheet {
148
178
        id: resultsSheet
149
179
 
150
180
        anchors.fill: parent
151
 
        anchors.topMargin: -50
 
181
        anchors.topMargin: (width > height || status == DialogStatus.Closed) ? 0 : -50 // see bug 1915
152
182
 
153
183
        acceptButtonText: _('Subscribe')
154
184
        rejectButtonText: _('Cancel')
165
195
                id: listView
166
196
                property variant selectedIndices: []
167
197
 
168
 
                opacity: (searchResultsListModel.status == XmlListModel.Ready)?1:0
 
198
                opacity: searchResultsListModel.loaded ? 1 : 0
169
199
                Behavior on opacity { PropertyAnimation { } }
170
200
 
171
201
                anchors.fill: parent
172
202
 
173
 
                model: SearchResultsListModel {
 
203
                model: ListModel {
174
204
                    id: searchResultsListModel
175
 
 
176
 
                    function searchFor(query) {
177
 
                        console.log('Searching for: ' + query)
178
 
                        source = 'http://gpodder.net/search.xml?q=' + query
179
 
                        console.log('new source:' + source)
 
205
                    property bool loaded: false
 
206
 
 
207
                    function search(query) {
 
208
                        loadJson('https://gpodder.net/search.json?q=' + query);
 
209
                    }
 
210
 
 
211
                    function loadJson(url) {
 
212
                        clear();
 
213
                        searchResultsListModel.loaded = false;
 
214
 
 
215
                        var result = new XMLHttpRequest();
 
216
                        result.onreadystatechange = function() {
 
217
                            if (result.readyState == XMLHttpRequest.DONE) {
 
218
                                var data = JSON.parse(result.responseText);
 
219
                                data.sort(function (a, b) {
 
220
                                    // Sort by subscriber count, descending
 
221
                                    return b.subscribers - a.subscribers;
 
222
                                });
 
223
                                for (var i=0; i<data.length; i++) {
 
224
                                    searchResultsListModel.append(data[i]);
 
225
                                }
 
226
                                searchResultsListModel.loaded = true;
 
227
                            }
 
228
                        };
 
229
 
 
230
                        result.open('GET', url);
 
231
                        result.send();
180
232
                    }
181
233
                }
182
234
 
202
254
 
203
255
                        Image {
204
256
                            anchors.centerIn: parent
205
 
                            source: logo
 
257
                            source: scaled_logo_url
206
258
                        }
207
259
                    }
208
260
 
261
313
                anchors.centerIn: parent
262
314
                running: opacity > 0
263
315
 
264
 
                opacity: (searchResultsListModel.status == XmlListModel.Loading)?1:0
 
316
                opacity: searchResultsListModel.loaded ? 0 : 1
265
317
                Behavior on opacity { PropertyAnimation { } }
266
318
            }
267
319
        }