chiark / gitweb /
Disobedience can now adopt tracks.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 13 Dec 2008 16:07:06 +0000 (16:07 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 13 Dec 2008 16:07:06 +0000 (16:07 +0000)
disobedience/queue-generic.h
disobedience/queue-menu.c
disobedience/queue.c

index b73d90a..4b31fe9 100644 (file)
@@ -134,6 +134,9 @@ void ql_remove_activate(GtkMenuItem *menuitem,
 int ql_play_sensitive(void *extra);
 void ql_play_activate(GtkMenuItem *menuitem,
                       gpointer user_data);
+int ql_adopt_sensitive(void *extra);
+void ql_adopt_activate(GtkMenuItem *menuitem,
+                       gpointer user_data);
 gboolean ql_button_release(GtkWidget *widget,
                            GdkEventButton *event,
                            gpointer user_data);
index 8111205..beb40f5 100644 (file)
@@ -187,6 +187,64 @@ gboolean ql_button_release(GtkWidget *widget,
   return FALSE;
 }
 
+/* Adopt */
+
+static void ql_adopt_sensitive_callback(GtkTreeModel *model,
+                                        GtkTreePath attribute((unused)) *path,
+                                        GtkTreeIter *iter,
+                                        gpointer data) {
+  struct queue_entry *const q = ql_iter_to_q(model, iter);
+  int *const count = data;
+
+  if(*count < 0)
+    return;
+  if(q->origin == origin_random)
+    ++*count;
+  else
+    *count = -1;
+}
+
+/** @brief Determine whether we're pointing at an adoptable track */
+int ql_adopt_sensitive(void *extra) {
+  struct queuelike *ql = extra;
+  int count = 0;
+
+  /* We'll need RIGHT_PLAY */
+  if(!(last_rights & RIGHT_PLAY))
+    return FALSE;
+  /* Check that (1) only random tracks are selected (2) at least something is
+   * selected */
+  gtk_tree_selection_selected_foreach(ql->selection,
+                                      ql_adopt_sensitive_callback,
+                                      &count);
+  if(count <= 0)
+    return FALSE;
+  return TRUE;
+}
+
+static void ql_adopt_completed(void attribute((unused)) *v, const char *err) {
+  if(err)
+    popup_protocol_error(0, err);
+}
+
+static void ql_adopt_activate_callback(GtkTreeModel *model,
+                                       GtkTreePath attribute((unused)) *path,
+                                       GtkTreeIter *iter,
+                                       gpointer attribute((unused)) data) {
+  struct queue_entry *const q = ql_iter_to_q(model, iter);
+
+  disorder_eclient_adopt(client, ql_adopt_completed, q->id, q);
+}
+
+/** @brief Called to adopt a track */
+void ql_adopt_activate(GtkMenuItem attribute((unused)) *menuitem,
+                       gpointer user_data) {
+  struct queuelike *ql = user_data;
+  gtk_tree_selection_selected_foreach(ql->selection,
+                                      ql_adopt_activate_callback,
+                                      NULL);
+}
+
 struct tabtype *ql_tabtype(struct queuelike *ql) {
   static const struct tabtype queuelike_tabtype = {
     ql_properties_sensitive,
index c19dbc9..f4e92a1 100644 (file)
@@ -166,6 +166,7 @@ static struct menuitem queue_menuitems[] = {
   { "Deselect all tracks", ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 },
   { "Scratch playing track", ql_scratch_activate, ql_scratch_sensitive, 0, 0 },
   { "Remove track from queue", ql_remove_activate, ql_remove_sensitive, 0, 0 },
+  { "Adopt track", ql_adopt_activate, ql_adopt_sensitive, 0, 0 },
 };
 
 struct queuelike ql_queue = {