mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 10:22:52 +00:00
kdeplasma-addons: sync BackgroundListModel copy
copy of: kde-workspace/plasma/wallpapers/image/backgroundlistmodel.cpp with minor changes Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e98da706cb
commit
1197c31614
2 changed files with 6 additions and 47 deletions
|
@ -13,35 +13,19 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QThreadPool>
|
||||
#include <QImageReader>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KGlobal>
|
||||
#include <KIO/PreviewJob>
|
||||
#include <KProgressDialog>
|
||||
#include <KStandardDirs>
|
||||
#include <KImageIO>
|
||||
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/PackageStructure>
|
||||
|
||||
#include "backgrounddelegate.h"
|
||||
#include "virus.h"
|
||||
|
||||
ImageSizeFinder::ImageSizeFinder(const QString &path, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_path(path)
|
||||
{
|
||||
}
|
||||
|
||||
void ImageSizeFinder::run()
|
||||
{
|
||||
QImage image(m_path);
|
||||
emit sizeFound(m_path, image.size());
|
||||
}
|
||||
|
||||
|
||||
BackgroundListModel::BackgroundListModel(Plasma::Wallpaper *listener, QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_structureParent(listener),
|
||||
|
@ -174,26 +158,16 @@ QSize BackgroundListModel::bestSize(Plasma::Package *package) const
|
|||
QSize size = imagereader.size();
|
||||
// backup solution if image handler does not provide size option
|
||||
if (size.width() == 0 || size.height() == 0) {
|
||||
// kDebug() << "fall back to ImageSizeFinder";
|
||||
ImageSizeFinder *finder = new ImageSizeFinder(image);
|
||||
connect(finder, SIGNAL(sizeFound(QString,QSize)), this,
|
||||
SLOT(sizeFound(QString,QSize)));
|
||||
QThreadPool::globalInstance()->start(finder);
|
||||
size = QSize(-1, -1);
|
||||
size = imagereader.read().size();
|
||||
}
|
||||
m_sizeCache.insert(package, size);
|
||||
|
||||
const_cast<BackgroundListModel *>(this)->m_sizeCache.insert(package, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void BackgroundListModel::sizeFound(const QString &path, const QSize &s)
|
||||
{
|
||||
QModelIndex index = indexOf(path);
|
||||
QModelIndex index = indexOf(image);
|
||||
if (index.isValid()) {
|
||||
Plasma::Package *package = m_packages.at(index.row());
|
||||
m_sizeCache.insert(package, s);
|
||||
static_cast<Virus *>(m_structureParent)->updateScreenshot(index);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
QVariant BackgroundListModel::data(const QModelIndex &index, int role) const
|
||||
|
|
|
@ -28,20 +28,6 @@ namespace Plasma
|
|||
class Package;
|
||||
} // namespace Plasma
|
||||
|
||||
class ImageSizeFinder : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageSizeFinder(const QString &path, QObject *parent = 0);
|
||||
void run();
|
||||
|
||||
Q_SIGNALS:
|
||||
void sizeFound(const QString &path, const QSize &size);
|
||||
|
||||
private:
|
||||
QString m_path;
|
||||
};
|
||||
|
||||
class BackgroundListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -66,7 +52,6 @@ protected Q_SLOTS:
|
|||
void reload();
|
||||
void showPreview(const KFileItem &item, const QPixmap &preview);
|
||||
void previewFailed(const KFileItem &item);
|
||||
void sizeFound(const QString &path, const QSize &s);
|
||||
void processPaths(const QStringList &paths);
|
||||
|
||||
private:
|
||||
|
@ -74,7 +59,7 @@ private:
|
|||
|
||||
Plasma::Wallpaper *m_structureParent;
|
||||
QList<Plasma::Package *> m_packages;
|
||||
QHash<Plasma::Package *, QSize> m_sizeCache;
|
||||
mutable QHash<Plasma::Package *, QSize> m_sizeCache;
|
||||
QHash<Plasma::Package *, QPixmap> m_previews;
|
||||
QHash<KUrl, QPersistentModelIndex> m_previewJobs;
|
||||
KDirWatch m_dirwatch;
|
||||
|
|
Loading…
Add table
Reference in a new issue