Episode list model: Store and restore episode list filter
This commit is contained in:
parent
65b692b16d
commit
deaa5e8268
6 changed files with 41 additions and 8 deletions
|
@ -40,6 +40,7 @@ Python {
|
|||
signal episodeListChanged(int podcast_id)
|
||||
signal updatedEpisode(var episode)
|
||||
signal updateStats()
|
||||
signal configChanged(string key, var value)
|
||||
|
||||
Component.onCompleted: {
|
||||
setHandler('hello', function (coreversion, uiversion) {
|
||||
|
@ -61,6 +62,7 @@ Python {
|
|||
setHandler('episode-list-changed', py.episodeListChanged);
|
||||
setHandler('updated-episode', py.updatedEpisode);
|
||||
setHandler('update-stats', py.updateStats);
|
||||
setHandler('config-changed', py.configChanged);
|
||||
|
||||
addImportPath(Qt.resolvedUrl('../..'));
|
||||
|
||||
|
|
|
@ -54,9 +54,23 @@ ListModel {
|
|||
property int currentFilterIndex: -1
|
||||
property string currentCustomQuery: queries.All
|
||||
|
||||
Component.onCompleted: {
|
||||
// Request filter, then load episodes
|
||||
py.call('main.get_config_value', ['ui.qml.episode_list.filter_eql'], function (result) {
|
||||
setQuery(result);
|
||||
reload();
|
||||
});
|
||||
}
|
||||
|
||||
function setQueryIndex(index) {
|
||||
currentFilterIndex = index;
|
||||
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', filters[currentFilterIndex].query]);
|
||||
}
|
||||
|
||||
function setQuery(query) {
|
||||
for (var i=0; i<filters.length; i++) {
|
||||
if (filters[i].query === query) {
|
||||
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', query]);
|
||||
currentFilterIndex = i;
|
||||
return;
|
||||
}
|
||||
|
@ -64,6 +78,8 @@ ListModel {
|
|||
|
||||
currentFilterIndex = -1;
|
||||
currentCustomQuery = query;
|
||||
|
||||
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', query]);
|
||||
}
|
||||
|
||||
function loadAllEpisodes(callback) {
|
||||
|
@ -119,5 +135,12 @@ ListModel {
|
|||
episodeListModel.reload();
|
||||
}
|
||||
}
|
||||
|
||||
onConfigChanged: {
|
||||
if (key === 'ui.qml.episode_list.filter_eql') {
|
||||
setQuery(value);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
main.py
14
main.py
|
@ -70,9 +70,15 @@ class gPotherSide:
|
|||
self.core = core.Core(progname=progname)
|
||||
pyotherside.send('podcast-list-changed')
|
||||
|
||||
self.core.config.add_observer(self._config_option_changed)
|
||||
|
||||
def atexit(self):
|
||||
self.core.shutdown()
|
||||
|
||||
def _config_option_changed(self, name, old_value, new_value):
|
||||
logger.warn('Config option changed: %s = %s -> %s', name, old_value, new_value)
|
||||
pyotherside.send('config-changed', name, new_value)
|
||||
|
||||
def _get_episode_by_id(self, episode_id):
|
||||
for podcast in self.core.model.get_podcasts():
|
||||
for episode in podcast.episodes:
|
||||
|
@ -361,6 +367,12 @@ class gPotherSide:
|
|||
if episode.total_time > 0:
|
||||
yield '%02d:%02d:%02d' % (episode.total_time / (60 * 60), (episode.total_time / 60) % 60, episode.total_time % 60)
|
||||
|
||||
def set_config_value(self, option, value):
|
||||
self.core.config.update_field(option, value)
|
||||
|
||||
def get_config_value(self, option):
|
||||
return self.core.config.get_field(option)
|
||||
|
||||
gpotherside = gPotherSide()
|
||||
pyotherside.atexit(gpotherside.atexit)
|
||||
|
||||
|
@ -385,3 +397,5 @@ change_section = gpotherside.change_section
|
|||
report_playback_event = gpotherside.report_playback_event
|
||||
mark_episodes_as_old = gpotherside.mark_episodes_as_old
|
||||
save_playback_state = gpotherside.save_playback_state
|
||||
set_config_value = gpotherside.set_config_value
|
||||
get_config_value = gpotherside.get_config_value
|
||||
|
|
|
@ -31,7 +31,7 @@ Item {
|
|||
pgst.loadPage('SelectionDialog.qml', {
|
||||
title: episodeQueryControl.title,
|
||||
callback: function (index, result) {
|
||||
episodeQueryControl.model.currentFilterIndex = index;
|
||||
episodeQueryControl.model.setQueryIndex(index);
|
||||
episodeQueryControl.model.reload();
|
||||
},
|
||||
items: function () {
|
||||
|
|
|
@ -39,11 +39,6 @@ SlidePage {
|
|||
title: 'Select filter'
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
episodeList.model.setQuery(episodeList.model.queries.Fresh);
|
||||
episodeList.model.reload();
|
||||
}
|
||||
|
||||
EpisodeListView {
|
||||
id: episodeList
|
||||
title: 'Episodes'
|
||||
|
|
|
@ -63,8 +63,7 @@ SlidePage {
|
|||
|
||||
Component.onCompleted: {
|
||||
episodeList.model.podcast_id = podcast_id;
|
||||
episodeList.model.setQuery(episodeList.model.queries.All);
|
||||
episodeList.model.reload();
|
||||
// List model will be loaded automatically on load
|
||||
}
|
||||
|
||||
EpisodeQueryControl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue