diff options
| author | Olivier Goffart <[email protected]> | 2015-09-07 17:47:53 +0200 |
|---|---|---|
| committer | Olivier Goffart <[email protected]> | 2015-11-04 14:21:39 +0100 |
| commit | 800d5114cb1a9b7d5c874f382cc831b4f142469b (patch) | |
| tree | 0a048d981b8d74db205e3e79751ca052cb330665 | |
| parent | 7b273bb4c66de0d2c4f53bcffa418839eb3b5972 (diff) | |
Use the new KOverlayIconPlugin interface from KIO::Widgets
REVIEW: 125675
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.cpp | 37 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.h | 8 |
3 files changed, 45 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f1e2835d..36feb87ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set (KDE_APPLICATIONS_VERSION_MICRO "1") set (KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") set(QT_MIN_VERSION "5.4.0") -set(KF5_MIN_VERSION "5.7.0") +set(KF5_MIN_VERSION "5.16.0") set(ECM_MIN_VERSION "1.6.0") # ECM setup diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 14e301522..d3d3745fc 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -29,6 +29,8 @@ #include <KJobWidgets> #include <KIO/JobUiDelegate> #include <KIO/PreviewJob> +#include <KPluginLoader> +#include <KOverlayIconPlugin> #include "private/kpixmapmodifier.h" #include "private/kdirectorycontentscounter.h" @@ -47,6 +49,7 @@ #include <Baloo/FileMonitor> #endif + // #define KFILEITEMMODELROLESUPDATER_DEBUG namespace { @@ -129,6 +132,18 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO m_directoryContentsCounter = new KDirectoryContentsCounter(m_model, this); connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result, this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived); + + auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, this); + foreach (QObject *it, plugins) { + auto plugin = qobject_cast<KOverlayIconPlugin*>(it); + if (plugin) { + m_overlayIconsPlugin.append(plugin); + connect(plugin, &KOverlayIconPlugin::overlaysChanged, this, &KFileItemModelRolesUpdater::slotOverlaysChanged); + } else { + // not our/valid plugin, so delete the created object + it->deleteLater(); + } + } } KFileItemModelRolesUpdater::~KFileItemModelRolesUpdater() @@ -1065,7 +1080,11 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte data.insert("type", item.mimeComment()); } - data.insert("iconOverlays", item.overlays()); + QStringList overlays = item.overlays(); + foreach(KOverlayIconPlugin *it, m_overlayIconsPlugin) { + overlays.append(it->getOverlays(item.url())); + } + data.insert("iconOverlays", overlays); #ifdef HAVE_BALOO if (m_balooFileMonitor) { @@ -1076,6 +1095,22 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte return data; } +void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl& url, const QStringList &) +{ + const KFileItem item = m_model->fileItem(url); + if (item.isNull()) { + return; + } + const int index = m_model->index(item); + QHash<QByteArray, QVariant> data = m_model->data(index); + QStringList overlays = item.overlays(); + foreach (KOverlayIconPlugin *it, m_overlayIconsPlugin) { + overlays.append(it->getOverlays(url)); + } + data.insert("iconOverlays", overlays); + m_model->setData(index, data); +} + void KFileItemModelRolesUpdater::updateAllPreviews() { if (m_state == Paused) { diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h index 6e7559fb5..f3d40a6c5 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -36,6 +36,7 @@ class KDirectoryContentsCounter; class KFileItemModel; class QPixmap; class QTimer; +class KOverlayIconPlugin; namespace KIO { class PreviewJob; @@ -184,6 +185,11 @@ private slots: void slotPreviewJobFinished(); /** + * Is invoked when one of the KOverlayIconPlugin emit the signal that an overlay has changed + */ + void slotOverlaysChanged(const QUrl& url, const QStringList&); + + /** * Resolves the sort role of the next item in m_pendingSortRole, applies it * to the model, and invokes itself if there are any pending items left. If * that is not the case, \a startUpdating() is called. @@ -334,6 +340,8 @@ private: KDirectoryContentsCounter* m_directoryContentsCounter; + QList<KOverlayIconPlugin*> m_overlayIconsPlugin; + #ifdef HAVE_BALOO Baloo::FileMonitor* m_balooFileMonitor; Baloo::IndexerConfig m_balooConfig; |
