File indexing completed on 2025-01-05 04:25:58
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * Copyright (c) 2007 Casey Link <unnamedrambler@gmail.com> * 0004 * Copyright (c) 2010 Jeff Mitchell <mitchell@kde.org> * 0005 * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de> * 0006 * * 0007 * This program is free software; you can redistribute it and/or modify it under * 0008 * the terms of the GNU General Public License as published by the Free Software * 0009 * Foundation; either version 2 of the License, or (at your option) any later * 0010 * version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #ifndef AMAROK_COLLECTION_DATABASECOLLECTION_H 0021 #define AMAROK_COLLECTION_DATABASECOLLECTION_H 0022 0023 #include "core/collections/Collection.h" 0024 #include "core/capabilities/CollectionScanCapability.h" 0025 #include "core/capabilities/CollectionImportCapability.h" 0026 0027 #include <QIcon> 0028 0029 #include <QMutex> 0030 0031 typedef QHash<QString, QString> TrackUrls; 0032 typedef QHash<QString, QPair<QString, QString> > ChangedTrackUrls; 0033 0034 class MountPointManager; 0035 class GenericScanManager; 0036 0037 namespace Collections { 0038 0039 class CollectionLocation; 0040 0041 /** The DatabaseCollection is intended to be a base class for all database backed primary collections. 0042 * Primary collection implies that the basis for the collection is a file system. 0043 * It also means that there is a scan manager that scans the file system and 0044 * a mount point manager for the dynamic collection feature (we can blend out 0045 * whole parts of the collection in case a drive is just unmounted). 0046 */ 0047 class DatabaseCollection : public Collections::Collection 0048 { 0049 Q_OBJECT 0050 0051 /** This property is important. CollectionSetup is using the property to 0052 determine the folders covered by this collection (and also setting them) */ 0053 Q_PROPERTY( QStringList collectionFolders 0054 READ collectionFolders 0055 WRITE setCollectionFolders 0056 SCRIPTABLE false 0057 DESIGNABLE false ) 0058 0059 public: 0060 /** Creates a new DatabaseCollection. 0061 */ 0062 DatabaseCollection(); 0063 ~DatabaseCollection() override; 0064 0065 QString collectionId() const override; 0066 QString prettyName() const override; 0067 QIcon icon() const override; 0068 0069 virtual GenericScanManager *scanManager() const; 0070 virtual MountPointManager *mountPointManager() const; 0071 /** This set's the mount point manager which is actually only useful for testing. 0072 * Note: The old MountPointManager is not deleted when the new one is set. 0073 */ 0074 virtual void setMountPointManager( MountPointManager *mpm ); 0075 0076 virtual QStringList collectionFolders() const; 0077 virtual void setCollectionFolders( const QStringList &folders ); 0078 0079 /** 0080 * Call this function to prevent the collection updated signal emitted. 0081 * This function can be called in preparation of larger updates. 0082 */ 0083 void blockUpdatedSignal(); 0084 0085 /** 0086 * Unblocks one blockUpdatedSignal call. If collectionUpdated() has been called, 0087 * when the update was blocked, update() will be emitted here. 0088 */ 0089 void unblockUpdatedSignal(); 0090 0091 /** 0092 * Emit updated if the signal. If it is blocked by blockUpdatedSignal(), it will 0093 * be postponed until unblockUpdatedSignal() is called, but never discarded. 0094 */ 0095 void collectionUpdated(); 0096 0097 bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override; 0098 Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override; 0099 0100 public Q_SLOTS: 0101 /** Dumps the complete database content. 0102 * The content of all Amarok tables is dumped in a couple of files 0103 * in the users homedirectory. 0104 */ 0105 virtual void dumpDatabaseContent() = 0; 0106 0107 protected Q_SLOTS: 0108 virtual void slotDeviceAdded( int id ) { Q_UNUSED( id ); } 0109 virtual void slotDeviceRemoved( int id ) { Q_UNUSED( id ); } 0110 0111 protected: 0112 MountPointManager *m_mpm; 0113 GenericScanManager *m_scanManager; 0114 0115 int m_blockUpdatedSignalCount; 0116 bool m_updatedSignalRequested; 0117 QMutex m_mutex; 0118 }; 0119 0120 class DatabaseCollectionScanCapability : public Capabilities::CollectionScanCapability 0121 { 0122 Q_OBJECT 0123 public: 0124 0125 explicit DatabaseCollectionScanCapability( DatabaseCollection* collection ); 0126 ~DatabaseCollectionScanCapability() override; 0127 0128 void startFullScan() override; 0129 void startIncrementalScan( const QString &directory = QString() ) override; 0130 void stopScan() override; 0131 0132 private: 0133 DatabaseCollection* m_collection; 0134 }; 0135 0136 class DatabaseCollectionImportCapability : public Capabilities::CollectionImportCapability 0137 { 0138 Q_OBJECT 0139 public: 0140 0141 explicit DatabaseCollectionImportCapability( DatabaseCollection* collection ); 0142 ~DatabaseCollectionImportCapability() override; 0143 0144 void import( QIODevice *input, QObject *listener ) override; 0145 0146 private: 0147 DatabaseCollection* m_collection; 0148 }; 0149 0150 0151 } 0152 0153 Q_DECLARE_METATYPE( TrackUrls ) 0154 Q_DECLARE_METATYPE( ChangedTrackUrls ) 0155 0156 #endif /* AMAROK_COLLECTION_DATABASECOLLECTION_H */