File indexing completed on 2024-04-21 04:40:31

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
0003    Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
0004    Copyright (C) 2003-2015 Jarosław Staniek <staniek@kde.org>
0005    Copyright (C) 2012 Dimitrios T. Tanis <dimitrios.tanis@kdemail.net>
0006 
0007    This program is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This program is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this program; see the file COPYING.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KDB_DRIVER_MANAGER_H
0024 #define KDB_DRIVER_MANAGER_H
0025 
0026 #include <QString>
0027 #include <QCoreApplication>
0028 
0029 #include "kdb_export.h"
0030 
0031 class KDbResult;
0032 class KDbResultable;
0033 class KDbDriver;
0034 class KDbDriverMetaData;
0035 
0036 //! A driver manager for finding and loading driver plugins.
0037 class KDB_EXPORT KDbDriverManager
0038 {
0039     Q_DECLARE_TR_FUNCTIONS(KDbDriverManager)
0040 public:
0041     KDbDriverManager();
0042     virtual ~KDbDriverManager();
0043 
0044     //! @return result of the recent operation.
0045     KDbResult result() const;
0046 
0047     //! @return KDbResultable object for the recent operation.
0048     //! It adds serverResultName() in addition to the result().
0049     KDbResultable* resultable() const;
0050 
0051     /*! @return information (metadata) about driver with ID @a id.
0052       The lookup is case insensitive.
0053       The metadata object is owned by KDb internals and is not deleted after
0054       this KDbDriverManager object is deleted.
0055       @a nullptr is returned if the metadata has not been found.
0056       On error status can be obtained using result().
0057 
0058       @see driver(const QString& id) for information about duplicated drivers. */
0059     const KDbDriverMetaData* driverMetaData(const QString &id);
0060 
0061     /*! Tries to load db driver with ID @a id.
0062       The lookup is case insensitive.
0063       @return driver object or @a nullptr on error.
0064       On error status can be obtained using result().
0065       The driver object is owned by KDb internals and is not deleted after
0066       this KDbDriverManager object is deleted.
0067 
0068       @note If more than one driver with the same ID found on the search path, first
0069       located driver is selected. All other drivers for this ID are skip with a warning
0070       "Driver with ID '...' already found at (path) -- skipping another at (path).
0071       The warning can be suppressed by setting a KDB_NO_DUPLICATED_DRIVER_WARNINGS
0072       environment variable. */
0073     KDbDriver* driver(const QString& id);
0074 
0075     /*! returns list of available drivers IDs.
0076       That drivers can be loaded by first use of driver() method. */
0077     QStringList driverIds();
0078 
0079     /**
0080      * Returns list of driver IDs for @a mimeType MIME type
0081      *
0082      * IDs of drivers for file-based databases are only returned.
0083      * Empty list is returned if no driver has been found for the type or if the type is invalid.
0084      * Driver supports the supplied MIME type if it is specified as supported in the driver's
0085      * metadata. If a MIME type alias is supplied, proper type for this alias is resolved and driver
0086      * IDs for that type are returned. Similarly, if proper MIME type is supplied, IDs are returned
0087      * for drivers that support any alias for this type.
0088      *
0089      * The lookup is case insensitive.
0090      */
0091     QStringList driverIdsForMimeType(const QString& mimeType);
0092 
0093     /*! @return HTML-formatted message about possible problems encountered.
0094      It can be displayed in a 'details' section of a GUI message if an error encountered.
0095      Currently the message contains a list of incompatible db drivers.
0096      Can be used in code that finds driver depending on file format. */
0097 //! @todo make it just QStringList
0098     QString possibleProblemsMessage() const;
0099 
0100     /*! @return true if there is at least one server-based database driver installed. */
0101     bool hasDatabaseServerDrivers();
0102 
0103 private:
0104     Q_DISABLE_COPY(KDbDriverManager)
0105 };
0106 
0107 #endif