summaryrefslogtreecommitdiffstats
path: root/kscd/kcompactdisc.h
blob: 8015ab277bb5ae3aa285a27535a5dced2374109f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
 *  KCompactDisc - A CD drive interface for the KDE Project.
 *
 *  Copyright (c) 2005 Shaheedur R. Haque <srhaque@iee.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef KCOMPACTDISC_H
#define KCOMPACTDISC_H

#include <tqobject.h>
#include <tqtimer.h>
#include <tqvaluelist.h>

/**
 *  KCompactDisc - A CD drive interface for the KDE Project.
 *
 *  The disc lifecycle is modelled by these signals:
 *
 * @see #trayClosing(): A disc is being inserted.
 * @see #discChanged(): A disc was inserted or removed.
 * @see #trayOpening(): A disc is being removed.
 *
 *  The progress of playout is modelled by these signals:
 *
 * @see #trackPlaying(): A track started playing, or is still playing.
 * @see #trackPaused(): A track was paused.
 * @see #discStopped(): The disc stopped.
 *
 *  All times in this interface are in milliseconds. Valid track numbers are
 *  positive numbers; zero is not a valid track number.
 */
class KCompactDisc :
    public TQObject
{
    Q_OBJECT
  TQ_OBJECT
public:
    enum InformationMode
    {
        Synchronous, // Return and emit signal when cdrom and cddb information arrives.
        Asynchronous // Block until cdrom and cddb infromation has been obtained
    };

    KCompactDisc(InformationMode=Synchronous);
    virtual ~KCompactDisc();

    /**
     * Open/close tray.
     */
    void eject();

    /**
     * Start playout at given position of track.
     */
    void play(unsigned startTrack = 0, unsigned startTrackPosition = 0, unsigned endTrack = 0);

    /**
     * Pause/resume playout.
     */
    void pause();

    /**
     * If the url is a media:/ or system:/ URL returns
     * the device it represents, otherwise returns device
     */
    static TQString urlToDevice(const TQString& device);

    /**
     * @param device Name of CD device, e.g. /dev/cdrom.
     * @param digitalPlayback Select digial or analogue playback.
     * @param audioSystem For analogue playback, system to use, e.g. "arts".
     * @param audioDevice For analogue playback, device to use.
     * @return true if the device seemed usable.
     */
    bool setDevice(
        const TQString &device = defaultDevice,
        unsigned volume = 50,
        bool digitalPlayback = true,
        const TQString &audioSystem = TQString(),
        const TQString &audioDevice = TQString());

    void setVolume(unsigned volume);

    /**
     * Stop playout.
     */
    void stop();

    /**
     * The default CD for this system.
     */
    static const TQString defaultDevice;

    /**
     * Current device.
     *
     * @return Null string if no usable device set.
     */
    const TQString &device() const;

    /**
     * The discId for a missing disc.
     */
    static const unsigned missingDisc;

    /**
     * Current disc, missingDisc if no disc.
     */
    unsigned discId() const { return m_discId; }

    /**
     * CDDB signature of disc.
     */
    const TQValueList<unsigned> &discSignature() const { return m_trackStartFrames; }

    /**
     * Artist for whole disc.
     *
     * @return Disc artist or null string.
     */
    const TQString &discArtist() const { return m_artist; }

    /**
     * Title of disc.
     *
     * @return Disc title or null string.
     */
    const TQString &discTitle() const { return m_title; }

    /**
     * Length of disc.
     *
     * @return Disc length in milliseconds.
     */
    unsigned discLength() const;

    /**
     * Position in disc.
     *
     * @return Position in milliseconds.
     */
    unsigned discPosition() const;
    /**
     * Artist of current track.
     *
     * @return Track artist or null string.
     */
    const TQString &trackArtist() const;

    /**
     * Artist of given track.
     *
     * @return Track artist or null string.
     */
    const TQString &trackArtist(unsigned track) const;

    /**
     * Title of current track.
     *
     * @return Track title or null string.
     */
    const TQString &trackTitle() const;

    /**
     * Title of given track.
     *
     * @return Track title or null string.
     */
    const TQString &trackTitle(unsigned track) const;

    /**
     * Current track.
     *
     * @return Track number.
     */
    unsigned track() const;

    /**
     * Number of tracks.
     */
    unsigned tracks() const;

    /**
     * @return if the track is actually an audio track.
     */
    bool isAudio(unsigned track) const;

    /**
     * Length of current track.
     *
     * @return Track length in milliseconds.
     */
    unsigned trackLength() const;

    /**
     * Length of given track.
     *
     * @param track Track number.
     * @return Track length in milliseconds.
     */
    unsigned trackLength(unsigned track) const;

    /**
     * Position in current track.
     *
     * @return Position in milliseconds.
     */
    unsigned trackPosition() const;

    bool isPaused() const;

    bool isPlaying() const;

signals:

    /**
     * A disc is being inserted.
     */
    void trayClosing();

    /**
     * A disc is being removed.
     */
    void trayOpening();

    /**
     * A disc was inserted or removed.
     *
     * @param discId Current disc, missingDisc if no disc.
     */
    void discChanged(unsigned discId);

    /**
     * Disc stopped. See @see #trackPaused.
     */
    void discStopped();

    /**
     * The current track changed.
     *
     * @param track Track number.
     * @param trackLength Length within track in milliseconds.
     */
    void trackChanged(unsigned track, unsigned trackLength);

    /**
     * A track started playing, or is still playing. This signal is delivered at
     * approximately 1 second intervals while a track is playing. At first sight,
     * this might seem overzealous, but its likely that any CD player UI will use
     * this to track the second-by-second position, so we may as well do it for
     * them.
     *
     * @param track Track number.
     * @param trackPosition Position within track in milliseconds.
     */
    void trackPlaying(unsigned track, unsigned trackPosition);

    /**
     * A track paused playing.
     *
     * @param track Track number.
     * @param trackPosition Position within track in milliseconds.
     */
    void trackPaused(unsigned track, unsigned trackPosition);

private:
    TQTimer timer;
    TQString m_device;
    int m_status;
    int m_previousStatus;
    unsigned m_discId;
    unsigned m_previousDiscId;
    TQString m_artist;
    TQString m_title;
    unsigned m_tracks;
    TQValueList<unsigned> m_trackStartFrames;
    TQStringList m_trackArtists;
    TQStringList m_trackTitles;
    unsigned m_track;
    unsigned m_previousTrack;
    void checkDeviceStatus();
    TQString discStatus(int status);
    class KCompactDiscPrivate *d;
    InformationMode m_infoMode;

private slots:
    void timerExpired();
};

#endif