From e2779e8930e02d69fa64dc5664e7e7bb5773683d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 4 Mar 2022 16:08:17 +0200 Subject: [PATCH] plasma: somewhat fix BackgroundListModel thread-safety issues and add more image suffixes, patterns and MIME types Signed-off-by: Ivailo Monev --- plasma/wallpapers/image/backgroundlistmodel.cpp | 29 +++++++--------------- plasma/wallpapers/image/backgroundlistmodel.h | 8 +++--- plasma/wallpapers/image/image.cpp | 3 ++- .../image/plasma-wallpaper-image.desktop | 4 +-- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/plasma/wallpapers/image/backgroundlistmodel.cpp b/plasma/wallpapers/image/backgroundlistmodel.cpp index 437a27d1..512ab491 100644 --- a/plasma/wallpapers/image/backgroundlistmodel.cpp +++ b/plasma/wallpapers/image/backgroundlistmodel.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -28,10 +29,8 @@ #include "backgrounddelegate.h" #include "image.h" -QSet BackgroundFinder::m_suffixes; - ImageSizeFinder::ImageSizeFinder(const QString &path, QObject *parent) - : QObject(parent), + : QThread(parent), m_path(path) { } @@ -203,13 +202,12 @@ QSize BackgroundListModel::bestSize(Plasma::Package *package) const return QSize(); } - ImageSizeFinder *finder = new ImageSizeFinder(image); + QSize size(-1, -1); + m_sizeCache.insert(package, size); + ImageSizeFinder *finder = new ImageSizeFinder(image, const_cast(this)); connect(finder, SIGNAL(sizeFound(QString,QSize)), this, SLOT(sizeFound(QString,QSize))); - QThreadPool::globalInstance()->start(finder); - - QSize size(-1, -1); - const_cast(this)->m_sizeCache.insert(package, size); + finder->start(); return size; } @@ -252,7 +250,6 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const return title; } - break; case BackgroundDelegate::ScreenshotRole: { if (m_previews.contains(b)) { @@ -277,11 +274,9 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const const_cast(this)->m_previews.insert(b, m_previewUnavailablePix); return m_previewUnavailablePix; } - break; case BackgroundDelegate::AuthorRole: return b->metadata().author(); - break; case BackgroundDelegate::ResolutionRole:{ QSize size = bestSize(b); @@ -292,11 +287,9 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const return QString(); } - break; default: return QVariant(); - break; } } @@ -361,20 +354,16 @@ QString BackgroundFinder::token() const return m_token; } -const QSet &BackgroundFinder::suffixes() +QStringList BackgroundFinder::suffixes() { - if(m_suffixes.isEmpty()) { - m_suffixes << "png" << "jpeg" << "jpg" << "svg" << "svgz"; - } - - return m_suffixes; + return KImageIO::types(KImageIO::Reading); } void BackgroundFinder::run() { //QTime t; //t.start(); - const QSet &fileSuffixes = suffixes(); + const QStringList fileSuffixes = suffixes(); QStringList papersFound; //kDebug() << "starting with" << m_paths; diff --git a/plasma/wallpapers/image/backgroundlistmodel.h b/plasma/wallpapers/image/backgroundlistmodel.h index 2917957c..bd660836 100644 --- a/plasma/wallpapers/image/backgroundlistmodel.h +++ b/plasma/wallpapers/image/backgroundlistmodel.h @@ -30,7 +30,7 @@ namespace Plasma class Image; -class ImageSizeFinder : public QObject, public QRunnable +class ImageSizeFinder : public QThread { Q_OBJECT public: @@ -78,7 +78,7 @@ private: QWeakPointer m_structureParent; QList m_packages; - QHash m_sizeCache; + mutable QHash m_sizeCache; QHash m_previews; QHash m_previewJobs; KDirWatch m_dirwatch; @@ -99,7 +99,7 @@ public: QString token() const; - static const QSet &suffixes(); + static QStringList suffixes(); signals: void backgroundsFound(const QStringList &paths, const QString &token); @@ -111,8 +111,6 @@ private: Plasma::PackageStructure::Ptr m_structure; QStringList m_paths; QString m_token; - - static QSet m_suffixes; }; #endif // BACKGROUNDLISTMODEL_H diff --git a/plasma/wallpapers/image/image.cpp b/plasma/wallpapers/image/image.cpp index 5c42fec8..58b0485e 100644 --- a/plasma/wallpapers/image/image.cpp +++ b/plasma/wallpapers/image/image.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -664,7 +665,7 @@ void Image::showFileDialog() baseUrl = KUrl(m_wallpaper); } - m_dialog = new KFileDialog(baseUrl, "*.png *.jpeg *.jpg *.xcf *.svg *.svgz *.bmp", m_configWidget); + m_dialog = new KFileDialog(baseUrl, KImageIO::pattern(KImageIO::Reading), m_configWidget); m_dialog->setOperationMode(KFileDialog::Opening); m_dialog->setInlinePreviewShown(true); m_dialog->setCaption(i18n("Select Wallpaper Image File")); diff --git a/plasma/wallpapers/image/plasma-wallpaper-image.desktop b/plasma/wallpapers/image/plasma-wallpaper-image.desktop index c4a633f0..6e0770fc 100644 --- a/plasma/wallpapers/image/plasma-wallpaper-image.desktop +++ b/plasma/wallpapers/image/plasma-wallpaper-image.desktop @@ -93,8 +93,8 @@ X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-License=GPL X-KDE-PluginInfo-EnabledByDefault=true -MimeType=image/jpeg;image/png;image/svg+xml;image/svg+xml-compressed;image/bmp; -X-Plasma-DropMimeTypes=image/jpeg,image/png,image/svg+xml,image/svg+xml-compressed,image/bmp +MimeType=image/bmp;image/gif;image/jp2;image/jpeg;image/katie;image/png;image/svg+xml;image/svg+xml-compressed;image/tiff;image/vnd.microsoft.icon;image/webp;image/x-dcraw;image/x-dds;image/x-eps;image/x-exr;image/x-pcx;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-psd;image/x-tga;image/x-xbitmap;image/x-xcf;image/x-xpixmap; +X-Plasma-DropMimeTypes=image/bmp,image/gif,image/jp2,image/jpeg,image/katie,image/png,image/svg+xml,image/svg+xml-compressed,image/tiff,image/vnd.microsoft.icon,image/webp,image/x-dcraw,image/x-dds,image/x-eps,image/x-exr,image/x-pcx,image/x-portable-bitmap,image/x-portable-graymap,image/x-portable-pixmap,image/x-psd,image/x-tga,image/x-xbitmap,image/x-xcf,image/x-xpixmap [Desktop Action SingleImage] Name=Image -- 2.11.0