]> Pileus Git - ~andy/gtk/commitdiff
recent-manager: Add RecentInfo.create_app_info()
authorEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 22 Oct 2010 10:42:39 +0000 (11:42 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 22 Oct 2010 10:54:53 +0000 (11:54 +0100)
A simple wrapper that makes it possible to create a GAppInfo from a
GtkRecentInfo blob.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkrecentmanager.c
gtk/gtkrecentmanager.h

index 1f488eef65743908bc5ab7d56e698a93f5575894..fc73186672512a190e1ca48c84415279291c7334 100644 (file)
@@ -2620,9 +2620,10 @@ gtk_recent_info_get_private_hint
 gtk_recent_info_get_application_info
 gtk_recent_info_get_applications
 gtk_recent_info_last_application
+gtk_recent_info_has_application
+gtk_recent_info_create_app_info
 gtk_recent_info_get_groups
 gtk_recent_info_has_group
-gtk_recent_info_has_application
 gtk_recent_info_get_icon
 gtk_recent_info_get_short_name
 gtk_recent_info_get_uri_display
index 3abfd5e59a7ff97e7d61a4a91442a159458e22cc..b968d7a09efcf6574b57196aacbf7a533e78291c 100644 (file)
@@ -2793,6 +2793,7 @@ gtk_recent_info_get_application_info
 gtk_recent_info_get_applications G_GNUC_MALLOC
 gtk_recent_info_last_application G_GNUC_MALLOC
 gtk_recent_info_has_application
+gtk_recent_info_create_app_info
 gtk_recent_info_get_groups G_GNUC_MALLOC
 gtk_recent_info_has_group
 gtk_recent_info_get_icon
index 7e3aff0c9b630ae9edc79867f089676fe50bf61c..a53b1b8092e63314ab0d6c9034a9add84d63c0f3 100644 (file)
@@ -2316,6 +2316,72 @@ gtk_recent_info_has_group (GtkRecentInfo *info,
   return FALSE;
 }
 
+/**
+ * gtk_recent_info_create_app_info:
+ * @info: a #GtkRecentInfo
+ * @app_name: (allow-none): the name of the application that should
+ *   be mapped to a #GAppInfo; if %NULL is used then the default
+ *   application for the MIME type is used
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Creates a #GAppInfo for the specified #GtkRecentInfo
+ *
+ * Return value: (transfer full): the newly created #GAppInfo, or %NULL.
+ *   In case of error, @error will be set either with a
+ *   %GTK_RECENT_MANAGER_ERROR or a %G_IO_ERROR
+ */
+GAppInfo *
+gtk_recent_info_create_app_info (GtkRecentInfo  *info,
+                                 const gchar    *app_name,
+                                 GError        **error)
+{
+  RecentAppInfo *ai;
+  GAppInfo *app_info;
+  GError *internal_error = NULL;
+
+  g_return_val_if_fail (info != NULL, NULL);
+
+  if (app_name == NULL || *app_name == '\0')
+    {
+      char *content_type;
+
+      if (info->mime_type == NULL)
+        return NULL;
+
+      content_type = g_content_type_from_mime_type (info->mime_type);
+      if (content_type == NULL)
+        return NULL;
+
+      app_info = g_app_info_get_default_for_type (content_type, TRUE);
+      g_free (content_type);
+
+      return app_info;
+    }
+
+  ai = g_hash_table_lookup (info->apps_lookup, app_name);
+  if (ai == NULL)
+    {
+      g_set_error (error, GTK_RECENT_MANAGER_ERROR,
+                   GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED,
+                   _("No registered application with name '%s' for item with URI '%s' found"),
+                   app_name,
+                   info->uri);
+      return NULL;
+    }
+
+  internal_error = NULL;
+  app_info = g_app_info_create_from_commandline (ai->exec, ai->name,
+                                                 G_APP_INFO_CREATE_NONE,
+                                                 &internal_error);
+  if (internal_error != NULL)
+    {
+      g_propagate_error (error, internal_error);
+      return NULL;
+    }
+
+  return app_info;
+}
+
 /*
  * _gtk_recent_manager_sync:
  * 
index b9a56791b28eda63d26c0728c6c7aad8cc8105f0..df5ce0ecdd2fdd8ac64d70cb05ed9ed4716f3309 100644 (file)
@@ -204,6 +204,9 @@ gboolean              gtk_recent_info_get_application_info (GtkRecentInfo  *info
                                                            const gchar   **app_exec,
                                                            guint          *count,
                                                            time_t         *time_);
+GAppInfo *            gtk_recent_info_create_app_info      (GtkRecentInfo  *info,
+                                                            const gchar    *app_name,
+                                                            GError        **error);
 gchar **              gtk_recent_info_get_applications     (GtkRecentInfo  *info,
                                                            gsize          *length) G_GNUC_MALLOC;
 gchar *               gtk_recent_info_last_application     (GtkRecentInfo  *info) G_GNUC_MALLOC;