~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/wallpapers/image/backgroundlistmodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
 
3
 
 
4
  This program is free software; you can redistribute it and/or modify
 
5
  it under the terms of the GNU General Public License as published by
 
6
  the Free Software Foundation; either version 2 of the License, or
 
7
  (at your option) any later version.
 
8
*/
 
9
 
 
10
#ifndef BACKGROUNDLISTMODEL_H
 
11
#define BACKGROUNDLISTMODEL_H
 
12
 
 
13
#include <QAbstractListModel>
 
14
#include <QPixmap>
 
15
#include <QRunnable>
 
16
#include <QThread>
 
17
 
 
18
#include <KDirWatch>
 
19
#include <KFileItem>
 
20
 
 
21
#include <Plasma/Wallpaper>
 
22
 
 
23
class QEventLoop;
 
24
class KProgressDialog;
 
25
 
 
26
namespace Plasma
 
27
{
 
28
    class Package;
 
29
} // namespace Plasma
 
30
 
 
31
class ImageSizeFinder : public QObject, public QRunnable
 
32
{
 
33
    Q_OBJECT
 
34
    public:
 
35
        ImageSizeFinder(const QString &path, QObject *parent = 0);
 
36
        void run();
 
37
 
 
38
    Q_SIGNALS:
 
39
        void sizeFound(const QString &path, const QSize &size);
 
40
 
 
41
    private:
 
42
        QString m_path;
 
43
};
 
44
 
 
45
class BackgroundListModel : public QAbstractListModel
 
46
{
 
47
    Q_OBJECT
 
48
 
 
49
public:
 
50
    BackgroundListModel(Plasma::Wallpaper *listener, QObject *parent);
 
51
    virtual ~BackgroundListModel();
 
52
 
 
53
    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
 
54
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
55
    Plasma::Package *package(int index) const;
 
56
 
 
57
    void reload();
 
58
    void reload(const QStringList &selected);
 
59
    void addBackground(const QString &path);
 
60
    QModelIndex indexOf(const QString &path) const;
 
61
    virtual bool contains(const QString &bg) const;
 
62
 
 
63
    void setWallpaperSize(const QSize& size);
 
64
    void setResizeMethod(Plasma::Wallpaper::ResizeMethod resizeMethod);
 
65
 
 
66
protected Q_SLOTS:
 
67
    void removeBackground(const QString &path);
 
68
    void showPreview(const KFileItem &item, const QPixmap &preview);
 
69
    void previewFailed(const KFileItem &item);
 
70
    void sizeFound(const QString &path, const QSize &s);
 
71
    void backgroundsFound(const QStringList &paths, const QString &token);
 
72
    void processPaths(const QStringList &paths);
 
73
 
 
74
private:
 
75
    QSize bestSize(Plasma::Package *package) const;
 
76
 
 
77
    Plasma::Wallpaper *m_structureParent;
 
78
    QList<Plasma::Package *> m_packages;
 
79
    QHash<Plasma::Package *, QSize> m_sizeCache;
 
80
    QHash<Plasma::Package *, QPixmap> m_previews;
 
81
    QHash<KUrl, QPersistentModelIndex> m_previewJobs;
 
82
    KDirWatch m_dirwatch;
 
83
 
 
84
    QSize m_size;
 
85
    Plasma::Wallpaper::ResizeMethod m_resizeMethod;
 
86
    QString m_findToken;
 
87
    QPixmap m_previewUnavailablePix;
 
88
};
 
89
 
 
90
class BackgroundFinder : public QThread
 
91
{
 
92
    Q_OBJECT
 
93
 
 
94
public:
 
95
    BackgroundFinder(Plasma::Wallpaper *structureParent, const QStringList &p);
 
96
    ~BackgroundFinder();
 
97
 
 
98
    QString token() const;
 
99
 
 
100
signals:
 
101
    void backgroundsFound(const QStringList &paths, const QString &token);
 
102
 
 
103
protected:
 
104
    void run();
 
105
 
 
106
private:
 
107
    Plasma::PackageStructure::Ptr m_structure;
 
108
    QStringList m_paths;
 
109
    QString m_token;
 
110
};
 
111
 
 
112
#endif // BACKGROUNDLISTMODEL_H