Merge lp:~kalikiana/u1db-qt/relativePath into lp:u1db-qt

Proposed by Christian Dywan
Status: Merged
Approved by: Christian Dywan
Approved revision: 101
Merged at revision: 102
Proposed branch: lp:~kalikiana/u1db-qt/relativePath
Merge into: lp:u1db-qt
Diff against target: 52 lines (+18/-3)
1 file modified
src/database.cpp (+18/-3)
To merge this branch: bzr merge lp:~kalikiana/u1db-qt/relativePath
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
U1DB Qt developers Pending
Review via email: mp+180113@code.launchpad.net

Commit message

Use QStandardPaths to find a good path for relative filenames

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/database.cpp'
2--- src/database.cpp 2013-08-12 08:58:02 +0000
3+++ src/database.cpp 2013-08-14 12:08:12 +0000
4@@ -20,6 +20,9 @@
5 #include <QDebug>
6 #include <QSqlQuery>
7 #include <QFile>
8+#include <QFileInfo>
9+#include <QStandardPaths>
10+#include <QDir>
11 #include <QSqlError>
12 #include <QUuid>
13 #include <QStringList>
14@@ -110,7 +113,18 @@
15
16 if (!m_db.isValid())
17 return setError("QSqlDatabase error");
18+
19+ if (path != ":memory:" && QDir::isRelativePath(path)) {
20+ QString dataPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
21+ QString absolutePath(QDir(dataPath).absoluteFilePath(path));
22+ QString parent(QFileInfo(absolutePath).dir().path());
23+ if (!QDir().mkpath(parent))
24+ qWarning() << "Failed to make data folder" << parent;
25+ m_db.setDatabaseName(absolutePath);
26+ }
27+ else
28 m_db.setDatabaseName(path);
29+
30 if (!m_db.open())
31 return setError(QString("Failed to open %1: %2").arg(path).arg(m_db.lastError().text()));
32 if (!isInitialized())
33@@ -686,8 +700,10 @@
34
35 /*!
36 \property Database::path
37- A relative filename or absolute path to store documents
38- and indexes persistently on disk. By default documents are stored in memory.
39+ A relative filename can be given to store the database in an app-specific
40+ writable folder. This is recommended as it ensures to work with confinement.
41+ If more control is needed absolute paths can be used.
42+ By default everything is stored in memory.
43 */
44 void
45 Database::setPath(const QString& path)
46@@ -697,7 +713,6 @@
47
48 beginResetModel();
49 m_db.close();
50- // TODO: relative path
51 initializeIfNeeded(path);
52 endResetModel();
53

Subscribers

People subscribed via source and target branches

to all changes: