diff options
Diffstat (limited to 'src/kde')
-rw-r--r-- | src/kde/Makefile.am | 8 | ||||
-rw-r--r-- | src/kde/kchmdcopiface.cpp | 86 | ||||
-rw-r--r-- | src/kde/kchmdcopiface.h | 58 | ||||
-rw-r--r-- | src/kde/kchmdcopiface_skel.cpp | 98 | ||||
-rw-r--r-- | src/kde/kchmviewwindow_khtmlpart.cpp | 163 | ||||
-rw-r--r-- | src/kde/kchmviewwindow_khtmlpart.h | 114 |
6 files changed, 527 insertions, 0 deletions
diff --git a/src/kde/Makefile.am b/src/kde/Makefile.am new file mode 100644 index 0000000..e095be6 --- /dev/null +++ b/src/kde/Makefile.am @@ -0,0 +1,8 @@ +lib_LIBRARIES=libkdeextra.a +libkdeextra_a_SOURCES = kchmdcopiface.cpp kchmdcopiface.skel kchmviewwindow_khtmlpart.cpp +noinst_HEADERS = kchmdcopiface.h kchmviewwindow_khtmlpart.h + +INCLUDES = $(QT_INCLUDES) $(CHM_INCLUDES) $(KDE_INCLUDES) $(LIBCHMFILE_INCLUDES) + +METASOURCES = AUTO +KDE_OPTIONS = qtonly diff --git a/src/kde/kchmdcopiface.cpp b/src/kde/kchmdcopiface.cpp new file mode 100644 index 0000000..967380e --- /dev/null +++ b/src/kde/kchmdcopiface.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (C) 2004-2005 by Georgy Yunaev, [email protected] * + * 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. * + ***************************************************************************/ + +#include "kchmdcopiface.h" +#include "kchmdcopiface.moc" + +#include "kchmmainwindow.h" +#include "kchmsearchwindow.h" + + +KCHMDCOPIface::KCHMDCOPIface(QObject *parent, const char *name) + : QObject(parent, name), DCOPObject( "KCHMDCOPIface" ) +{ +} + + +KCHMDCOPIface::~KCHMDCOPIface() +{ +} + + +void KCHMDCOPIface::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 KCHMDCOPIface::openPage( const QString & page2open ) +{ + QStringList args; + + args.push_back( page2open ); + qApp->postEvent( ::mainWindow, new KCHMUserEvent( "openPage", args ) ); +} + + +void KCHMDCOPIface::guiFindInIndex( const QString & word ) +{ + QStringList args; + + args.push_back( word ); + qApp->postEvent( ::mainWindow, new KCHMUserEvent( "findInIndex", args ) ); +} + + +void KCHMDCOPIface::guiSearchQuery( const QString & query ) +{ + QStringList args; + + args.push_back( query ); + qApp->postEvent( ::mainWindow, new KCHMUserEvent( "searchQuery", args ) ); +} + +QStringList KCHMDCOPIface::searchQuery( const QString & query ) +{ + QStringList results; + + if ( ::mainWindow->searchWindow()->searchQuery( query, &results ) ) + return results; + else + return QStringList(); +} + diff --git a/src/kde/kchmdcopiface.h b/src/kde/kchmdcopiface.h new file mode 100644 index 0000000..c062fc8 --- /dev/null +++ b/src/kde/kchmdcopiface.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2004-2005 by Georgy Yunaev, [email protected] * + * 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. * + ***************************************************************************/ + +#ifndef KCHMDCOPIFACE_H +#define KCHMDCOPIFACE_H + +#include <qobject.h> +#include <dcopobject.h> +#include <qstring.h> +#include <qstringlist.h> + +class KCHMDCOPIface : public QObject, public DCOPObject +{ + Q_OBJECT + K_DCOP + + public: + KCHMDCOPIface( QObject *parent = 0, const char *name = 0 ); + ~KCHMDCOPIface(); + + k_dcop: + //! Loads a CHM file \a filename , and opens the URL \a url. Use URL "/" to open default homepage + void loadHelpFile( const QString& filename, const QString& url ); + + //! Opens a specific \a url inside the loaded CHM file + void openPage( const QString& url ); + + //! Tries to find word in index, opening the index window and scrolling it there + void guiFindInIndex( const QString& word ); + + //! Executes a search in GUI. \a query contains the complete search query. + 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 + QStringList searchQuery( const QString& query ); +}; + +#endif diff --git a/src/kde/kchmdcopiface_skel.cpp b/src/kde/kchmdcopiface_skel.cpp new file mode 100644 index 0000000..130a60f --- /dev/null +++ b/src/kde/kchmdcopiface_skel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** DCOP Skeleton generated by dcopidl2cpp from kchmdcopiface.kidl +** +** WARNING! All changes made in this file will be lost! +** +*****************************************************************************/ + +#include "./kchmdcopiface.h" + +#include <kdatastream.h> + + +static const char* const KCHMDCOPIface_ftable[6][3] = { + { "void", "loadHelpFile(QString,QString)", "loadHelpFile(QString filename,QString url)" }, + { "void", "openPage(QString)", "openPage(QString url)" }, + { "void", "guiFindInIndex(QString)", "guiFindInIndex(QString word)" }, + { "void", "guiSearchQuery(QString)", "guiSearchQuery(QString query)" }, + { "QStringList", "searchQuery(QString)", "searchQuery(QString query)" }, + { 0, 0, 0 } +}; +static const int KCHMDCOPIface_ftable_hiddens[5] = { + 0, + 0, + 0, + 0, + 0, +}; + +bool KCHMDCOPIface::process(const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData) +{ + if ( fun == KCHMDCOPIface_ftable[0][1] ) { // void loadHelpFile(QString,QString) + QString arg0; + QString arg1; + QDataStream arg( data, IO_ReadOnly ); + if (arg.atEnd()) return false; + arg >> arg0; + if (arg.atEnd()) return false; + arg >> arg1; + replyType = KCHMDCOPIface_ftable[0][0]; + loadHelpFile(arg0, arg1 ); + } else if ( fun == KCHMDCOPIface_ftable[1][1] ) { // void openPage(QString) + QString arg0; + QDataStream arg( data, IO_ReadOnly ); + if (arg.atEnd()) return false; + arg >> arg0; + replyType = KCHMDCOPIface_ftable[1][0]; + openPage(arg0 ); + } else if ( fun == KCHMDCOPIface_ftable[2][1] ) { // void guiFindInIndex(QString) + QString arg0; + QDataStream arg( data, IO_ReadOnly ); + if (arg.atEnd()) return false; + arg >> arg0; + replyType = KCHMDCOPIface_ftable[2][0]; + guiFindInIndex(arg0 ); + } else if ( fun == KCHMDCOPIface_ftable[3][1] ) { // void guiSearchQuery(QString) + QString arg0; + QDataStream arg( data, IO_ReadOnly ); + if (arg.atEnd()) return false; + arg >> arg0; + replyType = KCHMDCOPIface_ftable[3][0]; + guiSearchQuery(arg0 ); + } else if ( fun == KCHMDCOPIface_ftable[4][1] ) { // QStringList searchQuery(QString) + QString arg0; + QDataStream arg( data, IO_ReadOnly ); + if (arg.atEnd()) return false; + arg >> arg0; + replyType = KCHMDCOPIface_ftable[4][0]; + QDataStream _replyStream( replyData, IO_WriteOnly ); + _replyStream << searchQuery(arg0 ); + } else { + return DCOPObject::process( fun, data, replyType, replyData ); + } + return true; +} + +QCStringList KCHMDCOPIface::interfaces() +{ + QCStringList ifaces = DCOPObject::interfaces(); + ifaces += "KCHMDCOPIface"; + return ifaces; +} + +QCStringList KCHMDCOPIface::functions() +{ + QCStringList funcs = DCOPObject::functions(); + for ( int i = 0; KCHMDCOPIface_ftable[i][2]; i++ ) { + if (KCHMDCOPIface_ftable_hiddens[i]) + continue; + QCString func = KCHMDCOPIface_ftable[i][0]; + func += ' '; + func += KCHMDCOPIface_ftable[i][2]; + funcs << func; + } + return funcs; +} + + diff --git a/src/kde/kchmviewwindow_khtmlpart.cpp b/src/kde/kchmviewwindow_khtmlpart.cpp new file mode 100644 index 0000000..e68e53d --- /dev/null +++ b/src/kde/kchmviewwindow_khtmlpart.cpp @@ -0,0 +1,163 @@ +/*************************************************************************** + * Copyright (C) 2004-2007 by Georgy Yunaev, [email protected] * + * 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. * + ***************************************************************************/ + +#include <qclipboard.h> + +#include <khtmlview.h> +#include <kfinddialog.h> + +#include "kde-qt.h" +#include "kchmmainwindow.h" +#include "kchmconfig.h" +#include "kchmviewwindow_khtmlpart.h" + +#include "kchmviewwindow_khtmlpart.moc" + + +QWidget * KCHMViewWindow_KHTMLPart::getQWidget() +{ + return view(); +} + +KCHMViewWindow_KHTMLPart::KCHMViewWindow_KHTMLPart( QTabWidget * parent ) + : KHTMLPart ( parent ), KCHMViewWindow ( parent ) +{ + m_zoomfactor = 0; + m_currentEncoding = 0; + m_searchForward = true; + + invalidate(); + + connect( browserExtension(), SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs & ) ), + this, SLOT ( onOpenURLRequest( const KURL &, const KParts::URLArgs & )) ); + + 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() ) + { + m_currentEncoding = ::mainWindow->chmFile()->currentEncoding(); + setEncoding ( m_currentEncoding->qtcodec, TRUE ); + } + + QString fullurl = "ms-its:" + ::mainWindow->getOpenedFileName() + "::" + url; + 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; + m_searchForward = true; + m_searchText = QString::null; + + 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::searchWord( const QString & word, bool forward, bool ) +{ + if ( word != m_searchText || forward != m_searchForward ) + { + m_searchText = word; + m_searchForward = forward; + + findText ( word, forward ? 0 : KFindDialog::FindBackwards, ::mainWindow, 0 ); + } + + findTextNext (); +} + +void KCHMViewWindow_KHTMLPart::onOpenURLRequest( const KURL & url, const KParts::URLArgs & ) +{ + bool sourcechange = true; + emit signalLinkClicked ( url.prettyURL(), sourcechange ); +} + +void KCHMViewWindow_KHTMLPart::slotLinkClicked( const QString & newlink ) +{ + bool notused; + emit signalLinkClicked (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 ) +{ + KQPopupMenu * menu = getContextMenu( url, view() ); + menu->exec( point ); +} + diff --git a/src/kde/kchmviewwindow_khtmlpart.h b/src/kde/kchmviewwindow_khtmlpart.h new file mode 100644 index 0000000..5799f62 --- /dev/null +++ b/src/kde/kchmviewwindow_khtmlpart.h @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (C) 2004-2007 by Georgy Yunaev, [email protected] * + * 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. * + ***************************************************************************/ + +#ifndef KCHMVIEWWINDOW_KHTMLPART_H +#define KCHMVIEWWINDOW_KHTMLPART_H + +#include "kde-qt.h" + +#include "kchmviewwindow.h" +#include "kchmsourcefactory.h" +#include "libchmtextencoding.h" + + +/** +@author Georgy Yunaev +*/ +/* + * For Qt-only version, we cannot compile KCHMViewWindow_KHTMLPart. However, + * we cannot just exclude it, because it would not generate a MOC file for a KDE + * version. Therefore we declare it, and compile the .moc file, but do not provide + * the class methods. + */ +#if defined (USE_KDE) +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(); + + //! Initiates the find-in-page search, if succeed, cursor moved to the first entry + virtual void searchWord( const QString & word, bool forward = true, bool casesensitive = false ); + + //! Select the content of the whole page + virtual void clipSelectAll(); + + //! Copies the selected content to the clipboard + virtual void clipCopy(); + + /*! + * 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 signalLinkClicked() sets follow_link to false, the current page should NOT change. + * Otherwise it should be changed to the new link value. + */ + void signalLinkClicked ( const QString & newlink, bool& follow_link ); + +private slots: + virtual void slotLinkClicked ( const QString & newlink); + virtual void onOpenURLRequest( const KURL &, const KParts::URLArgs & ); + virtual void onPopupMenu ( const QString & url, const QPoint & point ); + +private: + void setSource ( const QString & name ); + + int m_zoomfactor; + bool m_searchForward; + QString m_searchText; + + const LCHMTextEncoding * m_currentEncoding; +}; + +#endif /* USE_KDE */ + +#endif /* KCHMVIEWWINDOW_KHTMLPART_H */ |