]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/tooltips/tooltipmanager.cpp
Merge branch 'release/22.04'
[dolphin.git] / src / views / tooltips / tooltipmanager.cpp
index aae97458cfd6bbadfb606840366fec6b7765da7e..e80d45e614c1c9125d821672ddc64befdb0f293c 100644 (file)
@@ -1,21 +1,8 @@
-/*******************************************************************************
- *   Copyright (C) 2008 by Konstantin Heil <konst.heil@stud.uni-heidelberg.de> *
- *                                                                             *
- *   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.                                       *
- *                                                                             *
- *   This program is distributed in the hope that it will be useful,           *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of            *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
- *   GNU General Public License for more details.                              *
- *                                                                             *
- *   You should have received a copy of the GNU General Public License         *
- *   along with this program; if not, write to the                             *
- *   Free Software Foundation, Inc.,                                           *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA                *
- *******************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2008 Konstantin Heil <konst.heil@stud.uni-heidelberg.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "tooltipmanager.h"
 
@@ -23,7 +10,9 @@
 
 #include <KIO/JobUiDelegate>
 #include <KIO/PreviewJob>
+#include <KConfigGroup>
 #include <KJobWidgets>
+#include <KSharedConfig>
 #include <KToolTipWidget>
 #include <KIconLoader>
 
@@ -72,6 +61,13 @@ ToolTipManager::ToolTipManager(QWidget* parent) :
     connect(m_contentRetrievalTimer, &QTimer::timeout, this, &ToolTipManager::startContentRetrieval);
 
     Q_ASSERT(m_contentRetrievalTimer->interval() < m_showToolTipTimer->interval());
+
+    // Only start the retrieving of the content, when the mouse has been over this
+    // item for 200 milliseconds. This prevents a lot of useless preview jobs and
+    // meta data retrieval, when passing rapidly over a lot of items.
+    m_fileMetaDataWidget = new DolphinFileMetaDataWidget(parent);
+    connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished);
+    connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::urlActivated, this, &ToolTipManager::urlActivated);
 }
 
 ToolTipManager::~ToolTipManager()
@@ -80,7 +76,7 @@ ToolTipManager::~ToolTipManager()
 
 void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, QWindow *transientParent)
 {
-    hideToolTip();
+    hideToolTip(HideBehavior::Instantly);
 
     m_itemRect = itemRect.toRect();
 
@@ -89,22 +85,13 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect,
 
     m_transientParent = transientParent;
 
-    // Only start the retrieving of the content, when the mouse has been over this
-    // item for 200 milliseconds. This prevents a lot of useless preview jobs and
-    // meta data retrieval, when passing rapidly over a lot of items.
-    m_fileMetaDataWidget.reset(new DolphinFileMetaDataWidget());
-    connect(m_fileMetaDataWidget.data(), &DolphinFileMetaDataWidget::metaDataRequestFinished,
-            this, &ToolTipManager::slotMetaDataRequestFinished);
-    connect(m_fileMetaDataWidget.data(), &DolphinFileMetaDataWidget::urlActivated,
-            this, &ToolTipManager::urlActivated);
-
     m_contentRetrievalTimer->start();
     m_showToolTipTimer->start();
     m_toolTipRequested = true;
     Q_ASSERT(!m_metaDataRequested);
 }
 
-void ToolTipManager::hideToolTip()
+void ToolTipManager::hideToolTip(const HideBehavior behavior)
 {
     if (m_appliedWaitCursor) {
         QApplication::restoreOverrideCursor();
@@ -116,7 +103,14 @@ void ToolTipManager::hideToolTip()
     m_showToolTipTimer->stop();
     m_contentRetrievalTimer->stop();
     if (m_tooltipWidget) {
-        m_tooltipWidget->hideLater();
+        switch (behavior) {
+        case HideBehavior::Instantly:
+            m_tooltipWidget->hide();
+            break;
+        case HideBehavior::Later:
+            m_tooltipWidget->hideLater();
+            break;
+        }
     }
 }
 
@@ -138,11 +132,12 @@ void ToolTipManager::startContentRetrieval()
     // Request a preview of the item
     m_fileMetaDataWidget->setPreview(QPixmap());
 
-    QStringList plugins = KIO::PreviewJob::availablePlugins();
+    const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
+    const QStringList plugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins());
     KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << m_item,
                                                QSize(256, 256),
                                                &plugins);
-    job->setIgnoreMaximumSize(m_item.isLocalFile());
+    job->setIgnoreMaximumSize(m_item.isLocalFile() && !m_item.isSlow());
     if (job->uiDelegate()) {
         KJobWidgets::setWindow(job, qApp->activeWindow());
     }
@@ -223,7 +218,7 @@ void ToolTipManager::showToolTip()
     if (!m_tooltipWidget) {
         m_tooltipWidget.reset(new KToolTipWidget());
     }
-    m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget.data(), m_transientParent);
+    m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget, m_transientParent);
     m_toolTipRequested = false;
 }