~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/library/noatunplaylist.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef NOATUNPLAYLIST_H
 
2
#define NOATUNPLAYLIST_H
 
3
 
 
4
#include <qobject.h>
 
5
#include <kurl.h>
 
6
#include <qdict.h>
 
7
 
 
8
/**
 
9
 * Do not, under any circumstances, call a Playlist method
 
10
 * when you can call a Player method, unless, of course, you
 
11
 * ARE the playlist.
 
12
 **/
 
13
class PlaylistItem
 
14
{
 
15
        friend class Downloader;
 
16
public:
 
17
        /**
 
18
         * if dl is true, then download this ASAP
 
19
         * dl implicitly becomes false if u==0 or
 
20
         * it's a local file
 
21
         **/
 
22
        PlaylistItem(const KURL &u=0, bool dl=true);
 
23
        virtual ~PlaylistItem();
 
24
 
 
25
        /**
 
26
         * title of the song
 
27
         * it may just be the ID3 tag, but I can't guarantee it
 
28
         **/
 
29
        QString title() const;
 
30
        /**
 
31
         * set the title of the song (ID3 loaders do this)
 
32
         * also, note that that rather then overridering
 
33
         * this, you should prefer modified()
 
34
         **/
 
35
        virtual void setTitle(const QString &t);
 
36
        
 
37
        /**
 
38
         * return the location as local, or null if 
 
39
         * file hasn't yet started downloading
 
40
         **/
 
41
        QString file() const;
 
42
 
 
43
        /**
 
44
         * is the file completely downloaded?
 
45
         * if so, file() will return the name
 
46
         **/
 
47
        bool isDownloaded() const;
 
48
        /**
 
49
         * if false, don't try to play the file
 
50
         * if true, go ahead, but it may not
 
51
         * be complete
 
52
         **/
 
53
        bool playable() const;
 
54
        
 
55
        KURL url() const;
 
56
        virtual void setUrl(const KURL &u, bool dl=true);
 
57
        
 
58
        /**
 
59
         * length as a string
 
60
         * The format is cc:cc/ll:ll where c is current
 
61
         * and l is length
 
62
         **/
 
63
        QString lengthString() const;
 
64
 
 
65
        /**
 
66
         * If you can identify the length of this file
 
67
         * set it, in milliseconds.  The engine will do it
 
68
         * itself.
 
69
         *
 
70
         * If unknown, the length will be -1
 
71
         **/
 
72
        virtual void setLength(int msec);
 
73
 
 
74
        /**
 
75
         * length of the song in seconds, or -1 if unknown
 
76
         **/
 
77
        int length() const { return mLength; }
 
78
 
 
79
        /**
 
80
         * retursn the mimetype for this file
 
81
         * (potentially slow)
 
82
         **/
 
83
        QCString mimetype() const;
 
84
 
 
85
        /**
 
86
         * returns the mimetype's associated extentions
 
87
         **/
 
88
        QStrList extension() const;
 
89
 
 
90
        /**
 
91
         * exactly the same as file()
 
92
         **/
 
93
        operator QString() const { return file(); }
 
94
        
 
95
        /**
 
96
         * return the net-location
 
97
         **/
 
98
        operator KURL() const { return url(); }
 
99
 
 
100
        /**
 
101
         * Noatun stores file properties in the form
 
102
         * of Atoms.  To get an atom, give a name for it,
 
103
         * and it'l return the value, or @p def
 
104
         * if it's not set.
 
105
         * 
 
106
         * To implement an atom, the keys can't conflict
 
107
         * so, here's the format:
 
108
         * PluginName:AtomName
 
109
         * 
 
110
         * The core doesn't need the "PluginName" part.
 
111
         *
 
112
         * Internally, we use the following <b>case sensitive</b> keys, so far:
 
113
         *
 
114
         * title, artist, album, date, comment
 
115
         * 
 
116
         * If you, the Noatun Plugin Developer wants
 
117
         * to add a new atom, that in some way or another
 
118
         * should be standard (Like fps for Frames/Second). <b>Contact
 
119
         * us, or Else!</b>
 
120
         *
 
121
         * A Key name that ends with an underscore is not visible
 
122
         * to the user, and the value can be generic crap encoding in
 
123
         * any weird format
 
124
         **/
 
125
        QString property(const QString &key, const QString &def=0) const;
 
126
 
 
127
        /**
 
128
         * Set the said property for the given key
 
129
         * Clearing it first if it already exists.
 
130
         *
 
131
         * Send changed can be left alone
 
132
         **/
 
133
        void setProperty(const QString &key, const QString &property, bool sendchanged=true);
 
134
 
 
135
        /**
 
136
         * Clear the property for the given key in this item
 
137
         **/
 
138
        void clearProperty(const QString &key, bool sendchanged=false);
 
139
 
 
140
        /**
 
141
         * Returns a list of all properties. the best playlist will be
 
142
         * able to store them all between noatun sessions
 
143
         **/
 
144
        QStringList properties() const;
 
145
 
 
146
        /**
 
147
         * returns whether the given key exists as a property
 
148
         **/
 
149
        bool isProperty(const QString &key) const;
 
150
        
 
151
protected: // methods accessed by Downloader (friend)
 
152
        /**
 
153
         * this file is done downloading
 
154
         **/
 
155
        virtual void doneDownloading();
 
156
        
 
157
        /**
 
158
         * called every so often when the percent of download
 
159
         * changes.
 
160
         **/
 
161
        virtual void downloaded(int percent);
 
162
 
 
163
        /**
 
164
         * called when the title or  length, or when
 
165
         * the file is done downloading
 
166
         **/
 
167
        virtual void modified();
 
168
 
 
169
        /**
 
170
         * download timed out, by default, delete this
 
171
         **/
 
172
        virtual void timeout();
 
173
        
 
174
protected:
 
175
        KURL mUrl;
 
176
        QString mFile;
 
177
        bool mDownloaded;
 
178
        int mLength;
 
179
        QDict<QString> mProperties;
 
180
};
 
181
 
 
182
/**
 
183
 * The playlist, which you derive from when creating
 
184
 * your own playlist.
 
185
 *
 
186
 * Do not, under any circumstances, call a Playlist method
 
187
 * when you can call a Player method, unless, of course, you
 
188
 * ARE the playlist.
 
189
 **/
 
190
class Playlist : public QObject
 
191
{
 
192
Q_OBJECT
 
193
        friend class PlaylistItem;
 
194
public:
 
195
        Playlist(QObject *parent, const char *name);
 
196
        
 
197
        /**
 
198
         * go to the front
 
199
         **/
 
200
        virtual void reset()=0;
 
201
        
 
202
        /**
 
203
         * empty the list
 
204
         **/
 
205
        virtual void clear()=0;
 
206
        /**
 
207
         * add a file
 
208
         */
 
209
        virtual void addFile(const KURL&, bool play=false)=0;
 
210
 
 
211
        /**
 
212
         * cycle forward, return that
 
213
         **/    
 
214
        virtual PlaylistItem *next()=0;
 
215
        /**
 
216
         * current item
 
217
         **/
 
218
        virtual PlaylistItem *current()=0;
 
219
        /**
 
220
         * cycle back, return that
 
221
         **/
 
222
        virtual PlaylistItem *previous()=0;
 
223
 
 
224
        /**
 
225
         * get the first item
 
226
         **/
 
227
        virtual PlaylistItem *getFirst() const =0;
 
228
 
 
229
        /**
 
230
         * get the item after item
 
231
         **/
 
232
        virtual PlaylistItem *getAfter(const PlaylistItem *item) const =0;
 
233
         
 
234
        /**
 
235
         * is the view visible?
 
236
         **/
 
237
        virtual bool listVisible() const =0;
 
238
        /**
 
239
         * do the KCmdLineArgs stuff
 
240
         **/
 
241
        int handleArguments();
 
242
 
 
243
        /**
 
244
         * Clear the properties in all the playlistitems
 
245
         * in which the key is equal to the given
 
246
         *
 
247
         * This requires @ref getFirst and @ref getAfter to work :)
 
248
         **/
 
249
        virtual void clearProperties(const QString &key, bool sendchanged=true);
 
250
 
 
251
public slots:
 
252
        /**
 
253
         * show the list!
 
254
         **/
 
255
        virtual void showList()=0;
 
256
        /**
 
257
         * hide it
 
258
         **/
 
259
        virtual void hideList()=0;
 
260
        /**
 
261
         * toggle visibility
 
262
         **/
 
263
        virtual void toggleList();
 
264
        /**
 
265
         * remove the item
 
266
         **/
 
267
        virtual void remove(PlaylistItem*)=0;
 
268
 
 
269
signals:
 
270
        /**
 
271
         * when item @p item is deleted from the 
 
272
         * playlist.  the item itself has no such
 
273
         * signal since it's not a QObject
 
274
         *
 
275
         * This is called by the internals to signal
 
276
         * a deleted file
 
277
         **/
 
278
        void removed(PlaylistItem *item);
 
279
        /**
 
280
         * when you want the engine to reload current()
 
281
         **/
 
282
        void playCurrent();
 
283
        /**
 
284
         * when the list is hidden
 
285
         **/
 
286
        void listHidden();
 
287
        /**
 
288
         * when the list is shown
 
289
         **/
 
290
        void listShown();
 
291
        /**
 
292
         * they just added one that will be played when
 
293
         * the play button is pressed.  emit this when no file
 
294
         * has been replace by some file, not always.
 
295
         **/
 
296
        void newCurrent();
 
297
 
 
298
        /**
 
299
         * A new item has been allocated, this is
 
300
         * called by the internals
 
301
         **/
 
302
        void added(PlaylistItem *item);
 
303
 
 
304
private:
 
305
        void deleted(PlaylistItem *item);
 
306
};
 
307
 
 
308
#endif
 
309