diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/help/helpwidget.cpp | 6 | ||||
| -rw-r--r-- | src/modules/help/helpwidget.h | 12 | ||||
| -rw-r--r-- | src/modules/help/helpwindow.cpp | 166 | ||||
| -rw-r--r-- | src/modules/help/helpwindow.h | 27 | ||||
| -rwxr-xr-x | src/modules/help/index.cpp | 1160 | ||||
| -rwxr-xr-x | src/modules/help/index.h | 141 | ||||
| -rw-r--r-- | src/modules/help/libkvihelp.cpp | 32 |
7 files changed, 615 insertions, 929 deletions
diff --git a/src/modules/help/helpwidget.cpp b/src/modules/help/helpwidget.cpp index 64beb989e..cf4e7f408 100644 --- a/src/modules/help/helpwidget.cpp +++ b/src/modules/help/helpwidget.cpp @@ -21,6 +21,7 @@ // #include "helpwidget.h" +#include "helpwindow.h" #include "kvi_frame.h" #include "kvi_iconmanager.h" @@ -29,7 +30,6 @@ #include "kvi_msgbox.h" #include "kvi_module.h" #include "kvi_styled_controls.h" -#include "helpwindow.h" #include "kvi_fileutils.h" #include <QToolButton> @@ -45,7 +45,6 @@ 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; @@ -86,7 +85,6 @@ KviHelpWidget::KviHelpWidget(QWidget * par,KviFrame * lpFrm,bool bIsStandalone) connect(m_pTextBrowser,SIGNAL(forwardAvailable(bool)),m_pBtnForward,SLOT(setEnabled(bool))); m_pTextBrowser->viewport()->installEventFilter(this); - } KviHelpWidget::~KviHelpWidget() @@ -142,8 +140,6 @@ bool KviHelpWidget::eventFilter(QObject * o, QEvent *e) return QWidget::eventFilter(o,e); } - - #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "helpwidget.moc" #endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/help/helpwidget.h b/src/modules/help/helpwidget.h index 8d592e93c..8d7e35199 100644 --- a/src/modules/help/helpwidget.h +++ b/src/modules/help/helpwidget.h @@ -22,14 +22,16 @@ // Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // -#include "kvi_tal_hbox.h" -#include <qtextbrowser.h> #include "index.h" -#include <qprogressbar.h> -class KviFrame; +#include "kvi_tal_hbox.h" + +#include <QTextBrowser> +#include <QProgressBar> + class QToolButton; class QLineEdit; +class KviFrame; //class KviProcess; class KviHelpWidget : public QWidget @@ -42,7 +44,7 @@ private: QToolButton * m_pBtnIndex; QToolButton * m_pBtnBackward; QToolButton * m_pBtnForward; - KviTalHBox * m_pToolBar; + KviTalHBox * m_pToolBar; QTextBrowser * m_pTextBrowser; bool m_bIsStandalone; protected: diff --git a/src/modules/help/helpwindow.cpp b/src/modules/help/helpwindow.cpp index 4dc1bf257..3bc290534 100644 --- a/src/modules/help/helpwindow.cpp +++ b/src/modules/help/helpwindow.cpp @@ -23,13 +23,15 @@ #include "helpwindow.h" #include "helpwidget.h" -#include "kvi_app.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_valuelist.h" +#include "kvi_sourcesdate.h" #include "kvi_styled_controls.h" #include <QFileInfo> @@ -38,9 +40,6 @@ #include <QMessageBox> #include <QRegExp> #include <QToolTip> -#include "kvi_valuelist.h" - -#include "kvi_sourcesdate.h" extern Index * g_pDocIndex; extern KviPointerList<KviHelpWindow> * g_pHelpWindowList; @@ -50,7 +49,6 @@ bool g_bIndexingDone = FALSE; KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name) : KviWindow(KVI_WINDOW_TYPE_HELP,lpFrm,name) { - if(!g_bIndexingDone) { QString szDoclist,szDict; @@ -140,7 +138,6 @@ void KviHelpWindow::loadProperties(KviConfig *cfg) KviWindow::loadProperties(cfg); } - void KviHelpWindow::refreshIndex() { m_pIndexListBox->clear(); @@ -159,78 +156,77 @@ void KviHelpWindow::refreshIndex() 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( '\"' ) ) { - if ( (str.count( '\"' ))%2 == 0 ) { - 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; + 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( '\"' ) ) { + if ( (str.count( '\"' ))%2 == 0 ) { + 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; } - 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; } - } - setCursor( Qt::WaitCursor ); - m_foundDocs.clear(); - m_foundDocs = g_pDocIndex->query( m_terms, termSeq, seqWords ); + setCursor( Qt::WaitCursor ); + 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_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; + 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; - setCursor( Qt::ArrowCursor ); + setCursor( Qt::ArrowCursor ); } QTextBrowser * KviHelpWindow::textBrowser() @@ -247,18 +243,18 @@ void KviHelpWindow::showIndexTopic() 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; + 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(); } - i = i->next(); - } } void KviHelpWindow::indexSelected ( int index ) @@ -287,6 +283,7 @@ QSize KviHelpWindow::sizeHint() const { return m_pHelpWidget->sizeHint(); } + void KviHelpWindow::fillCaptionBuffers() { m_szPlainTextCaption = __tr2qs("Help Browser"); @@ -297,7 +294,6 @@ void KviHelpWindow::fillCaptionBuffers() 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>"; diff --git a/src/modules/help/helpwindow.h b/src/modules/help/helpwindow.h index 2f130eaaa..941f90456 100644 --- a/src/modules/help/helpwindow.h +++ b/src/modules/help/helpwindow.h @@ -25,13 +25,14 @@ #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; +#include <QTabWidget> +#include <QLineEdit> +#include <QProgressDialog> + class QTextBrowser; +class KviHelpWidget; class KviHelpWindow : public KviWindow { @@ -41,17 +42,17 @@ public: ~KviHelpWindow(); protected: KviHelpWidget * m_pHelpWidget; - KviTalVBox * m_pToolBar; + KviTalVBox * m_pToolBar; QTabWidget * m_pTabWidget; - KviTalVBox * m_pIndexTab; - KviTalVBox * m_pSearchTab; + KviTalVBox * m_pIndexTab; + KviTalVBox * m_pSearchTab; - KviTalListBox * m_pIndexListBox; - QLineEdit * m_pIndexSearch; - QStringList m_foundDocs; - QStringList m_terms; - KviTalListBox * m_pResultBox; - QLineEdit * m_pTermsEdit; + 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: diff --git a/src/modules/help/index.cpp b/src/modules/help/index.cpp index 353758145..e82074105 100755 --- a/src/modules/help/index.cpp +++ b/src/modules/help/index.cpp @@ -1,7 +1,34 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + #include "index.h" #include "kvi_file.h" #include "kvi_pointerhashtable.h" + #include <ctype.h> #include <QDir> @@ -11,841 +38,522 @@ int kvi_compare(const Term * p1,const Term * p2) { - if(p1->frequency == p2->frequency) - return 0; - if(p1->frequency < p2->frequency) - return -1; + 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; + 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; + 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 ) - +: QObject( 0, 0 ), dict( 8999 ), docPath( dp ) { - alreadyHaveDocList = FALSE; - lastWindowClosed = FALSE; - connect( qApp, SIGNAL( lastWindowClosed() ), - this, SLOT( setLastWinClosed() ) ); + alreadyHaveDocList = FALSE; + lastWindowClosed = FALSE; + connect(qApp,SIGNAL(lastWindowClosed()),this,SLOT(setLastWinClosed())); } - - Index::Index( const QStringList &dl, const QString &hp ) - - : QObject( 0, 0 ), dict( 8999 ) - +: QObject( 0, 0 ), dict( 8999 ) { - docList = dl; - alreadyHaveDocList = TRUE; - lastWindowClosed = FALSE; - connect( qApp, SIGNAL( lastWindowClosed() ), - this, SLOT( setLastWinClosed() ) ); + docList = dl; + alreadyHaveDocList = TRUE; + lastWindowClosed = FALSE; + connect(qApp,SIGNAL(lastWindowClosed()),this,SLOT(setLastWinClosed())); } - - void Index::setLastWinClosed() - { - - lastWindowClosed = TRUE; - + lastWindowClosed = TRUE; } - - void Index::setDictionaryFile( const QString &f ) - { - - dictFile = f; - + dictFile = f; } - - void Index::setDocListFile( const QString &f ) { - docListFile = 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 ); + 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; + 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 )); - } + 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 ) ); - } + 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; + KviFile file( filename ); + if ( !file.openForReading() ) { + qWarning( "can not open file " + filename ); + return; } - 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; + 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]; } - c = buf[++j]; - - } - - if ( i > 1 ) - - insertInDict( QString(str,i), docNum ); - - file.close(); - + 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(); - + 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; + 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(); + 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); + //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()); + // qDebug(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 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; - + + 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; } - - } - - 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 ]; - + + QStringList results; + 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 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; - + 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 ); - - QStringList::Iterator iter; - - - 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; - + QStringList lst; + QStringList terms = split( term ); + QStringList::Iterator iter; + + 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 ( index != -1 ) { - - found = TRUE; - - index += (*iter).length(); - - continue; - - } else { - - found = FALSE; - - break; - - } - + + if ( found ) lst << text; } - - if ( found ) - - lst << text; - - } - - - - return lst; - + + 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 << "*"; - + 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 ); } - - 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; - + + 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 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 ); - + + 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(); } - - t = termList.next(); - - } - - return maxList; - + + return maxList; } - - void Index::buildMiniDict( const QString &str ) - { - - if ( miniDict[ str ] ) - - miniDict[ str ]->positions.append( wordNum ); - - ++wordNum; - + 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; - + KviFile file( fileName ); + + if ( !file.openForReading() ) { + qWarning( "cannot open file " + fileName ); + return FALSE; } - - 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; - + + 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 { - - aIt = a.remove( aIt ); - + if ( i > 1 ) buildMiniDict( QString(str,i) ); + i = 0; } - - } - + + c = buf[++j]; } - - } - - if ( a.count() ) - - return TRUE; - - return FALSE; - + + 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; } - #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "index.moc" #endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/help/index.h b/src/modules/help/index.h index 9debcb3e9..f262fdeae 100755 --- a/src/modules/help/index.h +++ b/src/modules/help/index.h @@ -1,3 +1,5 @@ +#ifndef INDEX_H +#define INDEX_H /********************************************************************** ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. ** @@ -24,35 +26,31 @@ ** **********************************************************************/ - - -#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> + +#include <QDataStream> +#include <QObject> +#include <QStringList> 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; + 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 ); @@ -60,65 +58,62 @@ QDataStream &operator<<( QDataStream &s, const Document &l ); class Index : public QObject { - Q_OBJECT + 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; }; + 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 ); + void indexingProgress( int ); private slots: - void setLastWinClosed(); + 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; + 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( const QString &t, int f, KviValueList<Document> l ) : term( t ), frequency( f ), documents( l ) {} - QString term; - int frequency; - KviValueList<Document>documents; + 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 index 66b774982..d0da3456e 100644 --- a/src/modules/help/libkvihelp.cpp +++ b/src/modules/help/libkvihelp.cpp @@ -20,17 +20,13 @@ // Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_module.h" +#include "kvi_sourcesdate.h" +#include "kvi_app.h" #include "kvi_frame.h" #include <QFileInfo> @@ -137,7 +133,7 @@ static bool help_kvs_cmd_search(KviKvsModuleCommandCall * c) static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c) -{ +{ QString doc, szHelpDir; KVSM_PARAMETERS_BEGIN(c) @@ -146,21 +142,15 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c) g_pApp->getGlobalKvircDirectory(szHelpDir,KviApp::Help); if(doc.isEmpty()){ - doc = szHelpDir + "\\index.html"; - debug ("No file, use default at path %s",doc.toUtf8().data()); - } - else - - { - debug("Doc set from user to %s",doc.toUtf8().data()); - } + qDebug ("No file, use default at path %s",doc.toUtf8().data()); + } else qDebug("Doc set from user to %s",doc.toUtf8().data()); + QFileInfo * f= new QFileInfo(doc); - debug ("Path %d",doc.toUtf8().data()); + debug("Path %d",doc.toUtf8().data()); if(f) { - if(!f->exists()) - doc = szHelpDir + "/nohelpavailable.html"; + if(!f->exists()) doc = szHelpDir + "/nohelpavailable.html"; } if(!c->switches()->find('n',"new")) @@ -186,8 +176,6 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c) return true; } - - static bool help_module_init(KviModule * m) { QString szHelpDir,szDocList; @@ -231,7 +219,7 @@ static bool help_module_can_unload(KviModule *m) KVIRC_MODULE( "Help", // module name - "1.0.0", // module version + "4.0.0", // module version "Copyright (C) 2000 Szymon Stefanek (pragma at kvirc dot net)", // author & (C) "Help browser extension", help_module_init, |
