Play a playlist from the menu
[disorder] / disobedience / playlists.c
index cd8979d..50529f0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2008 Richard Kettlewell
+ * Copyright (C) 2008, 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
@@ -56,6 +56,8 @@ char **playlists;
 /** @brief Count of playlists */
 int nplaylists;
 
+/* Maintianng the list of playlists ----------------------------------------- */
+
 /** @brief Schedule an update to the list of playlists */
 static void playlists_update(const char attribute((unused)) *event,
                              void attribute((unused)) *eventdata,
@@ -106,13 +108,33 @@ static void playlists_updated(void attribute((unused)) *v,
   event_raise("playlists-updated", 0);
 }
 
-/** @brief Called to activate a playlist */
+/* Playlists menu ----------------------------------------------------------- */
+
+/** @brief Play received playlist contents
+ *
+ * Passed as a completion callback by menu_activate_playlist().
+ */
+static void playlist_play_content(void attribute((unused)) *v,
+                                  const char *err,
+                                  int nvec, char **vec) {
+  if(err) {
+    popup_protocol_error(0, err);
+    return;
+  }
+  for(int n = 0; n < nvec; ++n)
+    disorder_eclient_play(client, vec[n], NULL, NULL);
+}
+
+/** @brief Called to activate a playlist
+ *
+ * Called when the menu item for a playlist is clicked.
+ */
 static void menu_activate_playlist(GtkMenuItem *menuitem,
                                    gpointer attribute((unused)) user_data) {
   GtkLabel *label = GTK_LABEL(GTK_BIN(menuitem)->child);
   const char *playlist = gtk_label_get_text(label);
 
-  fprintf(stderr, "activate playlist %s\n", playlist); /* TODO */
+  disorder_eclient_playlist_get(client, playlist_play_content, playlist, NULL);
 }
 
 /** @brief Called when the playlists change */
@@ -123,7 +145,9 @@ static void menu_playlists_changed(const char attribute((unused)) *event,
     return;                             /* OMG too soon */
   GtkMenuShell *menu = GTK_MENU_SHELL(playlists_menu);
   /* TODO: we could be more sophisticated and only insert/remove widgets as
-   * needed.  For now that's too much effort. */
+   * needed.  The current logic trashes the selection which is not acceptable
+   * and interacts badly with one playlist being currently locked and
+   * edited. */
   while(menu->children)
     gtk_container_remove(GTK_CONTAINER(menu), GTK_WIDGET(menu->children->data));
   /* NB nplaylists can be -1 as well as 0 */
@@ -139,6 +163,8 @@ static void menu_playlists_changed(const char attribute((unused)) *event,
                            nplaylists >= 0);
 }
 
+/* Playlists window (list of playlists) ------------------------------------- */
+
 /** @brief (Re-)populate the playlist tree model */
 static void playlists_fill(void) {
   GtkTreeIter iter[1];
@@ -188,11 +214,17 @@ static void playlists_add(GtkButton attribute((unused)) *button,
   /* Unselect whatever is selected */
   gtk_tree_selection_unselect_all(playlists_selection);
   fprintf(stderr, "playlists_add\n");/* TODO */
+  /* We need to pop up a window asking for:
+   * - the name for the playlist
+   * - whether it is to be a public, private or shared playlist
+   * Moreover we should keep track of the known playlists and grey out OK
+   * if the name is a clash (as well as if it's actually invalid).
+   */
 }
 
 /** @brief Called when the 'Delete' button is pressed */
 static void playlists_delete(GtkButton attribute((unused)) *button,
-                        gpointer attribute((unused)) userdata) {
+                             gpointer attribute((unused)) userdata) {
   GtkWidget *yesno;
   int res;
 
@@ -202,7 +234,7 @@ static void playlists_delete(GtkButton attribute((unused)) *button,
                                  GTK_DIALOG_MODAL,
                                  GTK_MESSAGE_QUESTION,
                                  GTK_BUTTONS_YES_NO,
-                                 "Do you really want to delete user %s?"
+                                 "Do you really want to delete playlist %s?"
                                  " This action cannot be undone.",
                                  playlists_selected);
   res = gtk_dialog_run(GTK_DIALOG(yesno));
@@ -247,6 +279,12 @@ static gboolean playlists_keypress(GtkWidget attribute((unused)) *widget,
   }
 }
 
+/* Playlists window --------------------------------------------------------- */
+
+/** @brief Pop up the playlists window
+ *
+ * Called when the playlists menu item is selected
+ */
 void edit_playlists(gpointer attribute((unused)) callback_data,
                      guint attribute((unused)) callback_action,
                      GtkWidget attribute((unused)) *menu_item) {