3 * Copyright (C) 2008 The Geeqie Team
5 * Authors: Vladimir Nadvornik / Laurent Monin
7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
16 #include "pixbuf_util.h"
17 #include "ui_fileops.h"
20 GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon,
21 const gchar *icon_file, const gchar *subtitle)
26 window = gtk_window_new(type);
27 if (!window) return NULL;
31 title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME);
35 title = g_strdup_printf("%s", GQ_APPNAME);
38 gtk_window_set_title(GTK_WINDOW(window), title);
41 window_set_icon(window, icon, icon_file);
42 gtk_window_set_role(GTK_WINDOW(window), name);
47 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file)
49 if (!icon && !file) icon = PIXBUF_INLINE_ICON;
55 pixbuf = pixbuf_inline(icon);
58 gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
59 g_object_unref(pixbuf);
64 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL);
68 gint window_maximized(GtkWidget *window)
72 if (!window || !window->window) return FALSE;
74 state = gdk_window_get_state(window->window);
75 return (state & GDK_WINDOW_STATE_MAXIMIZED);
79 *-----------------------------------------------------------------------------
80 * Open browser with the help Documentation
81 *-----------------------------------------------------------------------------
84 static gchar *command_result(const gchar *binary, const gchar *command)
91 if (!binary || binary[0] == '\0') return NULL;
92 if (!file_in_path(binary)) return NULL;
94 if (!command || command[0] == '\0') return g_strdup(binary);
95 if (command[0] == '!') return g_strdup(command + 1);
97 f = popen(command, "r");
100 while ((l = fread(buf, sizeof(gchar), sizeof(buf), f)) > 0)
106 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++;
107 if (n > 0) result = g_strndup(buf, n);
116 static int help_browser_command(const gchar *command, const gchar *path)
124 if (!command || !path) return retval;
126 DEBUG_1("Help command pre \"%s\", \"%s\"", command, path);
128 buf = g_strdup(command);
129 begin = strstr(buf, "%s");
136 result = g_strdup_printf("%s%s%s &", begin, path, end);
140 result = g_strdup_printf("%s \"%s\" &", command, path);
144 DEBUG_1("Help command post [%s]", result);
146 retval = runcmd(result);
147 DEBUG_1("Help command exit code: %d", retval);
154 * each set of 2 strings is one browser:
155 * the 1st is the binary to look for in the path
156 * the 2nd has 3 capabilities:
157 * NULL exec binary with html file path as command line
158 * string exec string and use results for command line
159 * !string use text following ! as command line, replacing optional %s with html file path
161 static gchar *html_browsers[] =
163 /* Our specific script */
164 GQ_APPNAME_LC "_html_browser", NULL,
165 /* Redhat has a nifty htmlview script to start the user's preferred browser */
167 /* Debian has even better approach with alternatives */
168 "sensible-browser", NULL,
170 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command",
172 "kfmclient", "!kfmclient exec \"%s\"",
181 static void help_browser_run(void)
183 gchar *name = options->helpers.html_browser.command_name;
184 gchar *cmd = options->helpers.html_browser.command_line;
185 gchar *path = g_build_filename(options->documentation.htmldir, "index.html", NULL);
186 gchar *result = NULL;
192 if ((name && *name) || (cmd && *cmd)) {
193 DEBUG_1("Trying browser: name=%s command=%s", name, cmd);
194 result = command_result(name, cmd);
195 DEBUG_1("Result: %s", result);
198 int ret = help_browser_command(result, path);
205 if (!html_browsers[i]) break;
206 name = html_browsers[i++];
207 cmd = html_browsers[i++];
212 log_printf("Unable to detect an installed browser.\n");
221 *-----------------------------------------------------------------------------
223 *-----------------------------------------------------------------------------
226 static GtkWidget *help_window = NULL;
228 static void help_window_destroy_cb(GtkWidget *window, gpointer data)
233 void help_window_show(const gchar *key)
237 if (key && strcmp(key, "html_contents") == 0)
245 gtk_window_present(GTK_WINDOW(help_window));
246 if (key) help_window_set_key(help_window, key);
250 path = g_build_filename(options->documentation.helpdir, "README", NULL);
251 help_window = help_window_new(_("Help"), "help", path, key);
254 g_signal_connect(G_OBJECT(help_window), "destroy",
255 G_CALLBACK(help_window_destroy_cb), NULL);
258 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */