From 46d2d147bf0bcbfc6c8a69e1c49e0590b679b7b4 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Thu, 24 Aug 2023 10:27:02 +0200 Subject: Special case file opening with middle click for executable scripts Since the first action would launch the script, we can use the first application associated to open the file. --- src/dolphinviewcontainer.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/dolphinviewcontainer.cpp') diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index ffd0d9b5e..2811a1ee4 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -745,8 +745,23 @@ void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item) { KService::List services = KApplicationTrader::queryByMimeType(item.mimetype()); - if (services.length() >= 2) { - auto service = services.at(1); + int indexOfAppToOpenFileWith = 1; + + // executable scripts + auto mimeType = item.currentMimeType(); + if (item.isLocalFile() && mimeType.inherits(QStringLiteral("application/x-executable")) && mimeType.inherits(QStringLiteral("text/plain")) + && QFileInfo(item.localPath()).isExecutable()) { + KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts"); + const QString value = cfgGroup.readEntry("behaviourOnLaunch", "alwaysAsk"); + + // in case KIO::WidgetsOpenOrExecuteFileHandler::promptUserOpenOrExecute would not open the file + if (value != QLatin1String("open")) { + indexOfAppToOpenFileWith = 0; + } + } + + if (services.length() >= indexOfAppToOpenFileWith + 1) { + auto service = services.at(indexOfAppToOpenFileWith); KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this); job->setUrls({item.url()}); -- cgit v1.3 From 1318f16fd7b84de79c04eb468d61e1c9b7b52e15 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Mon, 28 Aug 2023 10:32:35 +0200 Subject: Clean obsolete ifdefs since dolphin requires KF 5.101+ --- src/dolphincontextmenu.cpp | 8 ---- src/dolphinmainwindow.cpp | 30 --------------- src/dolphinpart.cpp | 8 ---- src/dolphinviewcontainer.cpp | 16 +------- src/kitemviews/kfileitemmodel.cpp | 12 ------ src/panels/folders/treeviewcontextmenu.cpp | 30 +-------------- .../contextmenu/contextmenusettingspage.cpp | 9 ----- src/settings/dolphinsettingsdialog.cpp | 12 ------ src/settings/viewpropertiesdialog.cpp | 8 ---- src/tests/kfileitemmodeltest.cpp | 3 -- src/trash/dolphintrash.cpp | 19 +-------- src/views/dolphinview.cpp | 45 +--------------------- 12 files changed, 5 insertions(+), 195 deletions(-) (limited to 'src/dolphinviewcontainer.cpp') diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 4addf53cd..99db5584c 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -171,11 +171,7 @@ void DolphinContextMenu::addDirectoryItemContextMenu() // set up 'Create New' menu DolphinNewFileMenu *newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); newFileMenu->checkUpToDate(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) newFileMenu->setWorkingDirectory(m_fileInfo.url()); -#else - newFileMenu->setPopupFiles(QList() << m_fileInfo.url()); -#endif newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); @@ -281,11 +277,7 @@ void DolphinContextMenu::addViewportContextMenu() // Set up and insert 'Create New' menu KNewFileMenu *newFileMenu = m_mainWindow->newFileMenu(); newFileMenu->checkUpToDate(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) newFileMenu->setWorkingDirectory(m_baseUrl); -#else - newFileMenu->setPopupFiles(QList() << m_baseUrl); -#endif addMenu(newFileMenu->menu()); // Show "open with" menu items even if the dir is empty, because there are legitimate diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index afb86e152..38843f82c 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -42,12 +42,7 @@ #include #include #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) #include -#else -#include -#endif #include #include #include @@ -69,9 +64,7 @@ #include #include #include - #include -#include #include #include @@ -676,20 +669,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup &group) void DolphinMainWindow::updateNewMenu() { m_newFileMenu->checkUpToDate(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); -#else - m_newFileMenu->setPopupFiles(QList() << activeViewContainer()->url()); -#endif } void DolphinMainWindow::createDirectory() { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); -#else - m_newFileMenu->setPopupFiles(QList() << activeViewContainer()->url()); -#endif m_newFileMenu->createDirectory(); } @@ -1177,25 +1162,14 @@ void DolphinMainWindow::openTerminalHere() if (urls.count() > 5) { QString question = i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls.count()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const int answer = KMessageBox::warningTwoActions( this, question, {}, -#else - const int answer = KMessageBox::warningYesNo( - this, - question, - {}, -#endif KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), QStringLiteral("utilities-terminal")), KStandardGuiItem::cancel(), QStringLiteral("ConfirmOpenManyTerminals")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) { -#else - if (answer != KMessageBox::Yes && answer != KMessageBox::Continue) { -#endif return; } } @@ -1265,11 +1239,7 @@ void DolphinMainWindow::handleUrl(const QUrl &url) activeViewContainer()->setUrl(url); } else { m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#else - m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#endif m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true); connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) { diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index f8da1c353..aac278035 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -548,11 +548,7 @@ void DolphinPart::updateNewMenu() // As requested by KNewFileMenu : m_newFileMenu->checkUpToDate(); // And set the files that the menu apply on : -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) m_newFileMenu->setWorkingDirectory(url()); -#else - m_newFileMenu->setPopupFiles(QList() << url()); -#endif } void DolphinPart::updateStatusBar() @@ -567,11 +563,7 @@ void DolphinPart::updateProgress(int percent) void DolphinPart::createDirectory() { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0) m_newFileMenu->setWorkingDirectory(url()); -#else - m_newFileMenu->setPopupFiles(QList() << url()); -#endif m_newFileMenu->createDirectory(); } diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 2811a1ee4..63d5bd27b 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -23,20 +23,16 @@ #if HAVE_KACTIVITIES #include #endif +#include #include #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) #include -#else -#include -#endif -#include #include #include #include #include #include +#include #include #include @@ -731,11 +727,7 @@ void DolphinViewContainer::slotItemActivated(const KFileItem &item) } KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl(), item.mimetype()); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#else - job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#endif job->setShowOpenOrExecuteDialog(true); connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished); job->start(); @@ -766,11 +758,7 @@ void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item) KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this); job->setUrls({item.url()}); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#else - job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); -#endif connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished); job->start(); } diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index bbe725dfd..40c76c7ef 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -263,11 +263,7 @@ void KFileItemModel::setShowTrashMime(bool show) void KFileItemModel::setShowHiddenFiles(bool show) { -#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0) - m_dirLister->setShowingDotFiles(show); -#else m_dirLister->setShowHiddenFiles(show); -#endif setShowTrashMime(show); m_dirLister->emitChanges(); if (show) { @@ -277,11 +273,7 @@ void KFileItemModel::setShowHiddenFiles(bool show) bool KFileItemModel::showHiddenFiles() const { -#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0) - return m_dirLister->showingDotFiles(); -#else return m_dirLister->showHiddenFiles(); -#endif } void KFileItemModel::setShowDirectoriesOnly(bool enabled) @@ -624,9 +616,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded) m_expandedDirs.remove(targetUrl); m_dirLister->stop(url); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0) m_dirLister->forgetDirs(url); -#endif const int parentLevel = expandedParentsCount(index); const int itemCount = m_itemData.count(); @@ -642,9 +632,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded) const QUrl url = itemData->item.url(); m_expandedDirs.remove(targetUrl); m_dirLister->stop(url); // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11 -#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0) m_dirLister->forgetDirs(url); -#endif expandedChildren.append(targetUrl); } ++childIndex; diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index e063ca85e..45e146a2e 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -22,13 +22,8 @@ #include #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) #include -#else -#include -#include -#endif +#include #include #include @@ -197,39 +192,16 @@ void TreeViewContextMenu::rename() void TreeViewContextMenu::moveToTrash() { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *deleteJob = new KIO::DeleteOrTrashJob(QList{m_fileItem.url()}, Iface::Trash, Iface::DefaultConfirmation, m_parent); deleteJob->start(); -#else - const QList list{m_fileItem.url()}; - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(m_parent); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::trash(list); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); - KJobWidgets::setWindow(job, m_parent); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } -#endif } void TreeViewContextMenu::deleteItem() { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *deleteJob = new KIO::DeleteOrTrashJob(QList{m_fileItem.url()}, Iface::Delete, Iface::DefaultConfirmation, m_parent); deleteJob->start(); -#else - const QList list{m_fileItem.url()}; - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(m_parent); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::del(list); - KJobWidgets::setWindow(job, m_parent); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } -#endif } void TreeViewContextMenu::showProperties() diff --git a/src/settings/contextmenu/contextmenusettingspage.cpp b/src/settings/contextmenu/contextmenusettingspage.cpp index 03e55ba32..fa3d0b256 100644 --- a/src/settings/contextmenu/contextmenusettingspage.cpp +++ b/src/settings/contextmenu/contextmenusettingspage.cpp @@ -206,24 +206,15 @@ void ContextMenuSettingsPage::applySettings() VersionControlSettings::self()->save(); if (!laterSelected) { -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) KMessageBox::ButtonCode promptRestart = KMessageBox::questionTwoActions(window(), -#else - KMessageBox::ButtonCode promptRestart = - KMessageBox::questionYesNo(window(), -#endif i18nc("@info", "Dolphin must be restarted to apply the " "updated version control system settings."), i18nc("@info", "Restart now?"), KGuiItem(QApplication::translate("KStandardGuiItem", "&Restart"), QStringLiteral("dialog-restart")), KGuiItem(QApplication::translate("KStandardGuiItem", "&Later"), QStringLiteral("dialog-later"))); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (promptRestart == KMessageBox::ButtonCode::PrimaryAction) { -#else - if (promptRestart == KMessageBox::ButtonCode::Yes) { -#endif Dolphin::openNewWindow(); qApp->quit(); } else { diff --git a/src/settings/dolphinsettingsdialog.cpp b/src/settings/dolphinsettingsdialog.cpp index 45aa7b65a..3a2ad31e9 100644 --- a/src/settings/dolphinsettingsdialog.cpp +++ b/src/settings/dolphinsettingsdialog.cpp @@ -160,29 +160,17 @@ void DolphinSettingsDialog::closeEvent(QCloseEvent *event) return; } -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const auto response = KMessageBox::warningTwoActionsCancel(this, -#else - const auto response = KMessageBox::warningYesNoCancel(this, -#endif i18n("You have unsaved changes. Do you want to apply the changes or discard them?"), i18n("Warning"), KStandardGuiItem::save(), KStandardGuiItem::discard(), KStandardGuiItem::cancel()); switch (response) { -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) case KMessageBox::PrimaryAction: -#else - case KMessageBox::Yes: -#endif applySettings(); Q_FALLTHROUGH(); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) case KMessageBox::SecondaryAction: -#else - case KMessageBox::No: -#endif event->accept(); break; case KMessageBox::Cancel: diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp index f7bd754b1..c630f8113 100644 --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -333,11 +333,7 @@ void ViewPropertiesDialog::applyViewProperties() const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked(); if (applyToSubFolders) { const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (KMessageBox::questionTwoActions(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) { -#else - if (KMessageBox::questionYesNo(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::No) { -#endif return; } @@ -367,11 +363,7 @@ void ViewPropertiesDialog::applyViewProperties() if (applyToAllFolders) { const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (KMessageBox::questionTwoActions(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) { -#else - if (KMessageBox::questionYesNo(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::No) { -#endif return; } diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 38d2544aa..753960a08 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -2479,9 +2479,6 @@ void KFileItemModelTest::testInsertAfterExpand() // Insert additional files into "a/b/" m_testDir->createFile("a/b/2"); -#if KIO_VERSION < QT_VERSION_CHECK(5, 92, 0) - QEXPECT_FAIL("", "Requires new API from frameworks", Abort); -#endif QVERIFY(!itemsInsertedSpy.wait(5000)); diff --git a/src/trash/dolphintrash.cpp b/src/trash/dolphintrash.cpp index b37a7430d..007f48a33 100644 --- a/src/trash/dolphintrash.cpp +++ b/src/trash/dolphintrash.cpp @@ -13,13 +13,8 @@ #include #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) #include -#else -#include -#include -#endif +#include Trash::Trash() : m_trashDirLister(new KDirLister()) @@ -62,22 +57,10 @@ static void notifyEmptied() void Trash::empty(QWidget *window) { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *emptyJob = new KIO::DeleteOrTrashJob(QList{}, Iface::EmptyTrash, Iface::DefaultConfirmation, window); QObject::connect(emptyJob, &KIO::Job::result, notifyEmptied); emptyJob->start(); -#else - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window); - bool confirmed = uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation); - if (confirmed) { - KIO::Job *job = KIO::emptyTrash(); - KJobWidgets::setWindow(job, window); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - QObject::connect(job, &KIO::Job::result, notifyEmptied); - } -#endif } bool Trash::isEmpty() diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 1d01b4c98..d525df4c6 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -49,10 +49,8 @@ #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) #include -#endif +#include #include #include @@ -758,43 +756,22 @@ void DolphinView::trashSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Trash, Iface::DefaultConfirmation, this); connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished); m_selectNextItem = true; trashJob->start(); -#else - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::trash(list); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotTrashFileFinished); - } -#endif } void DolphinView::deleteSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Delete, Iface::DefaultConfirmation, this); connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished); m_selectNextItem = true; trashJob->start(); -#else - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::del(list); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotDeleteFileFinished); - } -#endif } void DolphinView::cutSelectedItemsToClipboard() @@ -1081,25 +1058,14 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes) if (indexes.count() > 5) { QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const int answer = KMessageBox::warningTwoActions( this, question, {}, -#else - const int answer = - KMessageBox::warningYesNo(this, - question, - {}, -#endif KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()), QStringLiteral("document-open")), KStandardGuiItem::cancel(), QStringLiteral("ConfirmOpenManyFolders")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) { -#else - if (answer != KMessageBox::Yes && answer != KMessageBox::Continue) { -#endif return; } } @@ -2025,13 +1991,8 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { KGuiItem yesGuiItem(i18nc("@action:button", "Rename and Hide"), QStringLiteral("view-hidden")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const auto code = KMessageBox::questionTwoActions(this, -#else - const auto code = - KMessageBox::questionYesNo(this, -#endif oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" "Do you still want to rename it?") : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" @@ -2041,11 +2002,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con KStandardGuiItem::cancel(), QStringLiteral("ConfirmHide")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (code == KMessageBox::SecondaryAction) { -#else - if (code == KMessageBox::No) { -#endif return; } } -- cgit v1.3 From c4bb3db0229bef8adee1daa183892cebba5efe72 Mon Sep 17 00:00:00 2001 From: Amol Godbole Date: Mon, 4 Sep 2023 07:39:13 +0000 Subject: Restore the URL when DolphinSearchBox is cleared Currently, the URL navigator is not updated when the search box is cleared. This MR restores the URL, by closing and reopening the box. The call for emitting closeRequest() on pressing Esc has been replaced with emitCloseRequest(). The wait duration before starting a search has been reduced to 500ms to increase responsiveness. Also, the bugfix for BUG: 423328 is slightly incorrect and causes the search term to not be displayed when opening a saved search for the first time. As a better solution for this bug, DolphinSearchBox::setText() now updates the text only if the text has changed. BUG: 473775 --- src/dolphinviewcontainer.cpp | 6 ++++++ src/dolphinviewcontainer.h | 1 + src/search/dolphinsearchbox.cpp | 25 ++++++++++++++++--------- src/search/dolphinsearchbox.h | 5 +++++ 4 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src/dolphinviewcontainer.cpp') diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 63d5bd27b..66a9a116a 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -84,6 +84,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent) m_searchBox = new DolphinSearchBox(this); m_searchBox->hide(); connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate); + connect(m_searchBox, &DolphinSearchBox::openRequest, this, &DolphinViewContainer::openSearchBox); connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox); connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching); connect(m_searchBox, &DolphinSearchBox::focusViewRequest, this, &DolphinViewContainer::requestFocus); @@ -891,6 +892,11 @@ void DolphinViewContainer::startSearching() } } +void DolphinViewContainer::openSearchBox() +{ + setSearchModeEnabled(true); +} + void DolphinViewContainer::closeSearchBox() { setSearchModeEnabled(false); diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 0c8b184fe..52fd688f6 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -382,6 +382,7 @@ private Q_SLOTS: * Gets the search URL from the searchbox and starts searching. */ void startSearching(); + void openSearchBox(); void closeSearchBox(); /** diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 9df417c4f..a09f25293 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -60,7 +60,9 @@ DolphinSearchBox::~DolphinSearchBox() void DolphinSearchBox::setText(const QString &text) { - m_searchInput->setText(text); + if (m_searchInput->text() != text) { + m_searchInput->setText(text); + } } QString DolphinSearchBox::text() const @@ -201,7 +203,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event) QWidget::keyReleaseEvent(event); if (event->key() == Qt::Key_Escape) { if (m_searchInput->text().isEmpty()) { - Q_EMIT closeRequest(); + emitCloseRequest(); } else { m_searchInput->clear(); } @@ -261,7 +263,11 @@ void DolphinSearchBox::slotConfigurationChanged() void DolphinSearchBox::slotSearchTextChanged(const QString &text) { if (text.isEmpty()) { - m_startSearchTimer->stop(); + // Restore URL when search box is cleared by closing and reopening the box. + emitCloseRequest(); + QTimer::singleShot(0, this, [this] { + Q_EMIT openRequest(); + }); } else { m_startSearchTimer->start(); } @@ -270,6 +276,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text) void DolphinSearchBox::slotReturnPressed() { + if (m_searchInput->text().isEmpty()) { + return; + } + emitSearchRequest(); Q_EMIT focusViewRequest(); } @@ -443,10 +453,10 @@ void DolphinSearchBox::init() loadSettings(); // The searching should be started automatically after the user did not change - // the text within one second + // the text for a while m_startSearchTimer = new QTimer(this); m_startSearchTimer->setSingleShot(true); - m_startSearchTimer->setInterval(1000); + m_startSearchTimer->setInterval(500); connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest); } @@ -496,10 +506,7 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery &query) setSearchPath(QUrl::fromLocalFile(QDir::homePath())); } - // If the input box has focus, do not update to avoid messing with user typing - if (!m_searchInput->hasFocus()) { - setText(query.text()); - } + setText(query.text()); if (query.hasContentSearch()) { m_contentButton->setChecked(true); diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 4ccb7ac10..b73c2899f 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -111,6 +111,11 @@ Q_SIGNALS: */ void closeRequest(); + /** + * Is emitted when the search box should be opened. + */ + void openRequest(); + /** * Is emitted, if the searchbox has been activated by * an user interaction -- cgit v1.3