Browse Source

Merge pull request #102 from fiffty-50/develop-v0-1-fixes

Develop v0 1 fixes
Felix Turowsky 1 year ago
parent
commit
c7097d2a92

BIN
assets/database/logbook.db


+ 8 - 9
mainwindow.cpp

@@ -204,7 +204,7 @@ void MainWindow::onDatabaseInvalid()
     db_error.setIcon(QMessageBox::Warning);
     db_error.setWindowTitle(tr("No valid database found"));
     db_error.setText(tr("No valid database has been found.<br>"
-                       "Would you like to create a new database or import a backup?"));
+                        "Would you like to create a new database or import a backup?<br><br>"));
 
     int ret = db_error.exec();
     if (ret == QMessageBox::DestructiveRole) {
@@ -212,16 +212,15 @@ void MainWindow::onDatabaseInvalid()
         on_actionQuit_triggered();
     } else if (ret == QMessageBox::ButtonRole::AcceptRole) {
         DEB << "Yes(Import Backup)";
-        QString db_path = QFileDialog::getOpenFileName(this,
-                                                       tr("Select Database"),
-                                                       OPL::Paths::directory(OPL::Paths::Backup).canonicalPath(),
-                                                       tr("Database file (*.db)"));
+        QString db_path = QDir::toNativeSeparators(
+                          (QFileDialog::getOpenFileName(this,
+                                                        tr("Select Database"),
+                                                        OPL::Paths::directory(OPL::Paths::Backup).canonicalPath(),
+                                                        tr("Database file (*.db)"))));
         if (!db_path.isEmpty()) {
             if(!DB->restoreBackup(db_path)) {
-               WARN(tr("Unable to restore Backup file: %1").arg(db_path));
-               on_actionQuit_triggered();
-            } else {
-                INFO(tr("Backup successfully restored."));
+                WARN(tr("Unable to restore backup file:<br><br>%1").arg(db_path));
+                on_actionQuit_triggered();
             }
         }
     } else if (ret == QMessageBox::ButtonRole::RejectRole){

+ 16 - 20
src/database/database.cpp

@@ -583,10 +583,9 @@ bool Database::createBackup(const QString& dest_file)
 {
     LOG << "Backing up current database to: " << dest_file;
     Database::disconnect();
-    QFile db_file(databaseFile.absoluteFilePath());
-    //DEB << "File to Overwrite:" << db_file;
+    QFile db_file(QDir::toNativeSeparators(databaseFile.absoluteFilePath()));
 
-    if (!db_file.copy(dest_file)) {
+    if (!db_file.copy(QDir::toNativeSeparators(dest_file))) {
         LOG << "Unable to backup old database:" << db_file.errorString();
         return false;
     }
@@ -599,29 +598,26 @@ bool Database::createBackup(const QString& dest_file)
 
 bool Database::restoreBackup(const QString& backup_file)
 {
+    Database::disconnect();
     LOG << "Restoring backup from file:" << backup_file;
 
-    QString default_loc = databaseFile.absoluteFilePath();
-
-    Database::disconnect();
-    QFile backup(backup_file);
-    QFile current_db(default_loc);
+    QString databaseFilePath = QDir::toNativeSeparators(databaseFile.absoluteFilePath());
+    DEB << "DB File Path: " << databaseFilePath;
+    QString backupFilePath = QDir::toNativeSeparators(backup_file);
 
-    if (!current_db.rename(default_loc + QLatin1String(".tmp"))) { // move previously used db out of the way
-        LOG << current_db.errorString() << "Unable to remove current db file";
-        return false;
-    }
+    QFile dbFile(databaseFilePath);
+    if(dbFile.exists())
+        if(!dbFile.remove()) {
+            LOG << dbFile.errorString() << "Unable to remove current db file";
+            return false;
+        }
 
-    if (!backup.copy(default_loc))
-    {
-        LOG << backup.errorString() << "Could not copy" << backup.fileName() << "to" << databaseFile.absoluteFilePath();
-        // try to restore previously used db
-        current_db.rename(default_loc);
+    QFile backupFile(backupFilePath);
+    if(!backupFile.copy(databaseFilePath)) {
+        LOG << backupFile.errorString() << "Could not copy" << backupFile.fileName() << " to " << databaseFilePath;
         return false;
     }
 
-    // backup has been restored, clean up the previously moved file
-    current_db.remove();
     LOG << "Backup successfully restored!";
     Database::connect();
     emit connectionReset();
@@ -638,7 +634,7 @@ bool Database::createSchema()
     auto list = filedata.split(';');
 
     // make sure last empty line in sql file has not been parsed
-    if(list.last() == QByteArray("\n"))
+    if(list.last() == QByteArray("\n") || list.last() == QByteArray("\r\n"))
         list.removeLast();
 
     // Create Tables

+ 2 - 2
src/gui/dialogues/exporttocsvdialog.cpp

@@ -23,10 +23,10 @@ void ExportToCsvDialog::on_exportPushButton_clicked()
 {
     selectRows();
     // File Dialog where to save
-    QString filePath = QFileDialog::getSaveFileName(this,
+    QString filePath = QDir::toNativeSeparators(QFileDialog::getSaveFileName(this,
                                                     tr("Select Location"),
                                                     QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
-                                                    QStringLiteral("*.csv"));
+                                                                             QStringLiteral("*.csv")));
     if(filePath.isEmpty()) return; // user has cancelled file dialog
 
     if(!filePath.endsWith(QStringLiteral(".csv")))

+ 3 - 4
src/gui/dialogues/firstrundialog.cpp

@@ -430,12 +430,11 @@ void FirstRunDialog::on_currCustom2LineEdit_editingFinished()
 
 void FirstRunDialog::on_importPushButton_clicked()
 {
-    QString filename = QFileDialog::getOpenFileName(
+    QString filename = QDir::toNativeSeparators(QFileDialog::getOpenFileName(
                 this,
                 tr("Choose backup file"),
                 QDir::homePath(),
-                "*.db"
-    );
+                "*.db"));
 
     if(filename.isEmpty()) { // QFileDialog has been cancelled
         WARN(tr("No Database has been selected."));
@@ -452,7 +451,7 @@ void FirstRunDialog::on_importPushButton_clicked()
                        "<br>Is this correct?"
                        ).arg(OPL::DbSummary::summaryString(filename)));
     if (confirm.exec() == QMessageBox::Yes) {
-        if(!DB->restoreBackup(filename)) {
+        if(!DB->restoreBackup(QDir::toNativeSeparators(filename))) {
             WARN(tr("Unable to import database file:").arg(filename));
             return;
         }

+ 4 - 4
src/gui/widgets/backupwidget.cpp

@@ -103,7 +103,7 @@ void BackupWidget::on_createLocalPushButton_clicked()
     QString filename = absoluteBackupPath();
     DEB << filename;
 
-    if(!DB->createBackup(filename)) {
+    if(!DB->createBackup(QDir::toNativeSeparators(filename))) {
         WARN(tr("Could not create local file: %1").arg(filename));
         return;
     } else {
@@ -144,7 +144,7 @@ void BackupWidget::on_restoreLocalPushButton_clicked()
     if (confirm.exec() == QMessageBox::No)
         return;
 
-    if(!DB->restoreBackup(backup_name)) {
+    if(!DB->restoreBackup(QDir::toNativeSeparators(backup_name))) {
        WARN(tr("Unable to restore Backup file: %1").arg(backup_name));
     } else {
         INFO(tr("Backup successfully restored."));
@@ -212,7 +212,7 @@ void BackupWidget::on_createExternalPushButton_clicked()
         filename.append(".db");
     }
 
-    if(!DB->createBackup(filename)) {
+    if(!DB->createBackup(QDir::toNativeSeparators(filename))) {
         WARN(tr("Unable to backup file:").arg(filename));
         return;
     } else {
@@ -245,7 +245,7 @@ void BackupWidget::on_restoreExternalPushButton_clicked()
                        "<br>Continue?"
                        ).arg(OPL::DbSummary::summaryString(filename)));
     if (confirm.exec() == QMessageBox::Yes) {
-        if(!DB->restoreBackup(filename)) {
+        if(!DB->restoreBackup(QDir::toNativeSeparators(filename))) {
             WARN(tr("Unable to import database file:").arg(filename));
             return;
         }

+ 0 - 51
src/opl.h

@@ -157,56 +157,6 @@ public:
 
 private:
     Q_OBJECT
-
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
-    const static inline QHash<Translation, QString> L10N_FilePaths {
-        {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
-        {Translation::German,  QStringLiteral("l10n/openpilotlog_de")},
-        {Translation::Spanish, QStringLiteral("l10n/openpilotlog_es")},
-    };
-    const static inline QHash<Translation, QString> L10N_DisplayNames {
-        {Translation::English, QStringLiteral("English")},
-        {Translation::German,  QStringLiteral("Deutsch")},
-        {Translation::Spanish, QStringLiteral("Español")},
-    };
-    const static inline QHash<DbViewName, QString> DATABASE_VIEWS = {
-        {DbViewName::Default,        QStringLiteral("viewDefault")},
-        {DbViewName::DefaultWithSim, QStringLiteral("viewDefaultSim")},
-        {DbViewName::Easa,           QStringLiteral("viewEasa")},
-        {DbViewName::EasaWithSim,    QStringLiteral("viewEasaSim")},
-        {DbViewName::SimulatorOnly,  QStringLiteral("viewSimulators")},
-    };
-    const QHash<DbViewName, QString> DATABASE_VIEW_DISPLAY_NAMES = {
-        {DbViewName::Default,        tr("Default")},
-        {DbViewName::DefaultWithSim, tr("Default with Simulator")},
-        {DbViewName::Easa,           tr("EASA-FCL")},
-        {DbViewName::EasaWithSim,    tr("EASA-FCL with Simulator")},
-        {DbViewName::SimulatorOnly,  tr("Simulator Sessions Only")},
-    };
-    const static inline QHash<PilotFunction, QString> PILOT_FUNCTIONS = {
-        {PilotFunction::PIC,   QStringLiteral("PIC")},
-        {PilotFunction::PICUS, QStringLiteral("PICUS")},
-        {PilotFunction::SIC,   QStringLiteral("SIC")},
-        {PilotFunction::DUAL,  QStringLiteral("DUAL")},
-        {PilotFunction::FI,    QStringLiteral("FI")},
-    };
-    const static inline QHash<SimulatorType, QString> SIMULATOR_TYPES = {
-        {SimulatorType::FNPTI,  QStringLiteral("FNPT I")},
-        {SimulatorType::FNPTII, QStringLiteral("FNPT II")},
-        {SimulatorType::FSTD,   QStringLiteral("FSTD")},
-    };
-    const static inline QHash<DbTable, QString> DB_TABLES = {
-        //Flights, Simulators, Pilots, Tails, Aircraft, Airports
-        {DbTable::Flights,      QStringLiteral("flights")},
-        {DbTable::Simulators,   QStringLiteral("simulators")},
-        {DbTable::Pilots,       QStringLiteral("pilots")},
-        {DbTable::Tails,        QStringLiteral("tails")},
-        {DbTable::Aircraft,     QStringLiteral("aircraft")},
-        {DbTable::Airports,     QStringLiteral("airports")},
-        {DbTable::Currencies,   QStringLiteral("currencies")},
-        {DbTable::Changelog,    QStringLiteral("changelog")},
-    };
-#else
     const static inline QMap<Translation, QString> L10N_FilePaths {
         {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
         {Translation::German,  QStringLiteral("l10n/openpilotlog_de")},
@@ -253,7 +203,6 @@ private:
         {DbTable::Currencies,   QStringLiteral("currencies")},
         {DbTable::Changelog,    QStringLiteral("changelog")},
     };
-#endif
 
     const static inline QStringList APPROACH_TYPES = {
             QStringLiteral("VISUAL"),