Mercurial > geeqie
annotate src/window.c @ 995:6ca2c5fd7b13
Whitespaces cleanup.
| author | zas_ |
|---|---|
| date | Mon, 25 Aug 2008 22:20:45 +0000 |
| parents | ff16ed0d2c8a |
| children | 4fe8f9656107 |
| rev | line source |
|---|---|
| 648 | 1 /* |
| 2 * Geeqie | |
| 3 * Copyright (C) 2008 The Geeqie Team | |
| 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 | |
| 15 #include "pixbuf_util.h" | |
| 16 #include "ui_fileops.h" | |
| 17 #include "ui_help.h" | |
| 18 | |
| 19 GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon, | |
| 20 const gchar *icon_file, const gchar *subtitle) | |
| 21 { | |
| 22 gchar *title; | |
| 23 GtkWidget *window; | |
| 24 | |
| 25 window = gtk_window_new(type); | |
| 26 if (!window) return NULL; | |
| 27 | |
| 28 if (subtitle) | |
| 29 { | |
| 30 title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME); | |
| 31 } | |
| 32 else | |
| 33 { | |
| 34 title = g_strdup_printf("%s", GQ_APPNAME); | |
| 35 } | |
| 36 | |
| 37 gtk_window_set_title(GTK_WINDOW(window), title); | |
| 38 g_free(title); | |
| 39 | |
| 40 window_set_icon(window, icon, icon_file); | |
| 41 gtk_window_set_role(GTK_WINDOW(window), name); | |
| 42 gtk_window_set_wmclass(GTK_WINDOW(window), name, GQ_WMCLASS); | |
| 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 | |
| 68 gint window_maximized(GtkWidget *window) | |
| 69 { | |
| 70 GdkWindowState state; | |
| 71 | |
| 72 if (!window || !window->window) return FALSE; | |
| 73 | |
| 74 state = gdk_window_get_state(window->window); | |
| 75 return (state & GDK_WINDOW_STATE_MAXIMIZED); | |
| 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 | |
| 100 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0) | |
| 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 | |
| 116 static void help_browser_command(const gchar *command, const gchar *path) | |
| 117 { | |
| 118 gchar *result; | |
| 119 gchar *buf; | |
| 120 gchar *begin; | |
| 121 gchar *end; | |
| 122 | |
| 123 if (!command || !path) return; | |
| 124 | |
| 125 DEBUG_1("Help command pre \"%s\", \"%s\"", command, path); | |
| 126 | |
| 127 buf = g_strdup(command); | |
| 128 begin = strstr(buf, "%s"); | |
| 129 if (begin) | |
| 130 { | |
| 131 *begin = '\0'; | |
| 132 end = begin + 2; | |
| 133 begin = buf; | |
| 134 | |
| 135 result = g_strdup_printf("%s%s%s &", begin, path, end); | |
| 136 } | |
| 137 else | |
| 138 { | |
| 139 result = g_strdup_printf("%s \"%s\" &", command, path); | |
| 140 } | |
| 141 g_free(buf); | |
| 142 | |
| 143 DEBUG_1("Help command post [%s]", result); | |
| 144 | |
| 145 system(result); | |
| 146 | |
| 147 g_free(result); | |
| 148 } | |
| 149 | |
| 150 /* | |
| 151 * each set of 2 strings is one browser: | |
| 152 * the 1st is the binary to look for in the path | |
| 153 * the 2nd has 3 capabilities: | |
| 154 * NULL exec binary with html file path as command line | |
| 155 * string exec string and use results for command line | |
| 156 * !string use text following ! as command line, replacing optional %s with html file path | |
| 157 */ | |
| 158 static gchar *html_browsers[] = | |
| 159 { | |
|
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
160 /* Our specific script */ |
|
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
161 GQ_APPNAME_LC "_html_browser", NULL, |
| 648 | 162 /* Redhat has a nifty htmlview script to start the user's preferred browser */ |
| 163 "htmlview", NULL, | |
|
883
391a9e3336db
Apply debian-specific patch to launch help browser (bug 2015099).
zas_
parents:
728
diff
changeset
|
164 /* Debian has even better approach with alternatives */ |
|
391a9e3336db
Apply debian-specific patch to launch help browser (bug 2015099).
zas_
parents:
728
diff
changeset
|
165 "sensible-browser", NULL, |
| 648 | 166 /* GNOME 2 */ |
| 167 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command", | |
| 168 /* KDE */ | |
| 169 "kfmclient", "!kfmclient exec \"%s\"", | |
| 170 /* use fallbacks */ | |
| 171 "firefox", NULL, | |
| 172 "mozilla", NULL, | |
| 173 "konqueror", NULL, | |
| 174 "netscape", NULL, | |
| 175 NULL, NULL | |
| 176 }; | |
| 177 | |
| 178 static void help_browser_run(void) | |
| 179 { | |
|
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
180 gchar *result; |
| 648 | 181 gint i; |
| 182 | |
|
884
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
183 result = command_result(options->helpers.html_browser.command_name, options->helpers.html_browser.command_line); |
|
ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
zas_
parents:
883
diff
changeset
|
184 |
| 648 | 185 i = 0; |
| 186 while (!result && html_browsers[i]) | |
| 187 { | |
| 188 result = command_result(html_browsers[i], html_browsers[i+1]); | |
| 189 i += 2; | |
| 190 } | |
| 191 | |
| 192 if (!result) | |
| 193 { | |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
194 log_printf("Unable to detect an installed browser.\n"); |
| 648 | 195 return; |
| 196 } | |
| 197 | |
|
728
5042236af960
Replace hardcoded "/" by G_DIR_SEPARATOR_S where applicable.
zas_
parents:
673
diff
changeset
|
198 help_browser_command(result, GQ_HTMLDIR G_DIR_SEPARATOR_S "index.html"); |
| 648 | 199 |
| 200 g_free(result); | |
| 201 } | |
| 202 | |
| 203 /* | |
| 204 *----------------------------------------------------------------------------- | |
| 205 * help window | |
| 206 *----------------------------------------------------------------------------- | |
| 207 */ | |
| 208 | |
| 209 static GtkWidget *help_window = NULL; | |
| 210 | |
| 211 static void help_window_destroy_cb(GtkWidget *window, gpointer data) | |
| 212 { | |
| 213 help_window = NULL; | |
| 214 } | |
| 215 | |
| 216 void help_window_show(const gchar *key) | |
| 217 { | |
| 218 if (key && strcmp(key, "html_contents") == 0) | |
| 219 { | |
| 220 help_browser_run(); | |
| 221 return; | |
| 222 } | |
| 223 | |
| 224 if (help_window) | |
| 225 { | |
| 226 gtk_window_present(GTK_WINDOW(help_window)); | |
| 227 if (key) help_window_set_key(help_window, key); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 help_window = help_window_new(_("Help"), GQ_WMCLASS, "help", | |
|
728
5042236af960
Replace hardcoded "/" by G_DIR_SEPARATOR_S where applicable.
zas_
parents:
673
diff
changeset
|
232 GQ_HELPDIR G_DIR_SEPARATOR_S "README", key); |
| 648 | 233 |
| 234 g_signal_connect(G_OBJECT(help_window), "destroy", | |
| 235 G_CALLBACK(help_window_destroy_cb), NULL); | |
| 236 } | |
| 237 |
