]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
portalize drag urls
[dolphin.git] / src / views / dolphinview.cpp
index c4e5be30a4b0c56e3ff27981005e9776ab0da980..5e7c63e82748979dd759b4a31070c8084b6420b1 100644 (file)
@@ -25,7 +25,7 @@
 #include "views/tooltips/tooltipmanager.h"
 #include "zoomlevelinfo.h"
 
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
 #include <Baloo/IndexerConfig>
 #endif
 #include <KColorScheme>
@@ -45,6 +45,7 @@
 #include <KLocalizedString>
 #include <KMessageBox>
 #include <KProtocolManager>
+#include <KUrlMimeData>
 
 #include <QAbstractItemView>
 #include <QActionGroup>
@@ -70,7 +71,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),
@@ -202,14 +202,14 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
             this, &DolphinView::slotRoleEditingCanceled);
     connect(m_view->header(), &KItemListHeader::columnWidthChangeFinished,
             this, &DolphinView::slotHeaderColumnWidthChangeFinished);
-    connect(m_view->header(), &KItemListHeader::leadingPaddingChanged,
-            this, &DolphinView::slotLeadingPaddingWidthChanged);
+    connect(m_view->header(), &KItemListHeader::sidePaddingChanged,
+            this, &DolphinView::slotSidePaddingWidthChanged);
 
     KItemListSelectionManager* selectionManager = controller->selectionManager();
     connect(selectionManager, &KItemListSelectionManager::selectionChanged,
             this, &DolphinView::slotSelectionChanged);
 
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
     m_toolTipManager = new ToolTipManager(this);
     connect(m_toolTipManager, &ToolTipManager::urlActivated, this, &DolphinView::urlActivated);
 #endif
@@ -758,12 +758,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 +927,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::ToolTip:
-        tryShowNameToolTip(event);
+        tryShowNameToolTip(static_cast<QHelpEvent*>(event));
 
     default:
         break;
@@ -1076,7 +1078,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     const QList<QByteArray> visibleRolesSet = view->visibleRoles();
 
     bool indexingEnabled = false;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
     Baloo::IndexerConfig config;
     indexingEnabled = config.fileIndexingEnabled();
 #endif
@@ -1120,9 +1122,9 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     QActionGroup* widthsGroup = new QActionGroup(menu);
     const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
 
-    QAction* toggleLeadingPaddingAction = menu->addAction(i18nc("@action:inmenu", "Leading Column Padding"));
-    toggleLeadingPaddingAction->setCheckable(true);
-    toggleLeadingPaddingAction->setChecked(view->header()->leadingPadding() > 0);
+    QAction* toggleSidePaddingAction = menu->addAction(i18nc("@action:inmenu", "Side Padding"));
+    toggleSidePaddingAction->setCheckable(true);
+    toggleSidePaddingAction->setChecked(view->header()->sidePadding() > 0);
 
     QAction* autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
     autoAdjustWidthsAction->setCheckable(true);
@@ -1154,8 +1156,8 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
             }
             props.setHeaderColumnWidths(columnWidths);
             header->setAutomaticColumnResizing(false);
-        } else if (action == toggleLeadingPaddingAction) {
-            header->setLeadingPadding(toggleLeadingPaddingAction->isChecked() ? 20 : 0);
+        } else if (action == toggleSidePaddingAction) {
+            header->setSidePadding(toggleSidePaddingAction->isChecked() ? 20 : 0);
         } else {
             // Show or hide the selected role
             const QByteArray selectedRole = action->data().toByteArray();
@@ -1208,10 +1210,10 @@ void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray& role, qr
     props.setHeaderColumnWidths(columnWidths);
 }
 
-void DolphinView::slotLeadingPaddingWidthChanged(qreal width)
+void DolphinView::slotSidePaddingWidthChanged(qreal width)
 {
     ViewProperties props(viewPropertiesUrl());
-    DetailsModeSettings::setLeadingPadding(int(width));
+    DetailsModeSettings::setSidePadding(int(width));
     m_view->writeSettings();
 }
 
@@ -1224,8 +1226,11 @@ void DolphinView::slotItemHovered(int index)
         const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
         itemRect.moveTo(pos);
 
-#ifdef HAVE_BALOO
-        m_toolTipManager->showToolTip(item, itemRect, nativeParentWidget()->windowHandle());
+#if HAVE_BALOO
+        auto nativeParent = nativeParentWidget();
+        if (nativeParent) {
+            m_toolTipManager->showToolTip(item, itemRect, nativeParent->windowHandle());
+        }
 #endif
     }
 
@@ -1663,7 +1668,7 @@ void DolphinView::updateViewState()
 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
 {
     if (GeneralSettings::showToolTips()) {
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
         m_toolTipManager->hideToolTip(behavior);
 #else
         Q_UNUSED(behavior)
@@ -1725,7 +1730,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
@@ -1740,7 +1745,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.
@@ -1757,7 +1762,7 @@ void DolphinView::slotDirectoryLoadingCompleted()
 
 void DolphinView::slotDirectoryLoadingCanceled()
 {
-    m_loading = false;
+    m_loadingState = LoadingState::Canceled;
 
     updatePlaceholderLabel();
 
@@ -2011,7 +2016,7 @@ void DolphinView::applyViewProperties(const ViewProperties& props)
         } else {
             header->setAutomaticColumnResizing(true);
         }
-        header->setLeadingPadding(DetailsModeSettings::leadingPadding());
+        header->setSidePadding(DetailsModeSettings::sidePadding());
     }
 
     m_view->endTransaction();
@@ -2156,13 +2161,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"));
@@ -2193,11 +2200,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;
@@ -2209,7 +2215,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);
         }
     }