Browse Source

Refactored AStandardPaths, FirstRun, encapsulated standard paths better.

George 4 years ago
parent
commit
5df071e48a

+ 4 - 4
main.cpp

@@ -51,10 +51,10 @@ int main(int argc, char *argv[])
 
     FirstRunDialog().exec();
     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
     switch (ASettings::read("main/theme").toInt()) {

+ 8 - 5
src/astandardpaths.cpp

@@ -1,23 +1,26 @@
 #include "src/astandardpaths.h"
 
-QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::paths;
+//QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::paths;
+QMap<AStandardPaths::Dirs, QString> AStandardPaths::paths;
 
 void AStandardPaths::setup()
 {
     auto settings_location = QStandardPaths::AppConfigLocation;
     auto data_location = QStandardPaths::AppDataLocation;
     paths = {
-        {settings_location, QStandardPaths::writableLocation(settings_location)},
-        {data_location, QStandardPaths::writableLocation(data_location)},
+        {Database, QStandardPaths::writableLocation(data_location)},
+        {Templates, QDir(QStandardPaths::writableLocation(data_location)).filePath("templates")},
+        {Settings, QStandardPaths::writableLocation(settings_location)},
     };
+    DEB << "Paths created: " << paths;
 }
 
-QString AStandardPaths::getPath(QStandardPaths::StandardLocation loc)
+QString AStandardPaths::getPath(Dirs loc)
 {
     return paths[loc];
 }
 
-QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::getPaths()
+QMap<AStandardPaths::Dirs, QString> AStandardPaths::getPaths()
 {
     return paths;
 }

+ 9 - 3
src/astandardpaths.h

@@ -13,15 +13,21 @@
  * `QCoreApplication::setWhateverName`.
  */
 class AStandardPaths{
+public:
+    enum Dirs {
+        Database,
+        Templates,
+        Settings,
+    };
 private:
     static
-    QMap<QStandardPaths::StandardLocation, QString> paths;
+    QMap<Dirs, QString> paths;
 public:
     /// Initialise paths with corresponding StandardLocation paths
     static void setup();
 
-    static QString getPath(QStandardPaths::StandardLocation loc);
-    static QMap<QStandardPaths::StandardLocation, QString> getPaths();
+    static QString getPath(Dirs loc);
+    static QMap<Dirs, QString> getPaths();
 
     /// Ensure standard app paths exist, if not mkdir them.
     static void scan_paths();

+ 1 - 1
src/database/adatabase.cpp

@@ -51,7 +51,7 @@ ADatabase* ADatabase::getInstance()
 }
 
 ADatabase::ADatabase()
-    : databaseDir(QDir(AStandardPaths::getPath(QStandardPaths::AppDataLocation))),
+    : databaseDir(QDir(AStandardPaths::getPath(AStandardPaths::Database))),
       databasePath(databaseDir.filePath(QStringLiteral("logbook.db")))
 {}
 

+ 2 - 5
src/database/adatabasesetup.cpp

@@ -283,11 +283,8 @@ bool ADataBaseSetup::downloadTemplates()
 {
     QStringList templateTables = {"aircraft", "airports", "changelog"};
     QString linkStub = TEMPLATE_URL;
-    // [G]: could be moved to AStandard paths. Feels clunky here.
-    // Might aswell be created upfront and have a more strict access.
-    aDB()->databaseDir.mkdir("templates");
-    // ---
-    QDir template_dir(aDB()->databaseDir.filePath("templates"));
+    QDir template_dir(AStandardPaths::getPath(AStandardPaths::Templates));
+    DEB << template_dir;
     for (const auto& table : templateTables) {
         QEventLoop loop;
         ADownload* dl = new ADownload;

+ 2 - 0
src/gui/dialogues/firstrundialog.cpp

@@ -133,6 +133,8 @@ void FirstRunDialog::finish()
     aDB()->connect();
     auto pilot = APilotEntry(1);
     pilot.setData(data);
+    // [G]: Extremely suspect behaviour. Too much control for something that runs once.
+    // Main should handle the qApp since we dont have a dedicated "application" class
     if (aDB()->commit(pilot)) {
         qApp->quit();
         QProcess::startDetached(qApp->arguments()[0], qApp->arguments());

+ 1 - 1
src/gui/widgets/debugwidget.cpp

@@ -169,7 +169,7 @@ void DebugWidget::on_importCsvPushButton_clicked()
 
 void DebugWidget::on_debugPushButton_clicked()
 {
-    DEB << AStandardPaths::getPaths()[QStandardPaths::AppDataLocation];
+    DEB << AStandardPaths::getPaths()[AStandardPaths::Database	];
 }
 
 /* //Comparing two functions template