aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/help
diff options
context:
space:
mode:
authorGravatar Alexey Sokolov2016-04-29 23:57:30 +0100
committerGravatar Alexey Sokolov2016-04-29 23:57:48 +0100
commit690dd7a33ddc90678367d73adf313533536e10f2 (patch)
tree2276fe7c384ebbc222b40a19c536d5c3c5606ce8 /src/modules/help
parentAdd config for clang-format. (diff)
downloadKVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.gz
KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.bz2
KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.zip
Apply clang-format
Diffstat (limited to 'src/modules/help')
-rw-r--r--src/modules/help/HelpIndex.cpp899
-rw-r--r--src/modules/help/HelpIndex.h144
-rw-r--r--src/modules/help/HelpWidget.cpp102
-rw-r--r--src/modules/help/HelpWidget.h51
-rw-r--r--src/modules/help/HelpWindow.cpp243
-rw-r--r--src/modules/help/HelpWindow.h55
-rw-r--r--src/modules/help/libkvihelp.cpp112
7 files changed, 856 insertions, 750 deletions
diff --git a/src/modules/help/HelpIndex.cpp b/src/modules/help/HelpIndex.cpp
index 69a9c875b..3fba3c74d 100644
--- a/src/modules/help/HelpIndex.cpp
+++ b/src/modules/help/HelpIndex.cpp
@@ -52,38 +52,39 @@
QT_BEGIN_NAMESPACE
-struct Term {
- Term() : frequency(-1) {}
- Term( const QString &t, int f, QVector<Document> l ) : term( t ), frequency( f ), documents( l ) {}
- QString term;
- int frequency;
- QVector<Document>documents;
- bool operator<( const Term &i2 ) const { return frequency < i2.frequency; }
+struct Term
+{
+ Term() : frequency(-1) {}
+ Term(const QString & t, int f, QVector<Document> l) : term(t), frequency(f), documents(l) {}
+ QString term;
+ int frequency;
+ QVector<Document> documents;
+ bool operator<(const Term & i2) const { return frequency < i2.frequency; }
};
-QDataStream &operator>>( QDataStream &s, Document &l )
+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 )
+QDataStream & operator<<(QDataStream & s, const Document & l)
{
- s << (qint16)l.docNumber;
- s << (qint16)l.frequency;
- return s;
+ s << (qint16)l.docNumber;
+ s << (qint16)l.frequency;
+ return s;
}
-HelpIndex::HelpIndex( const QString &dp, const QString &hp )
- : QObject( 0 ), docPath( dp )
+HelpIndex::HelpIndex(const QString & dp, const QString & hp)
+ : QObject(0), docPath(dp)
{
- Q_UNUSED(hp);
+ Q_UNUSED(hp);
- alreadyHaveDocList = false;
- lastWindowClosed = false;
- connect( qApp, SIGNAL(lastWindowClosed()),
- this, SLOT(setLastWinClosed()) );
+ alreadyHaveDocList = false;
+ lastWindowClosed = false;
+ connect(qApp, SIGNAL(lastWindowClosed()),
+ this, SLOT(setLastWinClosed()));
m_pTimer = new QTimer(this);
m_pTimer->setSingleShot(true);
@@ -91,44 +92,44 @@ HelpIndex::HelpIndex( const QString &dp, const QString &hp )
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(filterNext()));
}
-HelpIndex::HelpIndex( const QStringList &dl, const QString &hp )
- : QObject( 0 )
+HelpIndex::HelpIndex(const QStringList & dl, const QString & hp)
+ : QObject(0)
{
- Q_UNUSED(hp);
- docList = dl;
- alreadyHaveDocList = true;
- lastWindowClosed = false;
- connect( qApp, SIGNAL(lastWindowClosed()),
- this, SLOT(setLastWinClosed()) );
+ Q_UNUSED(hp);
+ docList = dl;
+ alreadyHaveDocList = true;
+ lastWindowClosed = false;
+ connect(qApp, SIGNAL(lastWindowClosed()),
+ this, SLOT(setLastWinClosed()));
}
void HelpIndex::setLastWinClosed()
{
- lastWindowClosed = true;
+ lastWindowClosed = true;
}
-void HelpIndex::setDictionaryFile( const QString &f )
+void HelpIndex::setDictionaryFile(const QString & f)
{
- dictFile = f;
+ dictFile = f;
}
-void HelpIndex::setDocListFile( const QString &f )
+void HelpIndex::setDocListFile(const QString & f)
{
- docListFile = f;
+ docListFile = f;
}
-void HelpIndex::setDocList( const QStringList &lst )
+void HelpIndex::setDocList(const QStringList & lst)
{
- docList = lst;
+ docList = lst;
}
void HelpIndex::makeIndex()
{
- if ( !alreadyHaveDocList )
+ if(!alreadyHaveDocList)
setupDocumentList();
lastWindowClosed = false;
- emit indexingStart( docList.count() );
+ emit indexingStart(docList.count());
dict.clear();
m_iCurItem = 0;
m_pTimer->start(); //singleshot
@@ -139,465 +140,525 @@ void HelpIndex::filterNext()
if(m_iCurItem < docList.count() && !lastWindowClosed)
{
QUrl url(docList.at(m_iCurItem));
- parseDocument( url.toLocalFile(), m_iCurItem );
- emit indexingProgress( m_iCurItem );
+ parseDocument(url.toLocalFile(), m_iCurItem);
+ emit indexingProgress(m_iCurItem);
m_iCurItem++;
m_pTimer->start(); //singleshot
- } else {
+ }
+ else
+ {
emit indexingEnd();
}
}
void HelpIndex::setupDocumentList()
{
- docList.clear();
- titleList.clear();
- QDir d( docPath );
- QStringList filters;
- filters.append(QLatin1String("*.html"));
- QStringList lst = d.entryList(filters);
- QStringList::ConstIterator it = lst.constBegin();
- for ( ; it != lst.constEnd(); ++it )
- {
- QString filename=QLatin1String("file:///") + docPath + QLatin1String("/") + *it ;
- docList.append(filename);
- titleList.append(getDocumentTitle(filename));
- }
+ docList.clear();
+ titleList.clear();
+ QDir d(docPath);
+ QStringList filters;
+ filters.append(QLatin1String("*.html"));
+ QStringList lst = d.entryList(filters);
+ QStringList::ConstIterator it = lst.constBegin();
+ for(; it != lst.constEnd(); ++it)
+ {
+ QString filename = QLatin1String("file:///") + docPath + QLatin1String("/") + *it;
+ docList.append(filename);
+ titleList.append(getDocumentTitle(filename));
+ }
}
-void HelpIndex::insertInDict( const QString &str, int docNum )
+void HelpIndex::insertInDict(const QString & str, int docNum)
{
- if ( str == QLatin1String("amp") || str == QLatin1String("nbsp"))
- return;
- Entry *e = 0;
- if ( dict.count() )
- e = dict[ str ];
+ if(str == QLatin1String("amp") || str == QLatin1String("nbsp"))
+ return;
+ Entry * e = 0;
+ if(dict.count())
+ e = dict[str];
- if ( e ) {
- if ( e->documents.last().docNumber != docNum )
- e->documents.append( Document(docNum, 1 ) );
- else
- e->documents.last().frequency++;
- } else {
- dict.insert( str, new Entry( docNum ) );
- }
+ if(e)
+ {
+ if(e->documents.last().docNumber != docNum)
+ e->documents.append(Document(docNum, 1));
+ else
+ e->documents.last().frequency++;
+ }
+ else
+ {
+ dict.insert(str, new Entry(docNum));
+ }
}
-QString HelpIndex::getCharsetForDocument(QFile *file)
+QString HelpIndex::getCharsetForDocument(QFile * file)
{
- QTextStream s(file);
- QString contents = s.readAll();
+ QTextStream s(file);
+ QString contents = s.readAll();
- QString encoding;
- int start = contents.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive);
- if (start > 0) {
- int end = contents.indexOf(QLatin1String(">"), start);
- QString meta = contents.mid(start+5, end-start);
- meta = meta.toLower();
- QRegExp r(QLatin1String("charset=([^\"\\s]+)"));
- if (r.indexIn(meta) != -1) {
- encoding = r.cap(1);
- }
- }
+ QString encoding;
+ int start = contents.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive);
+ if(start > 0)
+ {
+ int end = contents.indexOf(QLatin1String(">"), start);
+ QString meta = contents.mid(start + 5, end - start);
+ meta = meta.toLower();
+ QRegExp r(QLatin1String("charset=([^\"\\s]+)"));
+ if(r.indexIn(meta) != -1)
+ {
+ encoding = r.cap(1);
+ }
+ }
- file->seek(0);
- if (encoding.isEmpty())
- return QLatin1String("utf-8");
- return encoding;
+ file->seek(0);
+ if(encoding.isEmpty())
+ return QLatin1String("utf-8");
+ return encoding;
}
-void HelpIndex::parseDocument( const QString &filename, int docNum )
+void HelpIndex::parseDocument(const QString & filename, int docNum)
{
- QFile file( filename );
- if ( !file.open(QFile::ReadOnly) ) {
- qWarning( "Can't open file %s", qPrintable(filename) );
- return;
- }
+ QFile file(filename);
+ if(!file.open(QFile::ReadOnly))
+ {
+ qWarning("Can't open file %s", qPrintable(filename));
+ return;
+ }
- QTextStream s(&file);
- QString en = getCharsetForDocument(&file);
- s.setCodec(QTextCodec::codecForName(en.toLatin1().constData()));
+ QTextStream s(&file);
+ QString en = getCharsetForDocument(&file);
+ s.setCodec(QTextCodec::codecForName(en.toLatin1().constData()));
- QString text = s.readAll();
- if (text.isNull())
- return;
+ QString text = s.readAll();
+ 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 ( j < text.length() ) {
- if ( c == QLatin1Char('<') || c == QLatin1Char('&') ) {
- valid = false;
- if ( i > 1 )
- insertInDict( QString(str,i), docNum );
- i = 0;
- c = buf[++j];
- continue;
- }
- if ( ( c == QLatin1Char('>') || c == QLatin1Char(';') ) && !valid ) {
- valid = true;
- c = buf[++j];
- continue;
- }
- if ( !valid ) {
- c = buf[++j];
- continue;
- }
- if ( ( c.isLetterOrNumber() || c == QLatin1Char('_') ) && i < 63 ) {
- str[i] = c.toLower();
- ++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();
+ bool valid = true;
+ const QChar * buf = text.unicode();
+ QChar str[64];
+ QChar c = buf[0];
+ int j = 0;
+ int i = 0;
+ while(j < text.length())
+ {
+ if(c == QLatin1Char('<') || c == QLatin1Char('&'))
+ {
+ valid = false;
+ if(i > 1)
+ insertInDict(QString(str, i), docNum);
+ i = 0;
+ c = buf[++j];
+ continue;
+ }
+ if((c == QLatin1Char('>') || c == QLatin1Char(';')) && !valid)
+ {
+ valid = true;
+ c = buf[++j];
+ continue;
+ }
+ if(!valid)
+ {
+ c = buf[++j];
+ continue;
+ }
+ if((c.isLetterOrNumber() || c == QLatin1Char('_')) && i < 63)
+ {
+ str[i] = c.toLower();
+ ++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 HelpIndex::writeDict()
{
- QFile f( dictFile );
- qDebug ("Write dict to %s",f.fileName().toUtf8().data());
- if ( !f.open(QFile::WriteOnly ) )
- return;
- QDataStream s( &f );
- for(QHash<QString, Entry *>::Iterator it = dict.begin(); it != dict.end(); ++it) {
- s << it.key();
- s << it.value()->documents.count();
- s << it.value()->documents;
- }
- f.close();
- writeDocumentList();
+ QFile f(dictFile);
+ qDebug("Write dict to %s", f.fileName().toUtf8().data());
+ if(!f.open(QFile::WriteOnly))
+ return;
+ QDataStream s(&f);
+ for(QHash<QString, Entry *>::Iterator it = dict.begin(); it != dict.end(); ++it)
+ {
+ s << it.key();
+ s << it.value()->documents.count();
+ s << it.value()->documents;
+ }
+ f.close();
+ writeDocumentList();
}
void HelpIndex::writeDocumentList()
{
- QFile f( docListFile );
- if ( !f.open(QFile::WriteOnly ) )
- return;
- QDataStream s( &f );
- s << docList;
-
- QFile f1( docListFile+".titles" );
- if ( !f1.open(QFile::WriteOnly ) )
- return;
- QDataStream s1( &f1 );
- s1 << titleList;
+ QFile f(docListFile);
+ if(!f.open(QFile::WriteOnly))
+ return;
+ QDataStream s(&f);
+ s << docList;
+ QFile f1(docListFile + ".titles");
+ if(!f1.open(QFile::WriteOnly))
+ return;
+ QDataStream s1(&f1);
+ s1 << titleList;
}
void HelpIndex::readDict()
{
- QFile f( dictFile );
- if ( !f.open(QFile::ReadOnly ) )
- return;
+ QFile f(dictFile);
+ if(!f.open(QFile::ReadOnly))
+ return;
- dict.clear();
- QDataStream s( &f );
- QString key;
- int numOfDocs;
- QVector<Document> docs;
- while ( !s.atEnd() ) {
- s >> key;
- s >> numOfDocs;
- docs.resize(numOfDocs);
- s >> docs;
- dict.insert( key, new Entry( docs ) );
- }
- f.close();
- readDocumentList();
+ dict.clear();
+ QDataStream s(&f);
+ QString key;
+ int numOfDocs;
+ QVector<Document> docs;
+ while(!s.atEnd())
+ {
+ s >> key;
+ s >> numOfDocs;
+ docs.resize(numOfDocs);
+ s >> docs;
+ dict.insert(key, new Entry(docs));
+ }
+ f.close();
+ readDocumentList();
}
void HelpIndex::readDocumentList()
{
- QFile f( docListFile );
- if ( !f.open(QFile::ReadOnly ) )
- return;
- QDataStream s( &f );
- s >> docList;
- QFile f1( docListFile+".titles" );
- if ( !f1.open(QFile::ReadOnly ) )
- return;
- QDataStream s1( &f1 );
- s1 >> titleList;
+ QFile f(docListFile);
+ if(!f.open(QFile::ReadOnly))
+ return;
+ QDataStream s(&f);
+ s >> docList;
+ QFile f1(docListFile + ".titles");
+ if(!f1.open(QFile::ReadOnly))
+ return;
+ QDataStream s1(&f1);
+ s1 >> titleList;
}
-QStringList HelpIndex::query( const QStringList &terms, const QStringList &termSeq, const QStringList &seqWords )
+QStringList HelpIndex::query(const QStringList & terms, const QStringList & termSeq, const QStringList & seqWords)
{
- QList<Term> termList;
- for (QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it ) {
- Entry *e = 0;
- if ( (*it).contains(QLatin1Char('*')) ) {
- QVector<Document> wcts = setupDummyTerm( getWildcardTerms( *it ) );
- termList.append( Term(QLatin1String("dummy"), wcts.count(), wcts ) );
- } else if ( dict[ *it ] ) {
- e = dict[ *it ];
- termList.append( Term( *it, e->documents.count(), e->documents ) );
- } else {
- return QStringList();
- }
- }
- if ( !termList.count() )
- return QStringList();
- qSort(termList);
+ QList<Term> termList;
+ for(QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it)
+ {
+ Entry * e = 0;
+ if((*it).contains(QLatin1Char('*')))
+ {
+ QVector<Document> wcts = setupDummyTerm(getWildcardTerms(*it));
+ termList.append(Term(QLatin1String("dummy"), wcts.count(), wcts));
+ }
+ else if(dict[*it])
+ {
+ e = dict[*it];
+ termList.append(Term(*it, e->documents.count(), e->documents));
+ }
+ else
+ {
+ return QStringList();
+ }
+ }
+ if(!termList.count())
+ return QStringList();
+ qSort(termList);
- QVector<Document> minDocs = termList.takeFirst().documents;
- for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it) {
- Term *t = &(*it);
- QVector<Document> docs = t->documents;
- for(QVector<Document>::Iterator minDoc_it = minDocs.begin(); minDoc_it != minDocs.end(); ) {
- bool found = false;
- for (QVector<Document>::ConstIterator doc_it = docs.constBegin(); doc_it != docs.constEnd(); ++doc_it ) {
- if ( (*minDoc_it).docNumber == (*doc_it).docNumber ) {
- (*minDoc_it).frequency += (*doc_it).frequency;
- found = true;
- break;
- }
- }
- if ( !found )
- minDoc_it = minDocs.erase( minDoc_it );
- else
- ++minDoc_it;
- }
- }
+ QVector<Document> minDocs = termList.takeFirst().documents;
+ for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it)
+ {
+ Term * t = &(*it);
+ QVector<Document> docs = t->documents;
+ for(QVector<Document>::Iterator minDoc_it = minDocs.begin(); minDoc_it != minDocs.end();)
+ {
+ bool found = false;
+ for(QVector<Document>::ConstIterator doc_it = docs.constBegin(); doc_it != docs.constEnd(); ++doc_it)
+ {
+ if((*minDoc_it).docNumber == (*doc_it).docNumber)
+ {
+ (*minDoc_it).frequency += (*doc_it).frequency;
+ found = true;
+ break;
+ }
+ }
+ if(!found)
+ minDoc_it = minDocs.erase(minDoc_it);
+ else
+ ++minDoc_it;
+ }
+ }
- QStringList results;
- qSort( minDocs );
- if ( termSeq.isEmpty() ) {
- for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it)
- results << docList.at((int)(*it).docNumber);
- return results;
- }
+ QStringList results;
+ qSort(minDocs);
+ if(termSeq.isEmpty())
+ {
+ for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it)
+ results << docList.at((int)(*it).docNumber);
+ return results;
+ }
- QString fileName;
- for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it) {
- fileName = docList[ (int)(*it).docNumber ];
- if ( searchForPattern( termSeq, seqWords, fileName ) )
- results << fileName;
- }
- return results;
+ QString fileName;
+ for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it)
+ {
+ fileName = docList[(int)(*it).docNumber];
+ if(searchForPattern(termSeq, seqWords, fileName))
+ results << fileName;
+ }
+ return results;
}
-QString HelpIndex::getDocumentTitle( const QString &fullFileName )
+QString HelpIndex::getDocumentTitle(const QString & fullFileName)
{
- QUrl url(fullFileName);
- QString fileName = url.toLocalFile();
+ QUrl url(fullFileName);
+ QString fileName = url.toLocalFile();
- if (documentTitleCache.contains(fileName))
- return documentTitleCache.value(fileName);
+ if(documentTitleCache.contains(fileName))
+ return documentTitleCache.value(fileName);
- QFile file( fileName );
- if ( !file.open( QFile::ReadOnly ) ) {
- qWarning( "Can't open file %s", qPrintable(fileName) );
- return fileName;
- }
- QTextStream s( &file );
- QString text = s.readAll();
+ QFile file(fileName);
+ if(!file.open(QFile::ReadOnly))
+ {
+ qWarning("Can't open file %s", qPrintable(fileName));
+ return fileName;
+ }
+ QTextStream s(&file);
+ QString text = s.readAll();
- int start = text.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7;
- int end = text.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive);
+ int start = text.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7;
+ int end = text.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive);
- QString title = tr("Untitled");
- if (end - start > 0) {
- title = text.mid(start, end - start);
- if (Qt::mightBeRichText(title)) {
- QTextDocument doc;
- doc.setHtml(title);
- title = doc.toPlainText();
- }
- }
- documentTitleCache.insert(fileName, title);
- return title;
+ QString title = tr("Untitled");
+ if(end - start > 0)
+ {
+ title = text.mid(start, end - start);
+ if(Qt::mightBeRichText(title))
+ {
+ QTextDocument doc;
+ doc.setHtml(title);
+ title = doc.toPlainText();
+ }
+ }
+ documentTitleCache.insert(fileName, title);
+ return title;
}
-QStringList HelpIndex::getWildcardTerms( const QString &term )
+QStringList HelpIndex::getWildcardTerms(const QString & term)
{
- QStringList lst;
- QStringList terms = split( term );
- QStringList::Iterator iter;
+ QStringList lst;
+ QStringList terms = split(term);
+ QStringList::Iterator iter;
- for(QHash<QString, Entry*>::Iterator it = dict.begin(); it != dict.end(); ++it) {
- int index = 0;
- bool found = false;
- QString text( it.key() );
- for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
- if ( *iter == QLatin1String("*") ) {
- found = true;
- continue;
- }
- if ( iter == terms.begin() && (*iter)[0] != text[0] ) {
- found = false;
- break;
- }
- index = text.indexOf( *iter, index );
- if ( *iter == terms.last() && index != (int)text.length()-1 ) {
- index = text.lastIndexOf( *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;
- }
+ for(QHash<QString, Entry *>::Iterator it = dict.begin(); it != dict.end(); ++it)
+ {
+ int index = 0;
+ bool found = false;
+ QString text(it.key());
+ for(iter = terms.begin(); iter != terms.end(); ++iter)
+ {
+ if(*iter == QLatin1String("*"))
+ {
+ found = true;
+ continue;
+ }
+ if(iter == terms.begin() && (*iter)[0] != text[0])
+ {
+ found = false;
+ break;
+ }
+ index = text.indexOf(*iter, index);
+ if(*iter == terms.last() && index != (int)text.length() - 1)
+ {
+ index = text.lastIndexOf(*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;
+ return lst;
}
-QStringList HelpIndex::split( const QString &str )
+QStringList HelpIndex::split(const QString & str)
{
- QStringList lst;
- int j = 0;
- int i = str.indexOf(QLatin1Char('*'), j );
+ QStringList lst;
+ int j = 0;
+ int i = str.indexOf(QLatin1Char('*'), j);
- if (str.startsWith(QLatin1String("*")))
- lst << QLatin1String("*");
+ if(str.startsWith(QLatin1String("*")))
+ lst << QLatin1String("*");
- while ( i != -1 ) {
- if ( i > j && i <= (int)str.length() ) {
- lst << str.mid( j, i - j );
- lst << QLatin1String("*");
- }
- j = i + 1;
- i = str.indexOf(QLatin1Char('*'), j );
- }
+ while(i != -1)
+ {
+ if(i > j && i <= (int)str.length())
+ {
+ lst << str.mid(j, i - j);
+ lst << QLatin1String("*");
+ }
+ j = i + 1;
+ i = str.indexOf(QLatin1Char('*'), j);
+ }
- int l = str.length() - 1;
- if ( str.mid( j, l - j + 1 ).length() > 0 )
- lst << str.mid( j, l - j + 1 );
+ int l = str.length() - 1;
+ if(str.mid(j, l - j + 1).length() > 0)
+ lst << str.mid(j, l - j + 1);
- return lst;
+ return lst;
}
-QVector<Document> HelpIndex::setupDummyTerm( const QStringList &terms )
+QVector<Document> HelpIndex::setupDummyTerm(const QStringList & terms)
{
- QList<Term> termList;
- for (QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it) {
- Entry *e = 0;
- if ( dict[ *it ] ) {
- e = dict[ *it ];
- termList.append( Term( *it, e->documents.count(), e->documents ) );
- }
- }
- QVector<Document> maxList(0);
- if ( !termList.count() )
- return maxList;
- qSort(termList);
+ QList<Term> termList;
+ for(QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it)
+ {
+ Entry * e = 0;
+ if(dict[*it])
+ {
+ e = dict[*it];
+ termList.append(Term(*it, e->documents.count(), e->documents));
+ }
+ }
+ QVector<Document> maxList(0);
+ if(!termList.count())
+ return maxList;
+ qSort(termList);
- maxList = termList.takeLast().documents;
- for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it) {
- Term *t = &(*it);
- QVector<Document> docs = t->documents;
- for (QVector<Document>::iterator docIt = docs.begin(); docIt != docs.end(); ++docIt ) {
- if ( maxList.indexOf( *docIt ) == -1 )
- maxList.append( *docIt );
- }
- }
- return maxList;
+ maxList = termList.takeLast().documents;
+ for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it)
+ {
+ Term * t = &(*it);
+ QVector<Document> docs = t->documents;
+ for(QVector<Document>::iterator docIt = docs.begin(); docIt != docs.end(); ++docIt)
+ {
+ if(maxList.indexOf(*docIt) == -1)
+ maxList.append(*docIt);
+ }
+ }
+ return maxList;
}
-void HelpIndex::buildMiniDict( const QString &str )
+void HelpIndex::buildMiniDict(const QString & str)
{
- if ( miniDict[ str ] )
- miniDict[ str ]->positions.append( wordNum );
- ++wordNum;
+ if(miniDict[str])
+ miniDict[str]->positions.append(wordNum);
+ ++wordNum;
}
-bool HelpIndex::searchForPattern( const QStringList &patterns, const QStringList &words, const QString &fileName )
+bool HelpIndex::searchForPattern(const QStringList & patterns, const QStringList & words, const QString & fileName)
{
- QUrl url(fileName);
- QString fName = url.toLocalFile();
- QFile file( fName );
- if ( !file.open( QFile::ReadOnly ) ) {
- qWarning( "Can't open file %s", qPrintable(fName) );
- return false;
- }
+ QUrl url(fileName);
+ QString fName = url.toLocalFile();
+ QFile file(fName);
+ if(!file.open(QFile::ReadOnly))
+ {
+ qWarning("Can't open file %s", qPrintable(fName));
+ return false;
+ }
- wordNum = 3;
- miniDict.clear();
- QStringList::ConstIterator cIt = words.begin();
- for ( ; cIt != words.end(); ++cIt )
- miniDict.insert( *cIt, new PosEntry( 0 ) );
+ 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.readAll();
- bool valid = true;
- const QChar *buf = text.unicode();
- QChar str[64];
- QChar c = buf[0];
- int j = 0;
- int i = 0;
- while ( j < text.length() ) {
- if ( c == QLatin1Char('<') || c == QLatin1Char('&') ) {
- valid = false;
- if ( i > 1 )
- buildMiniDict( QString(str,i) );
- i = 0;
- c = buf[++j];
- continue;
- }
- if ( ( c == QLatin1Char('>') || c == QLatin1Char(';') ) && !valid ) {
- valid = true;
- c = buf[++j];
- continue;
- }
- if ( !valid ) {
- c = buf[++j];
- continue;
- }
- if ( ( c.isLetterOrNumber() || c == QLatin1Char('_') ) && i < 63 ) {
- str[i] = c.toLower();
- ++i;
- } else {
- if ( i > 1 )
- buildMiniDict( QString(str,i) );
- i = 0;
- }
- c = buf[++j];
- }
- if ( i > 1 )
- buildMiniDict( QString(str,i) );
- file.close();
+ QTextStream s(&file);
+ QString text = s.readAll();
+ bool valid = true;
+ const QChar * buf = text.unicode();
+ QChar str[64];
+ QChar c = buf[0];
+ int j = 0;
+ int i = 0;
+ while(j < text.length())
+ {
+ if(c == QLatin1Char('<') || c == QLatin1Char('&'))
+ {
+ valid = false;
+ if(i > 1)
+ buildMiniDict(QString(str, i));
+ i = 0;
+ c = buf[++j];
+ continue;
+ }
+ if((c == QLatin1Char('>') || c == QLatin1Char(';')) && !valid)
+ {
+ valid = true;
+ c = buf[++j];
+ continue;
+ }
+ if(!valid)
+ {
+ c = buf[++j];
+ continue;
+ }
+ if((c.isLetterOrNumber() || c == QLatin1Char('_')) && i < 63)
+ {
+ str[i] = c.toLower();
+ ++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;
- QList<uint> a, b;
- QList<uint>::iterator aIt;
- for ( ; patIt != patterns.end(); ++patIt ) {
- wordLst = (*patIt).split(QLatin1Char(' '));
- 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.contains( *aIt + 1 )) {
- (*aIt)++;
- ++aIt;
- } else {
- aIt = a.erase( aIt );
- }
- }
- }
- }
- if ( a.count() )
- return true;
- return false;
+ QStringList::ConstIterator patIt = patterns.begin();
+ QStringList wordLst;
+ QList<uint> a, b;
+ QList<uint>::iterator aIt;
+ for(; patIt != patterns.end(); ++patIt)
+ {
+ wordLst = (*patIt).split(QLatin1Char(' '));
+ 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.contains(*aIt + 1))
+ {
+ (*aIt)++;
+ ++aIt;
+ }
+ else
+ {
+ aIt = a.erase(aIt);
+ }
+ }
+ }
+ }
+ if(a.count())
+ return true;
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/modules/help/HelpIndex.h b/src/modules/help/HelpIndex.h
index effe15f8e..0a6b401f8 100644
--- a/src/modules/help/HelpIndex.h
+++ b/src/modules/help/HelpIndex.h
@@ -50,88 +50,96 @@ class QTimer;
QT_BEGIN_NAMESPACE
-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;
- }
- qint16 docNumber;
- qint16 frequency;
+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;
+ }
+ qint16 docNumber;
+ qint16 frequency;
};
-QDataStream &operator>>( QDataStream &s, Document &l );
-QDataStream &operator<<( QDataStream &s, const Document &l );
+QDataStream & operator>>(QDataStream & s, Document & l);
+QDataStream & operator<<(QDataStream & s, const Document & l);
class HelpIndex : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
- struct Entry {
- Entry( int d ) { documents.append( Document( d, 1 ) ); }
- Entry( QVector<Document> l ) : documents( l ) {}
- QVector<Document> documents;
- };
- struct PosEntry {
- PosEntry( int p ) { positions.append( p ); }
- QList<uint> positions;
- };
+ struct Entry
+ {
+ Entry(int d) { documents.append(Document(d, 1)); }
+ Entry(QVector<Document> l) : documents(l) {}
+ QVector<Document> documents;
+ };
+ struct PosEntry
+ {
+ PosEntry(int p) { positions.append(p); }
+ QList<uint> positions;
+ };
- HelpIndex( const QString &dp, const QString &hp );
- HelpIndex( const QStringList &dl, const QString &hp );
- void writeDict();
- void readDict();
- void makeIndex();
- QStringList query( const QStringList&, const QStringList&, const QStringList& );
- QString getDocumentTitle( const QString& );
- void setDictionaryFile( const QString& );
- void setDocListFile( const QString& );
- void setDocList( const QStringList & );
+ HelpIndex(const QString & dp, const QString & hp);
+ HelpIndex(const QStringList & dl, const QString & hp);
+ void writeDict();
+ void readDict();
+ void makeIndex();
+ QStringList query(const QStringList &, const QStringList &, const QStringList &);
+ QString getDocumentTitle(const QString &);
+ void setDictionaryFile(const QString &);
+ void setDocListFile(const QString &);
+ void setDocList(const QStringList &);
- const QStringList& documentList() { return docList; };
- const QStringList& titlesList() { return titleList; };
+ const QStringList & documentList() { return docList; };
+ const QStringList & titlesList() { return titleList; };
signals:
- void indexingStart( int );
- void indexingProgress( int );
- void indexingEnd();
+ void indexingStart(int);
+ void indexingProgress(int);
+ void indexingEnd();
private slots:
- void setLastWinClosed();
+ void setLastWinClosed();
void filterNext();
+
private:
- void setupDocumentList();
- void parseDocument( const QString&, int );
- void insertInDict( const QString&, int );
- void writeDocumentList();
- void readDocumentList();
- QStringList getWildcardTerms( const QString& );
- QStringList split( const QString& );
- QVector<Document> setupDummyTerm( const QStringList& );
- bool searchForPattern( const QStringList&, const QStringList&, const QString& );
- void buildMiniDict( const QString& );
- QString getCharsetForDocument(QFile *);
- QStringList docList;
- QStringList titleList;
- QHash<QString, Entry*> dict;
- QHash<QString, PosEntry*> miniDict;
- uint wordNum;
- QString docPath;
- QString dictFile, docListFile;
- bool alreadyHaveDocList;
- bool lastWindowClosed;
- QHash<QString, QString> documentTitleCache;
- QTimer * m_pTimer;
- int m_iCurItem;
+ void setupDocumentList();
+ void parseDocument(const QString &, int);
+ void insertInDict(const QString &, int);
+ void writeDocumentList();
+ void readDocumentList();
+ QStringList getWildcardTerms(const QString &);
+ QStringList split(const QString &);
+ QVector<Document> setupDummyTerm(const QStringList &);
+ bool searchForPattern(const QStringList &, const QStringList &, const QString &);
+ void buildMiniDict(const QString &);
+ QString getCharsetForDocument(QFile *);
+ QStringList docList;
+ QStringList titleList;
+ QHash<QString, Entry *> dict;
+ QHash<QString, PosEntry *> miniDict;
+ uint wordNum;
+ QString docPath;
+ QString dictFile, docListFile;
+ bool alreadyHaveDocList;
+ bool lastWindowClosed;
+ QHash<QString, QString> documentTitleCache;
+ QTimer * m_pTimer;
+ int m_iCurItem;
};
#endif
diff --git a/src/modules/help/HelpWidget.cpp b/src/modules/help/HelpWidget.cpp
index f09ff7f8c..bdf6ec329 100644
--- a/src/modules/help/HelpWidget.cpp
+++ b/src/modules/help/HelpWidget.cpp
@@ -40,7 +40,7 @@
#include <QClipboard>
#include <QDir>
-extern HelpIndex * g_pDocIndex;
+extern HelpIndex * g_pDocIndex;
extern KviPointerList<HelpWindow> * g_pHelpWindowList;
extern KviPointerList<HelpWidget> * g_pHelpWidgetList;
@@ -51,15 +51,16 @@ extern KviPointerList<HelpWidget> * g_pHelpWidgetList;
#define HIGHLIGHT_FLAGS QWebPage::HighlightAllOccurrences
HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
-: QWidget(par)
+ : QWidget(par)
{
setObjectName("help_widget");
setMinimumWidth(80);
- if(bIsStandalone)g_pHelpWidgetList->append(this);
+ if(bIsStandalone)
+ g_pHelpWidgetList->append(this);
m_bIsStandalone = bIsStandalone;
- new QShortcut(QKeySequence::Copy,this,SLOT(slotCopy()),0,Qt::WidgetWithChildrenShortcut);
- new QShortcut(QKeySequence::Find,this,SLOT(slotShowHideFind()),0, bIsStandalone ? Qt::WidgetWithChildrenShortcut : Qt::WindowShortcut);
+ new QShortcut(QKeySequence::Copy, this, SLOT(slotCopy()), 0, Qt::WidgetWithChildrenShortcut);
+ new QShortcut(QKeySequence::Find, this, SLOT(slotShowHideFind()), 0, bIsStandalone ? Qt::WidgetWithChildrenShortcut : Qt::WindowShortcut);
// layout
m_pLayout = new QVBoxLayout(this);
@@ -76,33 +77,33 @@ HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
m_pTextBrowser->setObjectName("text_browser");
m_pTextBrowser->setStyleSheet("QTextBrowser { background-color:white; color:black; }");
m_pLayout->addWidget(m_pTextBrowser);
- connect(m_pTextBrowser,SIGNAL(loadFinished(bool)),this,SLOT(slotLoadFinished(bool)));
+ connect(m_pTextBrowser, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
// lower toolbar
m_pToolBarHighlight = new QToolBar(this);
m_pLayout->addWidget(m_pToolBarHighlight);
m_pToolBarHighlight->hide();
- QLabel *pHighlightLabel = new QLabel();
+ QLabel * pHighlightLabel = new QLabel();
pHighlightLabel->setText(__tr2qs("Highlight: "));
m_pToolBarHighlight->addWidget(pHighlightLabel);
m_pFindText = new QLineEdit();
m_pToolBarHighlight->addWidget(m_pFindText);
- connect(m_pFindText,SIGNAL(textChanged(const QString )),this,SLOT(slotTextChanged(const QString)));
+ connect(m_pFindText, SIGNAL(textChanged(const QString)), this, SLOT(slotTextChanged(const QString)));
m_pToolBarHighlight->addAction(*g_pIconManager->getSmallIcon(KviIconManager::Discard), __tr2qs("Reset"), this, SLOT(slotResetFind()));
m_pToolBarHighlight->addAction(*g_pIconManager->getSmallIcon(KviIconManager::Part), __tr2qs("Find previous"), this, SLOT(slotFindPrev()));
m_pToolBarHighlight->addAction(*g_pIconManager->getSmallIcon(KviIconManager::Join), __tr2qs("Find next"), this, SLOT(slotFindNext()));
// upper toolbar contents (depends on webview)
- QLabel *pBrowsingLabel = new QLabel();
+ QLabel * pBrowsingLabel = new QLabel();
pBrowsingLabel->setText(__tr2qs("Browsing: "));
m_pToolBar->addWidget(pBrowsingLabel);
m_pToolBar->addAction(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPINDEX), __tr2qs("Show index"), this, SLOT(showIndex()));
- QAction *pAction;
+ QAction * pAction;
pAction = m_pTextBrowser->pageAction(QWebPage::Back);
pAction->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPBACK));
m_pToolBar->addAction(pAction);
@@ -118,7 +119,6 @@ HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
setAttribute(Qt::WA_DeleteOnClose);
m_pToolBar->addAction(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPCLOSE), __tr2qs("Close"), this, SLOT(close()));
}
-
}
void HelpWidget::slotCopy()
@@ -131,32 +131,34 @@ void HelpWidget::slotShowHideFind()
if(m_pToolBarHighlight->isVisible())
{
m_pToolBarHighlight->hide();
- } else {
+ }
+ else
+ {
m_pToolBarHighlight->show();
m_pFindText->setFocus();
}
}
-void HelpWidget::slotLoadFinished(bool )
+void HelpWidget::slotLoadFinished(bool)
{
- m_pTextBrowser->findText(m_pFindText->text(),HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText(m_pFindText->text(), HIGHLIGHT_FLAGS);
}
void HelpWidget::slotTextChanged(const QString szFind)
{
- m_pTextBrowser->findText("",HIGHLIGHT_FLAGS);
- m_pTextBrowser->findText(szFind,HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText("", HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText(szFind, HIGHLIGHT_FLAGS);
}
void HelpWidget::slotResetFind()
{
m_pFindText->setText("");
- m_pTextBrowser->findText("",HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText("", HIGHLIGHT_FLAGS);
}
void HelpWidget::slotFindPrev()
{
- m_pTextBrowser->findText(m_pFindText->text(),QWebPage::FindBackward);
+ m_pTextBrowser->findText(m_pFindText->text(), QWebPage::FindBackward);
}
void HelpWidget::slotFindNext()
@@ -165,98 +167,104 @@ void HelpWidget::slotFindNext()
}
void HelpWidget::slotZoomIn()
{
- kvs_real_t dZoom=m_pTextBrowser->zoomFactor();
- if(dZoom>=2) return;
- dZoom+= 0.05;
+ kvs_real_t dZoom = m_pTextBrowser->zoomFactor();
+ if(dZoom >= 2)
+ return;
+ dZoom += 0.05;
m_pTextBrowser->setZoomFactor(dZoom);
}
void HelpWidget::slotZoomOut()
{
- kvs_real_t dZoom=m_pTextBrowser->zoomFactor();
- if(dZoom<=0.5) return;
- dZoom-= 0.05;
+ kvs_real_t dZoom = m_pTextBrowser->zoomFactor();
+ if(dZoom <= 0.5)
+ return;
+ dZoom -= 0.05;
m_pTextBrowser->setZoomFactor(dZoom);
}
#else
HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
-: QWidget(par)
+ : QWidget(par)
{
setObjectName("help_widget");
setMinimumWidth(80);
- if(bIsStandalone)g_pHelpWidgetList->append(this);
+ if(bIsStandalone)
+ g_pHelpWidgetList->append(this);
m_bIsStandalone = bIsStandalone;
m_pTextBrowser = new QTextBrowser(this);
m_pTextBrowser->setObjectName("text_browser");
- m_pTextBrowser->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken);
+ m_pTextBrowser->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
m_pTextBrowser->setStyleSheet("QTextBrowser { background-color:white; color:black; }");
m_pToolBar = new KviTalHBox(this);
m_pBtnIndex = new QToolButton(m_pToolBar);
m_pBtnIndex->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPINDEX));
- connect(m_pBtnIndex,SIGNAL(clicked()),this,SLOT(showIndex()));
+ connect(m_pBtnIndex, SIGNAL(clicked()), this, SLOT(showIndex()));
m_pBtnBackward = new QToolButton(m_pToolBar);
m_pBtnBackward->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPBACK));
- connect(m_pBtnBackward,SIGNAL(clicked()),m_pTextBrowser,SLOT(backward()));
+ connect(m_pBtnBackward, SIGNAL(clicked()), m_pTextBrowser, SLOT(backward()));
m_pBtnBackward->setEnabled(false);
m_pBtnForward = new QToolButton(m_pToolBar);
m_pBtnForward->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPFORWARD));
- connect(m_pBtnForward,SIGNAL(clicked()),m_pTextBrowser,SLOT(forward()));
+ connect(m_pBtnForward, SIGNAL(clicked()), m_pTextBrowser, SLOT(forward()));
m_pBtnForward->setEnabled(false);
- QWidget* pSpacer=new QWidget(m_pToolBar);
+ QWidget * pSpacer = new QWidget(m_pToolBar);
if(bIsStandalone)
{
setAttribute(Qt::WA_DeleteOnClose);
QToolButton * b = new QToolButton(m_pToolBar);
b->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPCLOSE));
- connect(b,SIGNAL(clicked()),this,SLOT(close()));
+ connect(b, SIGNAL(clicked()), this, SLOT(close()));
}
- 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_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)));
}
#endif
HelpWidget::~HelpWidget()
{
- if(m_bIsStandalone)g_pHelpWidgetList->removeRef(this);
+ if(m_bIsStandalone)
+ g_pHelpWidgetList->removeRef(this);
}
void HelpWidget::showIndex()
{
QString szHelpDir;
- QDir dirHelp;
+ QDir dirHelp;
- g_pApp->getGlobalKvircDirectory(szHelpDir,KviApplication::Help);
- dirHelp = QDir(szHelpDir);
- #ifdef COMPILE_WEBKIT_SUPPORT
+ g_pApp->getGlobalKvircDirectory(szHelpDir, KviApplication::Help);
+ dirHelp = QDir(szHelpDir);
+#ifdef COMPILE_WEBKIT_SUPPORT
m_pTextBrowser->load(QUrl::fromLocalFile(dirHelp.absoluteFilePath("index.html")));
- #else
+#else
m_pTextBrowser->setSource(QUrl::fromLocalFile(dirHelp.absoluteFilePath("index.html")));
- #endif
+#endif
}
void HelpWidget::resizeEvent(QResizeEvent *)
{
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);
+ if(hght < 40)
+ hght = 40;
+ m_pToolBar->setGeometry(0, 0, width(), hght);
+ m_pTextBrowser->setGeometry(0, hght, width(), height() - hght);
}
QSize HelpWidget::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());
+ if(m_pToolBar->sizeHint().width() > wdth)
+ wdth = m_pToolBar->sizeHint().width();
+ QSize s(wdth, m_pTextBrowser->sizeHint().height() + m_pToolBar->sizeHint().height());
return s;
}
diff --git a/src/modules/help/HelpWidget.h b/src/modules/help/HelpWidget.h
index 79a3d78fa..9e73989dc 100644
--- a/src/modules/help/HelpWidget.h
+++ b/src/modules/help/HelpWidget.h
@@ -28,12 +28,12 @@
#include "kvi_settings.h"
#ifdef COMPILE_WEBKIT_SUPPORT
- #include <QtWebKitWidgets/QWebView>
- #include <QToolBar>
- #include <QVBoxLayout>
+#include <QtWebKitWidgets/QWebView>
+#include <QToolBar>
+#include <QVBoxLayout>
#else
- #include "KviTalHBox.h"
- #include <QTextBrowser>
+#include "KviTalHBox.h"
+#include <QTextBrowser>
#endif
#include <QProgressBar>
@@ -45,25 +45,27 @@ class HelpWidget : public QWidget
{
Q_OBJECT
public:
- HelpWidget(QWidget *par, bool bIsStandalone = false);
+ HelpWidget(QWidget * par, bool bIsStandalone = false);
~HelpWidget();
+
private:
#ifdef COMPILE_WEBKIT_SUPPORT
- QToolBar * m_pToolBar;
- QToolBar * m_pToolBarHighlight;
- QLineEdit * m_pFindText;
- QVBoxLayout * m_pLayout;
- QWebView * m_pTextBrowser;
+ QToolBar * m_pToolBar;
+ QToolBar * m_pToolBarHighlight;
+ QLineEdit * m_pFindText;
+ QVBoxLayout * m_pLayout;
+ QWebView * m_pTextBrowser;
#else
- QToolButton * m_pBtnIndex;
- QToolButton * m_pBtnBackward;
- QToolButton * m_pBtnForward;
- KviTalHBox * m_pToolBar;
+ QToolButton * m_pBtnIndex;
+ QToolButton * m_pBtnBackward;
+ QToolButton * m_pBtnForward;
+ KviTalHBox * m_pToolBar;
QTextBrowser * m_pTextBrowser;
#endif
- bool m_bIsStandalone;
+ bool m_bIsStandalone;
+
protected:
- virtual void resizeEvent(QResizeEvent *e);
+ virtual void resizeEvent(QResizeEvent * e);
protected slots:
void showIndex();
#ifdef COMPILE_WEBKIT_SUPPORT
@@ -79,12 +81,17 @@ protected slots:
#endif
public:
virtual QSize sizeHint() const;
- #ifdef COMPILE_WEBKIT_SUPPORT
- QWebView * textBrowser() { return m_pTextBrowser; }
- #else
- QTextBrowser * textBrowser() { return m_pTextBrowser; }
+#ifdef COMPILE_WEBKIT_SUPPORT
+ QWebView * textBrowser()
+ {
+ return m_pTextBrowser;
+ }
+#else
+ QTextBrowser * textBrowser()
+ {
+ return m_pTextBrowser;
+ }
#endif
};
-
#endif //_HELPWIDGET_H_
diff --git a/src/modules/help/HelpWindow.cpp b/src/modules/help/HelpWindow.cpp
index 47c0fe854..541ca1ca8 100644
--- a/src/modules/help/HelpWindow.cpp
+++ b/src/modules/help/HelpWindow.cpp
@@ -43,62 +43,62 @@
#include <QToolTip>
#include <QTimer>
-extern HelpIndex * g_pDocIndex;
+extern HelpIndex * g_pDocIndex;
extern KviPointerList<HelpWindow> * g_pHelpWindowList;
extern KviPointerList<HelpWidget> * g_pHelpWidgetList;
//bool g_bIndexingDone = false;
HelpWindow::HelpWindow(const char * name)
-: KviWindow(KviWindow::Help,name)
+ : KviWindow(KviWindow::Help, name)
{
g_pHelpWindowList->append(this);
- m_pSplitter = new KviTalSplitter(Qt::Horizontal,this);
+ m_pSplitter = new KviTalSplitter(Qt::Horizontal, this);
m_pSplitter->setObjectName("main_splitter");
m_pSplitter->setChildrenCollapsible(false);
m_pHelpWidget = new HelpWidget(m_pSplitter);
- m_pToolBar=new KviTalVBox(m_pSplitter);
+ m_pToolBar = new KviTalVBox(m_pSplitter);
m_pTabWidget = new QTabWidget(m_pToolBar);
m_pBottomLayout = new KviTalHBox(m_pToolBar);
m_pProgressBar = new QProgressBar(m_pBottomLayout);
m_pCancelButton = new QPushButton(m_pBottomLayout);
- m_pCancelButton->setText(__tr2qs_ctx("Cancel","logview"));
- connect(m_pCancelButton,SIGNAL(clicked()),g_pDocIndex,SLOT(setLastWinClosed()));
+ m_pCancelButton->setText(__tr2qs_ctx("Cancel", "logview"));
+ connect(m_pCancelButton, SIGNAL(clicked()), g_pDocIndex, SLOT(setLastWinClosed()));
m_pBottomLayout->setVisible(false);
- m_pIndexTab = new KviTalVBox(m_pTabWidget);
- m_pTabWidget->addTab(m_pIndexTab,__tr2qs("Help Index"));
+ m_pIndexTab = new KviTalVBox(m_pTabWidget);
+ m_pTabWidget->addTab(m_pIndexTab, __tr2qs("Help Index"));
- KviTalHBox* pSearchBox = new KviTalHBox(m_pIndexTab);
+ 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() ) );
+ connect(m_pIndexSearch, SIGNAL(textChanged(const QString &)),
+ this, SLOT(searchInIndex(const QString &)));
+ connect(m_pIndexSearch, SIGNAL(returnPressed()),
+ this, SLOT(showIndexTopic()));
m_pBtnRefreshIndex = new QPushButton(pSearchBox);
m_pBtnRefreshIndex->setIcon(*g_pIconManager->getBigIcon(KVI_REFRESH_IMAGE_NAME));
- connect(m_pBtnRefreshIndex,SIGNAL(clicked()),this,SLOT(refreshIndex()));
- m_pBtnRefreshIndex->setToolTip(__tr2qs("Refresh index") );
+ connect(m_pBtnRefreshIndex, SIGNAL(clicked()), this, SLOT(refreshIndex()));
+ m_pBtnRefreshIndex->setToolTip(__tr2qs("Refresh index"));
m_pIndexListWidget = new KviTalListWidget(m_pIndexTab);
- connect(m_pIndexListWidget,SIGNAL(itemActivated(QListWidgetItem *)),this,SLOT(indexSelected (QListWidgetItem * )));
+ connect(m_pIndexListWidget, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(indexSelected(QListWidgetItem *)));
- m_pSearchTab = new KviTalVBox(m_pTabWidget);
- m_pTabWidget->addTab(m_pSearchTab,__tr2qs("Search"));
+ m_pSearchTab = new KviTalVBox(m_pTabWidget);
+ m_pTabWidget->addTab(m_pSearchTab, __tr2qs("Search"));
m_pTermsEdit = new QLineEdit(m_pSearchTab);
- connect( m_pTermsEdit, SIGNAL( returnPressed() ),
- this, SLOT( startSearch() ) );
+ connect(m_pTermsEdit, SIGNAL(returnPressed()),
+ this, SLOT(startSearch()));
m_pResultBox = new KviTalListWidget(m_pSearchTab);
- connect(m_pResultBox,SIGNAL(itemActivated(QListWidgetItem *)),this,SLOT(searchSelected (QListWidgetItem *)));
+ connect(m_pResultBox, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(searchSelected(QListWidgetItem *)));
QList<int> li;
- li.append(width()-80);
+ li.append(width() - 80);
li.append(80);
m_pSplitter->setSizes(li);
@@ -106,7 +106,7 @@ HelpWindow::HelpWindow(const char * name)
connect(g_pDocIndex, SIGNAL(indexingProgress(int)), this, SLOT(indexingProgress(int)));
connect(g_pDocIndex, SIGNAL(indexingEnd()), this, SLOT(indexingEnd()));
- QTimer::singleShot(0,this,SLOT(initialSetup()));
+ QTimer::singleShot(0, this, SLOT(initialSetup()));
}
HelpWindow::~HelpWindow()
@@ -118,36 +118,38 @@ void HelpWindow::initialSetup()
{
m_pIndexSearch->setFocus();
-/* if(!g_bIndexingDone)
+ /* if(!g_bIndexingDone)
{
g_bIndexingDone=true;*/
- QString szDoclist,szDict;
+ QString szDoclist, szDict;
- g_pApp->getLocalKvircDirectory(szDoclist,KviApplication::Help,"help.doclist." KVI_SOURCES_DATE);
- g_pApp->getLocalKvircDirectory(szDict,KviApplication::Help,"help.dict." KVI_SOURCES_DATE);
+ g_pApp->getLocalKvircDirectory(szDoclist, KviApplication::Help, "help.doclist." KVI_SOURCES_DATE);
+ g_pApp->getLocalKvircDirectory(szDict, KviApplication::Help, "help.dict." KVI_SOURCES_DATE);
- if ( QFileInfo( szDoclist ).exists() && QFileInfo( szDict ).exists() ) {
- g_pDocIndex->readDict();
- m_pIndexListWidget->clear();
- QStringList docList=g_pDocIndex->titlesList();
- m_pIndexListWidget->addItems(docList);
- m_pIndexListWidget->sortItems();
- m_pBtnRefreshIndex->setEnabled(true);
- } else {
- g_pDocIndex->makeIndex();
-
- }
+ if(QFileInfo(szDoclist).exists() && QFileInfo(szDict).exists())
+ {
+ g_pDocIndex->readDict();
+ m_pIndexListWidget->clear();
+ QStringList docList = g_pDocIndex->titlesList();
+ m_pIndexListWidget->addItems(docList);
+ m_pIndexListWidget->sortItems();
+ m_pBtnRefreshIndex->setEnabled(true);
+ }
+ else
+ {
+ g_pDocIndex->makeIndex();
+ }
//}
}
-void HelpWindow::indexingStart( int iNum )
+void HelpWindow::indexingStart(int iNum)
{
m_pBtnRefreshIndex->setEnabled(false);
m_pBottomLayout->setVisible(true);
m_pProgressBar->setRange(0, iNum);
m_pProgressBar->setValue(0);
}
-void HelpWindow::indexingProgress( int iNum )
+void HelpWindow::indexingProgress(int iNum)
{
m_pProgressBar->setValue(iNum);
}
@@ -158,25 +160,25 @@ void HelpWindow::indexingEnd()
m_pBottomLayout->setVisible(false);
g_pDocIndex->writeDict();
m_pIndexListWidget->clear();
- QStringList docList=g_pDocIndex->titlesList();
+ QStringList docList = g_pDocIndex->titlesList();
m_pIndexListWidget->addItems(docList);
m_pIndexListWidget->sortItems();
m_pBtnRefreshIndex->setEnabled(true);
}
-void HelpWindow::saveProperties(KviConfigurationFile *cfg)
+void HelpWindow::saveProperties(KviConfigurationFile * cfg)
{
KviWindow::saveProperties(cfg);
- cfg->writeEntry("Splitter",m_pSplitter->sizes());
+ cfg->writeEntry("Splitter", m_pSplitter->sizes());
}
-void HelpWindow::loadProperties(KviConfigurationFile *cfg)
+void HelpWindow::loadProperties(KviConfigurationFile * cfg)
{
QList<int> def;
int w = width();
def.append((w * 82) / 100);
def.append((w * 18) / 100);
- m_pSplitter->setSizes(cfg->readIntListEntry("Splitter",def));
+ m_pSplitter->setSizes(cfg->readIntListEntry("Splitter", def));
KviWindow::loadProperties(cfg);
}
@@ -188,79 +190,91 @@ void HelpWindow::refreshIndex()
void HelpWindow::startSearch()
{
QString str = m_pTermsEdit->text();
- str = str.replace( "\'", "\"" );
- str = str.replace( "`", "\"" );
+ str = str.replace("\'", "\"");
+ str = str.replace("`", "\"");
QString buf = str;
- str = str.replace( "-", " " );
- str = str.replace( QRegExp( "\\s[\\S]?\\s" ), " " );
- m_terms = str.split(" ",QString::SkipEmptyParts);
+ str = str.replace("-", " ");
+ str = str.replace(QRegExp("\\s[\\S]?\\s"), " ");
+ m_terms = str.split(" ", QString::SkipEmptyParts);
QStringList termSeq;
QStringList seqWords;
QStringList::iterator it = m_terms.begin();
- for ( ; it != m_terms.end(); ++it ) {
+ for(; it != m_terms.end(); ++it)
+ {
(*it) = (*it).simplified();
(*it) = (*it).toLower();
- (*it) = (*it).replace( "\"", "" );
+ (*it) = (*it).replace("\"", "");
}
- if ( str.contains( '\"' ) ) {
- if ( (str.count( '\"' ))%2 == 0 ) {
+ if(str.contains('\"'))
+ {
+ if((str.count('\"')) % 2 == 0)
+ {
int beg = 0;
int end = 0;
QString s;
- beg = str.indexOf( '\"', beg );
- while ( beg != -1 ) {
+ beg = str.indexOf('\"', beg);
+ while(beg != -1)
+ {
beg++;
- end = str.indexOf( '\"', beg );
- s = str.mid( beg, end - beg );
+ end = str.indexOf('\"', beg);
+ s = str.mid(beg, end - beg);
s = s.toLower();
s = s.simplified();
- if ( s.contains( '*' ) ) {
- QMessageBox::warning( this, tr( "Full Text Search - KVIrc" ),
- tr( "Using a wildcard within phrases is not allowed." ) );
- return;
+ if(s.contains('*'))
+ {
+ QMessageBox::warning(this, tr("Full Text Search - KVIrc"),
+ tr("Using a wildcard within phrases is not allowed."));
+ return;
}
- seqWords += s.split( ' ', QString::SkipEmptyParts );
+ seqWords += s.split(' ', QString::SkipEmptyParts);
termSeq << s;
- beg = str.indexOf( '\"', end + 1);
+ beg = str.indexOf('\"', end + 1);
}
- } else {
- QMessageBox::warning( this, tr( "Full Text Search - KVIrc" ),
- tr( "The closing quotation mark is missing." ) );
+ }
+ else
+ {
+ QMessageBox::warning(this, tr("Full Text Search - KVIrc"),
+ tr("The closing quotation mark is missing."));
return;
}
}
- setCursor( Qt::WaitCursor );
+ setCursor(Qt::WaitCursor);
m_foundDocs.clear();
- m_foundDocs = g_pDocIndex->query( m_terms, termSeq, seqWords );
+ m_foundDocs = g_pDocIndex->query(m_terms, termSeq, seqWords);
m_pResultBox->clear();
- for ( it = m_foundDocs.begin(); it != m_foundDocs.end(); ++it )
- m_pResultBox->addItem( g_pDocIndex->getDocumentTitle( *it ) );
+ for(it = m_foundDocs.begin(); it != m_foundDocs.end(); ++it)
+ m_pResultBox->addItem(g_pDocIndex->getDocumentTitle(*it));
m_terms.clear();
bool isPhrase = false;
QString s = "";
- for ( int i = 0; i < (int)buf.length(); ++i ) {
- if ( buf[i] == '\"' ) {
+ for(int i = 0; i < (int)buf.length(); ++i)
+ {
+ if(buf[i] == '\"')
+ {
isPhrase = !isPhrase;
s = s.simplified();
- if ( !s.isEmpty() )
+ if(!s.isEmpty())
m_terms << s;
s = "";
- } else if ( buf[i] == ' ' && !isPhrase ) {
+ }
+ else if(buf[i] == ' ' && !isPhrase)
+ {
s = s.simplified();
- if ( !s.isEmpty() )
+ if(!s.isEmpty())
m_terms << s;
s = "";
- } else
- s += buf[i];
+ }
+ else
+ s += buf[i];
}
- if ( !s.isEmpty() ) m_terms << s;
+ if(!s.isEmpty())
+ m_terms << s;
- setCursor( Qt::ArrowCursor );
+ setCursor(Qt::ArrowCursor);
}
-
#ifdef COMPILE_WEBKIT_SUPPORT
QWebView * HelpWindow::textBrowser()
#else
@@ -272,52 +286,55 @@ QTextBrowser * HelpWindow::textBrowser()
void HelpWindow::showIndexTopic()
{
- if (m_pIndexSearch->text().isEmpty()|| !m_pIndexListWidget->selectedItems().count()) return;
- int i=g_pDocIndex->titlesList().indexOf(m_pIndexListWidget->selectedItems().at(0)->text());
- #ifdef COMPILE_WEBKIT_SUPPORT
- textBrowser()->load(QUrl(g_pDocIndex->documentList()[ i ]));
- #else
- textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[ i ]));
- #endif
+ if(m_pIndexSearch->text().isEmpty() || !m_pIndexListWidget->selectedItems().count())
+ return;
+ int i = g_pDocIndex->titlesList().indexOf(m_pIndexListWidget->selectedItems().at(0)->text());
+#ifdef COMPILE_WEBKIT_SUPPORT
+ textBrowser()->load(QUrl(g_pDocIndex->documentList()[i]));
+#else
+ textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[i]));
+#endif
}
-void HelpWindow::searchInIndex( const QString &s )
+void HelpWindow::searchInIndex(const QString & s)
{
- QListWidgetItem *item ;
+ QListWidgetItem * item;
QString sl = s.toLower();
- for(int i=0;i<m_pIndexListWidget->count();i++)
+ for(int i = 0; i < m_pIndexListWidget->count(); i++)
{
- item=m_pIndexListWidget->item(i);
+ item = m_pIndexListWidget->item(i);
QString t = item->text();
- if ( t.length() >= sl.length() &&
- item->text().left(s.length()).toLower() == sl ) {
- m_pIndexListWidget->setCurrentItem( item );
- m_pIndexListWidget->scrollToItem(item,QAbstractItemView::PositionAtTop);
+ if(t.length() >= sl.length() && item->text().left(s.length()).toLower() == sl)
+ {
+ m_pIndexListWidget->setCurrentItem(item);
+ m_pIndexListWidget->scrollToItem(item, QAbstractItemView::PositionAtTop);
break;
}
}
}
-void HelpWindow::indexSelected ( QListWidgetItem *item )
+void HelpWindow::indexSelected(QListWidgetItem * item)
{
- if (!item) return;
- int i=g_pDocIndex->titlesList().indexOf(item->text());
- #ifdef COMPILE_WEBKIT_SUPPORT
- textBrowser()->load(QUrl(g_pDocIndex->documentList()[ i ]));
- #else
- textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[ i ]));
- #endif
+ if(!item)
+ return;
+ int i = g_pDocIndex->titlesList().indexOf(item->text());
+#ifdef COMPILE_WEBKIT_SUPPORT
+ textBrowser()->load(QUrl(g_pDocIndex->documentList()[i]));
+#else
+ textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[i]));
+#endif
}
-void HelpWindow::searchSelected ( QListWidgetItem *item )
+void HelpWindow::searchSelected(QListWidgetItem * item)
{
- if (!item) return;
- int i=g_pDocIndex->titlesList().indexOf(item->text());
- #ifdef COMPILE_WEBKIT_SUPPORT
- textBrowser()->load(QUrl(g_pDocIndex->documentList()[ i ]));
- #else
- textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[ i ]));
- #endif
+ if(!item)
+ return;
+ int i = g_pDocIndex->titlesList().indexOf(item->text());
+#ifdef COMPILE_WEBKIT_SUPPORT
+ textBrowser()->load(QUrl(g_pDocIndex->documentList()[i]));
+#else
+ textBrowser()->setSource(QUrl(g_pDocIndex->documentList()[i]));
+#endif
}
QPixmap * HelpWindow::myIconPtr()
@@ -327,7 +344,7 @@ QPixmap * HelpWindow::myIconPtr()
void HelpWindow::resizeEvent(QResizeEvent *)
{
- m_pSplitter->setGeometry(0,0,width(),height());
+ m_pSplitter->setGeometry(0, 0, width(), height());
}
void HelpWindow::fillCaptionBuffers()
diff --git a/src/modules/help/HelpWindow.h b/src/modules/help/HelpWindow.h
index 0c4d5f831..1447d15dc 100644
--- a/src/modules/help/HelpWindow.h
+++ b/src/modules/help/HelpWindow.h
@@ -32,9 +32,9 @@
#include <QTabWidget>
#ifdef COMPILE_WEBKIT_SUPPORT
- #include <QtWebKitWidgets/QWebView>
+#include <QtWebKitWidgets/QWebView>
#else
- class QTextBrowser;
+class QTextBrowser;
#endif
#include <QLineEdit>
@@ -50,48 +50,51 @@ class HelpWindow : public KviWindow
public:
HelpWindow(const char * name);
~HelpWindow();
+
protected:
HelpWidget * m_pHelpWidget;
- KviTalVBox * m_pToolBar;
- QTabWidget * m_pTabWidget;
- KviTalVBox * m_pIndexTab;
- KviTalVBox * m_pSearchTab;
- KviTalHBox * m_pBottomLayout;
- QPushButton * m_pCancelButton;
- QProgressBar * m_pProgressBar;
+ KviTalVBox * m_pToolBar;
+ QTabWidget * m_pTabWidget;
+ KviTalVBox * m_pIndexTab;
+ KviTalVBox * m_pSearchTab;
+ KviTalHBox * m_pBottomLayout;
+ QPushButton * m_pCancelButton;
+ QProgressBar * m_pProgressBar;
+
+ KviTalListWidget * m_pIndexListWidget;
+ QLineEdit * m_pIndexSearch;
+ QStringList m_foundDocs;
+ QStringList m_terms;
+ KviTalListWidget * m_pResultBox;
+ QLineEdit * m_pTermsEdit;
+ QPushButton * m_pBtnRefreshIndex;
- KviTalListWidget* m_pIndexListWidget;
- QLineEdit * m_pIndexSearch;
- QStringList m_foundDocs;
- QStringList m_terms;
- KviTalListWidget* m_pResultBox;
- QLineEdit * m_pTermsEdit;
- QPushButton * m_pBtnRefreshIndex;
public:
- HelpWidget * helpWidget(){ return m_pHelpWidget; };
+ HelpWidget * helpWidget() { return m_pHelpWidget; };
protected:
virtual QPixmap * myIconPtr();
virtual void fillCaptionBuffers();
- virtual void resizeEvent(QResizeEvent *e);
+ virtual void resizeEvent(QResizeEvent * e);
virtual void saveProperties(KviConfigurationFile * cfg);
virtual void loadProperties(KviConfigurationFile * cfg);
+
public:
- #ifdef COMPILE_WEBKIT_SUPPORT
+#ifdef COMPILE_WEBKIT_SUPPORT
QWebView * textBrowser();
- #else
+#else
QTextBrowser * textBrowser();
- #endif
+#endif
public slots:
- void indexSelected ( QListWidgetItem * );
- void searchInIndex( const QString &s );
+ void indexSelected(QListWidgetItem *);
+ void searchInIndex(const QString & s);
void showIndexTopic();
void startSearch();
- void searchSelected ( QListWidgetItem * );
+ void searchSelected(QListWidgetItem *);
void refreshIndex();
void initialSetup();
- void indexingStart( int iNum );
- void indexingProgress( int iNum );
+ void indexingStart(int iNum);
+ void indexingProgress(int iNum);
void indexingEnd();
};
diff --git a/src/modules/help/libkvihelp.cpp b/src/modules/help/libkvihelp.cpp
index 61b8bd1fd..c5dde5b99 100644
--- a/src/modules/help/libkvihelp.cpp
+++ b/src/modules/help/libkvihelp.cpp
@@ -36,7 +36,7 @@
#include <QFileInfo>
#include <QSplitter>
-HelpIndex * g_pDocIndex = 0;
+HelpIndex * g_pDocIndex = 0;
KviPointerList<HelpWidget> * g_pHelpWidgetList = 0;
KviPointerList<HelpWindow> * g_pHelpWindowList = 0;
@@ -80,21 +80,20 @@ KviPointerList<HelpWindow> * g_pHelpWindowList = 0;
[/example]
*/
-
static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
{
QString szDoc, szHelpDir, szParam;
- QDir dirHelp;
+ QDir dirHelp;
KVSM_PARAMETERS_BEGIN(c)
- KVSM_PARAMETER("document",KVS_PT_STRING,KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING,szParam)
+ KVSM_PARAMETER("document", KVS_PT_STRING, KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING, szParam)
KVSM_PARAMETERS_END(c)
// no document => index
if(szParam.isEmpty())
{
szParam = QString("index.html");
- qDebug ("No file, use default at path %s",szDoc.toUtf8().data());
+ qDebug("No file, use default at path %s", szDoc.toUtf8().data());
}
/*
@@ -109,20 +108,20 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
if(!f.exists() || !f.isAbsolute())
{
// try relative path (to local help)
- g_pApp->getLocalKvircDirectory(szHelpDir,KviApplication::Help);
+ g_pApp->getLocalKvircDirectory(szHelpDir, KviApplication::Help);
dirHelp = QDir(szHelpDir);
szDoc = dirHelp.absoluteFilePath(szParam);
- qDebug("No abs path, trying local relative path: %s",szDoc.toUtf8().data());
+ qDebug("No abs path, trying local relative path: %s", szDoc.toUtf8().data());
f.setFile(szDoc);
if(!f.exists())
{
//try relative path (to global help)
- g_pApp->getGlobalKvircDirectory(szHelpDir,KviApplication::Help);
+ g_pApp->getGlobalKvircDirectory(szHelpDir, KviApplication::Help);
dirHelp = QDir(szHelpDir);
szDoc = dirHelp.absoluteFilePath(szParam);
- qDebug("No local relative, trying global relative path: %s",szDoc.toUtf8().data());
+ qDebug("No local relative, trying global relative path: %s", szDoc.toUtf8().data());
f.setFile(szDoc);
}
}
@@ -133,33 +132,37 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
qDebug("No path, trying search..");
if(g_pDocIndex)
{
- if (!g_pDocIndex->documentList().count())
+ if(!g_pDocIndex->documentList().count())
{
- QString szDoclist,szDict;
- g_pApp->getLocalKvircDirectory(szDoclist,KviApplication::Help,"help.doclist." KVI_SOURCES_DATE);
- g_pApp->getLocalKvircDirectory(szDict,KviApplication::Help,"help.dict." KVI_SOURCES_DATE);
- if ( KviFileUtils::fileExists(szDoclist) && KviFileUtils::fileExists( szDict ))
+ QString szDoclist, szDict;
+ g_pApp->getLocalKvircDirectory(szDoclist, KviApplication::Help, "help.doclist." KVI_SOURCES_DATE);
+ g_pApp->getLocalKvircDirectory(szDict, KviApplication::Help, "help.dict." KVI_SOURCES_DATE);
+ if(KviFileUtils::fileExists(szDoclist) && KviFileUtils::fileExists(szDict))
{
g_pDocIndex->readDict();
- } else {
+ }
+ else
+ {
g_pDocIndex->makeIndex();
g_pDocIndex->writeDict();
}
}
- int i=g_pDocIndex->titlesList().indexOf(QRegExp(QRegExp::escape(szParam), Qt::CaseInsensitive));
- if (i!=-1)
+ int i = g_pDocIndex->titlesList().indexOf(QRegExp(QRegExp::escape(szParam), Qt::CaseInsensitive));
+ if(i != -1)
{
- szDoc=QUrl(g_pDocIndex->documentList()[ i ]).toLocalFile();
+ szDoc = QUrl(g_pDocIndex->documentList()[i]).toLocalFile();
f.setFile(szDoc);
- } else {
+ }
+ else
+ {
QString szTmpDocName(".*/doc_");
szTmpDocName.append(QRegExp::escape(szParam));
szTmpDocName.append("\\.html");
- i=g_pDocIndex->documentList().indexOf(QRegExp(szTmpDocName, Qt::CaseInsensitive));
- if (i!=-1)
+ i = g_pDocIndex->documentList().indexOf(QRegExp(szTmpDocName, Qt::CaseInsensitive));
+ if(i != -1)
{
- szDoc=QUrl(g_pDocIndex->documentList()[ i ]).toLocalFile();
+ szDoc = QUrl(g_pDocIndex->documentList()[i]).toLocalFile();
f.setFile(szDoc);
}
}
@@ -171,40 +174,42 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
{
szDoc = dirHelp.absoluteFilePath("nohelpavailable.html");
- qDebug("Document not found, defaulting to error page: %s",szDoc.toUtf8().data());
+ qDebug("Document not found, defaulting to error page: %s", szDoc.toUtf8().data());
f.setFile(szDoc);
}
- if(!c->switches()->find('n',"new"))
+ if(!c->switches()->find('n', "new"))
{
HelpWidget * w = (HelpWidget *)g_pMainWindow->findChild<HelpWidget *>("help_widget");
if(w)
{
- #ifdef COMPILE_WEBKIT_SUPPORT
+#ifdef COMPILE_WEBKIT_SUPPORT
w->textBrowser()->load(QUrl::fromLocalFile(f.absoluteFilePath()));
- #else
+#else
w->textBrowser()->setSource(QUrl::fromLocalFile(f.absoluteFilePath()));
- #endif
+#endif
return true;
}
}
- if(c->switches()->find('m',"mdi"))
+ if(c->switches()->find('m', "mdi"))
{
- HelpWindow *w = new HelpWindow("Help browser");
- #ifdef COMPILE_WEBKIT_SUPPORT
+ HelpWindow * w = new HelpWindow("Help browser");
+#ifdef COMPILE_WEBKIT_SUPPORT
w->textBrowser()->load(QUrl::fromLocalFile(f.absoluteFilePath()));
- #else
+#else
w->textBrowser()->setSource(QUrl::fromLocalFile(f.absoluteFilePath()));
- #endif
+#endif
g_pMainWindow->addWindow(w);
- } else {
- HelpWidget *w = new HelpWidget(g_pMainWindow->splitter(), true);
- #ifdef COMPILE_WEBKIT_SUPPORT
+ }
+ else
+ {
+ HelpWidget * w = new HelpWidget(g_pMainWindow->splitter(), true);
+#ifdef COMPILE_WEBKIT_SUPPORT
w->textBrowser()->load(QUrl::fromLocalFile(f.absoluteFilePath()));
- #else
+#else
w->textBrowser()->setSource(QUrl::fromLocalFile(f.absoluteFilePath()));
- #endif
+#endif
w->show();
}
@@ -213,15 +218,15 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c)
static bool help_module_init(KviModule * m)
{
- QString szHelpDir,szDocList;
+ QString szHelpDir, szDocList;
- g_pApp->getLocalKvircDirectory(szDocList,KviApplication::Help,"help.doclist." KVI_SOURCES_DATE);
- g_pApp->getGlobalKvircDirectory(szHelpDir,KviApplication::Help);
+ g_pApp->getLocalKvircDirectory(szDocList, KviApplication::Help, "help.doclist." KVI_SOURCES_DATE);
+ g_pApp->getGlobalKvircDirectory(szHelpDir, KviApplication::Help);
- g_pDocIndex = new HelpIndex(szHelpDir,szDocList);
+ g_pDocIndex = new HelpIndex(szHelpDir, szDocList);
g_pDocIndex->setDocListFile(szDocList);
- g_pApp->getLocalKvircDirectory(szHelpDir,KviApplication::Help,"help.dict." KVI_SOURCES_DATE);
+ g_pApp->getLocalKvircDirectory(szHelpDir, KviApplication::Help, "help.dict." KVI_SOURCES_DATE);
g_pDocIndex->setDictionaryFile(szHelpDir);
g_pHelpWidgetList = new KviPointerList<HelpWidget>;
@@ -229,9 +234,7 @@ static bool help_module_init(KviModule * m)
g_pHelpWindowList = new KviPointerList<HelpWindow>;
g_pHelpWindowList->setAutoDelete(false);
- KVSM_REGISTER_SIMPLE_COMMAND(m,"open",help_kvs_cmd_open);
-
-
+ KVSM_REGISTER_SIMPLE_COMMAND(m, "open", help_kvs_cmd_open);
return true;
}
@@ -257,13 +260,12 @@ static bool help_module_can_unload(KviModule *)
}
KVIRC_MODULE(
- "Help", // module name
- "4.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,
- 0
-)
+ "Help", // module name
+ "4.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,
+ 0)