void DocMetaInfo::endProcess( DocEntry *entry, DocEntryTraverser *traverser ) { // kdDebug() << "DocMetaInfo::endProcess() " << entry->name() << endl; if ( !entry ) { endTraverseEntries( traverser ); return; } if ( entry->hasChildren() ) { startTraverseEntry( entry->firstChild(), traverser->childTraverser( entry ) ); } else if ( entry->nextSibling() ) { startTraverseEntry( entry->nextSibling(), traverser ); } else { DocEntry *parent = entry->parent(); DocEntryTraverser *parentTraverser = 0; while ( parent ) { parentTraverser = traverser->parentTraverser(); traverser->deleteTraverser(); if ( parent->nextSibling() ) { startTraverseEntry( parent->nextSibling(), parentTraverser ); break; } else { parent = parent->parent(); traverser = parentTraverser; } } if ( !parent ) { endTraverseEntries( traverser ); } } }
DocEntry *DocMetaInfo::addDirEntry( const QDir &dir, DocEntry *parent ) { DocEntry *dirEntry = addDocEntry( dir.absPath() + "/.directory" ); if ( !dirEntry ) { dirEntry = new DocEntry; dirEntry->setName( dir.dirName() ); addDocEntry( dirEntry ); } dirEntry->setDirectory( true ); if ( parent ) parent->addChild( dirEntry ); return dirEntry; }
DocEntry *DocMetaInfo::addDocEntry(const QString &fileName) { QFileInfo fi(fileName); if(!fi.exists()) return 0; QString extension = fi.extension(); QStringList extensions = QStringList::split('.', extension); QString lang; if(extensions.count() >= 2) { lang = extensions[extensions.count() - 2]; } if(!lang.isEmpty() && mLanguages.find(lang) == mLanguages.end()) { return 0; } DocEntry *entry = new DocEntry(); if(entry->readFromFile(fileName)) { if(!lang.isEmpty() && lang != mLanguages.first()) { entry->setLang(lang); entry->setName(i18n("doctitle (language)", "%1 (%2)").arg(entry->name()).arg(mLanguageNames[lang])); } if(entry->searchMethod().lower() == "htdig") { mHtmlSearch->setupDocEntry(entry); } QString indexer = entry->indexer(); indexer.replace("%f", fileName); entry->setIndexer(indexer); addDocEntry(entry); return entry; } else { delete entry; return 0; } }
QString Navigator::createChildrenList( QTreeWidgetItem *child ) { ++mDirLevel; QString t; t += QLatin1String("<ul>\n"); int cc = child->childCount(); for (int i=0;i<cc;i++) { NavigatorItem *childItem = static_cast<NavigatorItem *>( child->child(i) ); DocEntry *e = childItem->entry(); t += QLatin1String("<li><a href=\"") + e->url() + QLatin1String("\">"); if ( e->isDirectory() ) t += QLatin1String("<b>"); t += e->name(); if ( e->isDirectory() ) t += QLatin1String("</b>"); t += QLatin1String("</a>"); if ( !e->info().isEmpty() ) { t += QLatin1String("<br>") + e->info(); } t += QLatin1String("</li>\n"); if ( childItem->childCount() > 0 && mDirLevel < 2 ) { t += createChildrenList( childItem ); } } t += QLatin1String("</ul>\n"); --mDirLevel; return t; }
bool KCMHelpCenter::buildIndex() { kdDebug(1401) << "Build Index" << endl; kdDebug() << "IndexPath: '" << Prefs::indexDirectory() << "'" << endl; if ( mProcess ) { kdError() << "Error: Index Process still running." << endl; return false; } mIndexQueue.clear(); QFontMetrics fm( font() ); int maxWidth = 0; mCmdFile = new KTempFile; mCmdFile->setAutoDelete( true ); QTextStream *ts = mCmdFile->textStream(); if ( !ts ) { kdError() << "Error opening command file." << endl; deleteCmdFile(); return false; } else { kdDebug() << "Writing to file '" << mCmdFile->name() << "'" << endl; } bool hasError = false; QListViewItemIterator it( mListView ); while ( it.current() != 0 ) { ScopeItem *item = static_cast<ScopeItem *>( it.current() ); if ( item->isOn() ) { DocEntry *entry = item->entry(); QString docText = i18n("Document '%1' (%2):\n") .arg( entry->identifier() ) .arg( entry->name() ); if ( entry->documentType().isEmpty() ) { KMessageBox::sorry( this, docText + i18n("No document type.") ); hasError = true; } else { SearchHandler *handler = mEngine->handler( entry->documentType() ); if ( !handler ) { KMessageBox::sorry( this, docText + i18n("No search handler available for document type '%1'.") .arg( entry->documentType() ) ); hasError = true; } else { QString indexer = handler->indexCommand( entry->identifier() ); if ( indexer.isEmpty() ) { KMessageBox::sorry( this, docText + i18n("No indexing command specified for document type '%1'.") .arg( entry->documentType() ) ); hasError = true; } else { indexer.replace( QRegExp( "%i" ), entry->identifier() ); indexer.replace( QRegExp( "%d" ), Prefs::indexDirectory() ); indexer.replace( QRegExp( "%p" ), entry->url() ); kdDebug() << "INDEXER: " << indexer << endl; *ts << indexer << endl; int width = fm.width( entry->name() ); if ( width > maxWidth ) maxWidth = width; mIndexQueue.append( entry ); } } } } ++it; } mCmdFile->close(); if ( mIndexQueue.isEmpty() ) { deleteCmdFile(); return !hasError; } mCurrentEntry = mIndexQueue.begin(); QString name = (*mCurrentEntry)->name(); if ( !mProgressDialog ) { mProgressDialog = new IndexProgressDialog( this ); connect( mProgressDialog, SIGNAL( cancelled() ), SLOT( cancelBuildIndex() ) ); connect( mProgressDialog, SIGNAL( closed() ), SLOT( slotProgressClosed() ) ); } mProgressDialog->setLabelText( name ); mProgressDialog->setTotalSteps( mIndexQueue.count() ); mProgressDialog->setMinimumLabelWidth( maxWidth ); mProgressDialog->show(); startIndexProcess(); return true; }