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

Mike Massonnet mmassonnet at xfce.org
Sat Feb 23 16:15:54 CET 2008


Author: mmassonnet
Date: 2008-02-23 15:15:54 +0000 (Sat, 23 Feb 2008)
New Revision: 3986

Modified:
   xfmpc/trunk/src/mpdclient.c
   xfmpc/trunk/src/mpdclient.h
   xfmpc/trunk/src/playlist.c
   xfmpc/trunk/src/playlist.h
Log:
Add key event to remove songs in the playlist (GDK_Delete)
* src/mpdclient.c,
  src/mpdclient.h:
  - New functions xfmpc_mpdclient_queue_commit and
  xfmpc_mpdclient_queue_remove_id
* src/playlist.c(xfmpc_playlist_init):
  - Connect signal key-release-event to new callback cb_key_released
* src/playlist.c(xfmpc_playlist_delete_selection),
  src/playlist.h:
  - New function to delete all selected songs in the playlist


Modified: xfmpc/trunk/src/mpdclient.c
===================================================================
--- xfmpc/trunk/src/mpdclient.c	2008-02-23 15:15:47 UTC (rev 3985)
+++ xfmpc/trunk/src/mpdclient.c	2008-02-23 15:15:54 UTC (rev 3986)
@@ -564,3 +564,26 @@
     g_signal_emit_by_name (mpdclient, "playlist-changed");
 }
 
+gboolean
+xfmpc_mpdclient_queue_commit (XfmpcMpdclient *mpdclient)
+{
+  XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT_GET_PRIVATE (mpdclient);
+
+  if (mpd_playlist_queue_commit (priv->mi) != MPD_OK)
+    return FALSE;
+
+  return TRUE;
+}
+
+gboolean
+xfmpc_mpdclient_queue_remove_id (XfmpcMpdclient *mpdclient,
+                                 gint id)
+{
+  XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT_GET_PRIVATE (mpdclient);
+
+  if (mpd_playlist_queue_delete_id (priv->mi, id) != MPD_OK)
+    return FALSE;
+
+  return TRUE;
+}
+

Modified: xfmpc/trunk/src/mpdclient.h
===================================================================
--- xfmpc/trunk/src/mpdclient.h	2008-02-23 15:15:47 UTC (rev 3985)
+++ xfmpc/trunk/src/mpdclient.h	2008-02-23 15:15:54 UTC (rev 3986)
@@ -89,7 +89,11 @@
                                                                  gint *id,
                                                                  gchar **song,
                                                                  gchar **length);
+gboolean                xfmpc_mpdclient_queue_commit            (XfmpcMpdclient *mpdclient);
 
+gboolean                xfmpc_mpdclient_queue_remove_id         (XfmpcMpdclient *mpdclient,
+                                                                 gint id);
+
 G_END_DECLS
 
 #endif

Modified: xfmpc/trunk/src/playlist.c
===================================================================
--- xfmpc/trunk/src/playlist.c	2008-02-23 15:15:47 UTC (rev 3985)
+++ xfmpc/trunk/src/playlist.c	2008-02-23 15:15:54 UTC (rev 3986)
@@ -21,6 +21,7 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 #include <libxfce4util/libxfce4util.h>
 
 #include "playlist.h"
@@ -44,6 +45,8 @@
 static void             cb_row_activated                        (XfmpcPlaylist *playlist,
                                                                  GtkTreePath *path,
                                                                  GtkTreeViewColumn *column);
+static gboolean         cb_key_released                         (XfmpcPlaylist *playlist,
+                                                                 GdkEventKey *event);
 
 
 
@@ -191,6 +194,8 @@
   gtk_box_pack_start (GTK_BOX (playlist), scrolled, TRUE, TRUE, 0);
 
   /* Signals */
+  g_signal_connect_swapped (priv->treeview, "key-release-event",
+                            G_CALLBACK (cb_key_released), playlist);
   g_signal_connect_swapped (priv->treeview, "row-activated",
                             G_CALLBACK (cb_row_activated), playlist);
   g_signal_connect_swapped (playlist->mpdclient, "song-changed",
@@ -260,6 +265,36 @@
   gtk_tree_path_free (path);
 }
 
+void
+xfmpc_playlist_delete_selection (XfmpcPlaylist *playlist)
+{
+  XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
+  GtkTreeModel         *store = GTK_TREE_MODEL (priv->store);
+  GtkTreeIter           iter;
+  GList                *list;
+  gint                  id;
+
+  list = gtk_tree_selection_get_selected_rows (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)),
+                                               &store);
+  while (NULL != list)
+    {
+      if (gtk_tree_model_get_iter (store, &iter, list->data))
+        {       
+          gtk_tree_model_get (store, &iter,
+                              COLUMN_ID, &id,
+                              -1);
+          xfmpc_mpdclient_queue_remove_id (playlist->mpdclient, id);
+        }
+      list = g_list_next (list);
+    }
+
+  xfmpc_mpdclient_queue_commit (playlist->mpdclient);
+
+  g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
+  g_list_free (list);
+}
+
+
 static void
 cb_playlist_changed (XfmpcPlaylist *playlist)
 {
@@ -303,3 +338,23 @@
   xfmpc_mpdclient_set_id (playlist->mpdclient, id);
 }
 
+static gboolean
+cb_key_released (XfmpcPlaylist *playlist,
+                 GdkEventKey *event)
+{
+  if (event->type != GDK_KEY_RELEASE)
+    return FALSE;
+
+  switch (event->keyval)
+    {
+    case GDK_Delete:
+      xfmpc_playlist_delete_selection (playlist);
+      break;
+
+    default:
+      return FALSE;
+    }
+
+  return TRUE;
+}
+

Modified: xfmpc/trunk/src/playlist.h
===================================================================
--- xfmpc/trunk/src/playlist.h	2008-02-23 15:15:47 UTC (rev 3985)
+++ xfmpc/trunk/src/playlist.h	2008-02-23 15:15:54 UTC (rev 3986)
@@ -48,6 +48,7 @@
 
 void                    xfmpc_playlist_select_row               (XfmpcPlaylist *playlist,
                                                                  gint i);
+void                    xfmpc_playlist_delete_selection         (XfmpcPlaylist *playlist);
 
 G_END_DECLS
 




More information about the Goodies-commits mailing list