#endif
#include <QApplication>
+#include <QIcon>
#include <QPainter>
#include <QElapsedTimer>
#include <QTimer>
m_resolvableRoles(),
m_enabledPlugins(),
m_localFileSizePreviewLimit(0),
+ m_scanDirectories(true),
m_pendingSortRoleItems(),
m_pendingIndexes(),
m_pendingPreviewItems(),
return m_localFileSizePreviewLimit;
}
+void KFileItemModelRolesUpdater::setScanDirectories(bool enabled)
+{
+ m_scanDirectories = enabled;
+}
+
+bool KFileItemModelRolesUpdater::scanDirectories() const
+{
+ return m_scanDirectories;
+}
+
void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges)
{
QElapsedTimer timer;
QPixmap scaledPixmap = pixmap;
- if (!pixmap.hasAlpha()
+ if (!pixmap.hasAlpha() && !pixmap.isNull()
&& m_iconSize.width() > KIconLoader::SizeSmallMedium
&& m_iconSize.height() > KIconLoader::SizeSmallMedium) {
if (m_enlargeSmallPreviews) {
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
}
}
- } else {
+ } else if (!pixmap.isNull()) {
KPixmapModifier::scale(scaledPixmap, m_iconSize * qApp->devicePixelRatio());
scaledPixmap.setDevicePixelRatio(qApp->devicePixelRatio());
}
// It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional
// setup time.
- for (const QString& overlay : overlays) {
- if (!overlay.isEmpty()) {
- // There is at least one overlay, draw all overlays above m_pixmap
- // and cancel the check
- KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
- break;
+ if (!scaledPixmap.isNull()) {
+ for (const QString& overlay : overlays) {
+ if (!overlay.isEmpty()) {
+ // There is at least one overlay, draw all overlays above m_pixmap
+ // and cancel the check
+ KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
+ break;
+ }
}
}
QList<int> visibleChangedIndexes;
QList<int> invisibleChangedIndexes;
- for (const KFileItem& item : qAsConst(m_changedItems)) {
+ // Iterate over a const copy because items are deleted within the loop
+ const auto changedItems = m_changedItems;
+ for (const KFileItem &item : changedItems) {
const int index = m_model->index(item);
if (index < 0) {
data.insert("type", item.mimeComment());
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
const QString path = item.localPath();
- m_directoryContentsCounter->scanDirectory(path);
+ if (m_scanDirectories) {
+ m_directoryContentsCounter->scanDirectory(path);
+ }
} else {
// Probably the sort role is a baloo role - just determine all roles.
data = rolesData(item);
data = rolesData(item);
}
- data.insert("iconName", item.iconName());
+ if (QIcon::hasThemeIcon(item.iconName())) {
+ data.insert("iconName", item.iconName());
+ }
if (m_clearPreviews) {
data.insert("iconPixmap", QPixmap());
const bool getIsExpandableRole = m_roles.contains("isExpandable");
if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
- if (item.isLocalFile()) {
+ if (item.isLocalFile() && !item.isSlow()) {
// Tell m_directoryContentsCounter that we want to count the items
// inside the directory. The result will be received in slotDirectoryContentsCountReceived.
- const QString path = item.localPath();
- m_directoryContentsCounter->scanDirectory(path);
+ if (m_scanDirectories) {
+ const QString path = item.localPath();
+ m_directoryContentsCounter->scanDirectory(path);
+ }
} else if (getSizeRole) {
data.insert("size", -1); // -1 indicates an unknown number of items
}