Plasma
backgroundlistmodel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef BACKGROUNDLISTMODEL_H
00011 #define BACKGROUNDLISTMODEL_H
00012
00013 #include <QAbstractListModel>
00014 #include <QPixmap>
00015
00016 #include <KDirWatch>
00017 #include <KFileItem>
00018
00019 #include <Plasma/Wallpaper>
00020
00021 class QEventLoop;
00022 class KProgressDialog;
00023
00024 namespace Plasma
00025 {
00026 class Package;
00027 }
00028
00029 class BackgroundListModel : public QAbstractListModel
00030 {
00031 Q_OBJECT
00032
00033 public:
00034 BackgroundListModel(float ratio, Plasma::Wallpaper *listener, QObject *parent);
00035 virtual ~BackgroundListModel();
00036
00037 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
00038 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00039 Plasma::Package *package(int index) const;
00040
00041 void reload();
00042 void reload(const QStringList &selected);
00043 void addBackground(const QString &path);
00044 QModelIndex indexOf(const QString &path) const;
00045 virtual bool contains(const QString &bg) const;
00046
00047 static QStringList findAllBackgrounds(Plasma::Wallpaper *structureParent,
00048 const BackgroundListModel *container,
00049 const QStringList &path);
00050 static void initProgressDialog(KProgressDialog *dialog);
00051
00052 void setWallpaperSize(QSize size);
00053 void setResizeMethod(Plasma::Wallpaper::ResizeMethod resizeMethod);
00054
00055 protected Q_SLOTS:
00056 void removeBackground(const QString &path);
00057 void showPreview(const KFileItem &item, const QPixmap &preview);
00058 void previewFailed(const KFileItem &item);
00059
00060 private:
00061 QSize bestSize(Plasma::Package *package) const;
00062
00063 Plasma::Wallpaper *m_listener;
00064 Plasma::Wallpaper *m_structureParent;
00065 QList<Plasma::Package *> m_packages;
00066 QHash<Plasma::Package *, QSize> m_sizeCache;
00067 QHash<Plasma::Package *, QPixmap> m_previews;
00068 QHash<KUrl, QPersistentModelIndex> m_previewJobs;
00069 float m_ratio;
00070 KDirWatch m_dirwatch;
00071
00072 QSize m_size;
00073 Plasma::Wallpaper::ResizeMethod m_resizeMethod;
00074 };
00075
00076 class BackgroundFinder : public QObject
00077 {
00078 Q_OBJECT
00079
00080 public:
00081 BackgroundFinder(Plasma::Wallpaper *structureParent,
00082 const BackgroundListModel *container,
00083 const QStringList &p,
00084 QEventLoop *eventLoop);
00085
00086 QStringList papersFound() const;
00087
00088 public slots:
00089 void start();
00090
00091 signals:
00092 void finished();
00093
00094 private:
00095 Plasma::Wallpaper *m_structureParent;
00096 const BackgroundListModel *m_container;
00097 QStringList m_paths;
00098 QStringList m_papersFound;
00099 QEventLoop *m_eventLoop;
00100 };
00101
00102 #endif // BACKGROUNDLISTMODEL_H