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