Переглянути джерело

Some tweaks on alog and backupwidget

- Adjusted tableview titles in BackupWidget and made them translatable
- Added descriptive text for 'About Backups'
- Added confirmation Dialogues for restoring/deleting backups
- Tweaked UI of BackupWidget
Felix Turo 3 роки тому
батько
коміт
56a9d4e500

+ 2 - 2
src/classes/astyle.cpp

@@ -88,7 +88,7 @@ void AStyle::resetStyle()
 void AStyle::setStyle(const QString &style_key)
 {
     resetStyle();
-    LOG << "Setting style:\t" << style_key << "\n";
+    LOG << "Setting style:\t" << style_key;
     QApplication::setStyle(QStyleFactory::create(style_key));
     currentStyle = style_key;
 }
@@ -96,7 +96,7 @@ void AStyle::setStyle(const QString &style_key)
 void AStyle::setStyle(const StyleSheet &style_sheet)
 {
     resetStyle();
-    LOG << "Setting stylesheet:\t" << style_sheet.styleSheetName << "\n";
+    LOG << "Setting stylesheet:\t" << style_sheet.styleSheetName;
     qApp->setStyleSheet(read_stylesheet(style_sheet.fileName));
     currentStyle = style_sheet.styleSheetName;
 }

+ 2 - 2
src/database/adatabase.cpp

@@ -111,7 +111,7 @@ bool ADatabase::connect()
     if (!db.open())
         return false;
 
-    LOG << "Database connection established.\n";
+    LOG << "Database connection established.";
     // Enable foreign key restrictions
     QSqlQuery query(QStringLiteral("PRAGMA foreign_keys = ON;"));
     updateLayout();
@@ -123,7 +123,7 @@ void ADatabase::disconnect()
 {
     auto db = ADatabase::database();
     db.close();
-    LOG << "Database connection closed.\n";
+    LOG << "Database connection closed.";
 }
 
 QSqlDatabase ADatabase::database()

+ 20 - 5
src/functions/alog.cpp

@@ -1,9 +1,26 @@
+/*
+ *openPilotLog - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020-2021 Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
 #include "alog.h"
 #include <QMessageBox>
 
 namespace ALog {
 
-static bool logDebug = false;
+static bool logDebug = false; // Debug doesn't log to file by default
 
 /*!
  * \brief setLogFileName sets a log file name ("Log_<Date>_<Time>.txt")
@@ -71,9 +88,7 @@ void aMessageHandler(QtMsgType type, const QMessageLogContext &context,
     //check file size and if needed create new log!
     {
         QFile outFileCheck(logFileName);
-        int size = outFileCheck.size();
-
-        if (size > sizeOfLogs) {
+        if (outFileCheck.size() > sizeOfLogs) {
             deleteOldLogs();
             setLogFileName();
         }
@@ -91,7 +106,7 @@ void aMessageHandler(QtMsgType type, const QMessageLogContext &context,
             break;
         case QtInfoMsg:
             log_stream << timeNow() << INFO_HEADER << msg.chopped(2) << "\t\t" << function << endl;
-            QTextStream(stdout) << INFO_HEADER_CONSOLE << msg;
+            QTextStream(stdout) << INFO_HEADER_CONSOLE << msg << endl;
             break;
         case QtWarningMsg:
             log_stream << timeNow() << WARN_HEADER << msg.chopped(2) << "\t\t" << endl;

+ 17 - 0
src/functions/alog.h

@@ -1,3 +1,20 @@
+/*
+ *openPilotLog - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020-2021 Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
 #ifndef ALOG_H
 #define ALOG_H
 

+ 52 - 27
src/gui/widgets/backupwidget.cpp

@@ -18,27 +18,9 @@ BackupWidget::BackupWidget(QWidget *parent) :
 {
     ui->setupUi(this);
 
-    /* This is just a quick and dirty overview to get something into the view so you have an idea.
-     * The goal is that the view does not just display file names, but a String, for example
-     *
-     * Available Backups
-     * =================
-     * 2020-01-01 - 476 Flights, 23 Aircraft, 12 Pilots, 1580:33 Total Time, Last Flight 2019-12-28
-     * 2020-02-02 - 512 Flights, 25 Aircraft, 13 Pilots, 1640:47 Total Time, Last Flight 2020-01-23
-     * ...
-     *
-     * So instead of QFileSystemModel with QListView, which would be the easiest way, using QAbstractItemModel
-     * and QTableView might be preferable since it allows us to customize the data we display.
-     *
-     * Below is just some sample code to fill the table with data to give you an impression of what
-     * the end result is supposed to be like. If you have another idea of how to get there, that's fine as well!
-     *
-     */
-
-
     model = new QStandardItemModel(this);
-    model->setHorizontalHeaderLabels(QStringList{"Backup File","Total Flights", "Total Tails",
-                                                 "Total Pilots", "Max Doft", "Total Time"});  // [G]: TODO make const but where?
+    model->setHorizontalHeaderLabels(QStringList{tr("Backup File"),tr("Flights"), tr("Aircraft"),
+                                                 tr("Pilots"), tr("Last Flight"), tr("Total Time")});  // [G]: TODO make const but where?
     view = ui->tableView;
     refresh();
 }
@@ -101,17 +83,15 @@ void BackupWidget::on_createLocalPushButton_clicked()
         return;
     }
 
-    // [G] TODO: propably make a function out of this for future tweaks
     QFileIconProvider provider;
     QMap<ADatabaseSummaryKey, QString> summary = aDB->databaseSummary(filename);
-    model->appendRow({new AFileStandardItem(provider.icon(QFileIconProvider::File), QFileInfo(filename)),
+    model->insertRow(0, {new AFileStandardItem(provider.icon(QFileIconProvider::File), QFileInfo(filename)),
                       new QStandardItem(summary[ADatabaseSummaryKey::total_flights]),
                       new QStandardItem(summary[ADatabaseSummaryKey::total_tails]),
                       new QStandardItem(summary[ADatabaseSummaryKey::total_pilots]),
                       new QStandardItem(summary[ADatabaseSummaryKey::max_doft]),
                       new QStandardItem(summary[ADatabaseSummaryKey::total_time])
                      });
-    model->sort(0);
 }
 
 void BackupWidget::on_restoreLocalPushButton_clicked()
@@ -126,9 +106,24 @@ void BackupWidget::on_restoreLocalPushButton_clicked()
                 selectedFileInfo->data(Qt::DisplayRole).toString()
                 );
 
+    QMessageBox confirm(this);
+    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    confirm.setDefaultButton(QMessageBox::No);
+    confirm.setIcon(QMessageBox::Warning);
+    confirm.setWindowTitle(tr("Restoring Backup"));
+    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()));
+    if (confirm.exec() == QMessageBox::No)
+        return;
+
     if(!aDB->restoreBackup(backup_name)) {
         WARN(tr("Couldnt restore Backup: %1").arg(backup_name));
     }
+
+    view->clearSelection();
+    selectedFileInfo = nullptr;
 }
 
 void BackupWidget::on_deleteSelectedPushButton_clicked()
@@ -147,7 +142,19 @@ void BackupWidget::on_deleteSelectedPushButton_clicked()
         return;
     }
 
-    DEB << "deleting:" << filename;
+    QMessageBox confirm(this);
+    confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    confirm.setDefaultButton(QMessageBox::No);
+    confirm.setIcon(QMessageBox::Question);
+    confirm.setWindowTitle(tr("Delete Backup"));
+    confirm.setText(tr("The following backup will be deleted:<br><br><b><tt>"
+                       "%1</b></tt><br><br>"
+                       "Are you sure?"
+                       ).arg(filename.fileName()));
+    if (confirm.exec() == QMessageBox::No)
+        return;
+
+    LOG << "Deleting backup:" << filename;
     if(!file.remove()) {
         WARN(tr("Unable to remove file %1\nError: %2").arg(filename.fileName(),file.errorString()));
         return;
@@ -204,9 +211,27 @@ void BackupWidget::on_restoreExternalPushButton_clicked()
     }
 }
 
-void BackupWidget::on_aboutPushButton_clicked() {
-    // [G]: Add message text. Could this be predefined in Opl::Assets?
-    QMessageBox msg_box(QMessageBox::Information, "About backups", "...", QMessageBox::Ok);
+void BackupWidget::on_aboutPushButton_clicked()
+{
+    TODO << "Implement settings and automatic backups";
+    QString text = tr(
+
+                      "<h3><center>About Backups</center></h3>"
+                      "<br>"
+                      "<p>By creating a backup, you create a copy of your logbook for safekeeping. This copy includes all your "
+                      "flights, pilots, aircraft and expiries. By creating a backup, you are creating a snapshot of your logbook to date. This backup can "
+                      "later be restored or kept for safekeeping. OpenPilotLog offers two kinds of backups: Local and External Backups.<br><br>Local backups "
+                      "are automatically stored in a folder on this computer and will show up in the list below. They can easily be created by selecting <b>Create Local backup</b> and restored with "
+                      "<b>Restore Local Backup</b>.<br>"
+                      "When using <b>Create External Backup</b>, you will be asked where to save your backup file. This can be a pen drive, a cloud location or any other location of your choice. "
+                      "This functionality can also be used to sync your database across devices or to take it with you when you buy a new PC. You can then import your backup file by selecting "
+                      "it with <b>Restore external backup</b>.</p>"
+                      "<p>Frequent backups are recommended to guard against data loss or corruption. It is also recommended to keep a backup copy in a seperate location from your main "
+                      "computer to prevent data loss due to system failures.</p>"
+                      //todo "<p>By default, OpenPilotLog creates a weekly automatic backup. If you would like to change this behaviour, you can adjust it in the settings.</p>"
+                      "<br>"
+                      );
+    QMessageBox msg_box(QMessageBox::Information, "About backups", text, QMessageBox::Ok, this);
     msg_box.exec();
 }
 

+ 65 - 107
src/gui/widgets/backupwidget.ui

@@ -14,44 +14,6 @@
    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="4" column="0">
-    <widget class="QTableView" name="tableView">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="sizeAdjustPolicy">
-      <enum>QAbstractScrollArea::AdjustToContents</enum>
-     </property>
-     <property name="editTriggers">
-      <set>QAbstractItemView::NoEditTriggers</set>
-     </property>
-     <property name="alternatingRowColors">
-      <bool>true</bool>
-     </property>
-     <property name="selectionMode">
-      <enum>QAbstractItemView::SingleSelection</enum>
-     </property>
-     <property name="selectionBehavior">
-      <enum>QAbstractItemView::SelectRows</enum>
-     </property>
-     <attribute name="horizontalHeaderStretchLastSection">
-      <bool>true</bool>
-     </attribute>
-     <attribute name="verticalHeaderVisible">
-      <bool>false</bool>
-     </attribute>
-    </widget>
-   </item>
-   <item row="2" column="0">
-    <widget class="Line" name="line">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
    <item row="6" column="0">
     <widget class="Line" name="line_2">
      <property name="orientation">
@@ -59,78 +21,43 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="0">
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <widget class="QLabel" name="aboutSpacerLabel1">
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLabel" name="aboutSpacerLabel2">
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLabel" name="aboutSpacerLabel3">
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="aboutPushButton">
-       <property name="text">
-        <string>About Backups</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+   <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">
-     <item>
-      <widget class="QLabel" name="titleSpacerLabel1">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
+    <layout class="QHBoxLayout" name="horizontalLayout_11">
      <item>
-      <widget class="QLabel" name="availableBackupsLabel">
+      <widget class="QPushButton" name="createLocalPushButton">
        <property name="text">
-        <string>Available Backups</string>
-       </property>
-       <property name="alignment">
-        <set>Qt::AlignCenter</set>
+        <string>Create Local Backup</string>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="titleSpacerLabel2">
+      <widget class="QPushButton" name="restoreLocalPushButton">
        <property name="text">
-        <string/>
+        <string>Restore Local Backup</string>
        </property>
       </widget>
      </item>
-    </layout>
-   </item>
-   <item row="3" column="0">
-    <layout class="QHBoxLayout" name="horizontalLayout_11">
      <item>
-      <widget class="QPushButton" name="restoreExternalPushButton">
+      <widget class="QPushButton" name="deleteSelectedPushButton">
        <property name="text">
-        <string>Restore External Backup</string>
+        <string>Delete Selected Backup</string>
        </property>
       </widget>
      </item>
@@ -142,28 +69,59 @@
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="deleteSelectedPushButton">
-       <property name="text">
-        <string>Delete Selected Backup</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="restoreLocalPushButton">
+      <widget class="QPushButton" name="restoreExternalPushButton">
        <property name="text">
-        <string>Restore Local Backup</string>
+        <string>Restore External Backup</string>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="createLocalPushButton">
+      <widget class="QPushButton" name="aboutPushButton">
        <property name="text">
-        <string>Create Local Backup</string>
+        <string>About Backups</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
+   <item row="4" column="0">
+    <widget class="QTableView" name="tableView">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="sizeAdjustPolicy">
+      <enum>QAbstractScrollArea::AdjustToContents</enum>
+     </property>
+     <property name="editTriggers">
+      <set>QAbstractItemView::NoEditTriggers</set>
+     </property>
+     <property name="alternatingRowColors">
+      <bool>true</bool>
+     </property>
+     <property name="selectionMode">
+      <enum>QAbstractItemView::SingleSelection</enum>
+     </property>
+     <property name="selectionBehavior">
+      <enum>QAbstractItemView::SelectRows</enum>
+     </property>
+     <attribute name="horizontalHeaderStretchLastSection">
+      <bool>true</bool>
+     </attribute>
+     <attribute name="verticalHeaderVisible">
+      <bool>false</bool>
+     </attribute>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="Line" name="line">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

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

@@ -164,7 +164,7 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
             flights_list_string.append(QStringLiteral("&nbsp;&nbsp;&nbsp;&nbsp;<br>"));
         }
 
-        QMessageBox confirm;
+        QMessageBox confirm(this);
         confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
         confirm.setDefaultButton(QMessageBox::No);
         confirm.setIcon(QMessageBox::Question);