File indexing completed on 2024-03-24 04:57:18
0001 /* 0002 * KCompactDisc - A CD drive interface for the KDE Project. 0003 * 0004 * Copyright (C) 2005 Shaheedur R. Haque <srhaque@iee.org> 0005 * Copyright (C) 2007 Alexander Kern <alex.kern@gmx.de> 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU General Public License as published by 0009 * the Free Software Foundation; either version 2, or (at your option) 0010 * any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KCOMPACTDISC_H 0023 #define KCOMPACTDISC_H 0024 0025 #include <QObject> 0026 #include <QStringList> 0027 #include <QUrl> 0028 #include <QTimer> 0029 0030 #include "kcompactdisc_export.h" 0031 0032 class KCompactDiscPrivate; 0033 0034 /** 0035 * KCompactDisc - A CD drive interface for the KDE Project. 0036 * 0037 * The disc interface is modelled by these slots: 0038 * 0039 * @see playTrack(unsigned int track): Play specified track. 0040 * @see playPosition(unsigned int position): seek to specified position. 0041 * @see next(): Play next track in the playlist. 0042 * @see prev(): Play previous track in the playlist. 0043 * @see pause(): Toggle between pause/resume. 0044 * @see stop(): Stop playout: 0045 * @see eject(): Stop playout and eject disc or Close 0046 * tray and try to read TOC from disc. 0047 * 0048 * The progress of playout is modelled by these signals: 0049 * 0050 * @see playoutPositionChanged(unsigned int position): A position in a track. 0051 * @see playoutTrackChanged(unsigned int track): A playout of this track is started. 0052 * 0053 * 0054 * The shape of playlist is controlled by these accessors. 0055 * 0056 * @see setRandomPlaylist(bool): Shuffle the playlist. 0057 * @see setLoopPlaylist(bool): Couple begin and end of playlist. 0058 * 0059 * 0060 * The disc lifecycle is modelled by these signals: 0061 * 0062 * @see #discChanged(...): A new disc was inserted. 0063 * @see discStatusString(KCompactDisc::Playing): A disc started playout. 0064 * @see discStatusString(KCompactDisc::Paused): A disc was paused. 0065 * @see discStatusString(KCompactDisc::Stopped): The disc stopped. 0066 * @see discStatusString(KCompactDisc::NoDisc): The disc is removed. No disc in tray or data disc. 0067 * @see discStatusString(KCompactDisc::NotReady): The disc is present. But playout is not possible. 0068 * @see discInformation(KCompactDisc::DiscInfo info): A content for disc information is arrived. 0069 * 0070 * 0071 * The volume control is modelled by these slots: 0072 * 0073 * @see setVolume(unsigned int volume): A new volume value. 0074 * @see setBalance(unsigned int balance): A new balance value. 0075 * 0076 * 0077 * And these signals: 0078 * 0079 * @see volumeChanged(unsigned int volume): A current volume value. 0080 * @see balanceChanged(unsigned int balance): A current balance value. 0081 * 0082 * 0083 * All times in this interface are in seconds. Valid track numbers are 0084 * positive numbers; zero is not a valid track number. 0085 */ 0086 class KCOMPACTDISC_EXPORT KCompactDisc : public QObject 0087 { 0088 Q_OBJECT 0089 /* 0090 Q_CLASSINFO("D-Bus Interface", "org.kde.KSCD") 0091 0092 public Q_SLOTS: 0093 Q_SCRIPTABLE bool playing(); 0094 Q_SCRIPTABLE void play() { play(); } 0095 Q_SCRIPTABLE void stop() { stop(); } 0096 Q_SCRIPTABLE void previous() { prev(); } 0097 Q_SCRIPTABLE void next() { next(); } 0098 Q_SCRIPTABLE void jumpTo(int seconds) { jumpToTime(seconds); } 0099 Q_SCRIPTABLE void eject() { eject(); } 0100 Q_SCRIPTABLE void toggleLoop() { loop(); } 0101 Q_SCRIPTABLE void toggleShuffle() { random(); } 0102 Q_SCRIPTABLE void toggleTimeDisplay() { cycleplaytimemode(); } 0103 Q_SCRIPTABLE void cddbDialog() { CDDialogSelected(); } 0104 Q_SCRIPTABLE void optionDialog() { showConfig(); } 0105 Q_SCRIPTABLE void setTrack(int t) { trackSelected(t > 0 ? t - 1 : 0); } 0106 Q_SCRIPTABLE void volumeDown() { decVolume(); } 0107 Q_SCRIPTABLE void volumeUp() { incVolume(); } 0108 Q_SCRIPTABLE void setVolume(int v); 0109 Q_SCRIPTABLE void setDevice(const QString& dev); 0110 Q_SCRIPTABLE int getVolume() { return Prefs::volume(); } 0111 Q_SCRIPTABLE int currentTrack(); 0112 Q_SCRIPTABLE int currentTrackLength(); 0113 Q_SCRIPTABLE int currentPosition(); 0114 Q_SCRIPTABLE int getStatus(); 0115 Q_SCRIPTABLE QString currentTrackTitle(); 0116 Q_SCRIPTABLE QString currentAlbum(); 0117 Q_SCRIPTABLE QString currentArtist(); 0118 Q_SCRIPTABLE QStringList trackList(); 0119 */ 0120 public: 0121 enum InformationMode 0122 { 0123 Synchronous, // Return and emit signal when cdrom and cddb information arrives. 0124 Asynchronous // Block until cdrom and cddb information has been obtained 0125 }; 0126 0127 enum DiscCommand 0128 { 0129 Play, 0130 Pause, 0131 Next, 0132 Prev, 0133 Stop, 0134 Eject, 0135 Loop, 0136 Random 0137 }; 0138 0139 enum DiscStatus 0140 { 0141 Playing, 0142 Paused, 0143 Stopped, 0144 Ejected, 0145 NoDisc, 0146 NotReady, 0147 Error 0148 }; 0149 0150 enum DiscInfo 0151 { 0152 Cdtext, 0153 Cddb, 0154 PhononMetadata 0155 }; 0156 0157 explicit KCompactDisc(InformationMode = KCompactDisc::Synchronous); 0158 ~KCompactDisc() override; 0159 0160 /** 0161 * @param device Name of CD device, e.g. /dev/cdrom. 0162 * @param volume Playback volume. 0163 * @param digitalPlayback Select digital or analog playback. 0164 * @param audioSystem For digital playback, system to use, e.g. "phonon". 0165 * @param audioDevice For digital playback, device to use. 0166 * @return true if the device seemed usable. 0167 */ 0168 bool setDevice( 0169 const QString &device, 0170 unsigned volume = 50, 0171 bool digitalPlayback = true, 0172 const QString &audioSystem = QString(), 0173 const QString &audioDevice = QString()); 0174 0175 /** 0176 * If the url is a media:/ or system:/ URL returns 0177 * the device it represents, otherwise returns device 0178 */ 0179 static QString urlToDevice(const QUrl& url); 0180 0181 /** 0182 * All installed audio backends. 0183 */ 0184 static const QStringList audioSystems(); 0185 0186 /** 0187 * All present CDROM devices. 0188 */ 0189 static const QStringList cdromDeviceNames(); 0190 0191 /** 0192 * The default CDROM device for this system. 0193 */ 0194 static const QString defaultCdromDeviceName(); 0195 0196 /** 0197 * The Url of default CDROM device for this system. 0198 */ 0199 static const QUrl defaultCdromDeviceUrl(); 0200 0201 /** 0202 * The Url of named CDROM device for this system. 0203 */ 0204 static const QUrl cdromDeviceUrl(const QString &); 0205 0206 /** 0207 * The Udi of default CDROM device for this system. 0208 */ 0209 static const QString defaultCdromDeviceUdi(); 0210 0211 /** 0212 * The Udi of named CDROM device for this system. 0213 */ 0214 static const QString cdromDeviceUdi(const QString &); 0215 0216 /** 0217 * SCSI parameter VENDOR of current CDROM device. 0218 * 0219 * @return Null string if no usable device set. 0220 */ 0221 const QString &deviceVendor(); 0222 0223 /** 0224 * SCSI parameter MODEL of current CDROM device. 0225 * 0226 * @return Null string if no usable device set. 0227 */ 0228 const QString &deviceModel(); 0229 0230 /** 0231 * SCSI parameter REVISION of current CDROM device. 0232 * 0233 * @return Null string if no usable device set. 0234 */ 0235 const QString &deviceRevision(); 0236 0237 /** 0238 * Current CDROM device. 0239 * 0240 * @return Null string if no usable device set. 0241 */ 0242 const QString &deviceName(); 0243 0244 /** 0245 * Current device as QUrl. 0246 */ 0247 const QUrl deviceUrl(); 0248 0249 /** 0250 * Current disc, 0 if no disc or impossible to calculate id. 0251 */ 0252 unsigned discId(); 0253 0254 /** 0255 * CDDB signature of disc, empty if no disc or not possible to deliver. 0256 */ 0257 const QList<unsigned> &discSignature(); 0258 0259 /** 0260 * Artist for whole disc. 0261 * 0262 * @return Disc artist or null string. 0263 */ 0264 const QString &discArtist(); 0265 0266 /** 0267 * Title of disc. 0268 * 0269 * @return Disc title or null string. 0270 */ 0271 const QString &discTitle(); 0272 0273 /** 0274 * Known length of disc. 0275 * 0276 * @return Disc length in seconds. 0277 */ 0278 unsigned discLength(); 0279 0280 /** 0281 * Current position on the disc. 0282 * 0283 * @return Position in seconds. 0284 */ 0285 unsigned discPosition(); 0286 0287 /** 0288 * Current status. 0289 * 0290 * @return Current status. 0291 */ 0292 KCompactDisc::DiscStatus discStatus(); 0293 0294 /** 0295 * Status as string. 0296 * 0297 * @return Status as QString. 0298 */ 0299 QString discStatusString(KCompactDisc::DiscStatus status); 0300 0301 /** 0302 * Artist of current track. 0303 * 0304 * @return Track artist or null string. 0305 */ 0306 QString trackArtist(); 0307 0308 /** 0309 * Artist of given track. 0310 * 0311 * @return Track artist or null string. 0312 */ 0313 QString trackArtist(unsigned track); 0314 0315 /** 0316 * Title of current track. 0317 * 0318 * @return Track title or null string. 0319 */ 0320 QString trackTitle(); 0321 0322 /** 0323 * Title of given track. 0324 * 0325 * @return Track title or null string. 0326 */ 0327 QString trackTitle(unsigned track); 0328 0329 /** 0330 * Length of current track. 0331 * 0332 * @return Track length in seconds. 0333 */ 0334 unsigned trackLength(); 0335 0336 /** 0337 * Length of given track. 0338 * 0339 * @param track Track number. 0340 * @return Track length in seconds. 0341 */ 0342 unsigned trackLength(unsigned track); 0343 0344 /** 0345 * Current track. 0346 * 0347 * @return Track number. 0348 */ 0349 unsigned track(); 0350 0351 /** 0352 * Current track position. 0353 * 0354 * @return Track position in seconds. 0355 */ 0356 unsigned trackPosition(); 0357 0358 /** 0359 * Number of tracks. 0360 */ 0361 unsigned tracks(); 0362 0363 /** 0364 * Is status playing. 0365 */ 0366 bool isPlaying(); 0367 0368 /** 0369 * Is status pausing. 0370 */ 0371 bool isPaused(); 0372 0373 /** 0374 * Is status no disc. 0375 */ 0376 bool isNoDisc(); 0377 0378 /** 0379 * @return if the track is actually an audio track. 0380 */ 0381 bool isAudio(unsigned track); 0382 0383 0384 public Q_SLOTS: 0385 0386 /** 0387 * Start playout of track. 0388 */ 0389 void playTrack(unsigned int track); 0390 0391 /** 0392 * Start playout or seek to given position of track. 0393 */ 0394 void playPosition(unsigned int position); 0395 0396 /* GUI bindings */ 0397 /** 0398 * Start playout. 0399 */ 0400 void play(); 0401 0402 /** 0403 * Start playout of next track. 0404 */ 0405 void next(); 0406 0407 /** 0408 * Start playout of previous track. 0409 */ 0410 void prev(); 0411 0412 /** 0413 * Pause/resume playout. 0414 */ 0415 void pause(); 0416 0417 /** 0418 * Stop playout. 0419 */ 0420 void stop(); 0421 0422 /** 0423 * Open/close tray. 0424 */ 0425 void eject(); 0426 0427 /** 0428 * Switch endless playout on/off. 0429 */ 0430 void loop(); 0431 0432 /** 0433 * Switch random playout on/off. 0434 */ 0435 void random(); 0436 0437 /** 0438 * Pipe GUI command. 0439 */ 0440 void doCommand(KCompactDisc::DiscCommand); 0441 0442 0443 void metadataLookup(); 0444 0445 0446 Q_SIGNALS: 0447 /** 0448 * A new position in a track. This signal is delivered at 0449 * approximately 1 second intervals while a track is playing. At first sight, 0450 * this might seem overzealous, but it is likely that any CD player UI will use 0451 * this to track the second-by-second position, so we may as well do it for 0452 * them. 0453 * 0454 * @param position Position within track in seconds. 0455 */ 0456 void playoutPositionChanged(unsigned int position); 0457 0458 /** 0459 * A new track is started. 0460 * 0461 * @param track Track number. 0462 */ 0463 void playoutTrackChanged(unsigned int track); 0464 0465 0466 public Q_SLOTS: 0467 0468 void setRandomPlaylist(bool); 0469 void setLoopPlaylist(bool); 0470 void setAutoMetadataLookup(bool); 0471 0472 0473 Q_SIGNALS: 0474 0475 void randomPlaylistChanged(bool); 0476 void loopPlaylistChanged(bool); 0477 0478 0479 Q_SIGNALS: 0480 0481 /** 0482 * A new Disc is inserted 0483 * 0484 */ 0485 void discChanged(unsigned int tracks); 0486 0487 /** 0488 * A new Disc information is arrived 0489 * 0490 */ 0491 void discInformation(KCompactDisc::DiscInfo info); 0492 0493 /** 0494 * A Disc status changed 0495 * 0496 */ 0497 void discStatusChanged(KCompactDisc::DiscStatus status); 0498 0499 0500 public Q_SLOTS: 0501 0502 /** 0503 * Set volume 0504 */ 0505 void setVolume(unsigned int volume); 0506 0507 /** 0508 * Set balance 0509 */ 0510 void setBalance(unsigned int balance); 0511 0512 Q_SIGNALS: 0513 0514 /** 0515 * New volume 0516 */ 0517 void volumeChanged(unsigned int volume); 0518 0519 /** 0520 * New balance 0521 */ 0522 void balanceChanged(unsigned int balance); 0523 0524 0525 protected: 0526 KCompactDiscPrivate * d_ptr; 0527 KCompactDisc(KCompactDiscPrivate &dd, QObject *parent); 0528 0529 private: 0530 Q_DECLARE_PRIVATE(KCompactDisc) 0531 #ifdef USE_WMLIB 0532 friend class KWMLibCompactDiscPrivate; 0533 #endif 0534 friend class KPhononCompactDiscPrivate; 0535 }; 0536 0537 #endif