File indexing completed on 2022-11-23 11:08:49

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003-2015 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDB_DRIVER_MANAGER_P_H
0021 #define KDB_DRIVER_MANAGER_P_H
0022 
0023 #include <QMap>
0024 #include "config-kdb.h"
0025 #include "KDbResult.h"
0026 
0027 class KDbDriverMetaData;
0028 class KDbDriver;
0029 
0030 //! Internal class of the KDbDriverManager.
0031 class KDB_TESTING_EXPORT DriverManagerInternal : public QObject, public KDbResultable
0032 {
0033     Q_OBJECT
0034 public:
0035     /*! Used by self() */
0036     DriverManagerInternal();
0037 
0038     ~DriverManagerInternal() override;
0039 
0040     QStringList driverIds();
0041 
0042     /*! Tries to load a driver with identifier @a id.
0043       @return db driver, or @c nullptr on error (then error result is also set) */
0044     KDbDriver* driver(const QString& id);
0045 
0046     const KDbDriverMetaData* driverMetaData(const QString &id);
0047 
0048     QStringList driverIdsForMimeType(const QString& mimeType);
0049 
0050     QStringList possibleProblems() const;
0051 
0052     static DriverManagerInternal *self();
0053 
0054 #ifdef BUILD_TESTING
0055     //! If @c true, sets the driver manager to have no drivers so this case can be tested.
0056     //! Afects driverIds(), driver(), driverMetaData(), driverIdsForMimeType()
0057     bool forceEmpty = false;
0058 #else
0059     const bool forceEmpty = false;
0060 #endif
0061 
0062 protected Q_SLOTS:
0063     /*! Used to destroy all drivers on QApplication quit, so even if there are
0064      KDbDriverManager's static instances that are destroyed on program
0065      "static destruction", drivers are not kept after QApplication death.
0066     */
0067     void slotAppQuits();
0068 
0069 private:
0070     Q_DISABLE_COPY(DriverManagerInternal)
0071 
0072     bool lookupDrivers();
0073     void lookupDriversInternal();
0074     void clear();
0075 
0076     QMap<QString, KDbDriverMetaData*> m_metadata_by_mimetype;
0077     QMap<QString, KDbDriverMetaData*> m_driversMetaData; //!< used to store driver metadata
0078     QMap<QString, KDbDriver*> m_drivers; //!< for owning drivers
0079     QString m_pluginsDir;
0080     QStringList m_possibleProblems;
0081     bool m_lookupDriversNeeded;
0082 };
0083 
0084 #endif