[Xfce4-commits] <xfce4-clipman-plugin:master> Update code to show the documentation with new location

Mike Massonnet noreply at xfce.org
Mon Oct 24 15:50:01 CEST 2011


Updating branch refs/heads/master
         to 2f3866d5989083218e6c6c38a109fabdd8e19eac (commit)
       from d0b74440f5d441c6518c8421445679849413ddcb (commit)

commit 2f3866d5989083218e6c6c38a109fabdd8e19eac
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Mon Oct 24 01:05:31 2011 +0200

    Update code to show the documentation with new location
    
    The code tries to find the new location of the localized documentation
    otherwise to fallback on the online documentation.

 panel-plugin/Makefile.am              |    1 +
 panel-plugin/xfce4-clipman-settings.c |   45 ++++++++++++++++++++++-----------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 75c354b..cf8a218 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -5,6 +5,7 @@ INCLUDES =								\
 	-DSYSCONFDIR=\"$(sysconfdir)\"					\
 	-DDATAROOTDIR=\"$(datarootdir)\"				\
 	-DDATADIR=\"$(datadir)\"					\
+	-DDOCDIR=\"$(docdir)\"						\
 	-DSRCDIR=\"$(top_srcdir)\"					\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
 	$(NULL)
diff --git a/panel-plugin/xfce4-clipman-settings.c b/panel-plugin/xfce4-clipman-settings.c
index d796d57..f1672f4 100644
--- a/panel-plugin/xfce4-clipman-settings.c
+++ b/panel-plugin/xfce4-clipman-settings.c
@@ -167,9 +167,10 @@ cb_show_help (GtkButton *button)
 {
   gchar *locale = NULL;
   gchar *offset;
-  gchar *filename = NULL;
+  gchar *docpath = NULL;
   gchar *command = NULL;
   
+  /* Find localized documentation path on disk */
 #ifdef ENABLE_NLS
 #ifdef HAVE_LOCALE_H
   locale = g_strdup (setlocale (LC_MESSAGES, ""));
@@ -185,47 +186,61 @@ cb_show_help (GtkButton *button)
   locale = g_strdup ("C");
 #endif
 
-  filename = g_strdup_printf ("file://"DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
-  if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+  docpath = g_strdup_printf (DOCDIR"/html/%s/index.html", locale);
+  if (!g_file_test (docpath, G_FILE_TEST_EXISTS))
     {
       offset = g_strrstr (locale, "_");
       if (offset == NULL)
         {
-          g_free (filename);
-          filename = g_strdup ("file://"DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+          g_free (docpath);
+          docpath = g_strdup (DOCDIR"/html/C/index.html");
         }
       else
         {
           *offset = '\0';
-          g_free (filename);
-          filename = g_strdup_printf ("file://"DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
-          if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+          g_free (docpath);
+          docpath = g_strdup_printf (DOCDIR"/html/%s/index.html", locale);
+          if (!g_file_test (docpath, G_FILE_TEST_EXISTS))
             {
-              g_free (filename);
-              filename = g_strdup ("file://"DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+              g_free (docpath);
+              docpath = g_strdup (DOCDIR"/html/C/index.html");
             }
         }
     }
 
   g_free (locale);
 #else
-  filename = g_strdup ("file://"DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+  docpath = g_strdup (DOCDIR"/html/C/index.html");
 #endif
 
-  command = g_strdup_printf ("exo-open --launch WebBrowser %s", filename);
+  /* Revert to online documentation if not available on disk */
+  if (g_file_test (docpath, G_FILE_TEST_EXISTS))
+    {
+      gchar *tmp = docpath;
+      docpath = g_strdup_printf ("file://%s", docpath);
+      g_free (tmp);
+    }
+  else
+    {
+      g_free (docpath);
+      docpath = g_strdup ("http://docs.xfce.org/help.php?package=xfce4-clipman-plugin");
+    }
+
+  /* Open documentation in webbrowser */
+  command = g_strdup_printf ("exo-open --launch WebBrowser %s", docpath);
   if (g_spawn_command_line_async (command, NULL))
     goto out;
 
   g_free (command);
-  command = g_strdup_printf ("firefox %s", filename);
+  command = g_strdup_printf ("firefox %s", docpath);
   if (g_spawn_command_line_async (command, NULL))
     goto out;
 
   xfce_dialog_show_error (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))),
-                          NULL, "Unable to open documentation \"%s\"", filename);
+                          NULL, "Unable to open documentation \"%s\"", docpath);
 
 out:
-  g_free (filename);
+  g_free (docpath);
   g_free (command);
 }
 


More information about the Xfce4-commits mailing list