Răsfoiți Sursa

Added convinience method getPath in AStandardPaths

George 4 ani în urmă
părinte
comite
d6141e93d3

+ 4 - 4
main.cpp

@@ -51,10 +51,10 @@ int main(int argc, char *argv[])
 
     aDB()->connect();
 
-//    if (!ASettings::read("setup/setup_complete").toBool()) {
-//        FirstRunDialog dialog;
-//        dialog.exec();
-//    }
+    if (!ASettings::read("setup/setup_complete").toBool()) {
+        FirstRunDialog dialog;
+        dialog.exec();
+    }
 
     //Theming
     int selectedtheme = ASettings::settings().value("main/theme").toInt();

+ 10 - 3
src/astandardpaths.cpp

@@ -4,12 +4,19 @@ QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::paths;
 
 void AStandardPaths::setup()
 {
-     paths = {
-        {QStandardPaths::AppConfigLocation, QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)},
-        {QStandardPaths::AppDataLocation, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)},
+    auto settings_location = QStandardPaths::AppConfigLocation;
+    auto data_location = QStandardPaths::AppDataLocation;
+    paths = {
+        {settings_location, QStandardPaths::writableLocation(settings_location)},
+        {data_location, QStandardPaths::writableLocation(data_location)},
     };
 }
 
+QString AStandardPaths::getPath(QStandardPaths::StandardLocation loc)
+{
+    return paths[loc];
+}
+
 QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::getPaths()
 {
     return paths;

+ 1 - 0
src/astandardpaths.h

@@ -20,6 +20,7 @@ public:
     /// Initialise paths with corresponding StandardLocation paths
     static void setup();
 
+    static QString getPath(QStandardPaths::StandardLocation loc);
     static QMap<QStandardPaths::StandardLocation, QString> getPaths();
 
     /// Ensure standard app paths exist, if not mkdir them.

+ 3 - 1
src/classes/asettings.cpp

@@ -22,7 +22,9 @@
 void ASettings::setup()
 {
     QSettings::setDefaultFormat(QSettings::IniFormat);
-    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, AStandardPaths::getPaths()[QStandardPaths::AppDataLocation]);
+    QSettings::setPath(QSettings::IniFormat,
+                       QSettings::UserScope,
+                       AStandardPaths::getPaths()[QStandardPaths::AppConfigLocation]);
 }
 
 QVariant ASettings::read(const QString &key)

+ 4 - 1
src/database/adatabase.cpp

@@ -17,6 +17,7 @@
  */
 #include "adatabase.h"
 #include "src/testing/adebug.h"
+#include "src/astandardpaths.h"
 
 #define DATABASE_VERSION 15
 const auto SQL_DRIVER = QStringLiteral("QSQLITE");
@@ -67,7 +68,9 @@ bool ADatabase::connect()
     if (!QSqlDatabase::isDriverAvailable(SQL_DRIVER))
         return false;
 
-    QDir directory(QStringLiteral("data"));
+    QString path = AStandardPaths::getPath(QStandardPaths::AppDataLocation);
+    QDir directory(path);
+    // [G]: Where would it make sense to define the database file?. In the class perhaps?
     QString databaseLocation = directory.filePath(QStringLiteral("logbook.db"));
     QSqlDatabase db = QSqlDatabase::addDatabase(SQL_DRIVER);
     db.setDatabaseName(databaseLocation);

+ 2 - 1
src/database/adatabase.h

@@ -85,11 +85,12 @@ public:
     ADatabase(const ADatabase&) = delete;
     void operator=(const ADatabase&) = delete;
     static ADatabase* getInstance();
-    ADatabaseError lastError;
     TableNames getTableNames() const;
     TableColumns getTableColumns() const;
     const QString sqliteVersion();
 
+    ADatabaseError lastError;
+
     /*!
      * \brief Connect to the database and populate database information.
      */