Add stats to new Server panel (close #38)
This commit is contained in:
parent
fe1b60ea17
commit
30175ee86a
196
data/gtk.glade
196
data/gtk.glade
|
@ -709,7 +709,201 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="center">
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="center">
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="row_spacing">2</property>
|
||||
<property name="column_spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-artists">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
<property name="selectable">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-albums">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-songs">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">albums</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">songs</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">artists</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-dbplaytime">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">seconds</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-uptime">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="server-stats-playtime">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="justify">right</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">4</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">seconds played</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">seconds running</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">page1</property>
|
||||
<property name="title" translatable="yes">Statistics</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
|
@ -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…
Reference in a new issue