File indexing completed on 2024-05-05 04:48:13
0001 /**************************************************************************************** 0002 * Copyright (c) 2014 Ralf Engels <ralf-engels@gmx.de> * 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 AMAROK_STORAGEMANAGER_H 0018 #define AMAROK_STORAGEMANAGER_H 0019 0020 #include "amarok_export.h" 0021 0022 #include <QObject> 0023 #include <QList> 0024 #include <QSharedPointer> 0025 #include <QStringList> 0026 0027 namespace Plugins { 0028 class PluginFactory; 0029 } 0030 0031 class SqlStorage; 0032 0033 /** Class managing the Amarok SqlStorage 0034 * 0035 * This singleton class is the main responsible for providing everybody 0036 * with the current SqlStorage. 0037 */ 0038 class AMAROK_EXPORT StorageManager : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 0044 /** Get THE instance of the storage manager. 0045 * 0046 * This function will return the storage manager 0047 * that returns the sql storage to be used for Amarok. 0048 * 0049 * In addition to the SqlCollection a lot of other components 0050 * use a sql storage to persist data. 0051 * 0052 */ 0053 static StorageManager *instance(); 0054 0055 /** Destroys the instance of the StorageManager. 0056 */ 0057 static void destroy(); 0058 0059 /** 0060 retrieve an interface which allows client-code to store/load data in a relational database. 0061 Note: You should never modify the database unless you really really know what you do. 0062 Using the SqlMeta (e.g. SqlRegistry or SqlTrack) is much better. 0063 @return Returns a pointer to the amarok wide SqlStorage or 0064 to an internal dummy SqlStorage if that cannot be found. 0065 It never returns a null pointer. 0066 */ 0067 QSharedPointer<SqlStorage> sqlStorage() const; 0068 0069 /** 0070 * Set the list of current factories 0071 * 0072 * For every factory that is a CollectionFactory uses it to create new 0073 * collections and register with this manager. 0074 */ 0075 void setFactories( const QList<QSharedPointer<Plugins::PluginFactory> > &factories ); 0076 0077 /** Returns a list of the last sql errors. 0078 The list might not include every one error if the number 0079 is beyond a sensible limit. 0080 */ 0081 QStringList getLastErrors() const; 0082 0083 /** Clears the list of the last errors. */ 0084 void clearLastErrors(); 0085 0086 private Q_SLOTS: 0087 0088 /** Will be called whenever a factory emits a newStorage signal. 0089 * 0090 * The first factory to Q_EMIT this signal will get it's storage 0091 * registered as "the" storage. 0092 * 0093 * StorageManager will take ownership of the pointer and free it 0094 * after all other plugins are done. 0095 */ 0096 void slotNewStorage( QSharedPointer<SqlStorage> newStorage ); 0097 0098 /** Will be called whenever a factory emits a newError signal. 0099 * 0100 * The factories will not Q_EMIT the newStorage signal in case 0101 * of initialization problems. 0102 * In order to report their issues they will instead Q_EMIT 0103 * newError with the list of errors. 0104 */ 0105 void slotNewError( const QStringList &errorMessageList ); 0106 0107 private: 0108 static StorageManager* s_instance; 0109 StorageManager(); 0110 ~StorageManager() override; 0111 0112 void init(); 0113 0114 0115 Q_DISABLE_COPY( StorageManager ) 0116 0117 struct Private; 0118 Private * const d; 0119 }; 0120 0121 #endif /* AMAROK_STORAGEMANAGER_H */