From 9ca0b519a13cf98528b66fe737c86139872c1649 Mon Sep 17 00:00:00 2001 From: Nedim Hadzic Date: Thu, 3 Dec 2015 14:10:43 +0100 Subject: [Datasource plugin] Implemented option for setting a custom storage location It was not possible to set the custom media location other than $HOME location. With this patch, one can set the storage location if media is in the different location than the $HOME location. Change-Id: I6383a81343e652b635c1872828d0883f06347ef3 Reviewed-by: Robert Griebl --- plugins/datasource/sqlquerydatasource.cpp | 10 ++++++++-- plugins/datasource/sqlquerydatasource.h | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/datasource/sqlquerydatasource.cpp b/plugins/datasource/sqlquerydatasource.cpp index fae43c4..48eb025 100644 --- a/plugins/datasource/sqlquerydatasource.cpp +++ b/plugins/datasource/sqlquerydatasource.cpp @@ -33,6 +33,7 @@ SqlQueryDataSource::SqlQueryDataSource(QObject *parent) : QObject(parent) + , m_storageLocation(QDir::homePath()) , m_model(new SqlQueryModel(this)) , m_status(SqlQueryDataSource::Null) { @@ -103,7 +104,7 @@ void SqlQueryDataSource::updateModel() m_database = QSqlDatabase::database(m_databaseName); } else { m_database = QSqlDatabase::addDatabase("QSQLITE", m_databaseName); - QString databasePath = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(m_databaseName + ".db"); + QString databasePath = QDir(m_storageLocation).filePath(m_databaseName + ".db"); m_database.setDatabaseName(databasePath); qDebug() << "database path: " << databasePath; } @@ -143,6 +144,11 @@ void SqlQueryDataSource::setStatus(SqlQueryDataSource::Status arg) QString SqlQueryDataSource::storageLocation() const { - return QDir::homePath(); + return m_storageLocation; +} + +void SqlQueryDataSource::setStorageLocation(QString path) +{ + m_storageLocation = QDir(path).absolutePath(); } diff --git a/plugins/datasource/sqlquerydatasource.h b/plugins/datasource/sqlquerydatasource.h index 4d3bb01..bdec973 100644 --- a/plugins/datasource/sqlquerydatasource.h +++ b/plugins/datasource/sqlquerydatasource.h @@ -44,7 +44,7 @@ class SqlQueryDataSource : public QObject Q_PROPERTY(QObject* model READ model NOTIFY modelChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QString storageLocation READ storageLocation CONSTANT) + Q_PROPERTY(QString storageLocation READ storageLocation WRITE setStorageLocation NOTIFY storageLocationChanged) Q_ENUMS(Status) public: @@ -65,6 +65,7 @@ public: Status status() const; QString storageLocation() const; + void setStorageLocation(QString path); private: void updateModel(); void setStatus(Status arg); @@ -78,10 +79,12 @@ signals: void statusChanged(Status arg); void modelChanged(QObject* model); + void storageLocationChanged(); private: QString m_queryString; QString m_databaseName; + QString m_storageLocation; SqlQueryModel *m_model; QSqlQuery m_query; QSqlDatabase m_database; -- cgit v1.2.3