Update stats as proper signal, only return values from backend

This commit is contained in:
Thomas Perl 2014-02-10 21:13:49 +01:00
parent 0ff355737c
commit ccd4a4dc17
4 changed files with 26 additions and 13 deletions

View file

@ -35,6 +35,7 @@ Python {
signal updatedPodcast(var podcast)
signal episodeListChanged(int podcast_id)
signal updatedEpisode(var episode)
signal updateStats()
Component.onCompleted: {
setHandler('hello', function (coreversion, uiversion) {
@ -52,6 +53,7 @@ Python {
setHandler('refreshing', function(v) { py.refreshing = v; });
setHandler('episode-list-changed', py.episodeListChanged);
setHandler('updated-episode', py.updatedEpisode);
setHandler('update-stats', py.updateStats);
addImportPath(Qt.resolvedUrl('../..'));

View file

@ -69,3 +69,9 @@ function disableUntilReturn(item, py, func, args) {
item.enabled = true;
});
}
function format(s, d) {
return s.replace(/{([^}]*)}/g, function (m, k) {
return (k in d) ? d[k] : m;
});
}

12
main.py
View file

@ -96,12 +96,12 @@ class gPotherSide:
downloaded += do
unplayed += un
return '\n'.join([
'%d podcasts' % len(podcasts),
'%d episodes' % total,
'%d new episodes' % new,
'%d downloads' % downloaded,
])
return {
'podcasts': len(podcasts),
'episodes': total,
'newEpisodes': new,
'downloaded': downloaded,
}
def _get_cover(self, podcast):
filename = self.core.cover_downloader.get_cover(podcast)

View file

@ -22,6 +22,7 @@ import QtQuick 2.0
import 'icons/icons.js' as Icons
import 'common/constants.js' as Constants
import 'common/util.js' as Util
SlidePage {
id: startPage
@ -29,7 +30,12 @@ SlidePage {
function update_stats() {
py.call('main.get_stats', [], function (result) {
stats.text = result;
stats.text = Util.format(
'{podcasts} podcasts\n' +
'{episodes} episodes\n' +
'{newEpisodes} new episodes\n' +
'{downloaded} downloaded',
result);
});
py.call('main.get_fresh_episodes_summary', [3], function (episodes) {
@ -37,12 +43,11 @@ SlidePage {
});
}
Component.onCompleted: {
py.setHandler('update-stats', startPage.update_stats);
Item {
Connections {
target: py
onUpdateStats: startPage.update_stats();
}
Component.onDestruction: {
py.setHandler('update-stats', undefined);
}
Flickable {