[libpeas] Added a Help button to the plugin manager



commit c2576707f353721f084e379786e0f032390e8970
Author: Garrett Regier <alias301 gmail com>
Date:   Tue Jul 20 11:56:49 2010 -0700

    Added a Help button to the plugin manager
    
    The help button is added automatically to the plugin configuration
    dialog if the plugin-info file contains a Help: key containing a valid
    URI (either http:// or ghelp://). Platform specific overrides are
    supported as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=623370

 docs/reference/libpeas-sections.txt                |    1 +
 libpeas/peas-plugin-info-priv.h                    |    1 +
 libpeas/peas-plugin-info.c                         |   37 +++++++++
 libpeas/peas-plugin-info.h                         |    1 +
 libpeasui/peas-ui-plugin-manager.c                 |   83 ++++++++++++++++++++
 .../plugins/helloworld/helloworld.peasdemo-plugin  |    1 +
 .../pythonhello/pythonhello.peasdemo-plugin        |    4 +
 7 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libpeas-sections.txt b/docs/reference/libpeas-sections.txt
index cd3b359..fc0e3fb 100644
--- a/docs/reference/libpeas-sections.txt
+++ b/docs/reference/libpeas-sections.txt
@@ -188,6 +188,7 @@ peas_plugin_info_get_data_dir
 peas_plugin_info_get_name
 peas_plugin_info_get_description
 peas_plugin_info_get_icon_name
+peas_plugin_info_get_help_uri
 peas_plugin_info_get_authors
 peas_plugin_info_get_website
 peas_plugin_info_get_copyright
diff --git a/libpeas/peas-plugin-info-priv.h b/libpeas/peas-plugin-info-priv.h
index 10de82c..ef4e6cf 100644
--- a/libpeas/peas-plugin-info-priv.h
+++ b/libpeas/peas-plugin-info-priv.h
@@ -44,6 +44,7 @@ struct _PeasPluginInfo {
   gchar *copyright;
   gchar *website;
   gchar *version;
+  gchar *help_uri;
   guint iage;
   GHashTable *keys;
 
diff --git a/libpeas/peas-plugin-info.c b/libpeas/peas-plugin-info.c
index 6023d8c..331bf9b 100644
--- a/libpeas/peas-plugin-info.c
+++ b/libpeas/peas-plugin-info.c
@@ -30,6 +30,14 @@
 #include "peas-i18n.h"
 #include "peas-plugin-info-priv.h"
 
+#ifdef G_OS_WIN32
+#define OS_HELP_KEY "Help-Windows"
+#elif defined(OS_OSX)
+#define OS_HELP_KEY "Help-MacOS-X"
+#else
+#define OS_HELP_KEY "Help-GNOME"
+#endif
+
 /**
  * SECTION:peas-plugin-info
  * @short_description: Information about a plugin.
@@ -64,6 +72,7 @@ _peas_plugin_info_unref (PeasPluginInfo *info)
   g_free (info->copyright);
   g_free (info->loader);
   g_free (info->version);
+  g_free (info->help_uri);
   g_strfreev (info->authors);
 
   g_free (info);
@@ -124,6 +133,7 @@ parse_extra_keys (PeasPluginInfo   *info,
           g_str_equal (keys[i], "Copyright") ||
           g_str_equal (keys[i], "Website") ||
           g_str_equal (keys[i], "Version") ||
+          g_str_has_prefix (keys[i], "Help") ||
           g_str_equal (keys[i], "Builtin"))
         continue;
 
@@ -288,6 +298,17 @@ _peas_plugin_info_new (const gchar *filename,
   if (str)
     info->version = str;
 
+  /* Get Help URI */
+  str = g_key_file_get_string (plugin_file, section_header, OS_HELP_KEY, NULL);
+  if (str)
+    info->help_uri = str;
+  else
+    {
+      str = g_key_file_get_string (plugin_file, section_header, "Help", NULL);
+      if (str)
+        info->help_uri = str;
+    }
+
   /* Get Builtin */
   b = g_key_file_get_boolean (plugin_file, section_header, "Builtin", &error);
   if (error != NULL)
@@ -541,6 +562,22 @@ peas_plugin_info_get_version (const PeasPluginInfo *info)
 }
 
 /**
+ * peas_plugin_info_get_help_uri:
+ * @info: A #PeasPluginInfo.
+ *
+ * Gets the help URI of the plugin.
+ *
+ * Returns: the plugin's help URI.
+ */
+const gchar *
+peas_plugin_info_get_help_uri (const PeasPluginInfo *info)
+{
+  g_return_val_if_fail (info != NULL, NULL);
+
+  return info->help_uri;
+}
+
+/**
  * peas_plugin_info_get_iage:
  * @info: A #PeasPluginInfo.
  *
diff --git a/libpeas/peas-plugin-info.h b/libpeas/peas-plugin-info.h
index 8afa7ba..d60deab 100644
--- a/libpeas/peas-plugin-info.h
+++ b/libpeas/peas-plugin-info.h
@@ -54,6 +54,7 @@ const gchar **peas_plugin_info_get_authors      (const PeasPluginInfo *info);
 const gchar  *peas_plugin_info_get_website      (const PeasPluginInfo *info);
 const gchar  *peas_plugin_info_get_copyright    (const PeasPluginInfo *info);
 const gchar  *peas_plugin_info_get_version      (const PeasPluginInfo *info);
+const gchar  *peas_plugin_info_get_help_uri     (const PeasPluginInfo *info);
 
 gint          peas_plugin_info_get_iage         (const PeasPluginInfo *info);
 const GHashTable *
diff --git a/libpeasui/peas-ui-plugin-manager.c b/libpeasui/peas-ui-plugin-manager.c
index 60089c8..96c90c6 100644
--- a/libpeasui/peas-ui-plugin-manager.c
+++ b/libpeasui/peas-ui-plugin-manager.c
@@ -28,6 +28,10 @@
 
 #include <string.h>
 
+#ifdef OS_OSX
+#include <Carbon/Carbon.h>
+#endif
+
 #include <libpeas/peas-engine.h>
 #include <libpeas/peas-plugin-info.h>
 #include <libpeas/peas-i18n.h>
@@ -136,6 +140,69 @@ show_about_cb (GtkWidget           *widget,
 }
 
 static void
+help_button_cb (GtkWidget      *button,
+                PeasPluginInfo *info)
+{
+  const gchar *help_uri;
+#ifndef OS_OSX
+  GError *error = NULL;
+  GtkWindow *toplevel;
+  GtkWidget *error_dlg;
+  GtkWindowGroup *wg;
+#endif
+
+  g_return_if_fail (peas_plugin_info_get_help_uri (info) != NULL);
+
+  help_uri = peas_plugin_info_get_help_uri (info);
+
+#ifdef OS_OSX
+  [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:help_uri]]];
+#else
+
+  gtk_show_uri (NULL,
+                help_uri,
+                GDK_CURRENT_TIME,
+                &error);
+
+  if (error == NULL)
+    return;
+
+  g_debug ("PeasUIPluginManager: could not show help uri: '%s'", help_uri);
+
+  toplevel = GTK_WINDOW (gtk_widget_get_toplevel (button));
+  error_dlg = gtk_message_dialog_new (toplevel,
+                                      0,
+                                      GTK_MESSAGE_ERROR,
+                                      GTK_BUTTONS_CLOSE,
+                                      _("There was an error displaying the help."));
+
+  g_signal_connect (error_dlg,
+                    "response",
+                    G_CALLBACK (gtk_widget_destroy), NULL);
+
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dlg),
+                                            "%s", error->message);
+
+  if (gtk_window_has_group (toplevel))
+    {
+      wg = gtk_window_get_group (toplevel);
+    }
+  else
+    {
+      wg = gtk_window_group_new ();
+      gtk_window_group_add_window (wg, toplevel);
+    }
+
+  gtk_window_group_add_window (wg, GTK_WINDOW (error_dlg));
+
+  gtk_window_set_modal (GTK_WINDOW (error_dlg), TRUE);
+  gtk_widget_show_all (error_dlg);
+
+  g_error_free (error);
+#endif
+}
+
+static void
 show_configure_cb (GtkWidget           *widget,
                    PeasUIPluginManager *pm)
 {
@@ -172,6 +239,22 @@ show_configure_cb (GtkWidget           *widget,
   vbox = gtk_dialog_get_content_area (GTK_DIALOG (conf_dlg));
   gtk_box_pack_start (GTK_BOX (vbox), conf_widget, TRUE, TRUE, 0);
 
+  if (peas_plugin_info_get_help_uri (info) != NULL)
+    {
+      GtkWidget *buttonbox;
+      GtkWidget *help_button;
+
+      buttonbox = gtk_dialog_get_action_area (GTK_DIALOG (conf_dlg));
+      help_button = gtk_button_new_from_stock (GTK_STOCK_HELP);
+      gtk_container_add (GTK_CONTAINER (buttonbox), help_button);
+      gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (buttonbox), help_button, TRUE);
+
+      g_signal_connect (help_button,
+                        "clicked",
+                        G_CALLBACK (help_button_cb),
+                        info);
+    }
+
   if (gtk_window_has_group (toplevel))
     {
       wg = gtk_window_get_group (toplevel);
diff --git a/peas-demo/plugins/helloworld/helloworld.peasdemo-plugin b/peas-demo/plugins/helloworld/helloworld.peasdemo-plugin
index cc6748e..65fa56b 100644
--- a/peas-demo/plugins/helloworld/helloworld.peasdemo-plugin
+++ b/peas-demo/plugins/helloworld/helloworld.peasdemo-plugin
@@ -6,3 +6,4 @@ Description=Inserts a box containing "Hello World" in every windows.
 Authors=Steve Frécinaux <code istique net>
 Copyright=Copyright © 2009 Steve Frécinaux
 Website=http://code.istique.net/
+Help=http://git.gnome.org/browse/libpeas
diff --git a/peas-demo/plugins/pythonhello/pythonhello.peasdemo-plugin b/peas-demo/plugins/pythonhello/pythonhello.peasdemo-plugin
index 33580d5..6318953 100644
--- a/peas-demo/plugins/pythonhello/pythonhello.peasdemo-plugin
+++ b/peas-demo/plugins/pythonhello/pythonhello.peasdemo-plugin
@@ -7,3 +7,7 @@ Description=Inserts a box containing "Python Says Hello" in every windows.
 Authors=Steve Frécinaux <code istique net>
 Copyright=Copyright © 2009 Steve Frécinaux
 Website=http://code.istique.net/
+Help=http://git.gnome.org/browse/error
+Help-Windows=http://git.gnome.org/browse/libpeas
+Help-MacOS-X=http://git.gnome.org/browse/libpeas
+Help-GNOME=http://git.gnome.org/browse/libpeas



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