Mercurial > geeqie.yaz
annotate src/main.c @ 507:135570a8bd96
Move debug macros from main.h to new debug.h.
Make debug_level static to debug.c and add utility functions
to manipulate it.
Add #include "debug.h" where needed.
author | zas_ |
---|---|
date | Thu, 24 Apr 2008 08:53:39 +0000 |
parents | fc9c8a3e1a8b |
children | b78a91d0779e |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
9 | 13 |
281 | 14 #include "main.h" |
9 | 15 |
16 #include "cache.h" | |
17 #include "collect.h" | |
18 #include "collect-io.h" | |
507 | 19 #include "debug.h" |
9 | 20 #include "dnd.h" |
21 #include "editors.h" | |
22 #include "filelist.h" | |
354
5c82855feba7
Add a button to reset fullscreen info string to default value.
zas_
parents:
341
diff
changeset
|
23 #include "fullscreen.h" |
218
f4a0555794a9
Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents:
214
diff
changeset
|
24 #include "image-overlay.h" |
9 | 25 #include "img-view.h" |
26 #include "layout.h" | |
27 #include "layout_image.h" | |
28 #include "menu.h" | |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
29 #include "pixbuf_util.h" |
9 | 30 #include "preferences.h" |
31 #include "rcfile.h" | |
32 #include "remote.h" | |
33 #include "similar.h" | |
34 #include "slideshow.h" | |
35 #include "utilops.h" | |
36 #include "ui_bookmark.h" | |
37 #include "ui_help.h" | |
38 #include "ui_fileops.h" | |
39 #include "ui_tabcomp.h" | |
40 #include "ui_utildlg.h" | |
41 | |
1 | 42 #include <gdk/gdkkeysyms.h> /* for keyboard values */ |
43 | |
9 | 44 |
45 #include <math.h> | |
46 | |
47 | |
279 | 48 static RemoteConnection *remote_connection = NULL; |
49 static CollectionData *command_collection = NULL; | |
9 | 50 |
1 | 51 |
52 /* | |
53 *----------------------------------------------------------------------------- | |
9 | 54 * misc (public) |
1 | 55 *----------------------------------------------------------------------------- |
442 | 56 */ |
1 | 57 |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
58 GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon, |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
59 const gchar *icon_file, const gchar *subtitle) |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
60 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
61 gchar *title; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
62 GtkWidget *window; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
63 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
64 window = gtk_window_new(type); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
65 if (!window) return NULL; |
442 | 66 |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
67 if (subtitle) |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
68 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
69 title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
70 } |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
71 else |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
72 { |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
73 title = g_strdup_printf("%s", GQ_APPNAME); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
74 } |
442 | 75 |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
76 gtk_window_set_title(GTK_WINDOW(window), title); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
77 g_free(title); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
78 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
79 window_set_icon(window, icon, icon_file); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
80 gtk_window_set_role(GTK_WINDOW(window), name); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
81 gtk_window_set_wmclass(GTK_WINDOW(window), name, GQ_WMCLASS); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
82 |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
83 return window; |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
84 } |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
85 |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
86 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file) |
1 | 87 { |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
88 if (!icon && !file) icon = PIXBUF_INLINE_ICON; |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
89 |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
90 if (icon) |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
91 { |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
92 GdkPixbuf *pixbuf; |
1 | 93 |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
94 pixbuf = pixbuf_inline(icon); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
95 if (pixbuf) |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
96 { |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
97 gtk_window_set_icon(GTK_WINDOW(window), pixbuf); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
98 g_object_unref(pixbuf); |
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
99 } |
9 | 100 } |
101 else | |
102 { | |
91
d063f97503b7
Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
81
diff
changeset
|
103 gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL); |
9 | 104 } |
105 } | |
1 | 106 |
9 | 107 gint window_maximized(GtkWidget *window) |
108 { | |
109 GdkWindowState state; | |
110 | |
111 if (!window || !window->window) return FALSE; | |
112 | |
113 state = gdk_window_get_state(window->window); | |
114 return (state & GDK_WINDOW_STATE_MAXIMIZED); | |
115 } | |
116 | |
117 gdouble get_zoom_increment(void) | |
118 { | |
334 | 119 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); |
1 | 120 } |
121 | |
412
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
122 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y) |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
123 { |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
124 if (x->tv_usec < y->tv_usec) |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
125 { |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
126 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
127 y->tv_usec -= 1000000 * nsec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
128 y->tv_sec += nsec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
129 } |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
130 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
131 if (x->tv_usec - y->tv_usec > 1000000) |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
132 { |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
133 gint nsec = (x->tv_usec - y->tv_usec) / 1000000; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
134 y->tv_usec += 1000000 * nsec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
135 y->tv_sec -= nsec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
136 } |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
137 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
138 result->tv_sec = x->tv_sec - y->tv_sec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
139 result->tv_usec = x->tv_usec - y->tv_usec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
140 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
141 return x->tv_sec < y->tv_sec; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
142 } |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
143 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
144 const gchar *get_exec_time() |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
145 { |
412
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
146 static gchar timestr[30]; |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
147 static struct timeval start_tv = {0, 0}; |
412
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
148 static struct timeval previous = {0, 0}; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
149 static gint started = 0; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
150 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
151 struct timeval tv = {0, 0}; |
412
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
152 static struct timeval delta = {0, 0}; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
153 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
154 gettimeofday(&tv, NULL); |
442 | 155 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
156 if (start_tv.tv_sec == 0) start_tv = tv; |
442 | 157 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
158 tv.tv_sec -= start_tv.tv_sec; |
442 | 159 if (tv.tv_usec >= start_tv.tv_usec) |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
160 tv.tv_usec -= start_tv.tv_usec; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
161 else |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
162 { |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
163 tv.tv_usec += 1000000 - start_tv.tv_usec; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
164 tv.tv_sec -= 1; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
165 } |
412
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
166 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
167 if (started) timeval_delta(&delta, &tv, &previous); |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
168 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
169 previous = tv; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
170 started = 1; |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
171 |
eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
zas_
parents:
403
diff
changeset
|
172 g_snprintf(timestr, sizeof(timestr), "%5d.%06d (+%05d.%06d)", (int)tv.tv_sec, (int)tv.tv_usec, (int)delta.tv_sec, (int)delta.tv_usec); |
442 | 173 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
174 return timestr; |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
175 } |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
176 |
1 | 177 /* |
178 *----------------------------------------------------------------------------- | |
9 | 179 * Open browser with the help Documentation |
180 *----------------------------------------------------------------------------- | |
181 */ | |
182 | |
183 static gchar *command_result(const gchar *binary, const gchar *command) | |
184 { | |
185 gchar *result = NULL; | |
186 FILE *f; | |
187 char buf[2048]; | |
188 int l; | |
189 | |
190 if (!binary) return NULL; | |
191 if (!file_in_path(binary)) return NULL; | |
192 | |
193 if (!command) return g_strdup(binary); | |
194 if (command[0] == '!') return g_strdup(command + 1); | |
195 | |
196 f = popen(command, "r"); | |
197 if (!f) return NULL; | |
198 | |
199 while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0) | |
200 { | |
201 if (!result) | |
202 { | |
203 int n = 0; | |
204 | |
205 while (n < l && buf[n] != '\n' && buf[n] != '\r') n++; | |
206 if (n > 0) result = g_strndup(buf, n); | |
207 } | |
208 } | |
209 | |
210 pclose(f); | |
211 | |
212 return result; | |
213 } | |
214 | |
215 static void help_browser_command(const gchar *command, const gchar *path) | |
216 { | |
217 gchar *result; | |
218 gchar *buf; | |
219 gchar *begin; | |
220 gchar *end; | |
221 | |
222 if (!command || !path) return; | |
223 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
224 DEBUG_1("Help command pre \"%s\", \"%s\"", command, path); |
9 | 225 |
226 buf = g_strdup(command); | |
227 begin = strstr(buf, "%s"); | |
228 if (begin) | |
229 { | |
230 *begin = '\0'; | |
231 end = begin + 2; | |
232 begin = buf; | |
233 | |
234 result = g_strdup_printf("%s%s%s &", begin, path, end); | |
235 } | |
236 else | |
237 { | |
238 result = g_strdup_printf("%s \"%s\" &", command, path); | |
239 } | |
240 g_free(buf); | |
241 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
242 DEBUG_1("Help command post [%s]", result); |
9 | 243 |
244 system(result); | |
245 | |
246 g_free(result); | |
247 } | |
248 | |
249 /* | |
250 * each set of 2 strings is one browser: | |
251 * the 1st is the binary to look for in the path | |
252 * the 2nd has 3 capabilities: | |
253 * NULL exec binary with html file path as command line | |
254 * string exec string and use results for command line | |
255 * !string use text following ! as command line, replacing optional %s with html file path | |
256 */ | |
257 static gchar *html_browsers[] = | |
258 { | |
259 /* Redhat has a nifty htmlview script to start the user's preferred browser */ | |
260 "htmlview", NULL, | |
261 /* GNOME 2 */ | |
262 "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command", | |
263 /* KDE */ | |
264 "kfmclient", "!kfmclient exec \"%s\"", | |
265 /* use fallbacks */ | |
266 "firefox", NULL, | |
267 "mozilla", NULL, | |
268 "konqueror", NULL, | |
269 "netscape", NULL, | |
270 NULL, NULL | |
271 }; | |
272 | |
273 static void help_browser_run(void) | |
274 { | |
275 gchar *result = NULL; | |
276 gint i; | |
277 | |
278 i = 0; | |
279 while (!result && html_browsers[i]) | |
280 { | |
281 result = command_result(html_browsers[i], html_browsers[i+1]); | |
282 i += 2; | |
283 } | |
284 | |
285 if (!result) | |
286 { | |
287 printf("Unable to detect an installed browser.\n"); | |
288 return; | |
289 } | |
290 | |
283 | 291 help_browser_command(result, GQ_HTMLDIR "/index.html"); |
9 | 292 |
293 g_free(result); | |
294 } | |
295 | |
296 /* | |
297 *----------------------------------------------------------------------------- | |
298 * help window | |
1 | 299 *----------------------------------------------------------------------------- |
442 | 300 */ |
1 | 301 |
9 | 302 static GtkWidget *help_window = NULL; |
303 | |
304 static void help_window_destroy_cb(GtkWidget *window, gpointer data) | |
1 | 305 { |
9 | 306 help_window = NULL; |
1 | 307 } |
308 | |
9 | 309 void help_window_show(const gchar *key) |
1 | 310 { |
9 | 311 if (key && strcmp(key, "html_contents") == 0) |
312 { | |
313 help_browser_run(); | |
314 return; | |
315 } | |
316 | |
317 if (help_window) | |
1 | 318 { |
9 | 319 gtk_window_present(GTK_WINDOW(help_window)); |
320 if (key) help_window_set_key(help_window, key); | |
321 return; | |
1 | 322 } |
9 | 323 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
324 { |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
325 gchar *title = g_strdup_printf("%s - %s", _("Help"), GQ_APPNAME); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
326 help_window = help_window_new(title, GQ_WMCLASS, "help", |
442 | 327 GQ_HELPDIR "/README", key); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
328 g_free(title); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
329 } |
9 | 330 g_signal_connect(G_OBJECT(help_window), "destroy", |
331 G_CALLBACK(help_window_destroy_cb), NULL); | |
1 | 332 } |
333 | |
9 | 334 |
1 | 335 /* |
336 *----------------------------------------------------------------------------- | |
337 * keyboard functions | |
338 *----------------------------------------------------------------------------- | |
339 */ | |
340 | |
341 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event) | |
342 { | |
343 static gint delta = 0; | |
344 static guint32 time_old = 0; | |
345 static guint keyval_old = 0; | |
346 | |
9 | 347 if (event->state & GDK_CONTROL_MASK) |
348 { | |
349 if (*x < 0) *x = G_MININT / 2; | |
350 if (*x > 0) *x = G_MAXINT / 2; | |
351 if (*y < 0) *y = G_MININT / 2; | |
352 if (*y > 0) *y = G_MAXINT / 2; | |
353 | |
354 return; | |
355 } | |
356 | |
318 | 357 if (options->progressive_key_scrolling) |
1 | 358 { |
359 guint32 time_diff; | |
360 | |
361 time_diff = event->time - time_old; | |
362 | |
363 /* key pressed within 125ms ? (1/8 second) */ | |
364 if (time_diff > 125 || event->keyval != keyval_old) delta = 0; | |
365 | |
366 time_old = event->time; | |
367 keyval_old = event->keyval; | |
368 | |
369 delta += 2; | |
370 } | |
371 else | |
372 { | |
373 delta = 8; | |
374 } | |
375 | |
376 *x = *x * delta; | |
377 *y = *y * delta; | |
378 } | |
379 | |
9 | 380 |
381 /* | |
382 *----------------------------------------------------------------------------- | |
383 * remote functions | |
384 *----------------------------------------------------------------------------- | |
385 */ | |
386 | |
387 static void gr_image_next(const gchar *text, gpointer data) | |
388 { | |
389 layout_image_next(NULL); | |
390 } | |
391 | |
392 static void gr_image_prev(const gchar *text, gpointer data) | |
393 { | |
394 layout_image_prev(NULL); | |
395 } | |
396 | |
397 static void gr_image_first(const gchar *text, gpointer data) | |
398 { | |
399 layout_image_first(NULL); | |
400 } | |
401 | |
402 static void gr_image_last(const gchar *text, gpointer data) | |
403 { | |
404 layout_image_last(NULL); | |
405 } | |
406 | |
407 static void gr_fullscreen_toggle(const gchar *text, gpointer data) | |
408 { | |
409 layout_image_full_screen_toggle(NULL); | |
410 } | |
411 | |
412 static void gr_fullscreen_start(const gchar *text, gpointer data) | |
1 | 413 { |
9 | 414 layout_image_full_screen_start(NULL); |
415 } | |
416 | |
417 static void gr_fullscreen_stop(const gchar *text, gpointer data) | |
418 { | |
419 layout_image_full_screen_stop(NULL); | |
420 } | |
421 | |
422 static void gr_slideshow_start_rec(const gchar *text, gpointer data) | |
423 { | |
424 GList *list; | |
425 | |
426 list = path_list_recursive(text); | |
427 if (!list) return; | |
214 | 428 //printf("length: %d\n", g_list_length(list)); |
9 | 429 layout_image_slideshow_stop(NULL); |
430 layout_image_slideshow_start_from_list(NULL, list); | |
431 } | |
1 | 432 |
9 | 433 static void gr_slideshow_toggle(const gchar *text, gpointer data) |
434 { | |
435 layout_image_slideshow_toggle(NULL); | |
436 } | |
437 | |
438 static void gr_slideshow_start(const gchar *text, gpointer data) | |
439 { | |
440 layout_image_slideshow_start(NULL); | |
441 } | |
442 | |
443 static void gr_slideshow_stop(const gchar *text, gpointer data) | |
444 { | |
445 layout_image_slideshow_stop(NULL); | |
446 } | |
447 | |
448 static void gr_slideshow_delay(const gchar *text, gpointer data) | |
449 { | |
450 gdouble n; | |
451 | |
452 n = strtod(text, NULL); | |
453 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS) | |
1 | 454 { |
403 | 455 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n", |
456 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS); | |
9 | 457 return; |
458 } | |
326 | 459 options->slideshow.delay = (gint)(n * 10.0 + 0.01); |
9 | 460 } |
461 | |
462 static void gr_tools_show(const gchar *text, gpointer data) | |
463 { | |
464 gint popped; | |
465 gint hidden; | |
466 | |
467 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden) | |
468 { | |
469 layout_tools_float_set(NULL, popped, FALSE); | |
1 | 470 } |
9 | 471 } |
1 | 472 |
9 | 473 static void gr_tools_hide(const gchar *text, gpointer data) |
474 { | |
475 gint popped; | |
476 gint hidden; | |
477 | |
478 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden) | |
1 | 479 { |
9 | 480 layout_tools_float_set(NULL, popped, TRUE); |
481 } | |
482 } | |
483 | |
484 static gint gr_quit_idle_cb(gpointer data) | |
485 { | |
278 | 486 exit_program(); |
9 | 487 |
488 return FALSE; | |
489 } | |
490 | |
491 static void gr_quit(const gchar *text, gpointer data) | |
492 { | |
493 /* schedule exit when idle, if done from within a | |
494 * remote handler remote_close will crash | |
495 */ | |
496 g_idle_add(gr_quit_idle_cb, NULL); | |
497 } | |
498 | |
499 static void gr_file_load(const gchar *text, gpointer data) | |
500 { | |
501 if (isfile(text)) | |
502 { | |
503 if (file_extension_match(text, ".gqv")) | |
1 | 504 { |
9 | 505 collection_window_new(text); |
506 } | |
507 else | |
508 { | |
509 layout_set_path(NULL, text); | |
1 | 510 } |
511 } | |
9 | 512 else if (isdir(text)) |
513 { | |
514 layout_set_path(NULL, text); | |
515 } | |
516 else | |
517 { | |
518 printf("remote sent filename that does not exist:\"%s\"\n", text); | |
519 } | |
520 } | |
521 | |
522 static void gr_file_view(const gchar *text, gpointer data) | |
523 { | |
138 | 524 view_window_new(file_data_new_simple(text)); |
9 | 525 } |
526 | |
527 static void gr_list_clear(const gchar *text, gpointer data) | |
528 { | |
279 | 529 if (command_collection) collection_unref(command_collection); |
530 command_collection = NULL; | |
9 | 531 } |
532 | |
533 static void gr_list_add(const gchar *text, gpointer data) | |
534 { | |
535 gint new = TRUE; | |
536 | |
279 | 537 if (!command_collection) |
9 | 538 { |
539 CollectionData *cd; | |
540 | |
541 cd = collection_new(""); | |
542 | |
543 g_free(cd->path); | |
544 cd->path = NULL; | |
545 g_free(cd->name); | |
546 cd->name = g_strdup(_("Command line")); | |
547 | |
279 | 548 command_collection = cd; |
9 | 549 } |
550 else | |
551 { | |
279 | 552 new = (!collection_get_first(command_collection)); |
9 | 553 } |
1 | 554 |
279 | 555 if (collection_add(command_collection, file_data_new_simple(text), FALSE) && new) |
9 | 556 { |
279 | 557 layout_image_set_collection(NULL, command_collection, |
558 collection_get_first(command_collection)); | |
9 | 559 } |
560 } | |
561 | |
562 static void gr_raise(const gchar *text, gpointer data) | |
563 { | |
564 LayoutWindow *lw = NULL; | |
565 | |
566 if (layout_valid(&lw)) | |
567 { | |
568 gtk_window_present(GTK_WINDOW(lw->window)); | |
569 } | |
570 } | |
571 | |
572 typedef struct _RemoteCommandEntry RemoteCommandEntry; | |
573 struct _RemoteCommandEntry { | |
574 gchar *opt_s; | |
575 gchar *opt_l; | |
576 void (*func)(const gchar *text, gpointer data); | |
577 gint needs_extra; | |
578 gint prefer_command_line; | |
579 gchar *description; | |
580 }; | |
581 | |
582 static RemoteCommandEntry remote_commands[] = { | |
583 /* short, long callback, extra, prefer,description */ | |
584 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") }, | |
585 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") }, | |
586 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") }, | |
442 | 587 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") }, |
9 | 588 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") }, |
589 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") }, | |
590 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") }, | |
591 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") }, | |
592 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") }, | |
593 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") }, | |
594 { "-sr","--slideshow-recurse", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") }, | |
595 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") }, | |
596 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") }, | |
597 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") }, | |
598 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") }, | |
599 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") }, | |
600 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") }, | |
601 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL }, | |
602 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL }, | |
603 { NULL, "raise", gr_raise, FALSE, FALSE, NULL }, | |
604 { NULL, NULL, NULL, FALSE, FALSE, NULL } | |
605 }; | |
606 | |
279 | 607 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset) |
9 | 608 { |
609 gint match = FALSE; | |
610 gint i; | |
611 | |
612 i = 0; | |
613 while (!match && remote_commands[i].func != NULL) | |
1 | 614 { |
9 | 615 if (remote_commands[i].needs_extra) |
616 { | |
617 if (remote_commands[i].opt_s && | |
618 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0) | |
619 { | |
620 if (offset) *offset = text + strlen(remote_commands[i].opt_s); | |
621 return &remote_commands[i]; | |
622 } | |
623 else if (remote_commands[i].opt_l && | |
624 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0) | |
625 { | |
626 if (offset) *offset = text + strlen(remote_commands[i].opt_l); | |
627 return &remote_commands[i]; | |
628 } | |
629 } | |
630 else | |
631 { | |
632 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) || | |
633 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0)) | |
1 | 634 { |
9 | 635 if (offset) *offset = text; |
636 return &remote_commands[i]; | |
1 | 637 } |
9 | 638 } |
639 | |
640 i++; | |
641 } | |
642 | |
643 return NULL; | |
644 } | |
645 | |
279 | 646 static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data) |
9 | 647 { |
648 RemoteCommandEntry *entry; | |
649 const gchar *offset; | |
650 | |
279 | 651 entry = remote_command_find(text, &offset); |
9 | 652 if (entry && entry->func) |
653 { | |
654 entry->func(offset, data); | |
655 } | |
656 else | |
657 { | |
658 printf("unknown remote command:%s\n", text); | |
659 } | |
660 } | |
661 | |
279 | 662 static void remote_help(void) |
9 | 663 { |
664 gint i; | |
665 | |
666 print_term(_("Remote command list:\n")); | |
667 | |
668 i = 0; | |
669 while (remote_commands[i].func != NULL) | |
670 { | |
671 if (remote_commands[i].description) | |
672 { | |
403 | 673 printf_term(" %-3s%s %-20s %s\n", |
674 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "", | |
675 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ", | |
676 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "", | |
677 _(remote_commands[i].description)); | |
9 | 678 } |
679 i++; | |
680 } | |
681 } | |
682 | |
279 | 683 static GList *remote_build_list(GList *list, int argc, char *argv[]) |
9 | 684 { |
685 gint i; | |
686 | |
687 i = 1; | |
688 while (i < argc) | |
689 { | |
690 RemoteCommandEntry *entry; | |
691 | |
279 | 692 entry = remote_command_find(argv[i], NULL); |
9 | 693 if (entry) |
694 { | |
695 list = g_list_append(list, argv[i]); | |
696 } | |
697 i++; | |
1 | 698 } |
699 | |
9 | 700 return list; |
701 } | |
702 | |
279 | 703 static void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path, |
9 | 704 GList *cmd_list, GList *collection_list) |
705 { | |
706 RemoteConnection *rc; | |
707 gint started = FALSE; | |
708 gchar *buf; | |
709 | |
283 | 710 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL); |
9 | 711 rc = remote_client_open(buf); |
712 if (!rc) | |
713 { | |
714 GString *command; | |
715 GList *work; | |
716 gint retry_count = 12; | |
717 gint blank = FALSE; | |
718 | |
403 | 719 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
720 |
9 | 721 command = g_string_new(arg_exec); |
722 | |
723 work = remote_list; | |
724 while (work) | |
725 { | |
726 gchar *text; | |
727 RemoteCommandEntry *entry; | |
728 | |
729 text = work->data; | |
730 work = work->next; | |
731 | |
279 | 732 entry = remote_command_find(text, NULL); |
9 | 733 if (entry) |
734 { | |
735 if (entry->prefer_command_line) | |
736 { | |
737 remote_list = g_list_remove(remote_list, text); | |
738 g_string_append(command, " "); | |
739 g_string_append(command, text); | |
740 } | |
741 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0) | |
742 { | |
743 blank = TRUE; | |
744 } | |
745 } | |
746 } | |
747 | |
748 if (blank || cmd_list || path) g_string_append(command, " --blank"); | |
507 | 749 if (get_debug_level()) g_string_append(command, " --debug"); |
9 | 750 |
751 g_string_append(command, " &"); | |
752 system(command->str); | |
753 g_string_free(command, TRUE); | |
754 | |
755 while (!rc && retry_count > 0) | |
756 { | |
757 usleep((retry_count > 10) ? 500000 : 1000000); | |
758 rc = remote_client_open(buf); | |
759 if (!rc) print_term("."); | |
760 retry_count--; | |
761 } | |
762 | |
763 print_term("\n"); | |
764 | |
765 started = TRUE; | |
766 } | |
767 g_free(buf); | |
768 | |
769 if (rc) | |
1 | 770 { |
9 | 771 GList *work; |
772 const gchar *prefix; | |
773 gint use_path = TRUE; | |
774 gint sent = FALSE; | |
775 | |
776 work = remote_list; | |
777 while (work) | |
778 { | |
779 gchar *text; | |
780 RemoteCommandEntry *entry; | |
781 | |
782 text = work->data; | |
783 work = work->next; | |
784 | |
279 | 785 entry = remote_command_find(text, NULL); |
9 | 786 if (entry && |
787 entry->opt_l && | |
788 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE; | |
789 | |
790 remote_client_send(rc, text); | |
791 | |
792 sent = TRUE; | |
793 } | |
794 | |
795 if (cmd_list && cmd_list->next) | |
796 { | |
797 prefix = "--list-add:"; | |
798 remote_client_send(rc, "--list-clear"); | |
799 } | |
800 else | |
801 { | |
802 prefix = "file:"; | |
803 } | |
804 | |
805 work = cmd_list; | |
806 while (work) | |
807 { | |
808 const gchar *name; | |
809 gchar *text; | |
810 | |
811 name = work->data; | |
812 work = work->next; | |
813 | |
814 text = g_strconcat(prefix, name, NULL); | |
815 remote_client_send(rc, text); | |
816 g_free(text); | |
817 | |
818 sent = TRUE; | |
819 } | |
820 | |
821 if (path && !cmd_list && use_path) | |
822 { | |
823 gchar *text; | |
824 | |
825 text = g_strdup_printf("file:%s", path); | |
826 remote_client_send(rc, text); | |
827 g_free(text); | |
828 | |
829 sent = TRUE; | |
830 } | |
831 | |
832 work = collection_list; | |
833 while (work) | |
834 { | |
835 const gchar *name; | |
836 gchar *text; | |
837 | |
838 name = work->data; | |
839 work = work->next; | |
840 | |
841 text = g_strdup_printf("file:%s", name); | |
842 remote_client_send(rc, text); | |
843 g_free(text); | |
844 | |
845 sent = TRUE; | |
846 } | |
847 | |
848 if (!started && !sent) | |
849 { | |
850 remote_client_send(rc, "raise"); | |
851 } | |
852 } | |
853 else | |
854 { | |
855 print_term(_("Remote not available\n")); | |
1 | 856 } |
857 | |
9 | 858 _exit(0); |
1 | 859 } |
860 | |
861 /* | |
862 *----------------------------------------------------------------------------- | |
3 | 863 * command line parser (private) hehe, who needs popt anyway? |
1 | 864 *----------------------------------------------------------------------------- |
442 | 865 */ |
1 | 866 |
9 | 867 static gint startup_blank = FALSE; |
3 | 868 static gint startup_full_screen = FALSE; |
869 static gint startup_in_slideshow = FALSE; | |
9 | 870 static gint startup_command_line_collection = FALSE; |
3 | 871 |
9 | 872 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
873 static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file, |
442 | 874 GList **list, GList **collection_list) |
1 | 875 { |
9 | 876 gchar *path_parsed; |
877 | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
878 path_parsed = g_strdup(file_path); |
9 | 879 parse_out_relatives(path_parsed); |
880 | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
881 if (file_extension_match(path_parsed, ".gqv")) |
9 | 882 { |
883 *collection_list = g_list_append(*collection_list, path_parsed); | |
884 } | |
885 else | |
886 { | |
887 if (!*path) *path = remove_level_from_path(path_parsed); | |
888 if (!*file) *file = g_strdup(path_parsed); | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
889 *list = g_list_prepend(*list, path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
890 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
891 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
892 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
893 static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
894 GList **list) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
895 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
896 GList *files = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
897 gchar *path_parsed; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
898 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
899 path_parsed = g_strdup(dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
900 parse_out_relatives(path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
901 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
902 if (path_list(path_parsed, &files, NULL)) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
903 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
904 GList *work; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
905 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
906 files = path_list_filter(files, FALSE); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
907 files = path_list_sort(files); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
908 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
909 work = files; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
910 while (work) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
911 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
912 gchar *p; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
913 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
914 p = work->data; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
915 if (!*path) *path = remove_level_from_path(p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
916 if (!*file) *file = g_strdup(p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
917 *list = g_list_prepend(*list, p); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
918 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
919 work = work->next; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
920 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
921 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
922 g_list_free(files); |
9 | 923 } |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
924 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
925 g_free(path_parsed); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
926 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
927 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
928 static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
929 GList **list, gchar **first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
930 { |
442 | 931 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
932 if (!*list && !*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
933 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
934 *first_dir = g_strdup(dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
935 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
936 else |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
937 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
938 if (*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
939 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
940 parse_command_line_add_dir(*first_dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
941 g_free(*first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
942 *first_dir = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
943 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
944 parse_command_line_add_dir(dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
945 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
946 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
947 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
948 static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
949 GList **list, GList **collection_list, gchar **first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
950 { |
442 | 951 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
952 if (*first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
953 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
954 parse_command_line_add_dir(*first_dir, path, file, list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
955 g_free(*first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
956 *first_dir = NULL; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
957 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
958 parse_command_line_add_file(file_path, path, file, list, collection_list); |
9 | 959 } |
960 | |
961 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file, | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
962 GList **cmd_list, GList **collection_list, |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
963 gchar **geometry) |
9 | 964 { |
965 GList *list = NULL; | |
966 GList *remote_list = NULL; | |
967 gint remote_do = FALSE; | |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
968 gchar *first_dir = NULL; |
9 | 969 |
1 | 970 if (argc > 1) |
971 { | |
972 gint i; | |
973 gchar *base_dir = get_current_dir(); | |
974 i = 1; | |
975 while (i < argc) | |
976 { | |
9 | 977 const gchar *cmd_line = argv[i]; |
978 gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line); | |
1 | 979 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
980 if (cmd_line[0] == '/' && isdir(cmd_line)) |
1 | 981 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
982 parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir); |
1 | 983 } |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
984 else if (isdir(cmd_all)) |
1 | 985 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
986 parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir); |
1 | 987 } |
9 | 988 else if (cmd_line[0] == '/' && isfile(cmd_line)) |
1 | 989 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
990 parse_command_line_process_file(cmd_line, path, file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
991 &list, collection_list, &first_dir); |
1 | 992 } |
9 | 993 else if (isfile(cmd_all)) |
1 | 994 { |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
995 parse_command_line_process_file(cmd_all, path, file, |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
996 &list, collection_list, &first_dir); |
1 | 997 } |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
998 else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '=')) |
1 | 999 { |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1000 /* do nothing but do not produce warnings */ |
1 | 1001 } |
1002 else if (strcmp(cmd_line, "+t") == 0 || | |
3 | 1003 strcmp(cmd_line, "--with-tools") == 0) |
1 | 1004 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1005 options->layout.tools_float = FALSE; |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1006 options->layout.tools_hidden = FALSE; |
9 | 1007 |
1008 remote_list = g_list_append(remote_list, "+t"); | |
1 | 1009 } |
1010 else if (strcmp(cmd_line, "-t") == 0 || | |
3 | 1011 strcmp(cmd_line, "--without-tools") == 0) |
1 | 1012 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1013 options->layout.tools_hidden = TRUE; |
9 | 1014 |
1015 remote_list = g_list_append(remote_list, "-t"); | |
1 | 1016 } |
3 | 1017 else if (strcmp(cmd_line, "-f") == 0 || |
1018 strcmp(cmd_line, "--fullscreen") == 0) | |
1019 { | |
1020 startup_full_screen = TRUE; | |
1021 } | |
1022 else if (strcmp(cmd_line, "-s") == 0 || | |
1023 strcmp(cmd_line, "--slideshow") == 0) | |
1024 { | |
1025 startup_in_slideshow = TRUE; | |
1026 } | |
9 | 1027 else if (strcmp(cmd_line, "-l") == 0 || |
1028 strcmp(cmd_line, "--list") == 0) | |
1029 { | |
1030 startup_command_line_collection = TRUE; | |
1031 } | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1032 else if (strncmp(cmd_line, "--geometry=", 11) == 0) |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1033 { |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1034 if (!*geometry) *geometry = g_strdup(cmd_line + 11); |
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1035 } |
9 | 1036 else if (strcmp(cmd_line, "-r") == 0 || |
1037 strcmp(cmd_line, "--remote") == 0) | |
1038 { | |
1039 if (!remote_do) | |
1040 { | |
1041 remote_do = TRUE; | |
279 | 1042 remote_list = remote_build_list(remote_list, argc, argv); |
9 | 1043 } |
1044 } | |
1045 else if (strcmp(cmd_line, "-rh") == 0 || | |
1046 strcmp(cmd_line, "--remote-help") == 0) | |
1047 { | |
279 | 1048 remote_help(); |
9 | 1049 exit (0); |
1050 } | |
1051 else if (strcmp(cmd_line, "--blank") == 0) | |
1052 { | |
1053 startup_blank = TRUE; | |
1054 } | |
1055 else if (strcmp(cmd_line, "-v") == 0 || | |
1056 strcmp(cmd_line, "--version") == 0) | |
1057 { | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1058 printf("%s %s\n", GQ_APPNAME, VERSION); |
9 | 1059 exit (0); |
1060 } | |
1061 else if (strcmp(cmd_line, "--alternate") == 0) | |
1062 { | |
1063 /* enable faster experimental algorithm */ | |
1064 printf("Alternate similarity algorithm enabled\n"); | |
1065 image_sim_alternate_set(TRUE); | |
1066 } | |
3 | 1067 else if (strcmp(cmd_line, "-h") == 0 || |
1068 strcmp(cmd_line, "--help") == 0) | |
1 | 1069 { |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1070 printf("%s %s\n", GQ_APPNAME, VERSION); |
403 | 1071 printf_term(_("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC); |
9 | 1072 print_term(_("valid options are:\n")); |
1073 print_term(_(" +t, --with-tools force show of tools\n")); | |
1074 print_term(_(" -t, --without-tools force hide of tools\n")); | |
1075 print_term(_(" -f, --fullscreen start in full screen mode\n")); | |
1076 print_term(_(" -s, --slideshow start in slideshow mode\n")); | |
1077 print_term(_(" -l, --list open collection window for command line\n")); | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1078 print_term(_(" --geometry=GEOMETRY set main window location\n")); |
9 | 1079 print_term(_(" -r, --remote send following commands to open window\n")); |
1080 print_term(_(" -rh,--remote-help print remote command list\n")); | |
227
41fc4bfc8b25
Add a debug level spinner at the end of Preferences > Advanced.
zas_
parents:
218
diff
changeset
|
1081 #ifdef DEBUG |
379 | 1082 print_term(_(" --debug[=level] turn on debug output\n")); |
227
41fc4bfc8b25
Add a debug level spinner at the end of Preferences > Advanced.
zas_
parents:
218
diff
changeset
|
1083 #endif |
9 | 1084 print_term(_(" -v, --version print version info\n")); |
1085 print_term(_(" -h, --help show this message\n\n")); | |
442 | 1086 |
9 | 1087 #if 0 |
1088 /* these options are not officially supported! | |
1089 * only for testing new features, no need to translate them */ | |
1090 print_term( " --alternate use alternate similarity algorithm\n"); | |
1091 #endif | |
442 | 1092 |
1 | 1093 exit (0); |
1094 } | |
9 | 1095 else if (!remote_do) |
1 | 1096 { |
403 | 1097 printf_term(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line); |
1 | 1098 } |
9 | 1099 |
1 | 1100 g_free(cmd_all); |
1101 i++; | |
1102 } | |
1103 g_free(base_dir); | |
1104 parse_out_relatives(*path); | |
1105 parse_out_relatives(*file); | |
1106 } | |
9 | 1107 |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1108 list = g_list_reverse(list); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1109 |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1110 if (!*path && first_dir) |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1111 { |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1112 *path = first_dir; |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1113 first_dir = NULL; |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
1114 |
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
76
diff
changeset
|
1115 parse_out_relatives(*path); |
76
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1116 } |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1117 g_free(first_dir); |
07773a3c5b29
Sun Oct 15 04:03:41 2006 John Ellis <johne@verizon.net>
gqview
parents:
21
diff
changeset
|
1118 |
9 | 1119 if (remote_do) |
1120 { | |
279 | 1121 remote_control(argv[0], remote_list, *path, list, *collection_list); |
9 | 1122 } |
1123 g_list_free(remote_list); | |
1124 | |
1125 if (list && list->next) | |
1126 { | |
1127 *cmd_list = list; | |
1128 } | |
1129 else | |
1130 { | |
1131 path_list_free(list); | |
1132 *cmd_list = NULL; | |
1133 } | |
1 | 1134 } |
1135 | |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1136 static void parse_command_line_for_debug_option(int argc, char *argv[]) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1137 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1138 #ifdef DEBUG |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1139 const gchar *debug_option = "--debug"; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1140 gint len = strlen(debug_option); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1141 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1142 if (argc > 1) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1143 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1144 gint i; |
442 | 1145 |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1146 for (i = 1; i < argc; i++) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1147 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1148 const gchar *cmd_line = argv[i]; |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1149 if (strncmp(cmd_line, debug_option, len) == 0) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1150 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1151 gint cmd_line_len = strlen(cmd_line); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1152 |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1153 /* we now increment the debug state for verbosity */ |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1154 if (cmd_line_len == len) |
507 | 1155 debug_level_add(1); |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1156 else if (cmd_line[len] == '=' && g_ascii_isdigit(cmd_line[len+1])) |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1157 { |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1158 gint n = atoi(cmd_line + len + 1); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1159 if (n < 0) n = 1; |
507 | 1160 debug_level_add(n); |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1161 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1162 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1163 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1164 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1165 |
507 | 1166 DEBUG_1("debugging output enabled (level %d)", get_debug_level()); |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1167 #endif |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1168 } |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1169 |
1 | 1170 /* |
1171 *----------------------------------------------------------------------------- | |
1172 * startup, init, and exit | |
1173 *----------------------------------------------------------------------------- | |
442 | 1174 */ |
1 | 1175 |
9 | 1176 #define RC_HISTORY_NAME "history" |
1177 | |
1178 static void keys_load(void) | |
1179 { | |
1180 gchar *path; | |
1181 | |
283 | 1182 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL); |
9 | 1183 history_list_load(path); |
1184 g_free(path); | |
1185 } | |
1186 | |
1187 static void keys_save(void) | |
1188 { | |
1189 gchar *path; | |
1190 | |
283 | 1191 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/", RC_HISTORY_NAME, NULL); |
9 | 1192 history_list_save(path); |
1193 g_free(path); | |
1194 } | |
1195 | |
1196 static void check_for_home_path(gchar *path) | |
1 | 1197 { |
9 | 1198 gchar *buf; |
1199 | |
1200 buf = g_strconcat(homedir(), "/", path, NULL); | |
1201 if (!isdir(buf)) | |
1202 { | |
403 | 1203 printf_term(_("Creating %s dir:%s\n"), GQ_APPNAME, buf); |
442 | 1204 |
9 | 1205 if (!mkdir_utf8(buf, 0755)) |
1206 { | |
403 | 1207 printf_term(_("Could not create dir:%s\n"), buf); |
9 | 1208 } |
1209 } | |
1210 g_free(buf); | |
1211 } | |
1212 | |
1213 static void setup_default_options(void) | |
1214 { | |
1215 gchar *path; | |
1 | 1216 gint i; |
1217 | |
283 | 1218 for (i = 0; i < GQ_EDITOR_SLOTS; i++) |
1 | 1219 { |
318 | 1220 options->editor_name[i] = NULL; |
1221 options->editor_command[i] = NULL; | |
1 | 1222 } |
1223 | |
9 | 1224 editor_reset_defaults(); |
1 | 1225 |
9 | 1226 bookmark_add_default(_("Home"), homedir()); |
1227 path = concat_dir_and_file(homedir(), "Desktop"); | |
1228 bookmark_add_default(_("Desktop"), path); | |
1229 g_free(path); | |
283 | 1230 path = concat_dir_and_file(homedir(), GQ_RC_DIR_COLLECTIONS); |
9 | 1231 bookmark_add_default(_("Collections"), path); |
1232 g_free(path); | |
1 | 1233 |
341
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
340
diff
changeset
|
1234 g_free(options->file_ops.safe_delete_path); |
15c6b94545a2
Move safe_delete* and in place rename options to file_ops
zas_
parents:
340
diff
changeset
|
1235 options->file_ops.safe_delete_path = concat_dir_and_file(homedir(), GQ_RC_DIR_TRASH); |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1236 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1237 for (i = 0; i < COLOR_PROFILE_INPUTS; i++) |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1238 { |
327 | 1239 options->color_profile.input_file[i] = NULL; |
1240 options->color_profile.input_name[i] = NULL; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1241 } |
189
deea9e11f1d4
fixed reading sidecar extensions from config file
nadvornik
parents:
145
diff
changeset
|
1242 |
469
a05c72927e23
Rename few functions and replace fullscreen info with image overlay template string.
zas_
parents:
468
diff
changeset
|
1243 set_default_image_overlay_template_string(options); |
189
deea9e11f1d4
fixed reading sidecar extensions from config file
nadvornik
parents:
145
diff
changeset
|
1244 sidecar_ext_add_defaults(); |
367
3556cc825e59
Move layout.order default init to setup_default_options().
zas_
parents:
358
diff
changeset
|
1245 options->layout.order = g_strdup("123"); |
1 | 1246 } |
1247 | |
278 | 1248 static void exit_program_final(void) |
1 | 1249 { |
9 | 1250 gchar *path; |
1251 gchar *pathl; | |
1252 LayoutWindow *lw = NULL; | |
1253 | |
279 | 1254 remote_close(remote_connection); |
9 | 1255 |
1256 collect_manager_flush(); | |
1 | 1257 |
9 | 1258 if (layout_valid(&lw)) |
1259 { | |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1260 options->layout.main_window.maximized = window_maximized(lw->window); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1261 if (!options->layout.main_window.maximized) |
9 | 1262 { |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1263 layout_geometry_get(NULL, &options->layout.main_window.x, &options->layout.main_window.y, |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1264 &options->layout.main_window.w, &options->layout.main_window.h); |
9 | 1265 } |
468
2df505c60459
Replace fullscreen.info and fullscreen.show_info options by:
zas_
parents:
446
diff
changeset
|
1266 options->image_overlay.common.enabled = image_osd_get(lw->image, NULL, NULL); |
9 | 1267 } |
1 | 1268 |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1269 layout_geometry_get_dividers(NULL, &options->layout.main_window.hdivider_pos, &options->layout.main_window.vdivider_pos); |
9 | 1270 |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
379
diff
changeset
|
1271 layout_views_get(NULL, &options->layout.dir_view_type, &options->layout.view_as_icons); |
9 | 1272 |
340
77103f3f2cb1
Rename option thumbnails.enabled to layout.show_thumbnails as it makes
zas_
parents:
338
diff
changeset
|
1273 options->layout.show_thumbnails = layout_thumb_get(NULL); |
433
5ddcf93278c7
Save Show Marks state to rc file and display current state in menu.
zas_
parents:
412
diff
changeset
|
1274 options->layout.show_marks = layout_marks_get(NULL); |
5ddcf93278c7
Save Show Marks state to rc file and display current state in menu.
zas_
parents:
412
diff
changeset
|
1275 |
329 | 1276 layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending); |
9 | 1277 |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1278 layout_geometry_get_tools(NULL, &options->layout.float_window.x, &options->layout.float_window.y, |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1279 &options->layout.float_window.w, &options->layout.float_window.h, &options->layout.float_window.vdivider_pos); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1280 layout_tools_float_get(NULL, &options->layout.tools_float, &options->layout.tools_hidden); |
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1281 options->layout.toolbar_hidden = layout_toolbar_hidden(NULL); |
9 | 1282 |
327 | 1283 options->color_profile.enabled = layout_image_color_profile_get_use(NULL); |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1284 layout_image_color_profile_get(NULL, |
327 | 1285 &options->color_profile.input_type, |
1286 &options->color_profile.screen_type, | |
1287 &options->color_profile.use_image); | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
91
diff
changeset
|
1288 |
1 | 1289 save_options(); |
9 | 1290 keys_save(); |
1291 | |
283 | 1292 path = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL); |
9 | 1293 pathl = path_from_utf8(path); |
1294 gtk_accel_map_save(pathl); | |
1295 g_free(pathl); | |
1296 g_free(path); | |
1 | 1297 |
1298 gtk_main_quit(); | |
1299 } | |
1300 | |
9 | 1301 static GenericDialog *exit_dialog = NULL; |
1302 | |
1303 static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data) | |
1304 { | |
1305 exit_dialog = NULL; | |
1306 generic_dialog_close(gd); | |
1307 } | |
1308 | |
1309 static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data) | |
1310 { | |
1311 exit_dialog = NULL; | |
1312 generic_dialog_close(gd); | |
278 | 1313 exit_program_final(); |
9 | 1314 } |
1315 | |
1316 static gint exit_confirm_dlg(void) | |
1317 { | |
1318 GtkWidget *parent; | |
1319 LayoutWindow *lw; | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1320 gchar *msg; |
9 | 1321 |
1322 if (exit_dialog) | |
1323 { | |
1324 gtk_window_present(GTK_WINDOW(exit_dialog->dialog)); | |
1325 return TRUE; | |
1326 } | |
1327 | |
1328 if (!collection_window_modified_exists()) return FALSE; | |
1329 | |
1330 parent = NULL; | |
1331 lw = NULL; | |
1332 if (layout_valid(&lw)) | |
1333 { | |
1334 parent = lw->window; | |
1335 } | |
1336 | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1337 msg = g_strdup_printf("%s - %s", GQ_APPNAME, _("exit")); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1338 exit_dialog = generic_dialog_new(msg, |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
227
diff
changeset
|
1339 GQ_WMCLASS, "exit", parent, FALSE, |
9 | 1340 exit_confirm_cancel_cb, NULL); |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1341 g_free(msg); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1342 msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME); |
9 | 1343 generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION, |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1344 msg, _("Collections have been modified. Quit anyway?")); |
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1345 g_free(msg); |
9 | 1346 generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE); |
1347 | |
1348 gtk_widget_show(exit_dialog->dialog); | |
1349 | |
1350 return TRUE; | |
1351 } | |
1352 | |
278 | 1353 void exit_program(void) |
9 | 1354 { |
1355 layout_image_full_screen_stop(NULL); | |
1356 | |
1357 if (exit_confirm_dlg()) return; | |
1358 | |
278 | 1359 exit_program_final(); |
9 | 1360 } |
1361 | |
1 | 1362 int main (int argc, char *argv[]) |
1363 { | |
9 | 1364 LayoutWindow *lw; |
1365 gchar *path = NULL; | |
1 | 1366 gchar *cmd_path = NULL; |
1367 gchar *cmd_file = NULL; | |
9 | 1368 GList *cmd_list = NULL; |
1369 GList *collection_list = NULL; | |
1370 CollectionData *first_collection = NULL; | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1371 gchar *geometry = NULL; |
9 | 1372 gchar *buf; |
1373 gchar *bufl; | |
1 | 1374 |
386
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
1375 /* init execution time counter*/ |
0226daf8c30b
in debug mode print time information on selected events
nadvornik
parents:
380
diff
changeset
|
1376 get_exec_time(); |
442 | 1377 |
1 | 1378 /* setup locale, i18n */ |
1379 gtk_set_locale(); | |
283 | 1380 bindtextdomain(PACKAGE, GQ_LOCALEDIR); |
10 | 1381 bind_textdomain_codeset(PACKAGE, "UTF-8"); |
1382 textdomain(PACKAGE); | |
1 | 1383 |
1384 /* setup random seed for random slideshow */ | |
442 | 1385 srand(time(NULL)); |
1 | 1386 |
21
56866f205a68
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
10
diff
changeset
|
1387 #if 1 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1388 printf("%s %s, This is an alpha release.\n", GQ_APPNAME, VERSION); |
9 | 1389 #endif |
378
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1390 parse_command_line_for_debug_option(argc, argv); |
f1bdbbdb73ba
Parse command line for --debug option as soon as possible and allow
zas_
parents:
367
diff
changeset
|
1391 |
318 | 1392 options = init_options(NULL); |
1 | 1393 setup_default_options(); |
1394 load_options(); | |
1395 | |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1396 parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry); |
9 | 1397 |
1398 gtk_init (&argc, &argv); | |
1399 | |
1400 if (gtk_major_version < GTK_MAJOR_VERSION || | |
1401 (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) | |
1402 { | |
403 | 1403 printf_term("!!! This is a friendly warning.\n"); |
1404 printf_term("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); | |
1405 printf_term("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); | |
1406 printf_term("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); | |
1407 printf_term("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); | |
9 | 1408 } |
1409 | |
283 | 1410 check_for_home_path(GQ_RC_DIR); |
1411 check_for_home_path(GQ_RC_DIR_COLLECTIONS); | |
1412 check_for_home_path(GQ_CACHE_RC_THUMB); | |
1413 check_for_home_path(GQ_CACHE_RC_METADATA); | |
9 | 1414 |
1415 keys_load(); | |
1416 filter_add_defaults(); | |
1417 filter_rebuild(); | |
442 | 1418 |
283 | 1419 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/accels", NULL); |
9 | 1420 bufl = path_from_utf8(buf); |
1421 gtk_accel_map_load(bufl); | |
1422 g_free(bufl); | |
1423 g_free(buf); | |
1 | 1424 |
9 | 1425 if (startup_blank) |
1426 { | |
1427 g_free(cmd_path); | |
1428 cmd_path = NULL; | |
1429 g_free(cmd_file); | |
1430 cmd_file = NULL; | |
1431 path_list_free(cmd_list); | |
1432 cmd_list = NULL; | |
1433 path_list_free(collection_list); | |
1434 collection_list = NULL; | |
1435 | |
1436 path = NULL; | |
1437 } | |
1438 else if (cmd_path) | |
1439 { | |
1440 path = g_strdup(cmd_path); | |
1441 } | |
318 | 1442 else if (options->startup_path_enable && options->startup_path && isdir(options->startup_path)) |
9 | 1443 { |
318 | 1444 path = g_strdup(options->startup_path); |
9 | 1445 } |
1 | 1446 else |
9 | 1447 { |
1448 path = get_current_dir(); | |
1449 } | |
1450 | |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
334
diff
changeset
|
1451 lw = layout_new_with_geometry(NULL, options->layout.tools_float, options->layout.tools_hidden, geometry); |
329 | 1452 layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending); |
9 | 1453 |
1454 if (collection_list && !startup_command_line_collection) | |
1455 { | |
1456 GList *work; | |
1457 | |
1458 work = collection_list; | |
1459 while (work) | |
1460 { | |
1461 CollectWindow *cw; | |
1462 const gchar *path; | |
1 | 1463 |
9 | 1464 path = work->data; |
1465 work = work->next; | |
1466 | |
1467 cw = collection_window_new(path); | |
1468 if (!first_collection && cw) first_collection = cw->cd; | |
1469 } | |
1470 } | |
1471 | |
1472 if (cmd_list || | |
1473 (startup_command_line_collection && collection_list)) | |
1474 { | |
1475 CollectionData *cd; | |
1476 GList *work; | |
1477 | |
1478 if (startup_command_line_collection) | |
1479 { | |
1480 CollectWindow *cw; | |
1481 | |
1482 cw = collection_window_new(""); | |
1483 cd = cw->cd; | |
1484 } | |
1485 else | |
1486 { | |
1487 cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */ | |
279 | 1488 command_collection = cd; |
9 | 1489 } |
1490 | |
1491 g_free(cd->path); | |
1492 cd->path = NULL; | |
1493 g_free(cd->name); | |
1494 cd->name = g_strdup(_("Command line")); | |
1495 | |
1496 collection_path_changed(cd); | |
1 | 1497 |
9 | 1498 work = cmd_list; |
1499 while (work) | |
1500 { | |
138 | 1501 collection_add(cd, file_data_new_simple((gchar *)work->data), FALSE); |
9 | 1502 work = work->next; |
1503 } | |
1504 | |
1505 work = collection_list; | |
1506 while (work) | |
1507 { | |
358 | 1508 collection_load(cd, (gchar *)work->data, COLLECTION_LOAD_APPEND); |
9 | 1509 work = work->next; |
1510 } | |
1511 | |
1512 layout_set_path(lw, path); | |
1513 if (cd->list) layout_image_set_collection(lw, cd, cd->list->data); | |
1 | 1514 |
9 | 1515 /* mem leak, we never unref this collection when !startup_command_line_collection |
1516 * (the image view of the main window does not hold a ref to the collection) | |
1517 * this is sort of unavoidable, for if it did hold a ref, next/back | |
1518 * may not work as expected when closing collection windows. | |
1519 * | |
1520 * collection_unref(cd); | |
1521 */ | |
1522 | |
1523 } | |
1524 else if (cmd_file) | |
1525 { | |
1526 layout_set_path(lw, cmd_file); | |
1527 } | |
1528 else | |
1529 { | |
1530 layout_set_path(lw, path); | |
1531 if (first_collection) | |
1532 { | |
1533 layout_image_set_collection(lw, first_collection, | |
1534 collection_get_first(first_collection)); | |
1535 } | |
1536 } | |
468
2df505c60459
Replace fullscreen.info and fullscreen.show_info options by:
zas_
parents:
446
diff
changeset
|
1537 image_osd_set(lw->image, FALSE, (options->image_overlay.common.show_at_startup || options->image_overlay.common.enabled)); |
1 | 1538 |
81
0ef72a64930b
Thu Oct 19 09:35:18 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
1539 g_free(geometry); |
1 | 1540 g_free(cmd_path); |
1541 g_free(cmd_file); | |
9 | 1542 path_list_free(cmd_list); |
1543 path_list_free(collection_list); | |
1544 g_free(path); | |
1 | 1545 |
9 | 1546 if (startup_full_screen) layout_image_full_screen_start(lw); |
1547 if (startup_in_slideshow) layout_image_slideshow_start(lw); | |
1548 | |
283 | 1549 buf = g_strconcat(homedir(), "/", GQ_RC_DIR, "/.command", NULL); |
279 | 1550 remote_connection = remote_server_open(buf); |
1551 remote_server_subscribe(remote_connection, remote_cb, NULL); | |
9 | 1552 g_free(buf); |
3 | 1553 |
1 | 1554 gtk_main (); |
1555 return 0; | |
1556 } |