summaryrefslogtreecommitdiffstats
path: root/src/modules/help
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
commita6d58bb6052ac8cb01805a48c4ad2f129126116f (patch)
treedd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/help
downloadkvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz
kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/help')
-rw-r--r--src/modules/help/Makefile.am22
-rw-r--r--src/modules/help/helpwidget.cpp154
-rw-r--r--src/modules/help/helpwidget.h61
-rw-r--r--src/modules/help/helpwindow.cpp329
-rw-r--r--src/modules/help/helpwindow.h75
-rwxr-xr-xsrc/modules/help/index.cpp854
-rwxr-xr-xsrc/modules/help/index.h124
-rw-r--r--src/modules/help/libkvihelp.cpp236
8 files changed, 1855 insertions, 0 deletions
diff --git a/src/modules/help/Makefile.am b/src/modules/help/Makefile.am
new file mode 100644
index 00000000..fe6f03f6
--- /dev/null
+++ b/src/modules/help/Makefile.am
@@ -0,0 +1,22 @@
+###############################################################################
+# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek <stefanek@tin.it>
+###############################################################################
+
+AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \
+$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\"
+
+pluglib_LTLIBRARIES = libkvihelp.la
+
+libkvihelp_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS)
+
+libkvihelp_la_SOURCES = libkvihelp.cpp helpwidget.cpp helpwindow.cpp index.cpp index.moc
+libkvihelp_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la
+
+noinst_HEADERS= helpwidget.h helpwindow.h index.h
+
+%.moc: %.h
+ $(SS_QT_MOC) $< -o $@
+
+helpwidget.cpp: helpwidget.moc
+helpwindow.cpp: helpwindow.moc
+index.cpp: index.moc
diff --git a/src/modules/help/helpwidget.cpp b/src/modules/help/helpwidget.cpp
new file mode 100644
index 00000000..4036a0dd
--- /dev/null
+++ b/src/modules/help/helpwidget.cpp
@@ -0,0 +1,154 @@
+//
+// File : helpwidget.cpp
+// Creation date : Thu Aug 10 2000 17:42:12 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "helpwidget.h"
+
+#include "kvi_frame.h"
+#include "kvi_iconmanager.h"
+#include "kvi_locale.h"
+#include "kvi_app.h"
+#include "kvi_msgbox.h"
+#include "kvi_module.h"
+#include "kvi_styled_controls.h"
+#include "helpwindow.h"
+#include "kvi_fileutils.h"
+
+#include <qtoolbutton.h>
+#include <qlineedit.h>
+#include <qtooltip.h>
+#include <qtimer.h>
+#include <qclipboard.h>
+
+extern Index * g_pDocIndex;
+extern KviPointerList<KviHelpWindow> * g_pHelpWindowList;
+extern KviPointerList<KviHelpWidget> * g_pHelpWidgetList;
+
+KviHelpWidget::KviHelpWidget(QWidget * par,KviFrame * lpFrm,bool bIsStandalone)
+: QWidget(par,"help_widget")
+{
+
+ if(bIsStandalone)g_pHelpWidgetList->append(this);
+ m_bIsStandalone = bIsStandalone;
+
+//#warning "Re enable this when using Qt 3.0 : QProcess "
+ m_pTextBrowser = new QTextBrowser(this,"text_browser");
+ m_pTextBrowser->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken);
+#ifndef COMPILE_USE_QT4
+ m_pTextBrowser->setFocusPolicy(QWidget::NoFocus);
+#endif
+ m_pToolBar = new KviTalHBox(this);
+
+ m_pBtnIndex = new KviStyledToolButton(m_pToolBar);
+ m_pBtnIndex->setIconSet(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPINDEX));
+ connect(m_pBtnIndex,SIGNAL(clicked()),this,SLOT(showIndex()));
+ //m_pBtnIndex->setUsesBigPixmap(true);
+
+ m_pBtnBackward = new KviStyledToolButton(m_pToolBar);
+ m_pBtnBackward->setIconSet(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPBACK));
+ connect(m_pBtnBackward,SIGNAL(clicked()),m_pTextBrowser,SLOT(backward()));
+ m_pBtnBackward->setEnabled(false);
+ //m_pBtnBackward->setUsesBigPixmap(true);
+
+ m_pBtnForward = new KviStyledToolButton(m_pToolBar);
+ m_pBtnForward->setIconSet(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPFORWARD));
+ connect(m_pBtnForward,SIGNAL(clicked()),m_pTextBrowser,SLOT(forward()));
+ m_pBtnForward->setEnabled(false);
+ //m_pBtnForward->setUsesBigPixmap(true);
+
+ QWidget* pSpacer=new QWidget(m_pToolBar);
+
+ if(bIsStandalone)
+ {
+ QToolButton * b = new KviStyledToolButton(m_pToolBar);
+ b->setIconSet(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPCLOSE));
+ connect(b,SIGNAL(clicked()),this,SLOT(doClose()));
+ //b->setUsesBigPixmap(true);
+ }
+
+ m_pToolBar->setStretchFactor(pSpacer,1);
+ connect(m_pTextBrowser,SIGNAL(backwardAvailable(bool)),m_pBtnBackward,SLOT(setEnabled(bool)));
+ connect(m_pTextBrowser,SIGNAL(forwardAvailable(bool)),m_pBtnForward,SLOT(setEnabled(bool)));
+
+ m_pTextBrowser->viewport()->installEventFilter(this);
+
+}
+
+KviHelpWidget::~KviHelpWidget()
+{
+ if(m_bIsStandalone)g_pHelpWidgetList->removeRef(this);
+}
+
+void KviHelpWidget::showIndex()
+{
+#ifdef COMPILE_USE_QT4
+ m_pTextBrowser->setSource(QUrl("index.html"));
+#else
+ m_pTextBrowser->setSource("index.html");
+#endif
+}
+
+void KviHelpWidget::resizeEvent(QResizeEvent *e)
+{
+ int hght = m_pToolBar->sizeHint().height();
+ if(hght < 40)hght = 40;
+ m_pToolBar->setGeometry(0,0,width(),hght);
+ m_pTextBrowser->setGeometry(0,hght,width(),height() - hght);
+}
+
+void KviHelpWidget::doClose()
+{
+ // hack needed to workaround "QToolBar::emulateButtonClicked()"
+ // that refers to the "this" pointer after this slot has been
+ // called (from the "too-small-toolbar-for-all-items-popup")
+ QTimer::singleShot(0,this,SLOT(suicide()));
+}
+
+void KviHelpWidget::suicide()
+{
+ // goodbye cruel wolrd
+ delete this;
+}
+
+QSize KviHelpWidget::sizeHint() const
+{
+ int wdth = m_pTextBrowser->sizeHint().width();
+ if(m_pToolBar->sizeHint().width() > wdth)wdth = m_pToolBar->sizeHint().width();
+ QSize s(wdth,m_pTextBrowser->sizeHint().height() + m_pToolBar->sizeHint().height());
+ return s;
+}
+
+bool KviHelpWidget::eventFilter(QObject * o, QEvent *e)
+{
+ QClipboard *cb = QApplication::clipboard();
+
+ if(e->type() == QEvent::MouseButtonRelease) {
+ if(m_pTextBrowser->hasSelectedText()) {
+ cb->setText(m_pTextBrowser->selectedText());
+ }
+ }
+
+ return QWidget::eventFilter(o,e);
+}
+
+
+
+#include "helpwidget.moc"
diff --git a/src/modules/help/helpwidget.h b/src/modules/help/helpwidget.h
new file mode 100644
index 00000000..e00f8bcf
--- /dev/null
+++ b/src/modules/help/helpwidget.h
@@ -0,0 +1,61 @@
+#ifndef _HELPWIDGET_H_
+#define _HELPWIDGET_H_
+//
+// File : helpwidget.h
+// Creation date : Thu Aug 10 2000 17:26:20 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_tal_hbox.h"
+#include <qtextbrowser.h>
+#include "index.h"
+#include <qprogressbar.h>
+
+class KviFrame;
+class QToolButton;
+class QLineEdit;
+//class KviProcess;
+
+class KviHelpWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ KviHelpWidget(QWidget *par,KviFrame * lpFrm,bool bIsStandalone = false);
+ ~KviHelpWidget();
+private:
+ QToolButton * m_pBtnIndex;
+ QToolButton * m_pBtnBackward;
+ QToolButton * m_pBtnForward;
+ KviTalHBox * m_pToolBar;
+ QTextBrowser * m_pTextBrowser;
+ bool m_bIsStandalone;
+protected:
+ virtual void resizeEvent(QResizeEvent *e);
+ bool eventFilter(QObject *, QEvent *);
+protected slots:
+ void doClose();
+ void showIndex();
+ void suicide();
+public:
+ virtual QSize sizeHint() const;
+ QTextBrowser * textBrowser() { return m_pTextBrowser; }
+};
+
+
+#endif //_HELPWIDGET_H_
diff --git a/src/modules/help/helpwindow.cpp b/src/modules/help/helpwindow.cpp
new file mode 100644
index 00000000..9fc11427
--- /dev/null
+++ b/src/modules/help/helpwindow.cpp
@@ -0,0 +1,329 @@
+//
+// File : helpwindow.cpp
+// Creation date : Tue Aug 11 2000 18:08:22 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// This program is FREE software. You can redistribute it and/or
+// modify it under the m_terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your opinion) 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 "helpwindow.h"
+#include "helpwidget.h"
+#include "kvi_app.h"
+
+#include "kvi_iconmanager.h"
+#include "kvi_options.h"
+#include "kvi_locale.h"
+#include "kvi_module.h"
+#include "kvi_config.h"
+#include "kvi_styled_controls.h"
+
+#include <qfileinfo.h>
+#include <qsplitter.h>
+#include <qlineedit.h>
+#include <qmessagebox.h>
+#include <qregexp.h>
+#include <qtooltip.h>
+#include "kvi_valuelist.h"
+
+#include "kvi_sourcesdate.h"
+
+extern Index * g_pDocIndex;
+extern KviPointerList<KviHelpWindow> * g_pHelpWindowList;
+extern KviPointerList<KviHelpWidget> * g_pHelpWidgetList;
+
+bool g_bIndexingDone = FALSE;
+KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name)
+: KviWindow(KVI_WINDOW_TYPE_HELP,lpFrm,name)
+{
+
+ if(!g_bIndexingDone)
+ {
+ QString szDoclist,szDict;
+
+ g_pApp->getLocalKvircDirectory(szDoclist,KviApp::Help,"help.doclist." KVI_SOURCES_DATE);
+ g_pApp->getLocalKvircDirectory(szDict,KviApp::Help,"help.dict." KVI_SOURCES_DATE);
+
+ if ( QFileInfo( szDoclist ).exists() && QFileInfo( szDict ).exists() ) {
+ g_pDocIndex->readDict();
+ } else {
+#ifdef COMPILE_USE_QT4
+ QProgressDialog* pProgressDialog = new QProgressDialog( __tr2qs("Indexing help files"), __tr2qs("Cancel"), 0,100 );
+#else
+ QProgressDialog* pProgressDialog = new QProgressDialog( __tr2qs("Indexing help files"), __tr2qs("Cancel"), 100 );
+#endif
+ connect(g_pDocIndex,SIGNAL(indexingProgress(int)), pProgressDialog, SLOT(setProgress(int)) );
+ g_pDocIndex->makeIndex();
+ g_pDocIndex->writeDict();
+ g_pDocIndex->writeDocumentList();
+ delete pProgressDialog;
+ }
+ g_bIndexingDone=TRUE;
+ }
+
+ g_pHelpWindowList->append(this);
+ m_pSplitter = new QSplitter(Qt::Horizontal,this,"main_splitter");
+ m_pHelpWidget = new KviHelpWidget(m_pSplitter,lpFrm);
+
+ m_pToolBar=new KviTalVBox(m_pSplitter);
+
+ m_pTabWidget = new QTabWidget(m_pToolBar);
+
+ m_pIndexTab = new KviTalVBox(m_pTabWidget);
+ m_pTabWidget->insertTab(m_pIndexTab,__tr2qs("Index"));
+
+ KviTalHBox* pSearchBox = new KviTalHBox(m_pIndexTab);
+ m_pIndexSearch = new QLineEdit(pSearchBox);
+ connect( m_pIndexSearch, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( searchInIndex(const QString&) ) );
+ connect( m_pIndexSearch, SIGNAL( returnPressed() ),
+ this, SLOT( showIndexTopic() ) );
+
+ KviStyledToolButton* pBtnRefreshIndex = new KviStyledToolButton(pSearchBox);
+ pBtnRefreshIndex->setIconSet(*g_pIconManager->getBigIcon(KVI_REFRESH_IMAGE_NAME));
+ connect(pBtnRefreshIndex,SIGNAL(clicked()),this,SLOT(refreshIndex()));
+ QToolTip::add( pBtnRefreshIndex, __tr2qs("Refresh index") );
+
+ m_pIndexListBox = new KviTalListBox(m_pIndexTab);
+ QStringList docList=g_pDocIndex->titlesList();
+ m_pIndexListBox->insertStringList(docList);
+ connect(m_pIndexListBox,SIGNAL(selected(int)),this,SLOT(indexSelected ( int )));
+ m_pIndexListBox->sort();
+
+ m_pSearchTab = new KviTalVBox(m_pTabWidget);
+ m_pTabWidget->insertTab(m_pSearchTab,__tr2qs("Search"));
+
+ m_pTermsEdit = new QLineEdit(m_pSearchTab);
+/* connect( m_pTermsEdit, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( searchInIndex(const QString&) ) );*/
+ connect( m_pTermsEdit, SIGNAL( returnPressed() ),
+ this, SLOT( startSearch() ) );
+
+ m_pResultBox = new KviTalListBox(m_pSearchTab);
+ connect(m_pResultBox,SIGNAL(selected(int)),this,SLOT(searchSelected ( int )));
+
+ KviValueList<int> li;
+ li.append(width()-80);
+ li.append(80);
+ m_pSplitter->setSizes(li);
+
+}
+
+KviHelpWindow::~KviHelpWindow()
+{
+ g_pHelpWindowList->removeRef(this);
+}
+
+void KviHelpWindow::saveProperties(KviConfig *cfg)
+{
+ KviWindow::saveProperties(cfg);
+ cfg->writeEntry("Splitter",m_pSplitter->sizes());
+}
+
+void KviHelpWindow::loadProperties(KviConfig *cfg)
+{
+ KviValueList<int> def;
+ int w = width();
+ def.append((w * 82) / 100);
+ def.append((w * 18) / 100);
+ m_pSplitter->setSizes(cfg->readIntListEntry("Splitter",def));
+ KviWindow::loadProperties(cfg);
+}
+
+
+void KviHelpWindow::refreshIndex()
+{
+ m_pIndexListBox->clear();
+#ifdef COMPILE_USE_QT4
+ QProgressDialog* pProgressDialog = new QProgressDialog( __tr2qs("Indexing help files"), __tr2qs("Cancel"), 0,100 );
+#else
+ QProgressDialog* pProgressDialog = new QProgressDialog( __tr2qs("Indexing help files"), __tr2qs("Cancel"), 100 );
+#endif
+ connect(g_pDocIndex,SIGNAL(indexingProgress(int)), pProgressDialog, SLOT(setProgress(int)) );
+ g_pDocIndex->makeIndex();
+ g_pDocIndex->writeDict();
+ g_pDocIndex->writeDocumentList();
+ delete pProgressDialog;
+ g_bIndexingDone=TRUE;
+ QStringList docList=g_pDocIndex->titlesList();
+ m_pIndexListBox->insertStringList(docList);
+ m_pIndexListBox->sort();
+}
+
+void KviHelpWindow::startSearch()
+{
+
+ QString str = m_pTermsEdit->text();
+ str = str.replace( "\'", "\"" );
+ str = str.replace( "`", "\"" );
+ QString buf = str;
+ str = str.replace( "-", " " );
+ str = str.replace( QRegExp( "\\s[\\S]?\\s" ), " " );
+ m_terms = QStringList::split( " ", str );
+ QStringList termSeq;
+ QStringList seqWords;
+ QStringList::iterator it = m_terms.begin();
+ for ( ; it != m_terms.end(); ++it ) {
+ (*it) = (*it).simplifyWhiteSpace();
+ (*it) = (*it).lower();
+ (*it) = (*it).replace( "\"", "" );
+ }
+ if ( str.contains( '\"' ) ) {
+#ifdef COMPILE_USE_QT4
+ if ( (str.count( '\"' ))%2 == 0 ) {
+#else
+ if ( (str.contains( '\"' ))%2 == 0 ) {
+#endif
+ int beg = 0;
+ int end = 0;
+ QString s;
+ beg = str.find( '\"', beg );
+ while ( beg != -1 ) {
+ beg++;
+ end = str.find( '\"', beg );
+ s = str.mid( beg, end - beg );
+ s = s.lower();
+ s = s.simplifyWhiteSpace();
+ if ( s.contains( '*' ) ) {
+ QMessageBox::warning( this, tr( "Full Text Search" ),
+ tr( "Using a wildcard within phrases is not allowed." ) );
+ return;
+ }
+ seqWords += QStringList::split( ' ', s );
+ termSeq << s;
+ beg = str.find( '\"', end + 1);
+ }
+ } else {
+ QMessageBox::warning( this, tr( "Full Text Search" ),
+ tr( "The closing quotation mark is missing." ) );
+ return;
+ }
+ }
+#ifdef COMPILE_USE_QT4
+ setCursor( Qt::WaitCursor );
+#else
+ setCursor( waitCursor );
+#endif
+ m_foundDocs.clear();
+ m_foundDocs = g_pDocIndex->query( m_terms, termSeq, seqWords );
+
+ m_pResultBox->clear();
+ for ( it = m_foundDocs.begin(); it != m_foundDocs.end(); ++it )
+ m_pResultBox->insertItem( g_pDocIndex->getDocumentTitle( *it ) );
+
+ m_terms.clear();
+ bool isPhrase = FALSE;
+ QString s = "";
+ for ( int i = 0; i < (int)buf.length(); ++i ) {
+ if ( buf[i] == '\"' ) {
+ isPhrase = !isPhrase;
+ s = s.simplifyWhiteSpace();
+ if ( !s.isEmpty() )
+ m_terms << s;
+ s = "";
+ } else if ( buf[i] == ' ' && !isPhrase ) {
+ s = s.simplifyWhiteSpace();
+ if ( !s.isEmpty() )
+ m_terms << s;
+ s = "";
+ } else
+ s += buf[i];
+ }
+ if ( !s.isEmpty() )
+ m_terms << s;
+
+#ifdef COMPILE_USE_QT4
+ setCursor( Qt::ArrowCursor );
+#else
+ setCursor( arrowCursor );
+#endif
+}
+
+QTextBrowser * KviHelpWindow::textBrowser()
+{
+ return m_pHelpWidget->textBrowser();
+}
+
+void KviHelpWindow::showIndexTopic()
+{
+ if (m_pIndexSearch->text().isEmpty()|| !m_pIndexListBox->selectedItem()) return;
+ int i=g_pDocIndex->titlesList().findIndex(m_pIndexListBox->selectedItem()->text());
+ textBrowser()->setSource(g_pDocIndex->documentList()[ i ]);
+}
+
+void KviHelpWindow::searchInIndex( const QString &s )
+{
+ KviTalListBoxItem *i = m_pIndexListBox->firstItem();
+ QString sl = s.lower();
+ while ( i ) {
+ QString t = i->text();
+ if ( t.length() >= sl.length() &&
+ i->text().left(s.length()).lower() == sl ) {
+ m_pIndexListBox->setCurrentItem( i );
+ m_pIndexListBox->setTopItem(m_pIndexListBox->index(i));
+ break;
+ }
+ i = i->next();
+ }
+}
+
+void KviHelpWindow::indexSelected ( int index )
+{
+ int i=g_pDocIndex->titlesList().findIndex(m_pIndexListBox->text(index));
+ textBrowser()->setSource(g_pDocIndex->documentList()[ i ]);
+}
+
+void KviHelpWindow::searchSelected ( int index )
+{
+ int i=g_pDocIndex->titlesList().findIndex(m_pResultBox->text(index));
+ textBrowser()->setSource(g_pDocIndex->documentList()[ i ]);
+}
+
+QPixmap * KviHelpWindow::myIconPtr()
+{
+ return g_pIconManager->getSmallIcon(KVI_SMALLICON_MDIHELP);
+}
+
+void KviHelpWindow::resizeEvent(QResizeEvent *e)
+{
+ m_pSplitter->setGeometry(0,0,width(),height());
+}
+
+QSize KviHelpWindow::sizeHint() const
+{
+ return m_pHelpWidget->sizeHint();
+}
+void KviHelpWindow::fillCaptionBuffers()
+{
+ m_szPlainTextCaption = __tr2qs("Help Browser");
+
+ m_szHtmlActiveCaption = "<nobr><font color=\"";
+ m_szHtmlActiveCaption += KVI_OPTION_COLOR(KviOption_colorCaptionTextActive).name();
+ m_szHtmlActiveCaption += "\"><b>";
+ m_szHtmlActiveCaption += m_szPlainTextCaption;
+ m_szHtmlActiveCaption += "</b></font></nobr>";
+
+
+ m_szHtmlInactiveCaption = "<nobr><font color=\"";
+ m_szHtmlInactiveCaption += KVI_OPTION_COLOR(KviOption_colorCaptionTextInactive).name();
+ m_szHtmlInactiveCaption += "\"><b>";
+ m_szHtmlInactiveCaption += m_szPlainTextCaption;
+ m_szHtmlInactiveCaption += "</b></font></nobr>";
+}
+
+
+#include "helpwindow.moc"
diff --git a/src/modules/help/helpwindow.h b/src/modules/help/helpwindow.h
new file mode 100644
index 00000000..70f27af6
--- /dev/null
+++ b/src/modules/help/helpwindow.h
@@ -0,0 +1,75 @@
+#ifndef _HELPWINDOW_H_
+#define _HELPWINDOW_H_
+//
+// File : helpwindow.h
+// Creation date : Fri Aug 11 2000 18:05:59 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_window.h"
+#include "kvi_string.h"
+#include "kvi_tal_vbox.h"
+#include <qtabwidget.h>
+#include "kvi_tal_listbox.h"
+#include <qlineedit.h>
+#include <qprogressdialog.h>
+
+class KviHelpWidget;
+class QTextBrowser;
+
+class KviHelpWindow : public KviWindow
+{
+ Q_OBJECT
+public:
+ KviHelpWindow(KviFrame * lpFrm,const char * name);
+ ~KviHelpWindow();
+protected:
+ KviHelpWidget * m_pHelpWidget;
+ KviTalVBox * m_pToolBar;
+ QTabWidget * m_pTabWidget;
+ KviTalVBox * m_pIndexTab;
+ KviTalVBox * m_pSearchTab;
+
+ KviTalListBox * m_pIndexListBox;
+ QLineEdit * m_pIndexSearch;
+ QStringList m_foundDocs;
+ QStringList m_terms;
+ KviTalListBox * m_pResultBox;
+ QLineEdit * m_pTermsEdit;
+public:
+ KviHelpWidget * helpWidget(){ return m_pHelpWidget; };
+protected:
+ virtual QPixmap * myIconPtr();
+ virtual void fillCaptionBuffers();
+ virtual void resizeEvent(QResizeEvent *e);
+ virtual void saveProperties(KviConfig * cfg);
+ virtual void loadProperties(KviConfig * cfg);
+public:
+ virtual QSize sizeHint() const;
+ QTextBrowser * textBrowser();
+public slots:
+ void indexSelected ( int );
+ void searchInIndex( const QString &s );
+ void showIndexTopic();
+ void startSearch();
+ void searchSelected ( int index );
+ void refreshIndex();
+};
+
+#endif //_KVI_HELPWINDOW_H_
diff --git a/src/modules/help/index.cpp b/src/modules/help/index.cpp
new file mode 100755
index 00000000..659ff44c
--- /dev/null
+++ b/src/modules/help/index.cpp
@@ -0,0 +1,854 @@
+#include "index.h"
+
+#include "kvi_file.h"
+#include <qdir.h>
+#include <qstringlist.h>
+#include "kvi_pointerhashtable.h"
+#include <qapplication.h>
+#include <qtextstream.h>
+#include <ctype.h>
+
+
+int kvi_compare(const Term * p1,const Term * p2)
+{
+ if(p1->frequency == p2->frequency)
+ return 0;
+ if(p1->frequency < p2->frequency)
+ return -1;
+ return 1;
+}
+
+QDataStream &operator>>( QDataStream &s, Document &l )
+{
+ s >> l.docNumber;
+ s >> l.frequency;
+ return s;
+}
+
+QDataStream &operator<<( QDataStream &s, const Document &l )
+{
+ s << (Q_INT16)l.docNumber;
+ s << (Q_INT16)l.frequency;
+ return s;
+}
+
+Index::Index( const QString &dp, const QString &hp )
+
+ : QObject( 0, 0 ), dict( 8999 ), docPath( dp )
+
+{
+ alreadyHaveDocList = FALSE;
+ lastWindowClosed = FALSE;
+ connect( qApp, SIGNAL( lastWindowClosed() ),
+ this, SLOT( setLastWinClosed() ) );
+}
+
+
+
+Index::Index( const QStringList &dl, const QString &hp )
+
+ : QObject( 0, 0 ), dict( 8999 )
+
+{
+ docList = dl;
+ alreadyHaveDocList = TRUE;
+ lastWindowClosed = FALSE;
+ connect( qApp, SIGNAL( lastWindowClosed() ),
+ this, SLOT( setLastWinClosed() ) );
+}
+
+
+
+void Index::setLastWinClosed()
+
+{
+
+ lastWindowClosed = TRUE;
+
+}
+
+
+
+void Index::setDictionaryFile( const QString &f )
+
+{
+
+ dictFile = f;
+
+}
+
+
+
+void Index::setDocListFile( const QString &f )
+{
+ docListFile = f;
+}
+
+
+
+int Index::makeIndex()
+{
+ if ( !alreadyHaveDocList )
+ setupDocumentList();
+ if ( docList.isEmpty() )
+ return 1;
+ dict.clear();
+ QStringList::Iterator it = docList.begin();
+ int steps = docList.count() / 100;
+ if ( !steps )
+ steps++;
+ int prog = 0;
+ for ( int i = 0; it != docList.end(); ++it, ++i ) {
+ if ( lastWindowClosed ) {
+ return -1;
+ }
+ parseDocument( *it, i );
+ if ( i%steps == 0 ) {
+ prog++;
+ emit indexingProgress( prog );
+ }
+ }
+ return 0;
+}
+
+
+
+void Index::setupDocumentList()
+
+{
+ docList.clear();
+ titleList.clear();
+ QDir d( docPath );
+ QString szCur;
+ QStringList lst = d.entryList( "*.html" );
+ QStringList::ConstIterator it = lst.begin();
+ for ( ; it != lst.end(); ++it )
+ {
+ szCur=docPath + "/" + *it;
+ docList.append( szCur );
+ titleList.append(getDocumentTitle( szCur ));
+ }
+}
+
+
+
+void Index::insertInDict( const QString &str, int docNum )
+{
+ if ( strcmp( str, "amp" ) == 0 || strcmp( str, "nbsp" ) == 0 )
+ return;
+ Entry *e = 0;
+ if ( dict.count() )
+ e = dict[ str ];
+
+ if ( e ) {
+ if ( e->documents.first().docNumber != docNum )
+ e->documents.prepend( Document( docNum, 1 ) );
+ else
+ e->documents.first().frequency++;
+ } else {
+ dict.insert( str, new Entry( docNum ) );
+ }
+}
+
+
+
+void Index::parseDocument( const QString &filename, int docNum )
+{
+ KviFile file( filename );
+ if ( !file.openForReading() ) {
+ qWarning( "can not open file " + filename );
+ return;
+ }
+ QTextStream s( &file );
+ QString text = s.read();
+ if (text.isNull())
+ return;
+ bool valid = TRUE;
+ const QChar *buf = text.unicode();
+ QChar str[64];
+ QChar c = buf[0];
+ int j = 0;
+ int i = 0;
+ while ( (uint)j < text.length() ) {
+ if ( c == '<' || c == '&' ) {
+ valid = FALSE;
+ if ( i > 1 )
+ insertInDict( QString(str,i), docNum );
+ i = 0;
+ c = buf[++j];
+ continue;
+ }
+ if ( ( c == '>' || c == ';' ) && !valid ) {
+ valid = TRUE;
+ c = buf[++j];
+ continue;
+ }
+
+ if ( !valid ) {
+
+ c = buf[++j];
+
+ continue;
+
+ }
+
+ if ( ( c.isLetterOrNumber() || c == '_' ) && i < 63 ) {
+
+ str[i] = c.lower();
+
+ ++i;
+
+ } else {
+
+ if ( i > 1 )
+
+ insertInDict( QString(str,i), docNum );
+
+ i = 0;
+
+ }
+
+ c = buf[++j];
+
+ }
+
+ if ( i > 1 )
+
+ insertInDict( QString(str,i), docNum );
+
+ file.close();
+
+}
+
+
+
+void Index::writeDict()
+
+{
+
+ KviPointerHashTableIterator<QString,Entry> it( dict );
+
+ KviFile f( dictFile );
+
+ if ( !f.openForWriting() )
+
+ return;
+
+ QDataStream s( &f );
+
+ for( ; it.current(); ++it ) {
+
+ Entry *e = it.current();
+
+ s << it.currentKey();
+
+ s << e->documents;
+
+ }
+
+ f.close();
+
+ writeDocumentList();
+
+}
+
+
+
+void Index::writeDocumentList()
+
+{
+ KviFile f( docListFile );
+ if ( !f.openForWriting() )
+ return;
+ QTextStream s( &f );
+ QString docs = docList.join("[#item#]");
+ s << docs;
+
+ KviFile f1( docListFile+".titles" );
+ if ( !f1.openForWriting() )
+ return;
+ QTextStream s1( &f1 );
+ docs = titleList.join("[#item#]");
+ s1 << docs;
+}
+
+
+
+void Index::readDict()
+
+{
+ KviFile f( dictFile );
+ if ( !f.openForReading() )
+ return;
+ dict.clear();
+ QDataStream s( &f );
+ QString key;
+ KviValueList<Document> docs;
+ while ( !s.atEnd() ) {
+ s >> key;
+ s >> docs;
+ dict.insert( key, new Entry( docs ) );
+ }
+ f.close();
+ readDocumentList();
+}
+
+
+
+void Index::readDocumentList()
+{
+ //reading docs
+ KviFile f( docListFile );
+ if ( !f.openForReading() )
+ return;
+ QTextStream s( &f );
+ docList = QStringList::split("[#item#]",s.read());
+
+ //reading titles
+ KviFile f1( docListFile+".titles" );
+ if ( !f1.openForReading() )
+ return;
+ QTextStream s1( &f1 );
+ titleList = QStringList::split("[#item#]",s1.read());
+// debug(titleList);
+}
+
+
+
+QStringList Index::query( const QStringList &terms, const QStringList &termSeq, const QStringList &seqWords )
+
+{
+
+ TermList termList;
+
+
+
+ QStringList::ConstIterator it = terms.begin();
+
+ for ( it = terms.begin(); it != terms.end(); ++it ) {
+
+ Entry *e = 0;
+
+ if ( (*it).contains( '*' ) ) {
+
+ KviValueList<Document> wcts = setupDummyTerm( getWildcardTerms( *it ) );
+
+ termList.append( new Term( "dummy", wcts.count(), wcts ) );
+
+ } else if ( dict[ *it ] ) {
+
+ e = dict[ *it ];
+
+ termList.append( new Term( *it, e->documents.count(), e->documents ) );
+
+ } else {
+
+ return QStringList();
+
+ }
+
+ }
+
+ termList.sort();
+
+
+
+ Term *minTerm = termList.first();
+
+ if ( !termList.count() )
+
+ return QStringList();
+
+ termList.removeFirst();
+
+
+
+ KviValueList<Document> minDocs = minTerm->documents;
+
+ KviValueList<Document>::iterator C;
+
+ KviValueList<Document>::ConstIterator It;
+
+ Term *t = termList.first();
+
+ for ( ; t; t = termList.next() ) {
+
+ KviValueList<Document> docs = t->documents;
+
+ C = minDocs.begin();
+
+ while ( C != minDocs.end() ) {
+
+ bool found = FALSE;
+
+ for ( It = docs.begin(); It != docs.end(); ++It ) {
+
+ if ( (*C).docNumber == (*It).docNumber ) {
+
+ (*C).frequency += (*It).frequency;
+
+ found = TRUE;
+
+ break;
+
+ }
+
+ }
+
+ if ( !found )
+
+ C = minDocs.remove( C );
+
+ else
+
+ ++C;
+
+ }
+
+ }
+
+
+
+ QStringList results;
+
+#ifndef COMPILE_USE_QT4
+ qHeapSort( minDocs );
+#endif
+ if ( termSeq.isEmpty() ) {
+
+ for ( C = minDocs.begin(); C != minDocs.end(); ++C )
+
+ results << docList[ (int)(*C).docNumber ];
+
+ return results;
+
+ }
+
+
+
+ QString fileName;
+
+ for ( C = minDocs.begin(); C != minDocs.end(); ++C ) {
+
+ fileName = docList[ (int)(*C).docNumber ];
+
+ if ( searchForPattern( termSeq, seqWords, fileName ) )
+
+ results << fileName;
+
+ }
+
+ return results;
+
+}
+
+
+
+QString Index::getDocumentTitle( const QString &fileName )
+
+{
+
+ KviFile file( fileName );
+
+ if ( !file.openForReading() ) {
+
+ qWarning( "cannot open file " + fileName );
+
+ return fileName;
+
+ }
+
+ QTextStream s( &file );
+
+ QString text = s.read();
+
+
+
+ int start = text.find( "<title>", 0, FALSE ) + 7;
+
+ int end = text.find( "</title>", 0, FALSE );
+
+
+
+ QString title = ( end - start <= 0 ? tr("Untitled") : text.mid( start, end - start ) );
+
+ return title;
+
+}
+
+
+
+QStringList Index::getWildcardTerms( const QString &term )
+
+{
+
+ QStringList lst;
+
+ QStringList terms = split( term );
+
+#ifdef COMPILE_USE_QT4
+ QStringList::Iterator iter;
+#else
+ KviValueList<QString>::iterator iter;
+#endif
+
+
+ KviPointerHashTableIterator<QString,Entry> it( dict );
+
+ for( ; it.current(); ++it ) {
+
+ int index = 0;
+
+ bool found = FALSE;
+
+ QString text( it.currentKey() );
+
+ for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
+
+ if ( *iter == "*" ) {
+
+ found = TRUE;
+
+ continue;
+
+ }
+
+ if ( iter == terms.begin() && (*iter)[0] != text[0] ) {
+
+ found = FALSE;
+
+ break;
+
+ }
+
+ index = text.find( *iter, index );
+
+ if ( *iter == terms.last() && index != (int)text.length()-1 ) {
+
+ index = text.findRev( *iter );
+
+ if ( index != (int)text.length() - (int)(*iter).length() ) {
+
+ found = FALSE;
+
+ break;
+
+ }
+
+ }
+
+ if ( index != -1 ) {
+
+ found = TRUE;
+
+ index += (*iter).length();
+
+ continue;
+
+ } else {
+
+ found = FALSE;
+
+ break;
+
+ }
+
+ }
+
+ if ( found )
+
+ lst << text;
+
+ }
+
+
+
+ return lst;
+
+}
+
+
+
+QStringList Index::split( const QString &str )
+
+{
+
+ QStringList lst;
+
+ int j = 0;
+
+ int i = str.find( '*', j );
+
+
+
+ while ( i != -1 ) {
+
+ if ( i > j && i <= (int)str.length() ) {
+
+ lst << str.mid( j, i - j );
+
+ lst << "*";
+
+ }
+
+ j = i + 1;
+
+ i = str.find( '*', j );
+
+ }
+
+
+
+ int l = str.length() - 1;
+
+ if ( str.mid( j, l - j + 1 ).length() > 0 )
+
+ lst << str.mid( j, l - j + 1 );
+
+
+
+ return lst;
+
+}
+
+
+
+KviValueList<Document> Index::setupDummyTerm( const QStringList &terms )
+
+{
+
+ TermList termList;
+
+ QStringList::ConstIterator it = terms.begin();
+
+ for ( ; it != terms.end(); ++it ) {
+
+ Entry *e = 0;
+
+ if ( dict[ *it ] ) {
+
+ e = dict[ *it ];
+
+ termList.append( new Term( *it, e->documents.count(), e->documents ) );
+
+ }
+
+ }
+
+ termList.sort();
+
+
+
+ KviValueList<Document> maxList;
+
+
+
+ if ( !termList.count() )
+
+ return maxList;
+
+ maxList = termList.last()->documents;
+
+ termList.removeLast();
+
+
+
+ KviValueList<Document>::iterator docIt;
+
+ Term *t = termList.first();
+
+ while ( t ) {
+
+ KviValueList<Document> docs = t->documents;
+
+ for ( docIt = docs.begin(); docIt != docs.end(); ++docIt ) {
+
+ if ( maxList.findIndex( *docIt ) == -1 )
+
+ maxList.append( *docIt );
+
+ }
+
+ t = termList.next();
+
+ }
+
+ return maxList;
+
+}
+
+
+
+void Index::buildMiniDict( const QString &str )
+
+{
+
+ if ( miniDict[ str ] )
+
+ miniDict[ str ]->positions.append( wordNum );
+
+ ++wordNum;
+
+}
+
+
+
+bool Index::searchForPattern( const QStringList &patterns, const QStringList &words, const QString &fileName )
+
+{
+
+ KviFile file( fileName );
+
+ if ( !file.openForReading() ) {
+
+ qWarning( "cannot open file " + fileName );
+
+ return FALSE;
+
+ }
+
+
+
+ wordNum = 3;
+
+ miniDict.clear();
+
+ QStringList::ConstIterator cIt = words.begin();
+
+ for ( ; cIt != words.end(); ++cIt )
+
+ miniDict.insert( *cIt, new PosEntry( 0 ) );
+
+
+
+ QTextStream s( &file );
+
+ QString text = s.read();
+
+ bool valid = TRUE;
+
+ const QChar *buf = text.unicode();
+
+ QChar str[64];
+
+ QChar c = buf[0];
+
+ int j = 0;
+
+ int i = 0;
+
+ while ( (uint)j < text.length() ) {
+
+ if ( c == '<' || c == '&' ) {
+
+ valid = FALSE;
+
+ if ( i > 1 )
+
+ buildMiniDict( QString(str,i) );
+
+ i = 0;
+
+ c = buf[++j];
+
+ continue;
+
+ }
+
+ if ( ( c == '>' || c == ';' ) && !valid ) {
+
+ valid = TRUE;
+
+ c = buf[++j];
+
+ continue;
+
+ }
+
+ if ( !valid ) {
+
+ c = buf[++j];
+
+ continue;
+
+ }
+
+ if ( ( c.isLetterOrNumber() || c == '_' ) && i < 63 ) {
+
+ str[i] = c.lower();
+
+ ++i;
+
+ } else {
+
+ if ( i > 1 )
+
+ buildMiniDict( QString(str,i) );
+
+ i = 0;
+
+ }
+
+ c = buf[++j];
+
+ }
+
+ if ( i > 1 )
+
+ buildMiniDict( QString(str,i) );
+
+ file.close();
+
+
+
+ QStringList::ConstIterator patIt = patterns.begin();
+
+ QStringList wordLst;
+
+ KviValueList<uint> a, b;
+
+ KviValueList<uint>::iterator aIt;
+
+ for ( ; patIt != patterns.end(); ++patIt ) {
+
+ wordLst = QStringList::split( ' ', *patIt );
+
+ a = miniDict[ wordLst[0] ]->positions;
+
+ for ( int j = 1; j < (int)wordLst.count(); ++j ) {
+
+ b = miniDict[ wordLst[j] ]->positions;
+
+ aIt = a.begin();
+
+ while ( aIt != a.end() ) {
+
+ if ( b.find( *aIt + 1 ) != b.end() ) {
+
+ (*aIt)++;
+
+ ++aIt;
+
+ } else {
+
+ aIt = a.remove( aIt );
+
+ }
+
+ }
+
+ }
+
+ }
+
+ if ( a.count() )
+
+ return TRUE;
+
+ return FALSE;
+
+}
+
+
+
+#include "index.moc" \ No newline at end of file
diff --git a/src/modules/help/index.h b/src/modules/help/index.h
new file mode 100755
index 00000000..9debcb3e
--- /dev/null
+++ b/src/modules/help/index.h
@@ -0,0 +1,124 @@
+/**********************************************************************
+** Copyright (C) 2000-2003 Trolltech AS. All rights reserved.
+**
+** This file is part of the Qt Assistant.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+
+#ifndef INDEX_H
+#define INDEX_H
+
+#include <qstringlist.h>
+#include "kvi_pointerhashtable.h"
+#include "kvi_pointerlist.h"
+#include "kvi_valuelist.h"
+#include <qdatastream.h>
+#include <qobject.h>
+
+struct Document {
+ Document( int d, int f ) : docNumber( d ), frequency( f ) {}
+ Document() : docNumber( -1 ), frequency( 0 ) {}
+ bool operator==( const Document &doc ) const {
+ return docNumber == doc.docNumber;
+ }
+ bool operator<( const Document &doc ) const {
+ return frequency > doc.frequency;
+ }
+ bool operator<=( const Document &doc ) const {
+ return frequency >= doc.frequency;
+ }
+ bool operator>( const Document &doc ) const {
+ return frequency < doc.frequency;
+ }
+ Q_INT16 docNumber;
+ Q_INT16 frequency;
+};
+
+QDataStream &operator>>( QDataStream &s, Document &l );
+QDataStream &operator<<( QDataStream &s, const Document &l );
+
+class Index : public QObject
+{
+ Q_OBJECT
+public:
+ struct Entry {
+ Entry( int d ) { documents.append( Document( d, 1 ) ); }
+ Entry( KviValueList<Document> l ) : documents( l ) {}
+ KviValueList<Document> documents;
+ };
+ struct PosEntry {
+ PosEntry( int p ) { positions.append( p ); }
+ KviValueList<uint> positions;
+ };
+ Index( const QString &dp, const QString &hp );
+ Index( const QStringList &dl, const QString &hp );
+ void writeDict();
+ void readDict();
+ int makeIndex();
+ QStringList query( const QStringList&, const QStringList&, const QStringList& );
+ QString getDocumentTitle( const QString& );
+ void setDictionaryFile( const QString& );
+ void setDocListFile( const QString& );
+ void writeDocumentList();
+ void readDocumentList();
+ void setupDocumentList();
+ const QStringList& documentList() { return docList; };
+ const QStringList& titlesList() { return titleList; };
+signals:
+ void indexingProgress( int );
+private slots:
+ void setLastWinClosed();
+private:
+ void parseDocument( const QString&, int );
+ void insertInDict( const QString&, int );
+ QStringList getWildcardTerms( const QString& );
+ QStringList split( const QString& );
+ KviValueList<Document> setupDummyTerm( const QStringList& );
+ bool searchForPattern( const QStringList&, const QStringList&, const QString& );
+ void buildMiniDict( const QString& );
+ QStringList docList;
+ QStringList titleList;
+ KviPointerHashTable<QString,Entry> dict;
+ KviPointerHashTable<QString,PosEntry> miniDict;
+ uint wordNum;
+ QString docPath;
+ QString dictFile, docListFile;
+ bool alreadyHaveDocList;
+ bool lastWindowClosed;
+};
+
+struct Term {
+ Term( const QString &t, int f, KviValueList<Document> l )
+ : term( t ), frequency( f ), documents( l ) {}
+ QString term;
+ int frequency;
+ KviValueList<Document>documents;
+};
+
+
+
+#define TermList KviPointerList<Term>
+
+#endif
+
diff --git a/src/modules/help/libkvihelp.cpp b/src/modules/help/libkvihelp.cpp
new file mode 100644
index 00000000..c8da3c33
--- /dev/null
+++ b/src/modules/help/libkvihelp.cpp
@@ -0,0 +1,236 @@
+//
+// File : libkvihelp.cpp
+// Creation date : Sun Aug 13 2000 03:00:00 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "libkvihelp.h"
+
+#include "kvi_module.h"
+
+#include "kvi_sourcesdate.h"
+
+#include "helpwidget.h"
+#include "helpwindow.h"
+#include "index.h"
+#include "kvi_app.h"
+
+#include "kvi_frame.h"
+
+#ifdef COMPILE_USE_QT4
+ #include <q3mimefactory.h>
+#endif
+
+
+#include <qsplitter.h>
+Index * g_pDocIndex = 0;
+KviPointerList<KviHelpWidget> * g_pHelpWidgetList = 0;
+KviPointerList<KviHelpWindow> * g_pHelpWindowList = 0;
+
+/*
+ @doc: help.search
+ @type:
+ command
+ @title:
+ help.search
+ @short:
+ Searches the documentation
+ @syntax:
+ help.search [-n] [-m] <key terms>
+ @description:
+ Finds the first available help browser in the current frame
+ then searches the documentation for the specified <key terms>.
+ If no help browser is available it creates one first:
+ if the -m switch is present, the created browser is a MDI window,
+ otherwise it is a static window.
+ If the -n switch is present, the window creation is forced even
+ if there are other help browsers already open.[br]
+ The <key terms> are [b]space separated words[/b]
+ to be matched inside the document body (logical AND).[br]
+ This command is exported by the "help" module.
+*/
+
+/*tatic bool help_module_cmd_search(KviModule *m,KviCommand *c)
+{
+ ENTER_STACK_FRAME(c,"help_module_cmd_search");
+
+ KviStr keys;
+ if(!g_pZZZZZZUserParser->parseCmdFinalPart(c,keys))return false;
+
+ if(keys.isEmpty())keys = "kvirc";
+
+ if(!c->hasSwitch('n'))
+ {
+ // look for an already open help widget in this frame
+ KviHelpWidget * w = (KviHelpWidget *)c->window()->frame()->child(
+ "help_widget","KviHelpWidget");
+
+ if(w)
+ {
+ w->doExactSearchFor(keys.ptr());
+ return c->leaveStackFrame();
+ }
+ }
+
+ if(c->hasSwitch('m'))
+ {
+ KviHelpWindow *w = new KviHelpWindow(c->window()->frame(),"Help browser");
+ w->helpWidget()->doExactSearchFor(keys.ptr());
+ c->window()->frame()->addWindow(w);
+ } else {
+ KviHelpWidget *w = new KviHelpWidget(c->window()->frame()->splitter(),
+ c->window()->frame(),true);
+ w->doExactSearchFor(keys.ptr());
+ w->show();
+ }
+
+ return c->leaveStackFrame();
+}*/
+/*
+#ifdef COMPILE_NEW_KVS
+static bool help_kvs_cmd_search(KviKvsModuleCommandCall * c)
+{
+}
+#endif
+*/
+/*
+ @doc: help.open
+ @type:
+ command
+ @title:
+ help.open
+ @short:
+ Shows a help document
+ @syntax:
+ help.open [-n] [-m] [document: string]
+ @description:
+ Finds the first available help browser in the current frame
+ then opens the specified [document].
+ If no [document] is specified it the documentation index is shown.
+ If no help browser is available , a new one is created.
+ [document] can be an absolute path or a relative one: in this case
+ the document is searched in the KVIrc documentation directory.[br]
+ The help browser has limited html browsing capabilities: you can
+ use it to view simple html files on your filesystem.[br]
+ This command is exported by the "help" module.
+ @switches:
+ !sw: -m | --mdi
+ The created browser is a MDI window,
+ otherwise it is a static window.
+ !sw: -n | --new
+ The window creation is forced even
+ if there are other help browsers already open.[br]
+*/
+
+
+static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
+{
+ QString doc;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("document",KVS_PT_STRING,KVS_PF_OPTIONAL,doc)
+ KVSM_PARAMETERS_END(c)
+ if(doc.isEmpty())doc = "index.html";
+#ifdef COMPILE_USE_QT4
+ Q3MimeSourceFactory * f = Q3MimeSourceFactory::defaultFactory();
+#else
+ QMimeSourceFactory * f = QMimeSourceFactory::defaultFactory();
+#endif
+ if(f)
+ {
+ if(!f->data(doc))
+ doc = "nohelpavailable.html";
+ }
+
+ if(!c->switches()->find('n',"new"))
+ {
+ KviHelpWidget * w = (KviHelpWidget *)c->window()->frame()->child("help_widget","KviHelpWidget");
+ if(w)
+ {
+ w->textBrowser()->setSource(doc);
+ return true;
+ }
+ }
+ if(c->switches()->find('m',"mdi"))
+ {
+ KviHelpWindow *w = new KviHelpWindow(c->window()->frame(),"Help browser");
+ w->textBrowser()->setSource(doc);
+ c->window()->frame()->addWindow(w);
+ } else {
+ KviHelpWidget *w = new KviHelpWidget(c->window()->frame()->splitter(),
+ c->window()->frame(),true);
+ w->textBrowser()->setSource(doc);
+ w->show();
+ //debug ("mostro");
+ }
+ return true;
+}
+
+
+
+static bool help_module_init(KviModule * m)
+{
+ QString szHelpDir,szDocList;
+
+ g_pApp->getLocalKvircDirectory(szDocList,KviApp::Help,"help.doclist." KVI_SOURCES_DATE);
+ g_pApp->getGlobalKvircDirectory(szHelpDir,KviApp::Help);
+
+ g_pDocIndex = new Index(szHelpDir,szDocList);
+ g_pDocIndex->setDocListFile(szDocList);
+
+ g_pApp->getLocalKvircDirectory(szHelpDir,KviApp::Help,"help.dict." KVI_SOURCES_DATE);
+ g_pDocIndex->setDictionaryFile(szHelpDir);
+
+ g_pHelpWidgetList = new KviPointerList<KviHelpWidget>;
+ g_pHelpWidgetList->setAutoDelete(false);
+ g_pHelpWindowList = new KviPointerList<KviHelpWindow>;
+ g_pHelpWindowList->setAutoDelete(false);
+
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"open",help_kvs_cmd_open);
+
+
+ return true;
+}
+
+static bool help_module_cleanup(KviModule *m)
+{
+ if(g_pDocIndex) delete g_pDocIndex;
+ while(g_pHelpWidgetList->first())delete g_pHelpWidgetList->first();
+ delete g_pHelpWidgetList;
+ g_pHelpWidgetList = 0;
+ while(g_pHelpWindowList->first())g_pHelpWindowList->first()->close();
+ delete g_pHelpWindowList;
+ g_pHelpWindowList = 0;
+ return true;
+}
+
+static bool help_module_can_unload(KviModule *m)
+{
+ return (g_pHelpWidgetList->isEmpty() && g_pHelpWindowList->isEmpty());
+}
+
+KVIRC_MODULE(
+ "Help", // module name
+ "1.0.0", // module version
+ "Copyright (C) 2000 Szymon Stefanek (pragma at kvirc dot net)", // author & (C)
+ "Help browser extension",
+ help_module_init,
+ help_module_can_unload,
+ 0,
+ help_module_cleanup
+)