#include <KConfig>
#include <KConfigGroup>
-#include <KIO/JobUiDelegate>
#include <KIO/PreviewJob>
#include <KIconLoader>
#include <KJobWidgets>
#include <KOverlayIconPlugin>
-#include <KPluginLoader>
+#include <KPluginMetaData>
#include <KSharedConfig>
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
#include "private/kbaloorolesprovider.h"
#include <Baloo/File>
#include <Baloo/FileMonitor>
#endif
#include <QApplication>
-#include <QIcon>
-#include <QPainter>
#include <QElapsedTimer>
+#include <QFileInfo>
+#include <QPainter>
+#include <QPluginLoader>
#include <QTimer>
+#include <chrono>
+
+using namespace std::chrono_literals;
// #define KFILEITEMMODELROLESUPDATER_DEBUG
m_recentlyChangedItems(),
m_changedItems(),
m_directoryContentsCounter(nullptr)
- #ifdef HAVE_BALOO
+ #if HAVE_BALOO
, m_balooFileMonitor(nullptr)
#endif
{
// Use a timer to prevent that each call of slotItemsChanged() results in a synchronous
// resolving of the roles. Postpone the resolving until no update has been done for 100 ms.
m_recentlyChangedItemsTimer = new QTimer(this);
- m_recentlyChangedItemsTimer->setInterval(100);
+ m_recentlyChangedItemsTimer->setInterval(100ms);
m_recentlyChangedItemsTimer->setSingleShot(true);
connect(m_recentlyChangedItemsTimer, &QTimer::timeout, this, &KFileItemModelRolesUpdater::resolveRecentlyChangedItems);
m_resolvableRoles.insert("size");
m_resolvableRoles.insert("type");
m_resolvableRoles.insert("isExpandable");
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
m_resolvableRoles += KBalooRolesProvider::instance().roles();
#endif
connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result,
this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived);
- const auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, qApp);
- for (QObject *it : plugins) {
- auto plugin = qobject_cast<KOverlayIconPlugin*>(it);
+ const auto plugins = KPluginMetaData::findPlugins(QStringLiteral("kf" QT_STRINGIFY(QT_VERSION_MAJOR)) + QStringLiteral("/overlayicon"));
+ for (const KPluginMetaData &data : plugins) {
+ auto instance = QPluginLoader(data.fileName()).instance();
+ auto plugin = qobject_cast<KOverlayIconPlugin *>(instance);
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();
+ delete instance;
}
}
}
if (m_roles != roles) {
m_roles = roles;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
// Check whether there is at least one role that must be resolved
// with the help of Baloo. If this is the case, a (quite expensive)
// resolving will be done in KFileItemModelRolesUpdater::rolesData() and
const bool allItemsRemoved = (m_model->count() == 0);
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
if (m_balooFileMonitor) {
// Don't let the FileWatcher watch for removed items
if (allItemsRemoved) {
}
}
-void KFileItemModelRolesUpdater::slotItemsMoved(const KItemRange& itemRange, const QList<int> &movedToIndexes)
+void KFileItemModelRolesUpdater::slotItemsMoved(KItemRange itemRange, const QList<int> &movedToIndexes)
{
Q_UNUSED(itemRange)
Q_UNUSED(movedToIndexes)
void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString& file)
{
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
const KFileItem item = m_model->fileItem(QUrl::fromLocalFile(file));
if (item.isNull()) {
void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem &item)
{
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
Baloo::File file(item.localPath());
file.load();
KIO::PreviewJob* job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins);
- job->setIgnoreMaximumSize(itemSubSet.first().isLocalFile() && m_localFileSizePreviewLimit <= 0);
+ job->setIgnoreMaximumSize(itemSubSet.first().isLocalFile() && !itemSubSet.first().isSlow() && m_localFileSizePreviewLimit <= 0);
if (job->uiDelegate()) {
KJobWidgets::setWindow(job, qApp->activeWindow());
}
KIO::PreviewJob* job = new KIO::PreviewJob({m_hoverSequenceItem}, cacheSize, &m_enabledPlugins);
job->setSequenceIndex(loadSeqIdx);
- job->setIgnoreMaximumSize(m_hoverSequenceItem.isLocalFile() && m_localFileSizePreviewLimit <= 0);
+ job->setIgnoreMaximumSize(m_hoverSequenceItem.isLocalFile() && !m_hoverSequenceItem.isSlow() && m_localFileSizePreviewLimit <= 0);
if (job->uiDelegate()) {
KJobWidgets::setWindow(job, qApp->activeWindow());
}
}
}
+ if (m_roles.contains("extension")) {
+ data.insert("extension", QFileInfo(item.name()).suffix());
+ }
+
if (m_roles.contains("type")) {
data.insert("type", item.mimeComment());
}
for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) {
overlays.append(it->getOverlays(item.url()));
}
- data.insert("iconOverlays", overlays);
+ if (!overlays.isEmpty()) {
+ data.insert("iconOverlays", overlays);
+ }
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
if (m_balooFileMonitor) {
m_balooFileMonitor->addFile(item.localPath());
applyChangedBalooRolesForItem(item);