[rhythmbox] metadata: add rb_metadata_get_saveable_types method
- From: Jonathan Matthew <jmatthew src gnome org>
- To: svn-commits-list gnome org
- Subject: [rhythmbox] metadata: add rb_metadata_get_saveable_types method
- Date: Wed, 10 Jun 2009 03:45:02 -0400 (EDT)
commit 765e3a5689042428c2403db9150d83ea0369c277
Author: Jonathan Matthew <jonathan d14n org>
Date: Wed Jun 10 17:34:44 2009 +1000
metadata: add rb_metadata_get_saveable_types method
This will be used to cache information on what media types can be
retagged. Not properly implemented in the dbus client yet.
---
metadata/rb-metadata-dbus-client.c | 17 +++++++++
metadata/rb-metadata-dbus-service.c | 63 ++++++++++++++++++++++++++++++++++-
metadata/rb-metadata-gst.c | 19 ++++++++++
metadata/rb-metadata.h | 1 +
4 files changed, 99 insertions(+), 1 deletions(-)
diff --git a/metadata/rb-metadata-dbus-client.c b/metadata/rb-metadata-dbus-client.c
index 24b35ee..0c62a71 100644
--- a/metadata/rb-metadata-dbus-client.c
+++ b/metadata/rb-metadata-dbus-client.c
@@ -83,6 +83,7 @@ static GPid metadata_child = 0;
static int metadata_stdout = -1;
static GMainContext *main_context = NULL;
static GStaticMutex conn_mutex = G_STATIC_MUTEX_INIT;
+static char **saveable_types = NULL;
struct RBMetaDataPrivate
{
@@ -691,6 +692,22 @@ rb_metadata_can_save (RBMetaData *md, const char *mimetype)
}
/**
+ * rb_metadata_get_saveable_types:
+ * @md: a #RBMetaData
+ *
+ * Constructs a list of the media types for which the metadata backend
+ * implements tag saving.
+ *
+ * Return value: a NULL-terminated array of media type strings. Use g_strfreev
+ * to free it.
+ */
+char **
+rb_metadata_get_saveable_types (RBMetaData *md)
+{
+ return g_strdupv (saveable_types);
+}
+
+/**
* rb_metadata_save:
* @md: a #RBMetaData
* @error: returns error information
diff --git a/metadata/rb-metadata-dbus-service.c b/metadata/rb-metadata-dbus-service.c
index 12c080b..9ed87db 100644
--- a/metadata/rb-metadata-dbus-service.c
+++ b/metadata/rb-metadata-dbus-service.c
@@ -189,6 +189,43 @@ rb_metadata_dbus_load (DBusConnection *connection,
}
static DBusHandlerResult
+rb_metadata_dbus_get_saveable_types (DBusConnection *connection,
+ DBusMessage *message,
+ ServiceData *svc)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ char **saveable_types;
+
+ /* construct reply */
+ reply = dbus_message_new_method_return (message);
+ if (!reply) {
+ rb_debug ("out of memory creating return message");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ dbus_message_iter_init_append (reply, &iter);
+
+ saveable_types = rb_metadata_get_saveable_types (svc->metadata);
+
+ if (!rb_metadata_dbus_add_strv (&iter, saveable_types)) {
+ rb_debug ("out of memory adding saveable types to return message");
+ g_strfreev (saveable_types);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ g_strfreev (saveable_types);
+
+ if (!dbus_connection_send (connection, reply, NULL)) {
+ rb_debug ("failed to send return message");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
rb_metadata_dbus_can_save (DBusConnection *connection,
DBusMessage *message,
ServiceData *svc)
@@ -346,12 +383,14 @@ _handle_message (DBusConnection *connection, DBusMessage *message, void *data)
{
ServiceData *svc = (ServiceData *)data;
DBusHandlerResult result;
- rb_debug ("handling metadata service message");
+ rb_debug ("handling metadata service message: %s", dbus_message_get_member (message));
if (dbus_message_is_method_call (message, RB_METADATA_DBUS_INTERFACE, "load")) {
result = rb_metadata_dbus_load (connection, message, svc);
} else if (dbus_message_is_method_call (message, RB_METADATA_DBUS_INTERFACE, "canSave")) {
result = rb_metadata_dbus_can_save (connection, message, svc);
+ } else if (dbus_message_is_method_call (message, RB_METADATA_DBUS_INTERFACE, "getSaveableTypes")) {
+ result = rb_metadata_dbus_get_saveable_types (connection, message, svc);
} else if (dbus_message_is_method_call (message, RB_METADATA_DBUS_INTERFACE, "save")) {
result = rb_metadata_dbus_save (connection, message, svc);
} else if (dbus_message_is_method_call (message, RB_METADATA_DBUS_INTERFACE, "ping")) {
@@ -409,6 +448,25 @@ test_can_save (const char *mimetype)
}
static int
+test_saveable_types ()
+{
+ RBMetaData *md;
+ char **saveable;
+ int i;
+
+ md = rb_metadata_new ();
+ saveable = rb_metadata_get_saveable_types (md);
+ g_object_unref (md);
+
+ for (i = 0; saveable[i] != NULL; i++) {
+ g_print ("%s\n", saveable[i]);
+ }
+ g_strfreev (saveable);
+
+ return 0;
+}
+
+static int
test_load (const char *uri)
{
RBMetaData *md;
@@ -493,6 +551,9 @@ main (int argc, char **argv)
if (argv[1] != NULL && strcmp(argv[1], "--can-save") == 0) {
return test_can_save (argv[2]);
}
+ if (argv[1] != NULL && strcmp(argv[1], "--saveable-types") == 0) {
+ return test_saveable_types ();
+ }
if (argv[1] != NULL && strcmp (argv[1], "--external") == 0) {
argv++;
diff --git a/metadata/rb-metadata-gst.c b/metadata/rb-metadata-gst.c
index 8aa3b4b..4936ade 100644
--- a/metadata/rb-metadata-gst.c
+++ b/metadata/rb-metadata-gst.c
@@ -863,6 +863,25 @@ rb_metadata_can_save (RBMetaData *md, const char *mimetype)
return g_hash_table_lookup (md->priv->taggers, mimetype) != NULL;
}
+char **
+rb_metadata_get_saveable_types (RBMetaData *md)
+{
+ GHashTableIter iter;
+ gpointer key;
+ gpointer value;
+ char **types;
+ int i;
+
+ types = g_new0 (char *, g_hash_table_size (md->priv->taggers) + 1);
+ i = 0;
+ g_hash_table_iter_init (&iter, md->priv->taggers);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ types[i++] = g_strdup ((const char *) key);
+ }
+
+ return types;
+}
+
static void
rb_metadata_gst_add_tag_data (gpointer key, const GValue *val, RBMetaData *md)
{
diff --git a/metadata/rb-metadata.h b/metadata/rb-metadata.h
index 8c746c0..c8d550b 100644
--- a/metadata/rb-metadata.h
+++ b/metadata/rb-metadata.h
@@ -120,6 +120,7 @@ const char * rb_metadata_get_field_name (RBMetaDataField field);
RBMetaData * rb_metadata_new (void);
gboolean rb_metadata_can_save (RBMetaData *md, const char *mimetype);
+char ** rb_metadata_get_saveable_types (RBMetaData *md);
void rb_metadata_load (RBMetaData *md,
const char *uri,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]