Mercurial > geeqie
annotate src/window.c @ 1488:f96cc7807780
fixed a typo
author | nadvornik |
---|---|
date | Sun, 29 Mar 2009 19:57:19 +0000 |
parents | bc3f5c0432f6 |
children | df106a76897c |
rev | line source |
---|---|
648 | 1 /* |
2 * Geeqie | |
1284 | 3 * Copyright (C) 2008 - 2009 The Geeqie Team |
648 | 4 * |
5 * Authors: Vladimir Nadvornik / Laurent Monin | |
995 | 6 * |
648 | 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! | |
10 */ | |
11 | |
12 #include "main.h" | |
13 #include "window.h" | |
14 | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
15 #include "misc.h" |
648 | 16 #include "pixbuf_util.h" |
17 #include "ui_fileops.h" | |
18 #include "ui_help.h" | |
19 | |
1175
2518a4a73d89
Rename wmsubclass and name to role, which corresponds better to the purpose of the parameter as it ends to be passed to gtk_window_set_role().
zas_
parents:
1174
diff
changeset
|
20 GtkWidget *window_new(GtkWindowType type, const gchar *role, const gchar *icon, |
648 | 21 const gchar *icon_file, const gchar *subtitle) |
22 { | |
23 gchar *title; | |
24 GtkWidget *window; | |
25 | |
26 window = gtk_window_new(type); | |
27 if (!window) return NULL; | |
28 | |
29 if (subtitle) | |
30 { | |
31 title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME); | |
32 } | |
33 else | |
34 { | |
35 title = g_strdup_printf("%s", GQ_APPNAME); | |
36 } | |
37 | |
38 gtk_window_set_title(GTK_WINDOW(window), title); | |
39 g_free(title); | |
40 | |
41 window_set_icon(window, icon, icon_file); | |
1175
2518a4a73d89
Rename wmsubclass and name to role, which corresponds better to the purpose of the parameter as it ends to be passed to gtk_window_set_role().
zas_
parents:
1174
diff
changeset
|
42 gtk_window_set_role(GTK_WINDOW(window), role); |
648 | 43 |
44 return window; | |
45 } | |
46 | |
47 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file) | |
48 { | |
49 if (!icon && !file) icon = PIXBUF_INLINE_ICON; | |
50 | |
51 if (icon) | |
52 { | |
53 GdkPixbuf *pixbuf; | |
54 | |
55 pixbuf = pixbuf_inline(icon); | |
56 if (pixbuf) | |
57 { | |
58 gtk_window_set_icon(GTK_WINDOW(window), pixbuf); | |
59 g_object_unref(pixbuf); | |
60 } | |
61 } | |
62 else | |
63 { | |
64 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL); | |
65 } | |
66 } | |
67 | |
1453 | 68 gboolean window_maximized(GtkWidget *window) |
648 | 69 { |
70 GdkWindowState state; | |
71 | |
72 if (!window || !window->window) return FALSE; | |
73 | |
74 state = gdk_window_get_state(window->window); | |
1453 | 75 return !!(state & GDK_WINDOW_STATE_MAXIMIZED); |
648 | 76 } |
77 | |
78 /* | |
79 *----------------------------------------------------------------------------- | |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
80 * Open browser with the help Documentation |
648 | 81 *----------------------------------------------------------------------------- |
82 */ | |
83 | |
84 static gchar *command_result(const gchar *binary, const gchar *command) | |
85 { | |
86 gchar *result = NULL; | |
87 FILE *f; | |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
88 gchar buf[2048]; |
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
89 gint l; |
648 | 90 |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
91 if (!binary || binary[0] == '\0') return NULL; |
648 | 92 if (!file_in_path(binary)) return NULL; |
93 | |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
94 if (!command || command[0] == '\0') return g_strdup(binary); |
648 | 95 if (command[0] == '!') return g_strdup(command + 1); |
96 | |
97 f = popen(command, "r"); | |
98 if (!f) return NULL; | |
99 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
100 while ((l = fread(buf, sizeof(gchar), sizeof(buf), f)) > 0) |
648 | 101 { |
102 if (!result) | |
103 { | |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
104 gint n = 0; |
648 | 105 |
106 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++; | |
107 if (n > 0) result = g_strndup(buf, n); | |
108 } | |
109 } | |
110 | |
111 pclose(f); | |
112 | |
113 return result; | |
114 } | |
115 | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
116 static int help_browser_command(const gchar *command, const gchar *path) |
648 | 117 { |
118 gchar *result; | |
119 gchar *buf; | |
120 gchar *begin; | |
121 gchar *end; | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
122 int retval = -1; |
648 | 123 |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
124 if (!command || !path) return retval; |
648 | 125 |
126 DEBUG_1("Help command pre \"%s\", \"%s\"", command, path); | |
127 | |
128 buf = g_strdup(command); | |
129 begin = strstr(buf, "%s"); | |
130 if (begin) | |
131 { | |
132 *begin = '\0'; | |
133 end = begin + 2; | |
134 begin = buf; | |
135 | |
136 result = g_strdup_printf("%s%s%s &", begin, path, end); | |
137 } | |
138 else | |
139 { | |
140 result = g_strdup_printf("%s \"%s\" &", command, path); | |
141 } | |
142 g_free(buf); | |
143 | |
144 DEBUG_1("Help command post [%s]", result); | |
145 | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
146 retval = runcmd(result); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
147 DEBUG_1("Help command exit code: %d", retval); |
648 | 148 |
149 g_free(result); | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
150 return retval; |
648 | 151 } |
152 | |
153 /* | |
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 | |
160 */ | |
161 static gchar *html_browsers[] = | |
162 { | |
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
163 /* Our specific script */ |
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
164 GQ_APPNAME_LC "_html_browser", NULL, |
648 | 165 /* Redhat has a nifty htmlview script to start the user's preferred browser */ |
166 "htmlview", NULL, | |
883
391a9e3336db
Apply debian-specific patch to launch help browser (bug 2015099).
zas_
parents:
728
diff
changeset
|
167 /* Debian has even better approach with alternatives */ |
391a9e3336db
Apply debian-specific patch to launch help browser (bug 2015099).
zas_
parents:
728
diff
changeset
|
168 "sensible-browser", NULL, |
648 | 169 /* GNOME 2 */ |
170 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command", | |
171 /* KDE */ | |
172 "kfmclient", "!kfmclient exec \"%s\"", | |
173 /* use fallbacks */ | |
174 "firefox", NULL, | |
175 "mozilla", NULL, | |
176 "konqueror", NULL, | |
177 "netscape", NULL, | |
178 NULL, NULL | |
179 }; | |
180 | |
181 static void help_browser_run(void) | |
182 { | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
183 gchar *name = options->helpers.html_browser.command_name; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
184 gchar *cmd = options->helpers.html_browser.command_line; |
1267
dfa378900ec9
Remove harmful documentation.helpdir and documentation.htmldir options. These paths can still be modified through --with-readmedir and --htmldir configure options. Reported by Christopher Beland.
zas_
parents:
1175
diff
changeset
|
185 gchar *path = g_build_filename(GQ_HTMLDIR, "index.html", NULL); |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
186 gchar *result = NULL; |
648 | 187 gint i; |
188 | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
189 i = 0; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
190 while (!result) |
648 | 191 { |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
192 if ((name && *name) || (cmd && *cmd)) { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
193 DEBUG_1("Trying browser: name=%s command=%s", name, cmd); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
194 result = command_result(name, cmd); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
195 DEBUG_1("Result: %s", result); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
196 if (result) |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
197 { |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
198 int ret = help_browser_command(result, path); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
199 |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
200 if (ret == 0) break; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
201 g_free(result); |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
202 result = NULL; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
203 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
204 } |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
205 if (!html_browsers[i]) break; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
206 name = html_browsers[i++]; |
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
207 cmd = html_browsers[i++]; |
648 | 208 } |
209 | |
210 if (!result) | |
211 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
212 log_printf("Unable to detect an installed browser.\n"); |
648 | 213 return; |
214 } | |
215 | |
1013
88ebc61e33ae
Allow to override documentation paths through options:
zas_
parents:
1000
diff
changeset
|
216 g_free(path); |
648 | 217 g_free(result); |
218 } | |
219 | |
220 /* | |
221 *----------------------------------------------------------------------------- | |
222 * help window | |
223 *----------------------------------------------------------------------------- | |
224 */ | |
225 | |
226 static GtkWidget *help_window = NULL; | |
227 | |
228 static void help_window_destroy_cb(GtkWidget *window, gpointer data) | |
229 { | |
230 help_window = NULL; | |
231 } | |
232 | |
233 void help_window_show(const gchar *key) | |
234 { | |
1013
88ebc61e33ae
Allow to override documentation paths through options:
zas_
parents:
1000
diff
changeset
|
235 gchar *path; |
88ebc61e33ae
Allow to override documentation paths through options:
zas_
parents:
1000
diff
changeset
|
236 |
648 | 237 if (key && strcmp(key, "html_contents") == 0) |
238 { | |
239 help_browser_run(); | |
240 return; | |
241 } | |
242 | |
243 if (help_window) | |
244 { | |
245 gtk_window_present(GTK_WINDOW(help_window)); | |
246 if (key) help_window_set_key(help_window, key); | |
247 return; | |
248 } | |
249 | |
1267
dfa378900ec9
Remove harmful documentation.helpdir and documentation.htmldir options. These paths can still be modified through --with-readmedir and --htmldir configure options. Reported by Christopher Beland.
zas_
parents:
1175
diff
changeset
|
250 path = g_build_filename(GQ_HELPDIR, "README", NULL); |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1144
diff
changeset
|
251 help_window = help_window_new(_("Help"), "help", path, key); |
1013
88ebc61e33ae
Allow to override documentation paths through options:
zas_
parents:
1000
diff
changeset
|
252 g_free(path); |
648 | 253 |
254 g_signal_connect(G_OBJECT(help_window), "destroy", | |
255 G_CALLBACK(help_window_destroy_cb), NULL); | |
256 } | |
257 | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1013
diff
changeset
|
258 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |