diff --git a/wallpapers/image/CMakeLists.txt b/wallpapers/image/CMakeLists.txt index d21ec5638..d6362a515 100644 --- a/wallpapers/image/CMakeLists.txt +++ b/wallpapers/image/CMakeLists.txt @@ -21,6 +21,7 @@ target_link_libraries(plasma_wallpaper_imageplugin KF5::KIOCore KF5::KIOWidgets # KFileDialog KF5::NewStuff + KF5::GuiAddons KF5::KDE4Support ) diff --git a/wallpapers/image/backgroundlistmodel.cpp b/wallpapers/image/backgroundlistmodel.cpp index cd762e888..a51a1944d 100644 --- a/wallpapers/image/backgroundlistmodel.cpp +++ b/wallpapers/image/backgroundlistmodel.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -62,8 +63,6 @@ BackgroundListModel::BackgroundListModel(Image *listener, QObject *parent) m_structureParent(listener) { connect(&m_dirwatch, SIGNAL(deleted(QString)), this, SLOT(removeBackground(QString))); - m_previewUnavailablePix.fill(Qt::transparent); - //m_previewUnavailablePix = KIcon("unknown").pixmap(m_previewUnavailablePix.size()); QHashroleNames; roleNames[Qt::DisplayRole] = "display"; @@ -73,6 +72,8 @@ BackgroundListModel::BackgroundListModel(Image *listener, QObject *parent) roleNames[ResolutionRole] = "resolution"; roleNames[PathRole] = "path"; setRoleNames(roleNames); + + m_imageCache = new KImageCache("plasma_wallpaper_preview", 10485760); } BackgroundListModel::~BackgroundListModel() @@ -281,12 +282,14 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const break; case ScreenshotRole: { - if (m_previews.contains(b.filePath("preferred"))) { - return m_previews.value(b.filePath("preferred")); + QPixmap preview = QPixmap(QSize(SCREENSHOT_SIZE*1.6, + SCREENSHOT_SIZE)); + if (m_imageCache->findPixmap(b.filePath("preferred"), &preview)) { + return preview; } // qDebug() << "WP preferred: " << b.filePath("preferred"); // qDebug() << "WP screenshot: " << b.filePath("screenshot"); - QUrl file(QString("file://") + b.filePath("preferred")); + QUrl file = QUrl::fromLocalFile(b.filePath("preferred")); if (!m_previewJobs.contains(file) && file.isValid()) { KFileItemList list; @@ -302,8 +305,8 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const const_cast(this)->m_previewJobs.insert(file, QPersistentModelIndex(index)); } - const_cast(this)->m_previews.insert(b.filePath("preferred"), m_previewUnavailablePix); - return m_previewUnavailablePix; + preview.fill(Qt::transparent); + return preview; } break; @@ -355,7 +358,7 @@ void BackgroundListModel::showPreview(const KFileItem &item, const QPixmap &prev return; } - m_previews.insert(b.filePath("preferred"), preview); + m_imageCache->insertPixmap(b.filePath("preferred"), preview); //qDebug() << "WP preview size:" << preview.size(); emit dataChanged(index, index); } diff --git a/wallpapers/image/backgroundlistmodel.h b/wallpapers/image/backgroundlistmodel.h index 8d51e0e5b..4e2b60609 100644 --- a/wallpapers/image/backgroundlistmodel.h +++ b/wallpapers/image/backgroundlistmodel.h @@ -30,6 +30,8 @@ #include #include +#include + #include class QEventLoop; @@ -98,12 +100,11 @@ private: QWeakPointer m_structureParent; QList m_packages; QHash m_sizeCache; - QHash m_previews; QHash m_previewJobs; KDirWatch m_dirwatch; + KImageCache* m_imageCache; QString m_findToken; - QPixmap m_previewUnavailablePix; }; class BackgroundFinder : public QThread