uonedb-qt team mailing list archive
-
uonedb-qt team
-
Mailing list archive
-
Message #00209
[Merge] lp:~kalikiana/u1db-qt/relativePath into lp:u1db-qt
Christian Dywan has proposed merging lp:~kalikiana/u1db-qt/relativePath into lp:u1db-qt.
Commit message:
Use QStandardPaths to find a good path for relative filenames
Requested reviews:
U1DB Qt developers (uonedb-qt)
Related bugs:
Bug #1206935 in U1DB Qt/ QML: "Default relative database filename to a sensible location"
https://bugs.launchpad.net/u1db-qt/+bug/1206935
For more details, see:
https://code.launchpad.net/~kalikiana/u1db-qt/relativePath/+merge/180113
--
https://code.launchpad.net/~kalikiana/u1db-qt/relativePath/+merge/180113
Your team U1DB Qt developers is requested to review the proposed merge of lp:~kalikiana/u1db-qt/relativePath into lp:u1db-qt.
=== modified file 'src/database.cpp'
--- src/database.cpp 2013-08-12 08:58:02 +0000
+++ src/database.cpp 2013-08-14 12:08:12 +0000
@@ -20,6 +20,9 @@
#include <QDebug>
#include <QSqlQuery>
#include <QFile>
+#include <QFileInfo>
+#include <QStandardPaths>
+#include <QDir>
#include <QSqlError>
#include <QUuid>
#include <QStringList>
@@ -110,7 +113,18 @@
if (!m_db.isValid())
return setError("QSqlDatabase error");
+
+ if (path != ":memory:" && QDir::isRelativePath(path)) {
+ QString dataPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
+ QString absolutePath(QDir(dataPath).absoluteFilePath(path));
+ QString parent(QFileInfo(absolutePath).dir().path());
+ if (!QDir().mkpath(parent))
+ qWarning() << "Failed to make data folder" << parent;
+ m_db.setDatabaseName(absolutePath);
+ }
+ else
m_db.setDatabaseName(path);
+
if (!m_db.open())
return setError(QString("Failed to open %1: %2").arg(path).arg(m_db.lastError().text()));
if (!isInitialized())
@@ -686,8 +700,10 @@
/*!
\property Database::path
- A relative filename or absolute path to store documents
- and indexes persistently on disk. By default documents are stored in memory.
+ A relative filename can be given to store the database in an app-specific
+ writable folder. This is recommended as it ensures to work with confinement.
+ If more control is needed absolute paths can be used.
+ By default everything is stored in memory.
*/
void
Database::setPath(const QString& path)
@@ -697,7 +713,6 @@
beginResetModel();
m_db.close();
- // TODO: relative path
initializeIfNeeded(path);
endResetModel();
Follow ups