Commit d685e4a7 authored by Martin Straka's avatar Martin Straka
Browse files

Added QML support for database location changing

parent 234e9b0e
......@@ -344,6 +344,29 @@ Component {
}
wrapMode: Text.Wrap
}
Label {
id: dbPathLabel
color: datovkaPalette.text
width: myWidht
text: qsTr("Databases location")
}
Text {
id: dbPathText
color: datovkaPalette.mid
width: myWidht
wrapMode: Text.Wrap
text: ""
}
Button {
id: dbPathButton
text: qsTr("Change")
onClicked: {
var newPath = settings.changeDbPath(dbPathText.text.toString(), false)
if (newPath != "") {
dbPathText.text = newPath;
}
}
}
}
Connections {
target: settings
......@@ -354,6 +377,7 @@ Component {
attachLifeSpinBox.setVal(fileLifeDays)
languageComboBoxId.currentIndex = langIndex
fontSizeSpinBox.setVal(fontSize)
dbPathText.text = dbPath
}
}
Connections {
......@@ -365,7 +389,8 @@ Component {
idownloadOnlyNewMsgs.checked,
idownloadCompleteMsgs.checked,
messageLifeSpinBox.val().toString(),
attachLifeSpinBox.val().toString())
attachLifeSpinBox.val().toString(),
dbPathText.text.toString())
pageView.pop(StackView.Immediate)
}
}
......
......@@ -127,8 +127,12 @@ void Settings::loadFromSettings(const QSettings &settings)
globSet.lastUpdate = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString();
//globSet.dbsLocation = settings.value(
// SETTINGS_GLOBAL_GROUP "/" SETTINGS_DBS_LOCATION).toString();
globSet.dbsLocation = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_DBS_LOCATION).toString();
if (globSet.dbsLocation.isEmpty()) {
globSet.dbsLocation =
existingWritableLocation(QStandardPaths::AppDataLocation);
}
}
......
......@@ -22,12 +22,16 @@
*/
#include <QtDebug> // qCritical
#include <QFileDialog>
#include <QStandardPaths>
#include "src/crypto/pin.h"
#include "src/crypto/wrapped.h"
#include "src/models/accountmodel.h" /* globAccountsModelPtr */
#include "src/settings.h"
#include "src/io/filesystem.h"
#include "src/setwrapper.h"
#include "src/settings.h"
GlobalSettingsQmlWrapper::GlobalSettingsQmlWrapper(QObject *parent)
: QObject(parent)
......@@ -75,7 +79,8 @@ void GlobalSettingsQmlWrapper::loadSettings(void)
/* Send data to QML */
emit sendSettingsData(langugeComboBoxIndex, globSet.fontSize,
globSet.downloadOnlyNewMsgs, globSet.downloadCompleteMsgs,
globSet.msgLifeTimeInDays, globSet.fileLifeTimeInDays);
globSet.msgLifeTimeInDays, globSet.fileLifeTimeInDays,
globSet.dbsLocation);
}
......@@ -97,7 +102,7 @@ void GlobalSettingsQmlWrapper::loadPinSettings(void)
*/
void GlobalSettingsQmlWrapper::updateSettings(const QString &language,
const QString &fontSize, bool downloadOnlyNewMsgs, bool downloadCompleteMsgs,
const QString &msgLifeDays, const QString &fileLifeDays)
const QString &msgLifeDays, const QString &fileLifeDays, const QString &dbPath)
/* ========================================================================= */
{
globSet.language = language;
......@@ -106,6 +111,7 @@ void GlobalSettingsQmlWrapper::updateSettings(const QString &language,
globSet.downloadCompleteMsgs = downloadCompleteMsgs;
globSet.msgLifeTimeInDays = msgLifeDays.toInt();
globSet.fileLifeTimeInDays = fileLifeDays.toInt();
globSet.dbsLocation = dbPath;
saveAllSettings();
}
......@@ -199,3 +205,25 @@ void GlobalSettingsQmlWrapper::saveSettingsRequest(void)
{
emit saveSettingsResponse();
}
/* ========================================================================= */
/*
* Slot: Returns new database location string to QML.
*/
QString GlobalSettingsQmlWrapper::changeDbPath(const QString &currentLocation,
bool setDefaultLocation)
/* ========================================================================= */
{
QString newLocation;
if (setDefaultLocation) {
newLocation =
existingWritableLocation(QStandardPaths::AppDataLocation);
} else {
newLocation = QFileDialog::getExistingDirectory(0,
tr("Select directory"), currentLocation,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
}
return newLocation;
}
......@@ -68,7 +68,7 @@ public:
Q_INVOKABLE void updateSettings(const QString &language,
const QString &fontSize, bool downloadOnlyNewMsgs,
bool downloadCompleteMsgs, const QString &msgLifeDays,
const QString &fileLifeDays);
const QString &fileLifeDays, const QString &dbPath);
/*!
* @brief Save PIN settings from QML.
......@@ -93,6 +93,13 @@ public:
Q_INVOKABLE
void saveSettingsRequest(void);
/*!
* @brief Returns new database location string to QML.
*/
Q_INVOKABLE
QString changeDbPath(const QString &currentLocation,
bool setDefaultLocation);
signals:
/*!
......@@ -105,7 +112,7 @@ signals:
*/
void sendSettingsData(int langIndex, int fontSize,
bool downloadOnlyNewMsgs, bool downloadCompleteMsgs,
int msgLifeDays, int fileLifeDays);
int msgLifeDays, int fileLifeDays, QString dbPath);
/*!
* @brief Send current PIN settings to QML.
......@@ -136,6 +143,7 @@ signals:
* TODO - Must be replaced via better solution in the future.
*/
void saveSettingsResponse(void);
};
#endif // SETWRAPPER_H
......@@ -50,20 +50,13 @@ bool FileDb::openDb(const QString &locDir, const QString &fileName,
bool storeToDisk)
/* ========================================================================= */
{
QString dirName =
existingWritableLocation(QStandardPaths::AppDataLocation);
if (!locDir.isEmpty()) {
dirName = locDir;
}
if (storeToDisk && dirName.isEmpty()) {
if (storeToDisk && locDir.isEmpty()) {
Q_ASSERT(0);
return false;
}
bool ret = SQLiteDb::openDb(
dirName + QDir::separator() + QDir::toNativeSeparators(fileName),
locDir + QDir::separator() + QDir::toNativeSeparators(fileName),
!storeToDisk, listOfTables());
return ret;
......
......@@ -145,21 +145,13 @@ bool MessageDb::openDb(const QString &locDir, const QString &fileName,
bool storeToDisk)
/* ========================================================================= */
{
QString dirName =
existingWritableLocation(QStandardPaths::AppDataLocation);
if (!locDir.isEmpty()) {
dirName = locDir;
}
if (storeToDisk && dirName.isEmpty()) {
if (storeToDisk && locDir.isEmpty()) {
Q_ASSERT(0);
return false;
}
bool ret = SQLiteDb::openDb(
dirName + QDir::separator() + QDir::toNativeSeparators(fileName),
locDir + QDir::separator() + QDir::toNativeSeparators(fileName),
!storeToDisk, listOfTables());
qDebug() << m_db.databaseName();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment