main.c
来自「Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。」· C语言 代码 · 共 1,367 行 · 第 1/3 页
C
1,367 行
{ remote_do = TRUE; remote_list = gqview_remote_build_list(remote_list, argc, argv); } } else if (strcmp(cmd_line, "-rh") == 0 || strcmp(cmd_line, "--remote-help") == 0) { gqview_remote_help(); exit (0); } else if (strcmp(cmd_line, "--blank") == 0) { startup_blank = TRUE; } else if (strcmp(cmd_line, "-v") == 0 || strcmp(cmd_line, "--version") == 0) { printf("GQview %s\n", VERSION); exit (0); } else if (strcmp(cmd_line, "--alternate") == 0) { /* enable faster experimental algorithm */ printf("Alternate similarity algorithm enabled\n"); image_sim_alternate_set(TRUE); } else if (strcmp(cmd_line, "-h") == 0 || strcmp(cmd_line, "--help") == 0) { printf("GQview %s\n", VERSION); print_term(_("Usage: gqview [options] [path]\n\n")); print_term(_("valid options are:\n")); print_term(_(" +t, --with-tools force show of tools\n")); print_term(_(" -t, --without-tools force hide of tools\n")); print_term(_(" -f, --fullscreen start in full screen mode\n")); print_term(_(" -s, --slideshow start in slideshow mode\n")); print_term(_(" -l, --list open collection window for command line\n")); print_term(_(" -r, --remote send following commands to open window\n")); print_term(_(" -rh,--remote-help print remote command list\n")); print_term(_(" --debug turn on debug output\n")); print_term(_(" -v, --version print version info\n")); print_term(_(" -h, --help show this message\n\n")); #if 0 /* these options are not officially supported! * only for testing new features, no need to translate them */ print_term( " --alternate use alternate similarity algorithm\n");#endif exit (0); } else if (!remote_do) { gchar *buf; buf = g_strdup_printf(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line); print_term(buf); g_free(buf); } g_free(cmd_all); i++; } g_free(base_dir); parse_out_relatives(*path); parse_out_relatives(*file); } if (remote_do) { gqview_remote_control(argv[0], remote_list, *path, list, *collection_list); } g_list_free(remote_list); if (list && list->next) { *cmd_list = list; } else { path_list_free(list); *cmd_list = NULL; }}/* *----------------------------------------------------------------------------- * startup, init, and exit *----------------------------------------------------------------------------- */ #define RC_HISTORY_NAME "history"static void keys_load(void){ gchar *path; path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL); history_list_load(path); g_free(path);}static void keys_save(void){ gchar *path; path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_HISTORY_NAME, NULL); history_list_save(path); g_free(path);}static void check_for_home_path(gchar *path){ gchar *buf; buf = g_strconcat(homedir(), "/", path, NULL); if (!isdir(buf)) { gchar *tmp; tmp = g_strdup_printf(_("Creating GQview dir:%s\n"), buf); print_term(tmp); g_free(tmp); if (!mkdir_utf8(buf, 0755)) { tmp = g_strdup_printf(_("Could not create dir:%s\n"), buf); print_term(tmp); g_free(tmp); } } g_free(buf);}static void setup_default_options(void){ gchar *path; gint i; for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++) { editor_name[i] = NULL; editor_command[i] = NULL; } editor_reset_defaults(); bookmark_add_default(_("Home"), homedir()); path = concat_dir_and_file(homedir(), "Desktop"); bookmark_add_default(_("Desktop"), path); g_free(path); path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_COLLECTIONS); bookmark_add_default(_("Collections"), path); g_free(path); g_free(safe_delete_path); safe_delete_path = concat_dir_and_file(homedir(), GQVIEW_RC_DIR_TRASH);}static void exit_gqview_final(void){ gchar *path; gchar *pathl; LayoutWindow *lw = NULL; remote_close(gqview_remote); collect_manager_flush(); if (layout_valid(&lw)) { main_window_maximized = window_maximized(lw->window); if (!main_window_maximized) { layout_geometry_get(NULL, &main_window_x, &main_window_y, &main_window_w, &main_window_h); } } layout_geometry_get_dividers(NULL, &window_hdivider_pos, &window_vdivider_pos); layout_views_get(NULL, &layout_view_tree, &layout_view_icons); thumbnails_enabled = layout_thumb_get(NULL); layout_sort_get(NULL, &file_sort_method, &file_sort_ascending); layout_geometry_get_tools(NULL, &float_window_x, &float_window_y, &float_window_w, &float_window_h, &float_window_divider); layout_tools_float_get(NULL, &tools_float, &tools_hidden); toolbar_hidden = layout_toolbar_hidden(NULL); save_options(); keys_save(); path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL); pathl = path_from_utf8(path); gtk_accel_map_save(pathl); g_free(pathl); g_free(path); gtk_main_quit();}static GenericDialog *exit_dialog = NULL;static void exit_confirm_cancel_cb(GenericDialog *gd, gpointer data){ exit_dialog = NULL; generic_dialog_close(gd);}static void exit_confirm_exit_cb(GenericDialog *gd, gpointer data){ exit_dialog = NULL; generic_dialog_close(gd); exit_gqview_final();}static gint exit_confirm_dlg(void){ GtkWidget *parent; LayoutWindow *lw; if (exit_dialog) { gtk_window_present(GTK_WINDOW(exit_dialog->dialog)); return TRUE; } if (!collection_window_modified_exists()) return FALSE; parent = NULL; lw = NULL; if (layout_valid(&lw)) { parent = lw->window; } exit_dialog = generic_dialog_new(_("GQview - exit"), "GQview", "exit", parent, FALSE, exit_confirm_cancel_cb, NULL); generic_dialog_add_message(exit_dialog, GTK_STOCK_DIALOG_QUESTION, _("Quit GQview"), _("Collections have been modified. Quit anyway?")); generic_dialog_add_button(exit_dialog, GTK_STOCK_QUIT, NULL, exit_confirm_exit_cb, TRUE); gtk_widget_show(exit_dialog->dialog); return TRUE;}void exit_gqview(void){ layout_image_full_screen_stop(NULL); if (exit_confirm_dlg()) return; exit_gqview_final();}int main (int argc, char *argv[]){ LayoutWindow *lw; gchar *path = NULL; gchar *cmd_path = NULL; gchar *cmd_file = NULL; GList *cmd_list = NULL; GList *collection_list = NULL; CollectionData *first_collection = NULL; gchar *buf; gchar *bufl; /* setup locale, i18n */ gtk_set_locale(); bindtextdomain(PACKAGE, GQVIEW_LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); /* setup random seed for random slideshow */ srand(time(NULL));#if 1 printf("GQview %s, This is a beta release.\n", VERSION);#endif layout_order = g_strdup("123"); setup_default_options(); load_options(); parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list); gtk_init (&argc, &argv); if (gtk_major_version < GTK_MAJOR_VERSION || (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) { gchar *msg; print_term("!!! This is a friendly warning.\n"); print_term("!!! The version of GTK+ in use now is older than when GQview was compiled.\n"); msg = g_strdup_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); print_term(msg); g_free(msg); msg = g_strdup_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); print_term(msg); g_free(msg); print_term("!!! GQview may quit unexpectedly with a relocation error.\n"); } check_for_home_path(GQVIEW_RC_DIR); check_for_home_path(GQVIEW_RC_DIR_COLLECTIONS); check_for_home_path(GQVIEW_CACHE_RC_THUMB); check_for_home_path(GQVIEW_CACHE_RC_METADATA); keys_load(); filter_add_defaults(); filter_rebuild(); buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/accels", NULL); bufl = path_from_utf8(buf); gtk_accel_map_load(bufl); g_free(bufl); g_free(buf); if (startup_blank) { g_free(cmd_path); cmd_path = NULL; g_free(cmd_file); cmd_file = NULL; path_list_free(cmd_list); cmd_list = NULL; path_list_free(collection_list); collection_list = NULL; path = NULL; } else if (cmd_path) { path = g_strdup(cmd_path); } else if (startup_path_enable && startup_path && isdir(startup_path)) { path = g_strdup(startup_path); } else { path = get_current_dir(); } lw = layout_new(NULL, tools_float, tools_hidden); layout_sort_set(lw, file_sort_method, file_sort_ascending); if (collection_list && !startup_command_line_collection) { GList *work; work = collection_list; while (work) { CollectWindow *cw; const gchar *path; path = work->data; work = work->next; cw = collection_window_new(path); if (!first_collection && cw) first_collection = cw->cd; } } if (cmd_list || (startup_command_line_collection && collection_list)) { CollectionData *cd; GList *work; if (startup_command_line_collection) { CollectWindow *cw; cw = collection_window_new(""); cd = cw->cd; } else { cd = collection_new(""); /* if we pass NULL, untitled counter is falsely increm. */ gqview_command_collection = cd; } g_free(cd->path); cd->path = NULL; g_free(cd->name); cd->name = g_strdup(_("Command line")); collection_path_changed(cd); work = cmd_list; while (work) { collection_add(cd, (gchar *)work->data, FALSE); work = work->next; } work = collection_list; while (work) { collection_load(cd, (gchar *)work->data, TRUE); work = work->next; } layout_set_path(lw, path); if (cd->list) layout_image_set_collection(lw, cd, cd->list->data); /* mem leak, we never unref this collection when !startup_command_line_collection * (the image view of the main window does not hold a ref to the collection) * this is sort of unavoidable, for if it did hold a ref, next/back * may not work as expected when closing collection windows. * * collection_unref(cd); */ } else if (cmd_file) { layout_set_path(lw, cmd_file); } else { layout_set_path(lw, path); if (first_collection) { layout_image_set_collection(lw, first_collection, collection_get_first(first_collection)); } } g_free(cmd_path); g_free(cmd_file); path_list_free(cmd_list); path_list_free(collection_list); g_free(path); if (startup_full_screen) layout_image_full_screen_start(lw); if (startup_in_slideshow) layout_image_slideshow_start(lw); buf = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/.command", NULL); gqview_remote = remote_server_open(buf); remote_server_subscribe(gqview_remote, gqview_remote_cb, NULL); g_free(buf); gtk_main (); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?