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