main.c
来自「Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。」· C语言 代码 · 共 1,367 行 · 第 1/3 页
C
1,367 行
/* * GQview * (C) 2004 John Ellis * * Author: John Ellis * * This software is released under the GNU General Public License (GNU GPL). * Please read the included file COPYING for more information. * This software comes with no warranty of any kind, use at your own risk! */#include "gqview.h"#include "cache.h"#include "collect.h"#include "collect-io.h"#include "dnd.h"#include "editors.h"#include "filelist.h"#include "img-view.h"#include "layout.h"#include "layout_image.h"#include "menu.h"#include "preferences.h"#include "rcfile.h"#include "remote.h"#include "similar.h"#include "slideshow.h"#include "utilops.h"#include "ui_bookmark.h"#include "ui_help.h"#include "ui_fileops.h"#include "ui_tabcomp.h"#include "ui_utildlg.h"#include <gdk/gdkkeysyms.h> /* for keyboard values */#include "icons/icon.xpm"#include <math.h>static RemoteConnection *gqview_remote = NULL;static CollectionData *gqview_command_collection = NULL;/* *----------------------------------------------------------------------------- * misc (public) *----------------------------------------------------------------------------- */ typedef struct _WindowIconData WindowIconData;struct _WindowIconData{ const char **icon; gchar *path;};static void window_set_icon_cb(GtkWidget *widget, gpointer data){ WindowIconData *wid = data; GdkPixbuf *pb; GdkPixmap *pixmap; GdkBitmap *mask; if (wid->icon) { pb = gdk_pixbuf_new_from_xpm_data(wid->icon); } else { pb = gdk_pixbuf_new_from_file(wid->path, NULL); } g_free(wid->path); g_free(wid); if (!pb) return; gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128); gdk_pixbuf_unref(pb); gdk_window_set_icon(widget->window, NULL, pixmap, mask); /* apparently, gdk_window_set_icon does not ref the pixmap and mask, so don't unref it (leak?) */}void window_set_icon(GtkWidget *window, const char **icon, const gchar *file){ WindowIconData *wid; if (!icon && !file) icon = (const char **)icon_xpm; wid = g_new0(WindowIconData, 1); wid->icon = icon; wid->path = g_strdup(file); g_signal_connect(G_OBJECT(window), "realize", G_CALLBACK(window_set_icon_cb), wid);}gint window_maximized(GtkWidget *window){ GdkWindowState state; if (!window || !window->window) return FALSE; state = gdk_window_get_state(window->window); return (state & GDK_WINDOW_STATE_MAXIMIZED);}gdouble get_zoom_increment(void){ return ((zoom_increment != 0) ? (gdouble)zoom_increment / 10.0 : 1.0);}/* *----------------------------------------------------------------------------- * Open browser with the help Documentation *----------------------------------------------------------------------------- */static gchar *command_result(const gchar *binary, const gchar *command){ gchar *result = NULL; FILE *f; char buf[2048]; int l; if (!binary) return NULL; if (!file_in_path(binary)) return NULL; if (!command) return g_strdup(binary); if (command[0] == '!') return g_strdup(command + 1); f = popen(command, "r"); if (!f) return NULL; while ((l = fread(buf, sizeof(char), sizeof(buf), f)) > 0) { if (!result) { int n = 0; while (n < l && buf[n] != '\n' && buf[n] != '\r') n++; if (n > 0) result = g_strndup(buf, n); } } pclose(f); return result;}static void help_browser_command(const gchar *command, const gchar *path){ gchar *result; gchar *buf; gchar *begin; gchar *end; if (!command || !path) return; if (debug) printf("Help command pre \"%s\", \"%s\"\n", command, path); buf = g_strdup(command); begin = strstr(buf, "%s"); if (begin) { *begin = '\0'; end = begin + 2; begin = buf; result = g_strdup_printf("%s%s%s &", begin, path, end); } else { result = g_strdup_printf("%s \"%s\" &", command, path); } g_free(buf); if (debug) printf("Help command post [%s]\n", result); system(result); g_free(result);}/* * each set of 2 strings is one browser: * the 1st is the binary to look for in the path * the 2nd has 3 capabilities: * NULL exec binary with html file path as command line * string exec string and use results for command line * !string use text following ! as command line, replacing optional %s with html file path*/static gchar *html_browsers[] ={ /* Redhat has a nifty htmlview script to start the user's preferred browser */ "htmlview", NULL, /* GNOME 2 */ "gconftool-2", "gconftool-2 -g /desktop/gnome/url-handlers/http/command", /* KDE */ "kfmclient", "!kfmclient exec \"%s\"", /* use fallbacks */ "firefox", NULL, "mozilla", NULL, "konqueror", NULL, "netscape", NULL, NULL, NULL};static void help_browser_run(void){ gchar *result = NULL; gint i; i = 0; while (!result && html_browsers[i]) { result = command_result(html_browsers[i], html_browsers[i+1]); i += 2; } if (!result) { printf("Unable to detect an installed browser.\n"); return; } help_browser_command(result, GQVIEW_HTMLDIR "/index.html"); g_free(result);}/* *----------------------------------------------------------------------------- * help window *----------------------------------------------------------------------------- */ static GtkWidget *help_window = NULL;static void help_window_destroy_cb(GtkWidget *window, gpointer data){ help_window = NULL;}void help_window_show(const gchar *key){ if (key && strcmp(key, "html_contents") == 0) { help_browser_run(); return; } if (help_window) { gtk_window_present(GTK_WINDOW(help_window)); if (key) help_window_set_key(help_window, key); return; } help_window = help_window_new(_("Help - GQview"), "GQview", "help", GQVIEW_HELPDIR "/README", key); g_signal_connect(G_OBJECT(help_window), "destroy", G_CALLBACK(help_window_destroy_cb), NULL);}/* *----------------------------------------------------------------------------- * keyboard functions *----------------------------------------------------------------------------- */void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event){ static gint delta = 0; static guint32 time_old = 0; static guint keyval_old = 0; if (event->state & GDK_CONTROL_MASK) { if (*x < 0) *x = G_MININT / 2; if (*x > 0) *x = G_MAXINT / 2; if (*y < 0) *y = G_MININT / 2; if (*y > 0) *y = G_MAXINT / 2; return; } if (progressive_key_scrolling) { guint32 time_diff; time_diff = event->time - time_old; /* key pressed within 125ms ? (1/8 second) */ if (time_diff > 125 || event->keyval != keyval_old) delta = 0; time_old = event->time; keyval_old = event->keyval; delta += 2; } else { delta = 8; } *x = *x * delta; *y = *y * delta;}/* *----------------------------------------------------------------------------- * remote functions *----------------------------------------------------------------------------- */static void gr_image_next(const gchar *text, gpointer data){ layout_image_next(NULL);}static void gr_image_prev(const gchar *text, gpointer data){ layout_image_prev(NULL);}static void gr_image_first(const gchar *text, gpointer data){ layout_image_first(NULL);}static void gr_image_last(const gchar *text, gpointer data){ layout_image_last(NULL);}static void gr_fullscreen_toggle(const gchar *text, gpointer data){ layout_image_full_screen_toggle(NULL);}static void gr_fullscreen_start(const gchar *text, gpointer data){ layout_image_full_screen_start(NULL);}static void gr_fullscreen_stop(const gchar *text, gpointer data){ layout_image_full_screen_stop(NULL);}static void gr_slideshow_start_rec(const gchar *text, gpointer data){ GList *list; list = path_list_recursive(text); if (!list) return;printf("length: %d\n", g_list_length(list)); layout_image_slideshow_stop(NULL); layout_image_slideshow_start_from_list(NULL, list);}static void gr_slideshow_toggle(const gchar *text, gpointer data){ layout_image_slideshow_toggle(NULL);}static void gr_slideshow_start(const gchar *text, gpointer data){ layout_image_slideshow_start(NULL);}static void gr_slideshow_stop(const gchar *text, gpointer data){ layout_image_slideshow_stop(NULL);}static void gr_slideshow_delay(const gchar *text, gpointer data){ gdouble n; n = strtod(text, NULL); if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS) { gchar *buf; buf = g_strdup_printf("Remote slideshow delay out of range (%.1f to %.1f)\n", SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS); print_term(buf); g_free(buf); return; } slideshow_delay = (gint)(n * 10.0 + 0.01);}static void gr_tools_show(const gchar *text, gpointer data){ gint popped; gint hidden; if (layout_tools_float_get(NULL, &popped, &hidden) && hidden) { layout_tools_float_set(NULL, popped, FALSE); }}static void gr_tools_hide(const gchar *text, gpointer data){ gint popped; gint hidden; if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden) { layout_tools_float_set(NULL, popped, TRUE); }}static gint gr_quit_idle_cb(gpointer data){ exit_gqview(); return FALSE;}static void gr_quit(const gchar *text, gpointer data){ /* schedule exit when idle, if done from within a * remote handler remote_close will crash */ g_idle_add(gr_quit_idle_cb, NULL);}static void gr_file_load(const gchar *text, gpointer data){ if (isfile(text)) { if (file_extension_match(text, ".gqv")) { collection_window_new(text); } else { layout_set_path(NULL, text); } } else if (isdir(text)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?