[rhythmbox] source: add a method to specify the delete action for the source



commit f40432fb255b31c29f72f889cfbfe2fe4f68afef
Author: Jonathan Matthew <jonathan d14n org>
Date:   Wed Jan 13 22:37:34 2010 +1000

    source: add a method to specify the delete action for the source
    
    Since 'delete' means a variety of things depending on the source, we
    should use different names and descriptions to display it.  This allows
    each source to specify its own delete action.
    
    For a start, allow sources to distinguish between 'remove' and 'delete'.
    Remove just removes something from the library, whereas delete also
    removes the underlying resource.

 bindings/python/rb.defs     |   11 ++++++
 bindings/python/rb.override |   83 +++++++++++++++++++++++++++++++++++++++++++
 shell/rb-shell-clipboard.c  |    7 +++-
 sources/rb-source.c         |   26 +++++++++++++-
 sources/rb-source.h         |    2 +
 5 files changed, 126 insertions(+), 3 deletions(-)
---
diff --git a/bindings/python/rb.defs b/bindings/python/rb.defs
index 66e4fc5..400d755 100644
--- a/bindings/python/rb.defs
+++ b/bindings/python/rb.defs
@@ -1066,6 +1066,12 @@
   (return-type "GList*")
 )
 
+(define-method get_delete_action
+  (of-object "RBSource")
+  (c-name "rb_source_get_delete_action")
+  (return-type "char*")
+)
+
 (define-method gather_selected_properties
   (of-object "RBSource")
   (c-name "rb_source_gather_selected_properties")
@@ -1267,6 +1273,11 @@
   (return-type "GList*")
 )
 
+(define-virtual impl_get_delete_action
+  (of-object "RBSource")
+  (return-type "char*")
+)
+
 
 ;; From ../../sources/rb-sourcelist.h
 
diff --git a/bindings/python/rb.override b/bindings/python/rb.override
index c42df81..358ff06 100644
--- a/bindings/python/rb.override
+++ b/bindings/python/rb.override
@@ -1462,3 +1462,86 @@ _wrap_rb_streaming_source_get_progress(PyGObject *self)
     return tuple;
 }
 
+%%
+override RBSource__proxy_do_impl_get_delete_action
+static char *
+_wrap_RBSource__proxy_do_impl_get_delete_action(RBSource *self)
+{
+    PyGILState_STATE __py_state;
+    PyObject *py_self;
+    PyObject *py_retval;
+    PyObject *py_method;
+    char *ret = NULL;
+
+    __py_state = pyg_gil_state_ensure();
+    py_self = pygobject_new((GObject *) self);
+    if (!py_self) {
+        if (PyErr_Occurred())
+            PyErr_Print();
+        pyg_gil_state_release(__py_state);
+        return NULL;
+    }
+
+    py_method = PyObject_GetAttrString(py_self, "do_impl_get_delete_action");
+    if (!py_method) {
+        if (PyErr_Occurred())
+            PyErr_Print();
+        Py_DECREF(py_self);
+        pyg_gil_state_release(__py_state);
+        return NULL;
+    }
+    py_retval = PyObject_CallObject(py_method, NULL);
+    if (!py_retval) {
+        if (PyErr_Occurred())
+            PyErr_Print();
+        Py_DECREF(py_method);
+        Py_DECREF(py_self);
+        pyg_gil_state_release(__py_state);
+        return NULL;
+    }
+    if (py_retval == Py_None) {
+        if (PyErr_Occurred())
+            PyErr_Print();
+        PyErr_SetString(PyExc_TypeError, "retval was None");
+    } else if (PyString_Check(py_retval) == FALSE) {
+        /* nothing */
+    } else {
+	ret = g_strdup (PyString_AsString(py_retval));
+    }
+
+    Py_DECREF(py_retval);
+    Py_DECREF(py_method);
+    Py_DECREF(py_self);
+    pyg_gil_state_release(__py_state);
+
+    return ret;
+}
+
+%%
+override RBSource__do_impl_get_delete_action
+static PyObject *
+_wrap_RBSource__do_impl_get_delete_action(PyObject *cls, PyObject *args, PyObject *kwargs)
+{
+    gpointer klass;
+    static char *kwlist[] = { "self", NULL };
+    PyGObject *self;
+    PyObject *tuple;
+    char *key = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:RBSource.impl_get_delete_action", kwlist, &PyRBSource_Type, &self))
+	return NULL;
+
+    klass = g_type_class_ref(pyg_type_from_object(cls));
+    if (RB_SOURCE_CLASS(klass)->impl_get_delete_action) {
+	key = RB_SOURCE_CLASS(klass)->impl_get_delete_action(RB_SOURCE(self->obj));
+    } else {
+	PyErr_SetString(PyExc_NotImplementedError, "virtual method RBSource.impl_get_delete_action not implemented");
+	g_type_class_unref(klass);
+	return NULL;
+    }
+    g_type_class_unref(klass);
+
+    tuple = Py_BuildValue ("(s)", key);
+    g_free (key);
+    return tuple;
+}
diff --git a/shell/rb-shell-clipboard.c b/shell/rb-shell-clipboard.c
index 344f3fa..5a4df18 100644
--- a/shell/rb-shell-clipboard.c
+++ b/shell/rb-shell-clipboard.c
@@ -160,8 +160,11 @@ static GtkActionEntry rb_shell_clipboard_actions [] =
 	{ "EditPaste", GTK_STOCK_PASTE, N_("_Paste"), "<control>V",
 	  N_("Paste selection"),
 	  G_CALLBACK (rb_shell_clipboard_cmd_paste) },
-	{ "EditDelete", GTK_STOCK_REMOVE, N_("_Remove"), NULL,
-	  N_("Remove selection"),
+	{ "EditDelete", GTK_STOCK_DELETE, N_("_Delete"), NULL,
+	  N_("Delete each selected item"),
+	  G_CALLBACK (rb_shell_clipboard_cmd_delete) },
+	{ "EditRemove", GTK_STOCK_REMOVE, N_("_Remove"), NULL,
+	  N_("Remove each selected item from the library"),
 	  G_CALLBACK (rb_shell_clipboard_cmd_delete) },
 	{ "EditMovetoTrash", "user-trash", N_("_Move to Trash"), NULL,
 	  N_("Move selection to the trash"),
diff --git a/sources/rb-source.c b/sources/rb-source.c
index aafbe01..78e1811 100644
--- a/sources/rb-source.c
+++ b/sources/rb-source.c
@@ -76,6 +76,7 @@ static void default_get_status (RBSource *source, char **text, char **progress_t
 static void default_move_to_trash (RBSource *source);
 static GList * default_get_ui_actions (RBSource *source);
 static GList * default_get_search_actions (RBSource *source);
+static char *default_get_delete_action (RBSource *source);
 
 static void rb_source_post_entry_deleted_cb (GtkTreeModel *model,
 					     RhythmDBEntry *entry,
@@ -189,6 +190,7 @@ rb_source_class_init (RBSourceClass *klass)
 	klass->impl_get_status = default_get_status;
 	klass->impl_get_ui_actions = default_get_ui_actions;
 	klass->impl_get_search_actions = default_get_search_actions;
+	klass->impl_get_delete_action = default_get_delete_action;
 	klass->impl_move_to_trash = default_move_to_trash;
 
 	/**
@@ -365,7 +367,6 @@ rb_source_class_init (RBSourceClass *klass)
 							    RB_TYPE_SOURCE_SEARCH_TYPE,
 							    RB_SOURCE_SEARCH_NONE,
 							    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
 	/**
 	 * RBSource::deleted:
 	 * @source: the #RBSource
@@ -1573,6 +1574,29 @@ rb_source_get_search_actions (RBSource *source)
 	return klass->impl_get_search_actions (source);
 }
 
+static char *
+default_get_delete_action (RBSource *source)
+{
+	return g_strdup ("EditRemove");
+}
+
+/**
+ * rb_source_get_delete_action:
+ * @source: a #RBSource
+ *
+ * Returns the name of the UI action to use for 'delete'.
+ * This allows the source to customise the visible action name
+ * and description to better describe what deletion actually does.
+ *
+ * Return value: allocated string holding UI action name
+ */
+char *
+rb_source_get_delete_action (RBSource *source)
+{
+	RBSourceClass *klass = RB_SOURCE_GET_CLASS (source);
+	return klass->impl_get_delete_action (source);
+}
+
 static gboolean
 _update_status_idle (RBSource *source)
 {
diff --git a/sources/rb-source.h b/sources/rb-source.h
index 9d5f004..16acb19 100644
--- a/sources/rb-source.h
+++ b/sources/rb-source.h
@@ -139,6 +139,7 @@ struct _RBSourceClass
 	void		(*impl_deactivate)	(RBSource *source);
 	GList *		(*impl_get_ui_actions)	(RBSource *source);
 	GList *		(*impl_get_search_actions) (RBSource *source);
+	char *		(*impl_get_delete_action) (RBSource *source);
 };
 
 GType		rb_source_get_type		(void);
@@ -209,6 +210,7 @@ void		rb_source_deactivate		(RBSource *source);
 
 GList *		rb_source_get_ui_actions	(RBSource *source);
 GList *		rb_source_get_search_actions	(RBSource *source);
+char *		rb_source_get_delete_action	(RBSource *source);
 
 GList *		rb_source_gather_selected_properties (RBSource *source, RhythmDBPropType prop);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]