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)
262 *-----------------------------------------------------------------------------
265 static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file)
270 gchar *base_dir = get_current_dir();
274 gchar *cmd_line = argv[i];
275 gchar *cmd_all = g_strconcat(base_dir, "/", cmd_line, NULL);
277 if (!*path && cmd_line[0] == '/' && isdir(cmd_line))
279 *path = g_strdup(cmd_line);
281 else if (!*path && isdir(cmd_all))
283 *path = g_strdup(cmd_all);
285 else if (!*file && cmd_line[0] == '/' && isfile(cmd_line))
288 *path = remove_level_from_path(cmd_line);
289 *file = g_strdup(cmd_line);
291 else if (!*file && isfile(cmd_all))
294 *path = remove_level_from_path(cmd_all);
295 *file = g_strdup(cmd_all);
297 else if (strcmp(cmd_line, "-debug") == 0)
300 printf("debugging output enabled\n");
302 else if (strcmp(cmd_line, "+t") == 0 ||
303 strcmp(cmd_line, "+tools") == 0)
306 tools_hidden = FALSE;
308 else if (strcmp(cmd_line, "-t") == 0 ||
309 strcmp(cmd_line, "-tools") == 0)
313 else if (strcmp(cmd_line, "-help") == 0)
315 printf("GQview version %s\n", VERSION);
316 printf(_("Usage: gqview [options] [path]\n\n"));
317 printf(_("valid options are:\n"));
318 printf(_(" +t, +tools force show of tools\n"));
319 printf(_(" -t, -tools force hide of tools\n"));
320 printf(_(" -debug turn on debug output\n"));
321 printf(_(" -help this message\n\n"));
326 printf(_("invalid or ignored: %s\nUse -help for options\n"), cmd_line);
332 parse_out_relatives(*path);
333 parse_out_relatives(*file);
338 *-----------------------------------------------------------------------------
339 * startup, init, and exit
340 *-----------------------------------------------------------------------------
343 static void setup_default_options()
349 editor_name[i] = NULL;
350 editor_command[i] = NULL;
353 editor_name[0] = g_strdup(_("The Gimp"));
354 editor_command[0] = g_strdup("gimp");
356 editor_name[1] = g_strdup(_("Electric Eyes"));
357 editor_command[1] = g_strdup("ee");
359 editor_name[2] = g_strdup(_("XV"));
360 editor_command[2] = g_strdup("xv");
362 editor_name[3] = g_strdup(_("Xpaint"));
363 editor_command[3] = g_strdup("xpaint");
365 custom_filter = g_strdup(".eim;");
372 gdk_window_get_position (mainwindow->window, &main_window_x, &main_window_y);
373 gdk_window_get_size(mainwindow->window, &main_window_w, &main_window_h);
377 gdk_window_get_position (toolwindow->window, &float_window_x, &float_window_y);
378 gdk_window_get_size(toolwindow->window, &float_window_w, &float_window_h);
385 int main (int argc, char *argv[])
387 gchar *cmd_path = NULL;
388 gchar *cmd_file = NULL;
390 /* setup locale, i18n */
392 bindtextdomain (PACKAGE, LOCALEDIR);
393 textdomain (PACKAGE);
395 /* setup random seed for random slideshow */
398 gtk_init (&argc, &argv);
401 /* push the correct color depths to gtk, (for 8-bit psuedo color displays)
402 * they should be popped, too, I guess...
404 gtk_widget_push_visual(gdk_imlib_get_visual());
405 gtk_widget_push_colormap(gdk_imlib_get_colormap());
407 setup_default_options();
410 parse_command_line(argc, argv, &cmd_path, &cmd_file);
413 current_path = g_strdup(cmd_path);
414 else if (startup_path_enable && startup_path && isdir(startup_path))
415 current_path = g_strdup(startup_path);
417 current_path = get_current_dir();
419 create_main_window();
420 update_edit_menus(mainwindow_accel_grp);
421 rebuild_file_filter();
426 while(gtk_events_pending()) gtk_main_iteration();
427 image_change_to(cmd_file);