#include <KJobWidgets>
#include <KIO/JobUiDelegate>
#include <KIO/PreviewJob>
+#include <KPluginLoader>
+#include <KOverlayIconPlugin>
#include "private/kpixmapmodifier.h"
#include "private/kdirectorycontentscounter.h"
#include <Baloo/FileMonitor>
#endif
+
// #define KFILEITEMMODELROLESUPDATER_DEBUG
namespace {
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()
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) {
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) {
class KFileItemModel;
class QPixmap;
class QTimer;
+class KOverlayIconPlugin;
namespace KIO {
class PreviewJob;
*/
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
KDirectoryContentsCounter* m_directoryContentsCounter;
+ QList<KOverlayIconPlugin*> m_overlayIconsPlugin;
+
#ifdef HAVE_BALOO
Baloo::FileMonitor* m_balooFileMonitor;
Baloo::IndexerConfig m_balooConfig;