File indexing completed on 2025-01-19 04:24:19
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AUDIOCDCOLLECTION_H 0018 #define AUDIOCDCOLLECTION_H 0019 0020 #include "core/collections/Collection.h" 0021 #include "MediaDeviceCollection.h" 0022 #include "MemoryCollection.h" 0023 #include "core-impl/meta/proxy/MetaProxy.h" 0024 0025 #include <QAction> 0026 #include <QObject> 0027 #include <QUrl> 0028 0029 #include <KIO/UDSEntry> 0030 0031 class MediaDeviceInfo; 0032 class KJob; 0033 namespace Collections { 0034 0035 class AudioCdCollection; 0036 0037 class AudioCdCollectionFactory : public MediaDeviceCollectionFactory<AudioCdCollection> 0038 { 0039 Q_PLUGIN_METADATA(IID AmarokPluginFactory_iid FILE "amarok_collection-audiocdcollection.json") 0040 Q_INTERFACES(Plugins::PluginFactory) 0041 Q_OBJECT 0042 0043 public: 0044 AudioCdCollectionFactory(); 0045 ~AudioCdCollectionFactory() override {} 0046 0047 /* virtual void init(); 0048 0049 private Q_SLOTS: 0050 void audioCdAdded( const QString &uid ); 0051 void deviceRemoved( const QString &uid ); 0052 0053 private: 0054 0055 QString m_currentUid; 0056 AudioCdCollection * m_collection;*/ 0057 0058 }; 0059 0060 0061 /** 0062 * This is a Memorycollection subclass that uses the KIO audiocd:/ slave to 0063 * populate itself whenever it detects a CD. 0064 * 0065 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0066 */ 0067 class AudioCdCollection : public MediaDeviceCollection 0068 { 0069 Q_OBJECT 0070 public: 0071 0072 enum { WAV, FLAC, OGG, MP3 } EncodingFormat; 0073 0074 explicit AudioCdCollection( MediaDeviceInfo* info ); 0075 ~AudioCdCollection() override; 0076 0077 QString encodingFormat() const; 0078 QString copyableFilePath( const QString &fileName ) const; 0079 0080 void setEncodingFormat( int format ) const; 0081 0082 QString collectionId() const override; 0083 QString prettyName() const override; 0084 QIcon icon() const override; 0085 0086 CollectionLocation* location() override; 0087 0088 bool possiblyContainsTrack( const QUrl &url ) const override; 0089 Meta::TrackPtr trackForUrl( const QUrl &url ) override; 0090 0091 void cdRemoved(); 0092 0093 virtual void startFullScan(); //Override this one as I really don't want to move parsing to the handler atm. 0094 void startFullScanDevice() override { startFullScan(); } 0095 0096 public Q_SLOTS: 0097 void eject() override; 0098 0099 private Q_SLOTS: 0100 void audioCdEntries( KIO::Job *job, const KIO::UDSEntryList &list ); 0101 void slotEntriesJobDone( KJob *job ); 0102 void infoFetchComplete( KJob *job ); 0103 void checkForStartPlayRequest(); 0104 0105 private: 0106 void readAudioCdSettings(); 0107 0108 // Helper function to build the audiocd url. 0109 QUrl audiocdUrl( const QString &path = "" ) const; 0110 // The file name of the track without extension 0111 QString trackBaseFileName( int i ) const; 0112 // The file name of the track in .wav format 0113 QString trackWavFileName( int i ) const; 0114 // The name of the track that should be displayed 0115 QString trackDisplayName( int i ) const; 0116 // The length of the track in milliseconds 0117 qint64 trackLength( int i ) const; 0118 0119 /** 0120 * Clear collection and read the CD currently in the drive, adding Artist, Album, 0121 * Genre, Year and whatnot as detected by audiocd using CDDB. 0122 */ 0123 void readCd(); 0124 0125 void noInfoAvailable(); 0126 0127 void updateProxyTracks(); 0128 0129 QMap<int, QUrl> m_cddbTextFiles; 0130 0131 QString m_cdName; 0132 QString m_discCddbId; 0133 QString m_udi; 0134 QString m_device; 0135 mutable int m_encodingFormat; 0136 0137 QString m_fileNamePattern; 0138 QString m_albumNamePattern; 0139 0140 QMap<QUrl, MetaProxy::Track*> m_proxyMap; 0141 }; 0142 0143 } //namespace Collections 0144 0145 #endif