Explorar el Código

Incomplete work on create external, cleaned some bool conditionals

Georgios Kotzampopoulos hace 3 años
padre
commit
12c04ac1d5
Se han modificado 2 ficheros con 36 adiciones y 9 borrados
  1. 9 4
      src/database/adatabase.cpp
  2. 27 5
      src/gui/widgets/backupwidget.cpp

+ 9 - 4
src/database/adatabase.cpp

@@ -725,11 +725,16 @@ bool ADatabase::createBackup(const QString& dest_file)
 {
     INFO << "Backing up current database to: " << dest_file;
     ADatabase::disconnect();
-    QFile file(databaseFile.absoluteFilePath());
-    DEB << "File:" << file;  // [G]: Check adebug.h got INFO WARN, ... additions and discuss convention of use.
+    QFile db_file(databaseFile.absoluteFilePath());
+    DEB << "File to Overwrite:" << db_file;  // [G]: Check adebug.h got INFO WARN, ... additions and discuss convention of use.
 
-    if (!file.copy(dest_file)) {
-        WARN << "Unable to backup old database:" << file.errorString();
+//    if(!db_file.remove()) {
+//        DEB << "Unable to delete file:" << db_file;
+//        return false;
+//    }
+
+    if (!db_file.copy(dest_file)) {
+        WARN << "Unable to backup old database:" << db_file.errorString();
         return false;
     }
 

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

@@ -113,13 +113,13 @@ void BackupWidget::on_deleteSelectedPushButton_clicked()
     const QFileInfo& filename = selectedFileInfo->info();
     QFile file(filename.absoluteFilePath());
 
-    if(file.exists() == false) {
+    if(!file.exists()) {
         WARN << "Selected backup file doesnt exist:" << file;
         return;
     }
 
     DEB << "deleting:" << filename;
-    if(file.remove() == false) {
+    if(!file.remove()) {
         WARN << "Unable to remove file:" << file.errorString();
         return;
     }
@@ -140,11 +140,33 @@ void BackupWidget::on_createExternalPushButton_clicked()
     QString filename = QFileDialog::getSaveFileName(
                 this,
                 "Choose destination file",
-                QStandardPaths::displayName(QStandardPaths::HomeLocation),
-                ".db"
+                // [G]: Is this necessary?
+                QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).absoluteFilePath("untitled.db"),
+                "*.db"
     );
+
+    if(!filename.endsWith(".db")) {
+        filename.append(".db");
+    }
+
+    if(!aDB->createBackup(filename)) {
+        DEB << "Unable to backup file:" << filename;
+        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)),
+                      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);
+
     // [G]: The window isn resizable and i cant easily debug the buttons (cant find them xD)
-    // Open something like a QFileDialog and let the user choose where to save the backup
 }
 
 void BackupWidget::on_restoreExternalPushButton_clicked()