File indexing completed on 2024-04-21 04:48:20
0001 /* 0002 * Copyright (C) 2000 Rik Hemsley (rikkus) <rik@kde.org> 0003 * Copyright (C) 2000-2002 Michael Matz <matz@kde.org> 0004 * Copyright (C) 2001 Carsten Duvenhorst <duvenhorst@m2.uni-hannover.de> 0005 * Copyright (C) 2001 Adrian Schroeter <adrian@suse.de> 0006 * Copyright (C) 2003 Richard Lärkäng <richard@goteborg.utfors.se> 0007 * Copyright (C) 2003 Scott Wheeler <wheeler@kde.org> 0008 * Copyright (C) 2004-2005 Benjamin Meyer <ben at meyerhome dot net> 0009 * 0010 * This program is free software; you can redistribute it and/or modify 0011 * it under the terms of the GNU General Public License as published by 0012 * the Free Software Foundation; either version 2 of the License, or 0013 * (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU General Public License 0021 * along with this program; if not, write to the Free Software 0022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 0023 * USA. 0024 */ 0025 0026 #ifndef AUDIO_CD_H 0027 #define AUDIO_CD_H 0028 0029 #include <KIO/WorkerBase> 0030 0031 class AudioCDEncoder; 0032 0033 struct cdrom_drive; 0034 0035 namespace AudioCD { 0036 0037 /** 0038 * The core class of the audiocd:// KIO worker. 0039 * It has the KIO worker login and the ripping logic. The actual encoding 0040 * is done by encoders that are separate objects. 0041 */ 0042 class AudioCDProtocol : public KIO::WorkerBase 0043 { 0044 public: 0045 AudioCDProtocol(const QByteArray &protocol, const QByteArray &pool, const QByteArray &app); 0046 ~AudioCDProtocol() override; 0047 0048 KIO::WorkerResult get(const QUrl &) override; 0049 KIO::WorkerResult stat(const QUrl &) override; 0050 KIO::WorkerResult listDir(const QUrl &) override; 0051 0052 protected: 0053 AudioCDEncoder *encoderFromExtension(const QString &extension); 0054 AudioCDEncoder *determineEncoder(const QString &filename); 0055 0056 struct cdrom_drive *findDrive(bool &noPermission); 0057 void parseURLArgs(const QUrl &); 0058 0059 void loadSettings(); 0060 0061 /** 0062 * From the request information (Private member "d"), 0063 * get the first and last sector for the request. 0064 * return false if the parameters are invalid (for instance, 0065 * track number which does not exist on this CD) 0066 */ 0067 bool getSectorsForRequest(struct cdrom_drive *drive, long &firstSector, long &lastSector) const; 0068 0069 /** 0070 * Give the size in bytes of the space between those two 0071 * sectors, depending on the file type. 0072 */ 0073 long fileSize(long firstSector, long lastSector, AudioCDEncoder *encoder); 0074 0075 /** 0076 * The heart of this KIO worker. 0077 * Reads data off the cd and then passes it to an encoder to encode 0078 */ 0079 KIO::WorkerResult 0080 paranoiaRead(struct cdrom_drive *drive, long firstSector, long lastSector, AudioCDEncoder *encoder, const QString &fileName, unsigned long size); 0081 0082 KIO::WorkerResult initRequest(const QUrl &url, struct cdrom_drive **drive); 0083 0084 /** 0085 * Add an entry in the KIO directory, using the title you give, 0086 * it will set the extension itself depending on the fileType. 0087 * You must also give the trackNumber for the size of the file 0088 * to be calculated. 0089 * @note If you want to add a file which is the whole CD, give 0090 * trackNo = -1 0091 * 0092 * @note You can always safely add MP3 or OGG files. The function 0093 * will check if kio_audiocd was compiled with support for those, 0094 * so NO NEED to wrap your calls with #ifdef for lame or vorbis. 0095 * this function will do the right thing. 0096 */ 0097 void addEntry(const QString &trackTitle, AudioCDEncoder *encoder, struct cdrom_drive *drive, int trackNo); 0098 0099 class Private; 0100 Private *d; 0101 0102 private: 0103 void generateTemplateTitles(); 0104 KIO::WorkerResult checkNoHost(const QUrl &url); 0105 0106 QList<AudioCDEncoder *> encoders; 0107 KIO::WorkerResult getDrive(struct cdrom_drive **drive); 0108 0109 // These are the only guaranteed encoders to be built, the rest 0110 // are dynamic depending on other libraries on the system 0111 AudioCDEncoder *encoderTypeCDA; 0112 AudioCDEncoder *encoderTypeWAV; 0113 }; 0114 0115 } // end namespace AudioCD 0116 0117 #endif // AUDIO_CD_H