[Goodies-commits] r3951 - xfmpc/trunk/src

Mike Massonnet mmassonnet at xfce.org
Fri Feb 15 03:35:41 CET 2008


Author: mmassonnet
Date: 2008-02-15 02:35:41 +0000 (Fri, 15 Feb 2008)
New Revision: 3951

Modified:
   xfmpc/trunk/src/playlist.c
   xfmpc/trunk/src/preferences.c
Log:
Add autocenter in playlist (optional)
* preferences.c:
  - New user preference PlaylistAutocenter
* playlist.c:
  - Include preferences interface
  - (cb_playlist_changed) If preference autocenter is set, scroll to the
  current song + select it


Modified: xfmpc/trunk/src/playlist.c
===================================================================
--- xfmpc/trunk/src/playlist.c	2008-02-15 02:35:35 UTC (rev 3950)
+++ xfmpc/trunk/src/playlist.c	2008-02-15 02:35:41 UTC (rev 3951)
@@ -24,6 +24,7 @@
 #include <libxfce4util/libxfce4util.h>
 
 #include "playlist.h"
+#include "preferences.h"
 #include "mpdclient.h"
 
 #define BORDER 4
@@ -67,6 +68,7 @@
 {
   GtkVBox               parent;
   XfmpcPlaylistPrivate *priv;
+  XfmpcPreferences     *preferences;
   XfmpcMpdclient       *mpdclient;
 };
 
@@ -74,6 +76,7 @@
 {
   GtkWidget            *treeview;
   GtkListStore         *store;
+  gboolean              autocenter;
 };
 
 
@@ -129,8 +132,13 @@
 {
   XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
 
+  playlist->preferences = xfmpc_preferences_get ();
   playlist->mpdclient = xfmpc_mpdclient_new ();
 
+  g_object_get (G_OBJECT (playlist->preferences),
+                "playlist-autocenter", &priv->autocenter,
+                NULL);
+
   /* Tree model */
   priv->store = gtk_list_store_new (N_COLUMNS,
                                     G_TYPE_INT,
@@ -243,20 +251,34 @@
 static void
 cb_playlist_changed (XfmpcPlaylist *playlist)
 {
+  XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
   gchar                *song;
   gchar                *length;
   gint                  id;
   gint                  current;
+  gboolean              count = priv->autocenter;
+  gint                  i = 0;
+  GtkTreePath          *path;
 
   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);
     }
+
+  if (priv->autocenter)
+    {
+      path = gtk_tree_path_new_from_indices (i, -1);
+      gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path, NULL, FALSE);
+      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL, TRUE, 0.5, 0);
+      gtk_tree_path_free (path);
+    }
 }
 
 static void

Modified: xfmpc/trunk/src/preferences.c
===================================================================
--- xfmpc/trunk/src/preferences.c	2008-02-15 02:35:35 UTC (rev 3950)
+++ xfmpc/trunk/src/preferences.c	2008-02-15 02:35:41 UTC (rev 3951)
@@ -34,6 +34,7 @@
   PROP_LAST_WINDOW_POSX,
   PROP_LAST_WINDOW_POSY,
   PROP_LAST_WINDOW_STATE_STICKY,
+  PROP_PLAYLIST_AUTOCENTER,
   N_PROPERTIES,
 };
 
@@ -139,6 +140,14 @@
                                                          "Sticky bit on window",
                                                          FALSE,
                                                          G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_PLAYLIST_AUTOCENTER,
+                                   g_param_spec_boolean ("playlist-autocenter",
+                                                         "PlaylistAutocenter",
+                                                         "Auto-centers the current song in the playlist",
+                                                         TRUE,
+                                                         G_PARAM_READWRITE));
 }
 
 static void




More information about the Goodies-commits mailing list