chiark / gitweb /
Fill playlist queulike. Selection is borked.
[disorder] / disobedience / queue-generic.c
index ce8f7be05d28563038f92d2ddb3bfe31b229cf3e..2f8aa709a1601439addb687a9070a98ffcb25b40 100644 (file)
@@ -438,6 +438,8 @@ void ql_new_queue(struct queuelike *ql,
  * This is used by ql_drag_motion() and ql_drag_data_received() to identify a
  * drop would or does land.  It's important that they use the same code since
  * otherwise the visual feedback can be inconsistent with the actual effect!
+ *
+ * Remember to free the returned path.
  */
 static GtkTreePath *ql_drop_path(GtkWidget *w,
                                  GtkTreeModel *model,
@@ -542,14 +544,6 @@ static gboolean ql_drag_motion(GtkWidget *w,
     if(path)
       gtk_tree_path_free(path);
   }
-  /* TODO _something_ is not quite right here.  Supposedly if action=0 we
-   * should probably be returning FALSE; _but_ actually we always want to
-   * support dropping, as dropping into the big empty space at the bottom
-   * should be the same as dropping at the end of the last row.
-   *
-   * As the code stands the drop works but the visual feedback is not quite
-   * right.
-   */
   autoscroll_add(GTK_TREE_VIEW(w));
   return TRUE;                          /* We are (always) in a drop zone */
 }
@@ -726,6 +720,8 @@ static void ql_drag_data_received(GtkWidget attribute((unused)) *w,
     ql->drop(ql, tracks->nvec, tracks->vec, NULL, q);
     break;
   }
+  if(path)
+    gtk_tree_path_free(path);
 }
 
 /** @brief Initialize a @ref queuelike */
@@ -767,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));
+  g_object_ref(ql->selection);
   gtk_tree_selection_set_mode(ql->selection, GTK_SELECTION_MULTIPLE);
 
   /* Catch button presses */
@@ -828,7 +825,8 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
   
   /* 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);
@@ -838,6 +836,31 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
   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