[gtk+] recent-manager: Add RecentInfo.create_app_info()



commit 03fc0dd5caf6e88f02574be4af34c9c79b6940aa
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Oct 22 11:42:39 2010 +0100

    recent-manager: Add RecentInfo.create_app_info()
    
    A simple wrapper that makes it possible to create a GAppInfo from a
    GtkRecentInfo blob.

 docs/reference/gtk/gtk3-sections.txt |    3 +-
 gtk/gtk.symbols                      |    1 +
 gtk/gtkrecentmanager.c               |   66 ++++++++++++++++++++++++++++++++++
 gtk/gtkrecentmanager.h               |    3 ++
 4 files changed, 72 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 1f488ee..fc73186 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -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
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 3abfd5e..b968d7a 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -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
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index 7e3aff0..a53b1b8 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -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:
  * 
diff --git a/gtk/gtkrecentmanager.h b/gtk/gtkrecentmanager.h
index b9a5679..df5ce0e 100644
--- a/gtk/gtkrecentmanager.h
+++ b/gtk/gtkrecentmanager.h
@@ -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;



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