📄 krsearchdialog.cpp
字号:
krConfig->writeEntry("Path Width", resultsList->columnWidth( 1 ) ); krConfig->writeEntry("Size Width", resultsList->columnWidth( 2 ) ); krConfig->writeEntry("Date Width", resultsList->columnWidth( 3 ) ); krConfig->writeEntry("Perm Width", resultsList->columnWidth( 4 ) ); lastSearchText = generalFilter->searchFor->currentText(); lastSearchType = generalFilter->ofType->currentItem(); lastSearchForCase = generalFilter->searchForCase->isChecked(); lastRemoteContentSearch = generalFilter->remoteContentSearch->isChecked(); lastContainsWholeWord = generalFilter->containsWholeWord->isChecked(); lastContainsWithCase = generalFilter->containsTextCase->isChecked(); lastSearchInSubDirs = generalFilter->searchInDirs->isChecked(); lastSearchInArchives = generalFilter->searchInArchives->isChecked(); lastFollowSymLinks = generalFilter->followLinks->isChecked(); hide(); SearchDialog = 0; if( isAccept ) QDialog::accept(); else QDialog::reject(); this->deleteLater();}void KrSearchDialog::reject() { closeDialog( false );}void KrSearchDialog::resizeEvent( QResizeEvent *e ){ if( !isMaximized() ) { sizeX = e->size().width(); sizeY = e->size().height(); }}void KrSearchDialog::found(QString what, QString where, KIO::filesize_t size, time_t mtime, QString perm, QString foundText){ // convert the time_t to struct tm struct tm* t=localtime((time_t *)&mtime); QDateTime tmp(QDate(t->tm_year+1900, t->tm_mon+1, t->tm_mday), QTime(t->tm_hour, t->tm_min)); ResultListViewItem *it =new ResultListViewItem(resultsList, what, where.replace(QRegExp("\\\\"),"#"), size, tmp, perm); QString totals = QString(i18n("Found %1 matches.")).arg(resultsList->childCount()); foundLabel->setText(totals); if (!foundText.isEmpty()) it->setFoundText(foundText);}bool KrSearchDialog::gui2query() { // prepare the query ... /////////////////// names, locations and greps if (query!=0) { delete query; query = 0; } query = new KRQuery(); return filterTabs->fillQuery( query );}void KrSearchDialog::startSearch() { // prepare the query ///////////////////////////////////////////// if (!gui2query()) return; // first, informative messages if ( query->searchInArchives() ) { KMessageBox::information(this, i18n("Since you chose to also search in archives, " "note the following limitations:\n" "You cannot search for text (grep) while doing" " a search that includes archives."), 0, "searchInArchives"); } // prepare the gui /////////////////////////////////////////////// mainSearchBtn->setEnabled(false); mainCloseBtn->setEnabled(false); mainStopBtn->setEnabled(true); mainFeedToListBoxBtn->setEnabled(false); resultsList->clear(); searchingLabel->setText(""); foundLabel->setText(i18n("Found 0 matches.")); searcherTabs->setCurrentPage(2); // show the results page foundTextLabel->setText(""); qApp->processEvents(); // start the search. if (searcher != 0) { delete searcher; searcher = 0; } searcher = new KRSearchMod(query); connect(searcher, SIGNAL(searching(const QString&)), searchingLabel, SLOT(setText(const QString&))); connect(searcher, SIGNAL(found(QString,QString,KIO::filesize_t,time_t,QString,QString)), this, SLOT(found(QString,QString,KIO::filesize_t,time_t,QString,QString))); connect(searcher, SIGNAL(finished()), this, SLOT(stopSearch())); isSearching = true; searcher->start(); isSearching = false; if( closed ) emit closeDialog();}void KrSearchDialog::stopSearch() { if (searcher!=0) { searcher->stop(); disconnect(searcher,0,0,0); delete query; query = 0; } // gui stuff mainSearchBtn->setEnabled(true); mainCloseBtn->setEnabled(true); mainStopBtn->setEnabled(false); if( resultsList->childCount() ) mainFeedToListBoxBtn->setEnabled( true ); searchingLabel->setText(i18n("Finished searching."));}void KrSearchDialog::resultDoubleClicked(QListViewItem* i) { ACTIVE_FUNC->openUrl(vfs::fromPathOrURL(i->text(1)),i->text(0)); showMinimized();}void KrSearchDialog::resultClicked(QListViewItem* i) { ResultListViewItem *it = dynamic_cast<ResultListViewItem*>(i); if( it == 0 ) return; if (!it->foundText().isEmpty()) { // ugly hack: find the <b> and </b> in the text, then // use it to set the are which we don't want squeezed int idx = it->foundText().find("<b>")-4; // take "<qt>" into account int length = it->foundText().find("</b>")-idx+4; foundTextLabel->setText(it->foundText(), idx, length); }}void KrSearchDialog::closeEvent(QCloseEvent *e){ /* if searching is in progress we must not close the window */ if( isSearching ) /* because qApp->processEvents() is called by the searcher and */ { /* at window desruction, the searcher object will be deleted */ stopSearch(); /* instead we stop searching */ closed = true; /* and after stopping: startSearch can close the window */ e->ignore(); /* ignoring the close event */ } else QDialog::closeEvent( e ); /* if no searching, let QDialog handle the event */}void KrSearchDialog::keyPressEvent(QKeyEvent *e){ KKey pressedKey( e ); if( isSearching && e->key() == Key_Escape ) /* at searching we must not close the window */ { stopSearch(); /* so we simply stop searching */ return; } if( resultsList->hasFocus() ) { if( e->key() == Key_F4 ) { if (!generalFilter->containsText->currentText().isEmpty() && QApplication::clipboard()->text() != generalFilter->containsText->currentText()) QApplication::clipboard()->setText(generalFilter->containsText->currentText()); editCurrent(); return; } else if( e->key() == Key_F3 ) { if (!generalFilter->containsText->currentText().isEmpty() && QApplication::clipboard()->text() != generalFilter->containsText->currentText()) QApplication::clipboard()->setText(generalFilter->containsText->currentText()); viewCurrent(); return; } else if( Krusader::actCopy->shortcut().contains( pressedKey ) ) { copyToClipBoard(); return; } } QDialog::keyPressEvent( e );}void KrSearchDialog::editCurrent(){ QListViewItem *current = resultsList->currentItem(); if( current ) { QString name = current->text(1); name += (name.endsWith( "/" ) ? current->text(0) : "/" + current->text(0) ); KURL url = vfs::fromPathOrURL( name ); KrViewer::edit( url, this ); }}void KrSearchDialog::viewCurrent(){ QListViewItem *current = resultsList->currentItem(); if( current ) { QString name = current->text(1); name += (name.endsWith( "/" ) ? current->text(0) : "/" + current->text(0) ); KURL url = vfs::fromPathOrURL( name ); KrViewer::view( url, this ); }}void KrSearchDialog::rightClickMenu(QListViewItem *item, const QPoint&, int){ // these are the values that will exist in the menu #define EDIT_FILE_ID 110 #define VIEW_FILE_ID 111 #define COPY_SELECTED_TO_CLIPBOARD 112 ////////////////////////////////////////////////////////// if (!item) return; // create the menu KPopupMenu popup; popup.insertTitle(i18n("Krusader Search")); popup.insertItem(i18n("View File (F3)"), VIEW_FILE_ID); popup.insertItem(i18n("Edit File (F4)"), EDIT_FILE_ID); popup.insertItem(i18n("Copy selected to clipboard"),COPY_SELECTED_TO_CLIPBOARD); int result=popup.exec(QCursor::pos()); // check out the user's option switch (result) { case VIEW_FILE_ID: viewCurrent(); break; case EDIT_FILE_ID: editCurrent(); break; case COPY_SELECTED_TO_CLIPBOARD: copyToClipBoard(); break; default: // the user clicked outside of the menu break; }}void KrSearchDialog::feedToListBox(){ virt_vfs v(0,true); v.vfs_refresh( KURL( "/" ) ); krConfig->setGroup( "Search" ); int listBoxNum = krConfig->readNumEntry( "Feed To Listbox Counter", 1 ); QString queryName; do { queryName = i18n("Search results")+QString( " %1" ).arg( listBoxNum++ ); }while( v.vfs_search( queryName ) != 0 ); krConfig->writeEntry( "Feed To Listbox Counter", listBoxNum ); krConfig->setGroup( "Advanced" ); if ( krConfig->readBoolEntry( "Confirm Feed to Listbox", _ConfirmFeedToListbox ) ) { bool ok; queryName = KInputDialog::getText( i18n("Query name"), // Caption i18n("Here you can name the file collection"), // Questiontext queryName, // Default &ok ); if ( ! ok) return; } KURL::List urlList; QListViewItem * item = resultsList->firstChild(); while( item ) { QString name = item->text(1); name += (name.endsWith( "/" ) ? item->text(0) : "/" + item->text(0) ); urlList.push_back( vfs::fromPathOrURL( name ) ); item = item->nextSibling(); } KURL url = KURL::fromPathOrURL( QString("virt:/") + queryName ); v.vfs_refresh( url ); v.vfs_addFiles( &urlList, KIO::CopyJob::Copy, 0 ); //ACTIVE_FUNC->openUrl(url); ACTIVE_MNG->slotNewTab(url.prettyURL()); closeDialog();}void KrSearchDialog::copyToClipBoard(){ KURL::List urls; QListViewItem * item = resultsList->firstChild(); while( item ) { if( item->isSelected() ) { QString name = item->text(1); name += (name.endsWith( "/" ) ? item->text(0) : "/" + item->text(0) ); urls.push_back( vfs::fromPathOrURL( name ) ); } item = item->nextSibling(); } if( urls.count() == 0 ) return; KURLDrag *d = new KURLDrag(urls, this); d->setPixmap( FL_LOADICON( "file" ), QPoint( -7, 0 ) ); QApplication::clipboard()->setData( d );}#include "krsearchdialog.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -