From 30175ee86afe714c26b0c82bde89a524a241e117 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 24 Dec 2017 22:29:43 +0100 Subject: [PATCH] Add stats to new Server panel (close #38) --- data/gtk.glade | 196 ++++++++++++++++++++++++++++++++++++++++++++++++- mcg/client.py | 41 +++++++++++ mcg/widgets.py | 25 ++++++- 3 files changed, 260 insertions(+), 2 deletions(-) diff --git a/data/gtk.glade b/data/gtk.glade index c2ec509..cc6be64 100644 --- a/data/gtk.glade +++ b/data/gtk.glade @@ -709,7 +709,201 @@ - + + True + False + + + + + + True + False + vertical + + + + + + True + False + 2 + 5 + + + True + False + end + right + True + + + 0 + 0 + + + + + True + False + end + right + + + 0 + 1 + + + + + True + False + end + right + + + 0 + 2 + + + + + True + False + start + albums + + + 1 + 1 + + + + + True + False + start + songs + + + 1 + 2 + + + + + True + False + start + artists + + + 1 + 0 + + + + + True + False + end + right + + + 0 + 3 + + + + + True + False + start + seconds + + + 1 + 3 + + + + + True + False + end + right + + + 0 + 6 + + + + + True + False + end + right + + + 0 + 5 + + + + + True + False + + + 0 + 4 + 2 + + + + + True + False + start + seconds played + + + 1 + 5 + + + + + True + False + seconds running + + + 1 + 6 + + + + + False + True + 1 + + + + + False + True + 1 + + + + + page1 + Statistics + 1 + diff --git a/mcg/client.py b/mcg/client.py index 39c8764..22cf6b7 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -108,6 +108,8 @@ class Client(Base): SIGNAL_CONNECTION = 'connection' # Signal: status SIGNAL_STATUS = 'status' + # Signal: stats + SIGNAL_STATS = 'stats' # Signal: load albums SIGNAL_LOAD_ALBUMS = 'load-albums' # Signal: load playlist @@ -174,6 +176,12 @@ class Client(Base): self._add_action(self._get_status) + def get_stats(self): + """Load statistics.""" + self._logger.info("get stats") + self._add_action(self._get_stats) + + def load_albums(self): self._logger.info("load albums") self._add_action(self._load_albums) @@ -406,6 +414,39 @@ class Client(Base): self._callback(Client.SIGNAL_STATUS, state, album, pos, time, volume, file, audio, bitrate, error) + def _get_stats(self): + """Action: Perform the real statistics gathering.""" + self._logger.info("getting statistics") + stats = self._parse_dict(self._call("stats")) + self._logger.debug("stats: %r", stats) + + # Artists + artists = 0 + if 'artists' in stats: + artists = int(stats['artists']) + # Albums + albums = 0 + if 'albums' in stats: + albums = int(stats['albums']) + # Songs + songs = 0 + if 'songs' in stats: + songs = int(stats['songs']) + # Database playtime + dbplaytime = 0 + if 'db_playtime' in stats: + dbplaytime = stats['db_playtime'] + # Playtime + playtime = 0 + if 'playtime' in stats: + playtime = stats['playtime'] + # Uptime + uptime = 0 + if 'uptime' in stats: + uptime = stats['uptime'] + self._callback(Client.SIGNAL_STATS, artists, albums, songs, dbplaytime, playtime, uptime) + + def _load_albums(self): """Action: Perform the real update.""" self._albums = {} diff --git a/mcg/widgets.py b/mcg/widgets.py index dbe53b1..e1e12d2 100644 --- a/mcg/widgets.py +++ b/mcg/widgets.py @@ -160,6 +160,7 @@ class Window(): self._panels[Window._PANEL_INDEX_LIBRARY].connect('sort-type-changed', self.on_library_panel_sort_type_changed) self._mcg.connect_signal(client.Client.SIGNAL_CONNECTION, self.on_mcg_connect) self._mcg.connect_signal(client.Client.SIGNAL_STATUS, self.on_mcg_status) + self._mcg.connect_signal(client.Client.SIGNAL_STATS, self.on_mcg_stats) self._mcg.connect_signal(client.Client.SIGNAL_LOAD_PLAYLIST, self.on_mcg_load_playlist) self._mcg.connect_signal(client.Client.SIGNAL_LOAD_ALBUMS, self.on_mcg_load_albums) self._mcg.connect_signal(client.Client.SIGNAL_ERROR, self.on_mcg_error) @@ -349,6 +350,7 @@ class Window(): self._mcg.load_playlist() self._mcg.load_albums() self._mcg.get_status() + self._mcg.get_stats() self._connect_action.set_state(GLib.Variant.new_boolean(True)) self._play_action.set_enabled(True) self._clear_playlist_action.set_enabled(True) @@ -375,7 +377,7 @@ class Window(): self._play_action.set_state(GLib.Variant.new_boolean(False)) # Volume GObject.idle_add(self._header_bar.set_volume, volume) - # Audio + # Status self._panels[Window._PANEL_INDEX_SERVER].set_status(file, audio, bitrate, error) # Error if error is None: @@ -384,6 +386,10 @@ class Window(): self._show_error(error) + def on_mcg_stats(self, artists, albums, songs, dbplaytime, playtime, uptime): + self._panels[Window._PANEL_INDEX_SERVER].set_stats(artists, albums, songs, dbplaytime, playtime, uptime) + + def on_mcg_load_playlist(self, playlist): self._panels[self._PANEL_INDEX_PLAYLIST].set_playlist(self._connection_panel.get_host(), playlist) @@ -810,6 +816,14 @@ class ServerPanel(GObject.GObject): self._status_bitrate = builder.get_object('server-status-bitrate') self._status_error = builder.get_object('server-status-error') + # Stats widgets + self._stats_artists = builder.get_object('server-stats-artists') + self._stats_albums = builder.get_object('server-stats-albums') + self._stats_songs = builder.get_object('server-stats-songs') + self._stats_dbplaytime = builder.get_object('server-stats-dbplaytime') + self._stats_playtime = builder.get_object('server-stats-playtime') + self._stats_uptime = builder.get_object('server-stats-uptime') + def get(self): return self._panel @@ -843,6 +857,15 @@ class ServerPanel(GObject.GObject): self._status_error.set_markup(error) + def set_stats(self, artists, albums, songs, dbplaytime, playtime, uptime): + self._stats_artists.set_text(str(artists)) + self._stats_albums.set_text(str(albums)) + self._stats_songs.set_text(str(songs)) + self._stats_dbplaytime.set_text(str(dbplaytime)) + self._stats_playtime.set_text(str(playtime)) + self._stats_uptime.set_text(str(uptime)) + + class CoverPanel(GObject.GObject):