10 #include <gdk/gdkkeysyms.h> /* for keyboard values */
12 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file);
13 static void setup_default_options();
16 *-----------------------------------------------------------------------------
17 * path manipulation routines (public)
18 *-----------------------------------------------------------------------------
21 gchar *filename_from_path(char *t)
26 while(p > t && p[0] != '/') p--;
31 gchar *remove_level_from_path(gchar *path)
37 if (!path) return NULL;
40 if (p < 0) return NULL;
41 while(ptr[p] != '/' && p > 0) p--;
42 if (p == 0 && ptr[p] == '/') p++;
43 new_path = g_strndup(path, (guint)p);
47 void parse_out_relatives(gchar *path)
55 while (path[s] != '\0')
57 if (path[s] == '/' && path[s+1] == '.' && (path[s+2] == '/' || path[s+2] == '\0') )
61 else if (path[s] == '/' && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == '/' || path[s+3] == '\0') )
65 while (path[t] != '/' && t > 0) t--;
69 if (s != t) path[t] = path[s];
74 if (t == 0 && path[t] == '/') t++;
75 if (t > 1 && path[t-1] == '/') t--;
80 *-----------------------------------------------------------------------------
81 * external editor start routines (public)
82 *-----------------------------------------------------------------------------
85 void start_editor_from_file(gint n, gchar *path)
89 cmd = g_strdup_printf("%s \"%s\" &", editor_command[n], path);
90 printf(_("GQview running: %s\n"),cmd);
95 void start_editor_from_image(gint n)
97 start_editor_from_file(n, image_get_path());
100 void start_editor_from_list(gint n)
104 GList *list = file_get_selected_list();
108 cmd = g_strconcat(editor_command[n], " ", NULL);
112 cmd = g_strconcat(buf, "\"", work->data, "\" ", NULL);
117 cmd = g_strconcat(buf, "&", NULL);
119 printf(_("GQview running: %s\n"),cmd);
122 free_selected_list(list);
126 *-----------------------------------------------------------------------------
128 *-----------------------------------------------------------------------------
131 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)
133 static gint delta = 0;
134 static guint32 time_old = 0;
135 static guint keyval_old = 0;
137 if (progressive_key_scrolling)
141 time_diff = event->time - time_old;
143 /* key pressed within 125ms ? (1/8 second) */
144 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
146 time_old = event->time;
147 keyval_old = event->keyval;
160 gint key_press_cb(GtkWidget *widget, GdkEventKey *event)
162 gint stop_signal = FALSE;
166 if (GTK_WIDGET_HAS_FOCUS(path_entry))
168 if (event->keyval == GDK_Escape)
169 gtk_entry_set_text(GTK_ENTRY(path_entry), current_path);
173 if (full_screen_window || GTK_WIDGET_HAS_FOCUS(main_image->viewport))
175 switch (event->keyval)
204 switch (event->keyval)
207 image_adjust_zoom(1);
226 file_util_delete(image_get_path(), NULL);
234 if (event->state == 0 || (event->state & GDK_MODIFIER_MASK) == GDK_LOCK_MASK)
242 if (event->state & GDK_SHIFT_MASK)
250 keyboard_scroll_calc(&x, &y, event);
254 if (stop_signal) gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event");
260 *-----------------------------------------------------------------------------
261 * command line parser (private) hehe, who needs popt anyway?
262 *-----------------------------------------------------------------------------
265 static gint startup_full_screen = FALSE;
266 static gint startup_in_slideshow = FALSE;
268 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file)
273 gchar *base_dir = get_current_dir();
277 gchar *cmd_line = argv[i];
278 gchar *cmd_all = g_strconcat(base_dir, "/", cmd_line, NULL);
280 if (!*path && cmd_line[0] == '/' && isdir(cmd_line))
282 *path = g_strdup(cmd_line);
284 else if (!*path && isdir(cmd_all))
286 *path = g_strdup(cmd_all);
288 else if (!*file && cmd_line[0] == '/' && isfile(cmd_line))
291 *path = remove_level_from_path(cmd_line);
292 *file = g_strdup(cmd_line);
294 else if (!*file && isfile(cmd_all))
297 *path = remove_level_from_path(cmd_all);
298 *file = g_strdup(cmd_all);
300 else if (strcmp(cmd_line, "--debug") == 0)
303 printf("debugging output enabled\n");
305 else if (strcmp(cmd_line, "+t") == 0 ||
306 strcmp(cmd_line, "--with-tools") == 0)
309 tools_hidden = FALSE;
311 else if (strcmp(cmd_line, "-t") == 0 ||
312 strcmp(cmd_line, "--without-tools") == 0)
316 else if (strcmp(cmd_line, "-f") == 0 ||
317 strcmp(cmd_line, "--fullscreen") == 0)
319 startup_full_screen = TRUE;
321 else if (strcmp(cmd_line, "-s") == 0 ||
322 strcmp(cmd_line, "--slideshow") == 0)
324 startup_in_slideshow = TRUE;
326 else if (strcmp(cmd_line, "-h") == 0 ||
327 strcmp(cmd_line, "--help") == 0)
329 printf("GQview version %s\n", VERSION);
330 printf(_("Usage: gqview [options] [path]\n\n"));
331 printf(_("valid options are:\n"));
332 printf(_(" +t, --with-tools force show of tools\n"));
333 printf(_(" -t, --without-tools force hide of tools\n"));
334 printf(_(" -f, --fullscreen start in full screen mode\n"));
335 printf(_(" -s, --slideshow start in slideshow mode\n"));
336 printf(_(" --debug turn on debug output\n"));
337 printf(_(" -h, --help show this message\n\n"));
342 printf(_("invalid or ignored: %s\nUse -help for options\n"), cmd_line);
348 parse_out_relatives(*path);
349 parse_out_relatives(*file);
354 *-----------------------------------------------------------------------------
355 * startup, init, and exit
356 *-----------------------------------------------------------------------------
359 static void setup_default_options()
365 editor_name[i] = NULL;
366 editor_command[i] = NULL;
369 editor_name[0] = g_strdup(_("The Gimp"));
370 editor_command[0] = g_strdup("gimp");
372 editor_name[1] = g_strdup(_("Electric Eyes"));
373 editor_command[1] = g_strdup("ee");
375 editor_name[2] = g_strdup(_("XV"));
376 editor_command[2] = g_strdup("xv");
378 editor_name[3] = g_strdup(_("Xpaint"));
379 editor_command[3] = g_strdup("xpaint");
381 custom_filter = g_strdup(".eim;");
388 gdk_window_get_position (mainwindow->window, &main_window_x, &main_window_y);
389 gdk_window_get_size(mainwindow->window, &main_window_w, &main_window_h);
393 gdk_window_get_position (toolwindow->window, &float_window_x, &float_window_y);
394 gdk_window_get_size(toolwindow->window, &float_window_w, &float_window_h);
401 int main (int argc, char *argv[])
403 gchar *cmd_path = NULL;
404 gchar *cmd_file = NULL;
406 /* setup locale, i18n */
408 bindtextdomain (PACKAGE, LOCALEDIR);
409 textdomain (PACKAGE);
411 /* setup random seed for random slideshow */
414 gtk_init (&argc, &argv);
417 /* push the correct color depths to gtk, (for 8-bit psuedo color displays)
418 * they should be popped, too, I guess...
420 gtk_widget_push_visual(gdk_imlib_get_visual());
421 gtk_widget_push_colormap(gdk_imlib_get_colormap());
423 setup_default_options();
426 parse_command_line(argc, argv, &cmd_path, &cmd_file);
429 current_path = g_strdup(cmd_path);
430 else if (startup_path_enable && startup_path && isdir(startup_path))
431 current_path = g_strdup(startup_path);
433 current_path = get_current_dir();
435 create_main_window();
436 update_edit_menus(mainwindow_accel_grp);
437 rebuild_file_filter();
442 while(gtk_events_pending()) gtk_main_iteration();
443 image_change_to(cmd_file);
448 if (startup_full_screen) full_screen_toggle();
449 if (startup_in_slideshow) slideshow_start();