Implement support for the new directory search API
This commit is contained in:
parent
6b5864806d
commit
1e87a2a3fb
5 changed files with 68 additions and 23 deletions
|
@ -22,28 +22,19 @@ import QtQuick 2.0
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: directorySearchModel
|
id: directorySearchModel
|
||||||
|
property string provider
|
||||||
|
|
||||||
function search(query, callback) {
|
function search(query, callback) {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
var result = new XMLHttpRequest();
|
py.call('main.get_directory_entries', [directorySearchModel.provider, query], function (result) {
|
||||||
result.onreadystatechange = function() {
|
for (var i=0; i<result.length; i++) {
|
||||||
if (result.readyState == XMLHttpRequest.DONE) {
|
directorySearchModel.append(result[i]);
|
||||||
var data = JSON.parse(result.responseText);
|
|
||||||
data.sort(function (a, b) {
|
|
||||||
// Sort by subscriber count, descending
|
|
||||||
return b.subscribers - a.subscribers;
|
|
||||||
});
|
|
||||||
for (var i=0; i<data.length; i++) {
|
|
||||||
directorySearchModel.append(data[i]);
|
|
||||||
}
|
|
||||||
if (callback !== undefined) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
result.open('GET', 'http://gpodder.net/search.json?q=' + query);
|
if (callback !== undefined) {
|
||||||
result.send();
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
main.py
27
main.py
|
@ -32,6 +32,7 @@ import gpodder
|
||||||
from gpodder.api import core
|
from gpodder.api import core
|
||||||
from gpodder.api import util
|
from gpodder.api import util
|
||||||
from gpodder.api import query
|
from gpodder.api import query
|
||||||
|
from gpodder.api import registry
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import functools
|
import functools
|
||||||
|
@ -373,6 +374,30 @@ class gPotherSide:
|
||||||
def get_config_value(self, option):
|
def get_config_value(self, option):
|
||||||
return self.core.config.get_field(option)
|
return self.core.config.get_field(option)
|
||||||
|
|
||||||
|
def get_directory_providers(self):
|
||||||
|
def select_provider(p):
|
||||||
|
return p.kind in (p.PROVIDER_SEARCH, p.PROVIDER_STATIC)
|
||||||
|
|
||||||
|
return [{
|
||||||
|
'label': provider.name,
|
||||||
|
'can_search': provider.kind == provider.PROVIDER_SEARCH
|
||||||
|
} for provider in registry.directory.select(select_provider)]
|
||||||
|
|
||||||
|
def get_directory_entries(self, provider, query):
|
||||||
|
def match_provider(p):
|
||||||
|
return p.name == provider
|
||||||
|
|
||||||
|
for provider in registry.directory.select(match_provider):
|
||||||
|
return [{
|
||||||
|
'title': e.title,
|
||||||
|
'url': e.url,
|
||||||
|
'image': e.image,
|
||||||
|
'subscribers': e.subscribers,
|
||||||
|
'description': e.description,
|
||||||
|
} for e in provider.on_string(query)]
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
gpotherside = gPotherSide()
|
gpotherside = gPotherSide()
|
||||||
pyotherside.atexit(gpotherside.atexit)
|
pyotherside.atexit(gpotherside.atexit)
|
||||||
|
|
||||||
|
@ -399,3 +424,5 @@ mark_episodes_as_old = gpotherside.mark_episodes_as_old
|
||||||
save_playback_state = gpotherside.save_playback_state
|
save_playback_state = gpotherside.save_playback_state
|
||||||
set_config_value = gpotherside.set_config_value
|
set_config_value = gpotherside.set_config_value
|
||||||
get_config_value = gpotherside.get_config_value
|
get_config_value = gpotherside.get_config_value
|
||||||
|
get_directory_providers = gpotherside.get_directory_providers
|
||||||
|
get_directory_entries = gpotherside.get_directory_entries
|
||||||
|
|
|
@ -24,6 +24,15 @@ import 'common'
|
||||||
|
|
||||||
SlidePage {
|
SlidePage {
|
||||||
id: directory
|
id: directory
|
||||||
|
property string provider
|
||||||
|
property bool can_search
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
if (!directory.can_search) {
|
||||||
|
// Load static data
|
||||||
|
search('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function search(text) {
|
function search(text) {
|
||||||
loading.visible = true;
|
loading.visible = true;
|
||||||
|
@ -40,7 +49,7 @@ SlidePage {
|
||||||
|
|
||||||
PScrollDecorator { flickable: listView }
|
PScrollDecorator { flickable: listView }
|
||||||
|
|
||||||
model: GPodderDirectorySearchModel { id: directorySearchModel }
|
model: GPodderDirectorySearchModel { id: directorySearchModel; provider: directory.provider }
|
||||||
|
|
||||||
header: Column {
|
header: Column {
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -48,9 +57,11 @@ SlidePage {
|
||||||
right: parent.right
|
right: parent.right
|
||||||
}
|
}
|
||||||
|
|
||||||
SlidePageHeader { title: 'Search gpodder.net' }
|
SlidePageHeader { title: directory.provider }
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
visible: directory.can_search
|
||||||
|
|
||||||
spacing: 0.5 * 30 * pgst.scalef
|
spacing: 0.5 * 30 * pgst.scalef
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
|
|
|
@ -46,7 +46,7 @@ ButtonArea {
|
||||||
width: 80 * pgst.scalef
|
width: 80 * pgst.scalef
|
||||||
height: 80 * pgst.scalef
|
height: 80 * pgst.scalef
|
||||||
|
|
||||||
source: scaled_logo_url
|
source: image
|
||||||
}
|
}
|
||||||
|
|
||||||
PLabel {
|
PLabel {
|
||||||
|
@ -70,6 +70,6 @@ ButtonArea {
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
text: subscribers
|
text: (subscribers > 0) ? subscribers : ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,25 @@ SlidePage {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Search gpodder.net',
|
label: 'Discover new podcasts',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
pgst.loadPage('Directory.qml');
|
py.call('main.get_directory_providers', [], function (result) {
|
||||||
|
var items = [];
|
||||||
|
for (var i=0; i<result.length; i++) {
|
||||||
|
(function (provider) {
|
||||||
|
items.push({
|
||||||
|
label: provider.label,
|
||||||
|
callback: function () {
|
||||||
|
pgst.loadPage('Directory.qml', {
|
||||||
|
provider: provider.label,
|
||||||
|
can_search: provider.can_search,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})(result[i]);
|
||||||
|
}
|
||||||
|
pgst.showSelection(items, 'Select provider');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue