1 /**************************************************************************************** 2 * Copyright (c) 2014 Ralf Engels <ralf-engels@gmx.de> * 3 * * 4 * This program is free software; you can redistribute it and/or modify it under * 5 * the terms of the GNU General Public License as published by the Free Software * 6 * Foundation; either version 2 of the License, or (at your option) any later * 7 * version. * 8 * * 9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 12 * * 13 * You should have received a copy of the GNU General Public License along with * 14 * this program. If not, see <http://www.gnu.org/licenses/>. * 15 ****************************************************************************************/ 16 17 #ifndef AMAROK_STORAGEMANAGER_H 18 #define AMAROK_STORAGEMANAGER_H 19 20 #include "amarok_export.h" 21 22 #include <QObject> 23 #include <QList> 24 #include <QSharedPointer> 25 #include <QStringList> 26 27 namespace Plugins { 28 class PluginFactory; 29 } 30 31 class SqlStorage; 32 33 /** Class managing the Amarok SqlStorage 34 * 35 * This singleton class is the main responsible for providing everybody 36 * with the current SqlStorage. 37 */ 38 class AMAROK_EXPORT StorageManager : public QObject 39 { 40 Q_OBJECT 41 42 public: 43 44 /** Get THE instance of the storage manager. 45 * 46 * This function will return the storage manager 47 * that returns the sql storage to be used for Amarok. 48 * 49 * In addition to the SqlCollection a lot of other components 50 * use a sql storage to persist data. 51 * 52 */ 53 static StorageManager *instance(); 54 55 /** Destroys the instance of the StorageManager. 56 */ 57 static void destroy(); 58 59 /** 60 retrieve an interface which allows client-code to store/load data in a relational database. 61 Note: You should never modify the database unless you really really know what you do. 62 Using the SqlMeta (e.g. SqlRegistry or SqlTrack) is much better. 63 @return Returns a pointer to the amarok wide SqlStorage or 64 to an internal dummy SqlStorage if that cannot be found. 65 It never returns a null pointer. 66 */ 67 QSharedPointer<SqlStorage> sqlStorage() const; 68 69 /** 70 * Set the list of current factories 71 * 72 * For every factory that is a CollectionFactory uses it to create new 73 * collections and register with this manager. 74 */ 75 void setFactories( const QList<QSharedPointer<Plugins::PluginFactory> > &factories ); 76 77 /** Returns a list of the last sql errors. 78 The list might not include every one error if the number 79 is beyond a sensible limit. 80 */ 81 QStringList getLastErrors() const; 82 83 /** Clears the list of the last errors. */ 84 void clearLastErrors(); 85 86 private Q_SLOTS: 87 88 /** Will be called whenever a factory emits a newStorage signal. 89 * 90 * The first factory to Q_EMIT this signal will get it's storage 91 * registered as "the" storage. 92 * 93 * StorageManager will take ownership of the pointer and free it 94 * after all other plugins are done. 95 */ 96 void slotNewStorage( QSharedPointer<SqlStorage> newStorage ); 97 98 /** Will be called whenever a factory emits a newError signal. 99 * 100 * The factories will not Q_EMIT the newStorage signal in case 101 * of initialization problems. 102 * In order to report their issues they will instead Q_EMIT 103 * newError with the list of errors. 104 */ 105 void slotNewError( const QStringList &errorMessageList ); 106 107 private: 108 static StorageManager* s_instance; 109 StorageManager(); 110 ~StorageManager() override; 111 112 void init(); 113 114 115 Q_DISABLE_COPY( StorageManager ) 116 117 struct Private; 118 Private * const d; 119 }; 120 121 #endif /* AMAROK_STORAGEMANAGER_H */ 122