23#include "KDbDriverManager.h"
24#include "KDbDriverManager_p.h"
25#include "KDbJsonTrader_p.h"
27#include "KDbDriverMetaData.h"
30#include <KPluginFactory>
32#include <QApplication>
33#include <QMimeDatabase>
37Q_GLOBAL_STATIC(DriverManagerInternal, s_self)
39DriverManagerInternal::DriverManagerInternal()
40 : m_lookupDriversNeeded(true)
45DriverManagerInternal::~DriverManagerInternal()
49 drivermanagerDebug() <<
"ok";
52void DriverManagerInternal::clear()
54 drivermanagerDebug() <<
"Clearing drivers...";
55 qDeleteAll(m_drivers);
57 qDeleteAll(m_driversMetaData);
58 m_driversMetaData.clear();
61void DriverManagerInternal::slotAppQuits()
63 if (qApp && !qApp->topLevelWidgets().isEmpty()
64 && qApp->topLevelWidgets().first()->isVisible()) {
71DriverManagerInternal *DriverManagerInternal::self()
76bool DriverManagerInternal::lookupDrivers()
78 if (!m_lookupDriversNeeded)
82 lookupDriversInternal();
83 m_lookupDriversNeeded =
false;
85 if (m_driversMetaData.isEmpty()) {
87 tr(
"Could not find any database drivers."));
93void DriverManagerInternal::lookupDriversInternal()
96 connect(qApp, SIGNAL(aboutToQuit()),
this, SLOT(slotAppQuits()));
105 .
arg(KDB_STABLE_VERSION_MAJOR).
arg(KDB_STABLE_VERSION_MINOR);
112 if (metaData->version() != expectedVersion) {
113 kdbWarning() <<
"Driver with ID" << metaData->id()
114 <<
"(" << metaData->fileName() <<
")"
115 <<
"has version" << metaData->version() <<
"but expected version is"
120 if (m_driversMetaData.contains(metaData->id())) {
121 if (qEnvironmentVariableIsEmpty(
"KDB_NO_DUPLICATED_DRIVER_WARNINGS")) {
122 kdbWarning() <<
"Driver with ID" << metaData->id() <<
"already found at"
123 << m_driversMetaData.value(metaData->id())->fileName()
124 <<
"-- skipping another at" << metaData->fileName();
129 for (
const QString &mimeType : metaData->mimeTypes()) {
132 kdbWarning() <<
"Driver with ID" << metaData->id()
133 <<
"specifies the unknown MIME type"
139 for (
const QString &mimeType : resolvedMimeTypes) {
140 m_metadata_by_mimetype.insertMulti(mimeType, metaData.data());
142 m_driversMetaData.
insert(metaData->id(), metaData.data());
151 if (!lookupDrivers()) {
154 if (m_driversMetaData.isEmpty() && result().isError()) {
157 return m_driversMetaData.keys();
162 if (!lookupDrivers()) {
166 if (!metaData || m_result.isError()) {
168 tr(
"Could not find database driver \"%1\".").arg(
id));
175 if (!lookupDrivers()) {
191QStringList DriverManagerInternal::possibleProblems()
const
193 return m_possibleProblems;
198 if (!lookupDrivers())
202 drivermanagerDebug() <<
"loading" << id;
206 driver = m_drivers.value(
id.toLower());
211 if (!m_driversMetaData.contains(
id.toLower())) {
213 tr(
"Could not find database driver \"%1\".").arg(
id));
218 KPluginFactory *factory = qobject_cast<KPluginFactory*>(metaData->instantiate());
221 tr(
"Could not load database driver's plugin file \"%1\".")
226 kdbWarning() << m_result.message() << m_result.serverMessage();
232 tr(
"Could not open database driver \"%1\" from plugin file \"%2\".")
235 kdbWarning() << m_result.message();
239 m_drivers.insert(
id.toLower(), driver);
245KDbDriverManager::KDbDriverManager()
249KDbDriverManager::~KDbDriverManager()
255 return s_self->result();
265 return s_self->driverIds();
270 return s_self->driverMetaData(
id);
275 return s_self->driverIdsForMimeType(mimeType);
280 return s_self->driver(
id);
285 if (s_self->possibleProblems().isEmpty()) {
291 foreach (
const QString& problem, s_self->possibleProblems())
QStringList driverIdsForMimeType(const QString &mimeType)
Returns list of driver IDs for mimeType MIME type.
const KDbDriverMetaData * driverMetaData(const QString &id)
KDbResultable * resultable() const
bool hasDatabaseServerDrivers()
QString possibleProblemsMessage() const
KDbDriver * driver(const QString &id)
Database driver's abstraction.
void setMetaData(const KDbDriverMetaData *metaData)
Interface for classes providing a result.
T * create(QObject *parent=nullptr, const QVariantList &args={})
KCALUTILS_EXPORT QString mimeType()
void append(QList< T > &&value)
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
bool isValid() const const
QString errorString() const const
iterator insert(const T &value)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
void reserve(qsizetype size)
QString toLower() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)