Commit 37f5f5d5 authored by Francesco Riosa's avatar Francesco Riosa
Browse files

Split "images" and "thumbnails" databases.

This commit splits the configure options of the images and thumbnail
databases, will then be possible use different database servers.
Also the migration dialog is now more flexible.

GUI: migrationdlg.cpp databasewidget.cpp
CCBUG: 277242
parent 30e61b7d
......@@ -146,7 +146,7 @@ DatabaseServerError DatabaseServer::startMYSQLDatabaseProcess()
{
DatabaseServerError result;
const QString dbType(DatabaseParameters::MySQLDatabaseType());
DatabaseParameters internalServerParameters = DatabaseParameters::defaultParameters(dbType);
DatabaseParameters internalServerParameters = DatabaseParameters::defaultParameters(dbType, true);
//TODO Don't know if this is needed, because after the thread is finished, the database server manager should close
d->pollThread->stop = false;
......
......@@ -77,6 +77,7 @@ extern "C"
// Local includes
#include "config-digikam.h"
#include "albumdb.h"
#include "album.h"
#include "albumsettings.h"
......@@ -239,7 +240,7 @@ public:
// build list
foreach (const QFileInfo& info, fileInfoList)
{
// ignore digikam4.db and journal and other temporary files
// ignore DIGIKAM4DB and journal and other temporary files
if (!dirWatchBlackList.contains(info.fileName()))
{
modList << info.lastModified();
......@@ -405,16 +406,28 @@ void AlbumManager::cleanUp()
}
}
bool AlbumManager::databaseEqual(const QString& dbType, const QString& dbName,
bool AlbumManager::imgDatabaseEqual(const QString& dbType, const QString& dbName,
const QString& dbHostName, int dbPort, bool dbInternalServer) const
{
DatabaseParameters params = DatabaseAccess::parameters();
return params.databaseType == dbType &&
params.databaseName == dbName &&
params.hostName == dbHostName &&
params.port == dbPort &&
return params.imgDatabaseType == dbType &&
params.imgDatabaseName == dbName &&
params.imgHostName == dbHostName &&
params.imgPort == dbPort &&
params.internalServer == dbInternalServer;
//FIXME: dbInternalServer
}
bool AlbumManager::tmbDatabaseEqual(const QString& dbType, const QString& dbName,
const QString& dbHostName, int dbPort) const
{
DatabaseParameters params = DatabaseAccess::parameters();
return params.tmbDatabaseType == dbType &&
params.tmbDatabaseName == dbName &&
params.tmbHostName == dbHostName &&
params.tmbPort == dbPort;
}
static bool moveToBackup(const QFileInfo& info)
......@@ -465,7 +478,7 @@ void AlbumManager::checkDatabaseDirsAfterFirstRun(const QString& dbPath, const Q
QDir newDir(dbPath);
QDir albumDir(albumPath);
DatabaseParameters newParams = DatabaseParameters::parametersForSQLiteDefaultFile(newDir.path());
QFileInfo digikam4DB(newParams.SQLiteDatabaseFile());
QFileInfo digikam4DB(newParams.imgSQLiteDatabaseFile());
if (!digikam4DB.exists())
{
......@@ -510,10 +523,10 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
DatabaseParameters params = DatabaseAccess::parameters();
// New database type SQLITE
if (newParams.isSQLite())
if (newParams.isImgSQLite())
{
QDir newDir(newParams.getDatabaseNameOrDir());
QFileInfo newFile(newDir, QString("digikam4.db"));
QDir newDir(newParams.getImgDatabaseNameOrDir());
QFileInfo newFile(newDir, QString(DIGIKAM4DB));
if (!newFile.exists())
{
......@@ -527,7 +540,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
KGuiItem upgrade(i18n("Upgrade Database"), "view-refresh");
int result = -1;
if (params.isSQLite())
if (params.isImgSQLite())
{
result = KMessageBox::warningYesNoCancel(0,
i18n("<p>You have chosen the folder \"%1\" as the new place to store the database. "
......@@ -566,7 +579,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
else if (result == KMessageBox::Cancel)
{
QDir oldDir(d->dbName);
QFileInfo oldFile(params.SQLiteDatabaseFile());
QFileInfo oldFile(params.imgSQLiteDatabaseFile());
copyToNewLocation(oldFile, newFile, i18n("Failed to copy the old database file (\"%1\") "
"to its new location (\"%2\"). "
"Trying to upgrade old databases.",
......@@ -577,7 +590,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
{
int result = KMessageBox::Yes;
if (params.isSQLite())
if (params.isImgSQLite())
{
KGuiItem copyCurrent(i18n("Copy Current Database"), "edit-copy");
KGuiItem startFresh(i18n("Create New Database"), "document-new");
......@@ -593,7 +606,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
if (result == KMessageBox::No)
{
QDir oldDir(d->dbName);
QFileInfo oldFile(params.SQLiteDatabaseFile());
QFileInfo oldFile(params.imgSQLiteDatabaseFile());
copyToNewLocation(oldFile, newFile);
}
}
......@@ -602,7 +615,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
{
int result = KMessageBox::No;
if (params.isSQLite())
if (params.isImgSQLite())
{
KGuiItem replaceItem(i18n("Copy Current Database"), "edit-copy");
KGuiItem useExistingItem(i18n("Use Existing File"), "document-open");
......@@ -622,7 +635,7 @@ void AlbumManager::changeDatabase(const DatabaseParameters& newParams)
if (moveToBackup(newFile))
{
QDir oldDir(d->dbName);
QFileInfo oldFile(params.SQLiteDatabaseFile());
QFileInfo oldFile(params.imgSQLiteDatabaseFile());
// then copy
copyToNewLocation(oldFile, newFile);
......@@ -986,9 +999,9 @@ bool AlbumManager::setDatabase(const DatabaseParameters& params, bool priority,
#ifdef USE_THUMBS_DB
QApplication::setOverrideCursor(Qt::WaitCursor);
if (params.isSQLite())
if (params.isTmbSQLite())
{
d->dirWatchBlackList << "thumbnails-digikam.db" << "thumbnails-digikam.db-journal";
d->dirWatchBlackList << THUMBNAILS_DIGIKAMDB << "thumbnails-digikam.db-journal";
}
ThumbnailLoadThread::initializeThumbnailDatabase(DatabaseAccess::parameters().thumbnailParameters(),
......@@ -1003,9 +1016,9 @@ bool AlbumManager::setDatabase(const DatabaseParameters& params, bool priority,
// -- ---------------------------------------------------------
// measures to filter out KDirWatch signals caused by database operations
if (params.isSQLite())
if (params.isImgSQLite())
{
QFileInfo dbFile(params.SQLiteDatabaseFile());
QFileInfo dbFile(params.imgSQLiteDatabaseFile());
d->dirWatchBlackList << dbFile.fileName() << dbFile.fileName() + "-journal";
// ensure this is done after setting up the black list
......@@ -3401,7 +3414,7 @@ void AlbumManager::slotDirWatchDirty(const QString& path)
DatabaseParameters params = DatabaseAccess::parameters();
if (params.isSQLite())
if (params.isImgSQLite())
{
QFileInfo info(path);
QDir dir;
......@@ -3415,7 +3428,7 @@ void AlbumManager::slotDirWatchDirty(const QString& path)
dir = info.dir();
}
QFileInfo dbFile(params.SQLiteDatabaseFile());
QFileInfo dbFile(params.imgSQLiteDatabaseFile());
// Workaround for broken KDirWatch in KDE 4.2.4
if (path.startsWith(dbFile.filePath()))
......
......@@ -125,7 +125,12 @@ public:
/**
* Checks if the given database path is equal to the current one
*/
bool databaseEqual(const QString& dbType, const QString& dbName, const QString& dbHostName, int dbPort, bool dbInternalServer) const;
bool imgDatabaseEqual(const QString& dbType, const QString& dbName, const QString& dbHostName, int dbPort, bool dbInternalServer) const;
/**
* Checks if the given database path is equal to the current one
*/
bool tmbDatabaseEqual(const QString& dbType, const QString& dbName, const QString& dbHostName, int dbPort) const;
/**
* starts scanning the libraryPath and listing the albums. If the
......
......@@ -81,16 +81,16 @@ DatabaseConnectionChecker::~DatabaseConnectionChecker()
void DatabaseConnectionChecker::run()
{
QString databaseID("ConnectionTest");
QSqlDatabase databaseHandler = QSqlDatabase::addDatabase(d->parameters.databaseType, databaseID);
databaseHandler.setHostName(d->parameters.hostName);
databaseHandler.setPort(d->parameters.port);
QSqlDatabase databaseHandler = QSqlDatabase::addDatabase(d->parameters.imgDatabaseType, databaseID);
databaseHandler.setHostName(d->parameters.imgHostName);
databaseHandler.setPort(d->parameters.imgPort);
databaseHandler.setDatabaseName(d->parameters.databaseName);
databaseHandler.setDatabaseName(d->parameters.imgDatabaseName);
databaseHandler.setUserName(d->parameters.userName);
databaseHandler.setPassword(d->parameters.password);
databaseHandler.setUserName(d->parameters.imgUserName);
databaseHandler.setPassword(d->parameters.imgPassword);
databaseHandler.setConnectOptions(d->parameters.connectOptions);
databaseHandler.setConnectOptions(d->parameters.imgConnectOptions);
int iteration = 1;
......
......@@ -78,7 +78,7 @@ DBStatDlg::DBStatDlg(QWidget* parent)
new QTreeWidgetItem(listView(), QStringList() << i18n("Tags") << QString::number(tags));
// Database Backend information
QString dbBe = AlbumSettings::instance()->getDatabaseType();
QString dbBe = AlbumSettings::instance()->getImgDatabaseType();
new QTreeWidgetItem(listView(), QStringList() << i18n("Database backend") << dbBe);
if (dbBe != QString("QSQLITE"))
......
......@@ -2493,13 +2493,28 @@ void DigikamApp::slotSetupChanged()
//if(AlbumSettings::instance()->getAlbumLibraryPath() != AlbumManager::instance()->getLibraryPath())
// d->view->clearHistory();
if (!AlbumManager::instance()->databaseEqual(AlbumSettings::instance()->getDatabaseType(),
AlbumSettings::instance()->getDatabaseName(), AlbumSettings::instance()->getDatabaseHostName(),
AlbumSettings::instance()->getDatabasePort(), AlbumSettings::instance()->getInternalDatabaseServer()))
//FIXME: getInternalDatabaseServer
if (!AlbumManager::instance()->imgDatabaseEqual(AlbumSettings::instance()->getImgDatabaseType(),
AlbumSettings::instance()->getImgDatabaseName(),
AlbumSettings::instance()->getImgDatabaseHostName(),
AlbumSettings::instance()->getImgDatabasePort(),
AlbumSettings::instance()->getInternalDatabaseServer()))
{
AlbumManager::instance()->changeDatabase(AlbumSettings::instance()->getDatabaseParameters());
}
if (!AlbumManager::instance()->tmbDatabaseEqual(AlbumSettings::instance()->getTmbDatabaseType(),
AlbumSettings::instance()->getTmbDatabaseName(),
AlbumSettings::instance()->getTmbDatabaseHostName(),
AlbumSettings::instance()->getTmbDatabasePort()))
{
AlbumManager::instance()->changeDatabase(AlbumSettings::instance()->getDatabaseParameters());
}
if (AlbumSettings::instance()->getShowFolderTreeViewItemsCount())
{
AlbumManager::instance()->prepareItemCounts();
......
......@@ -754,15 +754,26 @@ void AlbumSettings::emitSetupChanged()
emit setupChanged();
}
QString AlbumSettings::getDatabaseFilePath() const
QString AlbumSettings::getImgDatabaseFilePath() const
{
return d->databaseParams.getDatabaseNameOrDir();
return d->databaseParams.getImgDatabaseNameOrDir();
}
void AlbumSettings::setDatabaseFilePath(const QString& path)
QString AlbumSettings::getTmbDatabaseFilePath() const
{
d->databaseParams.setDatabasePath(path);
d->databaseParams.setThumbsDatabasePath(path);
return d->databaseParams.getImgDatabaseNameOrDir();
}
void AlbumSettings::setImgDatabaseFilePath(const QString& path)
{
d->databaseParams.setImgDatabasePath(path);
d->databaseParams.setTmbDatabasePath(path);
}
void AlbumSettings::setTmbDatabaseFilePath(const QString& path)
{
d->databaseParams.setImgDatabasePath(path);
d->databaseParams.setTmbDatabasePath(path);
}
void AlbumSettings::setShowSplashScreen(bool val)
......@@ -1541,89 +1552,149 @@ void AlbumSettings::setDatabaseParameters(const DatabaseParameters& params)
d->databaseParams = params;
}
QString AlbumSettings::getDatabaseType() const
QString AlbumSettings::getImgDatabaseType() const
{
return d->databaseParams.databaseType;
return d->databaseParams.imgDatabaseType;
}
void AlbumSettings::setDatabaseType(const QString& databaseType)
void AlbumSettings::setImgDatabaseType(const QString& databaseType)
{
d->databaseParams.databaseType = databaseType;
d->databaseParams.imgDatabaseType = databaseType;
}
QString AlbumSettings::getDatabaseConnectoptions() const
QString AlbumSettings::getImgDatabaseConnectoptions() const
{
return d->databaseParams.connectOptions;
return d->databaseParams.imgConnectOptions;
}
QString AlbumSettings::getDatabaseName() const
QString AlbumSettings::getImgDatabaseName() const
{
return d->databaseParams.databaseName;
return d->databaseParams.imgDatabaseName;
}
QString AlbumSettings::getDatabaseNameThumbnails() const
QString AlbumSettings::getImgDatabaseHostName() const
{
return d->databaseParams.databaseNameThumbnails;
return d->databaseParams.imgHostName;
}
QString AlbumSettings::getDatabaseHostName() const
QString AlbumSettings::getImgDatabasePassword() const
{
return d->databaseParams.hostName;
return d->databaseParams.imgPassword;
}
QString AlbumSettings::getDatabasePassword() const
int AlbumSettings::getImgDatabasePort() const
{
return d->databaseParams.password;
return d->databaseParams.imgPort;
}
int AlbumSettings::getDatabasePort() const
QString AlbumSettings::getImgDatabaseUserName() const
{
return d->databaseParams.port;
return d->databaseParams.imgUserName;
}
QString AlbumSettings::getDatabaseUserName() const
void AlbumSettings::setImgDatabaseConnectoptions(const QString& connectoptions)
{
return d->databaseParams.userName;
d->databaseParams.imgConnectOptions = connectoptions;
}
bool AlbumSettings::getInternalDatabaseServer() const
void AlbumSettings::setImgDatabaseName(const QString& databaseName)
{
return d->databaseParams.internalServer;
d->databaseParams.imgDatabaseName = databaseName;
}
void AlbumSettings::setImgDatabaseHostName(const QString& hostName)
{
d->databaseParams.imgHostName = hostName;
}
void AlbumSettings::setImgDatabasePassword(const QString& password)
{
d->databaseParams.imgPassword = password;
}
void AlbumSettings::setImgDatabasePort(int port)
{
d->databaseParams.imgPort = port;
}
void AlbumSettings::setImgDatabaseUserName(const QString& userName)
{
d->databaseParams.imgUserName = userName;
}
QString AlbumSettings::getTmbDatabaseType() const
{
return d->databaseParams.tmbDatabaseType;
}
void AlbumSettings::setDatabaseConnectoptions(const QString& connectoptions)
void AlbumSettings::setTmbDatabaseType(const QString& databaseType)
{
d->databaseParams.connectOptions = connectoptions;
d->databaseParams.tmbDatabaseType = databaseType;
}
void AlbumSettings::setDatabaseName(const QString& databaseName)
QString AlbumSettings::getTmbDatabaseConnectoptions() const
{
d->databaseParams.databaseName = databaseName;
return d->databaseParams.tmbConnectOptions;
}
void AlbumSettings::setDatabaseNameThumbnails(const QString& databaseNameThumbnails)
QString AlbumSettings::getTmbDatabaseName() const
{
d->databaseParams.databaseNameThumbnails = databaseNameThumbnails;
return d->databaseParams.tmbDatabaseName;
}
void AlbumSettings::setDatabaseHostName(const QString& hostName)
QString AlbumSettings::getTmbDatabaseHostName() const
{
d->databaseParams.hostName = hostName;
return d->databaseParams.tmbHostName;
}
void AlbumSettings::setDatabasePassword(const QString& password)
QString AlbumSettings::getTmbDatabasePassword() const
{
d->databaseParams.password = password;
return d->databaseParams.tmbPassword;
}
void AlbumSettings::setDatabasePort(int port)
int AlbumSettings::getTmbDatabasePort() const
{
d->databaseParams.port = port;
return d->databaseParams.tmbPort;
}
void AlbumSettings::setDatabaseUserName(const QString& userName)
QString AlbumSettings::getTmbDatabaseUserName() const
{
d->databaseParams.userName = userName;
return d->databaseParams.tmbUserName;
}
void AlbumSettings::setTmbDatabaseConnectoptions(const QString& connectoptions)
{
d->databaseParams.tmbConnectOptions = connectoptions;
}
void AlbumSettings::setTmbDatabaseName(const QString& databaseName)
{
d->databaseParams.tmbDatabaseName = databaseName;
}
void AlbumSettings::setTmbDatabaseHostName(const QString& hostName)
{
d->databaseParams.tmbHostName = hostName;
}
void AlbumSettings::setTmbDatabasePassword(const QString& password)
{
d->databaseParams.tmbPassword = password;
}
void AlbumSettings::setTmbDatabasePort(int port)
{
d->databaseParams.tmbPort = port;
}
void AlbumSettings::setTmbDatabaseUserName(const QString& userName)
{
d->databaseParams.tmbUserName = userName;
}
bool AlbumSettings::getInternalDatabaseServer() const
{
return d->databaseParams.internalServer;
}
void AlbumSettings::setInternalDatabaseServer(const bool useInternalDBServer)
......
......@@ -103,8 +103,11 @@ public:
bool showToolTipsIsValid() const;
bool showAlbumToolTipsIsValid() const;
void setDatabaseFilePath(const QString& path);
QString getDatabaseFilePath() const;
void setImgDatabaseFilePath(const QString& path);
QString getImgDatabaseFilePath() const;
void setTmbDatabaseFilePath(const QString& path);
QString getTmbDatabaseFilePath() const;
void setShowSplashScreen(bool val);
bool getShowSplashScreen() const;
......@@ -327,29 +330,47 @@ public:
DatabaseParameters getDatabaseParameters() const;
void setDatabaseParameters(const DatabaseParameters& params);
QString getDatabaseType() const;
void setDatabaseType(const QString& databaseType);
QString getImgDatabaseType() const;
void setImgDatabaseType(const QString& databaseType);
QString getImgDatabaseConnectoptions() const;
void setImgDatabaseConnectoptions(const QString& connectoptions);
QString getImgDatabaseName() const;
void setImgDatabaseName(const QString& databaseName);
QString getImgDatabaseHostName() const;
void setImgDatabaseHostName(const QString& hostName);
QString getImgDatabasePassword() const;
void setImgDatabasePassword(const QString& password);
int getImgDatabasePort() const;
void setImgDatabasePort(int port);
QString getImgDatabaseUserName() const;
void setImgDatabaseUserName(const QString& userName);
QString getDatabaseConnectoptions() const;
void setDatabaseConnectoptions(const QString& connectoptions);
QString getTmbDatabaseType() const;
void setTmbDatabaseType(const QString& databaseType);
QString getDatabaseName() const;
void setDatabaseName(const QString& databaseName);
QString getTmbDatabaseConnectoptions() const;
void setTmbDatabaseConnectoptions(const QString& connectoptions);
QString getDatabaseNameThumbnails() const;
void setDatabaseNameThumbnails(const QString& databaseNameThumbnails);
QString getTmbDatabaseName() const;
void setTmbDatabaseName(const QString& databaseName);
QString getDatabaseHostName() const;
void setDatabaseHostName(const QString& hostName);
QString getTmbDatabaseHostName() const;
void setTmbDatabaseHostName(const QString& hostName);
QString getDatabasePassword() const;
void setDatabasePassword(const QString& password);
QString getTmbDatabasePassword() const;
void setTmbDatabasePassword(const QString& password);
int getDatabasePort() const;
void setDatabasePort(int port);
int getTmbDatabasePort() const;
void setTmbDatabasePort(int port);
QString getDatabaseUserName() const;
void setDatabaseUserName(const QString& userName);
QString getTmbDatabaseUserName() const;
void setTmbDatabaseUserName(const QString& userName);
bool getInternalDatabaseServer() const;
void setInternalDatabaseServer(const bool useInternalDBServer);
......
......@@ -80,7 +80,7 @@ static inline void showDigikamComponentsInfo()
// Database Backend information
QString dbBe = AlbumSettings::instance()->getDatabaseType();
QString dbBe = AlbumSettings::instance()->getImgDatabaseType();
list.insert(i18n("Database backend"), dbBe);
if (dbBe != QString("QSQLITE"))
......
......@@ -24,6 +24,9 @@
#ifndef CONFIG_DIGIKAM_H
#define CONFIG_DIGIKAM_H
#define DIGIKAM4DB "digikam4.db"
#define THUMBNAILS_DIGIKAMDB "thumbnails-digikam.db"
/* Define to 1 if you have KDEPIM shared library installed */
#cmakedefine HAVE_KDEPIMLIBS 1
......
......@@ -188,11 +188,11 @@ bool DatabaseCoreBackendPrivate::open(QSqlDatabase& db)
QThread* thread = QThread::currentThread();
db = QSqlDatabase::addDatabase(parameters.databaseType, connectionName(thread));
db = QSqlDatabase::addDatabase(parameters.imgDatabaseType, connectionName(thread));
QString connectOptions = parameters.connectOptions;
QString connectOptions = parameters.imgConnectOptions;
if (parameters.isSQLite())
if (parameters.isImgSQLite())
{
QStringList toAdd;
// enable shared cache, especially useful with SQLite >= 3.5.0
......@@ -208,12 +208,12 @@ bool DatabaseCoreBackendPrivate::open(QSqlDatabase& db)
connectOptions += toAdd.join(";");
}
db.setDatabaseName(parameters.databaseName);
db.setDatabaseName(parameters.imgDatabaseName);
db.setConnectOptions(connectOptions);
db.setHostName(parameters.hostName);
db.setPort(parameters.port);
db.setUserName(parameters.userName);