diff --git a/krusader/Search/krsearchdialog.cpp b/krusader/Search/krsearchdialog.cpp index 2070225a..bb2e1254 100644 --- a/krusader/Search/krsearchdialog.cpp +++ b/krusader/Search/krsearchdialog.cpp @@ -1,672 +1,675 @@ /*************************************************************************** krsearchdialog.cpp ------------------- copyright : (C) 2001 by Shie Erlich & Rafi Yanai email : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD S o u r c e F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "krsearchdialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// QtCore +#include +#include +// QtGui +#include +#include +#include +#include +#include +#include +// QtWidgets +#include +#include +#include +#include +#include +#include +#include #include #include #include "krsearchmod.h" #include "../krglobal.h" #include "../kractions.h" #include "../krservices.h" #include "../krslots.h" #include "../defaults.h" #include "../panelmanager.h" #include "../kicons.h" #include "../krusaderview.h" #include "../Dialogs/krdialogs.h" #include "../Dialogs/krspecialwidgets.h" #include "../Dialogs/krsqueezedtextlabel.h" #include "../VFS/virt_vfs.h" #include "../VFS/krquery.h" #include "../KViewer/krviewer.h" #include "../Panel/krview.h" #include "../Panel/krviewfactory.h" #include "../Panel/quickfilter.h" #include "../Panel/krpanel.h" #include "../Panel/panelfunc.h" #include "../Filter/filtertabs.h" #include "../Filter/generalfilter.h" #define RESULTVIEW_TYPE 0 class SearchResultContainer : public VfileContainer { public: SearchResultContainer(QObject *parent) : VfileContainer(parent) {} virtual ~SearchResultContainer() { clear(); } virtual QList vfiles() Q_DECL_OVERRIDE { return _vfiles; } virtual unsigned long numVfiles() Q_DECL_OVERRIDE { return _vfiles.count(); } virtual bool isRoot() Q_DECL_OVERRIDE { return true; } void clear() { emit cleared(); foreach(vfile *vf, _vfiles) delete vf; _vfiles.clear(); _foundText.clear(); } void addItem(QString path, KIO::filesize_t size, time_t mtime, QString perm, uid_t uid, gid_t gid, QString foundText) { vfile *vf = new vfile(path, size, perm, mtime, false/*FIXME*/, false/*FIXME*/, uid, gid, QString(), QString(), 0); vf->vfile_setUrl(QUrl::fromUserInput(path)); _vfiles << vf; if(!foundText.isEmpty()) _foundText[vf] = foundText; emit addedVfile(vf); } QString foundText(const vfile *vf) { return _foundText[vf]; } private: QList _vfiles; QHash _foundText; }; KrSearchDialog *KrSearchDialog::SearchDialog = 0; QString KrSearchDialog::lastSearchText = "*"; int KrSearchDialog::lastSearchType = 0; bool KrSearchDialog::lastSearchForCase = false; bool KrSearchDialog::lastRemoteContentSearch = false; bool KrSearchDialog::lastContainsWholeWord = false; bool KrSearchDialog::lastContainsWithCase = true; bool KrSearchDialog::lastSearchInSubDirs = true; bool KrSearchDialog::lastSearchInArchives = false; bool KrSearchDialog::lastFollowSymLinks = false; bool KrSearchDialog::lastContainsRegExp = false; // class starts here ///////////////////////////////////////// KrSearchDialog::KrSearchDialog(QString profile, QWidget* parent) : QDialog(parent), query(0), searcher(0), isBusy(false), closed(false) { KConfigGroup group(krConfig, "Search"); setWindowTitle(i18n("Krusader::Search")); setWindowIcon(QIcon::fromTheme("system-search")); QGridLayout* searchBaseLayout = new QGridLayout(this); searchBaseLayout->setSpacing(6); searchBaseLayout->setContentsMargins(11, 11, 11, 11); // creating the dialog buttons ( Search, Stop, Close ) QHBoxLayout* buttonsLayout = new QHBoxLayout(); buttonsLayout->setSpacing(6); buttonsLayout->setContentsMargins(0, 0, 0, 0); profileManager = new ProfileManager("SearcherProfile", this); buttonsLayout->addWidget(profileManager); QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); buttonsLayout->addItem(spacer); mainFeedToListBoxBtn = new QPushButton(this); mainFeedToListBoxBtn->setText(i18n("Feed to listbox")); mainFeedToListBoxBtn->setIcon(QIcon::fromTheme("list-add")); mainFeedToListBoxBtn->setEnabled(false); buttonsLayout->addWidget(mainFeedToListBoxBtn); mainSearchBtn = new QPushButton(this); mainSearchBtn->setText(i18n("Search")); mainSearchBtn->setIcon(QIcon::fromTheme("edit-find")); mainSearchBtn->setDefault(true); buttonsLayout->addWidget(mainSearchBtn); mainStopBtn = new QPushButton(this); mainStopBtn->setEnabled(false); mainStopBtn->setText(i18n("Stop")); mainStopBtn->setIcon(QIcon::fromTheme("process-stop")); buttonsLayout->addWidget(mainStopBtn); mainCloseBtn = new QPushButton(this); mainCloseBtn->setText(i18n("Close")); mainCloseBtn->setIcon(QIcon::fromTheme("dialog-close")); buttonsLayout->addWidget(mainCloseBtn); searchBaseLayout->addLayout(buttonsLayout, 1, 0); // creating the searcher tabs searcherTabs = new QTabWidget(this); filterTabs = FilterTabs::addTo(searcherTabs, FilterTabs::Default | FilterTabs::HasRemoteContentSearch); generalFilter = (GeneralFilter *)filterTabs->get("GeneralFilter"); QWidget* resultTab = new QWidget(searcherTabs); QGridLayout* resultLayout = new QGridLayout(resultTab); resultLayout->setSpacing(6); resultLayout->setContentsMargins(6, 6, 6, 6); // creating the result tab QHBoxLayout* resultLabelLayout = new QHBoxLayout(); resultLabelLayout->setSpacing(6); resultLabelLayout->setContentsMargins(0, 0, 0, 0); foundLabel = new QLabel(resultTab); QSizePolicy foundpolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); foundpolicy.setHeightForWidth(foundLabel->sizePolicy().hasHeightForWidth()); foundLabel->setSizePolicy(foundpolicy); foundLabel->setFrameShape(QLabel::StyledPanel); foundLabel->setFrameShadow(QLabel::Sunken); foundLabel->setText(i18n("Found 0 matches.")); resultLabelLayout->addWidget(foundLabel); searchingLabel = new KSqueezedTextLabel(resultTab); searchingLabel->setFrameShape(QLabel::StyledPanel); searchingLabel->setFrameShadow(QLabel::Sunken); searchingLabel->setText(""); resultLabelLayout->addWidget(searchingLabel); resultLayout->addLayout(resultLabelLayout, 3, 0); // creating the result list view result = new SearchResultContainer(this); // quicksearch KrQuickSearch *quickSearch = new KrQuickSearch(this); quickSearch->hide(); resultLayout->addWidget(quickSearch, 1, 0); // quickfilter QuickFilter *quickFilter = new QuickFilter(this); quickFilter->hide(); resultLayout->addWidget(quickFilter, 2, 0); // the view resultView = KrViewFactory::createView(RESULTVIEW_TYPE, resultTab, krConfig); resultView->init(); resultView->restoreSettings(KConfigGroup(&group, "ResultView")); resultView->enableUpdateDefaultSettings(false); resultView->setMainWindow(this); resultView->op()->setQuickSearch(quickSearch); resultView->op()->setQuickFilter(quickFilter); resultView->prepareForActive(); resultView->refreshColors(); resultView->setFiles(result); resultView->refresh(); resultLayout->addWidget(resultView->widget(), 0, 0); QHBoxLayout* foundTextLayout = new QHBoxLayout(); foundTextLayout->setSpacing(6); foundTextLayout->setContentsMargins(0, 0, 0, 0); QLabel *l1 = new QLabel(resultTab); QSizePolicy l1policy(QSizePolicy::Minimum, QSizePolicy::Minimum); l1policy.setHeightForWidth(l1->sizePolicy().hasHeightForWidth()); l1->setSizePolicy(l1policy); l1->setFrameShape(QLabel::StyledPanel); l1->setFrameShadow(QLabel::Sunken); l1->setText(i18n("Text found:")); foundTextLayout->addWidget(l1); foundTextLabel = new KrSqueezedTextLabel(resultTab); foundTextLabel->setFrameShape(QLabel::StyledPanel); foundTextLabel->setFrameShadow(QLabel::Sunken); foundTextLabel->setText(""); foundTextLayout->addWidget(foundTextLabel); resultLayout->addLayout(foundTextLayout, 4, 0); searcherTabs->addTab(resultTab, i18n("&Results")); searchBaseLayout->addWidget(searcherTabs, 0, 0); // signals and slots connections connect(mainSearchBtn, SIGNAL(clicked()), this, SLOT(startSearch())); connect(mainStopBtn, SIGNAL(clicked()), this, SLOT(stopSearch())); connect(mainCloseBtn, SIGNAL(clicked()), this, SLOT(closeDialog())); connect(mainFeedToListBoxBtn, SIGNAL(clicked()), this, SLOT(feedToListBox())); connect(profileManager, SIGNAL(loadFromProfile(QString)), filterTabs, SLOT(loadFromProfile(QString))); connect(profileManager, SIGNAL(saveToProfile(QString)), filterTabs, SLOT(saveToProfile(QString))); connect(resultView->op(), SIGNAL(currentChanged(KrViewItem*)), SLOT(currentChanged(KrViewItem*))); connect(resultView->op(), SIGNAL(executed(const QString&)), SLOT(executed(const QString&))); connect(resultView->op(), SIGNAL(contextMenu(const QPoint&)), SLOT(contextMenu(const QPoint &))); // tab order setTabOrder(mainSearchBtn, mainCloseBtn); setTabOrder(mainCloseBtn, mainStopBtn); setTabOrder(mainStopBtn, searcherTabs); setTabOrder(searcherTabs, resultView->widget()); sizeX = group.readEntry("Window Width", -1); sizeY = group.readEntry("Window Height", -1); if (sizeX != -1 && sizeY != -1) resize(sizeX, sizeY); if (group.readEntry("Window Maximized", false)) showMaximized(); else show(); generalFilter->searchFor->setFocus(); // finaly, load a profile of apply defaults: if (profile.isEmpty()) { // load the last used values generalFilter->searchFor->setEditText(lastSearchText); generalFilter->searchFor->lineEdit()->selectAll(); generalFilter->ofType->setCurrentIndex(lastSearchType); generalFilter->searchForCase->setChecked(lastSearchForCase); generalFilter->remoteContentSearch->setChecked(lastRemoteContentSearch); generalFilter->containsWholeWord->setChecked(lastContainsWholeWord); generalFilter->containsTextCase->setChecked(lastContainsWithCase); generalFilter->containsRegExp->setChecked(lastContainsRegExp); generalFilter->searchInDirs->setChecked(lastSearchInSubDirs); generalFilter->searchInArchives->setChecked(lastSearchInArchives); generalFilter->followLinks->setChecked(lastFollowSymLinks); // the path in the active panel should be the default search location generalFilter->searchIn->lineEdit()->setText(ACTIVE_PANEL->virtualPath().toDisplayString(QUrl::PreferLocalFile)); } else profileManager->loadProfile(profile); // important: call this _after_ you've connected profileManager ot the loadFromProfile!! } KrSearchDialog::~KrSearchDialog() { delete query; query = 0; delete resultView; resultView = 0; } void KrSearchDialog::closeDialog(bool isAccept) { if(isBusy) { closed = true; return; } // stop the search if it's on-going if (searcher != 0) { delete searcher; searcher = 0; } // saving the searcher state KConfigGroup group(krConfig, "Search"); group.writeEntry("Window Width", sizeX); group.writeEntry("Window Height", sizeY); group.writeEntry("Window Maximized", isMaximized()); resultView->saveSettings(KConfigGroup(&group, "ResultView")); lastSearchText = generalFilter->searchFor->currentText(); lastSearchType = generalFilter->ofType->currentIndex(); lastSearchForCase = generalFilter->searchForCase->isChecked(); lastRemoteContentSearch = generalFilter->remoteContentSearch->isChecked(); lastContainsWholeWord = generalFilter->containsWholeWord->isChecked(); lastContainsWithCase = generalFilter->containsTextCase->isChecked(); lastContainsRegExp = generalFilter->containsRegExp->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, uid_t uid, gid_t gid, QString foundText) { where = where.replace(QRegExp("\\\\"), "#"); //FIXME ? why is that done ? QString path = where.endsWith('/') ? (where + what) : (where + "/" + what); if(perm[0] == 'd' && !path.endsWith('/')) // file is a directory path += '/'; result->addItem(path, size, mtime, perm, uid, gid, foundText); foundLabel->setText(i18np("Found %1 match.", "Found %1 matches.", result->numVfiles())); } 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() { if(isBusy) return; // 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); result->clear(); resultView->setSortMode(KrViewProperties::NoColumn, 0); searchingLabel->setText(""); foundLabel->setText(i18n("Found 0 matches.")); searcherTabs->setCurrentIndex(2); // show the results page foundTextLabel->setText(""); isBusy = true; qApp->processEvents(); // start the search. if (searcher != 0) abort(); 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, uid_t, gid_t, QString)), this, SLOT(found(QString, QString, KIO::filesize_t, time_t, QString, uid_t, gid_t, QString))); connect(searcher, SIGNAL(finished()), this, SLOT(stopSearch())); searcher->start(); isBusy = false; delete searcher; searcher = 0; // gui stuff mainSearchBtn->setEnabled(true); mainCloseBtn->setEnabled(true); mainStopBtn->setEnabled(false); if (result->numVfiles()) mainFeedToListBoxBtn->setEnabled(true); searchingLabel->setText(i18n("Finished searching.")); if (closed) closeDialog(); } void KrSearchDialog::stopSearch() { if (searcher != 0) { searcher->stop(); disconnect(searcher, 0, 0, 0); } } void KrSearchDialog::executed(const QString &name) { QString path = name; QString fileName; if(!name.endsWith('/')) { int idx = name.lastIndexOf("/"); fileName = name.mid(idx+1); path = name.left(idx); } ACTIVE_FUNC->openUrl(QUrl::fromLocalFile(path), fileName); showMinimized(); } void KrSearchDialog::currentChanged(KrViewItem *item) { if(!item) return; QString text = result->foundText(item->getVfile()); if(!text.isEmpty()) { // ugly hack: find the and in the text, then // use it to set the are which we don't want squeezed int idx = text.indexOf("") - 4; // take "" into account int length = text.indexOf("") - idx + 4; foundTextLabel->setText(text, idx, length); } } void KrSearchDialog::closeEvent(QCloseEvent *e) { /* if searching is in progress we must not close the window */ if (isBusy) /* 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) { // TODO: don't use hardcoded shortcuts if (isBusy && e->key() == Qt::Key_Escape) { /* at searching we must not close the window */ stopSearch(); /* so we simply stop searching */ return; } if (resultView->widget()->hasFocus()) { if ((e->key() | e->modifiers()) == (Qt::CTRL | Qt::Key_I)) resultView->op()->startQuickFilter(); if (e->key() == Qt::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() == Qt::Key_F3) { if (!generalFilter->containsText->currentText().isEmpty() && QApplication::clipboard()->text() != generalFilter->containsText->currentText()) QApplication::clipboard()->setText(generalFilter->containsText->currentText()); viewCurrent(); return; } else if (e->key() == Qt::Key_F10) { compareByContent(); return; } else if (KrGlobal::copyShortcut == QKeySequence(e->key() | e->modifiers())) { copyToClipBoard(); return; } } QDialog::keyPressEvent(e); } void KrSearchDialog::editCurrent() { KrViewItem *current = resultView->getCurrentKrViewItem(); if (current) KrViewer::edit(current->getVfile()->vfile_getUrl(), this); } void KrSearchDialog::viewCurrent() { KrViewItem *current = resultView->getCurrentKrViewItem(); if (current) KrViewer::view(current->getVfile()->vfile_getUrl(), this); } void KrSearchDialog::compareByContent() { KrViewItemList list; resultView->getSelectedKrViewItems(&list); if (list.count() != 2) return; SLOTS->compareContent(list[0]->getVfile()->vfile_getUrl(), list[1]->getVfile()->vfile_getUrl()); } void KrSearchDialog::contextMenu(const QPoint &pos) { // create the menu QMenu popup; popup.setTitle(i18n("Krusader Search")); QAction *actView = popup.addAction(i18n("View File (F3)")); QAction *actEdit = popup.addAction(i18n("Edit File (F4)")); QAction *actComp = popup.addAction(i18n("Compare by content (F10)")); if(resultView->numSelected() != 2) actComp->setEnabled(false); QAction *actClip = popup.addAction(i18n("Copy selected to clipboard")); QAction *result = popup.exec(pos); // check out the user's option if (result == actView) viewCurrent(); else if (result == actEdit) editCurrent(); else if (result == actClip) copyToClipBoard(); else if (result == actComp) compareByContent(); } void KrSearchDialog::feedToListBox() { virt_vfs v(0, true); v.vfs_refresh(QUrl::fromLocalFile("/")); KConfigGroup group(krConfig, "Search"); int listBoxNum = group.readEntry("Feed To Listbox Counter", 1); QString queryName; if(query) { QString where = KrServices::toStringList(query->searchInDirs()).join(", "); if(query->content().isEmpty()) queryName = i18n("Search results for \"%1\" in %2", query->nameFilter(), where); else queryName = i18n("Search results for \"%1\" containing \"%2\" in %3", query->nameFilter(), query->content(), where); } QString vfsName; do { vfsName = i18n("Search results") + QString(" %1").arg(listBoxNum++); } while (v.vfs_search(vfsName) != 0); group.writeEntry("Feed To Listbox Counter", listBoxNum); KConfigGroup ga(krConfig, "Advanced"); if (ga.readEntry("Confirm Feed to Listbox", _ConfirmFeedToListbox)) { bool ok; vfsName = QInputDialog::getText(this, i18n("Query name"), i18n("Here you can name the file collection"), QLineEdit::Normal, vfsName, &ok); if (! ok) return; } QList urlList; foreach(vfile *vf, result->vfiles()) urlList.push_back(vf->vfile_getUrl()); mainSearchBtn->setEnabled(false); mainCloseBtn->setEnabled(false); mainFeedToListBoxBtn->setEnabled(false); isBusy = true; QUrl url = QUrl(QString("virt:/") + vfsName); v.vfs_refresh(url); v.vfs_addFiles(urlList, KIO::CopyJob::Copy, 0); v.setMetaInformation(queryName); //ACTIVE_FUNC->openUrl(url); ACTIVE_MNG->slotNewTab(url); isBusy = false; closeDialog(); } void KrSearchDialog::copyToClipBoard() { QList urls; foreach(vfile *vf, result->vfiles()) urls.push_back(vf->vfile_getUrl()); if (urls.count() == 0) return; QMimeData *mimeData = new QMimeData; mimeData->setImageData(FL_LOADICON("file")); mimeData->setUrls(urls); QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard); } diff --git a/krusader/Search/krsearchdialog.h b/krusader/Search/krsearchdialog.h index 293c9bf7..301eef0d 100644 --- a/krusader/Search/krsearchdialog.h +++ b/krusader/Search/krsearchdialog.h @@ -1,127 +1,129 @@ /*************************************************************************** krsearchdialog.h ------------------- copyright : (C) 2001 by Shie Erlich & Rafi Yanai email : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD H e a d e r F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef KRSEARCHDIALOG_H #define KRSEARCHDIALOG_H -#include -#include -#include +// QtCore +#include +#include +// QtWidgets +#include #include "krsearchmod.h" class QLabel; class SearchResultContainer; class KrView; class KrViewItem; class ProfileManager; class FilterTabs; class GeneralFilter; class QTabWidget; class KSqueezedTextLabel; class KrSqueezedTextLabel; class KrSearchDialog : public QDialog { Q_OBJECT public: KrSearchDialog(QString profile = QString(), QWidget* parent = 0); ~KrSearchDialog(); void prepareGUI(); static KrSearchDialog *SearchDialog; public slots: void startSearch(); void stopSearch(); void feedToListBox(); void copyToClipBoard(); void found(QString what, QString where, KIO::filesize_t size, time_t mtime, QString perm, uid_t uid, gid_t gid, QString foundText); void closeDialog(bool isAccept = true); void executed(const QString &name); void currentChanged(KrViewItem *item); void contextMenu(const QPoint &); virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; virtual void closeEvent(QCloseEvent *e) Q_DECL_OVERRIDE; virtual void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; protected slots: void reject(); private: bool gui2query(); void editCurrent(); void viewCurrent(); void compareByContent(); private: ProfileManager *profileManager; FilterTabs * filterTabs; GeneralFilter * generalFilter; QPushButton* mainSearchBtn; QPushButton* mainStopBtn; QPushButton* mainCloseBtn; QPushButton* mainFeedToListBoxBtn; QTabWidget* searcherTabs; QLabel* foundLabel; KrSqueezedTextLabel *foundTextLabel; KSqueezedTextLabel *searchingLabel; SearchResultContainer *result; KrView *resultView; KRQuery *query; KRSearchMod *searcher; bool isBusy; bool closed; static QString lastSearchText; static int lastSearchType; static bool lastSearchForCase; static bool lastRemoteContentSearch; static bool lastContainsWholeWord; static bool lastContainsWithCase; static bool lastSearchInSubDirs; static bool lastSearchInArchives; static bool lastFollowSymLinks; static bool lastContainsRegExp; int sizeX; int sizeY; }; #endif diff --git a/krusader/Search/krsearchmod.cpp b/krusader/Search/krsearchmod.cpp index cc13fc95..99b30869 100644 --- a/krusader/Search/krsearchmod.cpp +++ b/krusader/Search/krsearchmod.cpp @@ -1,242 +1,244 @@ /*************************************************************************** krsearchmod.cpp ------------------- copyright : (C) 2001 by Shie Erlich & Rafi Yanai email : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD S o u r c e F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "krsearchmod.h" -#include -#include -#include -#include -#include +// QtCore +#include +#include +#include +#include +// QtWidgets +#include #include #include #include "../VFS/krquery.h" #include "../VFS/vfile.h" #include "../VFS/krpermhandler.h" #include "../VFS/krarchandler.h" #define EVENT_PROCESS_DELAY 250 extern KRarcHandler arcHandler; KRSearchMod::KRSearchMod(const KRQuery* q) { stopSearch = false; /// ===> added query = new KRQuery(*q); connect(query, SIGNAL(status(const QString &)), this, SIGNAL(searching(const QString&))); connect(query, SIGNAL(processEvents(bool &)), this, SLOT(slotProcessEvents(bool &))); remote_vfs = 0; virtual_vfs = 0; } KRSearchMod::~KRSearchMod() { delete query; if (remote_vfs) delete remote_vfs; if (virtual_vfs) delete virtual_vfs; } void KRSearchMod::start() { unScannedUrls.clear(); scannedUrls.clear(); timer.start(); QList whereToSearch = query->searchInDirs(); // search every dir that needs to be searched for (int i = 0; i < whereToSearch.count(); ++i) scanURL(whereToSearch [ i ]); emit finished(); } void KRSearchMod::stop() { stopSearch = true; } void KRSearchMod::scanURL(QUrl url) { if (stopSearch) return; unScannedUrls.push(url); while (!unScannedUrls.isEmpty()) { QUrl urlToCheck = unScannedUrls.pop(); if (stopSearch) return; if (query->isExcluded(urlToCheck)) { if (!query->searchInDirs().contains(urlToCheck)) continue; } if (scannedUrls.contains(urlToCheck)) continue; scannedUrls.push(urlToCheck); emit searching(urlToCheck.toDisplayString(QUrl::PreferLocalFile)); if (urlToCheck.isLocalFile()) scanLocalDir(urlToCheck); else scanRemoteDir(urlToCheck); } } void KRSearchMod::scanLocalDir(QUrl urlToScan) { QString dir = vfs::ensureTrailingSlash(urlToScan).path(); QT_DIR* d = QT_OPENDIR(dir.toLocal8Bit()); if (!d) return ; QT_DIRENT* dirEnt; while ((dirEnt = QT_READDIR(d)) != NULL) { QString name = QString::fromLocal8Bit(dirEnt->d_name); // we don't scan the ".",".." enteries if (name == "." || name == "..") continue; QT_STATBUF stat_p; QT_LSTAT((dir + name).toLocal8Bit(), &stat_p); QUrl url = QUrl::fromLocalFile(dir + name); QString mime; if (query->searchInArchives() || !query->hasMimeType()) { QMimeDatabase db; QMimeType mt = db.mimeTypeForUrl(url); if (mt.isValid()) mime = mt.name(); } // creating a vfile object for matching with krquery vfile * vf = new vfile(name, (KIO::filesize_t)stat_p.st_size, KRpermHandler::mode2QString(stat_p.st_mode), stat_p.st_mtime, S_ISLNK(stat_p.st_mode), false/*FIXME*/, stat_p.st_uid, stat_p.st_gid, mime, "", stat_p.st_mode); vf->vfile_setUrl(url); if (query->isRecursive()) { if (S_ISLNK(stat_p.st_mode) && query->followLinks()) unScannedUrls.push(QUrl::fromLocalFile(QDir(dir + name).canonicalPath())); else if (S_ISDIR(stat_p.st_mode)) unScannedUrls.push(url); } if (query->searchInArchives()) { if (KRarcHandler::arcSupported(mime)) { QUrl archiveURL = url; bool encrypted; QString realType = arcHandler.getType(encrypted, url.path(), mime); if (!encrypted) { if (realType == "tbz" || realType == "tgz" || realType == "tarz" || realType == "tar" || realType == "tlz") archiveURL.setScheme("tar"); else archiveURL.setScheme("krarc"); unScannedUrls.push(archiveURL); } } } if (query->match(vf)) { // if we got here - we got a winner results.append(dir + name); emit found(name, dir, (KIO::filesize_t) stat_p.st_size, stat_p.st_mtime, KRpermHandler::mode2QString(stat_p.st_mode), stat_p.st_uid, stat_p.st_gid, query->foundText()); } delete vf; if (timer.elapsed() >= EVENT_PROCESS_DELAY) { qApp->processEvents(); timer.start(); if (stopSearch) return; } } // clean up QT_CLOSEDIR(d); } void KRSearchMod::scanRemoteDir(QUrl url) { vfs * vfs_; if (url.scheme() == QStringLiteral("virt")) { if (virtual_vfs == 0) virtual_vfs = new virt_vfs(0); vfs_ = virtual_vfs; } else { if (remote_vfs == 0) remote_vfs = new ftp_vfs(0); vfs_ = remote_vfs; } if (!vfs_->vfs_refresh(url)) return ; for (vfile * vf = vfs_->vfs_getFirstFile(); vf != 0 ; vf = vfs_->vfs_getNextFile()) { QString name = vf->vfile_getName(); QUrl fileURL = vfs_->vfs_getFile(name); if (query->isRecursive() && ((vf->vfile_isSymLink() && query->followLinks()) || vf->vfile_isDir())) unScannedUrls.push(fileURL); if (query->match(vf)) { // if we got here - we got a winner results.append(fileURL.toDisplayString(QUrl::PreferLocalFile)); emit found(fileURL.fileName(), KIO::upUrl(fileURL).toDisplayString(QUrl::PreferLocalFile | QUrl::StripTrailingSlash), vf->vfile_getSize(), vf->vfile_getTime_t(), vf->vfile_getPerm(), vf->vfile_getUid(), vf->vfile_getGid(), query->foundText()); } if (timer.elapsed() >= EVENT_PROCESS_DELAY) { qApp->processEvents(); timer.start(); if (stopSearch) return; } } } void KRSearchMod::slotProcessEvents(bool & stopped) { qApp->processEvents(); stopped = stopSearch; } diff --git a/krusader/Search/krsearchmod.h b/krusader/Search/krsearchmod.h index a00609be..aa606db2 100644 --- a/krusader/Search/krsearchmod.h +++ b/krusader/Search/krsearchmod.h @@ -1,88 +1,89 @@ /*************************************************************************** krsearchmod.h ------------------- copyright : (C) 2001 by Shie Erlich & Rafi Yanai email : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD H e a d e r F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef KRSEARCHMOD_H #define KRSEARCHMOD_H -#include -#include -#include -#include -#include +// QtCore +#include +#include +#include +#include +#include #include #include "../VFS/ftp_vfs.h" #include "../VFS/virt_vfs.h" class KRQuery; class ftp_vfs; class KRSearchMod : public QObject { Q_OBJECT public: KRSearchMod(const KRQuery *q); ~KRSearchMod(); void scanURL(QUrl url); void start(); void stop(); private: void scanLocalDir(QUrl url); void scanRemoteDir(QUrl url); signals: void finished(); void searching(const QString&); void found(QString what, QString where,KIO::filesize_t size, time_t mtime, QString perm, uid_t owner, gid_t group, QString textFound); private slots: void slotProcessEvents(bool & stopped); private: bool stopSearch; QStack scannedUrls; QStack unScannedUrls; KRQuery *query; QStringList results; ftp_vfs *remote_vfs; virt_vfs *virtual_vfs; QTime timer; }; #endif