chiark / gitweb /
protogen: The bulk of the eclient code generation.
[disorder] / disobedience / choose-menu.c
index 16aa593da7f6a805241e7010181260650886ce37..b4aa0ce5acf051e510ab660bc9ccc2468a8c5bad 100644 (file)
 #include "popup.h"
 #include "choose.h"
 
+static void choose_playchildren_callback(GtkTreeModel *model,
+                                         GtkTreePath *path,
+                                         GtkTreeIter *iter,
+                                         gpointer data);
+static void choose_playchildren_received(void *v,
+                                         const char *err,
+                                         int nvec, char **vec);
+static void choose_playchildren_played(void *v,
+                                       const char *err,
+                                       const char *id);
+
 /** @brief Popup menu */
 static GtkWidget *choose_menu;
 
 /** @brief Path to directory pending a "select children" operation */
 static GtkTreePath *choose_eventually_select_children;
 
-/** @brief Recursion step for choose_get_visible()
- * @param parent A visible node, or NULL for the root
- * @param callback Called for each visible node
- * @param userdata Passed to @p callback
- *
- * If @p callback returns nonzero, the walk stops immediately.
- */
-static int choose_visible_recurse(GtkTreeIter *parent,
-                                  int (*callback)(GtkTreeIter *it,
-                                                  int isfile,
-                                                  void *userdata),
-                                  void *userdata) {
-  int expanded;
-  if(parent) {
-    /* Skip placeholders */
-    if(choose_is_placeholder(parent))
-      return 0;
-    const int isfile = choose_is_file(parent);
-    if(callback(parent, isfile, userdata))
-      return 1;
-    if(isfile)
-      return 0;                 /* Files never have children */
-    GtkTreePath *parent_path
-      = gtk_tree_model_get_path(GTK_TREE_MODEL(choose_store),
-                                parent);
-    expanded = gtk_tree_view_row_expanded(GTK_TREE_VIEW(choose_view),
-                                          parent_path);
-    gtk_tree_path_free(parent_path);
-  } else
-    expanded = 1;
-  /* See if parent is expanded */
-  if(expanded) {
-    /* Parent is expanded, visit all its children */
-    GtkTreeIter it[1];
-    gboolean itv = gtk_tree_model_iter_children(GTK_TREE_MODEL(choose_store),
-                                                it,
-                                                parent);
-    while(itv) {
-      if(choose_visible_recurse(it, callback, userdata))
-        return TRUE;
-      itv = gtk_tree_model_iter_next(GTK_TREE_MODEL(choose_store), it);
-    }
-  }
-  return 0;
-}
-
 /** @brief Should edit->select all be sensitive?  No, for the choose tab. */
 static int choose_selectall_sensitive(void attribute((unused)) *extra) {
   return FALSE;
@@ -153,7 +118,7 @@ static void choose_play_activate(GtkMenuItem attribute((unused)) *item,
                                       choose_gather_selected_files_callback,
                                       v);
   for(int n = 0; n < v->nvec; ++n)
-    disorder_eclient_play(client, v->vec[n], choose_play_completed, 0);
+    disorder_eclient_play(client, choose_play_completed, v->vec[n], 0);
 }
   
 static int choose_properties_sensitive(void *extra) {
@@ -167,7 +132,7 @@ static void choose_properties_activate(GtkMenuItem attribute((unused)) *item,
   gtk_tree_selection_selected_foreach(choose_selection,
                                       choose_gather_selected_files_callback,
                                       v);
-  properties(v->nvec, (const char **)v->vec);
+  properties(v->nvec, (const char **)v->vec, toplevel);
 }
 
 /** @brief Set sensitivity for select children
@@ -256,10 +221,54 @@ static void choose_selectchildren_activate
                                       0);
 }
 
+/** @brief Play all children */
+static void choose_playchildren_activate
+    (GtkMenuItem attribute((unused)) *item,
+     gpointer attribute((unused)) userdata) {
+  /* Only one thing is selected */
+  gtk_tree_selection_selected_foreach(choose_selection,
+                                      choose_playchildren_callback,
+                                      0);
+}
+
+static void choose_playchildren_callback(GtkTreeModel attribute((unused)) *model,
+                                         GtkTreePath *path,
+                                         GtkTreeIter *iter,
+                                         gpointer attribute((unused)) data) {
+  /* Find the children and play them */
+  disorder_eclient_files(client, choose_playchildren_received,
+                         choose_get_track(iter),
+                         NULL/*re*/,
+                         NULL);
+  /* Expand the node */
+  gtk_tree_view_expand_row(GTK_TREE_VIEW(choose_view), path, FALSE);
+}
+
+static void choose_playchildren_received(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, choose_playchildren_played, vec[n], NULL);
+}
+
+static void choose_playchildren_played(void attribute((unused)) *v,
+                                       const char *err,
+                                       const char attribute((unused)) *id) {
+  if(err) {
+    popup_protocol_error(0, err);
+    return;
+  }
+}
+
 /** @brief Pop-up menu for choose */
 static struct menuitem choose_menuitems[] = {
   {
     "Play track",
+    GTK_STOCK_MEDIA_PLAY,
     choose_play_activate,
     choose_play_sensitive,
     0,
@@ -267,6 +276,7 @@ static struct menuitem choose_menuitems[] = {
   },
   {
     "Track properties",
+    GTK_STOCK_PROPERTIES,
     choose_properties_activate,
     choose_properties_sensitive,
     0,
@@ -274,13 +284,23 @@ static struct menuitem choose_menuitems[] = {
   },
   {
     "Select children",
+    NULL,
     choose_selectchildren_activate,
     choose_selectchildren_sensitive,
     0,
     0
   },
+  {
+    "Play children",
+    NULL,
+    choose_playchildren_activate,
+    choose_selectchildren_sensitive,    /* re-use */
+    0,
+    0
+  },
   {
     "Deselect all tracks",
+    NULL,
     choose_selectnone_activate,
     choose_selectnone_sensitive,
     0,