diff -Nru kchmviewer-4.1/build-release.sh kchmviewer-5.1/build-release.sh --- kchmviewer-4.1/build-release.sh 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/build-release.sh 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,61 @@ +#!/bin/sh + +# Export the source code + +PACKAGE=kchmviewer +BINARYFILE="bin/kchmviewer" + +FILE_VERSION="src/version.h" +RPM_ARCH="i586" +RPM_OUTDIR="/usr/src/packages/RPMS/$RPM_ARCH" + +# Get current version +VERSION_MAJOR=`sed -n 's/^\#define\s\+APP_VERSION_MAJOR\s\+\([0-9]\+\)/\1/p' $FILE_VERSION` +VERSION_MINOR=`sed -n 's/^\#define\s\+APP_VERSION_MINOR\s\+\([0-9]\+\)/\1/p' $FILE_VERSION` +CURRENTVER="$VERSION_MAJOR.$VERSION_MINOR" + +BUILDDIR="build-$CURRENTVER" +RELEASEDIR="release-$CURRENTVER" + +if [ -d "$BUILDDIR" ]; then + rm -rf "$BUILDDIR" +fi + +if [ -d "$RELEASEDIR" ]; then + rm -rf "$RELEASEDIR" +fi +mkdir "$RELEASEDIR" || exit 1 + +svn export . "$BUILDDIR/" || exit 1 + +# Source package without examples +tar zcf "$RELEASEDIR/$PACKAGE-$CURRENTVER.tar.gz" $BUILDDIR || exit 1 + +# Build it +(cd "$BUILDDIR" && qmake && make -j4) || exit 1 + +# Making an RPM +rm -rf "$BUILDDIR/buildroot" +mkdir -p "$BUILDDIR/buildroot/usr/bin" +mkdir -p "$BUILDDIR/buildroot/usr/share/applications" +mkdir -p "$BUILDDIR/buildroot/usr/share/pixmaps" +strip --strip-all "$BUILDDIR/$BINARYFILE" +cp "$BUILDDIR/$BINARYFILE" "$BUILDDIR/buildroot/usr/bin/" || exit 1 +cp packages/*.desktop "$BUILDDIR/buildroot/usr/share/applications" +cp packages/*.png "$BUILDDIR/buildroot/usr/share/pixmaps" + +# Prepare a spec file +sed "s/^Version: [0-9.]\\+/Version: $CURRENTVER/" packages/rpm.spec > $BUILDDIR/rpm.spec + +rpmbuild -bb --target=$RPM_ARCH --buildroot `pwd`"/$BUILDDIR/buildroot/" $BUILDDIR/rpm.spec || exit 1 +mv $RPM_OUTDIR/*.rpm $RELEASEDIR || exit 1 +rm -rf "$BUILDDIR" + +# win32 +sh build-win32-mingw.sh || exit 1 +(cd nsis && sh create_installer.sh) || exit 1 +mv nsis/InstallKchmviewer*.exe $RELEASEDIR + +rm -rf "$BUILDDIR" +rm -rf "build.win32" +echo "Done! Version $CURRENTVER released!" diff -Nru kchmviewer-4.1/build-win32-mingw.sh kchmviewer-5.1/build-win32-mingw.sh --- kchmviewer-4.1/build-win32-mingw.sh 2009-07-20 03:43:50.000000000 +0100 +++ kchmviewer-5.1/build-win32-mingw.sh 2009-12-15 06:02:57.000000000 +0000 @@ -17,4 +17,4 @@ # Compile it export PATH=$MINGWPATH:$PATH -$QTPATH/bin/qmake -r -spec win32-mingw-g++ && make || exit 1 +$QTPATH/bin/qmake -r -spec win32-mingw-g++ && make -j4 || exit 1 diff -Nru kchmviewer-4.1/ChangeLog kchmviewer-5.1/ChangeLog --- kchmviewer-4.1/ChangeLog 2009-07-20 04:33:41.000000000 +0100 +++ kchmviewer-5.1/ChangeLog 2009-12-17 09:44:14.000000000 +0000 @@ -1,3 +1,37 @@ +2009-12-17 tim + - 5.1 RELEASE + - Trying to use non-normalized URL first to fix CHMs which use them in TOC/Index + +2009-12-16 tim + - Fixed application settings storage. + - Fixed bookmark edit button. + - Version changed to 5.1 + +2009-12-14 tim + - 5.0 RELEASE + - Version changed to 5.0 + - Binary index parser commented out as it seems to be buggy. + - Toolbar mode is now configurable through settings. + - Now the application can start without opening a CHM file. Startup mode is selected in settings. + - Added check if a new version is available. + - Added new icons from DryIcons + +2009-12-13 tim + - Major code refactoring, with renamed files and classes, to make it easier to maintain + the code in future. + - Changed all license headers to GPLv3-compliant. + - Recent files feature now uses a separate class. + - The navigator tab is now a Dock widget, so can be moved and floated. + - Content tab is now always loaded, and the page is correctly located. + +2009-24-10 tim + - Version changed to 4.2 + - Fixed font size change on KHTMLPart (thanks to Jure Repinc) + - Fixed Windows file opener being unable to open the file with non-English characters. + - Fixed "Open in new tab" for QTextBrowser opening an empty page. + - Middle button in QTextBrowser and WebKit now opens the link in new tab in background. + - Middle button now closes opened tabs in the tab bar. + 2009-19-07 tim - Version changed to 4.1 - Updated Dutch translation (thanks to Sander Pientka) diff -Nru kchmviewer-4.1/CMakeLists.txt kchmviewer-5.1/CMakeLists.txt --- kchmviewer-4.1/CMakeLists.txt 2008-12-02 02:31:22.000000000 +0000 +++ kchmviewer-5.1/CMakeLists.txt 2010-02-27 21:12:14.000000000 +0000 @@ -18,6 +18,6 @@ # Run in those subdirectories ADD_SUBDIRECTORY( lib/libchmfile ) -ADD_SUBDIRECTORY( lib/kio-msits ) ADD_SUBDIRECTORY( src ) ADD_SUBDIRECTORY( po ) +ADD_SUBDIRECTORY( packages ) diff -Nru kchmviewer-4.1/debian/changelog kchmviewer-5.1/debian/changelog --- kchmviewer-4.1/debian/changelog 2010-02-27 21:12:13.000000000 +0000 +++ kchmviewer-5.1/debian/changelog 2010-02-27 21:12:14.000000000 +0000 @@ -1,3 +1,9 @@ +kchmviewer (5.1-0~padoka1) lucid; urgency=low + + * New upstream version + + -- Paulo Dias Sat, 27 Feb 2010 17:13:47 +0000 + kchmviewer (4.1-1) unstable; urgency=low * New upstream release. (Closes: #479402, #496888) diff -Nru kchmviewer-4.1/debian/control kchmviewer-5.1/debian/control --- kchmviewer-4.1/debian/control 2010-02-27 21:12:13.000000000 +0000 +++ kchmviewer-5.1/debian/control 2010-02-27 21:12:14.000000000 +0000 @@ -2,10 +2,10 @@ Section: kde Priority: optional Maintainer: Debian KDE Extras Team -Uploaders: Fathi Boudra , Jose Luis Tallon -Build-Depends: debhelper (>= 7.3.8), cmake, quilt, pkg-kde-tools (>= 0.4.11), +Original-Maintainer: Paulo Dias +Build-Depends: cdbs, debhelper (>= 7.3.8), cmake, quilt, pkg-kde-tools (>= 0.4.11), kdelibs5-dev, libchm-dev -Standards-Version: 3.8.2 +Standards-Version: 3.8.4 Homepage: http://www.kchmviewer.net/ Package: kchmviewer diff -Nru kchmviewer-4.1/debian/rules kchmviewer-5.1/debian/rules --- kchmviewer-4.1/debian/rules 2010-02-27 21:12:13.000000000 +0000 +++ kchmviewer-5.1/debian/rules 2010-02-27 21:12:14.000000000 +0000 @@ -1,6 +1,4 @@ #!/usr/bin/make -f -include /usr/share/pkg-kde-tools/makefiles/1/debhelper/kde.mk - -%: - dh --with quilt $@ +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/pkg-kde-tools/makefiles/1/cdbs/kde.mk diff -Nru kchmviewer-4.1/Doxyfile kchmviewer-5.1/Doxyfile --- kchmviewer-4.1/Doxyfile 2005-04-07 18:42:43.000000000 +0100 +++ kchmviewer-5.1/Doxyfile 1970-01-01 01:00:00.000000000 +0100 @@ -1,275 +0,0 @@ -# Doxyfile 1.4.1-KDevelop - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = kchmviewer.kdevelop -PROJECT_NUMBER = 0.1 -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -USE_WINDOWS_ENCODING = NO -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = YES -STRIP_FROM_PATH = /home/tim/ -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = NO -INHERIT_DOCS = YES -DISTRIBUTE_GROUP_DOC = NO -TAB_SIZE = 8 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = YES -FILE_VERSION_FILTER = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = /home/tim/work/kchmviewer -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.idl \ - *.odl \ - *.cs \ - *.php \ - *.php3 \ - *.inc \ - *.m \ - *.mm \ - *.dox \ - *.C \ - *.CC \ - *.C++ \ - *.II \ - *.I++ \ - *.H \ - *.HH \ - *.H++ \ - *.CS \ - *.PHP \ - *.PHP3 \ - *.M \ - *.MM \ - *.C \ - *.H \ - *.tlh \ - *.diff \ - *.patch \ - *.moc \ - *.xpm \ - *.dox -RECURSIVE = yes -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = YES -REFERENCES_RELATION = YES -VERBATIM_HEADERS = YES -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = NO -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = YES -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = NO -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = yes -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = kchmviewer.tag -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = NO -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -MAX_DOT_GRAPH_WIDTH = 1024 -MAX_DOT_GRAPH_HEIGHT = 1024 -MAX_DOT_GRAPH_DEPTH = 1000 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = NO diff -Nru kchmviewer-4.1/kchmviewer.kdevelop kchmviewer-5.1/kchmviewer.kdevelop --- kchmviewer-4.1/kchmviewer.kdevelop 2008-12-02 03:02:27.000000000 +0000 +++ kchmviewer-5.1/kchmviewer.kdevelop 1970-01-01 01:00:00.000000000 +0100 @@ -1,234 +0,0 @@ - - - - George Yunaev - gyunaev@ulduzsoft.com - 4.0 - KDevTrollProject - C++ - - Qt - - - kchmviewer - . - false - - - - - - - - - - - false - false - - - false - *.o,*.lo,CVS - - - - - true - 4 - 4 - ExternalDesigner - /home/tim/bin/qt-4.4.0/bin/qmake - /usr/bin/designer - /usr/lib/qt4 - - - - true - true - true - 250 - 400 - 250 - false - 0 - true - true - true - std=_GLIBCXX_STD;__gnu_cxx=std - true - false - true - false - true - true - true - false - .; - false - false - - - - set - m_,_ - theValue - true - true - - - false - true - Vertical - - - - - - bash - bash_bugs - clanlib - fortran_bugs_gcc - gnome1 - gnustep - gtk - gtk_bugs - haskell - haskell_bugs_ghc - java_bugs_gcc - java_bugs_sun - kde2book - opengl - pascal_bugs_fp - php - php_bugs - perl - perl_bugs - python - python_bugs - qt-kdev3 - ruby - ruby_bugs - sdl - stl - sw - w3c-dom-level2-html - w3c-svg - w3c-uaag10 - wxwidgets_bugs - - - KDE Libraries (Doxygen) - - - - - - - - /usr/bin/gdb - true - false - false - - - - false - - - false - true - 10 - - - - - - /home/tim/work/my/kchmviewer - - executable - - /home/tim/work/my/kchmviewer - false - false - true - false - false - - - - - - /home/tim/work/my/kchmviewer - - - - - - - src - - - true - false - 1 - false - - 0 - - - - 2 - false - true - false - true - true - - - - - - - - - - - - - - - - - - Doxygen Documentation Collection - kchmviewer.tag - - - - - kchmviewer - kchmviewer - Kchmviewer - KCHMVIEWER - George Yunaev - /usr/bin/designer - gyunaev@ulduzsoft.com - GPL - COPYING - /usr/bin/qmake - 4.0 - 2007 - /home/tim/work/kchmviewer - - - - .h - .cpp - - - - - /home/tim/work/kchmviewer/tags - - - diff -Nru kchmviewer-4.1/lib/libchmfile/bitfiddle.h kchmviewer-5.1/lib/libchmfile/bitfiddle.h --- kchmviewer-4.1/lib/libchmfile/bitfiddle.h 2008-12-01 09:03:08.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/bitfiddle.h 2009-10-25 00:12:05.000000000 +0100 @@ -47,9 +47,9 @@ } -inline u_int64_t be_encint(unsigned char* buffer, size_t& length) +inline quint64 be_encint(unsigned char* buffer, size_t& length) { - u_int64_t result = 0; + quint64 result = 0; int shift=0; length = 0; @@ -95,17 +95,17 @@ } -inline u_int64_t sr_int(unsigned char* byte, int* bit, +inline quint64 sr_int(unsigned char* byte, int* bit, unsigned char s, unsigned char r, size_t& length) { - u_int64_t ret; + quint64 ret; unsigned char mask; int n, n_bits, num_bits, base, count; length = 0; size_t fflen; if(!bit || *bit > 7 || s != 2) - return ~(u_int64_t)0; + return ~(quint64)0; ret = 0; count = ffus(byte, bit, fflen); @@ -150,7 +150,7 @@ mask <<= base; ret = (ret << (num_bits+1)) | - (u_int64_t)((*byte & mask) >> base); + (quint64)((*byte & mask) >> base); if( n > *bit ){ ++byte; @@ -164,7 +164,7 @@ } if(count) - ret |= (u_int64_t)1 << n_bits; + ret |= (quint64)1 << n_bits; return ret; } diff -Nru kchmviewer-4.1/lib/libchmfile/chmlib-win32/chm_lib.h kchmviewer-5.1/lib/libchmfile/chmlib-win32/chm_lib.h --- kchmviewer-4.1/lib/libchmfile/chmlib-win32/chm_lib.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/lib/libchmfile/chmlib-win32/chm_lib.h 2009-10-25 00:12:05.000000000 +0100 @@ -0,0 +1,147 @@ +/* $Id: chm_lib.h,v 1.10 2002/10/09 01:16:33 jedwin Exp $ */ +/*************************************************************************** + * chm_lib.h - CHM archive manipulation routines * + * ------------------- * + * * + * author: Jed Wing * + * version: 0.3 * + * notes: These routines are meant for the manipulation of microsoft * + * .chm (compiled html help) files, but may likely be used * + * for the manipulation of any ITSS archive, if ever ITSS * + * archives are used for any other purpose. * + * * + * Note also that the section names are statically handled. * + * To be entirely correct, the section names should be read * + * from the section names meta-file, and then the various * + * content sections and the "transforms" to apply to the data * + * they contain should be inferred from the section name and * + * the meta-files referenced using that name; however, all of * + * the files I've been able to get my hands on appear to have * + * only two sections: Uncompressed and MSCompressed. * + * Additionally, the ITSS.DLL file included with Windows does * + * not appear to handle any different transforms than the * + * simple LZX-transform. Furthermore, the list of transforms * + * to apply is broken, in that only half the required space * + * is allocated for the list. (It appears as though the * + * space is allocated for ASCII strings, but the strings are * + * written as unicode. As a result, only the first half of * + * the string appears.) So this is probably not too big of * + * a deal, at least until CHM v4 (MS .lit files), which also * + * incorporate encryption, of some description. * + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation; either version 2.1 of the * + * License, or (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef INCLUDED_CHMLIB_H +#define INCLUDED_CHMLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* RWE 6/12/1002 */ +#ifdef PPC_BSTR +#include +#endif + +#ifdef WIN32 +#include +#ifdef __MINGW32__ +#define __int64 long long +#endif +typedef unsigned __int64 LONGUINT64; +typedef __int64 LONGINT64; +#else +typedef unsigned long long LONGUINT64; +typedef long long LONGINT64; +#endif + +/* the two available spaces in a CHM file */ +/* N.B.: The format supports arbitrarily many spaces, but only */ +/* two appear to be used at present. */ +#define CHM_UNCOMPRESSED (0) +#define CHM_COMPRESSED (1) + +/* structure representing an ITS (CHM) file stream */ +struct chmFile; + +/* structure representing an element from an ITS file stream */ +#define CHM_MAX_PATHLEN (512) +struct chmUnitInfo +{ + LONGUINT64 start; + LONGUINT64 length; + int space; + int flags; + char path[CHM_MAX_PATHLEN+1]; +}; + +/* open an ITS archive */ +#ifdef PPC_BSTR +/* RWE 6/12/2003 */ +struct chmFile* chm_open(BSTR filename); +#elif defined (WIN32) +struct chmFile* chm_open(const WCHAR *filename); +#else +struct chmFile* chm_open(const char *filename); +#endif + +/* close an ITS archive */ +void chm_close(struct chmFile *h); + +/* methods for ssetting tuning parameters for particular file */ +#define CHM_PARAM_MAX_BLOCKS_CACHED 0 +void chm_set_param(struct chmFile *h, + int paramType, + int paramVal); + +/* resolve a particular object from the archive */ +#define CHM_RESOLVE_SUCCESS (0) +#define CHM_RESOLVE_FAILURE (1) +int chm_resolve_object(struct chmFile *h, + const char *objPath, + struct chmUnitInfo *ui); + +/* retrieve part of an object from the archive */ +LONGINT64 chm_retrieve_object(struct chmFile *h, + struct chmUnitInfo *ui, + unsigned char *buf, + LONGUINT64 addr, + LONGINT64 len); + +/* enumerate the objects in the .chm archive */ +typedef int (*CHM_ENUMERATOR)(struct chmFile *h, + struct chmUnitInfo *ui, + void *context); +#define CHM_ENUMERATE_NORMAL (1) +#define CHM_ENUMERATE_META (2) +#define CHM_ENUMERATE_SPECIAL (4) +#define CHM_ENUMERATE_FILES (8) +#define CHM_ENUMERATE_DIRS (16) +#define CHM_ENUMERATE_ALL (31) +#define CHM_ENUMERATOR_FAILURE (0) +#define CHM_ENUMERATOR_CONTINUE (1) +#define CHM_ENUMERATOR_SUCCESS (2) +int chm_enumerate(struct chmFile *h, + int what, + CHM_ENUMERATOR e, + void *context); + +int chm_enumerate_dir(struct chmFile *h, + const char *prefix, + int what, + CHM_ENUMERATOR e, + void *context); + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDED_CHMLIB_H */ diff -Nru kchmviewer-4.1/lib/libchmfile/chmlib-win32/chmlib-win32.patch kchmviewer-5.1/lib/libchmfile/chmlib-win32/chmlib-win32.patch --- kchmviewer-4.1/lib/libchmfile/chmlib-win32/chmlib-win32.patch 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/lib/libchmfile/chmlib-win32/chmlib-win32.patch 2009-10-25 00:12:05.000000000 +0100 @@ -0,0 +1,42 @@ +diff -ur chmlib-0.40/src/chm_lib.c chmlib-0.40.mod/src/chm_lib.c +--- chmlib-0.40/src/chm_lib.c 2009-05-23 07:43:31.000000000 -0700 ++++ chmlib-0.40.mod/src/chm_lib.c 2009-10-24 15:50:08.000000000 -0700 +@@ -750,6 +750,8 @@ + #ifdef PPC_BSTR + /* RWE 6/12/2003 */ + struct chmFile *chm_open(BSTR filename) ++#elif defined (WIN32) ++struct chmFile* chm_open(const WCHAR *filename) + #else + struct chmFile *chm_open(const char *filename) + #endif +@@ -791,7 +793,7 @@ + return NULL; + } + #else +- if ((newHandle->fd=CreateFileA(filename, ++ if ((newHandle->fd=CreateFileW(filename, + GENERIC_READ, + 0, + NULL, +Only in chmlib-0.40.mod/src: chm_lib.c~ +diff -ur chmlib-0.40/src/chm_lib.h chmlib-0.40.mod/src/chm_lib.h +--- chmlib-0.40/src/chm_lib.h 2009-05-23 07:43:31.000000000 -0700 ++++ chmlib-0.40.mod/src/chm_lib.h 2009-10-24 15:49:48.000000000 -0700 +@@ -52,6 +52,7 @@ + #endif + + #ifdef WIN32 ++#include + #ifdef __MINGW32__ + #define __int64 long long + #endif +@@ -86,6 +87,8 @@ + #ifdef PPC_BSTR + /* RWE 6/12/2003 */ + struct chmFile* chm_open(BSTR filename); ++#elif defined (WIN32) ++struct chmFile* chm_open(const WCHAR *filename); + #else + struct chmFile* chm_open(const char *filename); + #endif diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfile.cpp kchmviewer-5.1/lib/libchmfile/libchmfile.cpp --- kchmviewer-4.1/lib/libchmfile/libchmfile.cpp 2008-12-01 09:03:08.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmfile.cpp 2009-12-14 10:11:04.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "libchmfile.h" #include "libchmfileimpl.h" @@ -79,8 +76,8 @@ bool LCHMFile::parseIndex( QVector< LCHMParsedEntry > * indexes ) const { - return m_impl->parseBinaryIndex( indexes ) - || m_impl->parseFileAndFillArray( m_impl->m_indexFile, indexes, true ); + //return m_impl->parseBinaryIndex( indexes ) + return m_impl->parseFileAndFillArray( m_impl->m_indexFile, indexes, true ); } bool LCHMFile::getFileContentAsString( QString * str, const QString & url ) diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfile.h kchmviewer-5.1/lib/libchmfile/libchmfile.h --- kchmviewer-4.1/lib/libchmfile/libchmfile.h 2008-02-11 01:15:15.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmfile.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef INCLUDE_LIBCHMFILE_H #define INCLUDE_LIBCHMFILE_H diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfileimpl.cpp kchmviewer-5.1/lib/libchmfile/libchmfileimpl.cpp --- kchmviewer-4.1/lib/libchmfile/libchmfileimpl.cpp 2009-07-20 02:30:11.000000000 +0100 +++ kchmviewer-5.1/lib/libchmfile/libchmfileimpl.cpp 2009-12-14 10:11:04.000000000 +0000 @@ -1,24 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Portions Copyright (C) 2003 Razvan Cojocaru * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include @@ -30,7 +26,12 @@ #include #include -#include "chm_lib.h" +#if defined (USE_PATCHED_CHMLIB) + #include "chmlib-win32/chm_lib.h" +#else + #include "chm_lib.h" +#endif + #include "bitfiddle.h" #include "libchmfile.h" #include "libchmurlfactory.h" @@ -87,7 +88,11 @@ if( m_chmFile ) closeAll(); +#if defined (USE_PATCHED_CHMLIB) + m_chmFile = chm_open( (WCHAR*) filename.utf16() ); +#else m_chmFile = chm_open( QFile::encodeName(filename) ); +#endif if ( m_chmFile == NULL ) return false; @@ -474,7 +479,7 @@ free_space = UINT16ARRAY(cursor16); i = sizeof(unsigned int) + sizeof(unsigned short) + sizeof(unsigned short); - u_int64_t wlc_count, wlc_size; + quint64 wlc_count, wlc_size; unsigned int wlc_offset; while (i < node_len - free_space) @@ -571,9 +576,9 @@ inline unsigned int LCHMFileImpl::GetLeafNodeOffset(const QString& text, - unsigned int initialOffset, - unsigned int buffSize, - unsigned short treeDepth) + unsigned int initialOffset, + unsigned int buffSize, + unsigned short treeDepth) { unsigned int test_offset = 0; unsigned char* cursor16, *cursor32; @@ -629,7 +634,7 @@ } -inline bool LCHMFileImpl::ProcessWLC (u_int64_t wlc_count, u_int64_t wlc_size, +inline bool LCHMFileImpl::ProcessWLC (quint64 wlc_count, quint64 wlc_size, unsigned int wlc_offset, unsigned char ds, unsigned char dr, unsigned char cs, unsigned char cr, unsigned char ls, @@ -638,7 +643,7 @@ bool phrase_search) { int wlc_bit = 7; - u_int64_t index = 0, count; + quint64 index = 0, count; size_t length, off = 0; QVector buffer (wlc_size); unsigned char *cursor32; @@ -649,7 +654,7 @@ if ( RetrieveObject (&m_chmFIftiMain, buffer.data(), wlc_offset, wlc_size) == 0 ) return false; - for ( u_int64_t i = 0; i < wlc_count; ++i ) + for ( quint64 i = 0; i < wlc_count; ++i ) { if ( wlc_bit != 7 ) { @@ -683,9 +688,9 @@ if ( phrase_search ) progres.offsets.reserve (count); - for (u_int64_t j = 0; j < count; ++j) + for (quint64 j = 0; j < count; ++j) { - u_int64_t lcode = sr_int (buffer.data() + off, &wlc_bit, ls, lr, length); + quint64 lcode = sr_int (buffer.data() + off, &wlc_bit, ls, lr, length); off += length; if ( phrase_search ) @@ -990,7 +995,7 @@ // Split the HHC file by HTML tags int stringlen = src.length(); - + while ( pos < stringlen && (pos = src.indexOf ('<', pos)) != -1 ) { int i, word_end = 0; @@ -1023,7 +1028,7 @@ else tagword = tag.toLower(); - //qDebug ("tag: '%s', tagword: '%s'\n", qPrintable( tag ), qPrintable( tagword ) ); +// qDebug ("tag: '%s', tagword: '%s'\n", qPrintable( tag ), qPrintable( tagword ) ); // - a topic entry if ( tagword == "object" && tag.indexOf ("text/sitemap", 0, Qt::CaseInsensitive ) != -1 ) diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfileimpl.h kchmviewer-5.1/lib/libchmfile/libchmfileimpl.h --- kchmviewer-4.1/lib/libchmfile/libchmfileimpl.h 2009-07-20 02:30:11.000000000 +0100 +++ kchmviewer-5.1/lib/libchmfile/libchmfileimpl.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,31 +1,31 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Portions Copyright (C) 2003 Razvan Cojocaru * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef INCLUDE_LIBCHMFILEIMPL_H #define INCLUDE_LIBCHMFILEIMPL_H -#include +#if defined (USE_CHMLIB_WIN32) + #include "chmlib-win32/chm_lib.h" +#else + #include "chm_lib.h" +#endif -#include "chm_lib.h" +#include #include "libchmfile.h" #include "libchmtocimage.h" @@ -38,11 +38,11 @@ { public: inline LCHMSearchProgressResult() {} - inline LCHMSearchProgressResult( u_int32_t t, u_int32_t u ) : titleoff(t),urloff(u) {} + inline LCHMSearchProgressResult( unsigned int t, unsigned int u ) : titleoff(t),urloff(u) {} - QVector offsets; - u_int32_t titleoff; - u_int32_t urloff; + QVector offsets; + quint32 titleoff; + quint32 urloff; }; //! An array to keeps the intermediate search results @@ -144,15 +144,15 @@ const char * GetFontEncFromCharSet (const QString& font) const; //! Helper. Returns the $FIftiMain offset of leaf node or 0. - u_int32_t GetLeafNodeOffset(const QString& text, - u_int32_t initalOffset, - u_int32_t buffSize, - u_int16_t treeDepth ); + unsigned int GetLeafNodeOffset(const QString& text, + unsigned int initialOffset, + unsigned int buffSize, + unsigned short treeDepth); //! Helper. Processes the word location code entries while searching. - bool ProcessWLC(u_int64_t wlc_count, - u_int64_t wlc_size, - u_int32_t wlc_offset, + bool ProcessWLC(quint64 wlc_count, + quint64 wlc_size, + quint32 wlc_offset, unsigned char ds, unsigned char dr, unsigned char cs, diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfile.pro kchmviewer-5.1/lib/libchmfile/libchmfile.pro --- kchmviewer-4.1/lib/libchmfile/libchmfile.pro 2008-12-02 01:43:24.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmfile.pro 2009-10-25 00:12:05.000000000 +0100 @@ -24,3 +24,6 @@ INCLUDEPATH += ../../src CONFIG -= release +win32-mingw-g++: { + DEFINES += USE_PATCHED_CHMLIB +} diff -Nru kchmviewer-4.1/lib/libchmfile/libchmfile_search.cpp kchmviewer-5.1/lib/libchmfile/libchmfile_search.cpp --- kchmviewer-4.1/lib/libchmfile/libchmfile_search.cpp 2008-02-11 01:15:15.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmfile_search.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include @@ -80,12 +77,12 @@ } -static inline void findNextWords ( QVector & src, const QVector & needle ) +static inline void findNextWords ( QVector & src, const QVector & needle ) { for ( int s1 = 0; s1 < src.size(); s1++ ) { bool found = false; - u_int64_t target_offset = src[s1] + 1; + quint64 target_offset = src[s1] + 1; DEBUG_SEARCH (("Offset loop: offset at %u is %u, target %u", (unsigned int) s1, (unsigned int) src[s1], (unsigned int) target_offset)); diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine.cpp kchmviewer-5.1/lib/libchmfile/libchmsearchengine.cpp --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine.cpp 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "libchmfile.h" #include "libchmurlfactory.h" diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine.h kchmviewer-5.1/lib/libchmfile/libchmsearchengine.h --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine.h 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef LCHMSEARCHENGINE_H #define LCHMSEARCHENGINE_H diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine_impl.cpp kchmviewer-5.1/lib/libchmfile/libchmsearchengine_impl.cpp --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine_impl.cpp 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine_impl.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine_impl.h kchmviewer-5.1/lib/libchmfile/libchmsearchengine_impl.h --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine_impl.h 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine_impl.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef LCHMSEARCHENGINE_IMPL_H #define LCHMSEARCHENGINE_IMPL_H diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine_indexing.cpp kchmviewer-5.1/lib/libchmfile/libchmsearchengine_indexing.cpp --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine_indexing.cpp 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine_indexing.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,24 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Portions Copyright (C) 2000-2005 Trolltech AS. * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include diff -Nru kchmviewer-4.1/lib/libchmfile/libchmsearchengine_indexing.h kchmviewer-5.1/lib/libchmfile/libchmsearchengine_indexing.h --- kchmviewer-4.1/lib/libchmfile/libchmsearchengine_indexing.h 2008-02-12 01:37:21.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmsearchengine_indexing.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,24 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Portions Copyright (C) 2000-2005 Trolltech AS. * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef QASSISTANTINDEX_H #define QASSISTANTINDEX_H diff -Nru kchmviewer-4.1/lib/libchmfile/libchmtextencoding.cpp kchmviewer-5.1/lib/libchmfile/libchmtextencoding.cpp --- kchmviewer-4.1/lib/libchmfile/libchmtextencoding.cpp 2008-02-11 01:15:15.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmtextencoding.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "libchmfileimpl.h" #include "libchmtextencoding.h" diff -Nru kchmviewer-4.1/lib/libchmfile/libchmtextencoding.h kchmviewer-5.1/lib/libchmfile/libchmtextencoding.h --- kchmviewer-4.1/lib/libchmfile/libchmtextencoding.h 2008-06-10 01:46:56.000000000 +0100 +++ kchmviewer-5.1/lib/libchmfile/libchmtextencoding.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef LIBCHMTEXTENCODING_H #define LIBCHMTEXTENCODING_H diff -Nru kchmviewer-4.1/lib/libchmfile/libchmtocimage.cpp kchmviewer-5.1/lib/libchmfile/libchmtocimage.cpp --- kchmviewer-4.1/lib/libchmfile/libchmtocimage.cpp 2008-02-11 01:15:15.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmtocimage.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "libchmfile.h" #include "libchmtocimage.h" diff -Nru kchmviewer-4.1/lib/libchmfile/libchmtocimage.h kchmviewer-5.1/lib/libchmfile/libchmtocimage.h --- kchmviewer-4.1/lib/libchmfile/libchmtocimage.h 2008-12-01 10:03:06.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmtocimage.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,33 +1,26 @@ -//Added by qt3to4: -#include -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef INCLUDE_LIBCHMTOCIMAGE_H #define INCLUDE_LIBCHMTOCIMAGE_H - #include - //! This class is used to retrieve the book TOC icons associated with images class LCHMTocImageKeeper { diff -Nru kchmviewer-4.1/lib/libchmfile/libchmurlfactory.h kchmviewer-5.1/lib/libchmfile/libchmurlfactory.h --- kchmviewer-4.1/lib/libchmfile/libchmurlfactory.h 2008-02-12 00:31:26.000000000 +0000 +++ kchmviewer-5.1/lib/libchmfile/libchmurlfactory.h 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef LIBCHMURLFACTORY_H #define LIBCHMURLFACTORY_H diff -Nru kchmviewer-4.1/nsis/create_installer.sh kchmviewer-5.1/nsis/create_installer.sh --- kchmviewer-4.1/nsis/create_installer.sh 2009-07-20 04:30:48.000000000 +0100 +++ kchmviewer-5.1/nsis/create_installer.sh 2009-12-15 06:12:30.000000000 +0000 @@ -21,7 +21,9 @@ export NSISDIR=/home/tim/bin/nsis # Get current, and save the next version -VERSION=`sed -n 's/^\#define\s\+APP_VERSION\s\+\"\([0-9.a-zA-Z]\+\)\"/\1/p' $FILE_VERSION` +VERSION_MAJOR=`sed -n 's/^\#define\s\+APP_VERSION_MAJOR\s\+\([0-9]\+\)/\1/p' $FILE_VERSION` +VERSION_MINOR=`sed -n 's/^\#define\s\+APP_VERSION_MINOR\s\+\([0-9]\+\)/\1/p' $FILE_VERSION` +VERSION="$VERSION_MAJOR.$VERSION_MINOR" INSTNAME="InstallKchmviewer-$VERSION.exe" echo "Creating $INSTNAME" diff -Nru kchmviewer-4.1/packages/CMakeLists.txt kchmviewer-5.1/packages/CMakeLists.txt --- kchmviewer-4.1/packages/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/packages/CMakeLists.txt 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,4 @@ +INSTALL( FILES kchmviewer.desktop DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR} ) +KDE4_INSTALL_ICONS( ${KDE4_ICON_INSTALL_DIR} ) +KDE4_UPDATE_ICONCACHE( ) + diff -Nru kchmviewer-4.1/packages/kchmviewer.desktop kchmviewer-5.1/packages/kchmviewer.desktop --- kchmviewer-4.1/packages/kchmviewer.desktop 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/packages/kchmviewer.desktop 2009-12-15 06:02:57.000000000 +0000 @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=KchmViewer +Categories=Qt;KDE;Office;Viewer; +Terminal=false +Type=Application +Encoding=UTF-8 +Exec=kchmviewer %f +Icon=kchmviewer +GenericName=CHM file viewer +Comment=A viewer of CHM (MS-Help) files +MimeType=application/chm;application/x-chm; Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/packages/kchmviewer.png and /tmp/gVx62UHKyn/kchmviewer-5.1/packages/kchmviewer.png differ diff -Nru kchmviewer-4.1/packages/rpm.spec kchmviewer-5.1/packages/rpm.spec --- kchmviewer-4.1/packages/rpm.spec 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/packages/rpm.spec 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,29 @@ +Summary: Free CHM files viewer application +Name: kchmviewer +Version: 0.7 +Release: 1 +License: GPLv3+ +Group: Applications/Office +Packager: kchmviewer@ulduzsoft.com +URL: http://www.kchmviewer.net +%description +Kchmviewer is a free, open-source chm (MS HTML help file format) viewer, +which uses Qt toolkit. Its main advantage is the best support for non-English +languages. Unlike other viewers, kchmviewer in most cases is able to correctly +detect the chm file encoding and show it. It correctly shows the index and +table of context in Russian, Spanish, Romanian, Korean, Chinese and Arabic help +files, and with new search engine is able to search in any chm file no matter what +language it is written. + +Author: +------- +George Yunaev + +Requires: libqt4 >= 4.5.0 +%files +%defattr(-,root,root) +/usr/bin/kchmviewer +%defattr(-,root,root) +/usr/share/applications/kchmviewer.desktop +%defattr(-,root,root) +/usr/share/pixmaps/kchmviewer.png diff -Nru kchmviewer-4.1/.pc/01_disable_kio-msits_build.diff/CMakeLists.txt kchmviewer-5.1/.pc/01_disable_kio-msits_build.diff/CMakeLists.txt --- kchmviewer-4.1/.pc/01_disable_kio-msits_build.diff/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/.pc/01_disable_kio-msits_build.diff/CMakeLists.txt 2010-02-27 21:12:14.000000000 +0000 @@ -0,0 +1,24 @@ +# Project name +PROJECT( kchmviewer ) + +# Init cmake +#SET( CMAKE_VERBOSE_MAKEFILE ON ) +set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/") + +# Necessary packages +FIND_PACKAGE( KDE4 REQUIRED ) +FIND_PACKAGE( Libchm REQUIRED) + +# Set compilation params +INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/lib/libchmfile ) +ADD_DEFINITIONS( ${KDE4_DEFINITIONS} ) +ADD_DEFINITIONS( -DUSE_KDE ) + +# Run in those subdirectories +ADD_SUBDIRECTORY( lib/libchmfile ) +ADD_SUBDIRECTORY( lib/kio-msits ) +ADD_SUBDIRECTORY( src ) +ADD_SUBDIRECTORY( po ) +ADD_SUBDIRECTORY( packages ) diff -Nru kchmviewer-4.1/.pc/applied-patches kchmviewer-5.1/.pc/applied-patches --- kchmviewer-4.1/.pc/applied-patches 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/.pc/applied-patches 2010-02-27 21:12:14.000000000 +0000 @@ -0,0 +1 @@ +01_disable_kio-msits_build.diff diff -Nru kchmviewer-4.1/.pc/.quilt_patches kchmviewer-5.1/.pc/.quilt_patches --- kchmviewer-4.1/.pc/.quilt_patches 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/.pc/.quilt_patches 2010-02-27 21:12:14.000000000 +0000 @@ -0,0 +1 @@ +debian/patches diff -Nru kchmviewer-4.1/.pc/.quilt_series kchmviewer-5.1/.pc/.quilt_series --- kchmviewer-4.1/.pc/.quilt_series 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/.pc/.quilt_series 2010-02-27 21:12:14.000000000 +0000 @@ -0,0 +1 @@ +series diff -Nru kchmviewer-4.1/.pc/.version kchmviewer-5.1/.pc/.version --- kchmviewer-4.1/.pc/.version 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/.pc/.version 2010-02-27 21:12:14.000000000 +0000 @@ -0,0 +1 @@ +2 diff -Nru kchmviewer-4.1/README kchmviewer-5.1/README --- kchmviewer-4.1/README 2008-12-02 03:02:27.000000000 +0000 +++ kchmviewer-5.1/README 2009-12-14 01:51:00.000000000 +0000 @@ -102,20 +102,5 @@ 7. LICENSE - kchmviewer is distributed under GNU GPL license. - Copyright (C) 2004-2007 Georgy (George) Yunaev - - 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 - + kchmviewer is distributed under GNU GPL license version 3. + e \ No newline at end of file diff -Nru kchmviewer-4.1/src/checknewversion.cpp kchmviewer-5.1/src/checknewversion.cpp --- kchmviewer-4.1/src/checknewversion.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/checknewversion.cpp 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,380 @@ +/************************************************************************** + * Karlyriceditor - a lyrics editor for Karaoke songs * + * Copyright (C) 2009 George Yunaev, support@karlyriceditor.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include +#include + +#if !defined (WIN32) + #include + #include + #include + #include + #include + #include +#else + #include +#endif + +#include "checknewversion.h" + +// Uncomment this to enable debugging messages +//#define ENABLE_DEBUG_MESSAGES + + +CheckNewVersion::CheckNewVersion() + : QThread() +{ + m_sockfd = -1; + m_timeout = 180; + m_inputOffset = 0; + m_inputBuffer.resize( 8192 ); + + qRegisterMetaType< NewVersionMetaMap >("NewVersionMetaMap"); +} + +void CheckNewVersion::setUrl( const QString& url ) +{ + m_url = url; +} + +void CheckNewVersion::setCurrentVersion( const QString& version ) +{ + m_currentversion = version; +} + +void CheckNewVersion::closeSocket() +{ + if ( m_sockfd == -1 ) + return; + +#if defined (WIN32) + closesocket( m_sockfd ); +#else + close( m_sockfd ); +#endif + + m_sockfd = -1; +} + +void CheckNewVersion::fatalError( int code ) +{ +#if defined (ENABLE_DEBUG_MESSAGES) +#define CASE_PRINT(A) case A: qDebug("CheckNewVersion::fatalError( " #A " )"); break; + switch ( code ) + { + CASE_PRINT( Error_URL_Invalid ); + CASE_PRINT( Error_Name_Lookup ); + CASE_PRINT( Error_System ); + CASE_PRINT( Error_Connecting ); + CASE_PRINT( Error_Sending ); + CASE_PRINT( Error_Receiving ); + CASE_PRINT( Error_HTTPerror ); + CASE_PRINT( Error_InvalidFormat ); + CASE_PRINT( Error_InvalidSignature ); + } +#undef CASE_PRINT +#endif + + closeSocket(); + emit error( code ); + deleteLater(); +} + +void CheckNewVersion::reportStatus( int status ) +{ +#if defined (ENABLE_DEBUG_MESSAGES) +#define CASE_PRINT(A) case A: qDebug("CheckNewVersion::reportStatus( " #A " )"); break; + switch ( status ) + { + CASE_PRINT( Status_Resolving ); + CASE_PRINT( Status_Connecting ); + CASE_PRINT( Status_SendingRequest ); + CASE_PRINT( Status_ReceivingResponse ); + CASE_PRINT( Status_Proceeding ); + CASE_PRINT( Status_Finished ); + } +#undef CASE_PRINT +#endif + + emit statusChanged( status ); +} + +void CheckNewVersion::run() +{ + m_inputOffset = 0; + + // Validate the URL + QUrl url( m_url ); + + if ( !url.isValid() || url.scheme() != "http" || url.host().isEmpty() ) + { + fatalError( Error_URL_Invalid ); + return; + } + + // Win32s-specific socket initialization +#if defined (WIN32) + WORD wVersionRequested = MAKEWORD (1, 1); + WSADATA wsaData; + + if ( WSAStartup (wVersionRequested, &wsaData) != 0 ) + { + fatalError( Error_System ); + return; + } +#endif + + // IPv4 address resolving + struct sockaddr_in saddr; + memset( &saddr, 0, sizeof(saddr) ); + saddr.sin_family = AF_INET; + saddr.sin_port = htons( url.port(80) ); + saddr.sin_addr.s_addr = ::inet_addr ( qPrintable(url.host() ) ); + + if ( saddr.sin_addr.s_addr == INADDR_NONE ) + { + reportStatus( Status_Resolving ); + + struct hostent *hp; +#if defined HAVE_GETHOSTBYNAME_R + int tmp_errno; + struct hostent tmp_hostent; + char buf[2048]; + + if ( ::gethostbyname_r( qPrintable(url.host() ), &tmp_hostent, buf, sizeof(buf), &hp, &tmp_errno) ) + hp = 0; +#else + hp = ::gethostbyname( qPrintable(url.host() ) ); +#endif // HAVE_GETHOSTBYNAME_R + + if ( !hp ) + { + fatalError( Error_Name_Lookup ); + return; + } + + ::memcpy (&saddr.sin_addr, hp->h_addr, (size_t) hp->h_length); + } + + // create the socket + m_sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + if ( m_sockfd < 0 ) + { + fatalError( Error_System ); + return; + } + + reportStatus( Status_Connecting ); + + // Connect to the HTTP server + if ( ::connect( m_sockfd, (struct sockaddr *) &saddr, sizeof(saddr)) ) + { + fatalError( Error_Connecting ); + return; + } + + // Prepare the HTTP request + QString request = QString("GET %1 HTTP/1.1\r\n" + "Host: %2\r\n" + "User-Agent: Qt/New version checker (www.karlyriceditor.com)\r\nConnection: close\r\n\r\n") + .arg( url.path() ) .arg( url.host() ); + + // Send the request + reportStatus( Status_SendingRequest ); + + const char * reqmsg = qPrintable( request ); + unsigned int offset = 0, length = strlen( reqmsg ); + + while ( offset < length ) + { + int sentamount = ::send( m_sockfd, reqmsg + offset, length - offset, 0 ); + + if ( sentamount <= 0 ) + { + fatalError( Error_Sending ); + return; + } + + offset += sentamount; + } + + // Receive the response + reportStatus( Status_ReceivingResponse ); + + // First, receive the HTTP header + int contentlen = -1; + QStringList header; + + while ( 1 ) + { + QString line = readLine(); + + // Has connection closed? + if ( m_sockfd == -1 ) + { + fatalError( Error_Receiving ); + return; + } + + // Empty line separates header and body + if ( line.isEmpty() ) + break; + + header.push_back( line ); + } + + // Make sure server didn't return error + if ( header.isEmpty() || header[0].indexOf( QRegExp( "^http/1.\\d\\s+2\\d\\d", Qt::CaseInsensitive )) == -1 ) + { +#if defined (ENABLE_DEBUG_MESSAGES) + if ( !header.isEmpty() ) + qDebug("CheckNewVersion::run: server returned invalid header: %s", qPrintable( header[0]) ); +#endif + fatalError( Error_HTTPerror ); + return; + } + + // Find content-length + QRegExp clr( "^content-length: (\\d+)$" ); + clr.setCaseSensitivity( Qt::CaseInsensitive ); + + if ( header.indexOf( clr ) != -1 ) + contentlen = clr.cap( 1 ).toInt(); + + // Read the rest of content until we have contentlen or connection closed + while ( contentlen == -1 || contentlen < m_inputOffset ) + { + int amount = ::recv( m_sockfd, m_inputBuffer.data() + m_inputOffset, m_inputBuffer.size() - m_inputOffset, 0 ); + + // connection closed? + if ( amount == 0 ) + break; + + // read error + if ( amount < 0 ) + { + fatalError( Error_Receiving ); + return; + } + + m_inputOffset += amount; + } + + closeSocket(); + m_inputBuffer[ m_inputOffset ] ='\0'; + + // Remove/replace line ends, and convert to a string + reportStatus( Status_Proceeding ); + + m_inputBuffer.replace( '\r', '\n' ); + QStringList content_list = QString::fromUtf8( m_inputBuffer ).split( '\n', QString::SkipEmptyParts ); + QMap contentMap; + + // Validate the file, and parse it into map + for ( int i = 0; i < content_list.size(); i++ ) + { + QRegExp reg( "^(\\w+)\\s*:(.*)$" ); + + if ( content_list[i].indexOf( reg ) == -1 ) + { +#if defined (ENABLE_DEBUG_MESSAGES) + qDebug("CheckNewVersion::run: invalid line found: '%s'", qPrintable( content_list[i] ) ); +#endif + fatalError( Error_InvalidFormat ); + return; + } + + // Decode \n back to 0x0A + QString value = reg.cap( 2 ).trimmed(); + value.replace( "\\n", "\n" ); + value.replace( "\\\\", "\\" ); + contentMap[ reg.cap(1) ] = value; + } + + // Validate signature + if ( !contentMap.contains( "Signature" ) + || !contentMap.contains( "Version" ) + || contentMap["Signature"] != "CheckNewVersion1" ) + { + fatalError( Error_InvalidSignature ); + return; + } + + contentMap.remove( "Signature" ); + + // Do we need to call the callback? + if ( m_currentversion.isEmpty() || contentMap["Version"] != m_currentversion ) + emit newVersionAvailable( contentMap ); + + reportStatus( Status_Finished ); + deleteLater(); +} + + +QString CheckNewVersion::readLine() +{ + while ( 1 ) + { + // First check if we have a line in buffer already + if ( m_inputOffset > 0 ) + { + for ( int i = 0; i < m_inputOffset - 1; i++ ) + { + if ( m_inputBuffer[i] == '\r' && m_inputBuffer[i+1] == '\n' ) + { + // Null-terminate the buffer, and copy the string + m_inputBuffer[i] = '\0'; + QString line = QString::fromUtf8( m_inputBuffer ); + + // Now move the rest of the buffer if something left + unsigned int amount = i + 2; // removing CRLF too) + m_inputOffset -= amount; + + if ( m_inputOffset > 0 ) + memmove( m_inputBuffer.data(), m_inputBuffer.data() + amount, m_inputOffset ); + + return line; + } + } + } + + // No line in buffer yet + if ( m_inputOffset + 1 > m_inputBuffer.size() ) + return QString::null; + + int bytes = ::recv( m_sockfd, m_inputBuffer.data() + m_inputOffset, m_inputBuffer.size() - m_inputOffset, 0 ); + + // Error; restart on EINTR, abort on anything else + if ( bytes < 0 ) + { + if ( errno == EINTR ) + continue; + + break; + } + + if ( bytes == 0 ) + break; + + m_inputOffset += bytes; + } + + return QString::null; +} diff -Nru kchmviewer-4.1/src/checknewversion.h kchmviewer-5.1/src/checknewversion.h --- kchmviewer-4.1/src/checknewversion.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/checknewversion.h 2009-12-15 03:16:36.000000000 +0000 @@ -0,0 +1,129 @@ +/************************************************************************** + * Karlyriceditor - a lyrics editor for Karaoke songs * + * Copyright (C) 2009 George Yunaev, support@karlyriceditor.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef CHECKNEWVERSION_H +#define CHECKNEWVERSION_H + +// This class implements checking whether a new application version is available, +// and reports its availability via signal. It does not use Qt networking stuff, +// and therefore avoids linking with QtNetwork (savings of 1Mb!). +// All processing is done in a separate thread, so it does not block the app. +// It does not use GUI stuff, so should be safe. +// +// The proper way to use this class: +// +// CheckNewVersion * pN = new CheckNewVersion(); +// connect( pN, SIGNAL( newVersionAvailable( const QMap&) ), this, SLOT( newVersionAvailable( const QMap&) ) ); +// +// pN->setUrl( "http://www.example.com/latestversion.txt" ); +// pN->setCurrentVersion( "1.12" ); +// pN->start(); +// +// The text file must have the following format: +// : +// Two field names are required (Signature and Version). Any other names are optional. Any name may be added. +// A multiline value string should have all line feed characters replaced by \n, and all single backlashes replaced by two +// Signature must be the first field, and must contain the "CheckNewVersion1" value +// +// An example file with extra fields "URL" and "Changes" added: +// +// Signature:CheckNewVersion1 +// Version:1.12 +// URL: http://example.com/latestversion.zip +// Changes: new functionality added.\nA bar function added to package foo.\n\nZeta now works. +// +// + +#include +#include +#include + +typedef QMap NewVersionMetaMap; + +class CheckNewVersion : public QThread +{ + Q_OBJECT + + public: + enum + { + Status_Resolving, + Status_Connecting, + Status_SendingRequest, + Status_ReceivingResponse, + Status_Proceeding, + Status_Finished, + }; + + enum + { + Error_URL_Invalid, + Error_Name_Lookup, + Error_System, + Error_Connecting, + Error_Sending, + Error_Receiving, + Error_HTTPerror, + Error_InvalidFormat, + Error_InvalidSignature + }; + + CheckNewVersion(); + + // Sets the full URL to get the latest version information from. + void setUrl( const QString& url ); + + // Sets the current version. newVersionAvailable() will only be emitted + // if current version does not match the version in the downloaded file. + // If not called, newVersionAvailable() will be always emitted. + void setCurrentVersion( const QString& version ); + + signals: + void newVersionAvailable( const NewVersionMetaMap& metadata ); + void statusChanged( int newstatus ); + void error( int errorcode ); + + private: + // Reimplemented + void run(); + + // All those functions on error generate the event, and shut down the thread. + void fatalError( int code ); + + // Read the line from socket (or m_inputBuffer). + void reportStatus( int status ); + + // Read the data from socket up to length. May return less than length. + QString readLine(); + + // Closing the socket + void closeSocket(); + + private: + QString m_url; + QString m_currentversion; + + int m_sockfd; + unsigned int m_timeout; + int m_inputOffset; // in m_inputBuffer + QByteArray m_inputBuffer; // for socket input +}; + +Q_DECLARE_METATYPE(NewVersionMetaMap); + +#endif // CHECKNEWVERSION_H diff -Nru kchmviewer-4.1/src/CMakeLists.txt kchmviewer-5.1/src/CMakeLists.txt --- kchmviewer-4.1/src/CMakeLists.txt 2008-12-02 01:43:24.000000000 +0000 +++ kchmviewer-5.1/src/CMakeLists.txt 2009-12-15 06:27:57.000000000 +0000 @@ -2,35 +2,40 @@ # Project files SET( kchmviewerSources - kchmbookmarkwindow.cpp - kchmconfig.cpp - kchmindexwindow.cpp - kchmmainwindow.cpp - kchmsearchwindow.cpp - kchmsettings.cpp - kchmtreeviewitem.cpp - kchmviewwindow.cpp - main.cpp - kchmdialogchooseurlfromlist.cpp - kde-qt.cpp - kchmviewwindow_qtextbrowser.cpp - kchmviewwindowmgr.cpp - kchmkeyeventfilter.cpp - kchmcontentswindow.cpp - kchmsetupdialog.cpp - kchmdbusiface.cpp - kde/kchmviewwindow_khtmlpart.cpp + checknewversion.cpp + config.cpp + dbus_interface.cpp + dialog_chooseurlfromlist.cpp + dialog_setup.cpp + kde-qt.cpp + keyeventfilter.cpp + main.cpp + mainwindow.cpp + navigationpanel.cpp + recentfiles.cpp + settings.cpp + tab_bookmarks.cpp + tab_contents.cpp + tab_index.cpp + tab_search.cpp + treeviewitem.cpp + viewwindow.cpp + viewwindowmgr.cpp + viewwindow_qtextbrowser.cpp + kde/viewwindow_khtmlpart.cpp ) # UI files KDE4_ADD_UI_FILES( kchmviewerSources - tab_bookmarks.ui - tab_index.ui - tab_contents.ui - tab_search.ui + dialog_about.ui dialog_setup.ui - dialog_topicselector.ui - window_main.ui + dialog_topicselector.ui + mainwindow.ui + navigatorpanel.ui + tab_bookmarks.ui + tab_contents.ui + tab_index.ui + tab_search.ui window_browser.ui ) @@ -41,12 +46,10 @@ TARGET_LINK_LIBRARIES( kchmviewer chmfile - ${LIBCHM_LIBRARY} + ${LIBCHM_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KHTML_LIBS} ${KDE4_KFILE_LIBS} ) INSTALL( TARGETS kchmviewer DESTINATION ${KDE4_BIN_INSTALL_DIR} ) -INSTALL( FILES kde/kchmviewer.desktop DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR} ) -ADD_SUBDIRECTORY( kde ) diff -Nru kchmviewer-4.1/src/config.cpp kchmviewer-5.1/src/config.cpp --- kchmviewer-4.1/src/config.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/config.cpp 2009-12-16 09:59:07.000000000 +0000 @@ -0,0 +1,89 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include + +#include "kde-qt.h" +#include "config.h" +#include "settings.h" +#include "mainwindow.h" + +Config * pConfig; + +const char * APP_PATHINUSERDIR = ".kchmviewer"; + +Config::Config() +{ + QDir dir; + m_datapath = QDir::homePath () + "/" + APP_PATHINUSERDIR; + + dir.setPath (m_datapath); + + if ( !dir.exists() && !dir.mkdir(m_datapath) ) + qWarning( "Could not create directory %s", qPrintable( m_datapath )); + + QSettings settings; + m_startupMode = (Config::StartupMode) settings.value( "general/onstartup", STARTUP_DO_NOTHING ).toInt(); + m_onNewChmClick = (Config::choose_action_t) settings.value( "general/onnewchm", ACTION_ASK_USER ).toInt(); + m_onExternalLinkClick = (Config::choose_action_t) settings.value( "general/onexternal", ACTION_ASK_USER ).toInt(); + m_numOfRecentFiles = settings.value( "general/maxrecentfiles", 10 ).toInt(); + m_HistoryStoreExtra = settings.value( "general/extrahistory", true ).toBool(); + m_usedBrowser = settings.value( "general/usebrowser", BROWSER_QTEXTBROWSER ).toInt(); + m_kdeEnableJS = settings.value( "browser/enablejs", false ).toBool(); + m_kdeEnableJava = settings.value( "browser/enablejava", false ).toBool(); + m_kdeEnablePlugins = settings.value( "browser/enableplugins", true ).toBool(); + m_kdeEnableRefresh = settings.value( "browser/enablerefresh", false ).toBool(); + m_advUseInternalEditor = settings.value( "advanced/internaleditor", true ).toBool(); + m_advLayoutDirectionRL = settings.value( "advanced/layoutltr", false ).toBool(); + m_advAutodetectEncoding = settings.value( "advanced/autodetectenc", false ).toBool(); + m_advExternalEditorPath = settings.value( "advanced/editorpath", "/usr/bin/kate" ).toString(); + m_advCheckNewVersion = settings.value( "advanced/checknewver", true ).toBool(); + m_toolbarMode = (Config::ToolbarMode) settings.value( "advanced/toolbarmode", TOOLBAR_LARGEICONSTEXT ).toInt(); + m_lastOpenedDir = settings.value( "advanced/lastopendir", "." ).toString(); + + // Reset webkit browser to qtextbrowser when older version is running +#if !defined (QT_WEBKIT_LIB) + if ( m_usedBrowser == BROWSER_QTWEBKIT ) + m_usedBrowser = BROWSER_QTEXTBROWSER; +#endif +} + + +void Config::save( ) +{ + QSettings settings; + + settings.setValue( "general/onstartup", m_startupMode ); + settings.setValue( "general/onnewchm", m_onNewChmClick ); + settings.setValue( "general/onexternal", m_onExternalLinkClick ); + settings.setValue( "general/maxrecentfiles", m_numOfRecentFiles ); + settings.setValue( "general/extrahistory", m_HistoryStoreExtra ); + settings.setValue( "general/usebrowser", m_usedBrowser ); + settings.setValue( "browser/enablejs", m_kdeEnableJS ); + settings.setValue( "browser/enablejava", m_kdeEnableJava ); + settings.setValue( "browser/enableplugins", m_kdeEnablePlugins ); + settings.setValue( "browser/enablerefresh", m_kdeEnableRefresh ); + settings.setValue( "advanced/internaleditor", m_advUseInternalEditor ); + settings.setValue( "advanced/layoutltr", m_advLayoutDirectionRL ); + settings.setValue( "advanced/autodetectenc", m_advAutodetectEncoding ); + settings.setValue( "advanced/editorpath", m_advExternalEditorPath ); + settings.setValue( "advanced/checknewver", m_advCheckNewVersion ); + settings.setValue( "advanced/toolbarmode", m_toolbarMode ); + settings.setValue( "advanced/lastopendir", m_lastOpenedDir ); +} diff -Nru kchmviewer-4.1/src/config.h kchmviewer-5.1/src/config.h --- kchmviewer-4.1/src/config.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/config.h 2009-12-16 09:57:24.000000000 +0000 @@ -0,0 +1,90 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include + +#include "recentfiles.h" + +extern const char * APP_PATHINUSERDIR; + +class Config +{ + public: + enum choose_action_t + { + ACTION_ALWAYS_OPEN, + ACTION_ASK_USER, + ACTION_DONT_OPEN + }; + + enum UsedBrowser + { + BROWSER_QTEXTBROWSER = 0, + BROWSER_KHTMLPART, + BROWSER_QTWEBKIT + }; + + enum ToolbarMode + { + TOOLBAR_SMALLICONS, + TOOLBAR_LARGEICONS, + TOOLBAR_LARGEICONSTEXT, + TOOLBAR_TEXTONLY + }; + + enum StartupMode + { + STARTUP_DO_NOTHING, + STARTUP_LOAD_LAST_FILE, + STARTUP_POPUP_OPENFILE + }; + + Config(); + void save(); + + public: + QString m_datapath; + QString m_lastOpenedDir; + + StartupMode m_startupMode; + choose_action_t m_onNewChmClick; + choose_action_t m_onExternalLinkClick; + int m_numOfRecentFiles; + bool m_HistoryStoreExtra; + int m_usedBrowser; + ToolbarMode m_toolbarMode; + + bool m_kdeEnableJS; + bool m_kdeEnableJava; + bool m_kdeEnablePlugins; + bool m_kdeEnableRefresh; + + bool m_advUseInternalEditor; + QString m_advExternalEditorPath; + bool m_advLayoutDirectionRL; + bool m_advAutodetectEncoding; + bool m_advCheckNewVersion; +}; + +extern Config * pConfig; + +#endif diff -Nru kchmviewer-4.1/src/dbus_interface.cpp kchmviewer-5.1/src/dbus_interface.cpp --- kchmviewer-4.1/src/dbus_interface.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dbus_interface.cpp 2009-12-14 07:02:52.000000000 +0000 @@ -0,0 +1,81 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include + +#include "dbus_interface.h" +#include "mainwindow.h" +#include "navigationpanel.h" +#include "tab_search.h" + + +DBusInterface::DBusInterface( QObject *parent ) + : QObject( parent ) +{ + QDBusConnection::sessionBus().registerObject( "/application", + this, + QDBusConnection::ExportScriptableSlots ); +} + + +DBusInterface::~DBusInterface() +{ +} + + +void DBusInterface::loadHelpFile( const QString & filename, const QString & page2open ) +{ + QStringList args; + + args.push_back( filename ); + args.push_back( page2open ); + + qApp->postEvent( ::mainWindow, new UserEvent( "loadAndOpen", args ) ); +} + + +void DBusInterface::openPage( const QString & page2open ) +{ + QStringList args; + + args.push_back( page2open ); + qApp->postEvent( ::mainWindow, new UserEvent( "openPage", args ) ); +} + + +void DBusInterface::guiFindInIndex( const QString & word ) +{ + QStringList args; + + args.push_back( word ); + qApp->postEvent( ::mainWindow, new UserEvent( "findInIndex", args ) ); +} + + +void DBusInterface::guiSearchQuery( const QString & query ) +{ + QStringList args; + + args.push_back( query ); + qApp->postEvent( ::mainWindow, new UserEvent( "searchQuery", args ) ); +} + +QStringList DBusInterface::searchQuery( const QString & query ) +{ + return ::mainWindow->navigator()->searchQuery( query ); +} diff -Nru kchmviewer-4.1/src/dbus_interface.h kchmviewer-5.1/src/dbus_interface.h --- kchmviewer-4.1/src/dbus_interface.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dbus_interface.h 2009-12-14 07:02:52.000000000 +0000 @@ -0,0 +1,57 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef DBUS_INTERFACE_H +#define DBUS_INTERFACE_H + +#include +#include +#include + + +#define SERVICE_NAME "net.kchmviewer.application" + +class DBusInterface : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.kchmviewer.application") + + public: + DBusInterface( QObject *parent = 0 ); + ~DBusInterface(); + + public Q_SLOTS: + //! Loads a CHM file \a filename , and opens the URL \a url. Use URL "/" to open default homepage + Q_SCRIPTABLE void loadHelpFile( const QString& filename, const QString& url ); + + //! Opens a specific \a url inside the loaded CHM file + Q_SCRIPTABLE void openPage( const QString& url ); + + //! Tries to find word in index, opening the index window and scrolling it there + Q_SCRIPTABLE void guiFindInIndex( const QString& word ); + + //! Executes a search in GUI. \a query contains the complete search query. + Q_SCRIPTABLE void guiSearchQuery( const QString& query ); + + //! Executes a search; GUI is not involved and user sees nothing. + //! \a query contains the complete search query. + //! Returns a list of URLs, or empty array if nothing os + Q_SCRIPTABLE QStringList searchQuery( const QString& query ); +}; + +#endif // DBUSIFACE_H diff -Nru kchmviewer-4.1/src/dialog_about.ui kchmviewer-5.1/src/dialog_about.ui --- kchmviewer-4.1/src/dialog_about.ui 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dialog_about.ui 2009-12-15 04:06:16.000000000 +0000 @@ -0,0 +1,151 @@ + + + DialogAbout + + + + 0 + 0 + 455 + 256 + + + + About kchmviewer + + + + + + 0 + + + + About appplication + + + + + + + + + :/images/kchmviewer.png + + + + + + + + 1 + 1 + + + + About text + + + true + + + + + + + + Thanks + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Liberation Sans'; font-size:12pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; font-style:italic;">I would like to thank:</span></p> +<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- <a href="http://qt.nokia.com"><span style=" text-decoration: underline; color:#0000ff;">Trolltech</span></a> (now Nokia) for Qt library;</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- <a href="http://dryicons.com"><span style=" text-decoration: underline; color:#0000ff;">Dryicons</span></a> for nice free icons;</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- Jed Wing, the author of chmlib.</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- Razvan Cojocaru, the author of xchm.</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- Peter Volkov for significant QA (more than 20 reported bugs!)</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- And of course <span style=" font-weight:600;">everyone</span>, who report bugs, and suggest features.</p> +<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> + + + true + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + + buttonBox + accepted() + DialogAbout + accept() + + + 222 + 363 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogAbout + reject() + + + 290 + 369 + + + 286 + 274 + + + + + buttonBox + clicked(QAbstractButton*) + DialogAbout + accept() + + + 371 + 367 + + + 410 + 391 + + + + + diff -Nru kchmviewer-4.1/src/dialog_chooseurlfromlist.cpp kchmviewer-5.1/src/dialog_chooseurlfromlist.cpp --- kchmviewer-4.1/src/dialog_chooseurlfromlist.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dialog_chooseurlfromlist.cpp 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,53 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "kde-qt.h" + +#include "dialog_chooseurlfromlist.h" +#include "treeviewitem.h" + + +DialogChooseUrlFromList::DialogChooseUrlFromList( QWidget* parent ) + : QDialog( parent ), Ui::DialogTopicSelector() +{ + setupUi( this ); + + // List doubleclick + connect( list, + SIGNAL( itemDoubleClicked ( QListWidgetItem * ) ), + this, + SLOT( onDoubleClicked( QListWidgetItem * ) ) ); +} + +void DialogChooseUrlFromList::onDoubleClicked( QListWidgetItem * item ) +{ + if ( item ) + accept(); +} + + +QString DialogChooseUrlFromList::getSelectedItemUrl( const QStringList & urls, const QStringList & titles ) +{ + for ( int i = 0; i < urls.size(); i++ ) + list->addItem( titles[i] ); + + if ( exec() == QDialog::Accepted && list->currentRow() != -1 ) + return urls[ list->currentRow() ]; + + return QString::null; +} diff -Nru kchmviewer-4.1/src/dialog_chooseurlfromlist.h kchmviewer-5.1/src/dialog_chooseurlfromlist.h --- kchmviewer-4.1/src/dialog_chooseurlfromlist.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dialog_chooseurlfromlist.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,42 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef DIALOG_CHOOSEURLFROMLIST_H +#define DIALOG_CHOOSEURLFROMLIST_H + +#include +#include "ui_dialog_topicselector.h" + + +class DialogChooseUrlFromList : public QDialog, public Ui::DialogTopicSelector +{ + Q_OBJECT + + public: + DialogChooseUrlFromList( QWidget* parent ); + + // Shows the dialog with titles, and let the user to select the title. + // Obviously urls.size() == titles.size(). Returns the appropriate URL + // for the selected title, or empty string if no title selected, or dialog canceled. + QString getSelectedItemUrl( const QStringList& urls, const QStringList& titles ); + + private slots: + void onDoubleClicked( QListWidgetItem * item ); +}; + +#endif diff -Nru kchmviewer-4.1/src/dialog_setup.cpp kchmviewer-5.1/src/dialog_setup.cpp --- kchmviewer-4.1/src/dialog_setup.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dialog_setup.cpp 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,258 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "kde-qt.h" +#include "config.h" +#include "dialog_setup.h" +#include "mainwindow.h" +#include "version.h" + + +DialogSetup::DialogSetup(QWidget *parent) + : QDialog(parent), Ui::DialogSetup() +{ + setupUi( this ); + + connect( btnBrowse, SIGNAL( clicked() ), this, SLOT( browseExternalEditor() ) ); + + // Set up the parameters + switch ( pConfig->m_startupMode ) + { + case Config::STARTUP_DO_NOTHING: + rbStartWithNothing->setChecked( true ); + break; + + case Config::STARTUP_LOAD_LAST_FILE: + m_radioOnBeginOpenLast->setChecked( true ); + break; + + case Config::STARTUP_POPUP_OPENFILE: + m_radioOnBeginOpenDialog->setChecked( true ); + break; + } + + m_historySize->setValue ( pConfig->m_numOfRecentFiles ); + m_rememberHistoryInfo->setChecked ( pConfig->m_HistoryStoreExtra ); + + m_radioExtLinkOpenAlways->setChecked ( pConfig->m_onExternalLinkClick == Config::ACTION_ALWAYS_OPEN ); + m_radioExtLinkAsk->setChecked ( pConfig->m_onExternalLinkClick == Config::ACTION_ASK_USER ); + m_radioExtLinkOpenNever->setChecked ( pConfig->m_onExternalLinkClick == Config::ACTION_DONT_OPEN ); + + m_radioNewChmOpenAlways->setChecked ( pConfig->m_onNewChmClick == Config::ACTION_ALWAYS_OPEN ); + m_radioNewChmAsk->setChecked ( pConfig->m_onNewChmClick == Config::ACTION_ASK_USER ); + m_radioNewChmOpenNever->setChecked ( pConfig->m_onNewChmClick == Config::ACTION_DONT_OPEN ); + +#if !defined (USE_KDE) + m_radioUseKHTMLPart->setEnabled ( false ); +#endif + +#if !defined (QT_WEBKIT_LIB) + m_radioUseQtWebkit->setEnabled ( false ); +#endif + + switch ( pConfig->m_usedBrowser ) + { + default: + m_radioUseQtextBrowser->setChecked ( true ); + break; + +#if defined (USE_KDE) + case Config::BROWSER_KHTMLPART: + m_radioUseKHTMLPart->setChecked( true ); + break; +#endif + +#if defined (QT_WEBKIT_LIB) + case Config::BROWSER_QTWEBKIT: + m_radioUseQtWebkit->setChecked( true ); + break; +#endif + } + + m_enableJS->setChecked ( pConfig->m_kdeEnableJS ); + m_enablePlugins->setChecked ( pConfig->m_kdeEnablePlugins ); + m_enableJava->setChecked ( pConfig->m_kdeEnableJava ); + m_enableRefresh->setChecked ( pConfig->m_kdeEnableRefresh ); + + m_advExternalProgramName->setText( pConfig->m_advExternalEditorPath ); + m_advViewSourceExternal->setChecked ( !pConfig->m_advUseInternalEditor ); + m_advViewSourceInternal->setChecked ( pConfig->m_advUseInternalEditor ); + + m_numOfRecentFiles = pConfig->m_numOfRecentFiles; + + boxAutodetectEncoding->setChecked( pConfig->m_advAutodetectEncoding ); + boxLayoutDirectionRL->setChecked( pConfig->m_advLayoutDirectionRL ); + + switch ( pConfig->m_toolbarMode ) + { + case Config::TOOLBAR_SMALLICONS: + rbToolbarSmall->setChecked( true ); + break; + + case Config::TOOLBAR_LARGEICONS: + rbToolbarLarge->setChecked( true ); + break; + + case Config::TOOLBAR_LARGEICONSTEXT: + rbToolbarLargeText->setChecked( true ); + break; + + case Config::TOOLBAR_TEXTONLY: + rbToolbarText->setChecked( true ); + break; + } + + cbCheckForUpdates->setChecked( pConfig->m_advCheckNewVersion ); +} + +DialogSetup::~DialogSetup() +{ +} + + +void DialogSetup::accept() +{ + if ( rbStartWithNothing->isChecked() ) + pConfig->m_startupMode = Config::STARTUP_DO_NOTHING; + else if ( m_radioOnBeginOpenLast->isChecked() ) + pConfig->m_startupMode = Config::STARTUP_LOAD_LAST_FILE; + else + pConfig->m_startupMode = Config::STARTUP_POPUP_OPENFILE; + + pConfig->m_numOfRecentFiles = m_historySize->value(); + pConfig->m_HistoryStoreExtra = m_rememberHistoryInfo->isChecked(); + + if ( m_radioExtLinkOpenAlways->isChecked () ) + pConfig->m_onExternalLinkClick = Config::ACTION_ALWAYS_OPEN; + else if ( m_radioExtLinkAsk->isChecked () ) + pConfig->m_onExternalLinkClick = Config::ACTION_ASK_USER; + else + pConfig->m_onExternalLinkClick = Config::ACTION_DONT_OPEN; + + if ( m_radioNewChmOpenAlways->isChecked () ) + pConfig->m_onNewChmClick = Config::ACTION_ALWAYS_OPEN; + else if ( m_radioNewChmAsk->isChecked () ) + pConfig->m_onNewChmClick = Config::ACTION_ASK_USER; + else + pConfig->m_onNewChmClick = Config::ACTION_DONT_OPEN; + + // Check the changes + bool need_restart = false; + + if ( pConfig->m_kdeEnableJS != m_enableJS->isChecked() ) + { + need_restart = true; + pConfig->m_kdeEnableJS = m_enableJS->isChecked(); + } + + if ( pConfig->m_kdeEnablePlugins != m_enablePlugins->isChecked() ) + { + need_restart = true; + pConfig->m_kdeEnablePlugins = m_enablePlugins->isChecked(); + } + + if ( pConfig->m_kdeEnableJava != m_enableJava->isChecked() ) + { + need_restart = true; + pConfig->m_kdeEnableJava = m_enableJava->isChecked(); + } + + if ( pConfig->m_kdeEnableRefresh != m_enableRefresh->isChecked() ) + { + need_restart = true; + pConfig->m_kdeEnableRefresh = m_enableRefresh->isChecked(); + } + + int new_browser = Config::BROWSER_QTEXTBROWSER; + + if ( m_radioUseKHTMLPart->isChecked() ) + new_browser = Config::BROWSER_KHTMLPART; + else if ( m_radioUseQtWebkit->isChecked() ) + new_browser = Config::BROWSER_QTWEBKIT; + + if ( new_browser != pConfig->m_usedBrowser ) + { + need_restart = true; + pConfig->m_usedBrowser = new_browser; + } + + Config::ToolbarMode newmode; + + if ( rbToolbarSmall->isChecked() ) + newmode = Config::TOOLBAR_SMALLICONS; + else if ( rbToolbarLarge->isChecked() ) + newmode = Config::TOOLBAR_LARGEICONS; + else if ( rbToolbarLargeText->isChecked() ) + newmode = Config::TOOLBAR_LARGEICONSTEXT; + else + newmode = Config::TOOLBAR_TEXTONLY; + + if ( newmode != pConfig->m_toolbarMode ) + { + pConfig->m_toolbarMode = newmode; + ::mainWindow->updateToolbars(); + } + + pConfig->m_advExternalEditorPath = m_advExternalProgramName->text(); + pConfig->m_advUseInternalEditor = m_advViewSourceExternal->isChecked(); + pConfig->m_advUseInternalEditor = m_advViewSourceInternal->isChecked(); + + if ( pConfig->m_numOfRecentFiles != m_numOfRecentFiles ) + need_restart = true; + + // Autodetect encoding + if ( pConfig->m_advAutodetectEncoding != boxAutodetectEncoding->isChecked() ) + need_restart = true; + + pConfig->m_advAutodetectEncoding = boxAutodetectEncoding->isChecked(); + pConfig->m_advCheckNewVersion = cbCheckForUpdates->isChecked(); + + // Layout direction management + bool layout_rl = boxLayoutDirectionRL->isChecked(); + + if ( layout_rl != pConfig->m_advLayoutDirectionRL ) + { + pConfig->m_advLayoutDirectionRL = layout_rl; + need_restart = true; + } + + pConfig->save(); + + if ( need_restart ) + QMessageBox::information( this, + QCoreApplication::applicationName(), + i18n( "Changing those options requires restarting the application to take effect." ) ); + + QDialog::accept(); +} + + +void DialogSetup::browseExternalEditor() +{ +#if defined (USE_KDE) + QString exec = KFileDialog::getOpenFileName( KUrl(), i18n("*|Executables"), this, i18n("Choose an editor executable")); +#else + QString exec = QFileDialog::getOpenFileName(this, + i18n("Choose an editor executable"), + QString::null, + i18n( "Executables (*)") ); +#endif + + if ( !exec.isEmpty() ) + m_advExternalProgramName->setText( exec ); +} diff -Nru kchmviewer-4.1/src/dialog_setup.h kchmviewer-5.1/src/dialog_setup.h --- kchmviewer-4.1/src/dialog_setup.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/dialog_setup.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,42 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef DIALOG_SETUP_H +#define DIALOG_SETUP_H + +#include +#include + + +class DialogSetup : public QDialog, public Ui::DialogSetup +{ + Q_OBJECT + + public: + DialogSetup( QWidget *parent = 0 ); + ~DialogSetup(); + + public slots: + void browseExternalEditor(); + void accept(); + + private: + int m_numOfRecentFiles; +}; + +#endif diff -Nru kchmviewer-4.1/src/dialog_setup.ui kchmviewer-5.1/src/dialog_setup.ui --- kchmviewer-4.1/src/dialog_setup.ui 2009-07-20 01:53:28.000000000 +0100 +++ kchmviewer-5.1/src/dialog_setup.ui 2009-12-15 03:16:36.000000000 +0000 @@ -6,8 +6,8 @@ 0 0 - 624 - 443 + 675 + 476 @@ -59,7 +59,7 @@ - If no arguments given on load + If started with no arguments @@ -69,9 +69,16 @@ 9 + + + Start with nothing loaded + + + + - Open the 'open CHM file' dialog + Pop up the "open file" dialog @@ -494,6 +501,66 @@ + + + + If this option is enabled, the application will check for updates (when new version of application is released). If a new version is available, the program will show a messagebox dialog informing you about new version. This check will only performed once in 24 hours. No user information is requested or transmitted from your computer during this check. + + + Perform a check whether a new version is available (once a week) + + + + + + + + + + Toolbars + + + + + + Small icons + + + + + + + Large icons + + + + + + + Large icons and text + + + + + + + Just text + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff -Nru kchmviewer-4.1/src/kchmbookmarkwindow.cpp kchmviewer-5.1/src/kchmbookmarkwindow.cpp --- kchmviewer-4.1/src/kchmbookmarkwindow.cpp 2009-07-20 04:38:15.000000000 +0100 +++ kchmviewer-5.1/src/kchmbookmarkwindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,242 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "kchmbookmarkwindow.h" -#include "kchmmainwindow.h" -#include "kchmviewwindow.h" -#include "kchmtreeviewitem.h" -#include "version.h" - -class KCHMBookmarkItem : public QListWidgetItem -{ - public: - KCHMBookmarkItem( KCHMBookmarkWindow * widget, QListWidget* parent, const QString& name, const QString& url, int pos ) - : QListWidgetItem( parent ) - { - m_name = name; - m_url = url; - m_scroll_y = pos; - m_action = new QAction( name, widget ); - m_action->setData( qVariantFromValue( (void*) this ) ); - - QObject::connect( m_action, - SIGNAL( triggered() ), - widget, - SLOT( actionBookmarkActivated() ) ); - } - - // Visualization - virtual QVariant data ( int role ) const - { - switch ( role ) - { - case Qt::ToolTipRole: - case Qt::WhatsThisRole: - case Qt::DisplayRole: - return m_name; - } - - return QVariant(); - } - - QString m_name; - QString m_url; - int m_scroll_y; - QAction * m_action; -}; - - - -KCHMBookmarkWindow::KCHMBookmarkWindow( QWidget *parent ) - : QWidget( parent ), Ui::TabBookmarks() -{ - // UIC code - setupUi( this ); - - connect( list, - SIGNAL( itemDoubleClicked ( QListWidgetItem* ) ), - this, - SLOT( onItemDoubleClicked ( QListWidgetItem* ) ) ); - - connect( btnAdd, - SIGNAL( clicked () ), - this, - SLOT( onAddBookmarkPressed( ) ) ); - - connect( btnDel, - SIGNAL( clicked () ), - this, - SLOT( onDelBookmarkPressed( ) ) ); - - connect( btnEdit, - SIGNAL( clicked () ), - this, - SLOT( onEditBookmarkPressed( ) ) ); - - m_menuBookmarks = 0; - m_contextMenu = 0; - m_listChanged = false; - - // Activate custom context menu, and connect it - list->setContextMenuPolicy( Qt::CustomContextMenu ); - connect( list, - SIGNAL( customContextMenuRequested ( const QPoint & ) ), - this, - SLOT( onContextMenuRequested( const QPoint & ) ) ); -} - -void KCHMBookmarkWindow::onAddBookmarkPressed( ) -{ - bool ok; - QString url = ::mainWindow->currentBrowser()->getOpenedPage(); - QString title = ::mainWindow->chmFile()->getTopicByUrl(url); - QString name = QInputDialog::getText( - this, - i18n( "%1 - add a bookmark") . arg(APP_NAME), - i18n( "Enter the name for this bookmark:" ), - QLineEdit::Normal, - title, - &ok ); - - if ( !ok || name.isEmpty() ) - return; - - KCHMBookmarkItem * item = new KCHMBookmarkItem ( this, - list, - name, - url, - ::mainWindow->currentBrowser()->getScrollbarPosition() ); - - m_menuBookmarks->addAction( item->m_action ); - m_listChanged = true; -} - - -void KCHMBookmarkWindow::onDelBookmarkPressed( ) -{ - KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->currentItem(); - - if ( item ) - { - m_menuBookmarks->removeAction( item->m_action ); - delete item; - m_listChanged = true; - } -} - - -void KCHMBookmarkWindow::onEditBookmarkPressed( ) -{ - KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->currentItem(); - - if ( item ) - { - bool ok; - QString name = QInputDialog::getText( - this, - i18n( "%1 - edit the bookmark name") . arg(APP_NAME), - i18n( "Enter the name for this bookmark:" ), - QLineEdit::Normal, - item->m_name, - &ok ); - - if ( !ok || name.isEmpty() ) - return; - - item->setText( name ); - item->m_action->setText( name ); - m_listChanged = true; - } -} - - -void KCHMBookmarkWindow::restoreSettings( const KCHMSettings::bookmark_saved_settings_t & settings ) -{ - for ( int i = 0; i < settings.size(); i++ ) - { - KCHMBookmarkItem * item = new KCHMBookmarkItem( this, list, settings[i].name, settings[i].url, settings[i].scroll_y ); - m_menuBookmarks->addAction( item->m_action ); - } -} - - -void KCHMBookmarkWindow::saveSettings( KCHMSettings::bookmark_saved_settings_t & settings ) -{ - settings.clear(); - - for ( int i = 0; i < list->count(); i++ ) - { - KCHMBookmarkItem * treeitem = (KCHMBookmarkItem *) list->item( i ); - settings.push_back (KCHMSettings::SavedBookmark( treeitem->m_name, treeitem->m_url, treeitem->m_scroll_y) ); - } -} - -void KCHMBookmarkWindow::invalidate( ) -{ - for ( int i = 0; i < list->count(); i++ ) - m_menuBookmarks->removeAction( ((KCHMBookmarkItem *) list->item( i ))->m_action ); - - list->clear(); -} - -void KCHMBookmarkWindow::createMenu( QMenu * menuBookmarks ) -{ - m_menuBookmarks = menuBookmarks; -} - -void KCHMBookmarkWindow::onItemDoubleClicked(QListWidgetItem * item) -{ - if ( !item ) - return; - - KCHMBookmarkItem * treeitem = (KCHMBookmarkItem *) item; - - if ( ::mainWindow->currentBrowser()->getOpenedPage() != treeitem->m_url ) - ::mainWindow->openPage( treeitem->m_url, KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY ); - - ::mainWindow->currentBrowser()->setScrollbarPosition( treeitem->m_scroll_y ); -} - -void KCHMBookmarkWindow::actionBookmarkActivated() -{ - QAction *action = qobject_cast< QAction * >(sender()); - - KCHMBookmarkItem * item = (KCHMBookmarkItem *) action->data().value< void* > (); - - if ( !item ) - return; - - if ( ::mainWindow->currentBrowser()->getOpenedPage() != item->m_url ) - ::mainWindow->openPage( item->m_url, KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY ); - - ::mainWindow->currentBrowser()->setScrollbarPosition( item->m_scroll_y ); -} - -void KCHMBookmarkWindow::onContextMenuRequested(const QPoint & point) -{ - KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->itemAt( point ); - - if( item ) - { - ::mainWindow->currentBrowser()->setTabKeeper( item->m_url ); - ::mainWindow->tabItemsContextMenu()->popup( list->viewport()->mapToGlobal( point ) ); - } -} diff -Nru kchmviewer-4.1/src/kchmbookmarkwindow.h kchmviewer-5.1/src/kchmbookmarkwindow.h --- kchmviewer-4.1/src/kchmbookmarkwindow.h 2009-07-20 04:38:13.000000000 +0100 +++ kchmviewer-5.1/src/kchmbookmarkwindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMBOOKMARKWINDOW_H -#define KCHMBOOKMARKWINDOW_H - -#include "kde-qt.h" -#include "kchmsettings.h" - -#include "ui_tab_bookmarks.h" - - -class KCHMBookmarkWindow : public QWidget, public Ui::TabBookmarks -{ - Q_OBJECT - public: - KCHMBookmarkWindow( QWidget *parent ); - virtual ~KCHMBookmarkWindow() {}; - - void createMenu( QMenu * menuBookmarks ); - - void restoreSettings (const KCHMSettings::bookmark_saved_settings_t& settings); - void saveSettings (KCHMSettings::bookmark_saved_settings_t& settings); - void invalidate(); - - public slots: - void onAddBookmarkPressed (); - - private slots: - void actionBookmarkActivated(); - void onDelBookmarkPressed( ); - void onEditBookmarkPressed( ); - void onItemDoubleClicked ( QListWidgetItem* ); - void onContextMenuRequested ( const QPoint &point ); - - private: - QMenu * m_menuBookmarks; - QMenu * m_contextMenu; - QString m_bookmarkFileName; - bool m_listChanged; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmconfig.cpp kchmviewer-5.1/src/kchmconfig.cpp --- kchmviewer-4.1/src/kchmconfig.cpp 2009-07-20 04:38:11.000000000 +0100 +++ kchmviewer-5.1/src/kchmconfig.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,219 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include - -#include "kde-qt.h" -#include "kchmconfig.h" -#include "kchmsettings.h" -#include "kchmmainwindow.h" - - -KCHMConfig appConfig; - -const char * APP_PATHINUSERDIR = ".kchmviewer"; - - -KCHMConfig::KCHMConfig() -{ - QDir dir; - m_datapath = QDir::homePath () + "/" + APP_PATHINUSERDIR; - - dir.setPath (m_datapath); - - if ( !dir.exists() && !dir.mkdir(m_datapath) ) - qWarning( "Could not create directory %s", qPrintable( m_datapath )); - - m_LoadLatestFileOnStartup = false; - m_onNewChmClick = ACTION_ASK_USER; - m_onExternalLinkClick = ACTION_ASK_USER; - m_numOfRecentFiles = 10; - m_HistoryStoreExtra = true; - - // Webkit only present in 4.4+ -#if defined (QT_WEBKIT_LIB) - m_usedBrowser = BROWSER_QTWEBKIT; -#else - m_usedBrowser = BROWSER_QTEXTBROWSER; -#endif - - m_kdeEnableJS = false; - m_kdeEnableJava = false; - m_kdeEnablePlugins = true; - m_kdeEnableRefresh = false; - - m_advUseInternalEditor = true; - m_advLayoutDirectionRL = false; - m_advAutodetectEncoding = false; - m_advExternalEditorPath = "/usr/bin/kate"; - - m_lastOpenedDir = ""; -} - - -KCHMConfig::~KCHMConfig() -{ -} - -bool KCHMConfig::load() -{ - QFile file (m_datapath + "/config"); - if ( !file.open (QIODevice::ReadOnly) ) - return false; // no error message - not actually a problem - - QString line; - char readbuf[4096]; - bool getting_history = false; - m_recentFiles.clear(); - - while ( file.readLine( readbuf, sizeof(readbuf) - 1 ) > 0 ) - { - line = QString::fromUtf8( readbuf ).trimmed(); - - // skip empty lines and comments - if ( line.isEmpty() || line[0] == '#' ) - continue; - - QRegExp rxsection ("^\\[(\\w+)\\]$"), rxkeypair ("^(\\w+)\\s*=\\s*(.*)$"); - - if ( rxsection.indexIn( line ) != -1 ) - { - if ( rxsection.cap (1) == "settings" ) - getting_history = false; - else if ( rxsection.cap (1) == "history" ) - getting_history = true; - else - qWarning ("Unknown configuration section: %s", qPrintable( rxsection.cap(1) )); - - continue; - } - else if ( !getting_history && rxkeypair.indexIn( line ) != -1 ) - { - QString key (rxkeypair.cap (1)), value (rxkeypair.cap(2)); - - if ( key == "LoadLatestFileOnStartup" ) - m_LoadLatestFileOnStartup = value.toInt() ? true : false; - else if ( key == "onNewChmClick" ) - m_onNewChmClick = (choose_action_t) value.toInt(); - else if ( key == "onExternalLinkClick" ) - m_onExternalLinkClick = (choose_action_t) value.toInt(); - else if ( key == "HistorySize" ) - m_numOfRecentFiles = value.toInt(); - else if ( key == "HistoryStoreExtra" ) - m_HistoryStoreExtra = value.toInt() ? true : false; - else if ( key == "UsedBrowser" ) - m_usedBrowser = value.toInt(); - else if ( key == "kdeEnableJS" ) - m_kdeEnableJS = value.toInt() ? true : false; - else if ( key == "kdeEnableJava" ) - m_kdeEnableJava = value.toInt() ? true : false; - else if ( key == "kdeEnablePlugins" ) - m_kdeEnablePlugins = value.toInt() ? true : false; - else if ( key == "kdeEnableRefresh" ) - m_kdeEnableRefresh = value.toInt() ? true : false; - else if ( key == "LastOpenedDir" ) - m_lastOpenedDir = value; - else if ( key == "advUseInternalEditor" ) - m_advUseInternalEditor = value.toInt() ? true : false; - else if ( key == "advExternalEditorPath" ) - m_advExternalEditorPath = value; - else if ( key == "advLayoutDirectionRL" ) - m_advLayoutDirectionRL = value.toInt() ? true : false; - else if ( key == "advAutoDetectEncoding" ) - m_advAutodetectEncoding = value.toInt() ? true : false; - else if ( key == "useSearchEngine" || key == "QtBrowserPath" ) - // Do nothing; not used anymore - ; - else - qWarning ("Unknown key=value pair: %s", qPrintable( line )); - } - else if ( getting_history ) - { - if ( m_recentFiles.size() < m_numOfRecentFiles ) - addRecentFile( line ); - } - else - qWarning ("Unknown line in configuration: %s", qPrintable( line )); - } - - // Reset webkit browser to qtextbrowser when older version is running -#if !defined (QT_WEBKIT_LIB) - if ( m_usedBrowser == BROWSER_QTWEBKIT ) - m_usedBrowser = BROWSER_QTEXTBROWSER; -#endif - - return true; -} - -bool KCHMConfig::save( ) -{ - QFile file( m_datapath + "/config" ); - if ( !file.open (QIODevice::WriteOnly) ) - { - qWarning( "Could not write settings into file %s: %s", - qPrintable( file.fileName() ), - qPrintable( file.errorString() ) ); - return false; - } - - QTextStream stream( &file ); - stream.setCodec( "UTF-8" ); - stream << "[settings]\n"; - stream << "LoadLatestFileOnStartup=" << m_LoadLatestFileOnStartup << "\n"; - - stream << "onNewChmClick=" << m_onNewChmClick << "\n"; - stream << "onExternalLinkClick=" << m_onExternalLinkClick << "\n"; - stream << "HistorySize=" << m_numOfRecentFiles << "\n"; - stream << "HistoryStoreExtra=" << m_HistoryStoreExtra << "\n"; - stream << "UsedBrowser=" << m_usedBrowser << "\n"; - - stream << "kdeEnableJS=" << m_kdeEnableJS << "\n"; - stream << "kdeEnableJava=" << m_kdeEnableJava << "\n"; - stream << "kdeEnablePlugins=" << m_kdeEnablePlugins << "\n"; - stream << "kdeEnableRefresh=" << m_kdeEnableRefresh << "\n"; - stream << "advUseInternalEditor=" << m_advUseInternalEditor << "\n"; - stream << "advExternalEditorPath=" << m_advExternalEditorPath << "\n"; - stream << "advLayoutDirectionRL=" << m_advLayoutDirectionRL << "\n"; - stream << "advAutoDetectEncoding=" << m_advAutodetectEncoding << "\n"; - - stream << "LastOpenedDir=" << m_lastOpenedDir << "\n"; - - stream << "\n[history]\n"; - - // Do not write all the history, but only the needed amount - for ( int i = 0; i < m_recentFiles.size(); i++ ) - stream << m_recentFiles[m_recentFiles.size() - 1 - i] << "\n"; - - return true; -} - -void KCHMConfig::addRecentFile( const QString & filename ) -{ - m_recentFiles.removeAll( filename ); - m_recentFiles.prepend( filename ); - - while( m_recentFiles.size() > m_numOfRecentFiles ) - { - // Remove the appropriate history file - mainWindow->currentSettings()->removeSettings( m_recentFiles.last() ); - m_recentFiles.removeLast(); - } -} diff -Nru kchmviewer-4.1/src/kchmconfig.h kchmviewer-5.1/src/kchmconfig.h --- kchmviewer-4.1/src/kchmconfig.h 2009-07-20 04:38:09.000000000 +0100 +++ kchmviewer-5.1/src/kchmconfig.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMCONFIG_H -#define KCHMCONFIG_H - -#include -#include - -extern const char * APP_PATHINUSERDIR; - - -class KCHMConfig -{ - public: - enum choose_action_t - { - ACTION_ALWAYS_OPEN, - ACTION_ASK_USER, - ACTION_DONT_OPEN - }; - - enum UsedBrowser - { - BROWSER_QTEXTBROWSER = 0, - BROWSER_KHTMLPART, - BROWSER_QTWEBKIT - }; - - KCHMConfig(); - ~KCHMConfig(); - - bool load(); - bool save(); - - void addRecentFile( const QString& file ); - - public: - QString m_datapath; - QString m_lastOpenedDir; - - bool m_LoadLatestFileOnStartup; - choose_action_t m_onNewChmClick; - choose_action_t m_onExternalLinkClick; - int m_numOfRecentFiles; - bool m_HistoryStoreExtra; - int m_usedBrowser; - - bool m_kdeEnableJS; - bool m_kdeEnableJava; - bool m_kdeEnablePlugins; - bool m_kdeEnableRefresh; - - bool m_advUseInternalEditor; - QString m_advExternalEditorPath; - bool m_advLayoutDirectionRL; - bool m_advAutodetectEncoding; - - QStringList m_recentFiles; -}; - -extern KCHMConfig appConfig; - -#endif diff -Nru kchmviewer-4.1/src/kchmcontentswindow.cpp kchmviewer-5.1/src/kchmcontentswindow.cpp --- kchmviewer-4.1/src/kchmcontentswindow.cpp 2009-07-20 04:38:07.000000000 +0100 +++ kchmviewer-5.1/src/kchmcontentswindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,137 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - - -#include "kde-qt.h" - -#include "libchmfile.h" - -#include "kchmcontentswindow.h" -#include "kchmmainwindow.h" -#include "kchmtreeviewitem.h" - - -KCHMContentsWindow::KCHMContentsWindow( QWidget *parent ) - : QWidget( parent ), Ui::TabContents() -{ - setupUi( this ); - - m_contextMenu = 0; - m_contentFilled = false; - - tree->setFocus(); - tree->header()->hide(); - - // Handle clicking on m_contentsWindow element - connect( tree, - SIGNAL( itemClicked ( QTreeWidgetItem *, int ) ), - this, - SLOT( onClicked ( QTreeWidgetItem *, int ) ) ); - - // Activate custom context menu, and connect it - tree->setContextMenuPolicy( Qt::CustomContextMenu ); - connect( tree, - SIGNAL( customContextMenuRequested ( const QPoint & ) ), - this, - SLOT( onContextMenuRequested( const QPoint & ) ) ); -} - -KCHMContentsWindow::~KCHMContentsWindow() -{ -} - -void KCHMContentsWindow::refillTableOfContents( ) -{ - KCHMShowWaitCursor wc; - QVector< LCHMParsedEntry > data; - - if ( !::mainWindow->chmFile()->parseTableOfContents( &data ) - || data.size() == 0 ) - { - qWarning ("CHM toc present but is empty; wrong parsing?"); - return; - } - - kchmFillListViewWithParsedData( tree, data, &m_urlListMap ); -} - - -KCHMIndTocItem * KCHMContentsWindow::getTreeItem( const QString & url ) -{ - QString fixedstr = ::mainWindow->chmFile()->normalizeUrl( url ); - QMap::const_iterator it = m_urlListMap.find( fixedstr ); - - if ( it == m_urlListMap.end() ) - return 0; - - return *it; -} - -void KCHMContentsWindow::showItem(KCHMIndTocItem * item) -{ - tree->setCurrentItem( item ); - tree->scrollToItem( item ); -} - -void KCHMContentsWindow::showEvent(QShowEvent *) -{ - if ( !::mainWindow->chmFile() || m_contentFilled ) - return; - - m_contentFilled = true; - refillTableOfContents(); -} - -void KCHMContentsWindow::onClicked(QTreeWidgetItem * item, int) -{ - bool unused; - - if ( !item ) - return; - - KCHMIndTocItem * treeitem = (KCHMIndTocItem*) item; - ::mainWindow->activateLink( treeitem->getUrl(), unused ); -} - -void KCHMContentsWindow::onContextMenuRequested(const QPoint & point) -{ - KCHMIndTocItem * treeitem = (KCHMIndTocItem *) tree->itemAt( point ); - - if( treeitem ) - { - ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); - ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); - } -} - - -void KCHMContentsWindow::search( const QString & text ) -{ - QList items = tree->findItems( text, Qt::MatchWildcard | Qt::MatchRecursive ); - bool unused; - qDebug("found %d items of %d", items.size(), tree-> - topLevelItemCount() ); - if ( items.isEmpty() ) - return; - - KCHMIndTocItem * treeitem = (KCHMIndTocItem *) items.first(); - ::mainWindow->activateLink( treeitem->getUrl(), unused ); -} diff -Nru kchmviewer-4.1/src/kchmcontentswindow.h kchmviewer-5.1/src/kchmcontentswindow.h --- kchmviewer-4.1/src/kchmcontentswindow.h 2009-07-20 04:38:05.000000000 +0100 +++ kchmviewer-5.1/src/kchmcontentswindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef INCLUDE_KCHMCONTENTSWINDOW_H -#define INCLUDE_KCHMCONTENTSWINDOW_H - -#include "kde-qt.h" -#include "kchmtreeviewitem.h" -#include "ui_tab_contents.h" - - -class KCHMContentsWindow : public QWidget, public Ui::TabContents -{ - Q_OBJECT - public: - KCHMContentsWindow( QWidget *parent = 0 ); - ~KCHMContentsWindow(); - - void refillTableOfContents(); - void showItem( KCHMIndTocItem * item ); - void search( const QString& text ); - - KCHMIndTocItem * getTreeItem( const QString& url ); - - public slots: - void onContextMenuRequested ( const QPoint &point ); - void onClicked ( QTreeWidgetItem * item, int column ); - - private: - virtual void showEvent ( QShowEvent * ); - - private: - bool m_contentFilled; - QMenu * m_contextMenu; - QMap m_urlListMap; -}; - - -#endif /* INCLUDE_KCHMCONTENTSWINDOW_H */ diff -Nru kchmviewer-4.1/src/kchmdbusiface.cpp kchmviewer-5.1/src/kchmdbusiface.cpp --- kchmviewer-4.1/src/kchmdbusiface.cpp 2009-07-20 04:38:02.000000000 +0100 +++ kchmviewer-5.1/src/kchmdbusiface.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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 - -#include "kchmdbusiface.h" -#include "kchmmainwindow.h" -#include "kchmsearchwindow.h" - - -KCHMDBusIface::KCHMDBusIface( QObject *parent ) - : QObject( parent ) -{ - QDBusConnection::sessionBus().registerObject( "/application", - this, - QDBusConnection::ExportScriptableSlots ); -} - - -KCHMDBusIface::~KCHMDBusIface() -{ -} - - -void KCHMDBusIface::loadHelpFile( const QString & filename, const QString & page2open ) -{ - QStringList args; - - args.push_back( filename ); - args.push_back( page2open ); - - qApp->postEvent( ::mainWindow, new KCHMUserEvent( "loadAndOpen", args ) ); -} - - -void KCHMDBusIface::openPage( const QString & page2open ) -{ - QStringList args; - - args.push_back( page2open ); - qApp->postEvent( ::mainWindow, new KCHMUserEvent( "openPage", args ) ); -} - - -void KCHMDBusIface::guiFindInIndex( const QString & word ) -{ - QStringList args; - - args.push_back( word ); - qApp->postEvent( ::mainWindow, new KCHMUserEvent( "findInIndex", args ) ); -} - - -void KCHMDBusIface::guiSearchQuery( const QString & query ) -{ - QStringList args; - - args.push_back( query ); - qApp->postEvent( ::mainWindow, new KCHMUserEvent( "searchQuery", args ) ); -} - -QStringList KCHMDBusIface::searchQuery( const QString & query ) -{ - QStringList results; - - if ( ::mainWindow->searchWindow()->searchQuery( query, &results ) ) - return results; - else - return QStringList(); -} diff -Nru kchmviewer-4.1/src/kchmdbusiface.h kchmviewer-5.1/src/kchmdbusiface.h --- kchmviewer-4.1/src/kchmdbusiface.h 2009-07-20 04:38:00.000000000 +0100 +++ kchmviewer-5.1/src/kchmdbusiface.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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 KCHMDBUSIFACE_H -#define KCHMDBUSIFACE_H - -#include -#include -#include - - -#define SERVICE_NAME "net.kchmviewer.application" - -class KCHMDBusIface : public QObject -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "net.kchmviewer.application") - - public: - KCHMDBusIface( QObject *parent = 0 ); - ~KCHMDBusIface(); - - public Q_SLOTS: - //! Loads a CHM file \a filename , and opens the URL \a url. Use URL "/" to open default homepage - Q_SCRIPTABLE void loadHelpFile( const QString& filename, const QString& url ); - - //! Opens a specific \a url inside the loaded CHM file - Q_SCRIPTABLE void openPage( const QString& url ); - - //! Tries to find word in index, opening the index window and scrolling it there - Q_SCRIPTABLE void guiFindInIndex( const QString& word ); - - //! Executes a search in GUI. \a query contains the complete search query. - Q_SCRIPTABLE void guiSearchQuery( const QString& query ); - - //! Executes a search; GUI is not involved and user sees nothing. - //! \a query contains the complete search query. - //! Returns a list of URLs, or empty array if nothing os - Q_SCRIPTABLE QStringList searchQuery( const QString& query ); -}; - -#endif // KCHMDBUSIFACE_H diff -Nru kchmviewer-4.1/src/kchmdialogchooseurlfromlist.cpp kchmviewer-5.1/src/kchmdialogchooseurlfromlist.cpp --- kchmviewer-4.1/src/kchmdialogchooseurlfromlist.cpp 2009-07-20 04:37:58.000000000 +0100 +++ kchmviewer-5.1/src/kchmdialogchooseurlfromlist.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "kde-qt.h" - -#include "kchmdialogchooseurlfromlist.h" -#include "kchmtreeviewitem.h" - - -KCHMDialogChooseUrlFromList::KCHMDialogChooseUrlFromList( QWidget* parent ) - : QDialog( parent ), Ui::DialogTopicSelector() -{ - setupUi( this ); - - // List doubleclick - connect( list, - SIGNAL( itemDoubleClicked ( QListWidgetItem * ) ), - this, - SLOT( onDoubleClicked( QListWidgetItem * ) ) ); -} - -void KCHMDialogChooseUrlFromList::onDoubleClicked( QListWidgetItem * item ) -{ - if ( item ) - accept(); -} - - -QString KCHMDialogChooseUrlFromList::getSelectedItemUrl( const QStringList & urls, const QStringList & titles ) -{ - for ( int i = 0; i < urls.size(); i++ ) - list->addItem( titles[i] ); - - if ( exec() == QDialog::Accepted && list->currentRow() != -1 ) - return urls[ list->currentRow() ]; - - return QString::null; -} diff -Nru kchmviewer-4.1/src/kchmdialogchooseurlfromlist.h kchmviewer-5.1/src/kchmdialogchooseurlfromlist.h --- kchmviewer-4.1/src/kchmdialogchooseurlfromlist.h 2009-07-20 04:37:56.000000000 +0100 +++ kchmviewer-5.1/src/kchmdialogchooseurlfromlist.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMDIALOGCHOOSEURLFROMLIST_H -#define KCHMDIALOGCHOOSEURLFROMLIST_H - -#include -#include "ui_dialog_topicselector.h" - - -class KCHMDialogChooseUrlFromList : public QDialog, public Ui::DialogTopicSelector -{ - Q_OBJECT - - public: - KCHMDialogChooseUrlFromList( QWidget* parent ); - - // Shows the dialog with titles, and let the user to select the title. - // Obviously urls.size() == titles.size(). Returns the appropriate URL - // for the selected title, or empty string if no title selected, or dialog canceled. - QString getSelectedItemUrl( const QStringList& urls, const QStringList& titles ); - - private slots: - void onDoubleClicked( QListWidgetItem * item ); -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmindexwindow.cpp kchmviewer-5.1/src/kchmindexwindow.cpp --- kchmviewer-4.1/src/kchmindexwindow.cpp 2009-07-20 04:37:52.000000000 +0100 +++ kchmviewer-5.1/src/kchmindexwindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,184 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - - -#include "libchmfile.h" - -#include "kchmmainwindow.h" -#include "kchmindexwindow.h" -#include "kchmtreeviewitem.h" - - -KCHMIndexWindow::KCHMIndexWindow ( QWidget * parent ) - : QWidget( parent ), Ui::TabIndex() -{ - // UIC stuff - setupUi( this ); - - tree->headerItem()->setHidden( true ); - - connect( text, - SIGNAL( textChanged (const QString &) ), - this, - SLOT( onTextChanged(const QString &) ) ); - - connect( text, - SIGNAL( returnPressed() ), - this, - SLOT( onReturnPressed() ) ); - - connect( tree, - SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int ) ), - this, - SLOT( onDoubleClicked ( QTreeWidgetItem *, int) ) ); - - // Activate custom context menu, and connect it - tree->setContextMenuPolicy( Qt::CustomContextMenu ); - connect( tree, - SIGNAL( customContextMenuRequested ( const QPoint & ) ), - this, - SLOT( onContextMenuRequested( const QPoint & ) ) ); - - m_indexListFilled = false; - m_lastSelectedItem = 0; - m_contextMenu = 0; - - text->setFocus(); -} - -void KCHMIndexWindow::onTextChanged ( const QString & newvalue) -{ - QList items = tree->findItems( newvalue, Qt::MatchStartsWith ); - - if ( !items.isEmpty() ) - { - m_lastSelectedItem = items[0]; - tree->setCurrentItem( m_lastSelectedItem ); - tree->scrollToItem( m_lastSelectedItem ); - } - else - m_lastSelectedItem = 0; -} - - -void KCHMIndexWindow::showEvent( QShowEvent * ) -{ - if ( !::mainWindow->chmFile() || m_indexListFilled ) - return; - - m_indexListFilled = true; - refillIndex(); -} - -void KCHMIndexWindow::onReturnPressed( ) -{ - bool unused; - - if ( !m_lastSelectedItem ) - return; - - KCHMIndTocItem * treeitem = (KCHMIndTocItem*) m_lastSelectedItem; - ::mainWindow->activateLink( treeitem->getUrl(), unused ); -} - - -void KCHMIndexWindow::invalidate( ) -{ - tree->clear(); - m_indexListFilled = false; -} - -void KCHMIndexWindow::onDoubleClicked ( QTreeWidgetItem * item, int ) -{ - if ( !item ) - return; - - KCHMIndTocItem * treeitem = (KCHMIndTocItem*) item; - - // Prevent opened index tree item from closing; because the tree open/close - // procedure will be triggered after the slots are called, we change the tree - // state to "collapsed", so the slot handler expands it again. - if ( item->isExpanded() ) - item->setExpanded( false ); - - QString url = treeitem->getUrl(); - - if ( url.isEmpty() ) - return; - - if ( url[0] == ':' ) // 'see also' link - { - QList items = tree->findItems( url.mid(1), Qt::MatchFixedString ); - - if ( !items.isEmpty() ) - { - m_lastSelectedItem = items[0]; - tree->setCurrentItem( m_lastSelectedItem ); - tree->scrollToItem( m_lastSelectedItem ); - } - else - m_lastSelectedItem = 0; - } - else - ::mainWindow->openPage( url, KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY ); -} - - -void KCHMIndexWindow::refillIndex( ) -{ - KCHMShowWaitCursor wc; - QVector< LCHMParsedEntry > data; - - if ( !::mainWindow->chmFile()->parseIndex( &data ) - || data.size() == 0 ) - { - qWarning ("CHM index present but is empty; wrong parsing?"); - return; - } - - kchmFillListViewWithParsedData( tree, data, 0 ); -} - -void KCHMIndexWindow::search( const QString & index ) -{ - if ( !::mainWindow->chmFile() ) - return; - - if ( !m_indexListFilled ) - { - m_indexListFilled = true; - refillIndex(); - } - - text->setText( index ); - onTextChanged( index ); -} - -void KCHMIndexWindow::onContextMenuRequested(const QPoint & point) -{ - KCHMIndTocItem * treeitem = (KCHMIndTocItem *) tree->itemAt( point ); - - if( treeitem ) - { - ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); - ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); - } -} diff -Nru kchmviewer-4.1/src/kchmindexwindow.h kchmviewer-5.1/src/kchmindexwindow.h --- kchmviewer-4.1/src/kchmindexwindow.h 2009-07-20 04:37:35.000000000 +0100 +++ kchmviewer-5.1/src/kchmindexwindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMINDEXWINDOW_H -#define KCHMINDEXWINDOW_H - - -#include "kde-qt.h" -#include "ui_tab_index.h" - - -class KCHMIndexWindow : public QWidget, public Ui::TabIndex -{ - Q_OBJECT - public: - KCHMIndexWindow ( QWidget * parent = 0 ); - - void invalidate(); - void search( const QString& index ); - - private slots: - void onTextChanged ( const QString & newvalue); - void onReturnPressed (); - void onDoubleClicked ( QTreeWidgetItem * item, int column ); - void onContextMenuRequested ( const QPoint &point ); - - private: - virtual void showEvent ( QShowEvent * ); - - void refillIndex(); - - QMenu * m_contextMenu; - QTreeWidgetItem * m_lastSelectedItem; - bool m_indexListFilled; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmkeyeventfilter.cpp kchmviewer-5.1/src/kchmkeyeventfilter.cpp --- kchmviewer-4.1/src/kchmkeyeventfilter.cpp 2009-07-20 04:37:33.000000000 +0100 +++ kchmviewer-5.1/src/kchmkeyeventfilter.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include - -#include "kchmkeyeventfilter.h" - -KCHMKeyEventFilter gKeyEventFilter; - -KCHMKeyEventFilter::KCHMKeyEventFilter() - : QObject() -{ - m_shiftPressed = false; - m_ctrlPressed = false; -} - -bool KCHMKeyEventFilter::eventFilter( QObject *, QEvent *e ) -{ - // Handle KeyPress and KeyRelease events - if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) - { - bool * ptr = 0; - QKeyEvent *k = (QKeyEvent *) e; - - // We're interested only in Shift and Control - if ( k->key() == Qt::Key_Shift ) - ptr = &m_shiftPressed; - else if ( k->key() == Qt::Key_Control ) - ptr = &m_ctrlPressed; - - // Set it - if ( ptr ) - *ptr = e->type() == QEvent::KeyPress ? true : false; - } - - return FALSE; // Standard event processing -} diff -Nru kchmviewer-4.1/src/kchmkeyeventfilter.h kchmviewer-5.1/src/kchmkeyeventfilter.h --- kchmviewer-4.1/src/kchmkeyeventfilter.h 2009-07-20 04:37:30.000000000 +0100 +++ kchmviewer-5.1/src/kchmkeyeventfilter.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef INCLUDE_KCHMKEYEVENTFILTER_H -#define INCLUDE_KCHMKEYEVENTFILTER_H - -#include -#include - - -/*!* - * This class must be installed as a global event handler. Its responsibility - * is to intercept keyboard events, and store the Shift and Ctrl keys state information. - * Unfortunately it seems to be the only way to do it in Qt. - */ -class KCHMKeyEventFilter : public QObject -{ - public: - KCHMKeyEventFilter(); - - bool isShiftPressed() const { return m_shiftPressed; } - bool isCtrlPressed() const { return m_ctrlPressed; } - - private: - bool eventFilter( QObject *, QEvent *e ); - - bool m_shiftPressed; - bool m_ctrlPressed; -}; - -extern KCHMKeyEventFilter gKeyEventFilter; - -#endif /* INCLUDE_KCHMKEYEVENTFILTER_H */ diff -Nru kchmviewer-4.1/src/kchmmainwindow.cpp kchmviewer-5.1/src/kchmmainwindow.cpp --- kchmviewer-4.1/src/kchmmainwindow.cpp 2009-07-20 04:35:56.000000000 +0100 +++ kchmviewer-5.1/src/kchmmainwindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,1543 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "kde-qt.h" - -#include "libchmfile.h" -#include "libchmfileimpl.h" -#include "libchmurlfactory.h" - -#include "kchmmainwindow.h" -#include "kchmconfig.h" -#include "kchmindexwindow.h" -#include "kchmsearchwindow.h" -#include "kchmbookmarkwindow.h" -#include "kchmtreeviewitem.h" -#include "kchmsettings.h" -#include "kchmviewwindow.h" -#include "kchmviewwindowmgr.h" -#include "kchmkeyeventfilter.h" -#include "kchmcontentswindow.h" -#include "kchmsetupdialog.h" -#include "version.h" - - -KCHMMainWindow::KCHMMainWindow() - : QMainWindow ( 0 ), Ui::MainWindow() -{ - const unsigned int WND_X_SIZE = 700; - const unsigned int WND_Y_SIZE = 500; - const unsigned int SPLT_X_SIZE = 200; - - // Delete the pointer when the window is closed - setAttribute( Qt::WA_DeleteOnClose ); - - // UIC stuff - setupUi( this ); - - // Set up layout direction - if ( appConfig.m_advLayoutDirectionRL ) - qApp->setLayoutDirection( Qt::RightToLeft ); - else - qApp->setLayoutDirection( Qt::LeftToRight ); - - m_chmFile = 0; - - m_indexTab = 0; - m_searchTab = 0; - m_contentsTab = 0; - m_viewWindowMgr = 0; - - m_tabContextPage = -1; - m_tabIndexPage = -1; - m_tabSearchPage = -1; - m_tabBookmarkPage = -1; - - setupSignals(); - - m_currentSettings = new KCHMSettings; - - // Create the initial layout - a splitter with tab window in left, and text browser in right - m_windowSplitter = new QSplitter(this); - m_tabWidget = new KQTabWidget( m_windowSplitter ); - m_viewWindowMgr = new KCHMViewWindowMgr( m_windowSplitter ); - - m_bookmarkWindow = new KCHMBookmarkWindow( m_tabWidget ); - - // Add the tabs - m_tabWidget->addTab( m_bookmarkWindow, i18n("Bookmarks") ); - - // Splitter is a central widget - setCentralWidget( m_windowSplitter ); - - // Setting up splitter sizes - QList sizes; - sizes.push_back( SPLT_X_SIZE ); - sizes.push_back( WND_X_SIZE - SPLT_X_SIZE ); - m_windowSplitter->setSizes( sizes ); - - // Set up things - setupActions(); - setupLangEncodingMenu(); - - // Resize main window - resize( WND_X_SIZE, WND_Y_SIZE ); - -#if defined (ENABLE_AUTOTEST_SUPPORT) - m_autoteststate = STATE_OFF; -#endif /* defined (ENABLE_AUTOTEST_SUPPORT) */ - - statusBar()->show(); - qApp->setWindowIcon( QPixmap(":/images/application.png") ); - - m_aboutDlgMenuText = i18n( "%1 version %2

" - "Copyright (C) George Yunaev, 2004-2008
" - "gyunaev@ulduzsoft.com
" - "http://www.kchmviewer.net

" - "Licensed under GNU GPL license." ) - . arg(APP_NAME) . arg(APP_VERSION); - - QTimer::singleShot( 0, this, SLOT( firstShow()) ); -} - - -KCHMMainWindow::~KCHMMainWindow() -{ - // Temporary files cleanup - while ( !m_tempFileKeeper.isEmpty() ) - delete m_tempFileKeeper.takeFirst(); -} - - - -bool KCHMMainWindow::loadFile ( const QString &loadFileName, bool call_open_page ) -{ - QString fileName = loadFileName; - - // Strip file:// prefix if any - if ( fileName.startsWith( "file://" ) ) - fileName.remove( 0, 7 ); - - LCHMFile * new_chmfile = new LCHMFile(); - - if ( new_chmfile->loadFile( fileName ) ) - { - // The new file is opened, so we can close the old one - if ( m_chmFile ) - { - closeFile( ); - delete m_chmFile; - } - - m_chmFile = new_chmfile; - - // Show current encoding in status bar - showInStatusBar( i18n("Detected file encoding: %1 ( %2 )") - .arg( m_chmFile->currentEncoding()->family) - .arg( m_chmFile->currentEncoding()->qtcodec) ); - - // Make the file name absolute; we'll need it later - QDir qd; - qd.setPath (fileName); - m_chmFilename = qd.absolutePath(); - - // Qt's 'dirname' does not work well - QFileInfo qf ( m_chmFilename ); - appConfig.m_lastOpenedDir = qf.dir().path(); - m_chmFileBasename = qf.fileName(); - - // Order the tabulations - int number_of_pages = 0; - - if ( m_chmFile->hasTableOfContents() ) - m_tabContextPage = number_of_pages++; - else - m_tabContextPage = -1; - - if ( m_chmFile->hasIndexTable() ) - m_tabIndexPage = number_of_pages++; - else - m_tabIndexPage = -1; - - // We always show search - m_tabSearchPage = number_of_pages++; - - m_tabBookmarkPage = number_of_pages; - - showOrHideContextWindow( m_tabContextPage ); - showOrHideIndexWindow( m_tabIndexPage ); - showOrHideSearchWindow( m_tabSearchPage ); - - m_bookmarkWindow->invalidate(); - navSetBackEnabled( false ); - navSetForwardEnabled( false ); - m_viewWindowMgr->invalidate(); - refreshCurrentBrowser(); - - if ( m_currentSettings->loadSettings (fileName) ) - { - const LCHMTextEncoding * encoding = - m_chmFile->impl()->lookupByQtCodec( m_currentSettings->m_activeEncoding ); - - // tim: this one triggers loading Index if the chm file was closed when the index was opened - //m_tabWidget->setCurrentIndex( m_currentSettings->m_activetabsystem ); - - if ( encoding ) - setTextEncoding( encoding ); - - if ( m_searchTab ) - m_searchTab->restoreSettings (m_currentSettings->m_searchhistory); - - m_bookmarkWindow->restoreSettings (m_currentSettings->m_bookmarks); - - if ( call_open_page ) - { - m_viewWindowMgr->restoreSettings( m_currentSettings->m_viewwindows ); - m_viewWindowMgr->setCurrentPage( m_currentSettings->m_activetabwindow ); - - if ( m_tabContextPage != -1 && m_tabContextPage == m_currentSettings->m_activetabwindow ) - actionLocateInContentsTab(); - } - - // Restore the main window size - QList sizes; - sizes.push_back( m_currentSettings->m_window_size_splitter ); - sizes.push_back( m_currentSettings->m_window_size_x - m_currentSettings->m_window_size_splitter ); - - m_windowSplitter->setSizes( sizes ); - resize( m_currentSettings->m_window_size_x, m_currentSettings->m_window_size_y ); - } - else - { - m_tabWidget->setCurrentIndex( 0 ); - setTextEncoding( m_chmFile->currentEncoding() ); - - if ( call_open_page ) - openPage( m_chmFile->homeUrl() ); - } - - appConfig.addRecentFile( m_chmFilename ); - recentFilesUpdate(); - return true; - } - else - { - QMessageBox mbox( - i18n("%1 - failed to load the chm file") . arg(APP_NAME), - i18n("Unable to load the chm file %1") . arg(fileName), - QMessageBox::Critical, - QMessageBox::Ok, - Qt::NoButton, - Qt::NoButton); - mbox.exec(); - - statusBar()->showMessage( - i18n("Could not load file %1").arg(fileName), - 2000 ); - delete new_chmfile; - return false; - } -} - - - -void KCHMMainWindow::refreshCurrentBrowser( ) -{ - QString title = m_chmFile->title(); - - if ( title.isEmpty() ) - title = APP_NAME; - // KDE adds application name automatically, so we don't need it here -#if !defined (USE_KDE) - else - title = (QString) APP_NAME + " - " + title; -#endif - - setWindowTitle( title ); - - currentBrowser()->invalidate(); - - if ( m_contentsTab ) - m_contentsTab->refillTableOfContents(); -} - - - -void KCHMMainWindow::activateLink ( const QString & link, bool& follow_link ) -{ - if ( link.isEmpty() ) - return; - - if ( gKeyEventFilter.isShiftPressed() ) - { - openPage( link, OPF_NEW_TAB | OPF_CONTENT_TREE ); - follow_link = false; - } - else if ( gKeyEventFilter.isCtrlPressed() ) - { - openPage( link, OPF_NEW_TAB | OPF_BACKGROUND ); - follow_link = false; - } - else - // If the openPage failed, we do not need to follow the link. - follow_link = openPage( link, OPF_CONTENT_TREE | OPF_ADD2HISTORY ); -} - - -bool KCHMMainWindow::openPage( const QString & srcurl, unsigned int flags ) -{ - QString otherlink, otherfile, url = srcurl; - - if ( url == "/" ) - url = m_chmFile->homeUrl(); - - if ( LCHMUrlFactory::isRemoteURL (url, otherlink) ) - { - switch ( appConfig.m_onExternalLinkClick ) - { - case KCHMConfig::ACTION_DONT_OPEN: - break; - - case KCHMConfig::ACTION_ASK_USER: - if ( QMessageBox::question(this, - i18n("%1 - remote link clicked - %2") . arg(APP_NAME) . arg(otherlink), - i18n("A remote link %1 will start the external program to open it.\n\nDo you want to continue?").arg( url ), - i18n("&Yes"), i18n("&No"), - QString::null, 0, 1 ) ) - return false; - - // no break! should continue to open. - - case KCHMConfig::ACTION_ALWAYS_OPEN: -#if defined (USE_KDE) - new KRun ( url, 0 ); -#else - QDesktopServices::openUrl( url ); -#endif - break; - } - - return false; // do not change the current page. - } - - // Filter the URLs which do not need to be opened at all by Qt version - if ( LCHMUrlFactory::isJavascriptURL (url) ) - { - QMessageBox::information( this, - i18n( "%1 - JavsScript link clicked") . arg(APP_NAME), - i18n( "You have clicked a JavaScript link.\nTo prevent security-related issues JavaScript URLs are disabled in CHM files.") ); - - return false; - } - - if ( LCHMUrlFactory::isNewChmURL (url, otherfile, otherlink) ) - { - // If new filename has relative path, convert it to absolute. - QFileInfo finfo( otherfile ); - - if ( !finfo.isAbsolute() ) - { - QFileInfo chmfinfo( m_chmFilename ); - otherfile = chmfinfo.absolutePath() + QDir::separator() + otherfile; - } - - if ( otherfile != m_chmFilename ) - { - if ( QMessageBox::question( this, - i18n( "%1 - link to a new CHM file clicked"). arg(APP_NAME), - i18n( "You have clicked a link, which leads to a new CHM file %1.\nThe current file will be closed.\n\nDo you want to continue?").arg( otherfile ), - i18n( "&Yes" ), i18n( "&No" ), - QString::null, 0, 1 ) ) - return false; - - // Because chm file always contain relative link, and current filename is not changed, - // we need to form a new path - QStringList event_args; - event_args.push_back( otherfile ); - event_args.push_back( otherlink ); // url - - qApp->postEvent( this, new KCHMUserEvent( "loadAndOpen", event_args ) ); - return false; - } - else - url = otherlink; - } - - KCHMViewWindow * vwnd = currentBrowser(); - if ( flags & OPF_NEW_TAB ) - vwnd = m_viewWindowMgr->addNewTab( !(flags & OPF_BACKGROUND) ); - - // Store current page and position to add it to history if we change it - int hist_scrollpos = currentBrowser()->getScrollbarPosition(); - QString hist_url = currentBrowser()->getOpenedPage(); - - if ( vwnd->openUrl (url) ) - { - // Open all the tree items to show current item (if needed) - if ( (flags & OPF_CONTENT_TREE) != 0 ) - locateInContentTree( vwnd->getOpenedPage() ); - - if ( flags & OPF_ADD2HISTORY ) - currentBrowser()->addNavigationHistory( hist_url, hist_scrollpos ); - } - - return true; -} - - -void KCHMMainWindow::firstShow() -{ - if ( !parseCmdLineArgs( ) ) - { - if ( appConfig.m_LoadLatestFileOnStartup && appConfig.m_recentFiles.size() > 0 ) - { - if ( loadFile( appConfig.m_recentFiles[0] ) ) - return; - } - - emit actionOpenFile(); - } -} - - -void KCHMMainWindow::setTextEncoding( const LCHMTextEncoding * encoding ) -{ - m_chmFile->setCurrentEncoding( encoding ); - - // Find the appropriate encoding item in "Set encodings" menu - const QList encodings = m_encodingActions->actions(); - - for ( QList::const_iterator it = encodings.begin(); - it != encodings.end(); - ++it ) - { - const LCHMTextEncoding * enc = (const LCHMTextEncoding *) (*it)->data().value< void* > (); - - if ( !strcmp( enc->qtcodec, encoding->qtcodec ) ) - { - if ( !(*it)->isChecked() ) - (*it)->setChecked( true ); - - break; - } - } - - // Because updateView() will call view->invalidate(), which clears the view->getOpenedPage(), - // we have to make a copy of it. - QString url = currentBrowser()->getOpenedPage(); - - // Regenerate the content and index trees - refreshCurrentBrowser(); - - currentBrowser()->openUrl( url ); -} - -void KCHMMainWindow::closeFile( ) -{ - // Prepare the settings - if ( appConfig.m_HistoryStoreExtra ) - { - m_currentSettings->m_activeEncoding = m_chmFile->currentEncoding()->qtcodec; - m_currentSettings->m_activetabsystem = m_tabWidget->currentIndex( ); - m_currentSettings->m_activetabwindow = m_viewWindowMgr->currentPageIndex( ); - - m_currentSettings->m_window_size_x = width(); - m_currentSettings->m_window_size_y = height(); - m_currentSettings->m_window_size_splitter = m_windowSplitter->sizes()[0]; - - if ( m_searchTab ) - m_searchTab->saveSettings (m_currentSettings->m_searchhistory); - - m_bookmarkWindow->saveSettings( m_currentSettings->m_bookmarks ); - - m_viewWindowMgr->saveSettings( m_currentSettings->m_viewwindows ); - - m_currentSettings->saveSettings( ); - } - - appConfig.save(); -} - - -void KCHMMainWindow::closeEvent ( QCloseEvent * e ) -{ - // Save the settings if we have something opened - if ( m_chmFile ) - { - closeFile( ); - delete m_chmFile; - m_chmFile = 0; - } - - QMainWindow::closeEvent ( e ); -} - -bool KCHMMainWindow::parseCmdLineArgs( ) -{ - QString filename = QString::null, search_query = QString::null; - QString search_index = QString::null, search_bookmark = QString::null, search_toc = QString::null; - bool do_autotest = false; - -#if defined (USE_KDE) - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - - if ( args->isSet("autotestmode") || args->isSet("shortautotestmode") ) - do_autotest = true; - - search_query = args->getOption ("search"); - search_index = args->getOption ("sindex"); - search_toc = args->getOption ("stoc"); - - if ( args->count() > 0 ) - filename = args->arg(0); -#else - // argv[0] in Qt is still a program name - for ( int i = 1; i < qApp->argc(); i++ ) - { - if ( !strcmp (qApp->argv()[i], "-h") || !strcmp (qApp->argv()[i], "--help") ) - { - fprintf (stderr, "Usage: %s [options] [chmfile]\n" - " The following options supported:\n" - " --search specifies the search query to search, and activate the first entry if found\n" - " --sindex specifies the word to find in index, and activate if found\n" - " --stoc specifies the word(s) to find in TOC, and activate if found. Wildcards allowed\n", - qApp->argv()[0] ); - - exit (1); - } -#if defined (ENABLE_AUTOTEST_SUPPORT) - else if ( !strcmp (qApp->argv()[i], "--autotestmode") || !strcmp (qApp->argv()[i], "--shortautotestmode") ) - do_autotest = true; -#endif - else if ( !strcmp (qApp->argv()[i], "--search") ) - search_query = qApp->argv()[++i]; - else if ( !strcmp (qApp->argv()[i], "--sindex") ) - search_index = qApp->argv()[++i]; - else if ( !strcmp (qApp->argv()[i], "--stoc") ) - search_toc = qApp->argv()[++i]; - else - filename = QString::fromLocal8Bit( qApp->argv()[i] ); - } -#endif - - if ( !filename.isEmpty() ) - { - if ( !loadFile( filename ) ) - return true; // skip the latest checks, but do not exit from the program - - if ( !search_index.isEmpty() ) - { - QStringList event_args; - event_args.push_back( search_index ); - qApp->postEvent( this, new KCHMUserEvent( "findInIndex", event_args ) ); - } - - if ( !search_query.isEmpty() ) - { - QStringList event_args; - event_args.push_back( search_query ); - qApp->postEvent( this, new KCHMUserEvent( "searchQuery", event_args ) ); - } - - if ( !search_toc.isEmpty() ) - { - QStringList event_args; - event_args.push_back( search_toc ); - qApp->postEvent( this, new KCHMUserEvent( "findInToc", event_args ) ); - } - - if ( do_autotest ) - { -#if defined (ENABLE_AUTOTEST_SUPPORT) - if ( filename.isEmpty() ) - qFatal ("Could not use Auto Test mode without a chm file!"); - - m_autoteststate = STATE_INITIAL; - showMinimized (); - runAutoTest(); -#else - qFatal ("Auto Test mode support is not compiled in."); -#endif /* defined (ENABLE_AUTOTEST_SUPPORT) */ - } - return true; - } - - return false; -} - - - -void KCHMMainWindow::setupSignals( ) -{ -#if !defined (_WIN32) -#if defined(HAVE_SIGACTION) - struct sigaction sa; - memset ((char *)&sa, 0, sizeof(sa)); - sigemptyset (&sa.sa_mask); - sigaddset (&sa.sa_mask, SIGCHLD); - -#ifdef SA_RESTART - sa.sa_flags = SA_RESTART; -#endif - - sa.sa_handler = SIG_IGN; - sigaction (SIGCHLD, &sa, (struct sigaction *)0); -#else /* !HAVE_SIGACTION */ - signal (SIGCHLD, SIG_IGN); -#endif /* HAVE_SIGACTION */ -#endif /* !defined (_WIN32) */ -} - - -void KCHMMainWindow::showOrHideContextWindow( int tabindex ) -{ - if ( tabindex == -1 ) - { - if ( m_contentsTab ) - { - m_tabWidget->removeTab( m_tabWidget->indexOf( m_contentsTab ) ); - delete m_contentsTab; - m_contentsTab = 0; - } - - nav_actionPreviousPage->setEnabled( false ); - nav_actionNextPageToc->setEnabled( false ); - } - else - { - if ( !m_contentsTab ) - { - m_contentsTab = new KCHMContentsWindow( m_tabWidget ); - m_tabWidget->insertTab( tabindex, m_contentsTab, i18n( "Contents" ) ); - } - - nav_actionPreviousPage->setEnabled( true ); - nav_actionNextPageToc->setEnabled( true ); - } -} - -void KCHMMainWindow::showOrHideIndexWindow( int tabindex ) -{ - // Test whether to show/invalidate the index window - if ( tabindex == -1 ) - { - if ( m_indexTab ) - { - m_tabWidget->removeTab( m_tabWidget->indexOf( m_indexTab ) ); - delete m_indexTab; - m_indexTab = 0; - } - } - else - { - if ( !m_indexTab ) - { - m_indexTab = new KCHMIndexWindow (m_tabWidget); - m_tabWidget->insertTab( tabindex, m_indexTab, i18n( "Index" ) ); - } - else - m_indexTab->invalidate(); - } -} - -void KCHMMainWindow::showOrHideSearchWindow( int tabindex ) -{ - if ( tabindex == -1 ) - { - if ( m_searchTab ) - { - m_tabWidget->removeTab( m_tabWidget->indexOf( m_searchTab ) ); - delete m_searchTab; - m_searchTab = 0; - } - } - else - { - if ( !m_searchTab ) - { - m_searchTab = new KCHMSearchWindow (m_tabWidget); - m_tabWidget->insertTab( tabindex, m_searchTab, i18n( "Search" ) ); - } - else - m_searchTab->invalidate(); - } -} - - -KCHMViewWindow * KCHMMainWindow::currentBrowser( ) const -{ - return m_viewWindowMgr->current(); -} - -void KCHMMainWindow::onOpenPageInNewTab( ) -{ - openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_CONTENT_TREE ); -} - -void KCHMMainWindow::onOpenPageInNewBackgroundTab( ) -{ - openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_BACKGROUND ); -} - -void KCHMMainWindow::browserChanged( KCHMViewWindow * newbrowser ) -{ - locateInContentTree( newbrowser->getOpenedPage() ); -} - -void KCHMMainWindow::locateInContentTree( const QString & url ) -{ - if ( !m_contentsTab ) - return; - - KCHMIndTocItem * treeitem = m_contentsTab->getTreeItem( url ); - - if ( treeitem ) - { - KCHMIndTocItem * itemparent = treeitem; - while ( (itemparent = (KCHMIndTocItem*) itemparent->parent()) != 0 ) - itemparent->setExpanded(true); - - m_contentsTab->showItem( treeitem ); - } -} - -bool KCHMMainWindow::event( QEvent * e ) -{ - if ( e->type() == QEvent::User ) - return handleUserEvent( (KCHMUserEvent*) e ); - - return QWidget::event( e ); -} - -bool KCHMMainWindow::handleUserEvent( const KCHMUserEvent * event ) -{ - if ( event->m_action == "loadAndOpen" ) - { - if ( event->m_args.size() != 1 && event->m_args.size() != 2 ) - qFatal("handleUserEvent: event loadAndOpen must receive 1 or 2 args"); - - QString chmfile = event->m_args[0]; - QString openurl = event->m_args.size() > 1 ? event->m_args[1] : "/"; - - return loadFile( chmfile, false ) && openPage( openurl ); - } - else if ( event->m_action == "openPage" ) - { - if ( event->m_args.size() != 1 ) - qFatal("handleUserEvent: event openPage must receive 1 arg"); - - return openPage( event->m_args[0] ); - } - else if ( event->m_action == "findInIndex" ) - { - if ( event->m_args.size() != 1 ) - qFatal( "handleUserEvent: event findInIndex must receive 1 arg" ); - - if ( m_tabIndexPage == -1 ) - return false; - - actionSwitchToIndexTab(); - m_indexTab->search( event->m_args[0] ); - return true; - } - else if ( event->m_action == "findInToc" ) - { - if ( event->m_args.size() != 1 ) - qFatal( "handleUserEvent: event findInToc must receive 1 arg" ); - - if ( m_tabContextPage == -1 ) - return false; - - actionSwitchToContentTab(); - m_contentsTab->search( event->m_args[0] ); - return true; - } - else if ( event->m_action == "searchQuery" ) - { - if ( event->m_args.size() != 1 ) - qFatal( "handleUserEvent: event searchQuery must receive 1 arg" ); - - if ( m_tabSearchPage == -1 ) - return false; - - actionSwitchToSearchTab(); - m_searchTab->execSearchQueryInGui( event->m_args[0] ); - return true; - } - else - qWarning( "Unknown user event received: %s", qPrintable( event->m_action ) ); - - return false; -} - - -#if defined (ENABLE_AUTOTEST_SUPPORT) -void KCHMMainWindow::runAutoTest() -{ - switch (m_autoteststate) - { - case STATE_INITIAL: - m_autoteststate = STATE_OPEN_INDEX; - - QTimer::singleShot (500, this, SLOT(runAutoTest()) ); - break; // allow to finish the initialization sequence - - case STATE_OPEN_INDEX: - if ( m_indexTab ) - m_tabWidget->setCurrentIndex (1); - - m_autoteststate = STATE_SHUTDOWN; - QTimer::singleShot (500, this, SLOT(runAutoTest()) ); - break; - - case STATE_SHUTDOWN: - qApp->quit(); - break; - - default: - break; - } -} -#endif /* defined (ENABLE_AUTOTEST_SUPPORT) */ - - -void KCHMMainWindow::showInStatusBar(const QString & text) -{ - statusBar()->showMessage( text, 2000 ); -} - -void KCHMMainWindow::actionNavigateBack() -{ - currentBrowser()->navigateBack(); -} - -void KCHMMainWindow::actionNavigateForward() -{ - currentBrowser()->navigateForward(); -} - -void KCHMMainWindow::actionNavigateHome() -{ - currentBrowser()->navigateHome(); -} - -void KCHMMainWindow::actionOpenFile() -{ -#if defined (USE_KDE) - QString fn = KFileDialog::getOpenFileName( appConfig.m_lastOpenedDir, i18n("*.chm|Compressed Help Manual (*.chm)"), this); -#else - QString fn = QFileDialog::getOpenFileName( this, - i18n( "Open a chm file"), - appConfig.m_lastOpenedDir, - i18n("Compressed Help Manual (*.chm)"), - 0, - QFileDialog::DontResolveSymlinks ); -#endif - - if ( !fn.isEmpty() ) - loadFile( fn ); - else - { - if ( !m_chmFile ) - exit (1); - - statusBar()->showMessage( i18n("Loading aborted"), 2000 ); - } -} - -void KCHMMainWindow::actionPrint() -{ - currentBrowser()->printCurrentPage(); -} - -void KCHMMainWindow::actionEditCopy() -{ - currentBrowser()->clipCopy(); -} - -void KCHMMainWindow::actionEditSelectAll() -{ - currentBrowser()->clipSelectAll(); -} - -void KCHMMainWindow::actionFindInPage() -{ - m_viewWindowMgr->onActivateFind(); -} - -void KCHMMainWindow::actionChangeSettings() -{ - KCHMSetupDialog dlg ( this ); - - dlg.exec(); -} - - -void KCHMMainWindow::actionExtractCHM() -{ - QStringList files; - -#if defined (USE_KDE) - QString outdir = KFileDialog::getExistingDirectory ( - KUrl(), - this, - i18n("Choose a directory to store CHM content") ); -#else - QString outdir = QFileDialog::getExistingDirectory ( - this, - i18n("Choose a directory to store CHM content"), - QString::null, - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); -#endif - - if ( outdir.isEmpty() ) - return; - - outdir += "/"; - - // Enumerate all the files in archive - if ( !m_chmFile || !m_chmFile->enumerateFiles( &files ) ) - return; - - KQProgressModalDialog progress( i18n("Extracting CHM content"), - i18n("Extracting files..."), - i18n("Abort"), - files.size(), - this ); - - for ( int i = 0; i < files.size(); i++ ) - { - progress.setValue( i ); - - if ( (i % 3) == 0 ) - { - qApp->processEvents(); - - if ( progress.wasCancelled() ) - break; - } - - // Extract the file - QByteArray buf; - - if ( m_chmFile->getFileContentAsBinary( &buf, files[i] ) ) - { - // Split filename to get the list of subdirectories - QStringList dirs = files[i].split( '/' ); - - // Walk through the list of subdirectories, and create them if needed - // dirlevel is used to detect extra .. and prevent overwriting files - // outside the directory (like creating the file images/../../../../../etc/passwd - int i, dirlevel = 0; - QStringList dirlist; - - for ( i = 0; i < dirs.size() - 1; i++ ) - { - // Skip .. which lead too far above - if ( dirs[i] == ".." ) - { - if ( dirlevel > 0 ) - { - dirlevel--; - dirlist.pop_back(); - } - } - else - { - dirlist.push_back( dirs[i] ); - - QDir dir ( outdir + dirlist.join( "/" ) ); - if ( !dir.exists() ) - { - if ( !dir.mkdir( dir.path() ) ) - qWarning( "Could not create subdir %s\n", qPrintable( dir.path() ) ); - } - } - } - - QString filename = outdir + dirlist.join( "/" ) + "/" + dirs[i]; - QFile wf( filename ); - if ( !wf.open( QIODevice::WriteOnly ) ) - { - qWarning( "Could not write file %s\n", qPrintable( filename ) ); - continue; - } - - wf. write( buf ); - wf.close(); - } - else - qWarning( "Could not get file %s\n", qPrintable( files[i] ) ); - } - - progress.setValue( files.size() ); -} - -void KCHMMainWindow::actionAddBookmark() -{ - m_bookmarkWindow->onAddBookmarkPressed(); -} - -void KCHMMainWindow::actionFontSizeIncrease() -{ - currentBrowser()->addZoomFactor( 1 ); -} - -void KCHMMainWindow::actionFontSizeDecrease() -{ - currentBrowser()->addZoomFactor( -1 ); -} - -void KCHMMainWindow::actionViewHTMLsource() -{ - QString text; - - if ( !m_chmFile->getFileContentAsString( &text, currentBrowser()->getOpenedPage() ) || text.isEmpty() ) - return; - - if ( appConfig.m_advUseInternalEditor ) - { - QTextEdit * editor = new QTextEdit ( 0 ); - editor->setPlainText( text ); - editor->setWindowTitle( QString("HTML source of %1") .arg( currentBrowser()->getOpenedPage() )); - editor->resize( 800, 600 ); - editor->show(); - } - else - { - QTemporaryFile * tf = new QTemporaryFile(); - m_tempFileKeeper.append( tf ); - - if ( !tf->open() ) - { - qWarning("Cannot open created QTemporaryFile: something is wrong with your system"); - return; - } - - tf->write( text.toUtf8() ); - tf->seek( 0 ); - - // Run the external editor - QStringList arguments; - arguments.push_back( tf->fileName() ); - - if ( !QProcess::startDetached( appConfig.m_advExternalEditorPath, arguments, "." ) ) - { - QMessageBox::warning( 0, - "Cannot start external editor", - tr("Cannot start external editor %1.\nMake sure the path is absolute!") .arg( appConfig.m_advExternalEditorPath ) ); - delete m_tempFileKeeper.takeLast(); - } - } -} - -void KCHMMainWindow::actionToggleFullScreen() -{ - bool fullscreen = view_Toggle_fullscreen_action->isChecked(); - - if ( fullscreen ) - { - if ( !isFullScreen() ) - { - showFullScreen (); - - // Hiding menu bar disables menu actions. Probably a bug in Qt. - //menuBar()->hide(); - statusBar()->hide(); - } - } - else - { - if ( isFullScreen() ) - { - showNormal(); - menuBar()->show(); - statusBar()->show(); - } - } -} - -void KCHMMainWindow::actionToggleContentsTab() -{ - bool show = view_Toggle_contents_action->isChecked(); - - if ( show ) - m_tabWidget->show(); - else - m_tabWidget->hide(); -} - -void KCHMMainWindow::actionLocateInContentsTab() -{ - // There may be no content tab at all - if ( !m_contentsTab || m_tabContextPage == -1 ) - return; - - // Activate a content tab - m_tabWidget->setCurrentIndex( m_tabContextPage ); - - if ( m_contentsTab ) - { - // Open all the tree items to show current item (if needed) - KCHMIndTocItem * treeitem = m_contentsTab->getTreeItem( currentBrowser()->getOpenedPage() ); - - if ( treeitem ) - { - KCHMIndTocItem * itemparent = treeitem; - - while ( (itemparent = (KCHMIndTocItem*) itemparent->parent()) != 0 ) - itemparent->setExpanded(true); - - m_contentsTab->showItem( treeitem ); - } - else - statusBar()->showMessage( i18n( "Could not locate opened topic in content window"), 2000 ); - } -} - -void KCHMMainWindow::actionNavigatePrevInToc() -{ - if ( !m_contentsTab ) - return; - - // Try to find current list item - KCHMIndTocItem * current = m_contentsTab->getTreeItem( currentBrowser()->getOpenedPage() ); - - if ( !current ) - return; - - QTreeWidgetItemIterator lit( current ); - lit--; - - if ( *lit ) - ::mainWindow->openPage( ((KCHMIndTocItem *) (*lit) )->getUrl(), OPF_CONTENT_TREE | OPF_ADD2HISTORY ); -} - -void KCHMMainWindow::actionNavigateNextInToc() -{ - if ( !m_contentsTab ) - return; - - // Try to find current list item - KCHMIndTocItem * current = m_contentsTab->getTreeItem( currentBrowser()->getOpenedPage() ); - - if ( !current ) - return; - - QTreeWidgetItemIterator lit( current ); - lit++; - - if ( *lit ) - ::mainWindow->openPage( ((KCHMIndTocItem *) (*lit) )->getUrl(), OPF_CONTENT_TREE | OPF_ADD2HISTORY ); -} - -void KCHMMainWindow::actionAboutApp() -{ - QString caption = i18n( "About %1" ) . arg(APP_NAME); - QString text = m_aboutDlgMenuText; - - // It is quite funny that the argument order differs -#if defined (USE_KDE) - KMessageBox::about( this, text, caption ); -#else - QMessageBox::about( this, caption, text ); -#endif -} - -void KCHMMainWindow::actionAboutQt() -{ - QMessageBox::aboutQt( this, APP_NAME); -} - -void KCHMMainWindow::actionSwitchToContentTab() -{ - if ( m_tabContextPage != -1 ) - m_tabWidget->setCurrentIndex( m_tabContextPage ); -} - -void KCHMMainWindow::actionSwitchToIndexTab() -{ - if ( m_tabIndexPage != -1 ) - m_tabWidget->setCurrentIndex( m_tabIndexPage ); -} - -void KCHMMainWindow::actionSwitchToSearchTab() -{ - if ( m_tabSearchPage != -1 ) - m_tabWidget->setCurrentIndex( m_tabSearchPage ); -} - -void KCHMMainWindow::actionSwitchToBookmarkTab() -{ - m_tabWidget->setCurrentIndex( m_tabBookmarkPage ); -} - - -void KCHMMainWindow::setupActions() -{ - // Connect actions to slots - connect( file_Open_action, - SIGNAL( triggered() ), - this, - SLOT( actionOpenFile() ) ); - - connect( file_Print_action, - SIGNAL( triggered() ), - this, - SLOT( actionPrint() ) ); - - connect( edit_Copy_action, - SIGNAL( triggered() ), - this, - SLOT( actionEditCopy() ) ); - - connect( edit_SelectAll_action, - SIGNAL( triggered() ), - this, - SLOT( actionEditSelectAll() ) ); - - connect( edit_FindAction, - SIGNAL( triggered() ), - this, - SLOT( actionFindInPage() ) ); - - connect( file_ExtractCHMAction, - SIGNAL( triggered() ), - this, - SLOT( actionExtractCHM() ) ); - - connect( settings_SettingsAction, - SIGNAL( triggered() ), - this, - SLOT( actionChangeSettings() ) ); - - connect( bookmark_AddAction, - SIGNAL( triggered() ), - this, - SLOT( actionAddBookmark() ) ); - - connect( view_Increase_font_size_action, - SIGNAL( triggered() ), - this, - SLOT( actionFontSizeIncrease() ) ); - - connect( view_Decrease_font_size_action, - SIGNAL( triggered() ), - this, - SLOT( actionFontSizeDecrease() ) ); - - connect( view_View_HTML_source_action, - SIGNAL( triggered() ), - this, - SLOT( actionViewHTMLsource() ) ); - - connect( view_Toggle_fullscreen_action, - SIGNAL( triggered() ), - this, - SLOT( actionToggleFullScreen() ) ); - - connect( view_Toggle_contents_action, - SIGNAL( triggered() ), - this, - SLOT( actionToggleContentsTab() ) ); - - connect( view_Locate_in_contents_action, - SIGNAL( triggered() ), - this, - SLOT( actionLocateInContentsTab() ) ); - - connect( nav_action_Back, - SIGNAL( triggered() ), - this, - SLOT( actionNavigateBack() ) ); - - connect( nav_actionForward, - SIGNAL( triggered() ), - this, - SLOT( actionNavigateForward() ) ); - - connect( nav_actionHome, - SIGNAL( triggered() ), - this, - SLOT( actionNavigateHome() ) ); - - connect( nav_actionPreviousPage, - SIGNAL( triggered() ), - this, - SLOT( actionNavigatePrevInToc() ) ); - - connect( nav_actionNextPageToc, - SIGNAL( triggered() ), - this, - SLOT( actionNavigateNextInToc() ) ); - - // m_bookmarkWindow fills and maintains 'Bookmarks' menu - m_bookmarkWindow->createMenu( menu_Bookmarks ); - - // m_viewWindowMgr fills and maintains 'Window' menu - m_viewWindowMgr->createMenu( this, menu_Windows, action_Close_window ); - - // Close Window goes directly to the window manager - connect( action_Close_window, - SIGNAL( triggered() ), - this, - SLOT( actionNavigateNextInToc() ) ); - - connect( file_exit_action, - SIGNAL( triggered() ), - qApp, - SLOT( closeAllWindows() ) ); - - // Set up recent files - recentFilesInit( menu_File ); - - // Quit - menu_File->addSeparator(); - menu_File->addAction( file_exit_action ); - - QMenu * help = new QMenu( i18n( "&Help"), this ); - help->addAction( i18n( "&About"), this, SLOT( actionAboutApp() ), QKeySequence( "F1" ) ); - help->addAction( i18n( "About &Qt"), this, SLOT( actionAboutQt() ) ); - help->addSeparator(); - - // "What's this" action - QAction * whatsthis = QWhatsThis::createAction( this ); - help->addAction( whatsthis ); - viewToolbar->addAction( whatsthis ); - - menuBar()->addMenu( help ); - recentFilesUpdate(); - - // Tab switching actions - (void) new QShortcut( QKeySequence( i18n("Ctrl+1") ), - this, - SLOT( actionSwitchToContentTab() ), - SLOT( actionSwitchToContentTab() ), - Qt::ApplicationShortcut ); - - (void) new QShortcut( QKeySequence( i18n("Ctrl+2") ), - this, - SLOT( actionSwitchToIndexTab() ), - SLOT( actionSwitchToIndexTab() ), - Qt::ApplicationShortcut ); - - (void) new QShortcut( QKeySequence( i18n("Ctrl+3") ), - this, - SLOT( actionSwitchToSearchTab() ), - SLOT( actionSwitchToSearchTab() ), - Qt::ApplicationShortcut ); - - (void) new QShortcut( QKeySequence( i18n("Ctrl+4") ), - this, - SLOT( actionSwitchToBookmarkTab() ), - SLOT( actionSwitchToBookmarkTab() ), - Qt::ApplicationShortcut ); - - // Find (/) global shortcut - (void) new QShortcut( QKeySequence( i18n("/") ), - m_viewWindowMgr, - SLOT( onActivateFind() ), - SLOT( onActivateFind() ), - Qt::ApplicationShortcut ); - - // Find next global shortcut - (void) new QShortcut( QKeySequence( i18n("F3") ), - m_viewWindowMgr, - SLOT( onFindNext() ), - SLOT( onFindNext() ), - Qt::ApplicationShortcut ); - - // Open next page in TOC global shortcut - (void) new QShortcut( QKeySequence( i18n("Ctrl+Right") ), - this, - SLOT( actionNavigateNextInToc() ), - SLOT( actionNavigateNextInToc() ), - Qt::ApplicationShortcut ); - - // Open next page in TOC global shortcut - (void) new QShortcut( QKeySequence( i18n("Ctrl+Left") ), - this, - SLOT( actionNavigatePrevInToc() ), - SLOT( actionNavigatePrevInToc() ), - Qt::ApplicationShortcut ); - - // Context menu - m_contextMenu = new QMenu( this ); - - m_contextMenu->addAction ( "&Open this link in a new tab", - this, - SLOT( onOpenPageInNewTab() ), - QKeySequence( "Shift+Enter" ) ); - - m_contextMenu->addAction ( "&Open this link in a new background tab", - this, - SLOT( onOpenPageInNewBackgroundTab() ), - QKeySequence( "Ctrl+Enter" ) ); -} - - -void KCHMMainWindow::navSetBackEnabled(bool enabled) -{ - nav_action_Back->setEnabled( enabled ); -} - -void KCHMMainWindow::navSetForwardEnabled(bool enabled) -{ - nav_actionForward->setEnabled( enabled ); -} - - -void KCHMMainWindow::recentFilesInit( QMenu * menu ) -{ - m_numOfRecentFiles = appConfig.m_numOfRecentFiles; - - if ( !m_recentFiles.isEmpty() ) - { - for ( int i = 0; i < m_recentFiles.size(); i++ ) - delete m_recentFiles[i]; - - m_recentFiles.clear(); - } - - m_recentFiles.resize( m_numOfRecentFiles ); - - // Initialize the recent file actions - for ( int i = 0; i < m_numOfRecentFiles; ++i ) - { - m_recentFiles[i] = new QAction( this ); - m_recentFiles[i]->setVisible( false ); - connect( m_recentFiles[i], SIGNAL( triggered() ), this, SLOT( actionOpenRecentFile()) ); - } - - // Add the separator, and actions - m_recentFileSeparator = menu->addSeparator(); - - for ( int i = 0; i < m_numOfRecentFiles; ++i ) - menu->addAction( m_recentFiles[i] ); - -} - -void KCHMMainWindow::recentFilesUpdate() -{ - // Set the actions - for ( int i = 0; i < m_numOfRecentFiles; ++i ) - { - if ( i < appConfig.m_recentFiles.size() ) - { - QString text = tr("&%1 %2").arg(i + 1).arg( QFileInfo( appConfig.m_recentFiles[i] ).fileName() ); - m_recentFiles[i]->setText( text ); - m_recentFiles[i]->setData( appConfig.m_recentFiles[i] ); - m_recentFiles[i]->setVisible( true ); - } - else - m_recentFiles[i]->setVisible( false ); - } - - m_recentFileSeparator->setVisible( !appConfig.m_recentFiles.isEmpty() ); -} - -void KCHMMainWindow::actionOpenRecentFile() -{ - QAction *action = qobject_cast(sender()); - - if ( action ) - loadFile( action->data().toString() ); -} - -void KCHMMainWindow::setupLangEncodingMenu() -{ - // Create the language selection menu. - QMenu * encodings = new QMenu( this ); - - // Create the action group - m_encodingActions = new QActionGroup( this ); - - // Add the codepage entries - const LCHMTextEncoding * enctable = LCHMFileImpl::getTextEncodingTable(); - - for ( int idx = 0; (enctable + idx)->family; idx++ ) - { - const LCHMTextEncoding * enc = enctable + idx; - - QAction * action = new QAction( this ); - - QString text = i18n("%1 ( %2 )") .arg( enc->family) .arg( enc->qtcodec ); - action->setText( text ); - action->setData( qVariantFromValue( (void*) enc ) ); - action->setCheckable( true ); - - // Add to the action group, so only one is checkable - m_encodingActions->addAction( action ); - - // Add to the menu - encodings->addAction( action ); - } - - // Set up the Select Codepage action - view_Set_encoding_action->setMenu( encodings ); - - // Connect the action group signal - connect( m_encodingActions, - SIGNAL( triggered ( QAction * ) ), - this, - SLOT( actionEncodingChanged( QAction * ) ) ); -} - - -void KCHMMainWindow::actionEncodingChanged( QAction * action ) -{ - const LCHMTextEncoding * enc = (const LCHMTextEncoding *) action->data().value< void* > (); - setTextEncoding( enc ); -} - - -QMenu * KCHMMainWindow::tabItemsContextMenu() -{ - return m_contextMenu; -} - -void KCHMMainWindow::setupPopupMenu( QMenu * menu ) -{ - menu->addAction( action_Close_window ); - menu->addSeparator(); - menu->addAction( nav_action_Back ); - menu->addAction( nav_actionForward ); - menu->addAction( nav_actionHome ); - menu->addSeparator(); - menu->addAction( nav_actionPreviousPage ); - menu->addAction( nav_actionNextPageToc ); - menu->addSeparator(); - menu->addAction( view_Increase_font_size_action ); - menu->addAction( view_Decrease_font_size_action ); - menu->addSeparator(); - menu->addAction( edit_Copy_action ); - menu->addAction( edit_FindAction ); -} diff -Nru kchmviewer-4.1/src/kchmmainwindow.h kchmviewer-5.1/src/kchmmainwindow.h --- kchmviewer-4.1/src/kchmmainwindow.h 2009-07-20 04:37:26.000000000 +0100 +++ kchmviewer-5.1/src/kchmmainwindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,216 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMMAINWINDOW_H -#define KCHMMAINWINDOW_H - -#include "libchmfile.h" - -#include "kde-qt.h" -#include "kchmviewwindow.h" - -#include "ui_window_main.h" - -#define ENABLE_AUTOTEST_SUPPORT - -//! OpenPage extra flags, specifying extra behavior - - -//! Those events could be sent to main window to do useful things. See handleUserEvents() -class KCHMUserEvent : public QEvent -{ - public: - KCHMUserEvent( const QString& action, const QStringList& args = QStringList()) - : QEvent( QEvent::User ), m_action(action), m_args(args) {}; - - QString m_action; - QStringList m_args; -}; - - - -class KCHMMainWindow : public QMainWindow, public Ui::MainWindow -{ - Q_OBJECT - - public: - // "Open page" parameter flags - enum - { - OPF_CONTENT_TREE = 1 << 0, //! Locate this page in the content tree - OPF_ADD2HISTORY = 1 << 1, //! Add the previous page into the history - OPF_NEW_TAB = 1 << 2, //! Open the page in a new tab - OPF_BACKGROUND = 1 << 3 //! Open the page in a new tab in background - }; - - public: - KCHMMainWindow(); - ~KCHMMainWindow(); - - bool openPage ( const QString &url, unsigned int flags = OPF_CONTENT_TREE ); - - LCHMFile * chmFile() const { return m_chmFile; } - const QString& getOpenedFileName () { return m_chmFilename; } - const QString& getOpenedFileBaseName () { return m_chmFileBasename; } - - KCHMViewWindow * currentBrowser() const; - KCHMContentsWindow * contentsWindow() const { return m_contentsTab; } - KCHMSettings * currentSettings() const { return m_currentSettings; } - KCHMViewWindowMgr* viewWindowMgr() const { return m_viewWindowMgr; } - KCHMSearchWindow * searchWindow() const { return m_searchTab; } - - void showInStatusBar (const QString& text); - void setTextEncoding (const LCHMTextEncoding * enc); - QMenu * tabItemsContextMenu(); - - // Called from WindowMgr when another browser tab is activated - void browserChanged( KCHMViewWindow * newbrowser ); - - // Adds some main window actions to the provided popup menu - void setupPopupMenu( QMenu * menu ); - - public slots: - // Navigation toolbar icons - void navSetBackEnabled( bool enabled ); - void navSetForwardEnabled( bool enabled ); - - void onOpenPageInNewTab(); - void onOpenPageInNewBackgroundTab(); - - // Actions - void actionOpenFile(); - void actionPrint(); - void actionEditCopy(); - void actionEditSelectAll(); - void actionFindInPage(); - void actionExtractCHM(); - void actionChangeSettings(); - void actionAddBookmark(); - void actionFontSizeIncrease(); - void actionFontSizeDecrease(); - void actionViewHTMLsource(); - void actionToggleFullScreen(); - void actionToggleContentsTab(); - void actionLocateInContentsTab(); - - void actionNavigateBack(); - void actionNavigateForward(); - void actionNavigateHome(); - void actionNavigatePrevInToc(); - void actionNavigateNextInToc(); - - void actionAboutApp(); - void actionAboutQt(); - - void actionSwitchToContentTab(); - void actionSwitchToIndexTab(); - void actionSwitchToSearchTab(); - void actionSwitchToBookmarkTab(); - - void actionOpenRecentFile(); - void actionEncodingChanged( QAction * action ); - - // Link activation. MainWindow decides whether we should follow this link or not - // by setting up follow_link appropriately. - void activateLink( const QString & link, bool& follow_link ); - - protected slots: - // Called from the timer in main constructor - void firstShow(); - - protected: - // Reimplemented functions - void closeEvent ( QCloseEvent * e ); - bool event ( QEvent * e ); - - private: - bool parseCmdLineArgs(); - void setupSignals (); - void setupActions(); - void setupLangEncodingMenu(); - - bool loadFile( const QString &fileName, bool call_open_page = true ); - void closeFile(); - void refreshCurrentBrowser(); - - void showOrHideContextWindow( int tabindex ); - void showOrHideIndexWindow( int tabindex ); - void showOrHideSearchWindow( int tabindex ); - - // Creates and initializes the recent files array, and adds the - // entries logic to the menu - void recentFilesInit( QMenu * menu ); - void recentFilesUpdate(); - - bool handleUserEvent( const KCHMUserEvent * event ); - void locateInContentTree( const QString& url ); - - private: - QString m_chmFilename; - QString m_chmFileBasename; - QString m_aboutDlgMenuText; // to show in KDE or Qt about dialogs - - KCHMViewWindowMgr * m_viewWindowMgr; - KCHMIndexWindow * m_indexTab; - KCHMSearchWindow * m_searchTab; - KCHMBookmarkWindow * m_bookmarkWindow; - KCHMContentsWindow * m_contentsTab; - - KQTabWidget * m_tabWidget; - QSplitter * m_windowSplitter; - - KCHMSettings * m_currentSettings; - LCHMFile * m_chmFile; - - int m_tabContextPage; - int m_tabIndexPage; - int m_tabSearchPage; - int m_tabBookmarkPage; - - QList m_tempFileKeeper; - - int m_numOfRecentFiles; - QVector m_recentFiles; - QAction * m_recentFileSeparator; - - QActionGroup * m_encodingActions; - QMenu * m_contextMenu; - -#if defined (ENABLE_AUTOTEST_SUPPORT) - enum auto_test_state_t - { - STATE_OFF, - STATE_INITIAL, - STATE_OPEN_INDEX, - STATE_SHUTDOWN - }; - - auto_test_state_t m_autoteststate; - - private slots: - void runAutoTest(); -#endif /* defined (ENABLE_AUTOTEST_SUPPORT) */ - -}; - -extern KCHMMainWindow * mainWindow; - -#endif // KCHMMAINWINDOW_H diff -Nru kchmviewer-4.1/src/kchmsearchwindow.cpp kchmviewer-5.1/src/kchmsearchwindow.cpp --- kchmviewer-4.1/src/kchmsearchwindow.cpp 2009-07-20 04:37:24.000000000 +0100 +++ kchmviewer-5.1/src/kchmsearchwindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,311 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include - -#include "libchmfile.h" - -#include "kchmsearchwindow.h" -#include "kchmmainwindow.h" -#include "kchmconfig.h" -#include "kchmtreeviewitem.h" - - -class KCMSearchTreeViewItem : public QTreeWidgetItem -{ - public: - KCMSearchTreeViewItem( QTreeWidget * tree, const QString& name, const QString& url ) - : QTreeWidgetItem( tree ), m_name( name ), m_url( url ) {}; - - QString getUrl() const { return m_url; } - - protected: - // Overriden members - int columnCount () const { return 2; } - - // Overriden member - QVariant data ( int column, int role ) const - { - switch( role ) - { - // Item name - case Qt::DisplayRole: - case Qt::ToolTipRole: - case Qt::WhatsThisRole: - if ( column == 0 ) - return m_name; - else - return m_url; - } - - return QVariant(); - } - - private: - QString m_name; - QString m_url; -}; - - - -KCHMSearchWindow::KCHMSearchWindow( QWidget * parent ) - : QWidget( parent ), Ui::TabSearch() -{ - // UIC stuff - setupUi( this ); - - // Clickable Help label - connect( lblHelp, - SIGNAL( linkActivated( const QString & ) ), - this, - SLOT( onHelpClicked(const QString & ) ) ); - - // Go Button - connect( btnGo, - SIGNAL( clicked () ), - this, - SLOT( onReturnPressed() ) ); - - // Pressing 'Return' in the combo box line edit - connect( searchBox->lineEdit(), - SIGNAL( returnPressed() ), - this, - SLOT( onReturnPressed() ) ); - - // Clicking on tree element - connect( tree, - SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), - this, - SLOT( onDoubleClicked( QTreeWidgetItem *, int ) ) ); - - // Activate custom context menu, and connect it - tree->setContextMenuPolicy( Qt::CustomContextMenu ); - connect( tree, - SIGNAL( customContextMenuRequested ( const QPoint & ) ), - this, - SLOT( onContextMenuRequested( const QPoint & ) ) ); - - searchBox->setFocus(); - - m_contextMenu = 0; - m_genIndexProgress = 0; - m_searchEngineInitDone = false; - - m_searchEngine = new LCHMSearchEngine(); - connect( m_searchEngine, SIGNAL( progressStep( int, const QString& ) ), this, SLOT( onProgressStep( int, const QString& ) ) ); -} - - -void KCHMSearchWindow::invalidate( ) -{ - tree->clear(); - searchBox->clear(); - searchBox->lineEdit()->clear(); - - delete m_genIndexProgress; - m_genIndexProgress = 0; - - m_searchEngineInitDone = false; -} - - -void KCHMSearchWindow::onReturnPressed( ) -{ - QStringList results; - QString text = searchBox->lineEdit()->text(); - - if ( text.isEmpty() ) - return; - - tree->clear(); - - if ( searchQuery( text, &results ) ) - { - if ( !results.empty() ) - { - for ( int i = 0; i < results.size(); i++ ) - { - new KCMSearchTreeViewItem ( tree, - ::mainWindow->chmFile()->getTopicByUrl( results[i] ), - results[i] ); - } - - ::mainWindow->showInStatusBar( i18n( "Search returned %1 result(s)" ) . arg(results.size()) ); - } - else - ::mainWindow->showInStatusBar( i18n( "Search returned no results") ); - } - else - ::mainWindow->showInStatusBar( i18n( "Search failed") ); -} - - -void KCHMSearchWindow::onDoubleClicked( QTreeWidgetItem * item, int ) -{ - if ( !item ) - return; - - KCMSearchTreeViewItem * treeitem = (KCMSearchTreeViewItem *) item; - ::mainWindow->openPage( treeitem->getUrl(), KCHMMainWindow::OPF_ADD2HISTORY ); -} - - -void KCHMSearchWindow::restoreSettings( const KCHMSettings::search_saved_settings_t & settings ) -{ - for ( int i = 0; i < settings.size(); i++ ) - searchBox->addItem (settings[i]); -} - - -void KCHMSearchWindow::saveSettings( KCHMSettings::search_saved_settings_t & settings ) -{ - settings.clear(); - - for ( int i = 0; i < searchBox->count(); i++ ) - settings.push_back( searchBox->itemText(i) ); -} - - -void KCHMSearchWindow::onHelpClicked( const QString & ) -{ - QWhatsThis::showText ( mapToGlobal( lblHelp->pos() ), - i18n( "

The improved search engine allows you to search for a word, symbol or phrase, which is set of words and symbols included in quotes. Only the documents which include all the terms speficide in th search query are shown; no prefixes needed.

Unlike MS CHM internal search index, my improved search engine indexes everything, including special symbols. Therefore it is possible to search (and find!) for something like $q = new ChmFile();. This search also fully supports Unicode, which means that you can search in non-English documents.

If you want to search for a quote symbol, use quotation mark instead. The engine treats a quote and a quotation mark as the same symbol, which allows to use them in phrases.") ); -} - - -bool KCHMSearchWindow::initSearchEngine( ) -{ - KCHMShowWaitCursor waitcursor; - - QString indexfile = ::mainWindow->currentSettings()->searchIndexFile(); - - // First try to read the index if exists - QFile file( indexfile ); - - if ( file.open( QIODevice::ReadOnly ) ) - { - QDataStream stream( &file ); - - ::mainWindow->statusBar()->showMessage( i18n( "Reading dictionary..." ) ); - qApp->processEvents( QEventLoop::ExcludeUserInputEvents ); - - if ( m_searchEngine->loadIndex( stream ) ) - { - m_searchEngineInitDone = true; - return true; - } - } - - // So the index cannot be read or does not exist. Create a new one. - - // Show the user what we gonna do - m_genIndexProgress = new QProgressDialog( this ); - m_genIndexProgress->setWindowTitle( i18n( "Generating search index..." ) ); - m_genIndexProgress->setLabelText( i18n( "Generating search index..." ) ); - m_genIndexProgress->setMaximum( 100 ); - m_genIndexProgress->reset(); - m_genIndexProgress->show(); - - ::mainWindow->statusBar()->showMessage( tr( "Generating search index..." ) ); - - // Show 'em - qApp->processEvents( QEventLoop::ExcludeUserInputEvents ); - - // Since we gonna save it, reopen the file - file.close(); - - if ( !file.open( QIODevice::WriteOnly ) ) - { - QMessageBox::critical( 0, "Cannot save index", tr("The index cannot be saved into file %1") .arg( file.fileName() ) ); - return false; - } - - // Run the generation - QDataStream stream( &file ); - - m_searchEngine->generateIndex( ::mainWindow->chmFile(), stream ); - - delete m_genIndexProgress; - m_genIndexProgress = 0; - - if ( m_searchEngine->hasIndex() ) - { - m_searchEngineInitDone = true; - return true; - } - - m_searchEngineInitDone = false; - return false; -} - - -void KCHMSearchWindow::execSearchQueryInGui( const QString & query ) -{ - searchBox->lineEdit()->setText( query ); - onReturnPressed(); -} - - -bool KCHMSearchWindow::searchQuery( const QString & query, QStringList * results ) -{ - if ( !m_searchEngineInitDone ) - { - if ( !initSearchEngine() ) - return false; - } - - if ( !m_searchEngine->hasIndex() ) - { - QMessageBox::information ( this, "No index present", "The index is not present" ); - return false; - } - - if ( query.isEmpty() ) - return false; - - KCHMShowWaitCursor waitcursor; - bool result; - - result = m_searchEngine->searchQuery( query, results, ::mainWindow->chmFile() ); - return result; -} - - -void KCHMSearchWindow::onContextMenuRequested( const QPoint & point ) -{ - KCMSearchTreeViewItem * treeitem = (KCMSearchTreeViewItem *) tree->itemAt( point ); - - if( treeitem ) - { - ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); - ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); - } -} - - -void KCHMSearchWindow::onProgressStep(int value, const QString & stepName) -{ - if ( m_genIndexProgress ) - { - m_genIndexProgress->setLabelText( stepName ); - m_genIndexProgress->setValue( value ); - } -} diff -Nru kchmviewer-4.1/src/kchmsearchwindow.h kchmviewer-5.1/src/kchmsearchwindow.h --- kchmviewer-4.1/src/kchmsearchwindow.h 2009-07-20 04:37:22.000000000 +0100 +++ kchmviewer-5.1/src/kchmsearchwindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMSEARCHWINDOW_H -#define KCHMSEARCHWINDOW_H - -#include "kde-qt.h" -#include "kchmsettings.h" -#include "ui_tab_search.h" - -#include "libchmsearchengine.h" - - -class KCHMSearchWindow : public QWidget, public Ui::TabSearch -{ - Q_OBJECT - public: - KCHMSearchWindow ( QWidget * parent = 0 ); - - void invalidate(); - void restoreSettings (const KCHMSettings::search_saved_settings_t& settings); - void saveSettings( KCHMSettings::search_saved_settings_t& settings ); - void execSearchQueryInGui( const QString& query ); - bool searchQuery( const QString& query, QStringList * results ); - - private slots: - void onContextMenuRequested ( const QPoint &point ); - void onHelpClicked( const QString & ); - void onReturnPressed (); - void onDoubleClicked( QTreeWidgetItem * item, int ); - - // For index generation - void onProgressStep( int value, const QString& stepName ); - - private: - bool initSearchEngine(); - - private: - QMenu * m_contextMenu; - LCHMSearchEngine* m_searchEngine; - bool m_searchEngineInitDone; - - // For index generation - QProgressDialog * m_genIndexProgress; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmsettings.cpp kchmviewer-5.1/src/kchmsettings.cpp --- kchmviewer-4.1/src/kchmsettings.cpp 2009-07-20 04:37:19.000000000 +0100 +++ kchmviewer-5.1/src/kchmsettings.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,305 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include -#include - -#include "kchmsettings.h" -#include "kchmconfig.h" - -static qint32 SETTINGS_MAGIC = 0xD8AB4E76; -static qint32 SETTINGS_VERSION = 4; - -/* - * The order is important! - * To be compatible with next versions, you may add items ONLY before the MARKER_END! - */ -enum marker_t -{ - MARKER_FILESIZE = 1, - MARKER_FILETIME, - - MARKER_ACTIVETABSYSTEM, - MARKER_ACTIVETABWINDOW, - MARKER_ACTIVEENCODING, - MARKER_SEARCHHISTORY, - MARKER_WINDOW_SIZE, - - MARKER_BOOKMARKS, - MARKER_VIEWINDOWS, - - MARKER_CONTENTSDATA, - MARKER_INDEXDATA, - - MARKER_ACTIVEENCODINGNAME, - - // This should be the last - MARKER_END = 0x7FFF -}; - -// Helpers for serialization of SavedBookmark through QDataStream -static inline QDataStream& operator<< ( QDataStream& s, const KCHMSettings::SavedBookmark& b ) -{ - s << b.name; - s << b.url; - s << b.scroll_y; - return s; -} - -static inline QDataStream& operator>> ( QDataStream& s, KCHMSettings::SavedBookmark& b ) -{ - s >> b.name; - s >> b.url; - s >> b.scroll_y; - return s; -} - -// Helpers for serialization of SavedViewWindow through QDataStream -static inline QDataStream& operator<< ( QDataStream& s, const KCHMSettings::SavedViewWindow& b ) -{ - // Store the version first. Later we can increase it when adding new members. - s << 1; - s << b.url; - s << b.scroll_y; - s << b.zoom; - return s; -} - -static inline QDataStream& operator>> ( QDataStream& s, KCHMSettings::SavedViewWindow& b ) -{ - qint32 version; - - s >> version; - s >> b.url; - s >> b.scroll_y; - s >> b.zoom; - return s; -} - - -KCHMSettings::KCHMSettings( ) -{ - m_activetabsystem = 0; - m_activetabwindow = 0; - m_activeEncoding = "CP1252"; - - m_window_size_x = 700; - m_window_size_y = 500; - m_window_size_splitter = 200; -} - - -bool KCHMSettings::loadSettings( const QString & filename ) -{ - m_activetabsystem = 0; - m_activetabwindow = 0; - m_activeEncoding = "CP1252"; - - m_searchhistory.clear(); - m_bookmarks.clear(); - m_viewwindows.clear(); - - QFileInfo finfo ( filename ); - - m_settingsFile = QString::null; - m_searchIndex = QString::null; - - if ( !finfo.size() ) - return false; - - // Init those params, as they'll be used during save the first time even if the file is not here - m_currentfilesize = finfo.size(); - m_currentfiledate = finfo.lastModified().toTime_t(); - - getFilenames( filename, &m_settingsFile, &m_searchIndex ); - - QFile file( m_settingsFile ); - - if ( !file.open (QIODevice::ReadOnly) ) - return false; // it's ok, file may not exist - - QDataStream stream (&file); - - // Read and check header - qint32 data; - bool complete_read = false; - stream >> data; // magic - - if ( data != SETTINGS_MAGIC ) - { - qWarning ("file %s has bad magic value, ignoring it.", qPrintable( file.fileName()) ); - return false; - } - - stream >> data; // version - if ( data > SETTINGS_VERSION ) - { - qWarning ("file %s has unsupported data version %d, ignoring it.", qPrintable( file.fileName()), data); - return false; - } - - // Read everything by marker - while ( 1 ) - { - stream >> data; // marker - if ( data == MARKER_END ) - { - complete_read = true; - break; - } - - switch (data) - { - case MARKER_FILESIZE: - stream >> m_currentfilesize; - if ( m_currentfilesize != finfo.size() ) - { - m_currentfilesize = finfo.size(); - return false; - } - break; - - case MARKER_FILETIME: - stream >> m_currentfiledate; - if ( m_currentfiledate != finfo.lastModified().toTime_t() ) - { - m_currentfiledate = finfo.lastModified().toTime_t(); - return false; - } - break; - - case MARKER_ACTIVETABSYSTEM: - stream >> m_activetabsystem; - break; - - case MARKER_ACTIVETABWINDOW: - stream >> m_activetabwindow; - break; - - // Not used anymore - case MARKER_ACTIVEENCODING: - stream >> data; - break; - - case MARKER_ACTIVEENCODINGNAME: - stream >> m_activeEncoding; - break; - - case MARKER_WINDOW_SIZE: - stream >> m_window_size_x; - stream >> m_window_size_y; - stream >> m_window_size_splitter; - break; - - case MARKER_SEARCHHISTORY: - stream >> m_searchhistory; - break; - - case MARKER_BOOKMARKS: - stream >> m_bookmarks; - break; - - case MARKER_VIEWINDOWS: - stream >> m_viewwindows; - break; - } - } - - return complete_read; -} - - -bool KCHMSettings::saveSettings( ) -{ - QFile file( m_settingsFile ); - if ( !file.open (QIODevice::WriteOnly) ) - { - qWarning ("Could not write settings into file %s: %s", - qPrintable( file.fileName()), - qPrintable( file.errorString() )); - return false; - } - - QDataStream stream (&file); - - // Save header - stream << SETTINGS_MAGIC; - stream << SETTINGS_VERSION; - - // Save size and last-modified - stream << MARKER_FILESIZE; - stream << m_currentfilesize; - stream << MARKER_FILETIME; - stream << m_currentfiledate; - - // Save generic settings - stream << MARKER_ACTIVETABSYSTEM; - stream << m_activetabsystem; - - // Save generic settings - stream << MARKER_ACTIVETABWINDOW; - stream << m_activetabwindow; - - stream << MARKER_ACTIVEENCODINGNAME; - stream << m_activeEncoding; - - // Save search history vector - stream << MARKER_SEARCHHISTORY; - stream << m_searchhistory; - - // Save window size and splitter position - stream << MARKER_WINDOW_SIZE; - stream << m_window_size_x; - stream << m_window_size_y; - stream << m_window_size_splitter; - - stream << MARKER_BOOKMARKS; - stream << m_bookmarks; - - stream << MARKER_VIEWINDOWS; - stream << m_viewwindows; - - stream << MARKER_END; - return true; -} - - -void KCHMSettings::removeSettings( const QString & filename ) -{ - QString settingsfile, idxfile; - - getFilenames( filename, &settingsfile, &idxfile ); - - QFile::remove( settingsfile ); - QFile::remove( idxfile ); -} - - -void KCHMSettings::getFilenames(const QString & helpfilename, QString * settingsfile, QString * indexfile ) -{ - QFileInfo finfo ( helpfilename ); - QString prefix = appConfig.m_datapath + "/" + finfo.baseName(); - - *settingsfile = prefix + ".kchmviewer"; - *indexfile = prefix + ".idx"; -} diff -Nru kchmviewer-4.1/src/kchmsettings.h kchmviewer-5.1/src/kchmsettings.h --- kchmviewer-4.1/src/kchmsettings.h 2009-07-20 04:37:17.000000000 +0100 +++ kchmviewer-5.1/src/kchmsettings.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMSETTINGS_H -#define KCHMSETTINGS_H - -#include -#include - - -class KCHMSettings -{ - public: - KCHMSettings (); - - bool loadSettings (const QString& filename); - bool saveSettings ( ); - void removeSettings ( const QString& filename ); - - QString searchIndexFile() const { return m_searchIndex; } - - class SavedBookmark - { - public: - SavedBookmark() { scroll_y = 0; } - SavedBookmark ( const QString& n, const QString& u, int y) : name(n), url(u), scroll_y(y) {}; - - QString name; - QString url; - int scroll_y; - }; - - class SavedViewWindow - { - public: - SavedViewWindow() { scroll_y = 0; zoom = 0; } - SavedViewWindow ( const QString& u, int y, int z) : url(u), scroll_y(y), zoom(z) {}; - - QString url; - int scroll_y; - int zoom; - }; - - typedef QList search_saved_settings_t; - typedef QList bookmark_saved_settings_t; - typedef QList viewindow_saved_settings_t; - - int m_window_size_x; - int m_window_size_y; - int m_window_size_splitter; - int m_activetabsystem; - int m_activetabwindow; - QString m_activeEncoding; - search_saved_settings_t m_searchhistory; - bookmark_saved_settings_t m_bookmarks; - viewindow_saved_settings_t m_viewwindows; - - private: - void getFilenames(const QString & helpfilename, QString * settingsfile, QString * indexfile ); - - unsigned int m_currentfilesize; - unsigned int m_currentfiledate; - QString m_settingsFile; - QString m_searchIndex; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmsetupdialog.cpp kchmviewer-5.1/src/kchmsetupdialog.cpp --- kchmviewer-4.1/src/kchmsetupdialog.cpp 2009-07-20 04:37:15.000000000 +0100 +++ kchmviewer-5.1/src/kchmsetupdialog.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,202 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "kde-qt.h" -#include "kchmconfig.h" -#include "kchmsetupdialog.h" -#include "version.h" - - -KCHMSetupDialog::KCHMSetupDialog(QWidget *parent) - : QDialog(parent), Ui::DialogSetup() -{ - setupUi( this ); - - connect( btnBrowse, SIGNAL( clicked() ), this, SLOT( browseExternalEditor() ) ); - - // Set up the parameters - m_radioOnBeginOpenDialog->setChecked ( !appConfig.m_LoadLatestFileOnStartup ); - m_radioOnBeginOpenLast->setChecked ( appConfig.m_LoadLatestFileOnStartup ); - m_historySize->setValue ( appConfig.m_numOfRecentFiles ); - m_rememberHistoryInfo->setChecked ( appConfig.m_HistoryStoreExtra ); - - m_radioExtLinkOpenAlways->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_ALWAYS_OPEN ); - m_radioExtLinkAsk->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_ASK_USER ); - m_radioExtLinkOpenNever->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_DONT_OPEN ); - - m_radioNewChmOpenAlways->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_ALWAYS_OPEN ); - m_radioNewChmAsk->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_ASK_USER ); - m_radioNewChmOpenNever->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_DONT_OPEN ); - -#if !defined (USE_KDE) - m_radioUseKHTMLPart->setEnabled ( false ); -#endif - -#if !defined (QT_WEBKIT_LIB) - m_radioUseQtWebkit->setEnabled ( false ); -#endif - - switch ( appConfig.m_usedBrowser ) - { - default: - m_radioUseQtextBrowser->setChecked ( true ); - break; - -#if defined (USE_KDE) - case KCHMConfig::BROWSER_KHTMLPART: - m_radioUseKHTMLPart->setChecked( true ); - break; -#endif - -#if defined (QT_WEBKIT_LIB) - case KCHMConfig::BROWSER_QTWEBKIT: - m_radioUseQtWebkit->setChecked( true ); - break; -#endif - } - - m_enableJS->setChecked ( appConfig.m_kdeEnableJS ); - m_enablePlugins->setChecked ( appConfig.m_kdeEnablePlugins ); - m_enableJava->setChecked ( appConfig.m_kdeEnableJava ); - m_enableRefresh->setChecked ( appConfig.m_kdeEnableRefresh ); - - m_advExternalProgramName->setText( appConfig.m_advExternalEditorPath ); - m_advViewSourceExternal->setChecked ( !appConfig.m_advUseInternalEditor ); - m_advViewSourceInternal->setChecked ( appConfig.m_advUseInternalEditor ); - - m_numOfRecentFiles = appConfig.m_numOfRecentFiles; - - boxAutodetectEncoding->setChecked( appConfig.m_advAutodetectEncoding ); - boxLayoutDirectionRL->setChecked( appConfig.m_advLayoutDirectionRL ); -} - -KCHMSetupDialog::~KCHMSetupDialog() -{ -} - - -void KCHMSetupDialog::accept() -{ - appConfig.m_LoadLatestFileOnStartup = m_radioOnBeginOpenLast->isChecked(); - appConfig.m_numOfRecentFiles = m_historySize->value(); - appConfig.m_HistoryStoreExtra = m_rememberHistoryInfo->isChecked(); - - if ( m_radioExtLinkOpenAlways->isChecked () ) - appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_ALWAYS_OPEN; - else if ( m_radioExtLinkAsk->isChecked () ) - appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_ASK_USER; - else - appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_DONT_OPEN; - - if ( m_radioNewChmOpenAlways->isChecked () ) - appConfig.m_onNewChmClick = KCHMConfig::ACTION_ALWAYS_OPEN; - else if ( m_radioNewChmAsk->isChecked () ) - appConfig.m_onNewChmClick = KCHMConfig::ACTION_ASK_USER; - else - appConfig.m_onNewChmClick = KCHMConfig::ACTION_DONT_OPEN; - - // Check the changes - bool need_restart = false; - - if ( appConfig.m_kdeEnableJS != m_enableJS->isChecked() ) - { - need_restart = true; - appConfig.m_kdeEnableJS = m_enableJS->isChecked(); - } - - if ( appConfig.m_kdeEnablePlugins != m_enablePlugins->isChecked() ) - { - need_restart = true; - appConfig.m_kdeEnablePlugins = m_enablePlugins->isChecked(); - } - - if ( appConfig.m_kdeEnableJava != m_enableJava->isChecked() ) - { - need_restart = true; - appConfig.m_kdeEnableJava = m_enableJava->isChecked(); - } - - if ( appConfig.m_kdeEnableRefresh != m_enableRefresh->isChecked() ) - { - need_restart = true; - appConfig.m_kdeEnableRefresh = m_enableRefresh->isChecked(); - } - - int new_browser = KCHMConfig::BROWSER_QTEXTBROWSER; - - if ( m_radioUseKHTMLPart->isChecked() ) - new_browser = KCHMConfig::BROWSER_KHTMLPART; - else if ( m_radioUseQtWebkit->isChecked() ) - new_browser = KCHMConfig::BROWSER_QTWEBKIT; - - if ( new_browser != appConfig.m_usedBrowser ) - { - need_restart = true; - appConfig.m_usedBrowser = new_browser; - } - - appConfig.m_advExternalEditorPath = m_advExternalProgramName->text(); - appConfig.m_advUseInternalEditor = m_advViewSourceExternal->isChecked(); - appConfig.m_advUseInternalEditor = m_advViewSourceInternal->isChecked(); - - if ( appConfig.m_numOfRecentFiles != m_numOfRecentFiles ) - need_restart = true; - - // Autodetect encoding - if ( appConfig.m_advAutodetectEncoding != boxAutodetectEncoding->isChecked() ) - need_restart = true; - - appConfig.m_advAutodetectEncoding = boxAutodetectEncoding->isChecked(); - - // Layout direction management - bool layout_rl = boxLayoutDirectionRL->isChecked(); - - if ( layout_rl != appConfig.m_advLayoutDirectionRL ) - { - appConfig.m_advLayoutDirectionRL = layout_rl; - need_restart = true; - } - - appConfig.save(); - - if ( need_restart ) - QMessageBox::information( this, - APP_NAME, - i18n( "Changing those options requires restarting the application to take effect." ) ); - - QDialog::accept(); -} - - -void KCHMSetupDialog::browseExternalEditor() -{ -#if defined (USE_KDE) - QString exec = KFileDialog::getOpenFileName( KUrl(), i18n("*|Executables"), this, i18n("Choose an editor executable")); -#else - QString exec = QFileDialog::getOpenFileName(this, - i18n("Choose an editor executable"), - QString::null, - i18n( "Executables (*)") ); -#endif - - if ( !exec.isEmpty() ) - m_advExternalProgramName->setText( exec ); -} diff -Nru kchmviewer-4.1/src/kchmsetupdialog.h kchmviewer-5.1/src/kchmsetupdialog.h --- kchmviewer-4.1/src/kchmsetupdialog.h 2009-07-20 04:37:13.000000000 +0100 +++ kchmviewer-5.1/src/kchmsetupdialog.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMSETUPDIALOG_H -#define KCHMSETUPDIALOG_H - -#include -#include - - -class KCHMSetupDialog : public QDialog, public Ui::DialogSetup -{ - Q_OBJECT - - public: - KCHMSetupDialog( QWidget *parent = 0 ); - ~KCHMSetupDialog(); - - public slots: - void browseExternalEditor(); - void accept(); - - private: - int m_numOfRecentFiles; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmtreeviewitem.cpp kchmviewer-5.1/src/kchmtreeviewitem.cpp --- kchmviewer-4.1/src/kchmtreeviewitem.cpp 2009-07-20 04:37:11.000000000 +0100 +++ kchmviewer-5.1/src/kchmtreeviewitem.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,209 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include "kchmtreeviewitem.h" -#include "kchmmainwindow.h" -#include "kchmdialogchooseurlfromlist.h" - - -KCHMIndTocItem::KCHMIndTocItem( QTreeWidgetItem * parent, QTreeWidgetItem * after, const QString& name, const QString& aurl, int image) - : QTreeWidgetItem( parent, after ), m_name(name), m_url(aurl), m_image_number(image) -{ -} - -KCHMIndTocItem::KCHMIndTocItem( QTreeWidget * parent, QTreeWidgetItem * after, const QString& name, const QString& aurl, int image) - : QTreeWidgetItem( parent, after ), m_name(name), m_url(aurl), m_image_number(image) -{ -} - - -QString KCHMIndTocItem::getUrl( ) const -{ - if ( m_url.indexOf ('|') == -1 ) - return m_url; - - // Create a dialog with URLs, and show it, so user can select an URL he/she wants. - QStringList urls = m_url.split( '|' ); - QStringList titles; - LCHMFile * xchm = ::mainWindow->chmFile(); - - for ( int i = 0; i < urls.size(); i++ ) - { - QString title = xchm->getTopicByUrl (urls[i]); - - if ( title.isEmpty() ) - { - qWarning( "Could not get item name for url '%s'", qPrintable( urls[i] ) ); - titles.push_back(QString::null); - } - else - titles.push_back(title); - } - - KCHMDialogChooseUrlFromList dlg( ::mainWindow ); - return dlg.getSelectedItemUrl( urls, titles ); -} - - -int KCHMIndTocItem::columnCount() const -{ - return 1; -} - -QVariant KCHMIndTocItem::data(int column, int role) const -{ - int imagenum; - - if ( column != 0 ) - return QVariant(); - - switch( role ) - { - // Item name - case Qt::DisplayRole: - return m_name; - - // Item image - case Qt::DecorationRole: - if ( m_image_number != LCHMBookIcons::IMAGE_NONE - && m_image_number != LCHMBookIcons::IMAGE_INDEX ) - { - // If the item has children, we change the book image to "open book", or next image automatically - if ( childCount() ) - { - if ( isExpanded() ) - imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 1 : m_image_number; - else - imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 0 : m_image_number + 1; - } - else - imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 10 : m_image_number; - - const QPixmap *pix = ::mainWindow->chmFile()->getBookIconPixmap( imagenum ); - - if ( !pix || pix->isNull() ) - abort(); - - return *pix; - } - break; - - // Item foreground color - case Qt::ForegroundRole: - // For Index URL it means that there is URL list in m_url - if ( m_url.indexOf( '|' ) != -1 ) - return QBrush( QColor( Qt::red ) ); - // For Index URLs it means that this is "see also" URL - else if ( !m_url.isEmpty() && m_url[0] == ':' ) - return QBrush( QColor( Qt::lightGray ) ); - break; - - case Qt::ToolTipRole: - case Qt::WhatsThisRole: - return m_name; - } - - return QVariant(); -} - - -void kchmFillListViewWithParsedData( QTreeWidget * list, const QVector< LCHMParsedEntry >& data, QMap * map ) -{ - QVector< KCHMIndTocItem *> lastchild; - QVector< KCHMIndTocItem *> rootentry; - bool warning_shown = false; - - if ( map ) - map->clear(); - - list->clear(); - - for ( int i = 0; i < data.size(); i++ ) - { - int indent = data[i].indent; - - // Do we need to add another indent? - if ( indent >= rootentry.size() ) - { - int maxindent = rootentry.size() - 1; - - // Resize the arrays - lastchild.resize( indent + 1 ); - rootentry.resize( indent + 1 ); - - if ( indent > 0 && maxindent < 0 ) - qFatal("Invalid fisrt TOC indent (first entry has no root entry), aborting."); - - // And init the rest if needed - if ( (indent - maxindent) > 1 ) - { - if ( !warning_shown ) - { - qWarning("Invalid TOC step, applying workaround. Results may vary."); - warning_shown = true; - } - - for ( int j = maxindent; j < indent; j++ ) - { - lastchild[j+1] = lastchild[j]; - rootentry[j+1] = rootentry[j]; - } - } - - lastchild[indent] = 0; - rootentry[indent] = 0; - } - - // Create the node - KCHMIndTocItem * item; - QString url = data[i].urls.join ("|"); - - if ( indent == 0 ) - item = new KCHMIndTocItem( list, lastchild[indent], data[i].name, url, data[i].imageid ); - else - { - // New non-root entry. It is possible (for some buggy CHMs) that there is no previous entry: previoous entry had indent 1, - // and next entry has indent 3. Backtracking it up, creating missing entries. - if ( rootentry[indent-1] == 0 ) - qFatal("Child entry indented as %d with no root entry!", indent); - - item = new KCHMIndTocItem( rootentry[indent-1], lastchild[indent], data[i].name, url, data[i].imageid ); - } - - // Hack: if map is 0, we have index, so make it open - if ( map ) - { - for ( int li = 0; li < data[i].urls.size(); li++ ) - map->insert( data[i].urls[li], item ); - } - else - item->setExpanded( true ); - - lastchild[indent] = item; - rootentry[indent] = item; - } - - list->update(); -} diff -Nru kchmviewer-4.1/src/kchmtreeviewitem.h kchmviewer-5.1/src/kchmtreeviewitem.h --- kchmviewer-4.1/src/kchmtreeviewitem.h 2009-07-20 04:37:09.000000000 +0100 +++ kchmviewer-5.1/src/kchmtreeviewitem.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMTREEVIEWITEM_H -#define KCHMTREEVIEWITEM_H - -#include -#include -#include -#include -#include - -#include "libchmfile.h" - - -//! This is a list item used both in Index and Table Of Content trees -class KCHMIndTocItem : public QTreeWidgetItem -{ - public: - KCHMIndTocItem( QTreeWidgetItem* parent, QTreeWidgetItem* after, const QString& name, const QString& aurl, int image); - KCHMIndTocItem( QTreeWidget* parent, QTreeWidgetItem* after, const QString& name, const QString& url, int image); - - QString getUrl() const; - - // Overridden methods - int columnCount () const; - QVariant data ( int column, int role ) const; - - private: - QString m_name; - QString m_url; - int m_image_number; -}; - - - -void kchmFillListViewWithParsedData( QTreeWidget * list, const QVector< LCHMParsedEntry >& data, QMap * map ); - -#endif diff -Nru kchmviewer-4.1/src/kchmviewwindow.cpp kchmviewer-5.1/src/kchmviewwindow.cpp --- kchmviewer-4.1/src/kchmviewwindow.cpp 2009-07-20 04:37:07.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,302 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -// Do not use tr() or i18n() in this file - this class is not derived from QObject. - -#include -#include -#include - -#include "libchmfile.h" -#include "libchmurlfactory.h" - -#include "kchmconfig.h" -#include "kchmviewwindow.h" -#include "kchmmainwindow.h" -#include "kchmviewwindowmgr.h" - - -KCHMViewWindow::KCHMViewWindow( QTabWidget * parent ) -{ - invalidate(); - m_contextMenu = 0; - m_contextMenuLink = 0; - m_historyMaxSize = 25; - - m_parentTabWidget = parent; -} - -KCHMViewWindow::~KCHMViewWindow() -{ -} - -void KCHMViewWindow::invalidate( ) -{ - m_base_url = "/"; - m_openedPage = QString::null; - m_newTabLinkKeeper = QString::null; - - m_historyCurrentPos = 0; - m_history.clear(); - - updateNavigationToolbar(); -} - - - -QString KCHMViewWindow::makeURLabsolute ( const QString & url, bool set_as_base ) -{ - QString p1, p2, newurl = url; - - if ( !LCHMUrlFactory::isRemoteURL (url, p1) - && !LCHMUrlFactory::isJavascriptURL (url) - && !LCHMUrlFactory::isNewChmURL (url, p1, p2) ) - { - newurl = QDir::cleanPath (url); - - // Normalize url, so it becomes absolute - if ( newurl[0] != '/' ) - newurl = m_base_url + "/" + newurl; - - newurl = QDir::cleanPath (newurl); - - if ( set_as_base ) - { - m_base_url = newurl; - - // and set up new baseurl - int i = newurl.lastIndexOf('/'); - if ( i != -1 ) - m_base_url = QDir::cleanPath (newurl.left (i + 1)); - } - } - - //qDebug ("KCHMViewWindow::makeURLabsolute (%s) -> (%s)", url.ascii(), newurl.ascii()); - return newurl; -} - -bool KCHMViewWindow::openUrl ( const QString& origurl ) -{ - QString chmfile, page, newurl = origurl; - - if ( origurl.isEmpty() ) - return true; - - // URL could be a complete ms-its link. The file should be already loaded (for QTextBrowser), - // or will be loaded (for kio slave). We care only about the path component. - if ( LCHMUrlFactory::isNewChmURL( newurl, chmfile, page ) ) - { - // If a new chm file is opened here, and we do not use KCHMLPart, we better abort - if ( chmfile != ::mainWindow->getOpenedFileBaseName() && appConfig.m_usedBrowser != KCHMConfig::BROWSER_KHTMLPART ) - qFatal("KCHMViewWindow::openUrl(): opened new chm file %s while current is %s", - qPrintable( chmfile ), - qPrintable( ::mainWindow->getOpenedFileName() ) ); - - // It is OK to have a new file in chm for KHTMLPart - newurl = page; - } - - makeURLabsolute (newurl); - handleStartPageAsImage( newurl ); - - if ( openPage (newurl) ) - { - m_newTabLinkKeeper = QString::null; - m_openedPage = newurl; - - // If m_openedPage contains #, strip it, and everything after it - int hash = m_openedPage.indexOf( '#' ); - if ( hash != -1 ) - m_openedPage = m_openedPage.left( hash ); - - mainWindow->viewWindowMgr()->setTabName( this ); - return true; - } - - return false; -} - -void KCHMViewWindow::handleStartPageAsImage( QString & link ) -{ - // Handle pics - if ( link.endsWith( ".jpg", Qt::CaseInsensitive ) - || link.endsWith( ".jpeg", Qt::CaseInsensitive ) - || link.endsWith( ".gif", Qt::CaseInsensitive ) - || link.endsWith( ".png", Qt::CaseInsensitive ) - || link.endsWith( ".bmp", Qt::CaseInsensitive ) ) - link += LCHMUrlFactory::getInternalUriExtension(); -} - - -QMenu * KCHMViewWindow::createStandardContextMenu( QWidget * parent ) -{ - QMenu * contextMenu = new QMenu( parent ); - - contextMenu->addAction( "&Copy", ::mainWindow, SLOT(slotBrowserCopy()) ); - contextMenu->addAction( "&Select all", ::mainWindow, SLOT(slotBrowserSelectAll()) ); - - return contextMenu; -} - - -QMenu * KCHMViewWindow::getContextMenu( const QString & link, QWidget * parent ) -{ - if ( link.isEmpty() ) - { - // standard context menu - if ( !m_contextMenu ) - m_contextMenu = createStandardContextMenu( parent ); - - return m_contextMenu; - } - else - { - // Open in New Tab context menu - // standard context menu - if ( !m_contextMenuLink ) - { - m_contextMenuLink = createStandardContextMenu( parent ); - m_contextMenuLink->addSeparator(); - - m_contextMenuLink->addAction( "&Open this link in a new tab", ::mainWindow, SLOT(onOpenPageInNewTab()), QKeySequence("Shift+Enter") ); - - m_contextMenuLink->addAction( "&Open this link in a new background tab", ::mainWindow, SLOT(onOpenPageInNewBackgroundTab()), QKeySequence("Ctrl+Enter") ); - } - - setTabKeeper( link ); - return m_contextMenuLink; - } -} - -QString KCHMViewWindow::getTitle() const -{ - QString title = ::mainWindow->chmFile()->getTopicByUrl( m_openedPage ); - - if ( title.isEmpty() ) - title = m_openedPage; - - return title; -} - - -void KCHMViewWindow::navigateForward() -{ - if ( m_historyCurrentPos < m_history.size() ) - { - m_historyCurrentPos++; - ::mainWindow->openPage( m_history[m_historyCurrentPos].getUrl() ); - setScrollbarPosition( m_history[m_historyCurrentPos].getScrollPosition() ); - - // By default navigation starts with empty array, and a new entry is added when - // you change the current page (or it may not be added). So to have the whole system - // worked, the m_historyCurrentPos should never be m_history.size() - 1, it should be - // either greater or lesser. - // - // This is a dirty hack - but the whole navigation system now looks to me like - // it was written by some drunk monkey - which is probably not far from The Real Truth. - // Shame on me - Tim. - if ( m_historyCurrentPos == (m_history.size() - 1) ) - m_historyCurrentPos++; - } - - updateNavigationToolbar(); -} - -void KCHMViewWindow::navigateBack( ) -{ - if ( m_historyCurrentPos > 0 ) - { - // If we're on top of list, and pressing Back, the last page is still - // not in list - so add it, if it is not still here - if ( m_historyCurrentPos == m_history.size() ) - { - if ( m_history[m_historyCurrentPos-1].getUrl() != m_openedPage ) - m_history.push_back( KCHMUrlHistory( m_openedPage, getScrollbarPosition() ) ); - else - { - // part 2 of the navigation hack - see navigateForward() comment - m_history[m_historyCurrentPos-1].setScrollPosition( getScrollbarPosition() ); - m_historyCurrentPos--; - } - } - - m_historyCurrentPos--; - - ::mainWindow->openPage( m_history[m_historyCurrentPos].getUrl() ); - setScrollbarPosition( m_history[m_historyCurrentPos].getScrollPosition() ); - } - - updateNavigationToolbar(); -} - -void KCHMViewWindow::navigateHome( ) -{ - ::mainWindow->openPage( ::mainWindow->chmFile()->homeUrl() ); -} - -void KCHMViewWindow::addNavigationHistory( const QString & url, int scrollpos ) -{ - // shred the 'forward' history - if ( m_historyCurrentPos < m_history.size() ) - m_history.erase( m_history.begin() + m_historyCurrentPos, m_history.end() ); - - // do not grow the history if already max size - if ( m_history.size() >= m_historyMaxSize ) - m_history.pop_front(); - - m_history.push_back( KCHMUrlHistory( url, scrollpos ) ); - m_historyCurrentPos = m_history.size(); - - updateNavigationToolbar(); -} - -void KCHMViewWindow::updateNavigationToolbar( ) -{ - // Dump navigation for debugging -#if 0 - qDebug("\nNavigation dump (%d entries, current pos %d)", m_history.size(), m_historyCurrentPos ); - for ( unsigned int i = 0; i < m_history.size(); i++ ) - qDebug("[%02d]: %s [%d]", i, m_history[i].getUrl().ascii(), m_history[i].getScrollPosition()); -#endif - - if ( mainWindow ) - { - mainWindow->navSetBackEnabled( m_historyCurrentPos > 0 ); - mainWindow->navSetForwardEnabled( m_historyCurrentPos < (m_history.size() - 1) ); - } -} - - -void KCHMViewWindow::setTabKeeper( const QString & link ) -{ - // If we clicked on relative link, make sure we convert it to absolute right now, - // because later we will not have access to this view window variables - m_newTabLinkKeeper = link; - if ( m_newTabLinkKeeper[0] == '#' && !m_openedPage.isEmpty() ) - { - // Clean up opened page URL - int pos = m_openedPage.indexOf('#'); - QString fixedpath = pos == -1 ? m_openedPage : m_openedPage.left (pos); - m_newTabLinkKeeper = fixedpath + m_newTabLinkKeeper; - } - - m_newTabLinkKeeper = makeURLabsolute( m_newTabLinkKeeper, false ); -} diff -Nru kchmviewer-4.1/src/kchmviewwindow.h kchmviewer-5.1/src/kchmviewwindow.h --- kchmviewer-4.1/src/kchmviewwindow.h 2009-07-20 04:37:05.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,156 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMVIEWWINDOW_H -#define KCHMVIEWWINDOW_H - - -#include "kde-qt.h" - - -class KCHMViewWindow -{ - public: - enum - { - SEARCH_CASESENSITIVE = 0x10, - SEARCH_WHOLEWORDS = 0x20 - }; - - KCHMViewWindow ( QTabWidget * parent ); - virtual ~KCHMViewWindow(); - - //! Open a page from current chm archive - bool openUrl (const QString& url ); - - QString getBaseUrl() const { return m_base_url; } - QString getOpenedPage() const { return m_openedPage; } - QString getNewTabLink() const { return m_newTabLinkKeeper; } - QString makeURLabsolute ( const QString &url, bool set_as_base = true ); - - public: - // virtual members, which should be implemented by viewers - //! Invalidate current view, doing all the cleanups etc. - virtual void invalidate(); - - //! Popups the print dialog, and prints the current page on the printer. - virtual bool printCurrentPage() = 0; - - //! Search function. find() starts new search, onFindNext and onFindPrevious continue it - virtual void find( const QString& text, int flags ) = 0; - virtual void onFindNext() = 0; - virtual void onFindPrevious() = 0; - - //! Return current ZoomFactor. - virtual int getZoomFactor() const = 0; - - //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. - virtual void setZoomFactor (int zoom) = 0; - - //! Relatively changes ZoomFactor. Most common values are -1 and 1. - virtual void addZoomFactor (int value) = 0; - - virtual QObject * getQObject() = 0; - virtual QWidget * getQWidget() = 0; - - /*! - * Return current scrollbar position in view window. Saved on program exit. - * There is no restriction on returned value, except that giving this value to - * setScrollbarPosition() should move the scrollbar in the same position. - */ - virtual int getScrollbarPosition() = 0; - - //! Sets the scrollbar position. - virtual void setScrollbarPosition(int pos) = 0; - - //! Select the content of the whole page - virtual void clipSelectAll() = 0; - - //! Copies the selected content to the clipboard - virtual void clipCopy() = 0; - - //! Returns the window title - virtual QString getTitle() const; - - //! Navigation stuff - virtual void navigateBack(); - virtual void navigateHome(); - virtual void navigateForward(); - - //! Navigation auxiliary stuff - virtual void setHistoryMaxSize (unsigned int size) { m_historyMaxSize = size; } - virtual void addNavigationHistory( const QString & url, int scrollpos ); - virtual void updateNavigationToolbar(); - - //! Keeps the tab URL between link following - void setTabKeeper ( const QString& link ); - - protected: /* signals */ - /*! - * Emitted when the user clicked on the link, before the page changed. - * If linkClicked() return false, the current page should NOT change. - * Otherwise it should be changed to the new link value. - */ - virtual void linkClicked ( const QString & newlink, bool& follow_link ) = 0; - - protected: - virtual bool openPage ( const QString& url ) = 0; - virtual void handleStartPageAsImage( QString& link ); - - QMenu * getContextMenu( const QString& link, QWidget * parent ); - QMenu * createStandardContextMenu( QWidget * parent ); - - //! History - class KCHMUrlHistory - { - public: - KCHMUrlHistory() { scrollbarpos = 0; } - KCHMUrlHistory( const QString& _url, int _scrollbarpos ) - : url(_url), scrollbarpos(_scrollbarpos) {}; - - const QString& getUrl() const { return url; } - int getScrollPosition() const { return scrollbarpos; } - void setScrollPosition( int pos ) { scrollbarpos = pos; } - - private: - QString url; - int scrollbarpos; - }; - - int m_historyMaxSize; - int m_historyCurrentPos; - QMenu * m_contextMenu; - QMenu * m_contextMenuLink; - QList m_history; - - // This member keeps a "open new tab" link between getContextMenu() - // call and appropriate slot call - QString m_newTabLinkKeeper; - - QString m_openedPage; - QString m_lastOpenedPage; - QString m_base_url; - - // The parent tab browser - QTabWidget * m_parentTabWidget; -}; - -#endif diff -Nru kchmviewer-4.1/src/kchmviewwindowmgr.cpp kchmviewer-5.1/src/kchmviewwindowmgr.cpp --- kchmviewer-4.1/src/kchmviewwindowmgr.cpp 2009-07-20 04:37:02.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindowmgr.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,392 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "kchmconfig.h" -#include "kchmmainwindow.h" -#include "kchmviewwindow.h" -#include "kchmviewwindowmgr.h" - -#include "kchmviewwindow_qtextbrowser.h" - -#if defined (USE_KDE) - #include "kde/kchmviewwindow_khtmlpart.h" -#endif - -#if defined (QT_WEBKIT_LIB) - #include "kchmviewwindow_qtwebkit.h" -#endif - - -KCHMViewWindowMgr::KCHMViewWindowMgr( QWidget *parent ) - : QWidget( parent ), Ui::TabbedBrowser() -{ - // UIC - setupUi( this ); - - // Remove the UIC-generated tab if it's there. - // Do it right here before the signals are connected, since after Qt 4.4.0 it triggers - // the currentChanged signal. - if ( tabWidget->count() > 0 ) - tabWidget->removeTab ( 0 ); - - // on current tab changed - connect( tabWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( onTabChanged(QWidget *) ) ); - - // Create a close button - m_closeButton = new QToolButton( this ); - m_closeButton->setCursor( Qt::ArrowCursor ); - m_closeButton->setAutoRaise( true ); - m_closeButton->setIcon( QIcon( ":/images/closetab.png" ) ); - m_closeButton->setToolTip( i18n("Close current page") ); - m_closeButton->setEnabled( false ); - connect( m_closeButton, SIGNAL( clicked() ), this, SLOT( onCloseCurrentWindow() ) ); - - // Put it there - tabWidget->setCornerWidget( m_closeButton, Qt::TopRightCorner ); - - // Create a "new tab" button - QToolButton * newButton = new QToolButton( this ); - newButton->setCursor( Qt::ArrowCursor ); - newButton->setAutoRaise( true ); - newButton->setIcon( QIcon( ":/images/addtab.png" ) ); - newButton->setToolTip( i18n("Add page") ); - connect( newButton, SIGNAL( clicked() ), this, SLOT( openNewTab() ) ); - - // Put it there - tabWidget->setCornerWidget( newButton, Qt::TopLeftCorner ); - - // Hide the search frame - frameFind->setVisible( false ); - labelWrapped->setVisible( false ); - - // Search Line edit - connect( editFind, - SIGNAL( textEdited ( const QString & ) ), - this, - SLOT( editTextEdited( const QString & ) ) ); - - // Search toolbar buttons - connect( toolClose, SIGNAL(clicked()), frameFind, SLOT( hide()) ); - connect( toolPrevious, SIGNAL(clicked()), this, SLOT( onFindPrevious()) ); - connect( toolNext, SIGNAL(clicked()), this, SLOT( onFindNext()) ); -} - -KCHMViewWindowMgr::~KCHMViewWindowMgr( ) -{ -} - -void KCHMViewWindowMgr::createMenu( KCHMMainWindow *, QMenu * menuWindow, QAction * actionCloseWindow ) -{ - m_menuWindow = menuWindow; - m_actionCloseWindow = actionCloseWindow; -} - -void KCHMViewWindowMgr::invalidate() -{ - closeAllWindows(); - addNewTab( true ); -} - - -KCHMViewWindow * KCHMViewWindowMgr::current() -{ - TabData * tab = findTab( tabWidget->currentWidget() ); - - if ( !tab ) - abort(); - - return tab->window; -} - -KCHMViewWindow * KCHMViewWindowMgr::addNewTab( bool set_active ) -{ - KCHMViewWindow * viewvnd; - - switch ( appConfig.m_usedBrowser ) - { - default: - viewvnd = new KCHMViewWindow_QTextBrowser( tabWidget ); - break; - -#if defined (USE_KDE) - case KCHMConfig::BROWSER_KHTMLPART: - viewvnd = new KCHMViewWindow_KHTMLPart( tabWidget ); - break; -#endif - -#if defined (QT_WEBKIT_LIB) - case KCHMConfig::BROWSER_QTWEBKIT: - viewvnd = new KCHMViewWindow_QtWebKit( tabWidget ); - break; -#endif - } - - editFind->installEventFilter( this ); - - // Create the tab data structure - TabData tabdata; - tabdata.window = viewvnd; - tabdata.action = new QAction( "window", this ); // temporary name; real name is set in setTabName - tabdata.widget = viewvnd->getQWidget(); - - connect( tabdata.action, - SIGNAL( triggered() ), - this, - SLOT( activateWindow() ) ); - - m_Windows.push_back( tabdata ); - tabWidget->addTab( tabdata.widget, "" ); - Q_ASSERT( m_Windows.size() == tabWidget->count() ); - - // Set active if it is the first tab - if ( set_active || m_Windows.size() == 1 ) - tabWidget->setCurrentWidget( tabdata.widget ); - - // Handle clicking on link in browser window - connect( viewvnd->getQObject(), - SIGNAL( linkClicked (const QString &, bool &) ), - ::mainWindow, - SLOT( activateLink(const QString &, bool &) ) ); - - // Set up the accelerator if we have room - if ( m_Windows.size() < 10 ) - tabdata.action->setShortcut( QKeySequence( i18n("Alt+%1").arg( m_Windows.size() ) ) ); - - // Add it to the "Windows" menu - m_menuWindow->addAction( tabdata.action ); - - return viewvnd; -} - -void KCHMViewWindowMgr::closeAllWindows( ) -{ - // No it++ - we removing the window by every closeWindow call - while ( m_Windows.begin() != m_Windows.end() ) - closeWindow( m_Windows.first().widget ); -} - -void KCHMViewWindowMgr::setTabName( KCHMViewWindow * window ) -{ - TabData * tab = findTab( window->getQWidget() ); - - if ( tab ) - { - QString title = window->getTitle(); - - // Trim too long string - if ( title.length() > 25 ) - title = title.left( 22 ) + "..."; - - tabWidget->setTabText( tabWidget->indexOf( window->getQWidget() ), title ); - tab->action->setText( title ); - - updateCloseButtons(); - } -} - -void KCHMViewWindowMgr::onCloseCurrentWindow( ) -{ - // Do not allow to close the last window - if ( m_Windows.size() == 1 ) - return; - - TabData * tab = findTab( tabWidget->currentWidget() ); - closeWindow( tab->widget ); -} - -void KCHMViewWindowMgr::closeWindow( QWidget * widget ) -{ - WindowsIterator it; - - for ( it = m_Windows.begin(); it != m_Windows.end(); ++it ) - if ( it->widget == widget ) - break; - - if ( it == m_Windows.end() ) - qFatal( "KCHMViewWindowMgr::closeWindow called with unknown widget!" ); - - m_menuWindow->removeAction( it->action ); - - tabWidget->removeTab( tabWidget->indexOf( it->widget ) ); - delete it->window; - delete it->action; - - m_Windows.erase( it ); - updateCloseButtons(); - - // Change the accelerators, as we might have removed the item in the middle - int count = 1; - for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end() && count < 10; ++it, count++ ) - (*it).action->setShortcut( QKeySequence( i18n("Alt+%1").arg( count ) ) ); -} - - -void KCHMViewWindowMgr::restoreSettings( const KCHMSettings::viewindow_saved_settings_t & settings ) -{ - // Destroy automatically created tab - closeWindow( m_Windows.first().widget ); - - for ( int i = 0; i < settings.size(); i++ ) - { - KCHMViewWindow * window = addNewTab( false ); - window->openUrl( settings[i].url ); // will call setTabName() - window->setScrollbarPosition( settings[i].scroll_y ); - window->setZoomFactor( settings[i].zoom ); - } -} - - -void KCHMViewWindowMgr::saveSettings( KCHMSettings::viewindow_saved_settings_t & settings ) -{ - settings.clear(); - - for ( int i = 0; i < tabWidget->count(); i++ ) - { - QWidget * p = tabWidget->widget( i ); - TabData * tab = findTab( p ); - - if ( !tab ) - abort(); - - settings.push_back( - KCHMSettings::SavedViewWindow( - tab->window->getOpenedPage(), - tab->window->getScrollbarPosition(), - tab->window->getZoomFactor()) ); - } -} - -void KCHMViewWindowMgr::updateCloseButtons( ) -{ - bool enabled = m_Windows.size() > 1; - - m_actionCloseWindow->setEnabled( enabled ); - m_closeButton->setEnabled( enabled ); -} - -void KCHMViewWindowMgr::onTabChanged( QWidget * newtab ) -{ - TabData * tab = findTab( newtab ); - - if ( tab ) - { - tab->window->updateNavigationToolbar(); - mainWindow->browserChanged( tab->window ); - tab->widget->setFocus(); - } -} - - -void KCHMViewWindowMgr::openNewTab() -{ - ::mainWindow->openPage( current()->getOpenedPage(), - KCHMMainWindow::OPF_NEW_TAB | KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY ); -} - -void KCHMViewWindowMgr::activateWindow() -{ - QAction *action = qobject_cast< QAction * >(sender()); - - for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end(); ++it ) - { - if ( it->action != action ) - continue; - - QWidget *widget = it->widget; - tabWidget->setCurrentWidget(widget); - break; - } -} - -KCHMViewWindowMgr::TabData * KCHMViewWindowMgr::findTab(QWidget * widget) -{ - for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end(); ++it ) - if ( it->widget == widget ) - return (it.operator->()); - - return 0; -} - -void KCHMViewWindowMgr::setCurrentPage(int index) -{ - tabWidget->setCurrentIndex( index ); -} - -int KCHMViewWindowMgr::currentPageIndex() const -{ - return tabWidget->currentIndex(); -} - - -void KCHMViewWindowMgr::indicateFindResultStatus( SearchResultStatus status ) -{ - QPalette p = editFind->palette(); - - if ( status == SearchResultNotFound ) - p.setColor( QPalette::Active, QPalette::Base, QColor(255, 102, 102) ); - else - p.setColor( QPalette::Active, QPalette::Base, Qt::white ); - - editFind->setPalette( p ); - labelWrapped->setVisible( status == SearchResultFoundWrapped ); -} - - -void KCHMViewWindowMgr::onActivateFind() -{ - frameFind->show(); - labelWrapped->setVisible( false ); - editFind->setFocus( Qt::ShortcutFocusReason ); - editFind->selectAll(); -} - - -void KCHMViewWindowMgr::find() -{ - int flags = 0; - - if ( checkCase->isChecked() ) - flags |= KCHMViewWindow::SEARCH_CASESENSITIVE; - - if ( checkWholeWords->isChecked() ) - flags |= KCHMViewWindow::SEARCH_WHOLEWORDS; - - current()->find( editFind->text(), flags ); - - if ( !frameFind->isVisible() ) - frameFind->show(); -} - - -void KCHMViewWindowMgr::editTextEdited(const QString &) -{ - find(); -} - -void KCHMViewWindowMgr::onFindNext() -{ - current()->onFindNext(); -} - -void KCHMViewWindowMgr::onFindPrevious() -{ - current()->onFindPrevious(); -} diff -Nru kchmviewer-4.1/src/kchmviewwindowmgr.h kchmviewer-5.1/src/kchmviewwindowmgr.h --- kchmviewer-4.1/src/kchmviewwindowmgr.h 2009-07-20 04:37:00.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindowmgr.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,109 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef INCLUDE_KCHMVIEWWINDOWMGR_H -#define INCLUDE_KCHMVIEWWINDOWMGR_H - -#include "kde-qt.h" -#include "kchmsettings.h" -#include "ui_window_browser.h" - - -class KCHMViewWindowMgr : public QWidget, public Ui::TabbedBrowser -{ - Q_OBJECT - public: - enum SearchResultStatus - { - SearchResultFound, - SearchResultNotFound, - SearchResultFoundWrapped - }; - - KCHMViewWindowMgr( QWidget *parent ); - ~KCHMViewWindowMgr( ); - - // Returns a handle to a currently viewed window. - // Guaranteeed to return a valid handle, or aborts. - KCHMViewWindow * current(); - - // Adds a new tab, creating a new browser window - KCHMViewWindow * addNewTab( bool set_active ); - - // Sets the tab name and updates Windows menu - void setTabName( KCHMViewWindow* window ); - - void invalidate(); - - // Creates a Window menu - void createMenu( KCHMMainWindow * parent, QMenu * menuWindow, QAction * actionCloseWindow ); - - // Saves and restores current settings between sessions - void restoreSettings( const KCHMSettings::viewindow_saved_settings_t& settings ); - void saveSettings( KCHMSettings::viewindow_saved_settings_t& settings ); - - void setCurrentPage( int index ); - int currentPageIndex() const; - - public slots: - void onCloseCurrentWindow(); - void onActivateFind(); - void onFindNext(); - void onFindPrevious(); - void indicateFindResultStatus( SearchResultStatus status ); - - protected slots: - void openNewTab(); - void onTabChanged( QWidget * newtab ); - void updateCloseButtons(); - void activateWindow(); - - void editTextEdited( const QString & text ); - - private: - void find(); - - typedef struct - { - QWidget * widget; - KCHMViewWindow * window; - QAction * action; - } TabData; - - void closeAllWindows(); - void closeWindow( QWidget * widget ); - TabData * findTab( QWidget * widget ); - - // Storage of all available windows - QList< TabData > m_Windows; - typedef QList< TabData >::iterator WindowsIterator; - - QToolButton * m_closeButton; - QMenu * m_menuWindow; - QAction * m_actionCloseWindow; - - // Window menu actions. Contains one action per window. They are not - // linked permanently - if a middle window is deleted, all the following - // actions will be relinked and replaced. - QList< QAction* > m_actions; -}; - -#endif /* INCLUDE_KCHMVIEWWINDOWMGR_H */ diff -Nru kchmviewer-4.1/src/kchmviewwindow_qtextbrowser.cpp kchmviewer-5.1/src/kchmviewwindow_qtextbrowser.cpp --- kchmviewer-4.1/src/kchmviewwindow_qtextbrowser.cpp 2009-07-20 04:36:57.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow_qtextbrowser.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,327 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include - -#include "kde-qt.h" -#include "libchmurlfactory.h" -#include "kchmmainwindow.h" -#include "kchmviewwindowmgr.h" -#include "kchmviewwindow_qtextbrowser.h" - - -KCHMViewWindow_QTextBrowser::KCHMViewWindow_QTextBrowser( QTabWidget * parent ) - : QTextBrowser ( parent ), KCHMViewWindow ( parent ) -{ - m_zoomfactor = 0; - invalidate(); - -#if QT_VERSION >= 0x040300 - setOpenLinks( false ); -#endif - connect( this, SIGNAL( anchorClicked ( const QUrl& ) ), this, SLOT( onAnchorClicked ( const QUrl& ) ) ); -} - - -KCHMViewWindow_QTextBrowser::~KCHMViewWindow_QTextBrowser() -{ -} - -bool KCHMViewWindow_QTextBrowser::openPage (const QString& url) -{ - setSource (url); - return true; -} - -void KCHMViewWindow_QTextBrowser::setSource ( const QUrl & name ) -{ - if ( m_allowSourceChange ) - { - // Do URI decoding, qtextbrowser does stupid job. - QString fixedname = decodeUrl( name.toString() ); - QTextBrowser::setSource (fixedname); - } - else - m_allowSourceChange = true; -} - -void KCHMViewWindow_QTextBrowser::setZoomFactor( int zoom ) -{ - m_zoomfactor = zoom; - - if ( zoom < 0 ) - QTextBrowser::zoomOut( -zoom ); - else if ( zoom > 0 ) - QTextBrowser::zoomIn( zoom); -} - -void KCHMViewWindow_QTextBrowser::invalidate( ) -{ - m_zoomfactor = 0; - m_allowSourceChange = true; - reload(); - - KCHMViewWindow::invalidate( ); -} - -int KCHMViewWindow_QTextBrowser::getScrollbarPosition( ) -{ - return verticalScrollBar()->sliderPosition(); -} - -void KCHMViewWindow_QTextBrowser::setScrollbarPosition( int pos ) -{ - verticalScrollBar()->setSliderPosition( pos); -} - -void KCHMViewWindow_QTextBrowser::addZoomFactor( int value ) -{ - setZoomFactor( value); -} - -void KCHMViewWindow_QTextBrowser::onAnchorClicked(const QUrl & url) -{ -#if QT_VERSION < 0x040300 - emit linkClicked( url.toString(), m_allowSourceChange ); -#else - bool q; - emit linkClicked( url.toString(), q ); -#endif -} - - -bool KCHMViewWindow_QTextBrowser::printCurrentPage( ) -{ - QPrinter printer( QPrinter::HighResolution ); - //printer.setFullPage(true); - - QPrintDialog dlg( &printer, this ); - - if ( dlg.exec() != QDialog::Accepted ) - { - ::mainWindow->showInStatusBar( i18n( "Printing aborted") ); - return false; - } - - document()->print( &printer ); - ::mainWindow->showInStatusBar( i18n( "Printing finished") ); - return true; -} - -void KCHMViewWindow_QTextBrowser::clipSelectAll( ) -{ - selectAll(); -} - -void KCHMViewWindow_QTextBrowser::clipCopy( ) -{ - copy (); -} - - -// Shamelessly stolen from Qt -QString KCHMViewWindow_QTextBrowser::decodeUrl( const QString &input ) -{ - QString temp; - - int i = 0; - int len = input.length(); - int a, b; - QChar c; - while (i < len) - { - c = input[i]; - if (c == '%' && i + 2 < len) - { - a = input[++i].unicode(); - b = input[++i].unicode(); - - if (a >= '0' && a <= '9') - a -= '0'; - else if (a >= 'a' && a <= 'f') - a = a - 'a' + 10; - else if (a >= 'A' && a <= 'F') - a = a - 'A' + 10; - - if (b >= '0' && b <= '9') - b -= '0'; - else if (b >= 'a' && b <= 'f') - b = b - 'a' + 10; - else if (b >= 'A' && b <= 'F') - b = b - 'A' + 10; - - temp.append( (QChar)((a << 4) | b ) ); - } - else - { - temp.append( c ); - } - - ++i; - } - - return temp; -} - -QMenu * KCHMViewWindow_QTextBrowser::createPopupMenu( const QPoint & pos ) -{ - QMenu * menu = getContextMenu( anchorAt( pos ), this ); - menu->exec( viewport()->mapToGlobal( pos ) ); - - return 0; -} - -QVariant KCHMViewWindow_QTextBrowser::loadResource(int type, const QUrl & name) -{ - QString data, file, path = name.toString( QUrl::StripTrailingSlash ); - - // Retreive the data from chm file - LCHMFile * chm = ::mainWindow->chmFile(); - - if ( !chm ) - return 0; - - int pos = path.indexOf('#'); - if ( pos != -1 ) - path = path.left (pos); - - path = makeURLabsolute( path, false ); - - // To handle a single-image pages, we need to generate the HTML page to show - // this image. We did it in KCHMViewWindow::handleStartPageAsImage; now we need - // to generate the HTML page, and set it. - if ( LCHMUrlFactory::handleFileType( path, data ) ) - return QVariant( QString( data ) ); - - if ( type == QTextDocument::HtmlResource || type == QTextDocument::StyleSheetResource ) - { - if ( !chm->getFileContentAsString( &data, path ) ) - qWarning( "Needed file %s is not present in this CHM archive\n", qPrintable( path ) ); - - // A "fix" (actually hack) for CHM files people sent to me. I have no idea why QTextBrowser cannot show it. - if ( type == QTextDocument::HtmlResource ) - data.remove( "" ); - - return QVariant( QString( data ) ); - } - else if ( type == QTextDocument::ImageResource ) - { - QImage img; - QByteArray buf; - - QString fpath = decodeUrl( path ); - - if ( chm->getFileContentAsBinary( &buf, fpath ) ) - { - if ( !img.loadFromData ( (const uchar *) buf.data(), buf.size() ) ) - qWarning( "Needed file %s is not present in this CHM archive\n", qPrintable( path ) ); - } - - return QVariant( img ); - } - - qWarning("loadResource: Unknown type %d", type); - return QVariant(); -} - -void KCHMViewWindow_QTextBrowser::find(const QString & text, int flags) -{ - m_searchText = text; - m_flags = flags; - - find( false, false ); -} - -void KCHMViewWindow_QTextBrowser::onFindNext() -{ - find( true, false ); -} - -void KCHMViewWindow_QTextBrowser::onFindPrevious() -{ - find( false, true ); -} - -void KCHMViewWindow_QTextBrowser::find( bool forward, bool backward ) -{ - QTextDocument *doc = document(); - QTextCursor c = textCursor(); - QTextDocument::FindFlags options; - - ::mainWindow->viewWindowMgr()->indicateFindResultStatus( KCHMViewWindowMgr::SearchResultFound ); - - if ( c.hasSelection() ) - c.setPosition( forward ? c.position() : c.anchor(), QTextCursor::MoveAnchor ); - - QTextCursor newCursor = c; - - if ( !m_searchText.isEmpty() ) - { - if ( backward ) - options |= QTextDocument::FindBackward; - - if ( m_flags & SEARCH_CASESENSITIVE ) - options |= QTextDocument::FindCaseSensitively; - - if ( m_flags & SEARCH_WHOLEWORDS ) - options |= QTextDocument::FindWholeWords; - - newCursor = doc->find( m_searchText, c, options ); - - if ( newCursor.isNull() ) - { - QTextCursor ac( doc ); - ac.movePosition( options & QTextDocument::FindBackward - ? QTextCursor::End : QTextCursor::Start ); - newCursor = doc->find( m_searchText, ac, options ); - if ( newCursor.isNull() ) - { - ::mainWindow->viewWindowMgr()->indicateFindResultStatus( KCHMViewWindowMgr::SearchResultNotFound ); - newCursor = c; - } - else - ::mainWindow->viewWindowMgr()->indicateFindResultStatus( KCHMViewWindowMgr::SearchResultFoundWrapped ); - } - } - - setTextCursor( newCursor ); -} - -void KCHMViewWindow_QTextBrowser::contextMenuEvent(QContextMenuEvent * e) -{ - // From Qt Assistant - QMenu *m = new QMenu(0); - QString link = anchorAt( e->pos() ); - - if ( !link.isEmpty() ) - { - m->addAction( i18n("Open Link in a new tab\tShift+LMB"), ::mainWindow, SLOT( onOpenPageInNewTab() ) ); - m->addAction( i18n("Open Link in a new background tab\tCtrl+LMB"), ::mainWindow, SLOT( onOpenPageInNewBackgroundTab() ) ); - m->addSeparator(); - m_newTabLinkKeeper = link; - } - - ::mainWindow->setupPopupMenu( m ); - m->exec( e->globalPos() ); - delete m; - -} diff -Nru kchmviewer-4.1/src/kchmviewwindow_qtextbrowser.h kchmviewer-5.1/src/kchmviewwindow_qtextbrowser.h --- kchmviewer-4.1/src/kchmviewwindow_qtextbrowser.h 2009-07-20 04:36:53.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow_qtextbrowser.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,115 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMVIEWWINDOW_QTEXTBROWSER_H -#define KCHMVIEWWINDOW_QTEXTBROWSER_H - -#include "kde-qt.h" - -#include "kchmviewwindow.h" - - -class KCHMViewWindow_QTextBrowser : public QTextBrowser, public KCHMViewWindow -{ - Q_OBJECT - public: - KCHMViewWindow_QTextBrowser( QTabWidget * parent ); - ~KCHMViewWindow_QTextBrowser(); - - //! Open a page from current chm archive - virtual bool openPage (const QString& url); - - //! Invalidate current view, doing all the cleanups etc. - virtual void invalidate(); - - //! Return current ZoomFactor. - virtual int getZoomFactor() const { return m_zoomfactor; } - - //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. - virtual void setZoomFactor (int zoom); - - //! Relatively changes ZoomFactor. Most common values are -1 and 1. - virtual void addZoomFactor (int value); - - //! Popups the print dialog, and prints the current page on the printer. - virtual bool printCurrentPage(); - - //! Select the content of the whole page - virtual void clipSelectAll(); - - //! Copies the selected content to the clipboard - virtual void clipCopy(); - - //! Implements "find in page" functionality - virtual void find( const QString& text, int flags ); - virtual void onFindNext(); - virtual void onFindPrevious(); - - /*! - * Return current scrollbar position in view window. Saved on program exit. - * There is no restriction on returned value, except that giving this value to - * setScrollbarPosition() should move the scrollbar in the same position. - */ - virtual int getScrollbarPosition(); - - //! Sets the scrollbar position. - virtual void setScrollbarPosition(int pos); - - virtual QObject * getQObject() { return this; } - virtual QWidget * getQWidget() { return this; } - - static QString decodeUrl( const QString &url ); - - signals: - /*! - * Emitted when the user clicked on the link, before the page changed. - * If linkClicked() sets follow_link to false, the current page should NOT change. - * Otherwise it should be changed to the new link value. - */ - void linkClicked ( const QString & newlink, bool& follow_link ); - - private slots: - virtual void onAnchorClicked ( const QUrl& url); - - private: - // Overloaded to provide custom context menu - void contextMenuEvent( QContextMenuEvent *e ); - - void find( bool forward, bool backward ); - - QMenu * createPopupMenu ( const QPoint & pos ); - - // Overriden to change the source - void setSource ( const QUrl & name ); - - // Overriden to load resources - QVariant loadResource ( int type, const QUrl & name ); - - int m_zoomfactor; - bool m_allowSourceChange; - - // Search data - QString m_searchText; - int m_flags; -}; - - -#endif /* KCHMVIEWWINDOW_QTEXTBROWSER_H */ diff -Nru kchmviewer-4.1/src/kchmviewwindow_qtwebkit.cpp kchmviewer-5.1/src/kchmviewwindow_qtwebkit.cpp --- kchmviewer-4.1/src/kchmviewwindow_qtwebkit.cpp 2009-07-20 04:36:51.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow_qtwebkit.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,397 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -// Only compile this file if Qt WEBKIT is present -#if defined (QT_WEBKIT_LIB) - -#include -#include - -#include -#include -#include -#include - -#include "kde-qt.h" -#include "libchmurlfactory.h" -#include "kchmconfig.h" -#include "kchmmainwindow.h" -#include "kchmviewwindowmgr.h" -#include "kchmviewwindow_qtwebkit.h" - - -// -// A network reply to emulate data transfer from CHM file -// -class KCHMNetworkReply : public QNetworkReply -{ - public: - KCHMNetworkReply( const QNetworkRequest &request, const QUrl &url ) - { - setRequest( request ); - setOpenMode( QIODevice::ReadOnly ); - - m_data = loadResource( url ); - m_length = m_data.length(); - - setHeader( QNetworkRequest::ContentLengthHeader, QByteArray::number(m_data.length()) ); - QTimer::singleShot( 0, this, SIGNAL(metaDataChanged()) ); - QTimer::singleShot( 0, this, SIGNAL(readyRead()) ); - } - - virtual qint64 bytesAvailable() const - { - return m_data.length() + QNetworkReply::bytesAvailable(); - } - - virtual void abort() - { - } - - protected: - virtual qint64 readData(char *buffer, qint64 maxlen) - { - qint64 len = qMin(qint64(m_data.length()), maxlen); - if (len) - { - qMemCopy(buffer, m_data.constData(), len); - m_data.remove(0, len); - } - - if (!m_data.length()) - QTimer::singleShot(0, this, SIGNAL(finished())); - return len; - } - - QByteArray loadResource( const QUrl &url ) - { - QString data, file, path = url.path(); //toString( QUrl::StripTrailingSlash ); - - // Retreive the data from chm file - LCHMFile * chm = ::mainWindow->chmFile(); - - if ( !chm ) - return QByteArray(); - - int pos = path.indexOf('#'); - if ( pos != -1 ) - path = path.left (pos); - - // To handle a single-image pages, we need to generate the HTML page to show - // this image. We did it in KCHMViewWindow::handleStartPageAsImage; now we need - // to generate the HTML page, and set it. - if ( LCHMUrlFactory::handleFileType( path, data ) ) - return qPrintable( data ); - - QByteArray buf; - - if ( path.endsWith( ".html", Qt::CaseInsensitive ) - || path.endsWith( ".htm", Qt::CaseInsensitive ) ) - { - // If encoding autodetection is enabled, decode it. Otherwise pass as binary. - if ( appConfig.m_advAutodetectEncoding ) - { - if ( !chm->getFileContentAsString( &data, path ) ) - qWarning( "Could not resolve file %s\n", qPrintable( path ) ); - - setHeader( QNetworkRequest::ContentTypeHeader, "text/html" ); - buf = qPrintable( data ); - } - else - { - if ( !chm->getFileContentAsBinary( &buf, path ) ) - qWarning( "Could not resolve file %s\n", qPrintable( path ) ); - - setHeader( QNetworkRequest::ContentTypeHeader, "text/html" ); - } - } - else - { - QString fpath = KCHMViewWindow_QtWebKit::decodeUrl( path ); - - if ( !chm->getFileContentAsBinary( &buf, fpath ) ) - qWarning( "Could not resolve file %s\n", qPrintable( path ) ); - - setHeader( QNetworkRequest::ContentTypeHeader, "binary/octet" ); - } - - return buf; - } - - private: - QByteArray m_data; - qint64 m_length; -}; - - -// -// A network manager to emulate data transfer from CHM file -// -class KCHMNetworkAccessManager : public QNetworkAccessManager -{ - public: - KCHMNetworkAccessManager( QObject *parent ) - : QNetworkAccessManager(parent) - { - } - - protected: - virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) - { - const QString scheme = request.url().scheme(); - - if ( scheme == QLatin1String("ms-its") ) - return new KCHMNetworkReply( request, request.url() ); - - return QNetworkAccessManager::createRequest(op, request, outgoingData); - } -}; - - - - -// -// Webkit browser -// -KCHMViewWindow_QtWebKit::KCHMViewWindow_QtWebKit( QTabWidget * parent ) - : QWebView ( parent ), KCHMViewWindow ( parent ) -{ - m_zoomfactor = 1; - invalidate(); - - page()->setNetworkAccessManager(new KCHMNetworkAccessManager(this)); - - page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); - connect( this, SIGNAL( linkClicked ( const QUrl& ) ), this, SLOT( onAnchorClicked ( const QUrl& ) ) ); -} - - -KCHMViewWindow_QtWebKit::~KCHMViewWindow_QtWebKit() -{ -} - - -bool KCHMViewWindow_QtWebKit::openPage (const QString& url) -{ - if ( m_allowSourceChange ) - { - // Do URI decoding, qtextbrowser does stupid job. - QString fixedname = decodeUrl( url ); - - if ( !fixedname.startsWith( "ms-its://" ) ) - fixedname = "ms-its://" + fixedname; - - setUrl( fixedname ); - } - else - m_allowSourceChange = true; - - return true; -} - - -void KCHMViewWindow_QtWebKit::setZoomFactor( int zoom ) -{ - m_zoomfactor = zoom; - setTextSizeMultiplier ( 1.0 + m_zoomfactor * 0.5 ); -} - -void KCHMViewWindow_QtWebKit::invalidate( ) -{ - m_zoomfactor = 1; - m_allowSourceChange = true; - setTextSizeMultiplier( 1.0 ); - reload(); - - KCHMViewWindow::invalidate( ); -} - -int KCHMViewWindow_QtWebKit::getScrollbarPosition( ) -{ - return page()->currentFrame()->scrollBarValue( Qt::Vertical ); -} - -void KCHMViewWindow_QtWebKit::setScrollbarPosition( int pos ) -{ - page()->currentFrame()->setScrollBarValue( Qt::Vertical, pos ); -} - -void KCHMViewWindow_QtWebKit::addZoomFactor( int value ) -{ - setZoomFactor( m_zoomfactor + value ); -} - -void KCHMViewWindow_QtWebKit::onAnchorClicked(const QUrl & url) -{ - emit linkClicked( url.path(), m_allowSourceChange ); -} - - -bool KCHMViewWindow_QtWebKit::printCurrentPage( ) -{ - QPrinter printer( QPrinter::HighResolution ); - - QPrintDialog dlg( &printer, this ); - - if ( dlg.exec() != QDialog::Accepted ) - { - ::mainWindow->showInStatusBar( i18n( "Printing aborted") ); - return false; - } - - print( &printer ); - ::mainWindow->showInStatusBar( i18n( "Printing finished") ); - return true; -} - - -void KCHMViewWindow_QtWebKit::clipSelectAll( ) -{ - QMessageBox::information( 0, "Not implemented", "Not implemented" ); -// selectAll(); -} - - -void KCHMViewWindow_QtWebKit::clipCopy( ) -{ - triggerPageAction( QWebPage::Copy ); -} - - -// Shamelessly stolen from Qt -QString KCHMViewWindow_QtWebKit::decodeUrl( const QString &input ) -{ - QString temp; - - int i = 0; - int len = input.length(); - int a, b; - QChar c; - while (i < len) - { - c = input[i]; - if (c == '%' && i + 2 < len) - { - a = input[++i].unicode(); - b = input[++i].unicode(); - - if (a >= '0' && a <= '9') - a -= '0'; - else if (a >= 'a' && a <= 'f') - a = a - 'a' + 10; - else if (a >= 'A' && a <= 'F') - a = a - 'A' + 10; - - if (b >= '0' && b <= '9') - b -= '0'; - else if (b >= 'a' && b <= 'f') - b = b - 'a' + 10; - else if (b >= 'A' && b <= 'F') - b = b - 'A' + 10; - - temp.append( (QChar)((a << 4) | b ) ); - } - else - { - temp.append( c ); - } - - ++i; - } - - return temp; -} - - -QMenu * KCHMViewWindow_QtWebKit::createPopupMenu( const QPoint & pos ) -{ - QMenu * menu = getContextMenu( anchorAt( pos ), this ); - menu->exec( pos ); - - return 0; -} - - -void KCHMViewWindow_QtWebKit::find(const QString & text, int flags) -{ - m_searchText = text; - m_flags = flags; - - find( false, false ); -} - -void KCHMViewWindow_QtWebKit::onFindNext() -{ - find( true, false ); -} - -void KCHMViewWindow_QtWebKit::onFindPrevious() -{ - find( false, true ); -} - -void KCHMViewWindow_QtWebKit::find( bool , bool backward ) -{ - QWebPage::FindFlags flags = QWebPage::FindWrapsAroundDocument; - - if ( backward ) - flags |= QWebPage::FindBackward; - - if ( m_flags & SEARCH_CASESENSITIVE ) - flags |= QWebPage::FindCaseSensitively; - - if ( findText( m_searchText, flags ) ) - ::mainWindow->viewWindowMgr()->indicateFindResultStatus( KCHMViewWindowMgr::SearchResultFound ); - else - ::mainWindow->viewWindowMgr()->indicateFindResultStatus( KCHMViewWindowMgr::SearchResultNotFound ); -} - -void KCHMViewWindow_QtWebKit::contextMenuEvent(QContextMenuEvent * e) -{ - // From Qt Assistant - QMenu *m = new QMenu(0); - QString link = anchorAt( e->pos() ); - - if ( !link.isEmpty() ) - { - m->addAction( i18n("Open Link in a new tab\tShift+LMB"), ::mainWindow, SLOT( onOpenPageInNewTab() ) ); - m->addAction( i18n("Open Link in a new background tab\tCtrl+LMB"), ::mainWindow, SLOT( onOpenPageInNewBackgroundTab() ) ); - m->addSeparator(); - m_newTabLinkKeeper = link; - } - - ::mainWindow->setupPopupMenu( m ); - m->exec( e->globalPos() ); - delete m; -} - -QString KCHMViewWindow_QtWebKit::anchorAt(const QPoint & pos) -{ - QWebHitTestResult res = page()->currentFrame()->hitTestContent( pos ); - - if ( !res.linkUrl().isValid() ) - return QString::null; - - return res.linkUrl().path(); -} - -#endif // #if defined (QT_WEBKIT_LIB) - diff -Nru kchmviewer-4.1/src/kchmviewwindow_qtwebkit.h kchmviewer-5.1/src/kchmviewwindow_qtwebkit.h --- kchmviewer-4.1/src/kchmviewwindow_qtwebkit.h 2009-07-20 04:36:48.000000000 +0100 +++ kchmviewer-5.1/src/kchmviewwindow_qtwebkit.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,115 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef KCHMVIEWWINDOW_QTWEBKIT_H -#define KCHMVIEWWINDOW_QTWEBKIT_H - -#include - -#include "kde-qt.h" -#include "kchmviewwindow.h" - - -class KCHMViewWindow_QtWebKit : public QWebView, public KCHMViewWindow -{ - Q_OBJECT - public: - KCHMViewWindow_QtWebKit( QTabWidget * parent ); - ~KCHMViewWindow_QtWebKit(); - - //! Open a page from current chm archive - virtual bool openPage (const QString& url); - - //! Invalidate current view, doing all the cleanups etc. - virtual void invalidate(); - - //! Return current ZoomFactor. - virtual int getZoomFactor() const { return m_zoomfactor; } - - //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. - virtual void setZoomFactor (int zoom); - - //! Relatively changes ZoomFactor. Most common values are -1 and 1. - virtual void addZoomFactor (int value); - - //! Popups the print dialog, and prints the current page on the printer. - virtual bool printCurrentPage(); - - //! Select the content of the whole page - virtual void clipSelectAll(); - - //! Copies the selected content to the clipboard - virtual void clipCopy(); - - //! Implements "find in page" functionality - virtual void find( const QString& text, int flags ); - virtual void onFindNext(); - virtual void onFindPrevious(); - - /*! - * Return current scrollbar position in view window. Saved on program exit. - * There is no restriction on returned value, except that giving this value to - * setScrollbarPosition() should move the scrollbar in the same position. - */ - virtual int getScrollbarPosition(); - - //! Sets the scrollbar position. - virtual void setScrollbarPosition(int pos); - - virtual QObject * getQObject() { return this; } - virtual QWidget * getQWidget() { return this; } - - static QString decodeUrl( const QString &url ); - - signals: - /*! - * Emitted when the user clicked on the link, before the page changed. - * If linkClicked() sets follow_link to false, the current page should NOT change. - * Otherwise it should be changed to the new link value. - */ - void linkClicked ( const QString & newlink, bool& follow_link ); - - private slots: - virtual void onAnchorClicked ( const QUrl& url); - - private: - // Overloaded to provide custom context menu - void contextMenuEvent( QContextMenuEvent *e ); - - void find( bool forward, bool backward ); - - QMenu * createPopupMenu ( const QPoint & pos ); - - // Overriden to change the source - void setSource ( const QUrl & name ); - - QString anchorAt( const QPoint & pos ); - - int m_zoomfactor; - bool m_allowSourceChange; - - // Search data - QString m_searchText; - int m_flags; -}; - - -#endif /* KCHMVIEWWINDOW_QTWEBKIT_H */ diff -Nru kchmviewer-4.1/src/kde/CMakeLists.txt kchmviewer-5.1/src/kde/CMakeLists.txt --- kchmviewer-4.1/src/kde/CMakeLists.txt 2008-06-10 01:46:56.000000000 +0100 +++ kchmviewer-5.1/src/kde/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ -KDE4_INSTALL_ICONS( ${KDE4_ICON_INSTALL_DIR} ) -KDE4_UPDATE_ICONCACHE( ) - Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/kde/cr128-app-kchmviewer.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/kde/cr128-app-kchmviewer.png differ Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/kde/cr48-app-kchmviewer.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/kde/cr48-app-kchmviewer.png differ Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/kde/cr64-app-kchmviewer.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/kde/cr64-app-kchmviewer.png differ diff -Nru kchmviewer-4.1/src/kde/kchmviewer.desktop kchmviewer-5.1/src/kde/kchmviewer.desktop --- kchmviewer-4.1/src/kde/kchmviewer.desktop 2009-02-23 09:04:28.000000000 +0000 +++ kchmviewer-5.1/src/kde/kchmviewer.desktop 1970-01-01 01:00:00.000000000 +0100 @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=KchmViewer -Categories=Qt;KDE;Office;Viewer; -Terminal=false -Type=Application -Exec=kchmviewer %f -Icon=kchmviewer -GenericName=CHM file viewer -Comment=A viewer of CHM (MS-Help) files -MimeType=application/chm;application/x-chm; diff -Nru kchmviewer-4.1/src/kde/kchmviewwindow_khtmlpart.cpp kchmviewer-5.1/src/kde/kchmviewwindow_khtmlpart.cpp --- kchmviewer-4.1/src/kde/kchmviewwindow_khtmlpart.cpp 2008-06-19 00:34:09.000000000 +0100 +++ kchmviewer-5.1/src/kde/kchmviewwindow_khtmlpart.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,169 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 - -#include -#include - -#include "kde-qt.h" -#include "kchmmainwindow.h" -#include "kchmconfig.h" -#include "kchmviewwindow_khtmlpart.h" - - -QWidget * KCHMViewWindow_KHTMLPart::getQWidget() -{ - return view(); -} - -KCHMViewWindow_KHTMLPart::KCHMViewWindow_KHTMLPart( QTabWidget * parent ) - : KHTMLPart ( parent ), KCHMViewWindow ( parent ) -{ - m_zoomfactor = 0; - m_currentEncoding = 0; - - invalidate(); - - connect( browserExtension(), SIGNAL( openUrlRequest( const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments& ) ), - this, SLOT ( onOpenURLRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& )) ); - - connect( this, SIGNAL ( popupMenu ( const QString &, const QPoint &) ), - this, SLOT ( onPopupMenu ( const QString &, const QPoint &) ) ); -} - - -KCHMViewWindow_KHTMLPart::~KCHMViewWindow_KHTMLPart() -{ -} - -bool KCHMViewWindow_KHTMLPart::openPage (const QString& url) -{ - // Set or change the encoding - if ( m_currentEncoding != ::mainWindow->chmFile()->currentEncoding() - && appConfig.m_advAutodetectEncoding ) - { - m_currentEncoding = ::mainWindow->chmFile()->currentEncoding(); - setEncoding ( m_currentEncoding->qtcodec, TRUE ); - } - - QString fullurl = "ms-its:" + ::mainWindow->getOpenedFileName() + "::" + url; - KHTMLPart::openUrl ( KUrl(fullurl) ); - - return true; -} - -void KCHMViewWindow_KHTMLPart::setZoomFactor( int zoom ) -{ - m_zoomfactor = zoom; - - // Default ZoomFactor is 100, any increase or decrease should modify this value. - KHTMLPart::setZoomFactor ( 100 + (m_zoomfactor * 10) ); -} - -void KCHMViewWindow_KHTMLPart::invalidate( ) -{ - m_zoomfactor = 0; - - setJScriptEnabled ( appConfig.m_kdeEnableJS ); - setJavaEnabled ( appConfig.m_kdeEnableJava ); - setMetaRefreshEnabled ( appConfig.m_kdeEnableRefresh ); - setPluginsEnabled ( appConfig.m_kdeEnablePlugins ); - - KCHMViewWindow::invalidate( ); -} - -int KCHMViewWindow_KHTMLPart::getScrollbarPosition( ) -{ - return view()->contentsY (); -} - -void KCHMViewWindow_KHTMLPart::setScrollbarPosition( int pos ) -{ - view()->scrollBy (0, pos); -} - -void KCHMViewWindow_KHTMLPart::addZoomFactor( int value ) -{ - setZoomFactor( m_zoomfactor + value); -} - -bool KCHMViewWindow_KHTMLPart::printCurrentPage() -{ - view()->print(); - return true; -} - -void KCHMViewWindow_KHTMLPart::onOpenURLRequest( const KUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& ) -{ - bool notused; - emit linkClicked ( url.prettyUrl(), notused ); -} - -void KCHMViewWindow_KHTMLPart::slotLinkClicked( const QString & newlink ) -{ - bool notused; - emit linkClicked (newlink, notused); -} - - -void KCHMViewWindow_KHTMLPart::clipSelectAll() -{ - selectAll (); -} - -void KCHMViewWindow_KHTMLPart::clipCopy() -{ - QString text = selectedText(); - - if ( !text.isEmpty() ) - QApplication::clipboard()->setText( text ); -} - -void KCHMViewWindow_KHTMLPart::onPopupMenu ( const QString &url, const QPoint & point ) -{ - QMenu * menu = getContextMenu( url, view() ); - menu->exec( point ); -} - - -void KCHMViewWindow_KHTMLPart::find( const QString& text, int flags ) -{ - long options = 0; - - if ( flags & SEARCH_CASESENSITIVE ) - options |= KFind::CaseSensitive; - - if ( flags & SEARCH_WHOLEWORDS ) - options |= KFind::WholeWordsOnly; - - findText ( text, options, ::mainWindow, 0 ); -} - -void KCHMViewWindow_KHTMLPart::onFindNext() -{ - findTextNext( false ); -} - -void KCHMViewWindow_KHTMLPart::onFindPrevious() -{ - findTextNext( true ); -} diff -Nru kchmviewer-4.1/src/kde/kchmviewwindow_khtmlpart.h kchmviewer-5.1/src/kde/kchmviewwindow_khtmlpart.h --- kchmviewer-4.1/src/kde/kchmviewwindow_khtmlpart.h 2008-06-10 01:46:56.000000000 +0100 +++ kchmviewer-5.1/src/kde/kchmviewwindow_khtmlpart.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,105 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 KCHMVIEWWINDOW_KHTMLPART_H -#define KCHMVIEWWINDOW_KHTMLPART_H - -#include -#include "kde-qt.h" - -#include "kchmviewwindow.h" -#include "libchmtextencoding.h" - - -/** -@author Georgy Yunaev - */ -class KCHMViewWindow_KHTMLPart : public KHTMLPart, public KCHMViewWindow -{ - Q_OBJECT - public: - KCHMViewWindow_KHTMLPart( QTabWidget * parent ); - ~KCHMViewWindow_KHTMLPart(); - - //! Open a page from current chm archive - virtual bool openPage (const QString& url); - - //! Invalidate current view, doing all the cleanups etc. - virtual void invalidate(); - - //! Return current ZoomFactor. - virtual int getZoomFactor() const { return m_zoomfactor; } - - //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. - virtual void setZoomFactor (int zoom); - - //! Relatively changes ZoomFactor. Most common values are -1 and 1. - virtual void addZoomFactor (int value); - - //! Popups the print dialog, and prints the current page on the printer. - virtual bool printCurrentPage(); - - //! Select the content of the whole page - virtual void clipSelectAll(); - - //! Copies the selected content to the clipboard - virtual void clipCopy(); - - //! Implements "find in page" functionality - virtual void find( const QString& text, int flags ); - virtual void onFindNext(); - virtual void onFindPrevious(); - - /*! - * Return current scrollbar position in view window. Saved on program exit. - * There is no restriction on returned value, except that giving this value to - * setScrollbarPosition() should move the scrollbar in the same position. - */ - virtual int getScrollbarPosition(); - - //! Sets the scrollbar position. - virtual void setScrollbarPosition(int pos); - - virtual QObject * getQObject() { return this; } - virtual QWidget * getQWidget(); - - signals: - /*! - * Emitted when the user clicked on the link, before the page changed. - * If linkClicked() sets follow_link to false, the current page should NOT change. - * Otherwise it should be changed to the new link value. - */ - void linkClicked ( const QString & newlink, bool& follow_link ); - - private slots: - virtual void slotLinkClicked ( const QString & newlink); - virtual void onOpenURLRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& ); - virtual void onPopupMenu ( const QString & url, const QPoint & point ); - - private: - void setSource ( const QString & name ); - - int m_zoomfactor; - - const LCHMTextEncoding * m_currentEncoding; -}; - -#endif /* KCHMVIEWWINDOW_KHTMLPART_H */ diff -Nru kchmviewer-4.1/src/kde/viewwindow_khtmlpart.cpp kchmviewer-5.1/src/kde/viewwindow_khtmlpart.cpp --- kchmviewer-4.1/src/kde/viewwindow_khtmlpart.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/kde/viewwindow_khtmlpart.cpp 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,167 @@ +/************************************************************************** +* Kchmviewer - a CHM file viewer with broad language support * +* Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * +* * +* 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 3 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, see . * +**************************************************************************/ + +#include + +#include +#include + +#include "kde-qt.h" +#include "mainwindow.h" +#include "config.h" +#include "viewwindowmgr.h" +#include "viewwindow_khtmlpart.h" + + +QWidget * ViewWindow_KHTMLPart::getQWidget() +{ + return view(); +} + +ViewWindow_KHTMLPart::ViewWindow_KHTMLPart( ViewWindowTabs * parent ) + : KHTMLPart ( parent ), ViewWindow ( parent ) +{ + m_zoomfactor = 0; + m_currentEncoding = 0; + + invalidate(); + + connect( browserExtension(), SIGNAL( openUrlRequest( const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments& ) ), + this, SLOT ( onOpenURLRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& )) ); + + connect( this, SIGNAL ( popupMenu ( const QString &, const QPoint &) ), + this, SLOT ( onPopupMenu ( const QString &, const QPoint &) ) ); +} + + +ViewWindow_KHTMLPart::~ViewWindow_KHTMLPart() +{ +} + +bool ViewWindow_KHTMLPart::openPage (const QString& url) +{ + // Set or change the encoding + if ( m_currentEncoding != ::mainWindow->chmFile()->currentEncoding() + && pConfig->m_advAutodetectEncoding ) + { + m_currentEncoding = ::mainWindow->chmFile()->currentEncoding(); + setEncoding ( m_currentEncoding->qtcodec, TRUE ); + } + + QString fullurl = "ms-its:" + ::mainWindow->getOpenedFileName() + "::" + url; + KHTMLPart::openUrl ( KUrl(fullurl) ); + + return true; +} + +void ViewWindow_KHTMLPart::setZoomFactor( int zoom ) +{ + m_zoomfactor = zoom; + + // Default ZoomFactor is 100, any increase or decrease should modify this value. + KHTMLPart::setFontScaleFactor ( 100 + (m_zoomfactor * 10) ); +} + +void ViewWindow_KHTMLPart::invalidate( ) +{ + m_zoomfactor = 0; + + setJScriptEnabled ( pConfig->m_kdeEnableJS ); + setJavaEnabled ( pConfig->m_kdeEnableJava ); + setMetaRefreshEnabled ( pConfig->m_kdeEnableRefresh ); + setPluginsEnabled ( pConfig->m_kdeEnablePlugins ); + + ViewWindow::invalidate( ); +} + +int ViewWindow_KHTMLPart::getScrollbarPosition( ) +{ + return view()->contentsY (); +} + +void ViewWindow_KHTMLPart::setScrollbarPosition( int pos ) +{ + view()->scrollBy (0, pos); +} + +void ViewWindow_KHTMLPart::addZoomFactor( int value ) +{ + setZoomFactor( m_zoomfactor + value); +} + +bool ViewWindow_KHTMLPart::printCurrentPage() +{ + view()->print(); + return true; +} + +void ViewWindow_KHTMLPart::onOpenURLRequest( const KUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& ) +{ + bool notused; + emit linkClicked ( url.prettyUrl(), notused ); +} + +void ViewWindow_KHTMLPart::slotLinkClicked( const QString & newlink ) +{ + bool notused; + emit linkClicked (newlink, notused); +} + + +void ViewWindow_KHTMLPart::clipSelectAll() +{ + selectAll (); +} + +void ViewWindow_KHTMLPart::clipCopy() +{ + QString text = selectedText(); + + if ( !text.isEmpty() ) + QApplication::clipboard()->setText( text ); +} + +void ViewWindow_KHTMLPart::onPopupMenu ( const QString &url, const QPoint & point ) +{ + QMenu * menu = getContextMenu( url, view() ); + menu->exec( point ); +} + + +void ViewWindow_KHTMLPart::find( const QString& text, int flags ) +{ + long options = 0; + + if ( flags & SEARCH_CASESENSITIVE ) + options |= KFind::CaseSensitive; + + if ( flags & SEARCH_WHOLEWORDS ) + options |= KFind::WholeWordsOnly; + + findText ( text, options, ::mainWindow, 0 ); +} + +void ViewWindow_KHTMLPart::onFindNext() +{ + findTextNext( false ); +} + +void ViewWindow_KHTMLPart::onFindPrevious() +{ + findTextNext( true ); +} diff -Nru kchmviewer-4.1/src/kde/viewwindow_khtmlpart.h kchmviewer-5.1/src/kde/viewwindow_khtmlpart.h --- kchmviewer-4.1/src/kde/viewwindow_khtmlpart.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/kde/viewwindow_khtmlpart.h 2009-12-15 06:27:57.000000000 +0000 @@ -0,0 +1,102 @@ +/************************************************************************** +* Kchmviewer - a CHM file viewer with broad language support * +* Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * +* * +* 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 3 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, see . * +**************************************************************************/ + +#ifndef VIEWWINDOW_KHTMLPART_H +#define VIEWWINDOW_KHTMLPART_H + +#include +#include "kde-qt.h" + +#include "viewwindow.h" +#include "libchmtextencoding.h" + + +/** +@author Georgy Yunaev + */ +class ViewWindow_KHTMLPart : public KHTMLPart, public ViewWindow +{ + Q_OBJECT + public: + ViewWindow_KHTMLPart( ViewWindowTabs * parent ); + ~ViewWindow_KHTMLPart(); + + //! Open a page from current chm archive + virtual bool openPage (const QString& url); + + //! Invalidate current view, doing all the cleanups etc. + virtual void invalidate(); + + //! Return current ZoomFactor. + virtual int getZoomFactor() const { return m_zoomfactor; } + + //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. + virtual void setZoomFactor (int zoom); + + //! Relatively changes ZoomFactor. Most common values are -1 and 1. + virtual void addZoomFactor (int value); + + //! Popups the print dialog, and prints the current page on the printer. + virtual bool printCurrentPage(); + + //! Select the content of the whole page + virtual void clipSelectAll(); + + //! Copies the selected content to the clipboard + virtual void clipCopy(); + + //! Implements "find in page" functionality + virtual void find( const QString& text, int flags ); + virtual void onFindNext(); + virtual void onFindPrevious(); + + /*! + * Return current scrollbar position in view window. Saved on program exit. + * There is no restriction on returned value, except that giving this value to + * setScrollbarPosition() should move the scrollbar in the same position. + */ + virtual int getScrollbarPosition(); + + //! Sets the scrollbar position. + virtual void setScrollbarPosition(int pos); + + virtual QObject * getQObject() { return this; } + virtual QWidget * getQWidget(); + + signals: + /*! + * Emitted when the user clicked on the link, before the page changed. + * If linkClicked() sets follow_link to false, the current page should NOT change. + * Otherwise it should be changed to the new link value. + */ + void linkClicked ( const QString & newlink, bool& follow_link ); + + private slots: + virtual void slotLinkClicked ( const QString & newlink); + virtual void onOpenURLRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments& ); + virtual void onPopupMenu ( const QString & url, const QPoint & point ); + + private: + void setSource ( const QString & name ); + + int m_zoomfactor; + + const LCHMTextEncoding * m_currentEncoding; +}; + +#endif /* VIEWWINDOW_KHTMLPART_H */ diff -Nru kchmviewer-4.1/src/kde-qt.cpp kchmviewer-5.1/src/kde-qt.cpp --- kchmviewer-4.1/src/kde-qt.cpp 2009-07-20 04:36:45.000000000 +0100 +++ kchmviewer-5.1/src/kde-qt.cpp 2009-12-14 01:51:00.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "kde-qt.h" diff -Nru kchmviewer-4.1/src/kde-qt.h kchmviewer-5.1/src/kde-qt.h --- kchmviewer-4.1/src/kde-qt.h 2009-07-20 04:36:42.000000000 +0100 +++ kchmviewer-5.1/src/kde-qt.h 2009-12-14 07:02:52.000000000 +0000 @@ -1,23 +1,20 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef KDE_QT_H #define KDE_QT_H @@ -64,7 +61,6 @@ #endif /* USE_KDE */ // common non-wrapped UI classes -#include #include #include #include @@ -120,7 +116,7 @@ { public: KQTabWidget (QWidget *parent = 0 ) - : KQ_CLASSNAME(TabWidget) (parent) {}; + : KQ_CLASSNAME(TabWidget) (parent) {} }; @@ -137,25 +133,24 @@ #include -class KCHMShowWaitCursor +class ShowWaitCursor { public: - KCHMShowWaitCursor() { QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); } - ~KCHMShowWaitCursor() { QApplication::restoreOverrideCursor(); } + ShowWaitCursor() { QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); } + ~ShowWaitCursor() { QApplication::restoreOverrideCursor(); } }; // Forward declarations -class KCHMMainWindow; -class KCHMViewWindow; -class KCHMIndexWindow; -class KCHMSearchWindow; -class KCHMBookmarkWindow; -class KCHMSettings; -class KCHMSearchAndViewToolbar; -class KCHMViewWindow; -class KCHMViewWindowMgr; -class KCHMContentsWindow; +class MainWindow; +class ViewWindow; +class TabIndex; +class TabSearch; +class TabBookmarks; +class TabContents; +class Settings; +class ViewWindow; +class ViewWindowMgr; #endif /* KDE_QT_H */ diff -Nru kchmviewer-4.1/src/keyeventfilter.cpp kchmviewer-5.1/src/keyeventfilter.cpp --- kchmviewer-4.1/src/keyeventfilter.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/keyeventfilter.cpp 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,53 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include + +#include "keyeventfilter.h" + +KeyEventFilter gKeyEventFilter; + +KeyEventFilter::KeyEventFilter() + : QObject() +{ + m_shiftPressed = false; + m_ctrlPressed = false; +} + +bool KeyEventFilter::eventFilter( QObject *, QEvent *e ) +{ + // Handle KeyPress and KeyRelease events + if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) + { + bool * ptr = 0; + QKeyEvent *k = (QKeyEvent *) e; + + // We're interested only in Shift and Control + if ( k->key() == Qt::Key_Shift ) + ptr = &m_shiftPressed; + else if ( k->key() == Qt::Key_Control ) + ptr = &m_ctrlPressed; + + // Set it + if ( ptr ) + *ptr = e->type() == QEvent::KeyPress ? true : false; + } + + return FALSE; // Standard event processing +} diff -Nru kchmviewer-4.1/src/keyeventfilter.h kchmviewer-5.1/src/keyeventfilter.h --- kchmviewer-4.1/src/keyeventfilter.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/keyeventfilter.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,48 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef KEYEVENTFILTER_H +#define KEYEVENTFILTER_H + +#include +#include + + +/*!* + * This class must be installed as a global event handler. Its responsibility + * is to intercept keyboard events, and store the Shift and Ctrl keys state information. + * Unfortunately it seems to be the only way to do it in Qt. + */ +class KeyEventFilter : public QObject +{ + public: + KeyEventFilter(); + + bool isShiftPressed() const { return m_shiftPressed; } + bool isCtrlPressed() const { return m_ctrlPressed; } + + private: + bool eventFilter( QObject *, QEvent *e ); + + bool m_shiftPressed; + bool m_ctrlPressed; +}; + +extern KeyEventFilter gKeyEventFilter; + +#endif /* INCLUDE_KCHMKEYEVENTFILTER_H */ diff -Nru kchmviewer-4.1/src/main.cpp kchmviewer-5.1/src/main.cpp --- kchmviewer-4.1/src/main.cpp 2009-07-20 04:36:37.000000000 +0100 +++ kchmviewer-5.1/src/main.cpp 2009-12-15 06:27:57.000000000 +0000 @@ -1,30 +1,27 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #include "kde-qt.h" -#include "kchmmainwindow.h" -#include "kchmconfig.h" -#include "kchmkeyeventfilter.h" -#include "kchmdbusiface.h" +#include "mainwindow.h" +#include "config.h" +#include "keyeventfilter.h" +#include "dbus_interface.h" #include "version.h" #if !defined (WIN32) @@ -35,7 +32,7 @@ #include #endif -KCHMMainWindow * mainWindow; +MainWindow * mainWindow; int main( int argc, char ** argv ) @@ -51,8 +48,8 @@ KAboutData aboutdata ( "kchmviewer", QByteArray(), - ki18n(APP_NAME), - APP_VERSION, + ki18n("kchmviewer"), + qPrintable( QString("%1.%2") .arg(APP_VERSION_MAJOR) .arg(APP_VERSION_MINOR) ), ki18n("CHM file viewer"), KAboutData::License_GPL, ki18n("(c) 2004-2008 George Yunaev, gyunaev@ulduzsoft.com"), @@ -68,7 +65,14 @@ QApplication app( argc, argv ); #endif - appConfig.load(); + // Set data for QSettings + QCoreApplication::setOrganizationName("Ulduzsoft"); + QCoreApplication::setOrganizationDomain("kchmviewer.net"); + QCoreApplication::setApplicationName("kchmviewer"); + + // Configuration + pConfig = new Config(); + app.installEventFilter( &gKeyEventFilter ); #if !defined (WIN32) @@ -76,7 +80,7 @@ { if ( QDBusConnection::sessionBus().registerService(SERVICE_NAME) ) { - KCHMDBusIface * dbusiface = new KCHMDBusIface(); + DBusInterface * dbusiface = new DBusInterface(); QDBusConnection::sessionBus().registerObject( "/", dbusiface, QDBusConnection::ExportAllSlots ); } else @@ -86,11 +90,10 @@ qWarning( "Cannot connect to the D-BUS session bus. Going without D-BUS support." ); #endif - mainWindow = new KCHMMainWindow(); + mainWindow = new MainWindow(); mainWindow->show(); app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) ); return app.exec(); } - diff -Nru kchmviewer-4.1/src/mainwindow.cpp kchmviewer-5.1/src/mainwindow.cpp --- kchmviewer-4.1/src/mainwindow.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/mainwindow.cpp 2009-12-17 09:38:59.000000000 +0000 @@ -0,0 +1,1289 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include +#include +#include + +#include "kde-qt.h" + +#include "libchmfile.h" +#include "libchmfileimpl.h" +#include "libchmurlfactory.h" + +#include "mainwindow.h" +#include "config.h" +#include "treeviewitem.h" +#include "settings.h" +#include "viewwindow.h" +#include "viewwindowmgr.h" +#include "keyeventfilter.h" +#include "dialog_setup.h" +#include "recentfiles.h" +#include "navigationpanel.h" +#include "version.h" +#include "ui_dialog_about.h" + + +MainWindow::MainWindow() + : QMainWindow ( 0 ), Ui::MainWindow() +{ + const unsigned int WND_X_SIZE = 900; + const unsigned int WND_Y_SIZE = 700; + const unsigned int SPLT_X_SIZE = 300; + + // Delete the pointer when the window is closed + setAttribute( Qt::WA_DeleteOnClose ); + + // UIC stuff + setupUi( this ); + + // Set up layout direction + if ( pConfig->m_advLayoutDirectionRL ) + qApp->setLayoutDirection( Qt::RightToLeft ); + else + qApp->setLayoutDirection( Qt::LeftToRight ); + + m_chmFile = 0; + m_autoteststate = STATE_OFF; + + m_currentSettings = new Settings(); + + // Create the view window, which is a central widget + m_viewWindowMgr = new ViewWindowMgr( this ); + setCentralWidget( m_viewWindowMgr ); + + // Create a navigation panel + m_navPanel = new NavigationPanel( this ); + + // Add navigation dock + m_navPanel->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + addDockWidget( Qt::LeftDockWidgetArea, m_navPanel, Qt::Vertical ); + + // Set up things + setupActions(); + updateToolbars(); + setupLangEncodingMenu(); + + // Resize main window and dock + resize( WND_X_SIZE, WND_Y_SIZE ); + m_navPanel->resize( SPLT_X_SIZE, m_navPanel->height() ); + + statusBar()->show(); + + qApp->setWindowIcon( QPixmap(":/images/application.png") ); + + m_recentFiles = new RecentFiles( menu_File, file_exit_action, pConfig->m_numOfRecentFiles ); + connect( m_recentFiles, SIGNAL(openRecentFile(QString)), this, SLOT(actionOpenRecentFile(QString)) ); + + // Basically disable everything + updateActions(); + + // Check for a new version if needed + if ( pConfig->m_advCheckNewVersion ) + { + QSettings settings; + + if ( settings.contains( "advanced/lastupdate" ) ) + { + QDateTime lastupdate = settings.value( "advanced/lastupdate" ).toDateTime(); + + if ( lastupdate.secsTo( QDateTime::currentDateTime() ) >= 86400 * 7 ) // seven days + checkNewVersionAvailable(); + } + } + + QTimer::singleShot( 0, this, SLOT( firstShow()) ); +} + +MainWindow::~MainWindow() +{ + // Temporary files cleanup + while ( !m_tempFileKeeper.isEmpty() ) + delete m_tempFileKeeper.takeFirst(); +} + +void MainWindow::checkNewVersionAvailable() +{ + // Create a New version available object if necessary. This object will auto-delete itself + CheckNewVersion * pNewVer = new CheckNewVersion(); + + connect( pNewVer, SIGNAL(error(int)), this, SLOT(newVerAvailError(int)) ); + connect( pNewVer, SIGNAL(newVersionAvailable( NewVersionMetaMap )), this, SLOT(newVerAvailable(NewVersionMetaMap)) ); + + pNewVer->setUrl( "http://www.kchmviewer.net/latestversion.txt" ); + pNewVer->start(); +} + + +bool MainWindow::loadFile ( const QString &loadFileName, bool call_open_page ) +{ + QString fileName = loadFileName; + + // Strip file:// prefix if any + if ( fileName.startsWith( "file://" ) ) + fileName.remove( 0, 7 ); + + LCHMFile * new_chmfile = new LCHMFile(); + + if ( new_chmfile->loadFile( fileName ) ) + { + // The new file is opened, so we can close the old one + if ( m_chmFile ) + { + closeFile( ); + delete m_chmFile; + } + + m_chmFile = new_chmfile; + updateActions(); + + // Show current encoding in status bar + showInStatusBar( i18n("Detected file encoding: %1 ( %2 )") + .arg( m_chmFile->currentEncoding()->family) + .arg( m_chmFile->currentEncoding()->qtcodec) ); + + // Make the file name absolute; we'll need it later + QDir qd; + qd.setPath (fileName); + m_chmFilename = qd.absolutePath(); + + // Qt's 'dirname' does not work well + QFileInfo qf ( m_chmFilename ); + pConfig->m_lastOpenedDir = qf.dir().path(); + m_chmFileBasename = qf.fileName(); + + // Apply settings to the navigation dock + m_navPanel->updateTabs( m_chmFile ); + + // and to navigation buttons + nav_actionPreviousPage->setEnabled( m_chmFile->hasTableOfContents() ); + nav_actionNextPageToc->setEnabled( m_chmFile->hasTableOfContents() ); + + navSetBackEnabled( false ); + navSetForwardEnabled( false ); + + m_viewWindowMgr->invalidate(); + refreshCurrentBrowser(); + + if ( m_currentSettings->loadSettings (fileName) ) + { + const LCHMTextEncoding * encoding = + m_chmFile->impl()->lookupByQtCodec( m_currentSettings->m_activeEncoding ); + + if ( encoding ) + setTextEncoding( encoding ); + + m_navPanel->applySettings( m_currentSettings ); + + if ( call_open_page ) + { + m_viewWindowMgr->restoreSettings( m_currentSettings->m_viewwindows ); + m_viewWindowMgr->setCurrentPage( m_currentSettings->m_activetabwindow ); + + if ( m_chmFile->hasTableOfContents() ) + actionLocateInContentsTab(); + } + + // Restore the main window size + resize( m_currentSettings->m_window_size_x, m_currentSettings->m_window_size_y ); + m_navPanel->resize( m_currentSettings->m_window_size_splitter, m_navPanel->height() ); + } + else + { + m_navPanel->setActive( NavigationPanel::TAB_CONTENTS ); + setTextEncoding( m_chmFile->currentEncoding() ); + + if ( call_open_page ) + openPage( m_chmFile->homeUrl() ); + } + + m_recentFiles->setCurrentFile( m_chmFilename ); + return true; + } + else + { + QMessageBox mbox( + i18n("%1 - failed to load the chm file") . arg(QCoreApplication::applicationName() ), + i18n("Unable to load the chm file %1") . arg(fileName), + QMessageBox::Critical, + QMessageBox::Ok, + Qt::NoButton, + Qt::NoButton); + mbox.exec(); + + statusBar()->showMessage( + i18n("Could not load file %1").arg(fileName), + 2000 ); + + delete new_chmfile; + return false; + } +} + + + +void MainWindow::refreshCurrentBrowser( ) +{ + QString title = m_chmFile->title(); + + if ( title.isEmpty() ) + title = QCoreApplication::applicationName(); + // KDE adds application name automatically, so we don't need it here +#if !defined (USE_KDE) + else + title = (QString) QCoreApplication::applicationName() + " - " + title; +#endif + + setWindowTitle( title ); + + currentBrowser()->invalidate(); + + m_navPanel->refresh(); +} + + + +void MainWindow::activateLink ( const QString & link, bool& follow_link ) +{ + if ( link.isEmpty() ) + return; + + if ( gKeyEventFilter.isShiftPressed() ) + { + openPage( link, OPF_NEW_TAB | OPF_CONTENT_TREE ); + follow_link = false; + } + else if ( gKeyEventFilter.isCtrlPressed() ) + { + openPage( link, OPF_NEW_TAB | OPF_BACKGROUND ); + follow_link = false; + } + else + // If the openPage failed, we do not need to follow the link. + follow_link = openPage( link, OPF_CONTENT_TREE | OPF_ADD2HISTORY ); +} + + +bool MainWindow::openPage( const QString & srcurl, unsigned int flags ) +{ + QString otherlink, otherfile, url = srcurl; + + if ( url == "/" ) + url = m_chmFile->homeUrl(); + + if ( LCHMUrlFactory::isRemoteURL (url, otherlink) ) + { + switch ( pConfig->m_onExternalLinkClick ) + { + case Config::ACTION_DONT_OPEN: + break; + + case Config::ACTION_ASK_USER: + if ( QMessageBox::question(this, + i18n("%1 - remote link clicked - %2") . arg(QCoreApplication::applicationName()) . arg(otherlink), + i18n("A remote link %1 will start the external program to open it.\n\nDo you want to continue?").arg( url ), + i18n("&Yes"), i18n("&No"), + QString::null, 0, 1 ) ) + return false; + + // no break! should continue to open. + + case Config::ACTION_ALWAYS_OPEN: +#if defined (USE_KDE) + new KRun ( url, 0 ); +#else + QDesktopServices::openUrl( url ); +#endif + break; + } + + return false; // do not change the current page. + } + + // Filter the URLs which do not need to be opened at all by Qt version + if ( LCHMUrlFactory::isJavascriptURL (url) ) + { + QMessageBox::information( this, + i18n( "%1 - JavsScript link clicked") . arg(QCoreApplication::applicationName()), + i18n( "You have clicked a JavaScript link.\nTo prevent security-related issues JavaScript URLs are disabled in CHM files.") ); + + return false; + } + + if ( LCHMUrlFactory::isNewChmURL (url, otherfile, otherlink) ) + { + // If new filename has relative path, convert it to absolute. + QFileInfo finfo( otherfile ); + + if ( !finfo.isAbsolute() ) + { + QFileInfo chmfinfo( m_chmFilename ); + otherfile = chmfinfo.absolutePath() + QDir::separator() + otherfile; + } + + if ( otherfile != m_chmFilename ) + { + if ( QMessageBox::question( this, + i18n( "%1 - link to a new CHM file clicked"). arg(QCoreApplication::applicationName()), + i18n( "You have clicked a link, which leads to a new CHM file %1.\nThe current file will be closed.\n\nDo you want to continue?").arg( otherfile ), + i18n( "&Yes" ), i18n( "&No" ), + QString::null, 0, 1 ) ) + return false; + + // Because chm file always contain relative link, and current filename is not changed, + // we need to form a new path + QStringList event_args; + event_args.push_back( otherfile ); + event_args.push_back( otherlink ); // url + + qApp->postEvent( this, new UserEvent( "loadAndOpen", event_args ) ); + return false; + } + else + url = otherlink; + } + + ViewWindow * vwnd = currentBrowser(); + if ( flags & OPF_NEW_TAB ) + vwnd = m_viewWindowMgr->addNewTab( !(flags & OPF_BACKGROUND) ); + + // Store current page and position to add it to history if we change it + int hist_scrollpos = currentBrowser()->getScrollbarPosition(); + QString hist_url = currentBrowser()->getOpenedPage(); + + if ( vwnd->openUrl (url) ) + { + // Open all the tree items to show current item (if needed) + if ( (flags & OPF_CONTENT_TREE) != 0 ) + m_navPanel->findUrlInContents( url ); + + if ( flags & OPF_ADD2HISTORY ) + currentBrowser()->addNavigationHistory( hist_url, hist_scrollpos ); + } + + return true; +} + + +void MainWindow::firstShow() +{ + if ( !parseCmdLineArgs( ) ) + { + if ( pConfig->m_startupMode == Config::STARTUP_LOAD_LAST_FILE && !m_recentFiles->latestFile().isEmpty() ) + { + loadFile( m_recentFiles->latestFile() ); + return; + } + + if ( pConfig->m_startupMode == Config::STARTUP_POPUP_OPENFILE ) + actionOpenFile(); + } +} + + +void MainWindow::setTextEncoding( const LCHMTextEncoding * encoding ) +{ + m_chmFile->setCurrentEncoding( encoding ); + + // Find the appropriate encoding item in "Set encodings" menu + const QList encodings = m_encodingActions->actions(); + + for ( QList::const_iterator it = encodings.begin(); + it != encodings.end(); + ++it ) + { + const LCHMTextEncoding * enc = (const LCHMTextEncoding *) (*it)->data().value< void* > (); + + if ( !strcmp( enc->qtcodec, encoding->qtcodec ) ) + { + if ( !(*it)->isChecked() ) + (*it)->setChecked( true ); + + break; + } + } + + // Because updateView() will call view->invalidate(), which clears the view->getOpenedPage(), + // we have to make a copy of it. + QString url = currentBrowser()->getOpenedPage(); + + // Regenerate the content and index trees + refreshCurrentBrowser(); + + currentBrowser()->openUrl( url ); +} + +void MainWindow::closeFile( ) +{ + // Prepare the settings + if ( pConfig->m_HistoryStoreExtra ) + { + m_currentSettings->m_activeEncoding = m_chmFile->currentEncoding()->qtcodec; + m_currentSettings->m_activetabwindow = m_viewWindowMgr->currentPageIndex( ); + + m_currentSettings->m_window_size_x = width(); + m_currentSettings->m_window_size_y = height(); + m_currentSettings->m_window_size_splitter = m_navPanel->width(); + + m_navPanel->getSettings( m_currentSettings ); + + m_viewWindowMgr->saveSettings( m_currentSettings->m_viewwindows ); + + m_currentSettings->saveSettings( ); + } + + pConfig->save(); +} + + +void MainWindow::closeEvent ( QCloseEvent * e ) +{ + // Save the settings if we have something opened + if ( m_chmFile ) + { + closeFile( ); + delete m_chmFile; + m_chmFile = 0; + } + + QMainWindow::closeEvent ( e ); +} + +bool MainWindow::parseCmdLineArgs( ) +{ + QString filename = QString::null, search_query = QString::null; + QString search_index = QString::null, search_bookmark = QString::null, search_toc = QString::null; + bool do_autotest = false; + +#if defined (USE_KDE) + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if ( args->isSet("autotestmode") || args->isSet("shortautotestmode") ) + do_autotest = true; + + search_query = args->getOption ("search"); + search_index = args->getOption ("sindex"); + search_toc = args->getOption ("stoc"); + + if ( args->count() > 0 ) + filename = args->arg(0); +#else + // argv[0] in Qt is still a program name + for ( int i = 1; i < qApp->argc(); i++ ) + { + if ( !strcmp (qApp->argv()[i], "-h") || !strcmp (qApp->argv()[i], "--help") ) + { + fprintf (stderr, "Usage: %s [options] [chmfile]\n" + " The following options supported:\n" + " --search specifies the search query to search, and activate the first entry if found\n" + " --sindex specifies the word to find in index, and activate if found\n" + " --stoc specifies the word(s) to find in TOC, and activate if found. Wildcards allowed\n", + qApp->argv()[0] ); + + exit (1); + } + else if ( !strcmp (qApp->argv()[i], "--autotestmode") || !strcmp (qApp->argv()[i], "--shortautotestmode") ) + do_autotest = true; + else if ( !strcmp (qApp->argv()[i], "--search") ) + search_query = qApp->argv()[++i]; + else if ( !strcmp (qApp->argv()[i], "--sindex") ) + search_index = qApp->argv()[++i]; + else if ( !strcmp (qApp->argv()[i], "--stoc") ) + search_toc = qApp->argv()[++i]; + else + filename = QString::fromLocal8Bit( qApp->argv()[i] ); + } +#endif + + if ( !filename.isEmpty() ) + { + if ( !loadFile( filename ) ) + return true; // skip the latest checks, but do not exit from the program + + if ( !search_index.isEmpty() ) + { + QStringList event_args; + event_args.push_back( search_index ); + qApp->postEvent( this, new UserEvent( "findInIndex", event_args ) ); + } + + if ( !search_query.isEmpty() ) + { + QStringList event_args; + event_args.push_back( search_query ); + qApp->postEvent( this, new UserEvent( "searchQuery", event_args ) ); + } + + if ( !search_toc.isEmpty() ) + { + QStringList event_args; + event_args.push_back( search_toc ); + qApp->postEvent( this, new UserEvent( "findInToc", event_args ) ); + } + + if ( do_autotest ) + { + if ( filename.isEmpty() ) + qFatal ("Could not use Auto Test mode without a chm file!"); + + m_autoteststate = STATE_INITIAL; + showMinimized (); + runAutoTest(); + } + return true; + } + + return false; +} + +ViewWindow * MainWindow::currentBrowser( ) const +{ + return m_viewWindowMgr->current(); +} + +void MainWindow::onOpenPageInNewTab( ) +{ + openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_CONTENT_TREE ); +} + +void MainWindow::onOpenPageInNewBackgroundTab( ) +{ + openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_BACKGROUND ); +} + +void MainWindow::browserChanged( ViewWindow * newbrowser ) +{ + m_navPanel->findUrlInContents( newbrowser->getOpenedPage() ); +} + +bool MainWindow::event( QEvent * e ) +{ + if ( e->type() == QEvent::User ) + return handleUserEvent( (UserEvent*) e ); + + return QMainWindow::event( e ); +} + +bool MainWindow::handleUserEvent( const UserEvent * event ) +{ + if ( event->m_action == "loadAndOpen" ) + { + if ( event->m_args.size() != 1 && event->m_args.size() != 2 ) + qFatal("handleUserEvent: event loadAndOpen must receive 1 or 2 args"); + + QString chmfile = event->m_args[0]; + QString openurl = event->m_args.size() > 1 ? event->m_args[1] : "/"; + + return loadFile( chmfile, false ) && openPage( openurl ); + } + else if ( event->m_action == "openPage" ) + { + if ( event->m_args.size() != 1 ) + qFatal("handleUserEvent: event openPage must receive 1 arg"); + + return openPage( event->m_args[0] ); + } + else if ( event->m_action == "findInIndex" ) + { + if ( event->m_args.size() != 1 ) + qFatal( "handleUserEvent: event findInIndex must receive 1 arg" ); + + if ( !hasIndex() ) + return false; + + actionSwitchToIndexTab(); + m_navPanel->findInIndex( event->m_args[0] ); + return true; + } + else if ( event->m_action == "findInToc" ) + { + if ( event->m_args.size() != 1 ) + qFatal( "handleUserEvent: event findInToc must receive 1 arg" ); + + if ( !hasTableOfContents() ) + return false; + + actionSwitchToContentTab(); + m_navPanel->findTextInContents( event->m_args[0] ); + return true; + } + else if ( event->m_action == "searchQuery" ) + { + if ( event->m_args.size() != 1 ) + qFatal( "handleUserEvent: event searchQuery must receive 1 arg" ); + + actionSwitchToSearchTab(); + m_navPanel->executeQueryInSearch( event->m_args[0] ); + return true; + } + else + qWarning( "Unknown user event received: %s", qPrintable( event->m_action ) ); + + return false; +} + + +void MainWindow::runAutoTest() +{ + switch (m_autoteststate) + { + case STATE_INITIAL: + m_autoteststate = STATE_OPEN_INDEX; + + QTimer::singleShot (500, this, SLOT(runAutoTest()) ); + break; // allow to finish the initialization sequence + + case STATE_OPEN_INDEX: + if ( hasIndex() ) + m_navPanel->setActive( NavigationPanel::TAB_INDEX ); + + m_autoteststate = STATE_SHUTDOWN; + QTimer::singleShot (500, this, SLOT(runAutoTest()) ); + break; + + case STATE_SHUTDOWN: + qApp->quit(); + break; + + default: + break; + } +} + +void MainWindow::showInStatusBar(const QString & text) +{ + statusBar()->showMessage( text, 2000 ); +} + +void MainWindow::actionNavigateBack() +{ + currentBrowser()->navigateBack(); +} + +void MainWindow::actionNavigateForward() +{ + currentBrowser()->navigateForward(); +} + +void MainWindow::actionNavigateHome() +{ + currentBrowser()->navigateHome(); +} + +void MainWindow::actionOpenFile() +{ +#if defined (USE_KDE) + QString fn = KFileDialog::getOpenFileName( pConfig->m_lastOpenedDir, i18n("*.chm|Compressed Help Manual (*.chm)"), this); +#else + QString fn = QFileDialog::getOpenFileName( this, + i18n( "Open a chm file"), + pConfig->m_lastOpenedDir, + i18n("Compressed Help Manual (*.chm)"), + 0, + QFileDialog::DontResolveSymlinks ); +#endif + + if ( !fn.isEmpty() ) + loadFile( fn ); +} + +void MainWindow::actionPrint() +{ + currentBrowser()->printCurrentPage(); +} + +void MainWindow::actionEditCopy() +{ + currentBrowser()->clipCopy(); +} + +void MainWindow::actionEditSelectAll() +{ + currentBrowser()->clipSelectAll(); +} + +void MainWindow::actionFindInPage() +{ + m_viewWindowMgr->onActivateFind(); +} + +void MainWindow::actionChangeSettings() +{ + DialogSetup dlg ( this ); + + dlg.exec(); +} + + +void MainWindow::actionExtractCHM() +{ + QStringList files; + +#if defined (USE_KDE) + QString outdir = KFileDialog::getExistingDirectory ( + KUrl(), + this, + i18n("Choose a directory to store CHM content") ); +#else + QString outdir = QFileDialog::getExistingDirectory ( + this, + i18n("Choose a directory to store CHM content"), + QString::null, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); +#endif + + if ( outdir.isEmpty() ) + return; + + outdir += "/"; + + // Enumerate all the files in archive + if ( !m_chmFile || !m_chmFile->enumerateFiles( &files ) ) + return; + + KQProgressModalDialog progress( i18n("Extracting CHM content"), + i18n("Extracting files..."), + i18n("Abort"), + files.size(), + this ); + + for ( int i = 0; i < files.size(); i++ ) + { + progress.setValue( i ); + + if ( (i % 3) == 0 ) + { + qApp->processEvents(); + + if ( progress.wasCancelled() ) + break; + } + + // Extract the file + QByteArray buf; + + if ( m_chmFile->getFileContentAsBinary( &buf, files[i] ) ) + { + // Split filename to get the list of subdirectories + QStringList dirs = files[i].split( '/' ); + + // Walk through the list of subdirectories, and create them if needed + // dirlevel is used to detect extra .. and prevent overwriting files + // outside the directory (like creating the file images/../../../../../etc/passwd + int i, dirlevel = 0; + QStringList dirlist; + + for ( i = 0; i < dirs.size() - 1; i++ ) + { + // Skip .. which lead too far above + if ( dirs[i] == ".." ) + { + if ( dirlevel > 0 ) + { + dirlevel--; + dirlist.pop_back(); + } + } + else + { + dirlist.push_back( dirs[i] ); + + QDir dir ( outdir + dirlist.join( "/" ) ); + if ( !dir.exists() ) + { + if ( !dir.mkdir( dir.path() ) ) + qWarning( "Could not create subdir %s\n", qPrintable( dir.path() ) ); + } + } + } + + QString filename = outdir + dirlist.join( "/" ) + "/" + dirs[i]; + QFile wf( filename ); + if ( !wf.open( QIODevice::WriteOnly ) ) + { + qWarning( "Could not write file %s\n", qPrintable( filename ) ); + continue; + } + + wf. write( buf ); + wf.close(); + } + else + qWarning( "Could not get file %s\n", qPrintable( files[i] ) ); + } + + progress.setValue( files.size() ); +} + +void MainWindow::actionFontSizeIncrease() +{ + currentBrowser()->addZoomFactor( 1 ); +} + +void MainWindow::actionFontSizeDecrease() +{ + currentBrowser()->addZoomFactor( -1 ); +} + +void MainWindow::actionViewHTMLsource() +{ + QString text; + + if ( !m_chmFile->getFileContentAsString( &text, currentBrowser()->getOpenedPage() ) || text.isEmpty() ) + return; + + if ( pConfig->m_advUseInternalEditor ) + { + QTextEdit * editor = new QTextEdit ( 0 ); + editor->setPlainText( text ); + editor->setWindowTitle( QString("HTML source of %1") .arg( currentBrowser()->getOpenedPage() )); + editor->resize( 800, 600 ); + editor->show(); + } + else + { + QTemporaryFile * tf = new QTemporaryFile(); + m_tempFileKeeper.append( tf ); + + if ( !tf->open() ) + { + qWarning("Cannot open created QTemporaryFile: something is wrong with your system"); + return; + } + + tf->write( text.toUtf8() ); + tf->seek( 0 ); + + // Run the external editor + QStringList arguments; + arguments.push_back( tf->fileName() ); + + if ( !QProcess::startDetached( pConfig->m_advExternalEditorPath, arguments, "." ) ) + { + QMessageBox::warning( 0, + "Cannot start external editor", + tr("Cannot start external editor %1.\nMake sure the path is absolute!") .arg( pConfig->m_advExternalEditorPath ) ); + delete m_tempFileKeeper.takeLast(); + } + } +} + +void MainWindow::actionToggleFullScreen() +{ + bool fullscreen = view_Toggle_fullscreen_action->isChecked(); + + if ( fullscreen ) + { + if ( !isFullScreen() ) + { + showFullScreen (); + + // Hiding menu bar disables menu actions. Probably a bug in Qt. + //menuBar()->hide(); + statusBar()->hide(); + } + } + else + { + if ( isFullScreen() ) + { + showNormal(); + menuBar()->show(); + statusBar()->show(); + } + } +} + +void MainWindow::actionShowHideNavigator( bool toggle ) +{ + if ( toggle ) + m_navPanel->show(); + else + m_navPanel->hide(); +} + +void MainWindow::navigatorVisibilityChanged( bool visible ) +{ + view_Show_navigator_window->setChecked( visible ); +} + +void MainWindow::actionLocateInContentsTab() +{ + if ( m_navPanel->findUrlInContents( currentBrowser()->getOpenedPage() ) ) + m_navPanel->setActive( NavigationPanel::TAB_CONTENTS ); + else + statusBar()->showMessage( i18n( "Could not locate opened topic in content window"), 2000 ); +} + + +void MainWindow::actionAboutApp() +{ + QString abouttext = i18n( "kchmviewer version %1.%2

" + "Copyright (C) George Yunaev, 2004-2010
" + "gyunaev@ulduzsoft.com
" + "http://www.kchmviewer.net

" + "Licensed under GNU GPL license version 3." ) + .arg(APP_VERSION_MAJOR) .arg(APP_VERSION_MINOR); + + // It is quite funny that the argument order differs +#if defined (USE_KDE) + KMessageBox::about( this, abouttext, i18n("About kchmviewer") ); +#else + QDialog dlg; + Ui::DialogAbout ui; + + ui.setupUi( &dlg ); + ui.lblAbout->setText( abouttext ); + dlg.exec(); +#endif +} + +void MainWindow::actionAboutQt() +{ + QMessageBox::aboutQt( this, QCoreApplication::applicationName() ); +} + +void MainWindow::actionSwitchToContentTab() +{ + m_navPanel->setActive( NavigationPanel::TAB_CONTENTS ); +} + +void MainWindow::actionSwitchToIndexTab() +{ + m_navPanel->setActive( NavigationPanel::TAB_INDEX ); +} + +void MainWindow::actionSwitchToSearchTab() +{ + m_navPanel->setActive( NavigationPanel::TAB_SEARCH ); +} + +void MainWindow::actionSwitchToBookmarkTab() +{ + m_navPanel->setActive( NavigationPanel::TAB_BOOKMARK ); +} + + +void MainWindow::setupActions() +{ + // File menu + connect( file_Open_action, SIGNAL( triggered() ), this, SLOT( actionOpenFile() ) ); + connect( file_Print_action, SIGNAL( triggered() ), this, SLOT( actionPrint() ) ); + connect( file_ExtractCHMAction, SIGNAL( triggered() ), this, SLOT( actionExtractCHM() ) ); + connect( file_exit_action, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); + + // Edit + connect( edit_Copy_action, SIGNAL( triggered() ), this, SLOT( actionEditCopy() ) ); + connect( edit_SelectAll_action, SIGNAL( triggered() ), this, SLOT( actionEditSelectAll() ) ); + connect( edit_FindAction, SIGNAL( triggered() ), this, SLOT( actionFindInPage() ) ); + + // Settings + connect( settings_SettingsAction, SIGNAL( triggered() ), this, SLOT( actionChangeSettings() ) ); + connect( actionCheck_for_updates, SIGNAL(triggered()), this, SLOT(checkNewVersionAvailable()) ); + + // Bookmarks + connect( bookmark_AddAction, SIGNAL( triggered() ), m_navPanel, SLOT( addBookmark()) ); + + // View + connect( view_Increase_font_size_action, SIGNAL( triggered() ), this, SLOT( actionFontSizeIncrease() ) ); + connect( view_Decrease_font_size_action, SIGNAL( triggered() ), this, SLOT( actionFontSizeDecrease() ) ); + connect( view_View_HTML_source_action, SIGNAL( triggered() ), this, SLOT( actionViewHTMLsource() ) ); + connect( view_Toggle_fullscreen_action, SIGNAL( triggered() ), this, SLOT( actionToggleFullScreen() ) ); + connect( view_Show_navigator_window, SIGNAL( triggered(bool) ), this, SLOT( actionShowHideNavigator(bool) ) ); + connect( view_Locate_in_contents_action, SIGNAL( triggered() ), this, SLOT( actionLocateInContentsTab() ) ); + + // Navigation toolbar + connect( nav_action_Back, SIGNAL( triggered() ), this, SLOT( actionNavigateBack() ) ); + connect( nav_actionForward, SIGNAL( triggered() ), this, SLOT( actionNavigateForward() ) ); + connect( nav_actionHome, SIGNAL( triggered() ), this, SLOT( actionNavigateHome() ) ); + connect( nav_actionPreviousPage, SIGNAL( triggered() ), m_navPanel, SLOT( showPrevInToc() ) ); + connect( nav_actionNextPageToc, SIGNAL( triggered() ), m_navPanel, SLOT( showNextInToc() ) ); + + // m_viewWindowMgr fills and maintains 'Window' menu + m_viewWindowMgr->createMenu( this, menu_Windows, action_Close_window ); + + m_navPanel->setBookmarkMenu( menu_Bookmarks ); + + // Close Window goes directly to the window manager + connect( action_Close_window, SIGNAL( triggered() ), m_viewWindowMgr, SLOT( onCloseCurrentWindow() ) ); + + // Navigation panel visibility + connect( m_navPanel, SIGNAL(visibilityChanged(bool)), this, SLOT( navigatorVisibilityChanged(bool) ) ); + + // Help menu + connect( actionAbout_kchmviewer, SIGNAL(triggered()), this, SLOT(actionAboutApp()) ); + connect( actionAbout_Qt, SIGNAL(triggered()), this, SLOT(actionAboutQt()) ); + menuHelp->addSeparator(); + + // "What's this" action + QAction * whatsthis = QWhatsThis::createAction( this ); + menuHelp->addAction( whatsthis ); + viewToolbar->addAction( whatsthis ); + + // Tab switching actions + (void) new QShortcut( QKeySequence( i18n("Ctrl+1") ), + this, + SLOT( actionSwitchToContentTab() ), + SLOT( actionSwitchToContentTab() ), + Qt::ApplicationShortcut ); + + (void) new QShortcut( QKeySequence( i18n("Ctrl+2") ), + this, + SLOT( actionSwitchToIndexTab() ), + SLOT( actionSwitchToIndexTab() ), + Qt::ApplicationShortcut ); + + (void) new QShortcut( QKeySequence( i18n("Ctrl+3") ), + this, + SLOT( actionSwitchToSearchTab() ), + SLOT( actionSwitchToSearchTab() ), + Qt::ApplicationShortcut ); + + (void) new QShortcut( QKeySequence( i18n("Ctrl+4") ), + this, + SLOT( actionSwitchToBookmarkTab() ), + SLOT( actionSwitchToBookmarkTab() ), + Qt::ApplicationShortcut ); + + // Find (/) global shortcut + (void) new QShortcut( QKeySequence( i18n("/") ), + m_viewWindowMgr, + SLOT( onActivateFind() ), + SLOT( onActivateFind() ), + Qt::ApplicationShortcut ); + + // Find next global shortcut + (void) new QShortcut( QKeySequence( i18n("F3") ), + m_viewWindowMgr, + SLOT( onFindNext() ), + SLOT( onFindNext() ), + Qt::ApplicationShortcut ); + + // Open next page in TOC global shortcut + (void) new QShortcut( QKeySequence( i18n("Ctrl+Right") ), + m_navPanel, + SLOT( showNextInToc() ), + SLOT( showNextInToc() ), + Qt::ApplicationShortcut ); + + // Open next page in TOC global shortcut + (void) new QShortcut( QKeySequence( i18n("Ctrl+Left") ), + m_navPanel, + SLOT( showPrevInToc() ), + SLOT( showPrevInToc() ), + Qt::ApplicationShortcut ); + + // Context menu + m_contextMenu = new QMenu( this ); + + m_contextMenu->addAction ( "&Open this link in a new tab", + this, + SLOT( onOpenPageInNewTab() ), + QKeySequence( "Shift+Enter" ) ); + + m_contextMenu->addAction ( "&Open this link in a new background tab", + this, + SLOT( onOpenPageInNewBackgroundTab() ), + QKeySequence( "Ctrl+Enter" ) ); +} + +void MainWindow::updateToolbars() +{ + // Toolbars configuration + Qt::ToolButtonStyle buttonstyle = Qt::ToolButtonIconOnly; + QSize iconsize = QSize( 32, 32 ); + + switch ( pConfig->m_toolbarMode ) + { + case Config::TOOLBAR_SMALLICONS: + iconsize = QSize( 16, 16 ); + break; + + case Config::TOOLBAR_LARGEICONS: + break; + + case Config::TOOLBAR_LARGEICONSTEXT: + buttonstyle = Qt::ToolButtonTextUnderIcon; + break; + + case Config::TOOLBAR_TEXTONLY: + buttonstyle = Qt::ToolButtonTextOnly; + break; + } + + mainToolbar->setIconSize( iconsize ); + mainToolbar->setToolButtonStyle( buttonstyle ); + navToolbar->setIconSize( iconsize ); + navToolbar->setToolButtonStyle( buttonstyle ); + viewToolbar->setIconSize( iconsize ); + viewToolbar->setToolButtonStyle( buttonstyle ); +} + + +void MainWindow::navSetBackEnabled(bool enabled) +{ + nav_action_Back->setEnabled( enabled ); +} + +void MainWindow::navSetForwardEnabled(bool enabled) +{ + nav_actionForward->setEnabled( enabled ); +} + +void MainWindow::actionOpenRecentFile( const QString& file ) +{ + loadFile( file ); +} + +void MainWindow::setupLangEncodingMenu() +{ + // Create the language selection menu. + QMenu * encodings = new QMenu( this ); + + // Create the action group + m_encodingActions = new QActionGroup( this ); + + // Add the codepage entries + const LCHMTextEncoding * enctable = LCHMFileImpl::getTextEncodingTable(); + + for ( int idx = 0; (enctable + idx)->family; idx++ ) + { + const LCHMTextEncoding * enc = enctable + idx; + + QAction * action = new QAction( this ); + + QString text = i18n("%1 ( %2 )") .arg( enc->family) .arg( enc->qtcodec ); + action->setText( text ); + action->setData( qVariantFromValue( (void*) enc ) ); + action->setCheckable( true ); + + // Add to the action group, so only one is checkable + m_encodingActions->addAction( action ); + + // Add to the menu + encodings->addAction( action ); + } + + // Set up the Select Codepage action + view_Set_encoding_action->setMenu( encodings ); + + // Connect the action group signal + connect( m_encodingActions, + SIGNAL( triggered ( QAction * ) ), + this, + SLOT( actionEncodingChanged( QAction * ) ) ); +} + + +void MainWindow::actionEncodingChanged( QAction * action ) +{ + const LCHMTextEncoding * enc = (const LCHMTextEncoding *) action->data().value< void* > (); + setTextEncoding( enc ); +} + + +QMenu * MainWindow::tabItemsContextMenu() +{ + return m_contextMenu; +} + +void MainWindow::setupPopupMenu( QMenu * menu ) +{ + menu->addAction( action_Close_window ); + menu->addSeparator(); + menu->addAction( nav_action_Back ); + menu->addAction( nav_actionForward ); + menu->addAction( nav_actionHome ); + menu->addSeparator(); + menu->addAction( nav_actionPreviousPage ); + menu->addAction( nav_actionNextPageToc ); + menu->addSeparator(); + menu->addAction( view_Increase_font_size_action ); + menu->addAction( view_Decrease_font_size_action ); + menu->addSeparator(); + menu->addAction( edit_Copy_action ); + menu->addAction( edit_FindAction ); +} + +bool MainWindow::hasTableOfContents() const +{ + return m_chmFile && m_chmFile->hasTableOfContents(); +} + +bool MainWindow::hasIndex() const +{ + return m_chmFile && m_chmFile->hasIndexTable(); +} + +void MainWindow::updateActions() +{ + bool enabled = m_chmFile != 0; + + file_Print_action->setEnabled( enabled ); + edit_Copy_action->setEnabled( enabled ); + edit_SelectAll_action->setEnabled( enabled ); + edit_FindAction->setEnabled( enabled ); + file_ExtractCHMAction->setEnabled( enabled ); + bookmark_AddAction->setEnabled( enabled ); + view_Increase_font_size_action->setEnabled( enabled ); + view_Decrease_font_size_action->setEnabled( enabled ); + view_View_HTML_source_action->setEnabled( enabled ); + view_Locate_in_contents_action->setEnabled( enabled ); + view_Set_encoding_action->setEnabled( enabled ); + action_Close_window->setEnabled( enabled ); + nav_action_Back->setEnabled( enabled ); + nav_actionForward->setEnabled( enabled ); + nav_actionHome->setEnabled( enabled ); + nav_actionPreviousPage->setEnabled( enabled ); + nav_actionNextPageToc->setEnabled( enabled ); + m_navPanel->setEnabled( enabled ); +} + +void MainWindow::newVerAvailError( int ) +{ + statusBar()->showMessage( tr("Unable to check whether a new version is available"), 2000 ); +} + +void MainWindow::newVerAvailable( NewVersionMetaMap metadata ) +{ + QSettings().setValue( "advanced/lastupdate", QDateTime::currentDateTime() ); + + // What is the latest version? + QString current = QString("%1.%2") .arg(APP_VERSION_MAJOR) .arg(APP_VERSION_MINOR); + + if ( metadata["Version"] != current ) + { + if ( QMessageBox::question( 0, + tr("New version available"), + tr("A new version %1 of Karaoke Lyrics Editor is available!

" + "You are currently using version %3.
" + "Do you want to visit the application web site %2?") + .arg( metadata["Version"] ) + .arg( metadata["URL"] ) + .arg( current ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes ) == QMessageBox::No ) + return; + + QDesktopServices::openUrl ( QUrl(metadata["URL"]) ); + } + else + statusBar()->showMessage( tr("Checked for updates; you are using the latest version of kchmviewer"), 2000 ); +} diff -Nru kchmviewer-4.1/src/mainwindow.h kchmviewer-5.1/src/mainwindow.h --- kchmviewer-4.1/src/mainwindow.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/mainwindow.h 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,199 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include "libchmfile.h" + +#include "kde-qt.h" +#include "viewwindow.h" +#include "checknewversion.h" + +#include "ui_mainwindow.h" + + +//! Those events could be sent to main window to do useful things. See handleUserEvents() +class UserEvent : public QEvent +{ + public: + UserEvent( const QString& action, const QStringList& args = QStringList() ) + : QEvent( QEvent::User ), m_action(action), m_args(args) + { + } + + QString m_action; + QStringList m_args; +}; + + +class RecentFiles; +class NavigationPanel; + +class MainWindow : public QMainWindow, public Ui::MainWindow +{ + Q_OBJECT + + public: + // "Open page" parameter flags + enum + { + OPF_CONTENT_TREE = 1 << 0, //! Locate this page in the content tree + OPF_ADD2HISTORY = 1 << 1, //! Add the previous page into the history + OPF_NEW_TAB = 1 << 2, //! Open the page in a new tab + OPF_BACKGROUND = 1 << 3 //! Open the page in a new tab in background + }; + + public: + MainWindow(); + ~MainWindow(); + + bool openPage ( const QString &url, unsigned int flags = OPF_CONTENT_TREE ); + + LCHMFile * chmFile() const { return m_chmFile; } + const QString& getOpenedFileName () { return m_chmFilename; } + const QString& getOpenedFileBaseName () { return m_chmFileBasename; } + + ViewWindow * currentBrowser() const; + Settings * currentSettings() const { return m_currentSettings; } + ViewWindowMgr* viewWindowMgr() const { return m_viewWindowMgr; } + NavigationPanel * navigator() const { return m_navPanel; } + + void showInStatusBar (const QString& text); + void setTextEncoding (const LCHMTextEncoding * enc); + QMenu * tabItemsContextMenu(); + + // Called from WindowMgr when another browser tab is activated + void browserChanged( ViewWindow * newbrowser ); + + // Adds some main window actions to the provided popup menu + void setupPopupMenu( QMenu * menu ); + + // Returns true if currently opened file has TOC/index + bool hasTableOfContents() const; + bool hasIndex() const; + + public slots: + // Navigation toolbar icons + void navSetBackEnabled( bool enabled ); + void navSetForwardEnabled( bool enabled ); + + void onOpenPageInNewTab(); + void onOpenPageInNewBackgroundTab(); + + // Actions + void actionOpenFile(); + void actionPrint(); + void actionEditCopy(); + void actionEditSelectAll(); + void actionFindInPage(); + void actionExtractCHM(); + void actionChangeSettings(); + void actionFontSizeIncrease(); + void actionFontSizeDecrease(); + void actionViewHTMLsource(); + void actionToggleFullScreen(); + void actionShowHideNavigator(bool); + void navigatorVisibilityChanged( bool visible ); + void actionLocateInContentsTab(); + + void actionNavigateBack(); + void actionNavigateForward(); + void actionNavigateHome(); + + void actionAboutApp(); + void actionAboutQt(); + + void actionSwitchToContentTab(); + void actionSwitchToIndexTab(); + void actionSwitchToSearchTab(); + void actionSwitchToBookmarkTab(); + + void actionOpenRecentFile( const QString& file ); + void actionEncodingChanged( QAction * action ); + + // Link activation. MainWindow decides whether we should follow this link or not + // by setting up follow_link appropriately. + void activateLink( const QString & link, bool& follow_link ); + + void updateToolbars(); + void updateActions(); + + void checkNewVersionAvailable(); + + protected slots: + // Called from the timer in main constructor + void firstShow(); + + // checknewversion + void newVerAvailError( int ); + void newVerAvailable( NewVersionMetaMap metadata ); + + protected: + // Reimplemented functions + void closeEvent ( QCloseEvent * e ); + bool event ( QEvent * e ); + + private: + bool parseCmdLineArgs(); + void setupActions(); + void setupLangEncodingMenu(); + + bool loadFile( const QString &fileName, bool call_open_page = true ); + void closeFile(); + void refreshCurrentBrowser(); + + bool handleUserEvent( const UserEvent * event ); + + private: + QString m_chmFilename; + QString m_chmFileBasename; + + Settings * m_currentSettings; + LCHMFile * m_chmFile; + + QList m_tempFileKeeper; + + QActionGroup * m_encodingActions; + QMenu * m_contextMenu; + + RecentFiles * m_recentFiles; + + ViewWindowMgr * m_viewWindowMgr; + NavigationPanel * m_navPanel; + + private: + // This is used for application automatic testing + enum auto_test_state_t + { + STATE_OFF, + STATE_INITIAL, + STATE_OPEN_INDEX, + STATE_SHUTDOWN + }; + + auto_test_state_t m_autoteststate; + + private slots: + void runAutoTest(); + +}; + +extern MainWindow * mainWindow; + +#endif // MAINWINDOW_H diff -Nru kchmviewer-4.1/src/mainwindow.ui kchmviewer-5.1/src/mainwindow.ui --- kchmviewer-4.1/src/mainwindow.ui 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/mainwindow.ui 2009-12-16 10:06:05.000000000 +0000 @@ -0,0 +1,594 @@ + + + MainWindow + + + + 0 + 0 + 873 + 591 + + + + kchmviewer + + + + + + 0 + 0 + 873 + 25 + + + + + &Settings + + + + + + + + &Bookmarks + + + + + + + &File + + + + + + + + + + + &Edit + + + + + + + + + &View + + + + + + + + + + + + + + &Windows + + + + + + + Help + + + + + + + + + + + + + + + general toolbar + + + Qt::Horizontal + + + + 32 + 32 + + + + Qt::ToolButtonTextUnderIcon + + + TopToolBarArea + + + false + + + + + + + navigation toolbar + + + Qt::Horizontal + + + + 32 + 32 + + + + Qt::ToolButtonTextUnderIcon + + + TopToolBarArea + + + false + + + + + + + + action toolbar + + + Qt::Horizontal + + + + 32 + 32 + + + + Qt::ToolButtonTextUnderIcon + + + TopToolBarArea + + + false + + + + + + + + + + + + + + :/images/icon_print.png:/images/icon_print.png + + + &Print... + + + Print + + + Print current page + + + Prints currently opened page. + + + Ctrl+P + + + + + + :/images/find_close.png:/images/find_close.png + + + &Quit + + + Exit + + + Exits the application + + + Ctrl+Q + + + + + + :/images/icon_copy.png:/images/icon_copy.png + + + C&opy + + + Copy + + + Copies selected content to clipboard + + + Ctrl+C + + + + + + image8image8 + + + &Select All + + + Paste + + + Selects everything in the document + + + Ctrl+V + + + + + + :/images/icon_find.png:/images/icon_find.png + + + &Find... + + + Find text in currently opened page + + + Enters the Find in page mode + + + Ctrl+F + + + + + + :/images/dryicons_save.png:/images/dryicons_save.png + + + E&xtract CHM content... + + + Extract the CHM content to the directory + + + Exctracts the CHM archive content to the specified directory. All the files are extracted. + + + + + + :/images/dryicon_process.png:/images/dryicon_process.png + + + &Application settings... + + + Change the application settings + + + Change the application settings + + + + + + :/images/icon_add_bookmark.png:/images/icon_add_bookmark.png + + + &Add bookmark + + + Bookmark + + + Adds a bookmark for currently opened page + + + Adds a bookmark for currently opened page. Remembers the opened page, and scroll position. Bookmarks are accessible through Bookmarks menu or tab. + + + Ctrl+B + + + + + + :/images/icon_font_increase.png:/images/icon_font_increase.png + + + &Increase font size + + + Larger + + + Increase the font size + + + Increases the document font size. The new font size will be stored. + + + Ctrl+= + + + + + + :/images/icon_font_decrease.png:/images/icon_font_decrease.png + + + &Decrease font size + + + Smaller + + + Decrease the font size + + + Decreases the document font size. The new font size will be stored. + + + Ctrl+- + + + + + + :/images/icon_view_source.png:/images/icon_view_source.png + + + See &HTML + + + View HTML source of current page + + + Shows the HTML source of currently opened page + + + Ctrl+U + + + + + true + + + + :/images/dryicons_window.png:/images/dryicons_window.png + + + Enable &full screen mode + + + Enters or leaves the fullscreen mode + + + F11 + + + false + + + + + true + + + true + + + + :/images/icon_locate_in_content.png:/images/icon_locate_in_content.png + + + Show &navigator window + + + Show navigator dock window + + + Shows or hides the size window (with Content, Index, Search and Bookmark tabs) + + + F9 + + + false + + + + + + :/images/icon_locate_in_content.png:/images/icon_locate_in_content.png + + + &Locate + + + Locate the current page in contents window + + + If the current page is present in the Table of Contents, locate it there. + + + Ctrl+L + + + + + + :/images/dryicons_replace.png:/images/dryicons_replace.png + + + Set &encoding + + + Changes the current document encoding. + + + + + + :/images/icon_open_file.png:/images/icon_open_file.png + + + &Open... + + + Open a CHM file + + + Opens a new CHM file + + + + + + :/images/icon_back.png:/images/icon_back.png + + + Back + + + Navigate back + + + Navigate back in navigation history + + + + + + :/images/icon_forward.png:/images/icon_forward.png + + + Forward + + + Navigate forward + + + Navigate forward in navigation history + + + + + + :/images/icon_home.png:/images/icon_home.png + + + Home + + + Navigate home + + + Navigate to the document Home page, as specified in the document. + + + + + + :/images/icon_prev_page.png:/images/icon_prev_page.png + + + Previous + + + Go to the previous page in the Table of Contents + + + Go to the previous page in the <b>Table of Contents</b><br><br><i>Shortcut: Ctrl+Left Arrow</i> + + + + + + :/images/icon_next_page.png:/images/icon_next_page.png + + + Next + + + Go to the next page in the Table of Contents + + + Go to the next page in the <b>Table of Contents</b><br><br><i>Shortcut: Ctrl+Right Arrow</i> + + + + + + :/images/closetab.png:/images/closetab.png + + + &Close window + + + Close current window + + + Closes currently opened window + + + Ctrl+W + + + + + About kchmviewer... + + + + + About Qt + + + + + + :/images/find_wrap.png:/images/find_wrap.png + + + Check for updates + + + + + + + + + diff -Nru kchmviewer-4.1/src/navigationpanel.cpp kchmviewer-5.1/src/navigationpanel.cpp --- kchmviewer-4.1/src/navigationpanel.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/navigationpanel.cpp 2009-12-14 10:11:04.000000000 +0000 @@ -0,0 +1,238 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "navigationpanel.h" +#include "tab_contents.h" +#include "tab_index.h" +#include "tab_search.h" +#include "tab_bookmarks.h" +#include "settings.h" +#include "mainwindow.h" + + +NavigationPanel::NavigationPanel( QWidget * parent ) + : QDockWidget( parent ), Ui::NavigatorPanel() +{ + setupUi( this ); + + // There are tabs in UI-creared widget + m_tabWidget->clear(); + + // Add the required tabs + m_searchTab = new TabSearch(m_tabWidget); + m_tabWidget->addTab( m_searchTab, i18n( "Search" ) ); + + m_bookmarksTab = new TabBookmarks( m_tabWidget ); + m_tabWidget->addTab( m_bookmarksTab, i18n("Bookmarks") ); + + // Those tabs will be added later + m_contentsTab = 0; + m_indexTab = 0; +} + +void NavigationPanel::setBookmarkMenu( QMenu * menu ) +{ + m_bookmarksTab->createMenu( menu ); +} + +void NavigationPanel::invalidate() +{ + if ( m_contentsTab ) + { + m_tabWidget->removeTab( m_tabWidget->indexOf( m_contentsTab ) ); + delete m_contentsTab; + m_contentsTab = 0; + } + + if ( m_indexTab ) + { + m_tabWidget->removeTab( m_tabWidget->indexOf( m_indexTab ) ); + delete m_indexTab; + m_indexTab = 0; + } + + m_searchTab->invalidate(); + m_bookmarksTab->invalidate(); +} + +void NavigationPanel::updateTabs( LCHMFile * file ) +{ + invalidate(); + + // Insert index first + if ( file->hasIndexTable() ) + { + m_indexTab = new TabIndex(m_tabWidget); + m_tabWidget->insertTab( 0, m_indexTab, i18n( "Index" ) ); + } + + if ( file->hasTableOfContents() ) + { + m_contentsTab = new TabContents( m_tabWidget ); + m_tabWidget->insertTab( 0, m_contentsTab, i18n( "Contents" ) ); + } +} + +void NavigationPanel::applySettings( Settings * settings ) +{ + m_searchTab->restoreSettings( settings->m_searchhistory ); + m_bookmarksTab->restoreSettings( settings->m_bookmarks ); +} + +void NavigationPanel::getSettings( Settings * settings ) +{ + m_searchTab->saveSettings( settings->m_searchhistory ); + m_bookmarksTab->saveSettings( settings->m_bookmarks ); +} + +void NavigationPanel::refresh() +{ + if ( m_contentsTab ) + m_contentsTab->refillTableOfContents(); + +// gyunaev: do we need it? Not sure. +// if ( m_indexTab->isVisible() ) +// m_indexTab->refillIndex(); +} + +bool NavigationPanel::findUrlInContents( const QString & url ) +{ + if ( !m_contentsTab ) + return false; + + IndexTocItem * treeitem = m_contentsTab->getTreeItem( url ); + + if ( treeitem ) + { + IndexTocItem * itemparent = treeitem; + while ( (itemparent = (IndexTocItem*) itemparent->parent()) != 0 ) + itemparent->setExpanded(true); + + m_contentsTab->showItem( treeitem ); + return true; + } + + return false; +} + +void NavigationPanel::addBookmark() +{ + m_bookmarksTab->onAddBookmarkPressed(); +} + +void NavigationPanel::showPrevInToc() +{ + if ( !m_contentsTab ) + return; + + // Try to find current list item + IndexTocItem * current = m_contentsTab->getTreeItem( ::mainWindow->currentBrowser()->getOpenedPage() ); + + if ( !current ) + return; + + QTreeWidgetItemIterator lit( current ); + lit--; + + if ( *lit ) + ::mainWindow->openPage( ((IndexTocItem *) (*lit) )->getUrl(), + MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); +} + +void NavigationPanel::showNextInToc() +{ + if ( !m_contentsTab ) + return; + + // Try to find current list item + IndexTocItem * current = m_contentsTab->getTreeItem( ::mainWindow->currentBrowser()->getOpenedPage() ); + + if ( !current ) + return; + + QTreeWidgetItemIterator lit( current ); + lit++; + + if ( *lit ) + ::mainWindow->openPage( ((IndexTocItem *) (*lit) )->getUrl(), + MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); +} + + +int NavigationPanel::active() const +{ + QWidget * cur = m_tabWidget->currentWidget(); + + if ( cur == m_bookmarksTab ) + return TAB_BOOKMARK; + else if ( cur == m_searchTab ) + return TAB_SEARCH; + else if ( cur == m_indexTab ) + return TAB_INDEX; + + return TAB_CONTENTS; +} + +void NavigationPanel::setActive( int index ) +{ + switch ( index ) + { + case TAB_CONTENTS: + if ( m_contentsTab ) + m_tabWidget->setCurrentWidget( m_contentsTab ); + break; + + case TAB_INDEX: + if ( m_indexTab ) + m_tabWidget->setCurrentWidget( m_indexTab ); + break; + + case TAB_SEARCH: + m_tabWidget->setCurrentWidget( m_searchTab ); + break; + + case TAB_BOOKMARK: + m_tabWidget->setCurrentWidget( m_bookmarksTab ); + break; + } +} + +void NavigationPanel::findTextInContents( const QString & text ) +{ + if ( m_contentsTab ) + m_contentsTab->search( text ); +} + +void NavigationPanel::findInIndex( const QString& text ) +{ + if ( m_indexTab ) + m_indexTab->search( text ); +} + +void NavigationPanel::executeQueryInSearch( const QString& text ) +{ + m_searchTab->execSearchQueryInGui( text ); +} + +QStringList NavigationPanel::searchQuery( const QString& text ) +{ + QStringList res; + m_searchTab->searchQuery( text, &res ); + + return res; +} diff -Nru kchmviewer-4.1/src/navigationpanel.h kchmviewer-5.1/src/navigationpanel.h --- kchmviewer-4.1/src/navigationpanel.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/navigationpanel.h 2009-12-14 09:08:27.000000000 +0000 @@ -0,0 +1,92 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef NAVIGATIONPANEL_H +#define NAVIGATIONPANEL_H + +#include +#include "ui_navigatorpanel.h" +#include "kde-qt.h" + +class LCHMFile; + +// This class shows content, index, search and bookmark tabs +class NavigationPanel : public QDockWidget, public Ui::NavigatorPanel +{ + Q_OBJECT + + public: + enum + { + TAB_CONTENTS, + TAB_INDEX, + TAB_SEARCH, + TAB_BOOKMARK + }; + + NavigationPanel( QWidget * parent ); + + // Sets the bookmark menu (maintained by bookmark tab) + void setBookmarkMenu( QMenu * menu ); + + // Invalidate data in all tabs + void invalidate(); + + // Update tabs content from CHM file data + void updateTabs( LCHMFile * file ); + + // Save/load current file settings + void applySettings( Settings * settings ); + void getSettings( Settings * settings ); + + // Active tab get/set + int active() const; + void setActive( int index ); + + // Refresh content and index tab contents + void refresh(); + + // Locate URL or text in the contents tab + bool findUrlInContents( const QString & url ); + void findTextInContents( const QString & text ); + + // Find text in index tab + void findInIndex( const QString& text ); + + // Find text in search tab + void executeQueryInSearch( const QString& text ); + + // Just find text without using search tab + QStringList searchQuery( const QString& text ); + + public slots: + // Add a new bookmark + void addBookmark(); + + // Show previous/next page in table of contents + void showPrevInToc(); + void showNextInToc(); + + private: + TabContents * m_contentsTab; + TabIndex * m_indexTab; + TabSearch * m_searchTab; + TabBookmarks * m_bookmarksTab; +}; + +#endif // NAVIGATIONPANEL_H diff -Nru kchmviewer-4.1/src/navigatorpanel.ui kchmviewer-5.1/src/navigatorpanel.ui --- kchmviewer-4.1/src/navigatorpanel.ui 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/navigatorpanel.ui 2009-12-14 09:08:27.000000000 +0000 @@ -0,0 +1,38 @@ + + + NavigatorPanel + + + + 0 + 0 + 400 + 300 + + + + Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea + + + Navigator panel + + + + + + + 0 + + + + Tab 1 + + + + + + + + + + diff -Nru kchmviewer-4.1/src/recentfiles.cpp kchmviewer-5.1/src/recentfiles.cpp --- kchmviewer-4.1/src/recentfiles.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/recentfiles.cpp 2009-12-14 04:26:47.000000000 +0000 @@ -0,0 +1,128 @@ +/************************************************************************** + * Karlyriceditor - a lyrics editor for Karaoke songs * + * Copyright (C) 2009 George Yunaev, support@karlyriceditor.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include +#include + +#include "recentfiles.h" + +RecentFiles::RecentFiles( QMenu * menu, QAction * before, int maxfiles ) +{ + if ( maxfiles < 1 ) + qFatal( "RecentFiles::RecentFiles: maxfiles (%d) is < 1 ", maxfiles ); + + m_actions.resize( maxfiles ); + + // Create the actions + for ( int i = 0; i < maxfiles; ++i ) + { + m_actions[i] = new QAction( this ); + m_actions[i]->setVisible(false); + connect( m_actions[i], SIGNAL(triggered()), this, SLOT(actionRecent()) ); + } + + // Add them to the menu + for ( int i = 0; i < maxfiles; ++i ) + menu->insertAction( before, m_actions[i] ); + + // Add a separator after the last action + m_separator = menu->insertSeparator( before ); + + // Update the actions menu + updateMenu(); +} + +RecentFiles::~RecentFiles() +{ +} + +void RecentFiles::setCurrentFile( const QString& file ) +{ + QStringList files = loadRecentFiles(); + files.removeAll( file ); + files.prepend( file ); + + while ( files.size() > m_actions.size() ) + files.removeLast(); + + saveRecentFiles( files ); + + updateMenu(); +} + +void RecentFiles::removeRecentFile( const QString& file ) +{ + QStringList files = loadRecentFiles(); + files.removeAll( file ); + saveRecentFiles( files ); + + updateMenu(); +} + +void RecentFiles::actionRecent() +{ + QAction *action = qobject_cast(sender()); + + if ( action ) + emit openRecentFile( action->data().toString() ); +} + +void RecentFiles::updateMenu() +{ + QStringList files = loadRecentFiles(); + int numRecentFiles = qMin( files.size(), m_actions.size() ); + + for ( int i = 0; i < m_actions.size(); ++i ) + { + if ( i < numRecentFiles ) + { + QString text = tr("&%1 %2").arg(i + 1).arg( QFileInfo( files[i] ).fileName() ); + m_actions[i]->setText(text); + m_actions[i]->setToolTip( files[i] ); + m_actions[i]->setData(files[i]); + m_actions[i]->setVisible(true); + } + else + m_actions[i]->setVisible(false); + } + + m_separator->setVisible( numRecentFiles > 0 ); +} + +QString RecentFiles::latestFile() +{ + QStringList files = loadRecentFiles(); + + if ( files.isEmpty() ) + return QString::null; + else + return files[0]; +} + +QStringList RecentFiles::loadRecentFiles() +{ + QSettings settings; + return settings.value("recentFileList").toStringList(); +} + +void RecentFiles::saveRecentFiles( const QStringList& files ) +{ + QSettings settings; + settings.setValue( "recentFileList", files ); +} diff -Nru kchmviewer-4.1/src/recentfiles.h kchmviewer-5.1/src/recentfiles.h --- kchmviewer-4.1/src/recentfiles.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/recentfiles.h 2009-12-14 04:26:47.000000000 +0000 @@ -0,0 +1,76 @@ +/************************************************************************** + * Karlyriceditor - a lyrics editor for Karaoke songs * + * Copyright (C) 2009 George Yunaev, support@karlyriceditor.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef RECENTFILES_H +#define RECENTFILES_H + +#include +#include +#include +#include + + +// This class assumes QSettings object can be created using default constructor, i.e. +// QCoreApplication::setOrganizationName( ... ); +// QCoreApplication::setOrganizationDomain( ... ); +// QCoreApplication::setApplicationName( ... ); +// have been called. +// +// This class is based on Qt example +// +class RecentFiles : public QObject +{ + Q_OBJECT + + public: + // A constructor specifies the menu to add recent files to, and the action to add it before. + RecentFiles( QMenu * menu, QAction * before, int maxfiles = 5 ); + virtual ~RecentFiles(); + + signals: + void openRecentFile( const QString& file ); + + public slots: + // Sets the current file to the recent file. Does the following: + // - Adds it to the top of recent files list, or moves it to the top; + // - Removes the last entry, if necessary; + void setCurrentFile( const QString& file ); + + // Removes the current file from the recent files. Useful, for example, + // when attempt to open a recent project failed. + void removeRecentFile( const QString& file ); + + // Returns the last added recent file + QString latestFile(); + + protected: + // Override those functions in a derived class to store/load the + // list of recent files from a different place + QStringList loadRecentFiles(); + void saveRecentFiles( const QStringList& files ); + + private slots: + void actionRecent(); + void updateMenu(); + + private: + QAction * m_separator; + QVector< QAction* > m_actions; +}; + +#endif // RECENTFILES_H Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/resources/dryicon_process.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/resources/dryicon_process.png differ Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/resources/dryicons_replace.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/resources/dryicons_replace.png differ Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/resources/dryicons_save.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/resources/dryicons_save.png differ Binary files /tmp/ndmCzbvZsB/kchmviewer-4.1/src/resources/dryicons_window.png and /tmp/gVx62UHKyn/kchmviewer-5.1/src/resources/dryicons_window.png differ diff -Nru kchmviewer-4.1/src/resources/images.qrc kchmviewer-5.1/src/resources/images.qrc --- kchmviewer-4.1/src/resources/images.qrc 2007-08-30 18:16:49.000000000 +0100 +++ kchmviewer-5.1/src/resources/images.qrc 2009-12-15 04:06:16.000000000 +0000 @@ -23,5 +23,9 @@ icon_print.png icon_view_source.png kchmviewer.png + dryicon_process.png + dryicons_replace.png + dryicons_save.png + dryicons_window.png diff -Nru kchmviewer-4.1/src/resources/images.qrc~ kchmviewer-5.1/src/resources/images.qrc~ --- kchmviewer-4.1/src/resources/images.qrc~ 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/resources/images.qrc~ 2009-12-15 04:06:16.000000000 +0000 @@ -0,0 +1,20 @@ + + + closetab.png + icon_add_bookmark.png + icon_back.png + icon_find_next.png + icon_find_prev.png + icon_font_decrease.png + icon_font_increase.png + icon_forward.png + icon_home.png + icon_locate_in_content.png + icon_next_page.png + icon_open_file.png + icon_prev_page.png + icon_print.png + icon_view_source.png + kchmviewer.png + + diff -Nru kchmviewer-4.1/src/settings.cpp kchmviewer-5.1/src/settings.cpp --- kchmviewer-4.1/src/settings.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/settings.cpp 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,302 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include +#include +#include + +#include "settings.h" +#include "config.h" + +static qint32 SETTINGS_MAGIC = 0xD8AB4E76; +static qint32 SETTINGS_VERSION = 4; + +/* + * The order is important! + * To be compatible with next versions, you may add items ONLY before the MARKER_END! + */ +enum marker_t +{ + MARKER_FILESIZE = 1, + MARKER_FILETIME, + + MARKER_ACTIVETABSYSTEM, + MARKER_ACTIVETABWINDOW, + MARKER_ACTIVEENCODING, + MARKER_SEARCHHISTORY, + MARKER_WINDOW_SIZE, + + MARKER_BOOKMARKS, + MARKER_VIEWINDOWS, + + MARKER_CONTENTSDATA, + MARKER_INDEXDATA, + + MARKER_ACTIVEENCODINGNAME, + + // This should be the last + MARKER_END = 0x7FFF +}; + +// Helpers for serialization of SavedBookmark through QDataStream +static inline QDataStream& operator<< ( QDataStream& s, const Settings::SavedBookmark& b ) +{ + s << b.name; + s << b.url; + s << b.scroll_y; + return s; +} + +static inline QDataStream& operator>> ( QDataStream& s, Settings::SavedBookmark& b ) +{ + s >> b.name; + s >> b.url; + s >> b.scroll_y; + return s; +} + +// Helpers for serialization of SavedViewWindow through QDataStream +static inline QDataStream& operator<< ( QDataStream& s, const Settings::SavedViewWindow& b ) +{ + // Store the version first. Later we can increase it when adding new members. + s << 1; + s << b.url; + s << b.scroll_y; + s << b.zoom; + return s; +} + +static inline QDataStream& operator>> ( QDataStream& s, Settings::SavedViewWindow& b ) +{ + qint32 version; + + s >> version; + s >> b.url; + s >> b.scroll_y; + s >> b.zoom; + return s; +} + + +Settings::Settings() +{ + m_activetabsystem = 0; + m_activetabwindow = 0; + m_activeEncoding = "CP1252"; + + m_window_size_x = 700; + m_window_size_y = 500; + m_window_size_splitter = 200; +} + + +bool Settings::loadSettings( const QString & filename ) +{ + m_activetabsystem = 0; + m_activetabwindow = 0; + m_activeEncoding = "CP1252"; + + m_searchhistory.clear(); + m_bookmarks.clear(); + m_viewwindows.clear(); + + QFileInfo finfo ( filename ); + + m_settingsFile = QString::null; + m_searchIndex = QString::null; + + if ( !finfo.size() ) + return false; + + // Init those params, as they'll be used during save the first time even if the file is not here + m_currentfilesize = finfo.size(); + m_currentfiledate = finfo.lastModified().toTime_t(); + + getFilenames( filename, &m_settingsFile, &m_searchIndex ); + + QFile file( m_settingsFile ); + + if ( !file.open (QIODevice::ReadOnly) ) + return false; // it's ok, file may not exist + + QDataStream stream (&file); + + // Read and check header + qint32 data; + bool complete_read = false; + stream >> data; // magic + + if ( data != SETTINGS_MAGIC ) + { + qWarning ("file %s has bad magic value, ignoring it.", qPrintable( file.fileName()) ); + return false; + } + + stream >> data; // version + if ( data > SETTINGS_VERSION ) + { + qWarning ("file %s has unsupported data version %d, ignoring it.", qPrintable( file.fileName()), data); + return false; + } + + // Read everything by marker + while ( 1 ) + { + stream >> data; // marker + if ( data == MARKER_END ) + { + complete_read = true; + break; + } + + switch (data) + { + case MARKER_FILESIZE: + stream >> m_currentfilesize; + if ( m_currentfilesize != finfo.size() ) + { + m_currentfilesize = finfo.size(); + return false; + } + break; + + case MARKER_FILETIME: + stream >> m_currentfiledate; + if ( m_currentfiledate != finfo.lastModified().toTime_t() ) + { + m_currentfiledate = finfo.lastModified().toTime_t(); + return false; + } + break; + + case MARKER_ACTIVETABSYSTEM: + stream >> m_activetabsystem; + break; + + case MARKER_ACTIVETABWINDOW: + stream >> m_activetabwindow; + break; + + // Not used anymore + case MARKER_ACTIVEENCODING: + stream >> data; + break; + + case MARKER_ACTIVEENCODINGNAME: + stream >> m_activeEncoding; + break; + + case MARKER_WINDOW_SIZE: + stream >> m_window_size_x; + stream >> m_window_size_y; + stream >> m_window_size_splitter; + break; + + case MARKER_SEARCHHISTORY: + stream >> m_searchhistory; + break; + + case MARKER_BOOKMARKS: + stream >> m_bookmarks; + break; + + case MARKER_VIEWINDOWS: + stream >> m_viewwindows; + break; + } + } + + return complete_read; +} + + +bool Settings::saveSettings( ) +{ + QFile file( m_settingsFile ); + if ( !file.open (QIODevice::WriteOnly) ) + { + qWarning ("Could not write settings into file %s: %s", + qPrintable( file.fileName()), + qPrintable( file.errorString() )); + return false; + } + + QDataStream stream (&file); + + // Save header + stream << SETTINGS_MAGIC; + stream << SETTINGS_VERSION; + + // Save size and last-modified + stream << MARKER_FILESIZE; + stream << m_currentfilesize; + stream << MARKER_FILETIME; + stream << m_currentfiledate; + + // Save generic settings + stream << MARKER_ACTIVETABSYSTEM; + stream << m_activetabsystem; + + // Save generic settings + stream << MARKER_ACTIVETABWINDOW; + stream << m_activetabwindow; + + stream << MARKER_ACTIVEENCODINGNAME; + stream << m_activeEncoding; + + // Save search history vector + stream << MARKER_SEARCHHISTORY; + stream << m_searchhistory; + + // Save window size and splitter position + stream << MARKER_WINDOW_SIZE; + stream << m_window_size_x; + stream << m_window_size_y; + stream << m_window_size_splitter; + + stream << MARKER_BOOKMARKS; + stream << m_bookmarks; + + stream << MARKER_VIEWINDOWS; + stream << m_viewwindows; + + stream << MARKER_END; + return true; +} + + +void Settings::removeSettings( const QString & filename ) +{ + QString settingsfile, idxfile; + + getFilenames( filename, &settingsfile, &idxfile ); + + QFile::remove( settingsfile ); + QFile::remove( idxfile ); +} + + +void Settings::getFilenames(const QString & helpfilename, QString * settingsfile, QString * indexfile ) +{ + QFileInfo finfo ( helpfilename ); + QString prefix = pConfig->m_datapath + "/" + finfo.baseName(); + + *settingsfile = prefix + ".kchmviewer"; + *indexfile = prefix + ".idx"; +} diff -Nru kchmviewer-4.1/src/settings.h kchmviewer-5.1/src/settings.h --- kchmviewer-4.1/src/settings.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/settings.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,82 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + + +class Settings +{ + public: + Settings(); + + bool loadSettings (const QString& filename); + bool saveSettings ( ); + void removeSettings ( const QString& filename ); + + QString searchIndexFile() const { return m_searchIndex; } + + class SavedBookmark + { + public: + SavedBookmark() { scroll_y = 0; } + SavedBookmark ( const QString& n, const QString& u, int y) : name(n), url(u), scroll_y(y) {}; + + QString name; + QString url; + int scroll_y; + }; + + class SavedViewWindow + { + public: + SavedViewWindow() { scroll_y = 0; zoom = 0; } + SavedViewWindow ( const QString& u, int y, int z) : url(u), scroll_y(y), zoom(z) {}; + + QString url; + int scroll_y; + int zoom; + }; + + typedef QList search_saved_settings_t; + typedef QList bookmark_saved_settings_t; + typedef QList viewindow_saved_settings_t; + + int m_window_size_x; + int m_window_size_y; + int m_window_size_splitter; + int m_activetabsystem; + int m_activetabwindow; + QString m_activeEncoding; + search_saved_settings_t m_searchhistory; + bookmark_saved_settings_t m_bookmarks; + viewindow_saved_settings_t m_viewwindows; + + private: + void getFilenames(const QString & helpfilename, QString * settingsfile, QString * indexfile ); + + unsigned int m_currentfilesize; + unsigned int m_currentfiledate; + QString m_settingsFile; + QString m_searchIndex; +}; + +#endif diff -Nru kchmviewer-4.1/src/src.pro kchmviewer-5.1/src/src.pro --- kchmviewer-4.1/src/src.pro 2009-07-20 03:43:50.000000000 +0100 +++ kchmviewer-5.1/src/src.pro 2009-12-15 06:02:57.000000000 +0000 @@ -1,43 +1,76 @@ INCLUDEPATH += ../lib/libchmfile - -HEADERS += kchmsettings.h kchmbookmarkwindow.h kchmconfig.h kchmtreeviewitem.h \ - kchmdialogchooseurlfromlist.h kchmviewwindow.h kchmindexwindow.h \ - kchmmainwindow.h kchmviewwindow_qtextbrowser.h kde-qt.h \ - kchmsearchwindow.h kchmviewwindowmgr.h \ - kchmkeyeventfilter.h kchmcontentswindow.h kchmsetupdialog.h \ - version.h \ - kchmviewwindow_qtwebkit.h kchmdbusiface.h -SOURCES += kchmbookmarkwindow.cpp kchmconfig.cpp \ - kchmindexwindow.cpp kchmmainwindow.cpp kchmsearchwindow.cpp \ - kchmsettings.cpp kchmtreeviewitem.cpp kchmviewwindow.cpp main.cpp \ - kchmdialogchooseurlfromlist.cpp kde-qt.cpp kchmviewwindow_qtextbrowser.cpp \ - kchmviewwindowmgr.cpp \ - kchmkeyeventfilter.cpp kchmcontentswindow.cpp kchmsetupdialog.cpp \ - kchmviewwindow_qtwebkit.cpp kchmdbusiface.cpp -TARGETDEPS += ../lib/libchmfile/libchmfile.a -LIBS += ../lib/libchmfile/libchmfile.a -lchm +HEADERS += config.h \ + dbus_interface.h \ + dialog_chooseurlfromlist.h \ + dialog_setup.h \ + kde-qt.h \ + keyeventfilter.h \ + mainwindow.h \ + recentfiles.h \ + settings.h \ + tab_bookmarks.h \ + tab_contents.h \ + tab_index.h \ + tab_search.h \ + treeviewitem.h \ + version.h \ + viewwindow.h \ + viewwindowmgr.h \ + viewwindow_qtextbrowser.h \ + viewwindow_qtwebkit.h \ + navigationpanel.h \ + checknewversion.h +SOURCES += config.cpp \ + dbus_interface.cpp \ + dialog_chooseurlfromlist.cpp \ + dialog_setup.cpp \ + kde-qt.cpp \ + keyeventfilter.cpp \ + main.cpp \ + mainwindow.cpp \ + recentfiles.cpp \ + settings.cpp \ + tab_bookmarks.cpp \ + tab_contents.cpp \ + tab_index.cpp \ + tab_search.cpp \ + treeviewitem.cpp \ + viewwindow.cpp \ + viewwindowmgr.cpp \ + viewwindow_qtextbrowser.cpp \ + viewwindow_qtwebkit.cpp \ + navigationpanel.cpp \ + checknewversion.cpp +TARGETDEPS += ../lib/libchmfile/libchmfile.a +LIBS += ../lib/libchmfile/libchmfile.a \ + -lchm TARGET = ../bin/kchmviewer CONFIG += release \ - ordered \ - warn_on \ - qt \ - precompile_header \ - dbus + threads \ + ordered \ + warn_on \ + qt \ + precompile_header \ + dbus TEMPLATE = app FORMS += tab_bookmarks.ui \ -tab_index.ui \ -tab_contents.ui \ -tab_search.ui \ -dialog_setup.ui \ -dialog_topicselector.ui \ -window_main.ui \ -window_browser.ui + tab_index.ui \ + tab_contents.ui \ + tab_search.ui \ + dialog_setup.ui \ + dialog_topicselector.ui \ + mainwindow.ui \ + window_browser.ui \ + navigatorpanel.ui \ + dialog_about.ui RESOURCES += resources/images.qrc -QT += webkit dbus network - -win32-mingw-g++: { - QT -= dbus - HEADERS -= kchmdbusiface.h - SOURCES -= kchmdbusiface.cpp - CONFIG -= dbus +QT += webkit \ + dbus \ + network +win32-mingw-g++: { + QT -= dbus + HEADERS -= dbus_interface.h + SOURCES -= dbus_interface.cpp + CONFIG -= dbus + LIBS += -lwsock32 } diff -Nru kchmviewer-4.1/src/tab_bookmarks.cpp kchmviewer-5.1/src/tab_bookmarks.cpp --- kchmviewer-4.1/src/tab_bookmarks.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_bookmarks.cpp 2009-12-16 10:10:16.000000000 +0000 @@ -0,0 +1,245 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "mainwindow.h" +#include "viewwindow.h" +#include "treeviewitem.h" +#include "version.h" +#include "tab_bookmarks.h" + +class BookmarkItem : public QListWidgetItem +{ + public: + BookmarkItem( TabBookmarks * widget, QListWidget* parent, const QString& name, const QString& url, int pos ) + : QListWidgetItem( parent ) + { + m_name = name; + m_url = url; + m_scroll_y = pos; + m_action = new QAction( name, widget ); + m_action->setData( qVariantFromValue( (void*) this ) ); + + QObject::connect( m_action, + SIGNAL( triggered() ), + widget, + SLOT( actionBookmarkActivated() ) ); + } + + void setName( const QString& name ) + { + m_name = name; + } + + // Visualization + virtual QVariant data ( int role ) const + { + switch ( role ) + { + case Qt::ToolTipRole: + case Qt::WhatsThisRole: + case Qt::DisplayRole: + return m_name; + } + + return QVariant(); + } + + QString m_name; + QString m_url; + int m_scroll_y; + QAction * m_action; +}; + + + +TabBookmarks::TabBookmarks( QWidget *parent ) + : QWidget( parent ), Ui::TabBookmarks() +{ + // UIC code + setupUi( this ); + + connect( list, + SIGNAL( itemDoubleClicked ( QListWidgetItem* ) ), + this, + SLOT( onItemDoubleClicked ( QListWidgetItem* ) ) ); + + connect( btnAdd, + SIGNAL( clicked () ), + this, + SLOT( onAddBookmarkPressed( ) ) ); + + connect( btnDel, + SIGNAL( clicked () ), + this, + SLOT( onDelBookmarkPressed( ) ) ); + + connect( btnEdit, + SIGNAL( clicked () ), + this, + SLOT( onEditBookmarkPressed( ) ) ); + + m_menuBookmarks = 0; + m_contextMenu = 0; + m_listChanged = false; + + // Activate custom context menu, and connect it + list->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( list, + SIGNAL( customContextMenuRequested ( const QPoint & ) ), + this, + SLOT( onContextMenuRequested( const QPoint & ) ) ); +} + +void TabBookmarks::onAddBookmarkPressed( ) +{ + bool ok; + QString url = ::mainWindow->currentBrowser()->getOpenedPage(); + QString title = ::mainWindow->chmFile()->getTopicByUrl(url); + QString name = QInputDialog::getText( + this, + i18n( "%1 - add a bookmark") . arg(QCoreApplication::applicationName()), + i18n( "Enter the name for this bookmark:" ), + QLineEdit::Normal, + title, + &ok ); + + if ( !ok || name.isEmpty() ) + return; + + BookmarkItem * item = new BookmarkItem ( this, + list, + name, + url, + ::mainWindow->currentBrowser()->getScrollbarPosition() ); + + m_menuBookmarks->addAction( item->m_action ); + m_listChanged = true; +} + + +void TabBookmarks::onDelBookmarkPressed( ) +{ + BookmarkItem * item = (BookmarkItem *) list->currentItem(); + + if ( item ) + { + m_menuBookmarks->removeAction( item->m_action ); + delete item; + m_listChanged = true; + } +} + + +void TabBookmarks::onEditBookmarkPressed( ) +{ + BookmarkItem * item = (BookmarkItem *) list->currentItem(); + + if ( item ) + { + bool ok; + QString name = QInputDialog::getText( + this, + i18n( "%1 - edit the bookmark name") . arg(QCoreApplication::applicationName()), + i18n( "Enter the name for this bookmark:" ), + QLineEdit::Normal, + item->m_name, + &ok ); + + if ( !ok || name.isEmpty() ) + return; + + item->setName( name ); + item->m_action->setText( name ); + m_listChanged = true; + update(); + } +} + + +void TabBookmarks::restoreSettings( const Settings::bookmark_saved_settings_t & settings ) +{ + for ( int i = 0; i < settings.size(); i++ ) + { + BookmarkItem * item = new BookmarkItem( this, list, settings[i].name, settings[i].url, settings[i].scroll_y ); + m_menuBookmarks->addAction( item->m_action ); + } +} + + +void TabBookmarks::saveSettings( Settings::bookmark_saved_settings_t & settings ) +{ + settings.clear(); + + for ( int i = 0; i < list->count(); i++ ) + { + BookmarkItem * treeitem = (BookmarkItem *) list->item( i ); + settings.push_back( Settings::SavedBookmark( treeitem->m_name, treeitem->m_url, treeitem->m_scroll_y) ); + } +} + +void TabBookmarks::invalidate( ) +{ + for ( int i = 0; i < list->count(); i++ ) + m_menuBookmarks->removeAction( ((BookmarkItem *) list->item( i ))->m_action ); + + list->clear(); +} + +void TabBookmarks::createMenu( QMenu * menuBookmarks ) +{ + m_menuBookmarks = menuBookmarks; +} + +void TabBookmarks::onItemDoubleClicked(QListWidgetItem * item) +{ + if ( !item ) + return; + + BookmarkItem * treeitem = (BookmarkItem *) item; + + if ( ::mainWindow->currentBrowser()->getOpenedPage() != treeitem->m_url ) + ::mainWindow->openPage( treeitem->m_url, MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); + + ::mainWindow->currentBrowser()->setScrollbarPosition( treeitem->m_scroll_y ); +} + +void TabBookmarks::actionBookmarkActivated() +{ + QAction *action = qobject_cast< QAction * >(sender()); + + BookmarkItem * item = (BookmarkItem *) action->data().value< void* > (); + + if ( !item ) + return; + + if ( ::mainWindow->currentBrowser()->getOpenedPage() != item->m_url ) + ::mainWindow->openPage( item->m_url, MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); + + ::mainWindow->currentBrowser()->setScrollbarPosition( item->m_scroll_y ); +} + +void TabBookmarks::onContextMenuRequested(const QPoint & point) +{ + BookmarkItem * item = (BookmarkItem *) list->itemAt( point ); + + if( item ) + { + ::mainWindow->currentBrowser()->setTabKeeper( item->m_url ); + ::mainWindow->tabItemsContextMenu()->popup( list->viewport()->mapToGlobal( point ) ); + } +} diff -Nru kchmviewer-4.1/src/tab_bookmarks.h kchmviewer-5.1/src/tab_bookmarks.h --- kchmviewer-4.1/src/tab_bookmarks.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_bookmarks.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,57 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef TAB_BOOKMARK_H +#define TAB_BOOKMARK_H + +#include "kde-qt.h" +#include "settings.h" + +#include "ui_tab_bookmarks.h" + + +class TabBookmarks : public QWidget, public Ui::TabBookmarks +{ + Q_OBJECT + public: + TabBookmarks( QWidget *parent ); + + void createMenu( QMenu * menuBookmarks ); + + void restoreSettings ( const Settings::bookmark_saved_settings_t& settings ); + void saveSettings ( Settings::bookmark_saved_settings_t& settings ); + void invalidate(); + + public slots: + void onAddBookmarkPressed (); + + private slots: + void actionBookmarkActivated(); + void onDelBookmarkPressed( ); + void onEditBookmarkPressed( ); + void onItemDoubleClicked ( QListWidgetItem* ); + void onContextMenuRequested ( const QPoint &point ); + + private: + QMenu * m_menuBookmarks; + QMenu * m_contextMenu; + QString m_bookmarkFileName; + bool m_listChanged; +}; + +#endif diff -Nru kchmviewer-4.1/src/tab_contents.cpp kchmviewer-5.1/src/tab_contents.cpp --- kchmviewer-4.1/src/tab_contents.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_contents.cpp 2009-12-17 09:38:59.000000000 +0000 @@ -0,0 +1,136 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "kde-qt.h" + +#include "libchmfile.h" +#include "libchmurlfactory.h" + +#include "mainwindow.h" +#include "treeviewitem.h" +#include "tab_contents.h" + + +TabContents::TabContents( QWidget *parent ) + : QWidget( parent ), Ui::TabContents() +{ + setupUi( this ); + + m_contextMenu = 0; + + tree->setFocus(); + tree->header()->hide(); + + // Handle clicking on m_contentsWindow element + connect( tree, + SIGNAL( itemClicked ( QTreeWidgetItem *, int ) ), + this, + SLOT( onClicked ( QTreeWidgetItem *, int ) ) ); + + // Activate custom context menu, and connect it + tree->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( tree, + SIGNAL( customContextMenuRequested ( const QPoint & ) ), + this, + SLOT( onContextMenuRequested( const QPoint & ) ) ); + + if ( ::mainWindow->chmFile() ) + refillTableOfContents(); +} + +TabContents::~TabContents() +{ +} + +void TabContents::refillTableOfContents( ) +{ + ShowWaitCursor wc; + QVector< LCHMParsedEntry > data; + + if ( !::mainWindow->chmFile()->parseTableOfContents( &data ) + || data.size() == 0 ) + { + qWarning ("CHM toc present but is empty; wrong parsing?"); + return; + } + + kchmFillListViewWithParsedData( tree, data, &m_urlListMap ); +} + + +IndexTocItem * TabContents::getTreeItem( const QString & url ) +{ + QMap::const_iterator it; + + // First try to find non-normalized URL (present in some ugly CHM files) + it = m_urlListMap.find( LCHMUrlFactory::makeURLabsoluteIfNeeded(url) ); + + if ( it == m_urlListMap.end() ) + { + QString fixedstr = ::mainWindow->chmFile()->normalizeUrl( url ); + it = m_urlListMap.find( fixedstr ); + } + + if ( it == m_urlListMap.end() ) + return 0; + + return *it; +} + +void TabContents::showItem( IndexTocItem * item ) +{ + tree->setCurrentItem( item ); + tree->scrollToItem( item ); +} + + +void TabContents::onClicked(QTreeWidgetItem * item, int) +{ + bool unused; + + if ( !item ) + return; + + IndexTocItem * treeitem = (IndexTocItem*) item; + ::mainWindow->activateLink( treeitem->getUrl(), unused ); +} + +void TabContents::onContextMenuRequested(const QPoint & point) +{ + IndexTocItem * treeitem = (IndexTocItem *) tree->itemAt( point ); + + if( treeitem ) + { + ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); + ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); + } +} + + +void TabContents::search( const QString & text ) +{ + QList items = tree->findItems( text, Qt::MatchWildcard | Qt::MatchRecursive ); + bool unused; + qDebug("found %d items of %d", items.size(), tree-> + topLevelItemCount() ); + if ( items.isEmpty() ) + return; + + IndexTocItem * treeitem = (IndexTocItem *) items.first(); + ::mainWindow->activateLink( treeitem->getUrl(), unused ); +} diff -Nru kchmviewer-4.1/src/tab_contents.h kchmviewer-5.1/src/tab_contents.h --- kchmviewer-4.1/src/tab_contents.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_contents.h 2009-12-14 07:14:30.000000000 +0000 @@ -0,0 +1,50 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef TAB_CONTENTS_H +#define TAB_CONTENTS_H + +#include "kde-qt.h" +#include "treeviewitem.h" +#include "ui_tab_contents.h" + + +class TabContents : public QWidget, public Ui::TabContents +{ + Q_OBJECT + public: + TabContents( QWidget *parent = 0 ); + ~TabContents(); + + void refillTableOfContents(); + void showItem( IndexTocItem * item ); + void search( const QString& text ); + + IndexTocItem * getTreeItem( const QString& url ); + + public slots: + void onContextMenuRequested ( const QPoint &point ); + void onClicked ( QTreeWidgetItem * item, int column ); + + private: + QMenu * m_contextMenu; + QMap m_urlListMap; +}; + + +#endif /* INCLUDE_KCHMCONTENTSWINDOW_H */ diff -Nru kchmviewer-4.1/src/tab_index.cpp kchmviewer-5.1/src/tab_index.cpp --- kchmviewer-4.1/src/tab_index.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_index.cpp 2009-12-14 07:02:52.000000000 +0000 @@ -0,0 +1,181 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "libchmfile.h" + +#include "mainwindow.h" +#include "treeviewitem.h" +#include "tab_index.h" + + +TabIndex::TabIndex ( QWidget * parent ) + : QWidget( parent ), Ui::TabIndex() +{ + // UIC stuff + setupUi( this ); + + tree->headerItem()->setHidden( true ); + + connect( text, + SIGNAL( textChanged (const QString &) ), + this, + SLOT( onTextChanged(const QString &) ) ); + + connect( text, + SIGNAL( returnPressed() ), + this, + SLOT( onReturnPressed() ) ); + + connect( tree, + SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int ) ), + this, + SLOT( onDoubleClicked ( QTreeWidgetItem *, int) ) ); + + // Activate custom context menu, and connect it + tree->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( tree, + SIGNAL( customContextMenuRequested ( const QPoint & ) ), + this, + SLOT( onContextMenuRequested( const QPoint & ) ) ); + + m_indexListFilled = false; + m_lastSelectedItem = 0; + m_contextMenu = 0; + + text->setFocus(); +} + +void TabIndex::onTextChanged ( const QString & newvalue) +{ + QList items = tree->findItems( newvalue, Qt::MatchStartsWith ); + + if ( !items.isEmpty() ) + { + m_lastSelectedItem = items[0]; + tree->setCurrentItem( m_lastSelectedItem ); + tree->scrollToItem( m_lastSelectedItem ); + } + else + m_lastSelectedItem = 0; +} + + +void TabIndex::showEvent( QShowEvent * ) +{ + if ( !::mainWindow->chmFile() || m_indexListFilled ) + return; + + m_indexListFilled = true; + refillIndex(); +} + +void TabIndex::onReturnPressed( ) +{ + bool unused; + + if ( !m_lastSelectedItem ) + return; + + IndexTocItem * treeitem = (IndexTocItem*) m_lastSelectedItem; + ::mainWindow->activateLink( treeitem->getUrl(), unused ); +} + + +void TabIndex::invalidate( ) +{ + tree->clear(); + m_indexListFilled = false; + m_lastSelectedItem = 0; +} + +void TabIndex::onDoubleClicked ( QTreeWidgetItem * item, int ) +{ + if ( !item ) + return; + + IndexTocItem * treeitem = (IndexTocItem*) item; + + // Prevent opened index tree item from closing; because the tree open/close + // procedure will be triggered after the slots are called, we change the tree + // state to "collapsed", so the slot handler expands it again. + if ( item->isExpanded() ) + item->setExpanded( false ); + + QString url = treeitem->getUrl(); + + if ( url.isEmpty() ) + return; + + if ( url[0] == ':' ) // 'see also' link + { + QList items = tree->findItems( url.mid(1), Qt::MatchFixedString ); + + if ( !items.isEmpty() ) + { + m_lastSelectedItem = items[0]; + tree->setCurrentItem( m_lastSelectedItem ); + tree->scrollToItem( m_lastSelectedItem ); + } + else + m_lastSelectedItem = 0; + } + else + ::mainWindow->openPage( url, MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); +} + + +void TabIndex::refillIndex( ) +{ + ShowWaitCursor wc; + QVector< LCHMParsedEntry > data; + + if ( !::mainWindow->chmFile()->parseIndex( &data ) + || data.size() == 0 ) + { + qWarning ("CHM index present but is empty; wrong parsing?"); + return; + } + + kchmFillListViewWithParsedData( tree, data, 0 ); +} + +void TabIndex::search( const QString & index ) +{ + if ( !::mainWindow->chmFile() ) + return; + + if ( !m_indexListFilled ) + { + m_indexListFilled = true; + refillIndex(); + } + + text->setText( index ); + onTextChanged( index ); +} + +void TabIndex::onContextMenuRequested(const QPoint & point) +{ + IndexTocItem * treeitem = (IndexTocItem *) tree->itemAt( point ); + + if( treeitem ) + { + ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); + ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); + } +} diff -Nru kchmviewer-4.1/src/tab_index.h kchmviewer-5.1/src/tab_index.h --- kchmviewer-4.1/src/tab_index.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_index.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,52 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef TAB_INDEX_H +#define TAB_INDEX_H + + +#include "kde-qt.h" +#include "ui_tab_index.h" + + +class TabIndex : public QWidget, public Ui::TabIndex +{ + Q_OBJECT + public: + TabIndex( QWidget * parent = 0 ); + + void invalidate(); + void search( const QString& index ); + + private slots: + void onTextChanged ( const QString & newvalue); + void onReturnPressed (); + void onDoubleClicked ( QTreeWidgetItem * item, int column ); + void onContextMenuRequested ( const QPoint &point ); + + private: + virtual void showEvent ( QShowEvent * ); + + void refillIndex(); + + QMenu * m_contextMenu; + QTreeWidgetItem * m_lastSelectedItem; + bool m_indexListFilled; +}; + +#endif diff -Nru kchmviewer-4.1/src/tab_search.cpp kchmviewer-5.1/src/tab_search.cpp --- kchmviewer-4.1/src/tab_search.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_search.cpp 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,308 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include + +#include "libchmfile.h" + +#include "mainwindow.h" +#include "config.h" +#include "treeviewitem.h" +#include "tab_search.h" + + +class SearchTreeViewItem : public QTreeWidgetItem +{ + public: + SearchTreeViewItem( QTreeWidget * tree, const QString& name, const QString& url ) + : QTreeWidgetItem( tree ), m_name( name ), m_url( url ) {} + + QString getUrl() const { return m_url; } + + protected: + // Overriden members + int columnCount () const { return 2; } + + // Overriden member + QVariant data ( int column, int role ) const + { + switch( role ) + { + // Item name + case Qt::DisplayRole: + case Qt::ToolTipRole: + case Qt::WhatsThisRole: + if ( column == 0 ) + return m_name; + else + return m_url; + } + + return QVariant(); + } + + private: + QString m_name; + QString m_url; +}; + + + +TabSearch::TabSearch( QWidget * parent ) + : QWidget( parent ), Ui::TabSearch() +{ + // UIC stuff + setupUi( this ); + + // Clickable Help label + connect( lblHelp, + SIGNAL( linkActivated( const QString & ) ), + this, + SLOT( onHelpClicked(const QString & ) ) ); + + // Go Button + connect( btnGo, + SIGNAL( clicked () ), + this, + SLOT( onReturnPressed() ) ); + + // Pressing 'Return' in the combo box line edit + connect( searchBox->lineEdit(), + SIGNAL( returnPressed() ), + this, + SLOT( onReturnPressed() ) ); + + // Clicking on tree element + connect( tree, + SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), + this, + SLOT( onDoubleClicked( QTreeWidgetItem *, int ) ) ); + + // Activate custom context menu, and connect it + tree->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( tree, + SIGNAL( customContextMenuRequested ( const QPoint & ) ), + this, + SLOT( onContextMenuRequested( const QPoint & ) ) ); + + searchBox->setFocus(); + + m_contextMenu = 0; + m_genIndexProgress = 0; + m_searchEngineInitDone = false; + + m_searchEngine = new LCHMSearchEngine(); + connect( m_searchEngine, SIGNAL( progressStep( int, const QString& ) ), this, SLOT( onProgressStep( int, const QString& ) ) ); +} + + +void TabSearch::invalidate( ) +{ + tree->clear(); + searchBox->clear(); + searchBox->lineEdit()->clear(); + + delete m_genIndexProgress; + m_genIndexProgress = 0; + + m_searchEngineInitDone = false; +} + + +void TabSearch::onReturnPressed( ) +{ + QStringList results; + QString text = searchBox->lineEdit()->text(); + + if ( text.isEmpty() ) + return; + + tree->clear(); + + if ( searchQuery( text, &results ) ) + { + if ( !results.empty() ) + { + for ( int i = 0; i < results.size(); i++ ) + { + new SearchTreeViewItem ( tree, + ::mainWindow->chmFile()->getTopicByUrl( results[i] ), + results[i] ); + } + + ::mainWindow->showInStatusBar( i18n( "Search returned %1 result(s)" ) . arg(results.size()) ); + } + else + ::mainWindow->showInStatusBar( i18n( "Search returned no results") ); + } + else + ::mainWindow->showInStatusBar( i18n( "Search failed") ); +} + + +void TabSearch::onDoubleClicked( QTreeWidgetItem * item, int ) +{ + if ( !item ) + return; + + SearchTreeViewItem * treeitem = (SearchTreeViewItem *) item; + ::mainWindow->openPage( treeitem->getUrl(), MainWindow::OPF_ADD2HISTORY ); +} + + +void TabSearch::restoreSettings( const Settings::search_saved_settings_t & settings ) +{ + for ( int i = 0; i < settings.size(); i++ ) + searchBox->addItem (settings[i]); +} + + +void TabSearch::saveSettings( Settings::search_saved_settings_t & settings ) +{ + settings.clear(); + + for ( int i = 0; i < searchBox->count(); i++ ) + settings.push_back( searchBox->itemText(i) ); +} + + +void TabSearch::onHelpClicked( const QString & ) +{ + QWhatsThis::showText ( mapToGlobal( lblHelp->pos() ), + i18n( "

The improved search engine allows you to search for a word, symbol or phrase, which is set of words and symbols included in quotes. Only the documents which include all the terms speficide in th search query are shown; no prefixes needed.

Unlike MS CHM internal search index, my improved search engine indexes everything, including special symbols. Therefore it is possible to search (and find!) for something like $q = new ChmFile();. This search also fully supports Unicode, which means that you can search in non-English documents.

If you want to search for a quote symbol, use quotation mark instead. The engine treats a quote and a quotation mark as the same symbol, which allows to use them in phrases.") ); +} + + +bool TabSearch::initSearchEngine( ) +{ + ShowWaitCursor waitcursor; + + QString indexfile = ::mainWindow->currentSettings()->searchIndexFile(); + + // First try to read the index if exists + QFile file( indexfile ); + + if ( file.open( QIODevice::ReadOnly ) ) + { + QDataStream stream( &file ); + + ::mainWindow->statusBar()->showMessage( i18n( "Reading dictionary..." ) ); + qApp->processEvents( QEventLoop::ExcludeUserInputEvents ); + + if ( m_searchEngine->loadIndex( stream ) ) + { + m_searchEngineInitDone = true; + return true; + } + } + + // So the index cannot be read or does not exist. Create a new one. + + // Show the user what we gonna do + m_genIndexProgress = new QProgressDialog( this ); + m_genIndexProgress->setWindowTitle( i18n( "Generating search index..." ) ); + m_genIndexProgress->setLabelText( i18n( "Generating search index..." ) ); + m_genIndexProgress->setMaximum( 100 ); + m_genIndexProgress->reset(); + m_genIndexProgress->show(); + + ::mainWindow->statusBar()->showMessage( tr( "Generating search index..." ) ); + + // Show 'em + qApp->processEvents( QEventLoop::ExcludeUserInputEvents ); + + // Since we gonna save it, reopen the file + file.close(); + + if ( !file.open( QIODevice::WriteOnly ) ) + { + QMessageBox::critical( 0, "Cannot save index", tr("The index cannot be saved into file %1") .arg( file.fileName() ) ); + return false; + } + + // Run the generation + QDataStream stream( &file ); + + m_searchEngine->generateIndex( ::mainWindow->chmFile(), stream ); + + delete m_genIndexProgress; + m_genIndexProgress = 0; + + if ( m_searchEngine->hasIndex() ) + { + m_searchEngineInitDone = true; + return true; + } + + m_searchEngineInitDone = false; + return false; +} + + +void TabSearch::execSearchQueryInGui( const QString & query ) +{ + searchBox->lineEdit()->setText( query ); + onReturnPressed(); +} + + +bool TabSearch::searchQuery( const QString & query, QStringList * results ) +{ + if ( !m_searchEngineInitDone ) + { + if ( !initSearchEngine() ) + return false; + } + + if ( !m_searchEngine->hasIndex() ) + { + QMessageBox::information ( this, "No index present", "The index is not present" ); + return false; + } + + if ( query.isEmpty() ) + return false; + + ShowWaitCursor waitcursor; + bool result; + + result = m_searchEngine->searchQuery( query, results, ::mainWindow->chmFile() ); + return result; +} + + +void TabSearch::onContextMenuRequested( const QPoint & point ) +{ + SearchTreeViewItem * treeitem = (SearchTreeViewItem *) tree->itemAt( point ); + + if( treeitem ) + { + ::mainWindow->currentBrowser()->setTabKeeper( treeitem->getUrl() ); + ::mainWindow->tabItemsContextMenu()->popup( tree->viewport()->mapToGlobal( point ) ); + } +} + + +void TabSearch::onProgressStep(int value, const QString & stepName) +{ + if ( m_genIndexProgress ) + { + m_genIndexProgress->setLabelText( stepName ); + m_genIndexProgress->setValue( value ); + } +} diff -Nru kchmviewer-4.1/src/tab_search.h kchmviewer-5.1/src/tab_search.h --- kchmviewer-4.1/src/tab_search.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/tab_search.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,62 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef TAB_SEARCH_H +#define TAB_SEARCH_H + +#include "kde-qt.h" +#include "settings.h" +#include "ui_tab_search.h" + +#include "libchmsearchengine.h" + + +class TabSearch : public QWidget, public Ui::TabSearch +{ + Q_OBJECT + public: + TabSearch( QWidget * parent = 0 ); + + void invalidate(); + void restoreSettings (const Settings::search_saved_settings_t& settings); + void saveSettings( Settings::search_saved_settings_t& settings ); + void execSearchQueryInGui( const QString& query ); + bool searchQuery( const QString& query, QStringList * results ); + + private slots: + void onContextMenuRequested ( const QPoint &point ); + void onHelpClicked( const QString & ); + void onReturnPressed (); + void onDoubleClicked( QTreeWidgetItem * item, int ); + + // For index generation + void onProgressStep( int value, const QString& stepName ); + + private: + bool initSearchEngine(); + + private: + QMenu * m_contextMenu; + LCHMSearchEngine* m_searchEngine; + bool m_searchEngineInitDone; + + // For index generation + QProgressDialog * m_genIndexProgress; +}; + +#endif diff -Nru kchmviewer-4.1/src/treeviewitem.cpp kchmviewer-5.1/src/treeviewitem.cpp --- kchmviewer-4.1/src/treeviewitem.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/treeviewitem.cpp 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,205 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include + +#include "treeviewitem.h" +#include "mainwindow.h" +#include "dialog_chooseurlfromlist.h" + + +IndexTocItem::IndexTocItem( QTreeWidgetItem * parent, QTreeWidgetItem * after, const QString& name, const QString& aurl, int image) + : QTreeWidgetItem( parent, after ), m_name(name), m_url(aurl), m_image_number(image) +{ +} + +IndexTocItem::IndexTocItem( QTreeWidget * parent, QTreeWidgetItem * after, const QString& name, const QString& aurl, int image) + : QTreeWidgetItem( parent, after ), m_name(name), m_url(aurl), m_image_number(image) +{ +} + + +QString IndexTocItem::getUrl( ) const +{ + if ( m_url.indexOf ('|') == -1 ) + return m_url; + + // Create a dialog with URLs, and show it, so user can select an URL he/she wants. + QStringList urls = m_url.split( '|' ); + QStringList titles; + LCHMFile * xchm = ::mainWindow->chmFile(); + + for ( int i = 0; i < urls.size(); i++ ) + { + QString title = xchm->getTopicByUrl (urls[i]); + + if ( title.isEmpty() ) + { + qWarning( "Could not get item name for url '%s'", qPrintable( urls[i] ) ); + titles.push_back(QString::null); + } + else + titles.push_back(title); + } + + DialogChooseUrlFromList dlg( ::mainWindow ); + return dlg.getSelectedItemUrl( urls, titles ); +} + + +int IndexTocItem::columnCount() const +{ + return 1; +} + +QVariant IndexTocItem::data(int column, int role) const +{ + int imagenum; + + if ( column != 0 ) + return QVariant(); + + switch( role ) + { + // Item name + case Qt::DisplayRole: + return m_name; + + // Item image + case Qt::DecorationRole: + if ( m_image_number != LCHMBookIcons::IMAGE_NONE + && m_image_number != LCHMBookIcons::IMAGE_INDEX ) + { + // If the item has children, we change the book image to "open book", or next image automatically + if ( childCount() ) + { + if ( isExpanded() ) + imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 1 : m_image_number; + else + imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 0 : m_image_number + 1; + } + else + imagenum = (m_image_number == LCHMBookIcons::IMAGE_AUTO) ? 10 : m_image_number; + + const QPixmap *pix = ::mainWindow->chmFile()->getBookIconPixmap( imagenum ); + + if ( !pix || pix->isNull() ) + abort(); + + return *pix; + } + break; + + // Item foreground color + case Qt::ForegroundRole: + // For Index URL it means that there is URL list in m_url + if ( m_url.indexOf( '|' ) != -1 ) + return QBrush( QColor( Qt::red ) ); + // For Index URLs it means that this is "see also" URL + else if ( !m_url.isEmpty() && m_url[0] == ':' ) + return QBrush( QColor( Qt::lightGray ) ); + break; + + case Qt::ToolTipRole: + case Qt::WhatsThisRole: + return m_name; + } + + return QVariant(); +} + + +void kchmFillListViewWithParsedData( QTreeWidget * list, const QVector< LCHMParsedEntry >& data, QMap * map ) +{ + QVector< IndexTocItem *> lastchild; + QVector< IndexTocItem *> rootentry; + bool warning_shown = false; + + if ( map ) + map->clear(); + + list->clear(); + + for ( int i = 0; i < data.size(); i++ ) + { + int indent = data[i].indent; + + // Do we need to add another indent? + if ( indent >= rootentry.size() ) + { + int maxindent = rootentry.size() - 1; + + // Resize the arrays + lastchild.resize( indent + 1 ); + rootentry.resize( indent + 1 ); + + if ( indent > 0 && maxindent < 0 ) + qFatal("Invalid fisrt TOC indent (first entry has no root entry), aborting."); + + // And init the rest if needed + if ( (indent - maxindent) > 1 ) + { + if ( !warning_shown ) + { + qWarning("Invalid TOC step, applying workaround. Results may vary."); + warning_shown = true; + } + + for ( int j = maxindent; j < indent; j++ ) + { + lastchild[j+1] = lastchild[j]; + rootentry[j+1] = rootentry[j]; + } + } + + lastchild[indent] = 0; + rootentry[indent] = 0; + } + + // Create the node + IndexTocItem * item; + QString url = data[i].urls.join ("|"); + + if ( indent == 0 ) + item = new IndexTocItem( list, lastchild[indent], data[i].name, url, data[i].imageid ); + else + { + // New non-root entry. It is possible (for some buggy CHMs) that there is no previous entry: previoous entry had indent 1, + // and next entry has indent 3. Backtracking it up, creating missing entries. + if ( rootentry[indent-1] == 0 ) + qFatal("Child entry indented as %d with no root entry!", indent); + + item = new IndexTocItem( rootentry[indent-1], lastchild[indent], data[i].name, url, data[i].imageid ); + } + + // Hack: if map is 0, we have index, so make it open + if ( map ) + { + for ( int li = 0; li < data[i].urls.size(); li++ ) + map->insert( data[i].urls[li], item ); + } + else + item->setExpanded( true ); + + lastchild[indent] = item; + rootentry[indent] = item; + } + + list->update(); +} diff -Nru kchmviewer-4.1/src/treeviewitem.h kchmviewer-5.1/src/treeviewitem.h --- kchmviewer-4.1/src/treeviewitem.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/treeviewitem.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,54 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef TREEVIEWITEM_H +#define TREEVIEWITEM_H + +#include +#include +#include +#include +#include + +#include "libchmfile.h" + + +//! This is a list item used both in Index and Table Of Content trees +class IndexTocItem : public QTreeWidgetItem +{ + public: + IndexTocItem( QTreeWidgetItem* parent, QTreeWidgetItem* after, const QString& name, const QString& aurl, int image); + IndexTocItem( QTreeWidget* parent, QTreeWidgetItem* after, const QString& name, const QString& url, int image); + + QString getUrl() const; + + // Overridden methods + int columnCount () const; + QVariant data ( int column, int role ) const; + + private: + QString m_name; + QString m_url; + int m_image_number; +}; + + + +void kchmFillListViewWithParsedData( QTreeWidget * list, const QVector< LCHMParsedEntry >& data, QMap * map ); + +#endif diff -Nru kchmviewer-4.1/src/version.h kchmviewer-5.1/src/version.h --- kchmviewer-4.1/src/version.h 2009-07-20 04:36:32.000000000 +0100 +++ kchmviewer-5.1/src/version.h 2009-12-16 10:01:43.000000000 +0000 @@ -1,28 +1,25 @@ -/*************************************************************************** - * Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com * - * Please do not use email address above for bug reports; see * - * the README file * - * * - * 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 3 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ #ifndef INCLUDE_VERSION_H #define INCLUDE_VERSION_H -#define APP_NAME "kchmviewer" -#define APP_VERSION "4.1" +#define APP_VERSION_MAJOR 5 +#define APP_VERSION_MINOR 1 #endif /* INCLUDE_VERSION_H */ diff -Nru kchmviewer-4.1/src/viewwindow.cpp kchmviewer-5.1/src/viewwindow.cpp --- kchmviewer-4.1/src/viewwindow.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow.cpp 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,299 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +// Do not use tr() or i18n() in this file - this class is not derived from QObject. + +#include +#include +#include + +#include "libchmfile.h" +#include "libchmurlfactory.h" + +#include "config.h" +#include "viewwindow.h" +#include "mainwindow.h" +#include "viewwindowmgr.h" + + +ViewWindow::ViewWindow( ViewWindowTabs * parent ) +{ + invalidate(); + m_contextMenu = 0; + m_contextMenuLink = 0; + m_historyMaxSize = 25; + + m_parentTabWidget = parent; +} + +ViewWindow::~ViewWindow() +{ +} + +void ViewWindow::invalidate( ) +{ + m_base_url = "/"; + m_openedPage = QString::null; + m_newTabLinkKeeper = QString::null; + + m_historyCurrentPos = 0; + m_history.clear(); + + updateNavigationToolbar(); +} + + + +QString ViewWindow::makeURLabsolute ( const QString & url, bool set_as_base ) +{ + QString p1, p2, newurl = url; + + if ( !LCHMUrlFactory::isRemoteURL (url, p1) + && !LCHMUrlFactory::isJavascriptURL (url) + && !LCHMUrlFactory::isNewChmURL (url, p1, p2) ) + { + newurl = QDir::cleanPath (url); + + // Normalize url, so it becomes absolute + if ( newurl[0] != '/' ) + newurl = m_base_url + "/" + newurl; + + newurl = QDir::cleanPath (newurl); + + if ( set_as_base ) + { + m_base_url = newurl; + + // and set up new baseurl + int i = newurl.lastIndexOf('/'); + if ( i != -1 ) + m_base_url = QDir::cleanPath (newurl.left (i + 1)); + } + } + + //qDebug ("ViewWindow::makeURLabsolute (%s) -> (%s)", url.ascii(), newurl.ascii()); + return newurl; +} + +bool ViewWindow::openUrl ( const QString& origurl ) +{ + QString chmfile, page, newurl = origurl; + + if ( origurl.isEmpty() ) + return true; + + // URL could be a complete ms-its link. The file should be already loaded (for QTextBrowser), + // or will be loaded (for kio slave). We care only about the path component. + if ( LCHMUrlFactory::isNewChmURL( newurl, chmfile, page ) ) + { + // If a new chm file is opened here, and we do not use KCHMLPart, we better abort + if ( chmfile != ::mainWindow->getOpenedFileBaseName() && pConfig->m_usedBrowser != Config::BROWSER_KHTMLPART ) + qFatal("ViewWindow::openUrl(): opened new chm file %s while current is %s", + qPrintable( chmfile ), + qPrintable( ::mainWindow->getOpenedFileName() ) ); + + // It is OK to have a new file in chm for KHTMLPart + newurl = page; + } + + makeURLabsolute (newurl); + handleStartPageAsImage( newurl ); + + if ( openPage (newurl) ) + { + m_newTabLinkKeeper = QString::null; + m_openedPage = newurl; + + // If m_openedPage contains #, strip it, and everything after it + int hash = m_openedPage.indexOf( '#' ); + if ( hash != -1 ) + m_openedPage = m_openedPage.left( hash ); + + mainWindow->viewWindowMgr()->setTabName( this ); + return true; + } + + return false; +} + +void ViewWindow::handleStartPageAsImage( QString & link ) +{ + // Handle pics + if ( link.endsWith( ".jpg", Qt::CaseInsensitive ) + || link.endsWith( ".jpeg", Qt::CaseInsensitive ) + || link.endsWith( ".gif", Qt::CaseInsensitive ) + || link.endsWith( ".png", Qt::CaseInsensitive ) + || link.endsWith( ".bmp", Qt::CaseInsensitive ) ) + link += LCHMUrlFactory::getInternalUriExtension(); +} + + +QMenu * ViewWindow::createStandardContextMenu( QWidget * parent ) +{ + QMenu * contextMenu = new QMenu( parent ); + + contextMenu->addAction( "&Copy", ::mainWindow, SLOT(slotBrowserCopy()) ); + contextMenu->addAction( "&Select all", ::mainWindow, SLOT(slotBrowserSelectAll()) ); + + return contextMenu; +} + + +QMenu * ViewWindow::getContextMenu( const QString & link, QWidget * parent ) +{ + if ( link.isEmpty() ) + { + // standard context menu + if ( !m_contextMenu ) + m_contextMenu = createStandardContextMenu( parent ); + + return m_contextMenu; + } + else + { + // Open in New Tab context menu + // standard context menu + if ( !m_contextMenuLink ) + { + m_contextMenuLink = createStandardContextMenu( parent ); + m_contextMenuLink->addSeparator(); + + m_contextMenuLink->addAction( "&Open this link in a new tab", ::mainWindow, SLOT(onOpenPageInNewTab()), QKeySequence("Shift+Enter") ); + + m_contextMenuLink->addAction( "&Open this link in a new background tab", ::mainWindow, SLOT(onOpenPageInNewBackgroundTab()), QKeySequence("Ctrl+Enter") ); + } + + setTabKeeper( link ); + return m_contextMenuLink; + } +} + +QString ViewWindow::getTitle() const +{ + QString title = ::mainWindow->chmFile()->getTopicByUrl( m_openedPage ); + + if ( title.isEmpty() ) + title = m_openedPage; + + return title; +} + + +void ViewWindow::navigateForward() +{ + if ( m_historyCurrentPos < m_history.size() ) + { + m_historyCurrentPos++; + ::mainWindow->openPage( m_history[m_historyCurrentPos].getUrl() ); + setScrollbarPosition( m_history[m_historyCurrentPos].getScrollPosition() ); + + // By default navigation starts with empty array, and a new entry is added when + // you change the current page (or it may not be added). So to have the whole system + // worked, the m_historyCurrentPos should never be m_history.size() - 1, it should be + // either greater or lesser. + // + // This is a dirty hack - but the whole navigation system now looks to me like + // it was written by some drunk monkey - which is probably not far from The Real Truth. + // Shame on me - Tim. + if ( m_historyCurrentPos == (m_history.size() - 1) ) + m_historyCurrentPos++; + } + + updateNavigationToolbar(); +} + +void ViewWindow::navigateBack( ) +{ + if ( m_historyCurrentPos > 0 ) + { + // If we're on top of list, and pressing Back, the last page is still + // not in list - so add it, if it is not still here + if ( m_historyCurrentPos == m_history.size() ) + { + if ( m_history[m_historyCurrentPos-1].getUrl() != m_openedPage ) + m_history.push_back( UrlHistory( m_openedPage, getScrollbarPosition() ) ); + else + { + // part 2 of the navigation hack - see navigateForward() comment + m_history[m_historyCurrentPos-1].setScrollPosition( getScrollbarPosition() ); + m_historyCurrentPos--; + } + } + + m_historyCurrentPos--; + + ::mainWindow->openPage( m_history[m_historyCurrentPos].getUrl() ); + setScrollbarPosition( m_history[m_historyCurrentPos].getScrollPosition() ); + } + + updateNavigationToolbar(); +} + +void ViewWindow::navigateHome( ) +{ + ::mainWindow->openPage( ::mainWindow->chmFile()->homeUrl() ); +} + +void ViewWindow::addNavigationHistory( const QString & url, int scrollpos ) +{ + // shred the 'forward' history + if ( m_historyCurrentPos < m_history.size() ) + m_history.erase( m_history.begin() + m_historyCurrentPos, m_history.end() ); + + // do not grow the history if already max size + if ( m_history.size() >= m_historyMaxSize ) + m_history.pop_front(); + + m_history.push_back( UrlHistory( url, scrollpos ) ); + m_historyCurrentPos = m_history.size(); + + updateNavigationToolbar(); +} + +void ViewWindow::updateNavigationToolbar( ) +{ + // Dump navigation for debugging +#if 0 + qDebug("\nNavigation dump (%d entries, current pos %d)", m_history.size(), m_historyCurrentPos ); + for ( unsigned int i = 0; i < m_history.size(); i++ ) + qDebug("[%02d]: %s [%d]", i, m_history[i].getUrl().ascii(), m_history[i].getScrollPosition()); +#endif + + if ( mainWindow ) + { + mainWindow->navSetBackEnabled( m_historyCurrentPos > 0 ); + mainWindow->navSetForwardEnabled( m_historyCurrentPos < (m_history.size() - 1) ); + } +} + + +void ViewWindow::setTabKeeper( const QString & link ) +{ + // If we clicked on relative link, make sure we convert it to absolute right now, + // because later we will not have access to this view window variables + m_newTabLinkKeeper = link; + if ( m_newTabLinkKeeper[0] == '#' && !m_openedPage.isEmpty() ) + { + // Clean up opened page URL + int pos = m_openedPage.indexOf('#'); + QString fixedpath = pos == -1 ? m_openedPage : m_openedPage.left (pos); + m_newTabLinkKeeper = fixedpath + m_newTabLinkKeeper; + } + + m_newTabLinkKeeper = makeURLabsolute( m_newTabLinkKeeper, false ); +} diff -Nru kchmviewer-4.1/src/viewwindow.h kchmviewer-5.1/src/viewwindow.h --- kchmviewer-4.1/src/viewwindow.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,155 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef VIEWWINDOW_H +#define VIEWWINDOW_H + + +#include "kde-qt.h" + +class ViewWindowTabs; + +class ViewWindow +{ + public: + enum + { + SEARCH_CASESENSITIVE = 0x10, + SEARCH_WHOLEWORDS = 0x20 + }; + + ViewWindow ( ViewWindowTabs * parent ); + virtual ~ViewWindow(); + + //! Open a page from current chm archive + bool openUrl (const QString& url ); + + QString getBaseUrl() const { return m_base_url; } + QString getOpenedPage() const { return m_openedPage; } + QString getNewTabLink() const { return m_newTabLinkKeeper; } + QString makeURLabsolute ( const QString &url, bool set_as_base = true ); + + public: + // virtual members, which should be implemented by viewers + //! Invalidate current view, doing all the cleanups etc. + virtual void invalidate(); + + //! Popups the print dialog, and prints the current page on the printer. + virtual bool printCurrentPage() = 0; + + //! Search function. find() starts new search, onFindNext and onFindPrevious continue it + virtual void find( const QString& text, int flags ) = 0; + virtual void onFindNext() = 0; + virtual void onFindPrevious() = 0; + + //! Return current ZoomFactor. + virtual int getZoomFactor() const = 0; + + //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. + virtual void setZoomFactor (int zoom) = 0; + + //! Relatively changes ZoomFactor. Most common values are -1 and 1. + virtual void addZoomFactor (int value) = 0; + + virtual QObject * getQObject() = 0; + virtual QWidget * getQWidget() = 0; + + /*! + * Return current scrollbar position in view window. Saved on program exit. + * There is no restriction on returned value, except that giving this value to + * setScrollbarPosition() should move the scrollbar in the same position. + */ + virtual int getScrollbarPosition() = 0; + + //! Sets the scrollbar position. + virtual void setScrollbarPosition(int pos) = 0; + + //! Select the content of the whole page + virtual void clipSelectAll() = 0; + + //! Copies the selected content to the clipboard + virtual void clipCopy() = 0; + + //! Returns the window title + virtual QString getTitle() const; + + //! Navigation stuff + virtual void navigateBack(); + virtual void navigateHome(); + virtual void navigateForward(); + + //! Navigation auxiliary stuff + virtual void setHistoryMaxSize (unsigned int size) { m_historyMaxSize = size; } + virtual void addNavigationHistory( const QString & url, int scrollpos ); + virtual void updateNavigationToolbar(); + + //! Keeps the tab URL between link following + void setTabKeeper ( const QString& link ); + + protected: /* signals */ + /*! + * Emitted when the user clicked on the link, before the page changed. + * If linkClicked() return false, the current page should NOT change. + * Otherwise it should be changed to the new link value. + */ + virtual void linkClicked ( const QString & newlink, bool& follow_link ) = 0; + + protected: + virtual bool openPage ( const QString& url ) = 0; + virtual void handleStartPageAsImage( QString& link ); + + QMenu * getContextMenu( const QString& link, QWidget * parent ); + QMenu * createStandardContextMenu( QWidget * parent ); + + private: + //! History + class UrlHistory + { + public: + UrlHistory() { scrollbarpos = 0; } + UrlHistory( const QString& _url, int _scrollbarpos ) + : url(_url), scrollbarpos(_scrollbarpos) {} + + const QString& getUrl() const { return url; } + int getScrollPosition() const { return scrollbarpos; } + void setScrollPosition( int pos ) { scrollbarpos = pos; } + + private: + QString url; + int scrollbarpos; + }; + + int m_historyMaxSize; + int m_historyCurrentPos; + QMenu * m_contextMenu; + QMenu * m_contextMenuLink; + QList m_history; + + QString m_openedPage; + QString m_lastOpenedPage; + QString m_base_url; + + // The parent tab browser + ViewWindowTabs * m_parentTabWidget; + + // This member keeps a "open new tab" link between getContextMenu() + // call and appropriate slot call + QString m_newTabLinkKeeper; +}; + +#endif diff -Nru kchmviewer-4.1/src/viewwindowmgr.cpp kchmviewer-5.1/src/viewwindowmgr.cpp --- kchmviewer-4.1/src/viewwindowmgr.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindowmgr.cpp 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,423 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include "config.h" +#include "mainwindow.h" +#include "viewwindow.h" +#include "viewwindowmgr.h" + +#include "viewwindow_qtextbrowser.h" + +#if defined (USE_KDE) + #include "kde/viewwindow_khtmlpart.h" +#endif + +#if defined (QT_WEBKIT_LIB) + #include "viewwindow_qtwebkit.h" +#endif + + + +// A small overriden class to handle a middle click +ViewWindowTabs::ViewWindowTabs( QWidget * parent ) + : QTabWidget( parent ) +{ +} + +ViewWindowTabs::~ViewWindowTabs() +{ +} + +void ViewWindowTabs::mouseReleaseEvent ( QMouseEvent * event ) +{ + if ( event->button() == Qt::MidButton) + { + int tab = tabBar()->tabAt( event->pos() ); + + if ( tab != -1 ) + emit mouseMiddleClickTab( tab ); + } +} + + + +ViewWindowMgr::ViewWindowMgr( QWidget *parent ) + : QWidget( parent ), Ui::TabbedBrowser() +{ + // UIC + setupUi( this ); + + // Create the tab widget + m_tabWidget = new ViewWindowTabs( this ); + verticalLayout->insertWidget( 0, m_tabWidget, 10 ); + + // on current tab changed + connect( m_tabWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( onTabChanged(QWidget *) ) ); + connect( m_tabWidget, SIGNAL( mouseMiddleClickTab( int ) ), this, SLOT( onCloseWindow(int) ) ); + + // Create a close button + m_closeButton = new QToolButton( this ); + m_closeButton->setCursor( Qt::ArrowCursor ); + m_closeButton->setAutoRaise( true ); + m_closeButton->setIcon( QIcon( ":/images/closetab.png" ) ); + m_closeButton->setToolTip( i18n("Close current page") ); + m_closeButton->setEnabled( false ); + connect( m_closeButton, SIGNAL( clicked() ), this, SLOT( onCloseCurrentWindow() ) ); + + // Put it there + m_tabWidget->setCornerWidget( m_closeButton, Qt::TopRightCorner ); + + // Create a "new tab" button + QToolButton * newButton = new QToolButton( this ); + newButton->setCursor( Qt::ArrowCursor ); + newButton->setAutoRaise( true ); + newButton->setIcon( QIcon( ":/images/addtab.png" ) ); + newButton->setToolTip( i18n("Add page") ); + connect( newButton, SIGNAL( clicked() ), this, SLOT( openNewTab() ) ); + + // Put it there + m_tabWidget->setCornerWidget( newButton, Qt::TopLeftCorner ); + + // Hide the search frame + frameFind->setVisible( false ); + labelWrapped->setVisible( false ); + + // Search Line edit + connect( editFind, + SIGNAL( textEdited ( const QString & ) ), + this, + SLOT( editTextEdited( const QString & ) ) ); + + // Search toolbar buttons + connect( toolClose, SIGNAL(clicked()), frameFind, SLOT( hide()) ); + connect( toolPrevious, SIGNAL(clicked()), this, SLOT( onFindPrevious()) ); + connect( toolNext, SIGNAL(clicked()), this, SLOT( onFindNext()) ); +} + +ViewWindowMgr::~ViewWindowMgr( ) +{ +} + +void ViewWindowMgr::createMenu( MainWindow *, QMenu * menuWindow, QAction * actionCloseWindow ) +{ + m_menuWindow = menuWindow; + m_actionCloseWindow = actionCloseWindow; +} + +void ViewWindowMgr::invalidate() +{ + closeAllWindows(); + addNewTab( true ); +} + + +ViewWindow * ViewWindowMgr::current() +{ + TabData * tab = findTab( m_tabWidget->currentWidget() ); + + if ( !tab ) + abort(); + + return tab->window; +} + +ViewWindow * ViewWindowMgr::addNewTab( bool set_active ) +{ + ViewWindow * viewvnd; + + switch ( pConfig->m_usedBrowser ) + { + default: + viewvnd = new ViewWindow_QTextBrowser( m_tabWidget ); + break; + +#if defined (USE_KDE) + case Config::BROWSER_KHTMLPART: + viewvnd = new ViewWindow_KHTMLPart( m_tabWidget ); + break; +#endif + +#if defined (QT_WEBKIT_LIB) + case Config::BROWSER_QTWEBKIT: + viewvnd = new ViewWindow_QtWebKit( m_tabWidget ); + break; +#endif + } + + editFind->installEventFilter( this ); + + // Create the tab data structure + TabData tabdata; + tabdata.window = viewvnd; + tabdata.action = new QAction( "window", this ); // temporary name; real name is set in setTabName + tabdata.widget = viewvnd->getQWidget(); + + connect( tabdata.action, + SIGNAL( triggered() ), + this, + SLOT( activateWindow() ) ); + + m_Windows.push_back( tabdata ); + m_tabWidget->addTab( tabdata.widget, "" ); + Q_ASSERT( m_Windows.size() == m_tabWidget->count() ); + + // Set active if it is the first tab + if ( set_active || m_Windows.size() == 1 ) + m_tabWidget->setCurrentWidget( tabdata.widget ); + + // Handle clicking on link in browser window + connect( viewvnd->getQObject(), + SIGNAL( linkClicked (const QString &, bool &) ), + ::mainWindow, + SLOT( activateLink(const QString &, bool &) ) ); + + // Set up the accelerator if we have room + if ( m_Windows.size() < 10 ) + tabdata.action->setShortcut( QKeySequence( i18n("Alt+%1").arg( m_Windows.size() ) ) ); + + // Add it to the "Windows" menu + m_menuWindow->addAction( tabdata.action ); + + return viewvnd; +} + +void ViewWindowMgr::closeAllWindows( ) +{ + // No it++ - we removing the window by every closeWindow call + while ( m_Windows.begin() != m_Windows.end() ) + closeWindow( m_Windows.first().widget ); +} + +void ViewWindowMgr::setTabName( ViewWindow * window ) +{ + TabData * tab = findTab( window->getQWidget() ); + + if ( tab ) + { + QString title = window->getTitle(); + + // Trim too long string + if ( title.length() > 25 ) + title = title.left( 22 ) + "..."; + + m_tabWidget->setTabText( m_tabWidget->indexOf( window->getQWidget() ), title ); + tab->action->setText( title ); + + updateCloseButtons(); + } +} + +void ViewWindowMgr::onCloseCurrentWindow( ) +{ + // Do not allow to close the last window + if ( m_Windows.size() == 1 ) + return; + + TabData * tab = findTab( m_tabWidget->currentWidget() ); + closeWindow( tab->widget ); +} + + +void ViewWindowMgr::onCloseWindow( int num ) +{ + // Do not allow to close the last window + if ( m_Windows.size() == 1 ) + return; + + TabData * tab = findTab( m_tabWidget->widget( num )); + + if ( tab ) + closeWindow( tab->widget ); +} + +void ViewWindowMgr::closeWindow( QWidget * widget ) +{ + WindowsIterator it; + + for ( it = m_Windows.begin(); it != m_Windows.end(); ++it ) + if ( it->widget == widget ) + break; + + if ( it == m_Windows.end() ) + qFatal( "ViewWindowMgr::closeWindow called with unknown widget!" ); + + m_menuWindow->removeAction( it->action ); + + m_tabWidget->removeTab( m_tabWidget->indexOf( it->widget ) ); + delete it->window; + delete it->action; + + m_Windows.erase( it ); + updateCloseButtons(); + + // Change the accelerators, as we might have removed the item in the middle + int count = 1; + for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end() && count < 10; ++it, count++ ) + (*it).action->setShortcut( QKeySequence( i18n("Alt+%1").arg( count ) ) ); +} + + +void ViewWindowMgr::restoreSettings( const Settings::viewindow_saved_settings_t & settings ) +{ + // Destroy automatically created tab + closeWindow( m_Windows.first().widget ); + + for ( int i = 0; i < settings.size(); i++ ) + { + ViewWindow * window = addNewTab( false ); + window->openUrl( settings[i].url ); // will call setTabName() + window->setScrollbarPosition( settings[i].scroll_y ); + window->setZoomFactor( settings[i].zoom ); + } +} + + +void ViewWindowMgr::saveSettings( Settings::viewindow_saved_settings_t & settings ) +{ + settings.clear(); + + for ( int i = 0; i < m_tabWidget->count(); i++ ) + { + QWidget * p = m_tabWidget->widget( i ); + TabData * tab = findTab( p ); + + if ( !tab ) + abort(); + + settings.push_back( Settings::SavedViewWindow( tab->window->getOpenedPage(), + tab->window->getScrollbarPosition(), + tab->window->getZoomFactor()) ); + } +} + +void ViewWindowMgr::updateCloseButtons( ) +{ + bool enabled = m_Windows.size() > 1; + + m_actionCloseWindow->setEnabled( enabled ); + m_closeButton->setEnabled( enabled ); +} + +void ViewWindowMgr::onTabChanged( QWidget * newtab ) +{ + TabData * tab = findTab( newtab ); + + if ( tab ) + { + tab->window->updateNavigationToolbar(); + mainWindow->browserChanged( tab->window ); + tab->widget->setFocus(); + } +} + + +void ViewWindowMgr::openNewTab() +{ + ::mainWindow->openPage( current()->getOpenedPage(), + MainWindow::OPF_NEW_TAB | MainWindow::OPF_CONTENT_TREE | MainWindow::OPF_ADD2HISTORY ); +} + +void ViewWindowMgr::activateWindow() +{ + QAction *action = qobject_cast< QAction * >(sender()); + + for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end(); ++it ) + { + if ( it->action != action ) + continue; + + QWidget *widget = it->widget; + m_tabWidget->setCurrentWidget(widget); + break; + } +} + +ViewWindowMgr::TabData * ViewWindowMgr::findTab(QWidget * widget) +{ + for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end(); ++it ) + if ( it->widget == widget ) + return (it.operator->()); + + return 0; +} + +void ViewWindowMgr::setCurrentPage(int index) +{ + m_tabWidget->setCurrentIndex( index ); +} + +int ViewWindowMgr::currentPageIndex() const +{ + return m_tabWidget->currentIndex(); +} + + +void ViewWindowMgr::indicateFindResultStatus( SearchResultStatus status ) +{ + QPalette p = editFind->palette(); + + if ( status == SearchResultNotFound ) + p.setColor( QPalette::Active, QPalette::Base, QColor(255, 102, 102) ); + else + p.setColor( QPalette::Active, QPalette::Base, Qt::white ); + + editFind->setPalette( p ); + labelWrapped->setVisible( status == SearchResultFoundWrapped ); +} + + +void ViewWindowMgr::onActivateFind() +{ + frameFind->show(); + labelWrapped->setVisible( false ); + editFind->setFocus( Qt::ShortcutFocusReason ); + editFind->selectAll(); +} + + +void ViewWindowMgr::find() +{ + int flags = 0; + + if ( checkCase->isChecked() ) + flags |= ViewWindow::SEARCH_CASESENSITIVE; + + if ( checkWholeWords->isChecked() ) + flags |= ViewWindow::SEARCH_WHOLEWORDS; + + current()->find( editFind->text(), flags ); + + if ( !frameFind->isVisible() ) + frameFind->show(); +} + + +void ViewWindowMgr::editTextEdited(const QString &) +{ + find(); +} + +void ViewWindowMgr::onFindNext() +{ + current()->onFindNext(); +} + +void ViewWindowMgr::onFindPrevious() +{ + current()->onFindPrevious(); +} diff -Nru kchmviewer-4.1/src/viewwindowmgr.h kchmviewer-5.1/src/viewwindowmgr.h --- kchmviewer-4.1/src/viewwindowmgr.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindowmgr.h 2009-12-14 09:08:27.000000000 +0000 @@ -0,0 +1,129 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef VIEWWINDOWMGR_H +#define VIEWWINDOWMGR_H + +#include "kde-qt.h" +#include "settings.h" +#include "ui_window_browser.h" + +// A small overriden class to handle a middle click +// We cannot embed it into .cpp because of O_OBJECT :( +class ViewWindowTabs : public QTabWidget +{ + Q_OBJECT + + public: + ViewWindowTabs( QWidget * parent ); + + virtual ~ViewWindowTabs(); + + signals: + void mouseMiddleClickTab( int tab ); + + protected: + void mouseReleaseEvent ( QMouseEvent * event ); +}; + + +class ViewWindowTabs; + +class ViewWindowMgr : public QWidget, public Ui::TabbedBrowser +{ + Q_OBJECT + public: + enum SearchResultStatus + { + SearchResultFound, + SearchResultNotFound, + SearchResultFoundWrapped + }; + + ViewWindowMgr( QWidget *parent ); + ~ViewWindowMgr( ); + + // Returns a handle to a currently viewed window. + // Guaranteeed to return a valid handle, or aborts. + ViewWindow * current(); + + // Adds a new tab, creating a new browser window + ViewWindow * addNewTab( bool set_active ); + + // Sets the tab name and updates Windows menu + void setTabName( ViewWindow* window ); + + void invalidate(); + + // Creates a Window menu + void createMenu( MainWindow * parent, QMenu * menuWindow, QAction * actionCloseWindow ); + + // Saves and restores current settings between sessions + void restoreSettings( const Settings::viewindow_saved_settings_t& settings ); + void saveSettings( Settings::viewindow_saved_settings_t& settings ); + + void setCurrentPage( int index ); + int currentPageIndex() const; + + public slots: + void onCloseCurrentWindow(); + void onCloseWindow( int num ); + void onActivateFind(); + void onFindNext(); + void onFindPrevious(); + void indicateFindResultStatus( SearchResultStatus status ); + + protected slots: + void openNewTab(); + void onTabChanged( QWidget * newtab ); + void updateCloseButtons(); + void activateWindow(); + + void editTextEdited( const QString & text ); + + private: + void find(); + + typedef struct + { + QWidget * widget; + ViewWindow * window; + QAction * action; + } TabData; + + void closeAllWindows(); + void closeWindow( QWidget * widget ); + TabData * findTab( QWidget * widget ); + + // Storage of all available windows + QList< TabData > m_Windows; + typedef QList< TabData >::iterator WindowsIterator; + + QToolButton * m_closeButton; + QMenu * m_menuWindow; + QAction * m_actionCloseWindow; + + // Window menu actions. Contains one action per window. They are not + // linked permanently - if a middle window is deleted, all the following + // actions will be relinked and replaced. + QList< QAction* > m_actions; + + ViewWindowTabs * m_tabWidget; +}; + +#endif /* INCLUDE_KCHMVIEWWINDOWMGR_H */ diff -Nru kchmviewer-4.1/src/viewwindow_qtextbrowser.cpp kchmviewer-5.1/src/viewwindow_qtextbrowser.cpp --- kchmviewer-4.1/src/viewwindow_qtextbrowser.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow_qtextbrowser.cpp 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,342 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#include +#include + +#include "libchmurlfactory.h" + +#include "kde-qt.h" +#include "mainwindow.h" +#include "viewwindowmgr.h" +#include "viewwindow_qtextbrowser.h" + + +ViewWindow_QTextBrowser::ViewWindow_QTextBrowser( ViewWindowTabs * parent ) + : QTextBrowser ( parent ), ViewWindow ( parent ) +{ + m_zoomfactor = 0; + invalidate(); + +#if QT_VERSION >= 0x040300 + setOpenLinks( false ); +#endif + connect( this, SIGNAL( anchorClicked ( const QUrl& ) ), this, SLOT( onAnchorClicked ( const QUrl& ) ) ); +} + + +ViewWindow_QTextBrowser::~ViewWindow_QTextBrowser() +{ +} + +bool ViewWindow_QTextBrowser::openPage (const QString& url) +{ + setSource (url); + return true; +} + +void ViewWindow_QTextBrowser::setSource ( const QUrl & name ) +{ + if ( m_allowSourceChange ) + { + // Do URI decoding, qtextbrowser does stupid job. + QString fixedname = decodeUrl( name.toString() ); + QTextBrowser::setSource (fixedname); + } + else + m_allowSourceChange = true; +} + +void ViewWindow_QTextBrowser::setZoomFactor( int zoom ) +{ + m_zoomfactor = zoom; + + if ( zoom < 0 ) + QTextBrowser::zoomOut( -zoom ); + else if ( zoom > 0 ) + QTextBrowser::zoomIn( zoom); +} + +void ViewWindow_QTextBrowser::invalidate( ) +{ + m_zoomfactor = 0; + m_allowSourceChange = true; + reload(); + + ViewWindow::invalidate( ); +} + +int ViewWindow_QTextBrowser::getScrollbarPosition( ) +{ + return verticalScrollBar()->sliderPosition(); +} + +void ViewWindow_QTextBrowser::setScrollbarPosition( int pos ) +{ + verticalScrollBar()->setSliderPosition( pos); +} + +void ViewWindow_QTextBrowser::addZoomFactor( int value ) +{ + setZoomFactor( value); +} + +void ViewWindow_QTextBrowser::onAnchorClicked(const QUrl & url) +{ +#if QT_VERSION < 0x040300 + emit linkClicked( url.toString(), m_allowSourceChange ); +#else + bool q; + emit linkClicked( url.toString(), q ); +#endif +} + + +bool ViewWindow_QTextBrowser::printCurrentPage( ) +{ + QPrinter printer( QPrinter::HighResolution ); + //printer.setFullPage(true); + + QPrintDialog dlg( &printer, this ); + + if ( dlg.exec() != QDialog::Accepted ) + { + ::mainWindow->showInStatusBar( i18n( "Printing aborted") ); + return false; + } + + document()->print( &printer ); + ::mainWindow->showInStatusBar( i18n( "Printing finished") ); + return true; +} + +void ViewWindow_QTextBrowser::clipSelectAll( ) +{ + selectAll(); +} + +void ViewWindow_QTextBrowser::clipCopy( ) +{ + copy (); +} + + +// Shamelessly stolen from Qt +QString ViewWindow_QTextBrowser::decodeUrl( const QString &input ) +{ + QString temp; + + int i = 0; + int len = input.length(); + int a, b; + QChar c; + while (i < len) + { + c = input[i]; + if (c == '%' && i + 2 < len) + { + a = input[++i].unicode(); + b = input[++i].unicode(); + + if (a >= '0' && a <= '9') + a -= '0'; + else if (a >= 'a' && a <= 'f') + a = a - 'a' + 10; + else if (a >= 'A' && a <= 'F') + a = a - 'A' + 10; + + if (b >= '0' && b <= '9') + b -= '0'; + else if (b >= 'a' && b <= 'f') + b = b - 'a' + 10; + else if (b >= 'A' && b <= 'F') + b = b - 'A' + 10; + + temp.append( (QChar)((a << 4) | b ) ); + } + else + { + temp.append( c ); + } + + ++i; + } + + return temp; +} + +QMenu * ViewWindow_QTextBrowser::createPopupMenu( const QPoint & pos ) +{ + QMenu * menu = getContextMenu( anchorAt( pos ), this ); + menu->exec( viewport()->mapToGlobal( pos ) ); + + return 0; +} + +QVariant ViewWindow_QTextBrowser::loadResource(int type, const QUrl & name) +{ + QString data, file, path = name.toString( QUrl::StripTrailingSlash ); + + // Retreive the data from chm file + LCHMFile * chm = ::mainWindow->chmFile(); + + if ( !chm ) + return 0; + + int pos = path.indexOf('#'); + if ( pos != -1 ) + path = path.left (pos); + + path = makeURLabsolute( path, false ); + + // To handle a single-image pages, we need to generate the HTML page to show + // this image. We did it in KCHMViewWindow::handleStartPageAsImage; now we need + // to generate the HTML page, and set it. + if ( LCHMUrlFactory::handleFileType( path, data ) ) + return QVariant( QString( data ) ); + + if ( type == QTextDocument::HtmlResource || type == QTextDocument::StyleSheetResource ) + { + if ( !chm->getFileContentAsString( &data, path ) ) + qWarning( "Needed file %s is not present in this CHM archive\n", qPrintable( path ) ); + + // A "fix" (actually hack) for CHM files people sent to me. I have no idea why QTextBrowser cannot show it. + if ( type == QTextDocument::HtmlResource ) + data.remove( "" ); + + return QVariant( QString( data ) ); + } + else if ( type == QTextDocument::ImageResource ) + { + QImage img; + QByteArray buf; + + QString fpath = decodeUrl( path ); + + if ( chm->getFileContentAsBinary( &buf, fpath ) ) + { + if ( !img.loadFromData ( (const uchar *) buf.data(), buf.size() ) ) + qWarning( "Needed file %s is not present in this CHM archive\n", qPrintable( path ) ); + } + + return QVariant( img ); + } + + qWarning("loadResource: Unknown type %d", type); + return QVariant(); +} + +void ViewWindow_QTextBrowser::find(const QString & text, int flags) +{ + m_searchText = text; + m_flags = flags; + + find( false, false ); +} + +void ViewWindow_QTextBrowser::onFindNext() +{ + find( true, false ); +} + +void ViewWindow_QTextBrowser::onFindPrevious() +{ + find( false, true ); +} + +void ViewWindow_QTextBrowser::find( bool forward, bool backward ) +{ + QTextDocument *doc = document(); + QTextCursor c = textCursor(); + QTextDocument::FindFlags options; + + ::mainWindow->viewWindowMgr()->indicateFindResultStatus( ViewWindowMgr::SearchResultFound ); + + if ( c.hasSelection() ) + c.setPosition( forward ? c.position() : c.anchor(), QTextCursor::MoveAnchor ); + + QTextCursor newCursor = c; + + if ( !m_searchText.isEmpty() ) + { + if ( backward ) + options |= QTextDocument::FindBackward; + + if ( m_flags & SEARCH_CASESENSITIVE ) + options |= QTextDocument::FindCaseSensitively; + + if ( m_flags & SEARCH_WHOLEWORDS ) + options |= QTextDocument::FindWholeWords; + + newCursor = doc->find( m_searchText, c, options ); + + if ( newCursor.isNull() ) + { + QTextCursor ac( doc ); + ac.movePosition( options & QTextDocument::FindBackward + ? QTextCursor::End : QTextCursor::Start ); + newCursor = doc->find( m_searchText, ac, options ); + if ( newCursor.isNull() ) + { + ::mainWindow->viewWindowMgr()->indicateFindResultStatus( ViewWindowMgr::SearchResultNotFound ); + newCursor = c; + } + else + ::mainWindow->viewWindowMgr()->indicateFindResultStatus( ViewWindowMgr::SearchResultFoundWrapped ); + } + } + + setTextCursor( newCursor ); +} + +void ViewWindow_QTextBrowser::contextMenuEvent(QContextMenuEvent * e) +{ + // From Qt Assistant + QMenu *m = new QMenu(0); + QString link = anchorAt( e->pos() ); + + if ( !link.isEmpty() ) + { + m->addAction( i18n("Open Link in a new tab\tShift+LMB"), ::mainWindow, SLOT( onOpenPageInNewTab() ) ); + m->addAction( i18n("Open Link in a new background tab\tCtrl+LMB"), ::mainWindow, SLOT( onOpenPageInNewBackgroundTab() ) ); + m->addSeparator(); + setTabKeeper( link ); + } + + ::mainWindow->setupPopupMenu( m ); + m->exec( e->globalPos() ); + delete m; + +} + +void ViewWindow_QTextBrowser::mouseReleaseEvent ( QMouseEvent * event ) +{ + if ( event->button() == Qt::MidButton ) + { + QString link = anchorAt( event->pos() ); + + if ( !link.isEmpty() ) + { + setTabKeeper( link ); + ::mainWindow->onOpenPageInNewBackgroundTab(); + return; + } + } + + QTextBrowser::mouseReleaseEvent( event ); +} diff -Nru kchmviewer-4.1/src/viewwindow_qtextbrowser.h kchmviewer-5.1/src/viewwindow_qtextbrowser.h --- kchmviewer-4.1/src/viewwindow_qtextbrowser.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow_qtextbrowser.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,114 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef VIEWWINDOW_QTEXTBROWSER_H +#define VIEWWINDOW_QTEXTBROWSER_H + +#include "kde-qt.h" + +#include "viewwindow.h" + + +class ViewWindow_QTextBrowser : public QTextBrowser, public ViewWindow +{ + Q_OBJECT + public: + ViewWindow_QTextBrowser( ViewWindowTabs * parent ); + ~ViewWindow_QTextBrowser(); + + //! Open a page from current chm archive + virtual bool openPage (const QString& url); + + //! Invalidate current view, doing all the cleanups etc. + virtual void invalidate(); + + //! Return current ZoomFactor. + virtual int getZoomFactor() const { return m_zoomfactor; } + + //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. + virtual void setZoomFactor (int zoom); + + //! Relatively changes ZoomFactor. Most common values are -1 and 1. + virtual void addZoomFactor (int value); + + //! Popups the print dialog, and prints the current page on the printer. + virtual bool printCurrentPage(); + + //! Select the content of the whole page + virtual void clipSelectAll(); + + //! Copies the selected content to the clipboard + virtual void clipCopy(); + + //! Implements "find in page" functionality + virtual void find( const QString& text, int flags ); + virtual void onFindNext(); + virtual void onFindPrevious(); + + /*! + * Return current scrollbar position in view window. Saved on program exit. + * There is no restriction on returned value, except that giving this value to + * setScrollbarPosition() should move the scrollbar in the same position. + */ + virtual int getScrollbarPosition(); + + //! Sets the scrollbar position. + virtual void setScrollbarPosition(int pos); + + virtual QObject * getQObject() { return this; } + virtual QWidget * getQWidget() { return this; } + + static QString decodeUrl( const QString &url ); + + signals: + /*! + * Emitted when the user clicked on the link, before the page changed. + * If linkClicked() sets follow_link to false, the current page should NOT change. + * Otherwise it should be changed to the new link value. + */ + void linkClicked ( const QString & newlink, bool& follow_link ); + + private slots: + virtual void onAnchorClicked ( const QUrl& url); + + private: + // Overloaded to provide custom context menu + void contextMenuEvent( QContextMenuEvent *e ); + + void mouseReleaseEvent ( QMouseEvent * event ); + + void find( bool forward, bool backward ); + + QMenu * createPopupMenu ( const QPoint & pos ); + + // Overriden to change the source + void setSource ( const QUrl & name ); + + // Overriden to load resources + QVariant loadResource ( int type, const QUrl & name ); + + int m_zoomfactor; + bool m_allowSourceChange; + + // Search data + QString m_searchText; + int m_flags; +}; + + +#endif /* KCHMVIEWWINDOW_QTEXTBROWSER_H */ diff -Nru kchmviewer-4.1/src/viewwindow_qtwebkit.cpp kchmviewer-5.1/src/viewwindow_qtwebkit.cpp --- kchmviewer-4.1/src/viewwindow_qtwebkit.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow_qtwebkit.cpp 2009-12-15 04:36:32.000000000 +0000 @@ -0,0 +1,413 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +// Only compile this file if Qt WEBKIT is present +#if defined (QT_WEBKIT_LIB) + +#include +#include + +#include +#include +#include +#include + +#include "libchmurlfactory.h" + +#include "kde-qt.h" +#include "config.h" +#include "mainwindow.h" +#include "viewwindowmgr.h" +#include "viewwindow_qtwebkit.h" + + +// +// A network reply to emulate data transfer from CHM file +// +class KCHMNetworkReply : public QNetworkReply +{ + public: + KCHMNetworkReply( const QNetworkRequest &request, const QUrl &url ) + { + setRequest( request ); + setOpenMode( QIODevice::ReadOnly ); + + m_data = loadResource( url ); + m_length = m_data.length(); + + setHeader( QNetworkRequest::ContentLengthHeader, QByteArray::number(m_data.length()) ); + QTimer::singleShot( 0, this, SIGNAL(metaDataChanged()) ); + QTimer::singleShot( 0, this, SIGNAL(readyRead()) ); + } + + virtual qint64 bytesAvailable() const + { + return m_data.length() + QNetworkReply::bytesAvailable(); + } + + virtual void abort() + { + } + + protected: + virtual qint64 readData(char *buffer, qint64 maxlen) + { + qint64 len = qMin(qint64(m_data.length()), maxlen); + if (len) + { + qMemCopy(buffer, m_data.constData(), len); + m_data.remove(0, len); + } + + if (!m_data.length()) + QTimer::singleShot(0, this, SIGNAL(finished())); + return len; + } + + QByteArray loadResource( const QUrl &url ) + { + QString data, file, path = url.path(); //toString( QUrl::StripTrailingSlash ); + + // Retreive the data from chm file + LCHMFile * chm = ::mainWindow->chmFile(); + + if ( !chm ) + return QByteArray(); + + int pos = path.indexOf('#'); + if ( pos != -1 ) + path = path.left (pos); + + // To handle a single-image pages, we need to generate the HTML page to show + // this image. We did it in KCHMViewWindow::handleStartPageAsImage; now we need + // to generate the HTML page, and set it. + if ( LCHMUrlFactory::handleFileType( path, data ) ) + return qPrintable( data ); + + QByteArray buf; + + if ( path.endsWith( ".html", Qt::CaseInsensitive ) + || path.endsWith( ".htm", Qt::CaseInsensitive ) ) + { + // If encoding autodetection is enabled, decode it. Otherwise pass as binary. + if ( pConfig->m_advAutodetectEncoding ) + { + if ( !chm->getFileContentAsString( &data, path ) ) + qWarning( "Could not resolve file %s\n", qPrintable( path ) ); + + setHeader( QNetworkRequest::ContentTypeHeader, "text/html" ); + buf = qPrintable( data ); + } + else + { + if ( !chm->getFileContentAsBinary( &buf, path ) ) + qWarning( "Could not resolve file %s\n", qPrintable( path ) ); + + setHeader( QNetworkRequest::ContentTypeHeader, "text/html" ); + } + } + else + { + QString fpath = ViewWindow_QtWebKit::decodeUrl( path ); + + if ( !chm->getFileContentAsBinary( &buf, fpath ) ) + qWarning( "Could not resolve file %s\n", qPrintable( path ) ); + + setHeader( QNetworkRequest::ContentTypeHeader, "binary/octet" ); + } + + return buf; + } + + private: + QByteArray m_data; + qint64 m_length; +}; + + +// +// A network manager to emulate data transfer from CHM file +// +class KCHMNetworkAccessManager : public QNetworkAccessManager +{ + public: + KCHMNetworkAccessManager( QObject *parent ) + : QNetworkAccessManager(parent) + { + } + + protected: + virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) + { + const QString scheme = request.url().scheme(); + + if ( scheme == QLatin1String("ms-its") ) + return new KCHMNetworkReply( request, request.url() ); + + return QNetworkAccessManager::createRequest(op, request, outgoingData); + } +}; + + + + +// +// Webkit browser +// +ViewWindow_QtWebKit::ViewWindow_QtWebKit( ViewWindowTabs * parent ) + : QWebView ( parent ), ViewWindow ( parent ) +{ + m_zoomfactor = 1; + invalidate(); + + page()->setNetworkAccessManager(new KCHMNetworkAccessManager(this)); + + page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); + connect( this, SIGNAL( linkClicked ( const QUrl& ) ), this, SLOT( onAnchorClicked ( const QUrl& ) ) ); +} + + +ViewWindow_QtWebKit::~ViewWindow_QtWebKit() +{ +} + + +bool ViewWindow_QtWebKit::openPage (const QString& url) +{ + if ( m_allowSourceChange ) + { + // Do URI decoding, qtextbrowser does stupid job. + QString fixedname = decodeUrl( url ); + + if ( !fixedname.startsWith( "ms-its://" ) ) + fixedname = "ms-its://" + fixedname; + + setUrl( fixedname ); + } + else + m_allowSourceChange = true; + + return true; +} + + +void ViewWindow_QtWebKit::setZoomFactor( int zoom ) +{ + m_zoomfactor = zoom; + setTextSizeMultiplier ( 1.0 + m_zoomfactor * 0.5 ); +} + +void ViewWindow_QtWebKit::invalidate( ) +{ + m_zoomfactor = 1; + m_allowSourceChange = true; + setTextSizeMultiplier( 1.0 ); + reload(); + + ViewWindow::invalidate( ); +} + +int ViewWindow_QtWebKit::getScrollbarPosition( ) +{ + return page()->currentFrame()->scrollBarValue( Qt::Vertical ); +} + +void ViewWindow_QtWebKit::setScrollbarPosition( int pos ) +{ + page()->currentFrame()->setScrollBarValue( Qt::Vertical, pos ); +} + +void ViewWindow_QtWebKit::addZoomFactor( int value ) +{ + setZoomFactor( m_zoomfactor + value ); +} + +void ViewWindow_QtWebKit::onAnchorClicked(const QUrl & url) +{ + emit linkClicked( url.path(), m_allowSourceChange ); +} + + +bool ViewWindow_QtWebKit::printCurrentPage( ) +{ + QPrinter printer( QPrinter::HighResolution ); + + QPrintDialog dlg( &printer, this ); + + if ( dlg.exec() != QDialog::Accepted ) + { + ::mainWindow->showInStatusBar( i18n( "Printing aborted") ); + return false; + } + + print( &printer ); + ::mainWindow->showInStatusBar( i18n( "Printing finished") ); + return true; +} + + +void ViewWindow_QtWebKit::clipSelectAll( ) +{ + QMessageBox::information( 0, "Not implemented", "Not implemented" ); +// selectAll(); +} + + +void ViewWindow_QtWebKit::clipCopy( ) +{ + triggerPageAction( QWebPage::Copy ); +} + + +// Shamelessly stolen from Qt +QString ViewWindow_QtWebKit::decodeUrl( const QString &input ) +{ + QString temp; + + int i = 0; + int len = input.length(); + int a, b; + QChar c; + while (i < len) + { + c = input[i]; + if (c == '%' && i + 2 < len) + { + a = input[++i].unicode(); + b = input[++i].unicode(); + + if (a >= '0' && a <= '9') + a -= '0'; + else if (a >= 'a' && a <= 'f') + a = a - 'a' + 10; + else if (a >= 'A' && a <= 'F') + a = a - 'A' + 10; + + if (b >= '0' && b <= '9') + b -= '0'; + else if (b >= 'a' && b <= 'f') + b = b - 'a' + 10; + else if (b >= 'A' && b <= 'F') + b = b - 'A' + 10; + + temp.append( (QChar)((a << 4) | b ) ); + } + else + { + temp.append( c ); + } + + ++i; + } + + return temp; +} + + +QMenu * ViewWindow_QtWebKit::createPopupMenu( const QPoint & pos ) +{ + QMenu * menu = getContextMenu( anchorAt( pos ), this ); + menu->exec( pos ); + + return 0; +} + + +void ViewWindow_QtWebKit::find(const QString & text, int flags) +{ + m_searchText = text; + m_flags = flags; + + find( false, false ); +} + +void ViewWindow_QtWebKit::onFindNext() +{ + find( true, false ); +} + +void ViewWindow_QtWebKit::onFindPrevious() +{ + find( false, true ); +} + +void ViewWindow_QtWebKit::find( bool , bool backward ) +{ + QWebPage::FindFlags flags = QWebPage::FindWrapsAroundDocument; + + if ( backward ) + flags |= QWebPage::FindBackward; + + if ( m_flags & SEARCH_CASESENSITIVE ) + flags |= QWebPage::FindCaseSensitively; + + if ( findText( m_searchText, flags ) ) + ::mainWindow->viewWindowMgr()->indicateFindResultStatus( ViewWindowMgr::SearchResultFound ); + else + ::mainWindow->viewWindowMgr()->indicateFindResultStatus( ViewWindowMgr::SearchResultNotFound ); +} + +void ViewWindow_QtWebKit::contextMenuEvent(QContextMenuEvent * e) +{ + // From Qt Assistant + QMenu *m = new QMenu(0); + QString link = anchorAt( e->pos() ); + + if ( !link.isEmpty() ) + { + m->addAction( i18n("Open Link in a new tab\tShift+LMB"), ::mainWindow, SLOT( onOpenPageInNewTab() ) ); + m->addAction( i18n("Open Link in a new background tab\tCtrl+LMB"), ::mainWindow, SLOT( onOpenPageInNewBackgroundTab() ) ); + m->addSeparator(); + setTabKeeper( link ); + } + + ::mainWindow->setupPopupMenu( m ); + m->exec( e->globalPos() ); + delete m; +} + +QString ViewWindow_QtWebKit::anchorAt(const QPoint & pos) +{ + QWebHitTestResult res = page()->currentFrame()->hitTestContent( pos ); + + if ( !res.linkUrl().isValid() ) + return QString::null; + + return res.linkUrl().path(); +} + + +void ViewWindow_QtWebKit::mouseReleaseEvent ( QMouseEvent * event ) +{ + if ( event->button() == Qt::MidButton ) + { + QString link = anchorAt( event->pos() ); + + if ( !link.isEmpty() ) + { + setTabKeeper( link ); + ::mainWindow->onOpenPageInNewBackgroundTab(); + return; + } + } + + QWebView::mouseReleaseEvent( event ); +} + +#endif // #if defined (QT_WEBKIT_LIB) + diff -Nru kchmviewer-4.1/src/viewwindow_qtwebkit.h kchmviewer-5.1/src/viewwindow_qtwebkit.h --- kchmviewer-4.1/src/viewwindow_qtwebkit.h 1970-01-01 01:00:00.000000000 +0100 +++ kchmviewer-5.1/src/viewwindow_qtwebkit.h 2009-12-14 03:59:44.000000000 +0000 @@ -0,0 +1,114 @@ +/************************************************************************** + * Kchmviewer - a CHM file viewer with broad language support * + * Copyright (C) 2004-2010 George Yunaev, kchmviewer@ulduzsoft.com * + * * + * 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 3 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, see . * + **************************************************************************/ + +#ifndef VIEWWINDOW_QTWEBKIT_H +#define VIEWWINDOW_QTWEBKIT_H + +#include + +#include "kde-qt.h" +#include "viewwindow.h" + + +class ViewWindow_QtWebKit : public QWebView, public ViewWindow +{ + Q_OBJECT + public: + ViewWindow_QtWebKit( ViewWindowTabs * parent ); + ~ViewWindow_QtWebKit(); + + //! Open a page from current chm archive + virtual bool openPage (const QString& url); + + //! Invalidate current view, doing all the cleanups etc. + virtual void invalidate(); + + //! Return current ZoomFactor. + virtual int getZoomFactor() const { return m_zoomfactor; } + + //! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result. + virtual void setZoomFactor (int zoom); + + //! Relatively changes ZoomFactor. Most common values are -1 and 1. + virtual void addZoomFactor (int value); + + //! Popups the print dialog, and prints the current page on the printer. + virtual bool printCurrentPage(); + + //! Select the content of the whole page + virtual void clipSelectAll(); + + //! Copies the selected content to the clipboard + virtual void clipCopy(); + + //! Implements "find in page" functionality + virtual void find( const QString& text, int flags ); + virtual void onFindNext(); + virtual void onFindPrevious(); + + /*! + * Return current scrollbar position in view window. Saved on program exit. + * There is no restriction on returned value, except that giving this value to + * setScrollbarPosition() should move the scrollbar in the same position. + */ + virtual int getScrollbarPosition(); + + //! Sets the scrollbar position. + virtual void setScrollbarPosition(int pos); + + virtual QObject * getQObject() { return this; } + virtual QWidget * getQWidget() { return this; } + + static QString decodeUrl( const QString &url ); + + signals: + /*! + * Emitted when the user clicked on the link, before the page changed. + * If linkClicked() sets follow_link to false, the current page should NOT change. + * Otherwise it should be changed to the new link value. + */ + void linkClicked ( const QString & newlink, bool& follow_link ); + + private slots: + virtual void onAnchorClicked ( const QUrl& url); + + private: + // Overloaded to provide custom context menu + void contextMenuEvent( QContextMenuEvent *e ); + + void mouseReleaseEvent ( QMouseEvent * event ); + + void find( bool forward, bool backward ); + + QMenu * createPopupMenu ( const QPoint & pos ); + + // Overriden to change the source + void setSource ( const QUrl & name ); + + QString anchorAt( const QPoint & pos ); + + int m_zoomfactor; + bool m_allowSourceChange; + + // Search data + QString m_searchText; + int m_flags; +}; + + +#endif /* KCHMVIEWWINDOW_QTWEBKIT_H */ diff -Nru kchmviewer-4.1/src/window_browser.ui kchmviewer-5.1/src/window_browser.ui --- kchmviewer-4.1/src/window_browser.ui 2007-08-29 09:05:10.000000000 +0100 +++ kchmviewer-5.1/src/window_browser.ui 2009-10-25 01:26:00.000000000 +0100 @@ -1,4 +1,5 @@ - + + ********************************************************************* ** ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved. @@ -22,8 +23,8 @@ ** ********************************************************************* TabbedBrowser - - + + 0 0 @@ -31,72 +32,51 @@ 664 - + TabbedBrowser - - - 0 - - - 0 - + - - - - Untitled - - - - 8 - - - 6 - - - - + - - + + QFrame::StyledPanel - + QFrame::Raised - - - 0 - - + + 6 + + 0 + - - + + - - :/images/find_close.png + + + :/images/find_close.png:/images/find_close.png - + true - - - - 0 - 0 + + + 0 0 - + 150 0 @@ -105,94 +85,96 @@ - - + + Previous - - :/images/find_previous.png + + + :/images/find_previous.png:/images/find_previous.png - + Qt::ToolButtonTextBesideIcon - + true - - + + 0 0 - + Next - - :/images/find_next.png + + + :/images/find_next.png:/images/find_next.png - + Qt::ToolButtonTextBesideIcon - + true - + Qt::NoArrow - - + + Case Sensitive - - + + Whole words - - + + 0 20 - + 1050 20 - - <img src=":/images/find_wrap.png">&nbsp;Search wrapped + + <img src=":/images/find_wrap.png">&nbsp;Search wrapped - + Qt::RichText - + true - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + Qt::Horizontal - + 81 21 @@ -206,7 +188,7 @@ - + diff -Nru kchmviewer-4.1/src/window_main.ui kchmviewer-5.1/src/window_main.ui --- kchmviewer-4.1/src/window_main.ui 2009-07-20 00:51:20.000000000 +0100 +++ kchmviewer-5.1/src/window_main.ui 1970-01-01 01:00:00.000000000 +0100 @@ -1,505 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 873 - 591 - - - - kchmviewer - - - - - - 0 - 0 - 873 - 24 - - - - - &Settings - - - - - - &Bookmarks - - - - - - - &File - - - - - - - - - &Edit - - - - - - - - - &View - - - - - - - - - - - - - - &Windows - - - - - - - - - - - - - - general toolbar - - - Qt::Horizontal - - - TopToolBarArea - - - false - - - - - - - navigation toolbar - - - Qt::Horizontal - - - TopToolBarArea - - - false - - - - - - - - action toolbar - - - Qt::Horizontal - - - TopToolBarArea - - - false - - - - - - - - - - - - - - :/images/icon_print.png:/images/icon_print.png - - - &Print... - - - Print - - - Print current page - - - Prints currently opened page. - - - Ctrl+P - - - - - &Quit - - - Exit - - - Exits the application - - - Ctrl+Q - - - - - - :/images/icon_copy.png:/images/icon_copy.png - - - C&opy - - - Copy - - - Copies selected content to clipboard - - - Ctrl+C - - - - - - image8image8 - - - &Select All - - - Paste - - - Selects everything in the document - - - Ctrl+V - - - - - - :/images/icon_find.png:/images/icon_find.png - - - &Find... - - - Find - - - Find text in currently opened page - - - Enters the Find in page mode - - - Ctrl+F - - - - - E&xtract CHM content... - - - Extract the CHM content to the directory - - - Exctracts the CHM archive content to the specified directory. All the files are extracted. - - - - - &Application settings... - - - Change the application settings - - - Change the application settings - - - - - - :/images/icon_add_bookmark.png:/images/icon_add_bookmark.png - - - &Add bookmark - - - Adds a bookmark for currently opened page - - - Adds a bookmark for currently opened page. Remembers the opened page, and scroll position. Bookmarks are accessible through Bookmarks menu or tab. - - - Ctrl+B - - - - - - :/images/icon_font_increase.png:/images/icon_font_increase.png - - - &Increase font size - - - Increase the font size - - - Increases the document font size. The new font size will be stored. - - - Ctrl++ - - - - - - :/images/icon_font_decrease.png:/images/icon_font_decrease.png - - - &Decrease font size - - - Decrease the font size - - - Decreases the document font size. The new font size will be stored. - - - Ctrl+- - - - - - - :/images/icon_view_source.png:/images/icon_view_source.png - - - &View HTML source - - - View HTML source of current page - - - Shows the HTML source of currently opened page - - - Ctrl+U - - - - - true - - - Enable &full screen mode - - - Enters or leaves the fullscreen mode - - - F11 - - - false - - - - - true - - - true - - - Enable &side window - - - Shows or hides the size window (with Content, Index, Search and Bookmark tabs) - - - F9 - - - false - - - - - - :/images/icon_locate_in_content.png:/images/icon_locate_in_content.png - - - &Locate in contents window - - - Locate the current page in contents window - - - If the current page is present in the Table of Contents, locate it there. - - - Ctrl+ - - - - - Set &encoding - - - Changes the current document encoding. - - - - - - :/images/icon_open_file.png:/images/icon_open_file.png - - - &Open... - - - Open a CHM file - - - Opens a new CHM file - - - - - - :/images/icon_back.png:/images/icon_back.png - - - Back - - - Navigate back - - - Navigate back in navigation history - - - - - - :/images/icon_forward.png:/images/icon_forward.png - - - Forward - - - Navigate forward - - - Navigate forward in navigation history - - - - - - :/images/icon_home.png:/images/icon_home.png - - - Home - - - Navigate home - - - Navigate to the document Home page, as specified in the document. - - - - - - :/images/icon_prev_page.png:/images/icon_prev_page.png - - - Previous page in Table of Context - - - Previous page in TOC - - - Go to the previous page in the Table of Contents - - - Go to the previous page in the <b>Table of Contents</b><br><br><i>Shortcut: Ctrl+Left Arrow</i> - - - - - - :/images/icon_next_page.png:/images/icon_next_page.png - - - Next page in Table of Context - - - Next page in TOC - - - Go to the next page in the Table of Contents - - - Go to the next page in the <b>Table of Contents</b><br><br><i>Shortcut: Ctrl+Right Arrow</i> - - - - - &Close window - - - Close current window - - - Closes currently opened window - - - Ctrl+W - - - - - - - - - diff -Nru kchmviewer-4.1/tests/autotest.sh kchmviewer-5.1/tests/autotest.sh --- kchmviewer-4.1/tests/autotest.sh 2007-03-08 06:49:46.000000000 +0000 +++ kchmviewer-5.1/tests/autotest.sh 2009-12-14 09:08:27.000000000 +0000 @@ -2,7 +2,7 @@ CHMDIR="/mnt/ebooks /mnt/disk_d/Docs" #KCHMVIEWER="../src/kchmviewer" -KCHMVIEWER="../build/src/kchmviewer" +KCHMVIEWER="../bin/kchmviewer" COMMONLOG="autotest.log" FATALLOG="fatal.log" CMDOPTIONS="--nocrashhandler"