Improve ways to specify html browser (used for help, see bug 2015099).
authorLaurent Monin <geeqie@norz.org>
Sun, 13 Jul 2008 14:50:07 +0000 (14:50 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 13 Jul 2008 14:50:07 +0000 (14:50 +0000)
Two new rc file options were added:
- helpers.html_browser.command_name
- helpers.html_browser.command_line
These are checked first before trying common browser locations.
If these do not lead to a valid browser, then geeqie will
search for geeqie_html_browser script in the path, then
it will try various common browsers.

src/options.h
src/rcfile.c
src/window.c

index 49dcdc3..7b4b8ab 100644 (file)
@@ -38,6 +38,7 @@ struct _ConfOptions
 
        gboolean save_metadata_in_image_file;
 
+       /* start up */
        struct {
                gboolean restore_path;
                gboolean use_last_path;
@@ -237,6 +238,13 @@ struct _ConfOptions
 
        } color_profile;
 
+       /* Helpers programs */
+       struct {
+               struct {
+                       gchar *command_name;
+                       gchar *command_line;
+               } html_browser;
+       } helpers;
 };
 
 ConfOptions *options;
index d922343..bd197f0 100644 (file)
@@ -578,6 +578,18 @@ static gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
        WRITE_CHAR(shell.options);
 
 
+       WRITE_SUBTITLE("Helpers");
+       secure_fprintf(ssi, "# Html browser\n");
+       secure_fprintf(ssi, "# command_name is: the binary's name to look for in the path\n");
+       secure_fprintf(ssi, "# If command_name is empty, the program will try various common html browsers\n");
+       secure_fprintf(ssi, "# command_line is:\n");
+       secure_fprintf(ssi, "# \"\" (empty string)  = execute binary with html file path as command line\n");
+       secure_fprintf(ssi, "# \"string\"           = execute string and use results for command line\n");
+       secure_fprintf(ssi, "# \"!string\"          = use text following ! as command line, replacing optional %%s with html file path\n");
+       WRITE_CHAR(helpers.html_browser.command_name);
+       WRITE_CHAR(helpers.html_browser.command_line);
+
+
        WRITE_SUBTITLE("External Programs");
        secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS);
        secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS);
@@ -939,6 +951,10 @@ static gboolean load_options_from(const gchar *utf8_path, ConfOptions *options)
                READ_CHAR(shell.path);
                READ_CHAR(shell.options);
 
+               /* Helpers */
+               READ_CHAR(helpers.html_browser.command_name);
+               READ_CHAR(helpers.html_browser.command_line);
+
                /* External Programs */
 
                if (is_numbered_option(option, "external_", &i))
index bd54367..85f0383 100644 (file)
@@ -77,7 +77,7 @@ gint window_maximized(GtkWidget *window)
 
 /*
  *-----------------------------------------------------------------------------
- * Open  browser with the help Documentation
+ * Open browser with the help Documentation
  *-----------------------------------------------------------------------------
  */
 
@@ -85,13 +85,13 @@ static gchar *command_result(const gchar *binary, const gchar *command)
 {
        gchar *result = NULL;
        FILE *f;
-       char buf[2048];
-       int l;
+       gchar buf[2048];
+       gint l;
 
-       if (!binary) return NULL;
+       if (!binary || binary[0] == '\0') return NULL;
        if (!file_in_path(binary)) return NULL;
 
-       if (!command) return g_strdup(binary);
+       if (!command || command[0] == '\0') return g_strdup(binary);
        if (command[0] == '!') return g_strdup(command + 1);
 
        f = popen(command, "r");
@@ -101,7 +101,7 @@ static gchar *command_result(const gchar *binary, const gchar *command)
                {
                if (!result)
                        {
-                       int n = 0;
+                       gint n = 0;
 
                        while (n < l && buf[n] != '\n' && buf[n] != '\r') n++;
                        if (n > 0) result = g_strndup(buf, n);
@@ -157,6 +157,8 @@ static void help_browser_command(const gchar *command, const gchar *path)
 */
 static gchar *html_browsers[] =
 {
+       /* Our specific script */
+       GQ_APPNAME_LC "_html_browser", NULL,
        /* Redhat has a nifty htmlview script to start the user's preferred browser */
        "htmlview",     NULL,
        /* Debian has even better approach with alternatives */
@@ -175,9 +177,11 @@ static gchar *html_browsers[] =
 
 static void help_browser_run(void)
 {
-       gchar *result = NULL;
+       gchar *result;
        gint i;
 
+       result = command_result(options->helpers.html_browser.command_name, options->helpers.html_browser.command_line);
+
        i = 0;
        while (!result && html_browsers[i])
                {