use a KImageCache

Now from the second time the dialog is loaded, the thumbnail loading is istantaneous
wilder-5.14
Marco Martin 12 years ago
parent 666d8a9ffe
commit 3dfb46da81
  1. 1
      wallpapers/image/CMakeLists.txt
  2. 19
      wallpapers/image/backgroundlistmodel.cpp
  3. 5
      wallpapers/image/backgroundlistmodel.h

@ -21,6 +21,7 @@ target_link_libraries(plasma_wallpaper_imageplugin
KF5::KIOCore
KF5::KIOWidgets # KFileDialog
KF5::NewStuff
KF5::GuiAddons
KF5::KDE4Support
)

@ -34,6 +34,7 @@
#include <KLocalizedString>
#include <KProgressDialog>
#include <KStandardDirs>
#include <kimagecache.h>
#include <Plasma/Package>
#include <Plasma/PackageStructure>
@ -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());
QHash<int, QByteArray>roleNames;
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<BackgroundListModel *>(this)->m_previewJobs.insert(file, QPersistentModelIndex(index));
}
const_cast<BackgroundListModel *>(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);
}

@ -30,6 +30,8 @@
#include <KDirWatch>
#include <KFileItem>
#include <kimagecache.h>
#include <Plasma/PackageStructure>
class QEventLoop;
@ -98,12 +100,11 @@ private:
QWeakPointer<Image> m_structureParent;
QList<Plasma::Package> m_packages;
QHash<QString, QSize> m_sizeCache;
QHash<QString, QPixmap> m_previews;
QHash<QUrl, QPersistentModelIndex> m_previewJobs;
KDirWatch m_dirwatch;
KImageCache* m_imageCache;
QString m_findToken;
QPixmap m_previewUnavailablePix;
};
class BackgroundFinder : public QThread

Loading…
Cancel
Save