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; } }
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; }