From 7885f76d408b1a71a0f98e00bc16fe72dd351808 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 3 Feb 2011 20:26:22 +0100 Subject: initial commit Signed-off-by: Florian Pritz --- src/Makefile.am | 9 ++ src/Makefile.in | 472 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/about.c | 40 +++++ src/about.h | 27 ++++ src/callbacks.c | 214 +++++++++++++++++++++++++ src/callbacks.h | 60 +++++++ src/console.c | 46 ++++++ src/console.h | 28 ++++ src/hyperlink.c | 93 +++++++++++ src/hyperlink.h | 28 ++++ src/open.c | 140 ++++++++++++++++ src/open.h | 28 ++++ src/preferences.c | 204 +++++++++++++++++++++++ src/preferences.h | 29 ++++ src/qinfo.c | 85 ++++++++++ src/qinfo.h | 56 +++++++ src/settings.c | 187 +++++++++++++++++++++ src/settings.h | 28 ++++ src/window.c | 98 ++++++++++++ src/window.h | 28 ++++ 20 files changed, 1900 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/Makefile.in create mode 100644 src/about.c create mode 100644 src/about.h create mode 100644 src/callbacks.c create mode 100644 src/callbacks.h create mode 100644 src/console.c create mode 100644 src/console.h create mode 100644 src/hyperlink.c create mode 100644 src/hyperlink.h create mode 100644 src/open.c create mode 100644 src/open.h create mode 100644 src/preferences.c create mode 100644 src/preferences.h create mode 100644 src/qinfo.c create mode 100644 src/qinfo.h create mode 100644 src/settings.c create mode 100644 src/settings.h create mode 100644 src/window.c create mode 100644 src/window.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..29b8503 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,9 @@ +bin_PROGRAMS = qinfo + +qinfo_SOURCES = qinfo.c console.c window.c callbacks.c settings.c hyperlink.c open.c preferences.c about.c +qinfo_LDADD = $(DEPS_LIBS) + +AM_CPPFLAGS = $(DEPS_CFLAGS) \ + -DVERSION=\""$(PACKAGE_VERSION)"\" \ + -DPIXMAPS_DIR=\""$(datadir)/pixmaps"\" \ + -DUI_DIR=\""$(pkgdatadir)/ui"\" \ No newline at end of file diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..73e04ab --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,472 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = qinfo$(EXEEXT) +subdir = src +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_qinfo_OBJECTS = qinfo.$(OBJEXT) console.$(OBJEXT) window.$(OBJEXT) \ + callbacks.$(OBJEXT) settings.$(OBJEXT) hyperlink.$(OBJEXT) \ + open.$(OBJEXT) preferences.$(OBJEXT) about.$(OBJEXT) +qinfo_OBJECTS = $(am_qinfo_OBJECTS) +am__DEPENDENCIES_1 = +qinfo_DEPENDENCIES = $(am__DEPENDENCIES_1) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(qinfo_SOURCES) +DIST_SOURCES = $(qinfo_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DEPS_CFLAGS = @DEPS_CFLAGS@ +DEPS_LIBS = @DEPS_LIBS@ +DESKTOP_DATADIR = @DESKTOP_DATADIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +qinfo_SOURCES = qinfo.c console.c window.c callbacks.c settings.c hyperlink.c open.c preferences.c about.c +qinfo_LDADD = $(DEPS_LIBS) +AM_CPPFLAGS = $(DEPS_CFLAGS) \ + -DVERSION=\""$(PACKAGE_VERSION)"\" \ + -DPIXMAPS_DIR=\""$(datadir)/pixmaps"\" \ + -DUI_DIR=\""$(pkgdatadir)/ui"\" + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) +qinfo$(EXEEXT): $(qinfo_OBJECTS) $(qinfo_DEPENDENCIES) + @rm -f qinfo$(EXEEXT) + $(LINK) $(qinfo_OBJECTS) $(qinfo_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/about.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/callbacks.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/console.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hyperlink.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/preferences.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qinfo.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/settings.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/window.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic ctags distclean distclean-compile \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-binPROGRAMS \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-binPROGRAMS + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/about.c b/src/about.c new file mode 100644 index 0000000..a649e87 --- /dev/null +++ b/src/about.c @@ -0,0 +1,40 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "about.h" + +extern void about_init (qinfo_t *app) +{ + if (gtk_builder_add_from_file (app->builder, UI_DIR "/about.xml", + &app->error) == 0) + { + qinfo_error (app->window, &app->error); + return; + } + + GtkWidget *dialog = GTK_WIDGET (gtk_builder_get_object (app->builder, + "about_dialog")); + gtk_window_set_icon (GTK_WINDOW (dialog), app->icon); + + gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), VERSION); + gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (dialog), app->icon); + + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} diff --git a/src/about.h b/src/about.h new file mode 100644 index 0000000..078536c --- /dev/null +++ b/src/about.h @@ -0,0 +1,27 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ABOUT_H +#define ABOUT_H + +#include "qinfo.h" + +extern void about_init (qinfo_t *app); + +#endif diff --git a/src/callbacks.c b/src/callbacks.c new file mode 100644 index 0000000..b2da1a6 --- /dev/null +++ b/src/callbacks.c @@ -0,0 +1,214 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "callbacks.h" + +G_MODULE_EXPORT void on_window_destroy (GtkObject *object, qinfo_t *app) +{ + gtk_main_quit(); +} + +G_MODULE_EXPORT gboolean on_window_configure_event (GtkWidget *widget, + GdkEventConfigure *event, qinfo_t *app) +{ + app->x = event->x; + app->y = event->y; + app->width = event->width; + app->height = event->height; + + return FALSE; +} + +G_MODULE_EXPORT void on_open_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app) +{ + open_init (app); +} + +G_MODULE_EXPORT void on_open_toolbar_item_activated (GtkRecentChooser *chooser, + qinfo_t *app) +{ + gchar *file, *uri = gtk_recent_chooser_get_current_uri (chooser); + + if ((file = g_filename_from_uri (uri, NULL, &app->error)) != NULL) { + open_file (app, file); + g_free (file); + } + + g_free (uri); +} + +G_MODULE_EXPORT void on_all_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app) +{ + GtkTextIter start, end; + gtk_text_buffer_get_bounds (app->buffer, &start, &end); + gtk_text_buffer_select_range (app->buffer, &start, &end); +} + +G_MODULE_EXPORT void on_copy_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app) +{ + GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_text_buffer_copy_clipboard (app->buffer, clipboard); +} + +G_MODULE_EXPORT void on_preferences_toolbar_item_clicked (GtkObject *object, + qinfo_t *app) +{ + preferences_init (app); +} + +G_MODULE_EXPORT void on_preferences_dialog_response (GtkDialog *dialog, + gint response, qinfo_t *app) +{ + preferences_finish (app, dialog, response); +} + +G_MODULE_EXPORT void on_about_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app) +{ + about_init (app); +} + +G_MODULE_EXPORT gboolean on_textview_key_press_event (GtkWidget *textview, + GdkEventKey *event, qinfo_t *app) +{ + if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) { + GtkTextIter iter; + gtk_text_buffer_get_iter_at_mark (app->buffer, &iter, + gtk_text_buffer_get_insert (app->buffer)); + + hyperlink_follow (app, &iter); + } + + return FALSE; +} + +G_MODULE_EXPORT void on_textview_event_after (GtkWidget *textview, + GdkEvent *event, qinfo_t *app) +{ + if (event->type != GDK_BUTTON_RELEASE) + return; + + GdkEventButton *event_btn = (GdkEventButton *) event; + + if (event_btn->button != 1) + return; + + GtkTextIter start, end; + gtk_text_buffer_get_selection_bounds (app->buffer, &start, &end); + + if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end)) + return; + + gint x, y; + gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (textview), + GTK_TEXT_WINDOW_WIDGET, event_btn->x, event_btn->y, &x, &y); + + GtkTextIter iter; + gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (textview), &iter, x, y); + + hyperlink_follow (app, &iter); +} + +G_MODULE_EXPORT gboolean on_textview_motion_notify_event (GtkWidget *textview, + GdkEventMotion *event, qinfo_t *app) +{ + gint x, y; + gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (textview), + GTK_TEXT_WINDOW_WIDGET, event->x, event->y, &x, &y); + + hyperlink_cursor(app, x, y); + + return FALSE; +} + +G_MODULE_EXPORT gboolean on_textview_visibility_notify_event ( + GtkWidget *textview, GdkEventVisibility *event, qinfo_t *app) +{ + gint wx, wy; + gdk_window_get_pointer (textview->window, &wx, &wy, NULL); + + gint bx, by; + gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (textview), + GTK_TEXT_WINDOW_WIDGET, wx, wy, &bx, &by); + + hyperlink_cursor (app, bx, by); + + return FALSE; +} + +G_MODULE_EXPORT void on_textview_drag_data_received (GtkWidget *widget, + GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, + guint target_type, guint time, qinfo_t *app) +{ + if (selection_data->data != NULL && g_strstr_len ((gchar *) + selection_data->data, 5, "file:")) + { + gchar **files = g_strsplit_set ((gchar *) selection_data->data, "\r\n", + 2); + gchar *file = g_filename_from_uri (files[0], NULL, NULL); + + if (file != NULL) + open_file (app, file); + + g_free (file); + g_strfreev (files); + } +} + +G_MODULE_EXPORT gboolean on_textview_drag_motion (GtkWidget *widget, + GdkDragContext *drag_context, gint x, gint y, guint time, qinfo_t *app) +{ + return TRUE; +} +/* +G_MODULE_EXPORT void on_textview_size_request (GtkWidget *widget, + GtkRequisition *requisition, qinfo_t *app) +{ + if (app->expand == FALSE) + return; + + GdkRectangle rect; + gdk_window_get_frame_extents (GTK_WIDGET (app->window)->window, &rect); + + gint border = (rect.width - app->width) / 2; + gint width = requisition->width; + + if (GTK_WIDGET (app->view)->allocation.height < requisition->height) { + g_print ("added\n"); + width += 22; + } + + if (app->width < width) { + gint screen = gdk_screen_get_width (gtk_window_get_screen (GTK_WINDOW ( + app->window))) - border * 2; + + if (width > screen) { + gtk_window_move (GTK_WINDOW (app->window), border, app->y); + width = screen; + } else if (width > screen - app->x) { + gtk_window_move (GTK_WINDOW (app->window), screen - width, app->y); + } + + gtk_window_resize (GTK_WINDOW (app->window), width, app->height); + } +} +*/ diff --git a/src/callbacks.h b/src/callbacks.h new file mode 100644 index 0000000..a6090ab --- /dev/null +++ b/src/callbacks.h @@ -0,0 +1,60 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef CALLBACKS_H +#define CALLBACKS_H + +#include "qinfo.h" +#include "hyperlink.h" +#include "open.h" +#include "preferences.h" +#include "about.h" + +G_MODULE_EXPORT void on_window_destroy (GtkObject *object, qinfo_t *app); +G_MODULE_EXPORT gboolean on_window_configure_event (GtkWidget *widget, + GdkEventConfigure *event, qinfo_t *app); +G_MODULE_EXPORT void on_open_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app); +G_MODULE_EXPORT void on_open_toolbar_item_activated (GtkRecentChooser *chooser, + qinfo_t *app); +G_MODULE_EXPORT void on_all_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app); +G_MODULE_EXPORT void on_copy_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app); +G_MODULE_EXPORT void on_preferences_toolbar_item_clicked (GtkObject *object, + qinfo_t *app); +G_MODULE_EXPORT void on_preferences_dialog_response (GtkDialog *dialog, + gint response, qinfo_t *app); +G_MODULE_EXPORT void on_about_toolbar_item_clicked (GtkToolButton *button, + qinfo_t *app); +G_MODULE_EXPORT gboolean on_textview_key_press_event (GtkWidget *textview, + GdkEventKey *event, qinfo_t *app); +G_MODULE_EXPORT void on_textview_event_after (GtkWidget *textview, + GdkEvent *event, qinfo_t *app); +G_MODULE_EXPORT gboolean on_textview_motion_notify_event (GtkWidget *textview, + GdkEventMotion *event, qinfo_t *app); +G_MODULE_EXPORT gboolean on_textview_visibility_notify_event ( + GtkWidget *textview, GdkEventVisibility *event, qinfo_t *app); +G_MODULE_EXPORT void on_textview_drag_data_received (GtkWidget *widget, + GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, + guint target_type, guint time, qinfo_t *app); +G_MODULE_EXPORT gboolean on_textview_drag_motion (GtkWidget *widget, + GdkDragContext *drag_context, gint x, gint y, guint time, qinfo_t *app); + +#endif diff --git a/src/console.c b/src/console.c new file mode 100644 index 0000000..1c3ecbd --- /dev/null +++ b/src/console.c @@ -0,0 +1,46 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "console.h" + +extern void console_version () +{ + g_print ("qinfo " VERSION "\n"); +} + +extern void console_output (qinfo_t *app, const gchar *file) +{ + if (file == NULL) + return; + + gchar *text = NULL, *utf8 = NULL; + if (g_file_get_contents (file, &text, NULL, &app->error) == TRUE && + (utf8 = g_convert (text, -1, "UTF-8", "437", NULL, NULL, &app->error)) + != NULL) + { + g_print (utf8); + g_print ("\n"); + } else { + g_warning (app->error->message); + FREE_GERROR (app->error); + } + + g_free (text); + g_free (utf8); +} diff --git a/src/console.h b/src/console.h new file mode 100644 index 0000000..049e1b6 --- /dev/null +++ b/src/console.h @@ -0,0 +1,28 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef CONSOLE_H +#define CONSOLE_H + +#include "qinfo.h" + +extern void console_version (); +extern void console_output (qinfo_t *app, const gchar *file); + +#endif diff --git a/src/hyperlink.c b/src/hyperlink.c new file mode 100644 index 0000000..801b4a8 --- /dev/null +++ b/src/hyperlink.c @@ -0,0 +1,93 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hyperlink.h" + +extern void hyperlink_cursor (qinfo_t *app, gint x, gint y) +{ + gboolean hovering = FALSE; + + GtkTextIter iter; + gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (app->view), &iter, x, y); + + GSList *tags = NULL, *tagp = NULL; + tags = gtk_text_iter_get_tags (&iter); + + GtkTextTag *tag; + + for (tagp = tags; tagp != NULL; tagp = tagp->next) { + tag = tagp->data; + + if (tag == app->tag) { + hovering = TRUE; + break; + } + } + + if (hovering != app->hovering) { + app->hovering = hovering; + + if (app->hovering) + gdk_window_set_cursor (gtk_text_view_get_window ( + GTK_TEXT_VIEW (app->view), GTK_TEXT_WINDOW_TEXT), app->hand); + else + gdk_window_set_cursor (gtk_text_view_get_window( + GTK_TEXT_VIEW (app->view), GTK_TEXT_WINDOW_TEXT), app->cursor); + } + + g_slist_free (tags); +} + +extern void hyperlink_follow (qinfo_t *app, GtkTextIter *iter) +{ + GSList *tags = NULL, *tagp = NULL; + tags = gtk_text_iter_get_tags (iter); + + for (tagp = tags; tagp != NULL; tagp = tagp->next) { + GtkTextTag *tag = tagp->data; + + if (tag == app->tag) { + GtkTextIter *start = gtk_text_iter_copy (iter), *end = + gtk_text_iter_copy (iter); + + if (gtk_text_iter_begins_tag (start, app->tag) == FALSE) + gtk_text_iter_backward_to_tag_toggle (start, app->tag); + + if (gtk_text_iter_ends_tag (end, app->tag) == FALSE) + gtk_text_iter_forward_to_tag_toggle (end, app->tag); + + gchar *link = gtk_text_buffer_get_text (app->buffer, start, end, + FALSE); + gchar *cmd = g_strdup_printf (app->browser, link); + + if (g_spawn_command_line_async (cmd, &app->error) == FALSE) + qinfo_error (app->window, &app->error); + + g_free (cmd); + g_free (link); + + gtk_text_iter_free (start); + gtk_text_iter_free (end); + + break; + } + } + + g_slist_free (tags); +} diff --git a/src/hyperlink.h b/src/hyperlink.h new file mode 100644 index 0000000..31b2785 --- /dev/null +++ b/src/hyperlink.h @@ -0,0 +1,28 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HYPERLINK_H +#define HYPERLINK_H + +#include "qinfo.h" + +extern void hyperlink_cursor (qinfo_t *app, gint x, gint y); +extern void hyperlink_follow (qinfo_t *app, GtkTextIter *iter); + +#endif diff --git a/src/open.c b/src/open.c new file mode 100644 index 0000000..c0a33d7 --- /dev/null +++ b/src/open.c @@ -0,0 +1,140 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "open.h" + +extern void open_init (qinfo_t *app) +{ + GtkWidget *dialog = gtk_file_chooser_dialog_new ("Open file ...", + GTK_WINDOW (app->window), GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, + GTK_RESPONSE_ACCEPT, NULL); + + gtk_window_set_icon (GTK_WINDOW (dialog), app->icon); + + GtkFileFilter *ascii = gtk_file_filter_new (); + gtk_file_filter_set_name (ascii, "Ascii art documents"); + gtk_file_filter_add_pattern (ascii, "*.nfo"); + gtk_file_filter_add_pattern (ascii, "*.diz"); + + GtkFileFilter *all = gtk_file_filter_new (); + gtk_file_filter_set_name (all, "All files"); + gtk_file_filter_add_pattern (all, "*"); + + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), ascii); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) { + gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER ( + dialog)); + + if (filename != NULL) { + open_file (app, filename); + g_free (filename); + } + } + + gtk_widget_destroy (dialog); +} + +extern void open_file (qinfo_t *app, const gchar *file) +{ + gchar *text = NULL, *utf8 = NULL; + if (g_file_get_contents (file, &text, NULL, &app->error) == FALSE || + (utf8 = g_convert (text, -1, "UTF-8", "437", NULL, NULL, &app->error)) + == NULL) + { + qinfo_error (app->window, &app->error); + g_free (text); + return; + } + + g_free (text); + + GtkRecentData recent; + recent.display_name = NULL; + recent.description = NULL; + recent.mime_type = "text/plain"; + recent.app_name = "qinfo"; + recent.app_exec = "qinfo %f"; + recent.groups = NULL; + recent.is_private = FALSE; + + gchar *uri = g_filename_to_uri (file, NULL, NULL); + + if (G_LIKELY (uri != NULL)) { + gtk_recent_manager_add_full (gtk_recent_manager_get_default (), uri, + &recent); + g_free (uri); + } + + gtk_text_buffer_set_text (app->buffer, "", -1); + + GtkTextIter iter; + gtk_text_buffer_get_start_iter (app->buffer, &iter); + + gchar *p = utf8, *last = utf8; + + while (*p != 0x00) { + if (*p == ':' && *(p + 1) == '/' && *(p + 2) == '/') { + gchar *start = p, *end = p; + + while (g_ascii_isalpha(*(--start)) == TRUE); + ++start; + + while (g_ascii_isalnum (*(++end)) == TRUE || *end == '/' || + *end == '%' || *end == '.' || *end == '-' || *end == '_' || + *end == '?' || *end == '='); + --end; + + gtk_text_buffer_insert(app->buffer, &iter, last, start - last); + gtk_text_buffer_insert_with_tags(app->buffer, &iter, start, + end - start + 1, app->tag, NULL); + + last = p = end + 1; + } else if ((*p == 'w' || *p == 'W') && (*(p + 1) == 'w' || + *(p + 1) == 'W') && (*(p + 2) == 'w' || *(p + 2) == 'W') && + *(p + 3) == '.') + { + gchar *end = p + 3; + + while (g_ascii_isalnum (*(++end)) == TRUE || *end == '/' || + *end == '%' || *end == '.'); + --end; + + gtk_text_buffer_insert (app->buffer, &iter, last, p - last); + gtk_text_buffer_insert_with_tags (app->buffer, &iter, p, + end - p + 1, app->tag, NULL); + + last = p = end + 1; + } else { + ++p; + } + } + + gtk_text_buffer_insert (app->buffer, &iter, last, p - last); + + g_free (utf8); + + gchar *base = g_filename_display_basename (file); + gchar *title = g_strconcat (base, " - qinfo", NULL); + gtk_window_set_title(GTK_WINDOW(app->window), title); + g_free (title); + g_free (base); +} diff --git a/src/open.h b/src/open.h new file mode 100644 index 0000000..6157eb2 --- /dev/null +++ b/src/open.h @@ -0,0 +1,28 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef OPEN_H +#define OPEN_H + +#include "qinfo.h" + +extern void open_init (qinfo_t *app); +extern void open_file (qinfo_t *app, const gchar *file); + +#endif diff --git a/src/preferences.c b/src/preferences.c new file mode 100644 index 0000000..a1092fb --- /dev/null +++ b/src/preferences.c @@ -0,0 +1,204 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "preferences.h" + +static void preferences_read (qinfo_t *app) +{ + GtkFontButton *font = GTK_FONT_BUTTON (gtk_builder_get_object (app->builder, + "font")); + GtkColorButton *text = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "text")); + GtkColorButton *background = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "background")); + GtkColorButton *link = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "link")); + GtkComboBox *wrap = GTK_COMBO_BOX (gtk_builder_get_object (app->builder, + "wordwrap")); + GtkEntry *browser = GTK_ENTRY (gtk_builder_get_object (app->builder, + "action")); + GtkSpinButton *left = GTK_SPIN_BUTTON (gtk_builder_get_object (app->builder, + "left")); + GtkSpinButton *right = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "right")); + GtkSpinButton *above = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "above")); + GtkSpinButton *below = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "below")); + + gchar *str = pango_font_description_to_string (app->font); + gtk_font_button_set_font_name (font, str); + g_free (str); + + gtk_color_button_set_color (text, &app->fg); + gtk_color_button_set_color (background, &app->bg); + + gtk_combo_box_set_active (wrap, gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW ( + app->view))); + + GdkColor color; + gdk_color_parse (app->link, &color); + gtk_color_button_set_color (link, &color); + + gtk_entry_set_text (browser, app->browser); + + gtk_spin_button_set_value (left, (gdouble) gtk_text_view_get_left_margin ( + GTK_TEXT_VIEW (app->view))); + gtk_spin_button_set_value (right, (gdouble) gtk_text_view_get_right_margin ( + GTK_TEXT_VIEW (app->view))); + gtk_spin_button_set_value (above, (gdouble) + gtk_text_view_get_pixels_above_lines (GTK_TEXT_VIEW (app->view))); + gtk_spin_button_set_value (below, (gdouble) + gtk_text_view_get_pixels_below_lines (GTK_TEXT_VIEW (app->view))); +} + +static void preferences_write (qinfo_t *app) +{ + GtkFontButton *font = GTK_FONT_BUTTON (gtk_builder_get_object (app->builder, + "font")); + GtkColorButton *text = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "text")); + GtkColorButton *background = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "background")); + GtkColorButton *link = GTK_COLOR_BUTTON (gtk_builder_get_object ( + app->builder, "link")); + GtkComboBox *wrap = GTK_COMBO_BOX (gtk_builder_get_object (app->builder, + "wordwrap")); + GtkEntry *browser = GTK_ENTRY (gtk_builder_get_object (app->builder, + "action")); + GtkSpinButton *left = GTK_SPIN_BUTTON (gtk_builder_get_object (app->builder, + "left")); + GtkSpinButton *right = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "right")); + GtkSpinButton *above = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "above")); + GtkSpinButton *below = GTK_SPIN_BUTTON (gtk_builder_get_object ( + app->builder, "below")); + + GKeyFile *cfg = g_key_file_new (); + + gchar *file = g_build_filename (g_get_user_config_dir (), "qinfo", NULL); + + if (g_key_file_load_from_file (cfg, file, G_KEY_FILE_NONE, &app->error) == + FALSE) + { + g_warning (app->error->message); + } + + FREE_GERROR(app->error); + + const gchar *fontname = gtk_font_button_get_font_name (font); + pango_font_description_free (app->font); + app->font = pango_font_description_from_string (fontname); + gtk_widget_modify_font (app->view, app->font); + g_key_file_set_string (cfg, "textview", "font", fontname); + + gtk_color_button_get_color (text, &app->fg); + gtk_widget_modify_text (app->view, GTK_STATE_NORMAL, &app->fg); + gchar *str = gdk_color_to_string (&app->fg); + g_key_file_set_string (cfg, "textview", "text_color", str); + g_free (str); + + gtk_color_button_get_color (background, &app->bg); + gtk_widget_modify_base (app->view, GTK_STATE_NORMAL, &app->bg); + str = gdk_color_to_string (&app->bg); + g_key_file_set_string (cfg, "textview", "background_color", str); + g_free (str); + + gint value = gtk_combo_box_get_active (wrap); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (app->view), value); + g_key_file_set_integer (cfg, "textview", "word_wrap", value); + + GdkColor color; + gtk_color_button_get_color (link, &color); + str = gdk_color_to_string (&color); + g_free (app->link); + app->link = str; + g_object_set (app->tag, "foreground", app->link, NULL); + g_key_file_set_string (cfg, "textview", "link_color", str); + + const char *action = gtk_entry_get_text (browser); + g_free (app->browser); + app->browser = g_strdup (action); + g_key_file_set_string (cfg, "textview", "browser", action); + + value = gtk_spin_button_get_value_as_int (left); + gtk_text_view_set_left_margin (GTK_TEXT_VIEW (app->view), value); + g_key_file_set_integer (cfg, "textview", "left_margin", value); + + value = gtk_spin_button_get_value_as_int (right); + gtk_text_view_set_right_margin (GTK_TEXT_VIEW (app->view), value); + g_key_file_set_integer (cfg, "textview", "right_margin", value); + + value = gtk_spin_button_get_value_as_int (above); + gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (app->view), value); + g_key_file_set_integer (cfg, "textview", "pixels_above_lines", value); + + value = gtk_spin_button_get_value_as_int (below); + gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (app->view), value); + g_key_file_set_integer (cfg, "textview", "pixels_below_lines", value); + + gsize length; + gchar *data = g_key_file_to_data (cfg, &length, &app->error); + + g_key_file_free (cfg); + + if (app->error != NULL) { + g_warning (app->error->message); + } else { + if (g_file_set_contents (file, data, length, &app->error) == FALSE) + g_warning (app->error->message); + + g_free (data); + } + + g_free (file); + + FREE_GERROR (app->error); +} + +extern void preferences_init (qinfo_t *app) +{ + if (gtk_builder_add_from_file (app->builder, UI_DIR "/preferences.xml", + &app->error) == 0) + { + qinfo_error (app->window, &app->error); + return; + } + + GtkWidget *dialog = GTK_WIDGET (gtk_builder_get_object (app->builder, + "preferences_dialog")); + gtk_window_set_icon (GTK_WINDOW (dialog), app->icon); + + preferences_read (app); + + gtk_builder_connect_signals (app->builder, app); + gtk_widget_show (dialog); +} + +extern void preferences_finish (qinfo_t *app, GtkDialog *dialog, gint response) +{ + if (response == 0) + return; + + if (response == GTK_RESPONSE_OK) + preferences_write (app); + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} diff --git a/src/preferences.h b/src/preferences.h new file mode 100644 index 0000000..3bc1384 --- /dev/null +++ b/src/preferences.h @@ -0,0 +1,29 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include "qinfo.h" +#include "callbacks.h" + +extern void preferences_init (qinfo_t *app); +extern void preferences_finish (qinfo_t *app, GtkDialog *dialog, gint response); + +#endif diff --git a/src/qinfo.c b/src/qinfo.c new file mode 100644 index 0000000..4f04e57 --- /dev/null +++ b/src/qinfo.c @@ -0,0 +1,85 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "qinfo.h" +#include "console.h" +#include "window.h" + +int main (int argc, char *argv[]) +{ + gtk_init (&argc, &argv); + qinfo_t *app = g_slice_new (qinfo_t); + + gboolean console = FALSE, version = FALSE; + gchar **files = NULL, *file = NULL; + + GOptionEntry entries[] = { + {"console", 'c', 0, G_OPTION_ARG_NONE, &console, "Print the file " + "to the console", NULL}, + {"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Version " + "information", NULL}, + {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files, "", + NULL}, + {NULL} + }; + + GOptionContext *context = g_option_context_new ("[FILE]"); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + g_option_context_set_help_enabled (context, TRUE); + g_option_context_set_summary (context, "A tiny but strong ascii art text " + "viewer written in C using GTK+."); + + if (!g_option_context_parse (context, &argc, &argv, &app->error)) { + g_warning (app->error->message); + FREE_GERROR (app->error); + } + + g_option_context_free (context); + + if (files != NULL) { + file = g_strdup (files[0]); + g_strfreev (files); + } + + if (version == TRUE) { + console_version (); + } else if (console == TRUE) { + console_output (app, file); + } else { + window_init (app, file); + } + + g_free (file); + g_slice_free (qinfo_t, app); + + return 0; +} + +extern void qinfo_error (GtkWidget *parent, GError **error) +{ + GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (parent), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, (*error)->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + g_error_free (*error); + *error = NULL; +} diff --git a/src/qinfo.h b/src/qinfo.h new file mode 100644 index 0000000..ab4f02d --- /dev/null +++ b/src/qinfo.h @@ -0,0 +1,56 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef QINFO_H +#define QINFO_H + +#include +#include + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#define FREE_GERROR(error) if ((error) != NULL) \ + g_error_free(error); \ + (error) = NULL + +typedef struct qinfo { + GtkBuilder *builder; + GError *error; + GtkWidget *window; + GtkWidget *view; + GtkTextBuffer *buffer; + GtkTextTag *tag; + PangoFontDescription *font; + GdkColor fg; + GdkColor bg; + gchar *link; + gchar *browser; + gboolean hovering; + GdkCursor *cursor; + GdkCursor *hand; + int x, y; + int width, height; + GdkPixbuf *icon; +} qinfo_t; + +extern void qinfo_error (GtkWidget *parent, GError **error); + +#endif diff --git a/src/settings.c b/src/settings.c new file mode 100644 index 0000000..e572cb8 --- /dev/null +++ b/src/settings.c @@ -0,0 +1,187 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "settings.h" + +extern void settings_read (qinfo_t *app) +{ + GKeyFile *cfg = g_key_file_new (); + + gchar *file = g_build_filename (g_get_user_config_dir (), "qinfo", NULL); + + if (g_key_file_load_from_file (cfg, file, G_KEY_FILE_NONE, &app->error) == + FALSE) + { + g_warning (app->error->message); + } + + g_free (file); + + FREE_GERROR (app->error); + + app->x = g_key_file_get_integer (cfg, "window", "x", &app->error); + if (app->error != NULL) + app->x = 100; + + FREE_GERROR (app->error); + + app->y = g_key_file_get_integer (cfg, "window", "y", &app->error); + if (app->error != NULL) + app->y = 100; + + FREE_GERROR (app->error); + + app->width = g_key_file_get_integer (cfg, "window", "width", &app->error); + if (app->error != NULL) + app->width = 500; + + FREE_GERROR (app->error); + + app->height = g_key_file_get_integer (cfg, "window", "height", &app->error); + if (app->error != NULL) + app->height = 600; + + FREE_GERROR (app->error); + + gtk_window_resize (GTK_WINDOW (app->window), app->width, app->height); + gtk_window_move (GTK_WINDOW (app->window), app->x, app->y); + + gchar *str = g_key_file_get_string (cfg, "textview", "font", &app->error); + if (app->error != NULL) + str = g_strdup ("Terminus 8"); + app->font = pango_font_description_from_string (str); + + FREE_GERROR (app->error); + + str = g_key_file_get_string (cfg, "textview", "text_color", &app->error); + if (app->error != NULL) + str = g_strdup ("#000000"); + gdk_color_parse (str, &app->fg); + gdk_colormap_alloc_color (gdk_colormap_get_system (), &app->fg, FALSE, + TRUE); + g_free (str); + + FREE_GERROR (app->error); + + str = g_key_file_get_string (cfg, "textview", "background_color", + &app->error); + if (app->error != NULL) + str = g_strdup ("#FFFFFF"); + gdk_color_parse (str, &app->bg); + gdk_colormap_alloc_color (gdk_colormap_get_system (), &app->bg, FALSE, + TRUE); + g_free (str); + + FREE_GERROR (app->error); + + str = g_key_file_get_string (cfg, "textview", "link_color", &app->error); + if (app->error != NULL) + app->link = g_strdup ("#0000ff"); + else + app->link = str; + + FREE_GERROR(app->error); + + str = g_key_file_get_string (cfg, "textview", "browser", &app->error); + if (app->error == NULL) + app->browser = str; + else + app->browser = g_strdup ("xdg-open \"%s\""); + + FREE_GERROR(app->error); + + gtk_widget_modify_font (app->view, app->font); + gtk_widget_modify_text (app->view, GTK_STATE_NORMAL, &app->fg); + gtk_widget_modify_base (app->view, GTK_STATE_NORMAL, &app->bg); + g_object_set (app->tag, "foreground", app->link, NULL); + + gint value = g_key_file_get_integer (cfg, "textview", "word_wrap", + &app->error); + if (app->error == NULL) + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (app->view), value); + + FREE_GERROR (app->error); + + value = g_key_file_get_integer (cfg, "textview", "left_margin", + &app->error); + if (app->error == NULL) + gtk_text_view_set_left_margin (GTK_TEXT_VIEW (app->view), value); + + FREE_GERROR (app->error); + + value = g_key_file_get_integer (cfg, "textview", "right_margin", + &app->error); + if (app->error == NULL) + gtk_text_view_set_right_margin (GTK_TEXT_VIEW (app->view), value); + + FREE_GERROR (app->error); + + value = g_key_file_get_integer (cfg, "textview", "pixels_above_lines", + &app->error); + if (app->error == NULL) + gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (app->view), value); + + FREE_GERROR (app->error); + + value = g_key_file_get_integer (cfg, "textview", "pixels_below_lines", + &app->error); + if (app->error == NULL) + gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (app->view), value); + + FREE_GERROR (app->error); + + g_key_file_free (cfg); +} + +extern void settings_write (qinfo_t *app) +{ + gchar *file = g_build_filename (g_get_user_config_dir (), "qinfo", NULL); + GKeyFile *cfg = g_key_file_new (); + + if (g_key_file_load_from_file (cfg, file, G_KEY_FILE_NONE, &app->error) == + FALSE) + { + g_warning (app->error->message); + } + + FREE_GERROR (app->error); + + g_key_file_set_integer (cfg, "window", "width", app->width); + g_key_file_set_integer (cfg, "window", "height", app->height); + g_key_file_set_integer (cfg, "window", "x", app->x); + g_key_file_set_integer (cfg, "window", "y", app->y); + + gsize length; + gchar *data = g_key_file_to_data (cfg, &length, &app->error); + + g_key_file_free (cfg); + + if (app->error != NULL) { + g_warning (app->error->message); + } else { + if (g_file_set_contents (file, data, length, &app->error) == FALSE) + g_warning (app->error->message); + + g_free (data); + } + + g_free (file); + + FREE_GERROR (app->error); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..76c4246 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,28 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "qinfo.h" + +extern void settings_read (qinfo_t *app); +extern void settings_write (qinfo_t *app); + +#endif diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..a2557a1 --- /dev/null +++ b/src/window.c @@ -0,0 +1,98 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "window.h" + +static void window_recent (qinfo_t *app) +{ + GtkRecentFilter *filter = gtk_recent_filter_new (); + gtk_recent_filter_add_application (filter, "qinfo"); + + GtkWidget *recent = gtk_recent_chooser_menu_new (); + gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent), + GTK_RECENT_SORT_MRU); + gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent), 10); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (recent), filter); + + GtkWidget *button = GTK_WIDGET (gtk_builder_get_object (app->builder, + "open_toolbar_item")); + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (button), recent); + + g_signal_connect (GTK_RECENT_CHOOSER (recent), "item-activated", + G_CALLBACK (on_open_toolbar_item_activated), app); +} + +static void window_dnd (qinfo_t *app) +{ + GtkTargetEntry types[] = { + {"text/uri-list", 0, 0} + }; + + gtk_drag_dest_set (app->view, GTK_DEST_DEFAULT_ALL, types, 1, + GDK_ACTION_COPY); +} + +extern void window_init (qinfo_t *app, const gchar *file) +{ + app->builder = gtk_builder_new (); + + if (gtk_builder_add_from_file (app->builder, UI_DIR "/main.xml", + &app->error) == 0) + { + qinfo_error (NULL, &app->error); + return; + } + + app->window = GTK_WIDGET (gtk_builder_get_object (app->builder, "window")); + app->view = GTK_WIDGET (gtk_builder_get_object (app->builder, "textview")); + app->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (app->view)); + app->tag = gtk_text_buffer_create_tag (app->buffer, NULL, "foreground", + "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); + app->cursor = gdk_cursor_new (GDK_XTERM); + app->hand = gdk_cursor_new (GDK_HAND2); + app->icon = gdk_pixbuf_new_from_file (PIXMAPS_DIR "/qinfo.png", NULL); + + gtk_window_set_icon (GTK_WINDOW (app->window), app->icon); + + gtk_builder_connect_signals (app->builder, app); + + window_recent (app); + window_dnd (app); + + settings_read (app); + + gtk_widget_show (app->window); + + if (file != NULL) + open_file (app, file); + + gtk_main (); + + settings_write (app); + + gdk_colormap_free_colors (gdk_colormap_get_system (), &app->fg, 1); + gdk_colormap_free_colors (gdk_colormap_get_system (), &app->bg, 1); + pango_font_description_free (app->font); + g_free (app->browser); + g_free (app->link); + gdk_cursor_unref (app->cursor); + gdk_cursor_unref (app->hand); + g_object_unref (app->icon); + g_object_unref (app->builder); +} diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..d18857f --- /dev/null +++ b/src/window.h @@ -0,0 +1,28 @@ +/** + * qinfo - GTK+ based ascii art text viewer + * Copyright (C) 2008 Oliver Mader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef WINDOW_H +#define WINDOW_H + +#include "callbacks.h" +#include "settings.h" + +extern void window_init (qinfo_t *app, const gchar *file); + +#endif -- cgit v1.2.3-24-g4f1b