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
=== 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 @@
20#include <QDebug>20#include <QDebug>
21#include <QSqlQuery>21#include <QSqlQuery>
22#include <QFile>22#include <QFile>
23#include <QFileInfo>
24#include <QStandardPaths>
25#include <QDir>
23#include <QSqlError>26#include <QSqlError>
24#include <QUuid>27#include <QUuid>
25#include <QStringList>28#include <QStringList>
@@ -110,7 +113,18 @@
110113
111 if (!m_db.isValid())114 if (!m_db.isValid())
112 return setError("QSqlDatabase error");115 return setError("QSqlDatabase error");
116
117 if (path != ":memory:" && QDir::isRelativePath(path)) {
118 QString dataPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
119 QString absolutePath(QDir(dataPath).absoluteFilePath(path));
120 QString parent(QFileInfo(absolutePath).dir().path());
121 if (!QDir().mkpath(parent))
122 qWarning() << "Failed to make data folder" << parent;
123 m_db.setDatabaseName(absolutePath);
124 }
125 else
113 m_db.setDatabaseName(path);126 m_db.setDatabaseName(path);
127
114 if (!m_db.open())128 if (!m_db.open())
115 return setError(QString("Failed to open %1: %2").arg(path).arg(m_db.lastError().text()));129 return setError(QString("Failed to open %1: %2").arg(path).arg(m_db.lastError().text()));
116 if (!isInitialized())130 if (!isInitialized())
@@ -686,8 +700,10 @@
686700
687/*!701/*!
688 \property Database::path702 \property Database::path
689 A relative filename or absolute path to store documents703 A relative filename can be given to store the database in an app-specific
690 and indexes persistently on disk. By default documents are stored in memory.704 writable folder. This is recommended as it ensures to work with confinement.
705 If more control is needed absolute paths can be used.
706 By default everything is stored in memory.
691 */707 */
692void708void
693Database::setPath(const QString& path)709Database::setPath(const QString& path)
@@ -697,7 +713,6 @@
697713
698 beginResetModel();714 beginResetModel();
699 m_db.close();715 m_db.close();
700 // TODO: relative path
701 initializeIfNeeded(path);716 initializeIfNeeded(path);
702 endResetModel();717 endResetModel();
703718

Subscribers

People subscribed via source and target branches

to all changes: