chiark / gitweb /
Create a queuelike for playlist editing
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 22 Nov 2009 15:59:50 +0000 (15:59 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 22 Nov 2009 15:59:50 +0000 (15:59 +0000)
disobedience/playlists.c
disobedience/queue-generic.c
disobedience/queue-generic.h

index 0d57c07e5c0a745c7d86be96ec287b37fec0b5e1..7e0eec1d4c7cf13e3b4b0109c329976efd298c74 100644 (file)
@@ -28,6 +28,8 @@
  * - a close button
  */
 #include "disobedience.h"
  * - a close button
  */
 #include "disobedience.h"
+#include "queue-generic.h"
+#include "popup.h"
 
 #if PLAYLISTS
 
 
 #if PLAYLISTS
 
@@ -56,6 +58,35 @@ char **playlists;
 /** @brief Count of playlists */
 int nplaylists;
 
 /** @brief Count of playlists */
 int nplaylists;
 
+/** @brief Columns for the playlist editor */
+static const struct queue_column playlist_columns[] = {
+  { "Artist", column_namepart, "artist", COL_EXPAND|COL_ELLIPSIZE },
+  { "Album",  column_namepart, "album",  COL_EXPAND|COL_ELLIPSIZE },
+  { "Title",  column_namepart, "title",  COL_EXPAND|COL_ELLIPSIZE },
+  { "Length", column_length,   0,        COL_RIGHT }
+};
+
+/** @brief Pop-up menu for playlist editor */
+// TODO some of these may not be generic enough yet - check!
+static struct menuitem playlist_menuitems[] = {
+  { "Track properties", ql_properties_activate, ql_properties_sensitive, 0, 0 },
+  { "Play track", ql_play_activate, ql_play_sensitive, 0, 0 },
+  //{ "Play playlist", ql_playall_activate, ql_playall_sensitive, 0, 0 },
+  { "Remove track from queue", ql_remove_activate, ql_remove_sensitive, 0, 0 },
+  { "Select all tracks", ql_selectall_activate, ql_selectall_sensitive, 0, 0 },
+  { "Deselect all tracks", ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 },
+};
+
+/** @brief Queuelike for editing a playlist */
+static struct queuelike ql_playlist = {
+  .name = "playlist",
+  .columns = playlist_columns,
+  .ncolumns = sizeof playlist_columns / sizeof *playlist_columns,
+  .menuitems = playlist_menuitems,
+  .nmenuitems = sizeof playlist_menuitems / sizeof *playlist_menuitems,
+  //.drop = playlist_drop  //TODO
+};
+
 /* Maintaining the list of playlists ---------------------------------------- */
 
 /** @brief Schedule an update to the list of playlists */
 /* Maintaining the list of playlists ---------------------------------------- */
 
 /** @brief Schedule an update to the list of playlists */
@@ -304,7 +335,9 @@ static GtkWidget *playlists_window_list(void) {
 /* Playlists window (edit current playlist) --------------------------------- */
 
 static GtkWidget *playlists_window_edit(void) {
 /* Playlists window (edit current playlist) --------------------------------- */
 
 static GtkWidget *playlists_window_edit(void) {
-  return NULL;
+  assert(ql_playlist.view == NULL);     /* better not be set up already */
+  GtkWidget *w = init_queuelike(&ql_playlist);
+  return w;
 }
 
 /* Playlists window --------------------------------------------------------- */
 }
 
 /* Playlists window --------------------------------------------------------- */
@@ -324,7 +357,15 @@ static gboolean playlists_keypress(GtkWidget attribute((unused)) *widget,
   }
 }
 
   }
 }
 
-/** @brief Pop up the playlists window
+/** @brief Called when the playlist window is destroyed */
+static void playlists_window_destroyed(GtkWidget attribute((unused)) *widget,
+                                       GtkWidget **widget_pointer) {
+  fprintf(stderr, "playlists_window_destroy\n");
+  destroy_queuelike(&ql_playlist);
+  *widget_pointer = NULL;
+}
+
+/** @BRIEF Pop up the playlists window
  *
  * Called when the playlists menu item is selected
  */
  *
  * Called when the playlists menu item is selected
  */
@@ -340,7 +381,7 @@ void edit_playlists(gpointer attribute((unused)) callback_data,
   playlists_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_style(playlists_window, tool_style);
   g_signal_connect(playlists_window, "destroy",
   playlists_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_style(playlists_window, tool_style);
   g_signal_connect(playlists_window, "destroy",
-                  G_CALLBACK(gtk_widget_destroyed), &playlists_window);
+                  G_CALLBACK(playlists_window_destroyed), &playlists_window);
   gtk_window_set_title(GTK_WINDOW(playlists_window), "Playlists Management");
   /* TODO loads of this is very similar to (copied from!) users.c - can we
    * de-dupe? */
   gtk_window_set_title(GTK_WINDOW(playlists_window), "Playlists Management");
   /* TODO loads of this is very similar to (copied from!) users.c - can we
    * de-dupe? */
index 82bd9398f161acff6c65cf5713425d0f05916467..2f8aa709a1601439addb687a9070a98ffcb25b40 100644 (file)
@@ -763,6 +763,7 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
 
   /* The selection should support multiple things being selected */
   ql->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ql->view));
 
   /* The selection should support multiple things being selected */
   ql->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ql->view));
+  g_object_ref(ql->selection);
   gtk_tree_selection_set_mode(ql->selection, GTK_SELECTION_MULTIPLE);
 
   /* Catch button presses */
   gtk_tree_selection_set_mode(ql->selection, GTK_SELECTION_MULTIPLE);
 
   /* Catch button presses */
@@ -824,7 +825,8 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
   
   /* TODO style? */
 
   
   /* TODO style? */
 
-  ql->init(ql);
+  if(ql->init)
+    ql->init(ql);
 
   /* Update display text when lookups complete */
   event_register("lookups-completed", queue_lookups_completed, ql);
 
   /* Update display text when lookups complete */
   event_register("lookups-completed", queue_lookups_completed, ql);
@@ -834,6 +836,31 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
   return scrolled;
 }
 
   return scrolled;
 }
 
+/** @brief Destroy a queuelike
+ * @param ql Queuelike to destroy
+ *
+ * Returns @p ql to its initial state.
+ */
+void destroy_queuelike(struct queuelike *ql) {
+  if(ql->store) {
+    g_object_unref(ql->store);
+    ql->store = NULL;
+  }
+  if(ql->view) {
+    gtk_object_destroy(GTK_OBJECT(ql->view));
+    ql->view = NULL;
+  }
+  if(ql->menu) {
+    gtk_object_destroy(GTK_OBJECT(ql->menu));
+    ql->menu = NULL;
+  }
+  if(ql->selection) {
+    g_object_unref(ql->selection);
+    ql->selection = NULL;
+  }
+  ql->q = NULL;
+}
+
 /*
 Local Variables:
 c-basic-offset:2
 /*
 Local Variables:
 c-basic-offset:2
index c15b3834b6fb4facf9758d88ded2dd585f40f218..2b8b8ef1758fb2fb33b4daa76415fdf564bd2081 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
 /*
  * This file is part of DisOrder
- * Copyright (C) 2006-2008 Richard Kettlewell
+ * Copyright (C) 2006-2009 Richard Kettlewell
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -104,8 +104,6 @@ struct queuelike {
   void (*drop)(struct queuelike *ql, int ntracks, char **tracks, char **ids,
                struct queue_entry *after_me);
 
   void (*drop)(struct queuelike *ql, int ntracks, char **tracks, char **ids,
                struct queue_entry *after_me);
 
-  /** @brief Stashed drag target row */
-  GtkTreePath *drag_target;
 };
 
 enum {
 };
 
 enum {
@@ -157,6 +155,7 @@ gboolean ql_button_release(GtkWidget *widget,
                            GdkEventButton *event,
                            gpointer user_data);
 GtkWidget *init_queuelike(struct queuelike *ql);
                            GdkEventButton *event,
                            gpointer user_data);
 GtkWidget *init_queuelike(struct queuelike *ql);
+void destroy_queuelike(struct queuelike *ql);
 void ql_update_list_store(struct queuelike *ql) ;
 void ql_update_row(struct queue_entry *q,
                    GtkTreeIter *iter);
 void ql_update_list_store(struct queuelike *ql) ;
 void ql_update_row(struct queue_entry *q,
                    GtkTreeIter *iter);