~neon/juk/master

« back to all changes in this revision

Viewing changes to covermanager.h

  • Committer: Laurent Montel
  • Date: 2006-10-05 08:04:57 UTC
  • Revision ID: git-v1:6d286b4be0b244323cd0953569d56deccc4afb05
Port to uic4

svn path=/trunk/KDE/kdemultimedia/juk/; revision=592631

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
2
    begin                : Sun May 15 2005
3
 
    copyright            : (C) 2005, 2008 by Michael Pyne
 
3
    copyright            : (C) 2005 by Michael Pyne
4
4
    email                : michael.pyne@kdemail.net
5
5
***************************************************************************/
6
6
 
13
13
 *                                                                         *
14
14
 ***************************************************************************/
15
15
 
16
 
#ifndef JUK_COVERMANAGER_H
17
 
#define JUK_COVERMANAGER_H
 
16
#ifndef COVERMANAGER_H
 
17
#define COVERMANAGER_H
18
18
 
19
19
#include <ksharedptr.h>
20
20
 
21
 
#include <QObject>
22
 
#include <QMimeData>
23
 
#include <QString>
 
21
#include <QMap>
 
22
#include <q3dragobject.h>
 
23
//Added by qt3to4:
 
24
#include <QPixmap>
 
25
#include <Q3ValueList>
24
26
 
25
27
class CoverManagerPrivate;
26
 
class CoverProxy;
 
28
class QString;
27
29
class QPixmap;
28
 
class QTimer;
29
 
class KJob;
30
 
 
31
 
template<class Key, class Value>
32
 
class QMap;
33
 
 
34
 
template<class T>
35
 
class QList;
36
 
 
37
 
class KUrl;
38
 
 
39
 
/**
40
 
 * This class saves the covers when its saveCovers() slot is called to avoid
41
 
 * making CoverManager a QObject and avoid moving the actual implementation
42
 
 * class (CoverManagerPrivate) to this .h file.  Used with a QTimer to save
43
 
 * the covers after changes are made.
44
 
 */
45
 
class CoverSaveHelper : public QObject
46
 
{
47
 
    Q_OBJECT
48
 
 
49
 
public:
50
 
    CoverSaveHelper(QObject *parent);
51
 
    void saveCovers();
52
 
 
53
 
private slots:
54
 
    void commitChanges();
55
 
 
56
 
private:
57
 
    QTimer *m_timer;
58
 
};
 
30
class QDataStream;
59
31
 
60
32
/**
61
33
 * This class holds the data on a cover.  This includes the path to the cover
82
54
 
83
55
typedef KSharedPtr<CoverData> CoverDataPtr;
84
56
typedef unsigned long coverKey; ///< Type of the id for a cover.
85
 
 
86
57
typedef QMap<coverKey, CoverDataPtr> CoverDataMap;
87
58
 
88
 
// I can't believe this actually works...
89
 
typedef CoverDataMap::const_iterator CoverDataMapIterator;
90
 
 
91
 
typedef QList<coverKey> CoverList;
92
 
 
93
59
/**
94
60
 * This class is used to drag covers in JuK.  It adds a special mimetype that
95
61
 * contains the cover ID used for this cover, and also supports an image/png
99
65
 *
100
66
 * @author Michael Pyne <michael.pyne@kdemail.net>
101
67
 */
102
 
class CoverDrag : public QMimeData
 
68
class CoverDrag : public Q3DragObject
103
69
{
104
 
    Q_OBJECT
105
 
 
106
70
public:
107
 
    CoverDrag(coverKey id);
108
 
 
109
 
    static const char* mimetype();
110
 
 
111
 
    static bool isCover(const QMimeData *data);
112
 
 
113
 
    // CoverDrag stores QByteArray data for the cover id, this can convert it
114
 
    // back.
115
 
    static coverKey idFromData(const QMimeData *data);
 
71
    CoverDrag(coverKey id, QWidget *src);
 
72
 
 
73
    virtual const char *format(int i) const;
 
74
    virtual QByteArray encodedData(const char *mimetype) const;
 
75
 
 
76
    void setId(coverKey id) { m_id = id; }
 
77
 
 
78
    /**
 
79
     * Returns true if CoverDrag can decode the given mime source.  Note that
 
80
     * true is returned only if \p e contains a cover id, even though
 
81
     * CoverDrag can convert it to an image.
 
82
     */
 
83
    static bool canDecode(const QMimeSource *e);
 
84
    static bool decode(const QMimeSource *e, coverKey &id);
 
85
 
 
86
    static const char* mimetype;
 
87
 
 
88
private:
 
89
    coverKey m_id;
116
90
};
117
91
 
118
92
/**
196
170
     * @param artist The artist of the new cover.
197
171
     * @param album  The album of the new cover.
198
172
     */
199
 
    static coverKey addCover(const KUrl &path, const QString &artist = "", const QString &album = "");
 
173
    static coverKey addCover(const QString &path, const QString &artist = "", const QString &album = "");
200
174
 
201
175
    /**
202
176
     * Function to determine if @p id matches any covers in the database.
243
217
    /**
244
218
     * @return Iterator pointing to the first element in the cover database.
245
219
     */
246
 
    static CoverDataMapIterator begin();
 
220
    static CoverDataMap::ConstIterator begin();
247
221
 
248
222
    /**
249
223
     * @return Iterator pointing after the last element in the cover database.
250
224
     */
251
 
    static CoverDataMapIterator end();
 
225
    static CoverDataMap::ConstIterator end();
252
226
 
253
227
    /**
254
228
     * @return A list of all of the id's listed in the database.
255
229
     */
256
 
    static CoverList keys();
 
230
    static Q3ValueList<coverKey> keys();
257
231
 
258
232
    /**
259
233
     * Associates @p path with the cover identified by @id.  No comparison of
277
251
     * This identifier is used to indicate that no cover was found in the
278
252
     * database.
279
253
     */
280
 
    static const coverKey NoMatch;
 
254
    static const coverKey NoMatch = 0;
281
255
 
282
256
    private:
283
 
    friend class CoverProxy; // Our QObject-wielding friend.
 
257
    static CoverManagerPrivate *m_data;
284
258
 
285
 
    /// Called by CoverProxy to notify of a completed job.
286
 
    static void jobComplete(KJob *job, bool completedSatisfactory);
287
259
    static CoverManagerPrivate *data();
288
260
    static QPixmap createThumbnail(const QPixmap &base);
289
261
};
290
262
 
291
 
#endif /* JUK_COVERMANAGER_H */
 
263
#endif /* COVERMANAGER_H */
292
264
 
293
265
// vim: set et sw=4 tw=0 sta: