[Goodies-commits] r4080 - xfmpc/trunk/src
Mike Massonnet
mmassonnet at xfce.org
Fri Mar 21 22:01:30 CET 2008
Author: mmassonnet
Date: 2008-03-21 21:01:30 +0000 (Fri, 21 Mar 2008)
New Revision: 4080
Modified:
xfmpc/trunk/src/mpdclient.c
xfmpc/trunk/src/mpdclient.h
xfmpc/trunk/src/playlist.c
Log:
Add a new callback in XfmpcPlaylist on song changes where the entire playlist doesn't need to be refreshed
* src/mpdclient.c,
src/mpdclient.h:
- New public function xfmpc_mpdclient_get_pos to return the position of the
song in the playlist
* src/playlist.c:
- (cb_song_changed): New callback connected to the signal "song-changed" of
XfmpcMpdclient
- (cb_playlist_changed): Update callback with xfmpc_mpdclient_get_pos
Modified: xfmpc/trunk/src/mpdclient.c
===================================================================
--- xfmpc/trunk/src/mpdclient.c 2008-03-21 15:12:48 UTC (rev 4079)
+++ xfmpc/trunk/src/mpdclient.c 2008-03-21 21:01:30 UTC (rev 4080)
@@ -381,6 +381,14 @@
}
gint
+xfmpc_mpdclient_get_pos (XfmpcMpdclient *mpdclient)
+{
+ XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT_GET_PRIVATE (mpdclient);
+
+ return mpd_player_get_current_song_pos (priv->mi);
+}
+
+gint
xfmpc_mpdclient_get_id (XfmpcMpdclient *mpdclient)
{
XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT_GET_PRIVATE (mpdclient);
Modified: xfmpc/trunk/src/mpdclient.h
===================================================================
--- xfmpc/trunk/src/mpdclient.h 2008-03-21 15:12:48 UTC (rev 4079)
+++ xfmpc/trunk/src/mpdclient.h 2008-03-21 21:01:30 UTC (rev 4080)
@@ -63,6 +63,8 @@
guint8 volume);
gboolean xfmpc_mpdclient_set_song_time (XfmpcMpdclient *mpdclient,
guint time);
+gint xfmpc_mpdclient_get_pos (XfmpcMpdclient *mpdclient);
+
gint xfmpc_mpdclient_get_id (XfmpcMpdclient *mpdclient);
const gchar * xfmpc_mpdclient_get_artist (XfmpcMpdclient *mpdclient);
Modified: xfmpc/trunk/src/playlist.c
===================================================================
--- xfmpc/trunk/src/playlist.c 2008-03-21 15:12:48 UTC (rev 4079)
+++ xfmpc/trunk/src/playlist.c 2008-03-21 21:01:30 UTC (rev 4080)
@@ -40,6 +40,8 @@
static void xfmpc_playlist_dispose (GObject *object);
static void xfmpc_playlist_finalize (GObject *object);
+static void cb_song_changed (XfmpcPlaylist *playlist);
+
static void cb_playlist_changed (XfmpcPlaylist *playlist);
static void cb_row_activated (XfmpcPlaylist *playlist,
@@ -219,7 +221,7 @@
/* === Signals === */
g_signal_connect_swapped (playlist->mpdclient, "song-changed",
- G_CALLBACK (cb_playlist_changed), playlist);
+ G_CALLBACK (cb_song_changed), playlist);
g_signal_connect_swapped (playlist->mpdclient, "playlist-changed",
G_CALLBACK (cb_playlist_changed), playlist);
/* Tree view */
@@ -332,29 +334,51 @@
static void
+cb_song_changed (XfmpcPlaylist *playlist)
+{
+ XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
+ gint id, current;
+
+ /* Remove the bold from the "last" current song */
+ GtkTreeIter iter;
+ GtkTreePath *path = gtk_tree_path_new_from_indices (priv->current, -1);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), &iter, path);
+ gtk_list_store_set (priv->store, &iter,
+ COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL,
+ -1);
+
+ /* Find the iter of the current song, set it bold and select it */
+ priv->current = xfmpc_mpdclient_get_pos (playlist->mpdclient);
+ path = gtk_tree_path_new_from_indices (priv->current, -1);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), &iter, path);
+ gtk_list_store_set (priv->store, &iter,
+ COLUMN_WEIGHT, PANGO_WEIGHT_BOLD,
+ -1);
+ /* don't autocenter if a filter is typped in */
+ if (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry))[0] == '\0' && priv->autocenter)
+ xfmpc_playlist_select_row (playlist, priv->current);
+}
+
+static void
cb_playlist_changed (XfmpcPlaylist *playlist)
{
XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
gchar *song, *length;
gint id, current;
- gboolean count = priv->autocenter;
- gint i = 0;
current = xfmpc_mpdclient_get_id (playlist->mpdclient);
xfmpc_playlist_clear (playlist);
while (xfmpc_mpdclient_playlist_read (playlist->mpdclient, &id, &song, &length))
{
- if (count)
- count = current != id && (i += 1);
xfmpc_playlist_append (playlist, id, song, length, current == id);
g_free (song);
g_free (length);
}
- priv->current = i;
+ priv->current = xfmpc_mpdclient_get_pos (playlist->mpdclient);
/* don't autocenter if a filter is typped in */
- if (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry))[0] == '\0' && i > 0 && priv->autocenter)
+ if (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry))[0] == '\0' && priv->autocenter)
xfmpc_playlist_select_row (playlist, priv->current);
}
More information about the Goodies-commits
mailing list