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