Pārlūkot izejas kodu

Tweaks to backupwidget and FirstRunDialog

- Added the option to import an existing database to FirstRunDialog
- Added a QMessageBox to BackupWidget to confirm when importing backups
Felix Turo 3 gadi atpakaļ
vecāks
revīzija
1058fb0eaa

+ 14 - 0
src/database/adatabase.cpp

@@ -723,6 +723,20 @@ QMap<ADatabaseSummaryKey, QString> ADatabase::databaseSummary(const QString &db_
     return return_values;
 }
 
+const QString ADatabase::databaseSummaryString(const QString &db_path)
+{
+    auto summary_map = databaseSummary(db_path);
+    QString out = QLatin1String("<table>");
+    out.append(tr("<tr><td>Total Time: </td><td>%1</td>").arg(summary_map[ADatabaseSummaryKey::total_time]));
+    out.append(tr("<tr><td>Last Flight: </td><td>%1</td>").arg(summary_map[ADatabaseSummaryKey::last_flight]));
+    out.append(tr("<tr><td>Number of flights: </td><td>%1</td>").arg(summary_map[ADatabaseSummaryKey::total_flights]));
+    out.append(tr("<tr><td>Number of aircraft: </td><td>%1</td>").arg(summary_map[ADatabaseSummaryKey::total_tails]));
+    out.append(tr("<tr><td>Number of Pilots: </td><td>%1</td>").arg(summary_map[ADatabaseSummaryKey::total_pilots]));
+    out.append("</table>");
+
+    return out;
+}
+
 /*!
  * \brief ADatabase::createBackup copies the currently used database to an external backup location provided by the user
  * \param dest_file This is the full path and filename of where the backup will be created, e.g. 'home/Sully/myBackups/backupFromOpl.db'

+ 5 - 0
src/database/adatabase.h

@@ -305,6 +305,11 @@ public:
      */
     QMap<ADatabaseSummaryKey, QString> databaseSummary(const QString& db_path);
 
+    /*!
+     * \brief returns a short summary string of the database, containing total time and date of last flight.
+     */
+    const QString databaseSummaryString(const QString& db_path);
+
     bool restoreBackup(const QString& backup_file);
     bool createBackup(const QString& dest_file);
 

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

@@ -26,6 +26,7 @@
 #include "src/opl.h"
 #include "src/functions/adate.h"
 #include <QErrorMessage>
+#include <QFileDialog>
 #include "src/classes/astyle.h"
 
 FirstRunDialog::FirstRunDialog(QWidget *parent) :
@@ -369,3 +370,38 @@ void FirstRunDialog::on_dateFormatComboBox_currentIndexChanged(int index)
     }
     ASettings::write(ASettings::Main::DateFormat, index);
 }
+
+void FirstRunDialog::on_importPushButton_clicked()
+{
+    QString filename = QFileDialog::getOpenFileName(
+                this,
+                tr("Choose backup file"),
+                QDir::homePath(),
+                "*.db"
+    );
+
+    if(filename.isEmpty()) { // QFileDialog has been cancelled
+        WARN(tr("No Database has been selected."));
+        return;
+    }
+
+    QMessageBox confirm(this);
+    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    confirm.setDefaultButton(QMessageBox::No);
+    confirm.setIcon(QMessageBox::Question);
+    confirm.setWindowTitle(tr("Import Database"));
+    confirm.setText(tr("The following database will be imported:<br><br><b><tt>"
+                       "%1<br></b></tt>"
+                       "<br>Is this correct?"
+                       ).arg(aDB->databaseSummaryString(filename)));
+    if (confirm.exec() == QMessageBox::Yes) {
+        if(!aDB->restoreBackup(filename)) {
+            WARN(tr("Unable to import database file:").arg(filename));
+            return;
+        }
+        INFO(tr("Database successfully imported."));
+        QDialog::accept(); // quit the dialog as if a database was successfully created
+    } else {
+        return;
+    }
+}

+ 5 - 0
src/gui/dialogues/firstrundialog.h

@@ -54,6 +54,11 @@ private slots:
 
     void on_dateFormatComboBox_currentIndexChanged(int index);
 
+    /*!
+     * \brief Import an existing database instead of creating a new one
+     */
+    void on_importPushButton_clicked();
+
 private:
     Ui::FirstRunDialog *ui;
     bool useRessourceData;

+ 54 - 28
src/gui/dialogues/firstrundialog.ui

@@ -14,26 +14,27 @@
    <string>Dialog</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
+   <item row="2" column="0">
+    <widget class="QPushButton" name="previousPushButton">
+     <property name="text">
+      <string>Previous</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QPushButton" name="nextPushButton">
+     <property name="text">
+      <string>Next</string>
+     </property>
+    </widget>
+   </item>
    <item row="1" column="0" colspan="2">
     <widget class="QStackedWidget" name="stackedWidget">
      <property name="currentIndex">
-      <number>4</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="personalDataPage">
       <layout class="QGridLayout" name="gridLayout_9">
-       <item row="0" column="0">
-        <widget class="QLabel" name="label">
-         <property name="text">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Welcome to openPilotLog!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;The Free and Open Source Logbook application&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Before getting started, we need to quickly run through this initial set-up process. Please note that none of the data you put in will be stored in any place other than your own personal computer and will only be used to fill out information in your logbook.&lt;/p&gt;&lt;p&gt;OpenPilotLog does not collect, sell or use your private data for any commercial purpose.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="textFormat">
-          <enum>Qt::RichText</enum>
-         </property>
-         <property name="wordWrap">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
        <item row="1" column="0" rowspan="2">
         <layout class="QGridLayout" name="gridLayout_2">
          <item row="0" column="0">
@@ -129,6 +130,45 @@
          </item>
         </layout>
        </item>
+       <item row="4" column="0">
+        <widget class="QPushButton" name="importPushButton">
+         <property name="text">
+          <string>Import Database</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="0">
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Welcome to openPilotLog!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;The Free and Open Source Logbook application&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Before getting started, we need to quickly run through this initial set-up process. Please note that none of the data you put in will be stored in any place other than your own personal computer and will only be used to fill out information in your logbook.&lt;/p&gt;&lt;p&gt;OpenPilotLog does not collect, sell or use your private data for any commercial purpose.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="textFormat">
+          <enum>Qt::RichText</enum>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QLabel" name="importLabel">
+         <property name="font">
+          <font>
+           <weight>75</weight>
+           <bold>true</bold>
+          </font>
+         </property>
+         <property name="toolTip">
+          <string>If you already have been using openPilotLog before and wish to continue your logbook, skip this initial setup process and import your database instead.</string>
+         </property>
+         <property name="text">
+          <string>Already have a logbook database?</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="currencyPage">
@@ -800,20 +840,6 @@
      </widget>
     </widget>
    </item>
-   <item row="2" column="0">
-    <widget class="QPushButton" name="previousPushButton">
-     <property name="text">
-      <string>Previous</string>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="1">
-    <widget class="QPushButton" name="nextPushButton">
-     <property name="text">
-      <string>Next</string>
-     </property>
-    </widget>
-   </item>
    <item row="0" column="0" colspan="2">
     <widget class="QLabel" name="logoLabel">
      <property name="text">

+ 19 - 8
src/gui/widgets/backupwidget.cpp

@@ -37,10 +37,9 @@ BackupWidget::BackupWidget(QWidget *parent) :
 
     model = new QStandardItemModel(this);
     model->setHorizontalHeaderLabels(QStringList{tr("Backup File"),tr("Flights"), tr("Aircraft"),
-                                                 tr("Pilots"), tr("Last Flight"), tr("Total Time")});  // [G]: TODO make const but where?
+                                                 tr("Pilots"), tr("Last Flight"), tr("Total Time")});  // [G]: TODO make const but where?    
     view = ui->tableView;
     refresh();
-    TODO << "Update Documentation";
 }
 
 BackupWidget::~BackupWidget()
@@ -67,8 +66,8 @@ void BackupWidget::refresh()
                          });
     }
 
-    ui->tableView->setModel(model);
-    ui->tableView->resizeColumnsToContents();  // [G]: Bit hacky couldnt do it by default
+    view->setModel(model);
+    view->resizeColumnsToContents();
 }
 
 const QString BackupWidget::absoluteBackupPath()
@@ -132,7 +131,7 @@ void BackupWidget::on_restoreLocalPushButton_clicked()
     confirm.setText(tr("The following backup will be restored:<br><br><b><tt>"
                        "%1</b></tt><br><br>"
                        "This will replace your currently active database with the backup.<br>This action is irreversible.<br><br>Are you sure?"
-                       ).arg(selectedFileInfo->info().fileName()));
+                       ).arg(aDB->databaseSummaryString(backup_name)));
     if (confirm.exec() == QMessageBox::No)
         return;
 
@@ -220,9 +219,21 @@ void BackupWidget::on_restoreExternalPushButton_clicked()
 
     // Maybe create a Message Box asking for confirmation here and displaying the summary of backup and active DB
 
-    if(!aDB->restoreBackup(filename)) {
-        WARN(tr("Unable to backup file:").arg(filename));
-        return;
+    QMessageBox confirm(this);
+    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    confirm.setDefaultButton(QMessageBox::No);
+    confirm.setIcon(QMessageBox::Question);
+    confirm.setWindowTitle(tr("Import Database"));
+    confirm.setText(tr("The following database will be imported:<br><br><b><tt>"
+                       "%1<br></b></tt>"
+                       "<br>Is this correct?"
+                       ).arg(aDB->databaseSummaryString(filename)));
+    if (confirm.exec() == QMessageBox::Yes) {
+        if(!aDB->restoreBackup(filename)) {
+            WARN(tr("Unable to import database file:").arg(filename));
+            return;
+        }
+        INFO(tr("Database successfully imported."));
     }
 }
 

+ 83 - 73
src/gui/widgets/backupwidget.ui

@@ -14,77 +14,7 @@
    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="6" column="0">
-    <widget class="Line" name="line_2">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="0">
-    <widget class="QLabel" name="availableBackupsLabel">
-     <property name="font">
-      <font>
-       <pointsize>10</pointsize>
-       <weight>75</weight>
-       <bold>true</bold>
-      </font>
-     </property>
-     <property name="text">
-      <string>Available Backups</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <layout class="QHBoxLayout" name="horizontalLayout_11">
-     <item>
-      <widget class="QPushButton" name="createLocalPushButton">
-       <property name="text">
-        <string>Create Local Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="restoreLocalPushButton">
-       <property name="text">
-        <string>Restore Local Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="deleteSelectedPushButton">
-       <property name="text">
-        <string>Delete Selected Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="createExternalPushButton">
-       <property name="text">
-        <string>Create External Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="restoreExternalPushButton">
-       <property name="text">
-        <string>Restore External Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="aboutPushButton">
-       <property name="text">
-        <string>About Backups</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item row="4" column="0">
+   <item row="2" column="0" colspan="5">
     <widget class="QTableView" name="tableView">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -93,7 +23,7 @@
       </sizepolicy>
      </property>
      <property name="sizeAdjustPolicy">
-      <enum>QAbstractScrollArea::AdjustToContents</enum>
+      <enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
      </property>
      <property name="editTriggers">
       <set>QAbstractItemView::NoEditTriggers</set>
@@ -115,13 +45,93 @@
      </attribute>
     </widget>
    </item>
-   <item row="3" column="0">
+   <item row="1" column="0" colspan="5">
     <widget class="Line" name="line">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
+   <item row="4" column="1" rowspan="2">
+    <widget class="Line" name="line_3">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="4">
+    <widget class="QPushButton" name="restoreExternalPushButton">
+     <property name="text">
+      <string>Restore External Backup</string>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="2">
+    <widget class="QPushButton" name="aboutPushButton">
+     <property name="text">
+      <string>About Backups</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="QPushButton" name="createLocalPushButton">
+     <property name="text">
+      <string>Create Local Backup</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" colspan="5">
+    <widget class="Line" name="line_2">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="4">
+    <widget class="QPushButton" name="createExternalPushButton">
+     <property name="text">
+      <string>Create External Backup</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="3" rowspan="2">
+    <widget class="Line" name="line_4">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="2">
+    <widget class="QPushButton" name="deleteSelectedPushButton">
+     <property name="text">
+      <string>Delete Selected Backup</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="2">
+    <widget class="QLabel" name="availableBackupsLabel">
+     <property name="font">
+      <font>
+       <pointsize>12</pointsize>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Available Backups</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0">
+    <widget class="QPushButton" name="restoreLocalPushButton">
+     <property name="text">
+      <string>Restore Local Backup</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

+ 3 - 13
src/gui/widgets/debugwidget.cpp

@@ -187,19 +187,9 @@ void DebugWidget::on_importCsvPushButton_clicked()
 #include "src/functions/adate.h"
 void DebugWidget::on_debugPushButton_clicked()
 {
-    QMap<QString, Opl::Date::ADateFormat> dates = {
-        {"2020-01-01", Opl::Date::ADateFormat::ISODate},
-        {"20200101", Opl::Date::ADateFormat::ISODate},
-        {"03.01.2020", Opl::Date::ADateFormat::DE},
-        {"03012020", Opl::Date::ADateFormat::DE},
-        {"01/04/2020", Opl::Date::ADateFormat::EN},
-        {"01042020", Opl::Date::ADateFormat::EN},
-        {"01", Opl::Date::ADateFormat::EN}
-    };
-    QMap<QString, Opl::Date::ADateFormat>::iterator i;
-    for (i = dates.begin(); i != dates.end(); i++) {
-        DEB << ADate::formatInput(i.key(), i.value());
-    }
+    auto frdl = new FirstRunDialog(this);
+    frdl->exec();
+
 }
 
 /* //Comparing two functions template