]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Don't show error message on ERR_USER_CANCELED
[dolphin.git] / src / views / dolphinview.cpp
index 168e282b535f874aab36cc4cea2e2eb032ecc9be..a00d485c85dc3c4008712a686915cb1df09eeb67 100644 (file)
@@ -20,6 +20,7 @@
 #include "kitemviews/kitemlistselectionmanager.h"
 #include "kitemviews/private/kitemlistroleeditor.h"
 #include "settings/viewmodes/viewmodesettings.h"
+#include "selectionmode/singleclickselectionproxystyle.h"
 #include "versioncontrol/versioncontrolobserver.h"
 #include "viewproperties.h"
 #include "views/tooltips/tooltipmanager.h"
@@ -45,6 +46,7 @@
 #include <KLocalizedString>
 #include <KMessageBox>
 #include <KProtocolManager>
+#include <KUrlMimeData>
 
 #include <QAbstractItemView>
 #include <QActionGroup>
@@ -70,7 +72,6 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
     m_assureVisibleCurrentIndex(false),
     m_isFolderWritable(true),
     m_dragging(false),
-    m_loading(false),
     m_url(url),
     m_viewPropertiesContext(),
     m_mode(DolphinView::IconsView),
@@ -110,7 +111,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
 
     m_model = new KFileItemModel(this);
     m_view = new DolphinItemListView();
-    m_view->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
+    m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting);
     m_view->setVisibleRoles({"text"});
     applyModeToView();
 
@@ -172,6 +173,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
     connect(controller, &KItemListController::increaseZoom, this, &DolphinView::slotIncreaseZoom);
     connect(controller, &KItemListController::decreaseZoom, this, &DolphinView::slotDecreaseZoom);
     connect(controller, &KItemListController::swipeUp, this, &DolphinView::slotSwipeUp);
+    connect(controller, &KItemListController::selectionModeChangeRequested, this, &DolphinView::selectionModeChangeRequested);
 
     connect(m_model, &KFileItemModel::directoryLoadingStarted,       this, &DolphinView::slotDirectoryLoadingStarted);
     connect(m_model, &KFileItemModel::directoryLoadingCompleted,     this, &DolphinView::slotDirectoryLoadingCompleted);
@@ -262,7 +264,7 @@ bool DolphinView::isActive() const
     return m_active;
 }
 
-void DolphinView::setMode(Mode mode)
+void DolphinView::setViewMode(Mode mode)
 {
     if (mode != m_mode) {
         ViewProperties props(viewPropertiesUrl());
@@ -276,11 +278,31 @@ void DolphinView::setMode(Mode mode)
     }
 }
 
-DolphinView::Mode DolphinView::mode() const
+DolphinView::Mode DolphinView::viewMode() const
 {
     return m_mode;
 }
 
+void DolphinView::setSelectionModeEnabled(const bool enabled)
+{
+    if (enabled) {
+        m_proxyStyle = std::make_unique<SelectionMode::SingleClickSelectionProxyStyle>();
+        setStyle(m_proxyStyle.get());
+        m_view->setStyle(m_proxyStyle.get());
+        m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False);
+    } else {
+        setStyle(QApplication::style());
+        m_view->setStyle(QApplication::style());
+        m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting);
+    }
+    m_container->controller()->setSelectionModeEnabled(enabled);
+}
+
+bool DolphinView::selectionMode() const
+{
+    return m_container->controller()->selectionMode();
+}
+
 void DolphinView::setPreviewsShown(bool show)
 {
     if (previewsShown() == show) {
@@ -758,12 +780,14 @@ void DolphinView::cutSelectedItemsToClipboard()
 {
     QMimeData* mimeData = selectionMimeData();
     KIO::setClipboardDataCut(mimeData, true);
+    KUrlMimeData::exportUrlsToPortal(mimeData);
     QApplication::clipboard()->setMimeData(mimeData);
 }
 
 void DolphinView::copySelectedItemsToClipboard()
 {
-    QMimeData* mimeData = selectionMimeData();
+    QMimeData *mimeData = selectionMimeData();
+    KUrlMimeData::exportUrlsToPortal(mimeData);
     QApplication::clipboard()->setMimeData(mimeData);
 }
 
@@ -925,7 +949,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::ToolTip:
-        tryShowNameToolTip(event);
+        tryShowNameToolTip(static_cast<QHelpEvent*>(event));
 
     default:
         break;
@@ -993,7 +1017,10 @@ 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());
-        const int answer = KMessageBox::warningYesNo(this, question);
+        const int answer = KMessageBox::warningYesNo(this, question, {},
+                                                     KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()),
+                                                              QStringLiteral("document-open")),
+                                                     KStandardGuiItem::cancel());
         if (answer != KMessageBox::Yes) {
             return;
         }
@@ -1340,7 +1367,7 @@ void DolphinView::slotItemCreated(const QUrl& url)
 
 void DolphinView::slotJobResult(KJob *job)
 {
-    if (job->error()) {
+    if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
         Q_EMIT errorMessage(job->errorString());
     }
     if (!m_selectedUrls.isEmpty()) {
@@ -1728,7 +1755,7 @@ void DolphinView::slotRenamingResult(KJob* job)
 
 void DolphinView::slotDirectoryLoadingStarted()
 {
-    m_loading = true;
+    m_loadingState = LoadingState::Loading;
     updatePlaceholderLabel();
 
     // Disable the writestate temporary until it can be determined in a fast way
@@ -1743,7 +1770,7 @@ void DolphinView::slotDirectoryLoadingStarted()
 
 void DolphinView::slotDirectoryLoadingCompleted()
 {
-    m_loading = false;
+    m_loadingState = LoadingState::Completed;
 
     // Update the view-state. This has to be done asynchronously
     // because the view might not be in its final state yet.
@@ -1760,7 +1787,7 @@ void DolphinView::slotDirectoryLoadingCompleted()
 
 void DolphinView::slotDirectoryLoadingCanceled()
 {
-    m_loading = false;
+    m_loadingState = LoadingState::Canceled;
 
     updatePlaceholderLabel();
 
@@ -2159,13 +2186,15 @@ void DolphinView::updatePlaceholderLabel()
         return;
     }
 
-    if (m_loading) {
+    if (m_loadingState == LoadingState::Loading) {
         m_placeholderLabel->setVisible(false);
         m_showLoadingPlaceholderTimer->start();
         return;
     }
 
-    if (!nameFilter().isEmpty()) {
+    if (m_loadingState == LoadingState::Canceled) {
+        m_placeholderLabel->setText(i18n("Loading canceled"));
+    } else if (!nameFilter().isEmpty()) {
         m_placeholderLabel->setText(i18n("No items matching the filter"));
     } else if (m_url.scheme() == QLatin1String("baloosearch") || m_url.scheme() == QLatin1String("filenamesearch")) {
         m_placeholderLabel->setText(i18n("No items matching the search"));
@@ -2196,11 +2225,10 @@ void DolphinView::updatePlaceholderLabel()
     m_placeholderLabel->setVisible(true);
 }
 
-void DolphinView::tryShowNameToolTip(QEvent* event)
+void DolphinView::tryShowNameToolTip(QHelpEvent* event)
 {
     if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) {
-        QHelpEvent *hoverEvent = reinterpret_cast<QHelpEvent *>(event);
-        const std::optional<int> index = m_view->itemAt(hoverEvent->pos());
+        const std::optional<int> index = m_view->itemAt(event->pos());
 
         if (!index.has_value()) {
             return;
@@ -2212,7 +2240,7 @@ void DolphinView::tryShowNameToolTip(QEvent* event)
         if(isElided) {
             const KFileItem item = m_model->fileItem(index.value());
             const QString text = item.text();
-            const QPoint pos = mapToGlobal(hoverEvent->pos());
+            const QPoint pos = mapToGlobal(event->pos());
             QToolTip::showText(pos, text);
         }
     }