aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/services
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2015-04-19 22:30:43 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2015-04-19 22:30:43 -0400
commit094918f048c81474b22f9ba2940c96dc4033d753 (patch)
tree2b89c77ad7dc9c55e9ba383f23f9f25b82df358e /SQLiteStudio3/coreSQLiteStudio/services
parent640fff60ceecde402131937dddb3458f7a003e9c (diff)
parenta308f430f694423064ebc86fd0506c8c6fdb3d93 (diff)
Merge tag 'upstream/3.0.5'
Upstream version 3.0.5 # gpg: Signature made Sun 19 Apr 2015 10:30:41 PM EDT using RSA key ID EBE9BD91 # gpg: Good signature from "Unit 193 <unit193@gmail.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.org>" # gpg: aka "Unit 193 <unit193@ubuntu.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.com>"
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/services')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h2
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp148
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h1
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/services/populatemanager.cpp1
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/services/populatemanager.h1
5 files changed, 115 insertions, 38 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h b/SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h
index 5a56151..66bbf08 100644
--- a/SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h
+++ b/SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h
@@ -189,6 +189,8 @@ class API_EXPORT DbManager : public QObject
*/
virtual void notifyDatabasesAreLoaded() = 0;
+ virtual void rescanInvalidDatabasesForPlugin(DbPlugin* dbPlugin) = 0;
+
signals:
/**
* @brief Application just connected to the database.
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp
index e96e181..a7bff0d 100644
--- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp
@@ -81,8 +81,12 @@ bool DbManagerImpl::updateDb(Db* db, const QString &name, const QString &path, c
return false;
}
- QDir pathDir(path);
- QString normalizedPath = pathDir.absolutePath();
+ QString normalizedPath;
+ QUrl url(path);
+ if (url.scheme().isEmpty() || url.scheme() == "file")
+ normalizedPath = QDir(path).absolutePath();
+ else
+ normalizedPath = path;
listLock.lockForWrite();
nameToDb.remove(db->getName(), Qt::CaseInsensitive);
@@ -343,6 +347,66 @@ void DbManagerImpl::scanForNewDatabasesInConfig()
}
}
+void DbManagerImpl::rescanInvalidDatabasesForPlugin(DbPlugin* dbPlugin)
+{
+ if (!dbPlugin)
+ {
+ qWarning() << "Call to DbManagerImpl::rescanInvalidDatabasesForPlugin() with null plugin.";
+ return;
+ }
+
+ Db* db = nullptr;
+
+ QUrl url;
+ QString errorMessages;
+ for (Db* invalidDb : getInvalidDatabases())
+ {
+ if (invalidDb->getConnectionOptions().contains(DB_PLUGIN) && invalidDb->getConnectionOptions()[DB_PLUGIN].toString() != dbPlugin->getName())
+ continue;
+
+ url = QUrl::fromUserInput(invalidDb->getPath());
+ if (url.isLocalFile() && !QFile::exists(invalidDb->getPath()))
+ continue;
+
+ errorMessages = QString();
+ db = createDb(invalidDb->getName(), invalidDb->getPath(), invalidDb->getConnectionOptions(), &errorMessages);
+ if (!db)
+ {
+ if (!errorMessages.isNull())
+ {
+ dynamic_cast<InvalidDb*>(invalidDb)->setError(errorMessages);
+ }
+ continue; // For this db driver was not loaded yet.
+ }
+
+ if (!dbPlugin->checkIfDbServedByPlugin(db))
+ {
+ qDebug() << "Managed to load database" << db->getPath() << " (" << db->getName() << ")"
+ << "but it doesn't use DbPlugin that was just loaded, so it will not be loaded to the db manager";
+
+ delete db;
+ continue;
+ }
+
+ removeDbInternal(invalidDb, false);
+ delete invalidDb;
+
+ addDbInternal(db, false);
+
+ if (!db->getConnectionOptions().contains(DB_PLUGIN))
+ {
+ db->getConnectionOptions()[DB_PLUGIN] = dbPlugin->getName();
+ if (!CFG->updateDb(db->getName(), db->getName(), db->getPath(), db->getConnectionOptions()))
+ qWarning() << "Could not store handling plugin in options for database" << db->getName();
+ }
+
+ if (CFG->getDbGroup(db->getName())->open)
+ db->open();
+
+ emit dbLoaded(db);
+ }
+}
+
void DbManagerImpl::addDbInternal(Db* db, bool alsoToConfig)
{
if (alsoToConfig)
@@ -391,17 +455,23 @@ Db* DbManagerImpl::tryToLoadDb(InvalidDb* invalidDb, bool emitNotifySignal)
Db* DbManagerImpl::createDb(const QString &name, const QString &path, const QHash<QString,QVariant> &options, QString* errorMessages)
{
QList<DbPlugin*> dbPlugins = PLUGINS->getLoadedPlugins<DbPlugin>();
- DbPlugin* dbPlugin = nullptr;
Db* db = nullptr;
QStringList messages;
QString message;
- QDir pathDir(path); // Using QDir to normalize separator
- foreach (dbPlugin, dbPlugins)
+
+ QString normalizedPath;
+ QUrl url(path);
+ if (url.scheme().isEmpty() || url.scheme() == "file")
+ normalizedPath = QDir(path).absolutePath();
+ else
+ normalizedPath = path;
+
+ for (DbPlugin* dbPlugin : dbPlugins)
{
if (options.contains("plugin") && options["plugin"] != dbPlugin->getName())
continue;
- db = dbPlugin->getInstance(name, pathDir.absolutePath(), options, &message);
+ db = dbPlugin->getInstance(name, normalizedPath, options, &message);
if (!db)
{
messages << message;
@@ -410,6 +480,7 @@ Db* DbManagerImpl::createDb(const QString &name, const QString &path, const QHas
if (!db->initAfterCreated())
{
+ safe_delete(db);
messages << tr("Database could not be initialized.");
continue;
}
@@ -506,46 +577,47 @@ void DbManagerImpl::loaded(Plugin* plugin, PluginType* type)
return;
DbPlugin* dbPlugin = dynamic_cast<DbPlugin*>(plugin);
- Db* db = nullptr;
+ rescanInvalidDatabasesForPlugin(dbPlugin);
+// Db* db = nullptr;
- QUrl url;
- for (Db* invalidDb : getInvalidDatabases())
- {
- if (invalidDb->getConnectionOptions().contains(DB_PLUGIN) && invalidDb->getConnectionOptions()[DB_PLUGIN].toString() != dbPlugin->getName())
- continue;
+// QUrl url;
+// for (Db* invalidDb : getInvalidDatabases())
+// {
+// if (invalidDb->getConnectionOptions().contains(DB_PLUGIN) && invalidDb->getConnectionOptions()[DB_PLUGIN].toString() != dbPlugin->getName())
+// continue;
- url = QUrl::fromUserInput(invalidDb->getPath());
- if (url.isLocalFile() && !QFile::exists(invalidDb->getPath()))
- continue;
+// url = QUrl::fromUserInput(invalidDb->getPath());
+// if (url.isLocalFile() && !QFile::exists(invalidDb->getPath()))
+// continue;
- db = createDb(invalidDb->getName(), invalidDb->getPath(), invalidDb->getConnectionOptions());
- if (!db)
- continue; // For this db driver was not loaded yet.
+// db = createDb(invalidDb->getName(), invalidDb->getPath(), invalidDb->getConnectionOptions());
+// if (!db)
+// continue; // For this db driver was not loaded yet.
- if (!dbPlugin->checkIfDbServedByPlugin(db))
- {
- qDebug() << "Managed to load database" << db->getPath() << " (" << db->getName() << ")"
- << "but it doesn't use DbPlugin that was just loaded, so it will not be loaded to the db manager";
+// if (!dbPlugin->checkIfDbServedByPlugin(db))
+// {
+// qDebug() << "Managed to load database" << db->getPath() << " (" << db->getName() << ")"
+// << "but it doesn't use DbPlugin that was just loaded, so it will not be loaded to the db manager";
- delete db;
- continue;
- }
+// delete db;
+// continue;
+// }
- removeDbInternal(invalidDb, false);
- delete invalidDb;
+// removeDbInternal(invalidDb, false);
+// delete invalidDb;
- addDbInternal(db, false);
+// addDbInternal(db, false);
- if (!db->getConnectionOptions().contains(DB_PLUGIN))
- {
- db->getConnectionOptions()[DB_PLUGIN] = dbPlugin->getName();
- if (!CFG->updateDb(db->getName(), db->getName(), db->getPath(), db->getConnectionOptions()))
- qWarning() << "Could not store handling plugin in options for database" << db->getName();
- }
+// if (!db->getConnectionOptions().contains(DB_PLUGIN))
+// {
+// db->getConnectionOptions()[DB_PLUGIN] = dbPlugin->getName();
+// if (!CFG->updateDb(db->getName(), db->getName(), db->getPath(), db->getConnectionOptions()))
+// qWarning() << "Could not store handling plugin in options for database" << db->getName();
+// }
- if (CFG->getDbGroup(db->getName())->open)
- db->open();
+// if (CFG->getDbGroup(db->getName())->open)
+// db->open();
- emit dbLoaded(db);
- }
+// emit dbLoaded(db);
+// }
}
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h
index 5797ac6..67a1335 100644
--- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h
+++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h
@@ -178,6 +178,7 @@ class API_EXPORT DbManagerImpl : public DbManager
public slots:
void notifyDatabasesAreLoaded();
void scanForNewDatabasesInConfig();
+ void rescanInvalidDatabasesForPlugin(DbPlugin* dbPlugin);
};
#endif // DBMANAGERIMPL_H
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.cpp b/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.cpp
index 237667d..02ba549 100644
--- a/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.cpp
@@ -55,6 +55,7 @@ void PopulateManager::populate(Db* db, const QString& table, const QHash<QString
PopulateWorker* worker = new PopulateWorker(db, table, columns, engineList, rows);
connect(worker, SIGNAL(finished(bool)), this, SLOT(finalizePopulating(bool)));
+ connect(worker, SIGNAL(finishedStep(int)), this, SIGNAL(finishedStep(int)));
connect(this, SIGNAL(orderWorkerToInterrupt()), worker, SLOT(interrupt()));
QThreadPool::globalInstance()->start(worker);
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.h b/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.h
index 05b1f82..b445a9a 100644
--- a/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.h
+++ b/SQLiteStudio3/coreSQLiteStudio/services/populatemanager.h
@@ -41,6 +41,7 @@ class API_EXPORT PopulateManager : public PluginServiceBase
void populatingSuccessful();
void populatingFailed();
void orderWorkerToInterrupt();
+ void finishedStep(int step);
};
#define POPULATE_MANAGER SQLITESTUDIO->getPopulateManager()