Add stats to new Server panel (close #38)
This commit is contained in:
parent
fe1b60ea17
commit
30175ee86a
3 changed files with 260 additions and 2 deletions
|
|
@ -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 = {}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue