From ccd4a4dc17eba1effc40e3be449414f99c8a6d59 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Mon, 10 Feb 2014 21:13:49 +0100 Subject: [PATCH] Update stats as proper signal, only return values from backend --- common/GPodderCore.qml | 2 ++ common/util.js | 6 ++++++ main.py | 12 ++++++------ touch/StartPage.qml | 19 ++++++++++++------- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/common/GPodderCore.qml b/common/GPodderCore.qml index d8cd5fa..a4c38d8 100644 --- a/common/GPodderCore.qml +++ b/common/GPodderCore.qml @@ -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('../..')); diff --git a/common/util.js b/common/util.js index 3f48635..a70208a 100644 --- a/common/util.js +++ b/common/util.js @@ -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; + }); +} diff --git a/main.py b/main.py index ff3db33..b39e0cd 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/touch/StartPage.qml b/touch/StartPage.qml index 3999e28..d33c900 100644 --- a/touch/StartPage.qml +++ b/touch/StartPage.qml @@ -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); - } - - Component.onDestruction: { - py.setHandler('update-stats', undefined); + Item { + Connections { + target: py + onUpdateStats: startPage.update_stats(); + } } Flickable {