|
@@ -18,8 +18,6 @@
|
|
|
#include "backupwidget.h"
|
|
|
#include "ui_backupwidget.h"
|
|
|
#include "src/opl.h"
|
|
|
-#include "src/classes/astandardpaths.h"
|
|
|
-#include "src/functions/alog.h"
|
|
|
#include "src/database/database.h"
|
|
|
#include "src/functions/adatetime.h"
|
|
|
#include "src/database/dbsummary.h"
|
|
@@ -58,19 +56,21 @@ void BackupWidget::changeEvent(QEvent *event)
|
|
|
void BackupWidget::refresh()
|
|
|
{
|
|
|
// First column in table, would be created by listing the files in backupdir
|
|
|
- QDir backup_dir = QDir(AStandardPaths::directory(AStandardPaths::Backup));
|
|
|
+ QDir backup_dir = OPL::Paths::directory(OPL::Paths::Backup);
|
|
|
+ //QDir backup_dir = QDir(AStandardPaths::directory(AStandardPaths::Backup));
|
|
|
const QStringList entries = backup_dir.entryList(QStringList{"*.db"}, QDir::Files, QDir::Time);
|
|
|
QFileIconProvider provider;
|
|
|
|
|
|
// Get summary of each db file and populate lists (columns) of data
|
|
|
for (const auto &entry : entries) {
|
|
|
+ DEB << "Filename string: " << entry;
|
|
|
QMap<OPL::DbSummaryKey, QString> summary = OPL::DbSummary::databaseSummary(backup_dir.absoluteFilePath(entry));
|
|
|
model->appendRow({new QStandardItem(summary[OPL::DbSummaryKey::total_time]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::total_flights]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::total_tails]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::total_pilots]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::last_flight]),
|
|
|
- new AFileStandardItem(provider.icon(QFileIconProvider::File), entry, AStandardPaths::Backup)
|
|
|
+ new FileStandardItem(provider.icon(QFileIconProvider::File), entry, OPL::Paths::Backup)
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -83,7 +83,8 @@ const QString BackupWidget::absoluteBackupPath()
|
|
|
const QString backup_name = QLatin1String("logbook_backup_")
|
|
|
+ ADateTime::toString(QDateTime::currentDateTime(), OPL::DateTimeFormat::Backup)
|
|
|
+ QLatin1String(".db");
|
|
|
- return AStandardPaths::asChildOfDir(AStandardPaths::Backup, backup_name);
|
|
|
+ return OPL::Paths::filePath(OPL::Paths::Backup, backup_name);
|
|
|
+ //return AStandardPaths::asChildOfDir(AStandardPaths::Backup, backup_name);
|
|
|
}
|
|
|
|
|
|
const QString BackupWidget::backupName()
|
|
@@ -95,8 +96,9 @@ const QString BackupWidget::backupName()
|
|
|
|
|
|
void BackupWidget::on_tableView_clicked(const QModelIndex &index)
|
|
|
{
|
|
|
- selectedFileInfo = static_cast<AFileStandardItem*>(model->item(index.row(), 0));
|
|
|
- DEB << "Item at row:" << index.row() << "->" << selectedFileInfo->data(Qt::DisplayRole);
|
|
|
+ selectedRows.clear();
|
|
|
+ selectedRows.append(index.row());
|
|
|
+ DEB << model->item(index.row(), 5)->data(Qt::DisplayRole);
|
|
|
}
|
|
|
|
|
|
void BackupWidget::on_createLocalPushButton_clicked()
|
|
@@ -118,21 +120,19 @@ void BackupWidget::on_createLocalPushButton_clicked()
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::total_tails]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::total_pilots]),
|
|
|
new QStandardItem(summary[OPL::DbSummaryKey::last_flight]),
|
|
|
- new AFileStandardItem(provider.icon(QFileIconProvider::File), QFileInfo(filename)),
|
|
|
+ new FileStandardItem(provider.icon(QFileIconProvider::File), QFileInfo(filename)),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
void BackupWidget::on_restoreLocalPushButton_clicked()
|
|
|
{
|
|
|
- if(selectedFileInfo == nullptr) {
|
|
|
+ if(selectedRows.isEmpty()) {
|
|
|
INFO(tr("No backup selected"));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- QString backup_name = AStandardPaths::asChildOfDir(
|
|
|
- AStandardPaths::Backup,
|
|
|
- selectedFileInfo->data(Qt::DisplayRole).toString()
|
|
|
- );
|
|
|
+ const QString file_name = model->item(selectedRows.first(), 5)->data(Qt::DisplayRole).toString();
|
|
|
+ const QString backup_name = OPL::Paths::filePath(OPL::Paths::Backup, file_name);
|
|
|
|
|
|
QMessageBox confirm(this);
|
|
|
confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
@@ -153,21 +153,22 @@ void BackupWidget::on_restoreLocalPushButton_clicked()
|
|
|
}
|
|
|
|
|
|
view->clearSelection();
|
|
|
- selectedFileInfo = nullptr;
|
|
|
+ selectedRows.clear();
|
|
|
}
|
|
|
|
|
|
void BackupWidget::on_deleteSelectedPushButton_clicked()
|
|
|
{
|
|
|
- if(selectedFileInfo == nullptr) {
|
|
|
+ if(selectedRows.isEmpty()) {
|
|
|
INFO(tr("No backup was selected"));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const QFileInfo& filename = selectedFileInfo->info();
|
|
|
- QFile file(filename.absoluteFilePath());
|
|
|
+ const QString file_name = model->item(selectedRows.first(), 5)->data(Qt::DisplayRole).toString();
|
|
|
+ const QString backup_name = OPL::Paths::filePath(OPL::Paths::Backup, file_name);
|
|
|
+ QFile file(OPL::Paths::filePath(OPL::Paths::Backup, file_name));
|
|
|
|
|
|
if(!file.exists()) {
|
|
|
- WARN(tr("Selected backup file (<tt>%1</tt>) does not exist.").arg(filename.absolutePath()));
|
|
|
+ WARN(tr("Selected backup file (<tt>%1</tt>) does not exist.").arg(file_name));
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -176,24 +177,24 @@ void BackupWidget::on_deleteSelectedPushButton_clicked()
|
|
|
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()));
|
|
|
+ confirm.setText(tr("The following backup will be deleted:<br><br><i>%1</i><br><br><b><tt>"
|
|
|
+ "%2</b></tt><br><br>"
|
|
|
+ "<b>This action is irreversible.</b><br><br>Continue?"
|
|
|
+ ).arg(file_name, OPL::DbSummary::summaryString(backup_name)));
|
|
|
if (confirm.exec() == QMessageBox::No)
|
|
|
return;
|
|
|
|
|
|
- LOG << "Deleting backup:" << filename;
|
|
|
+ LOG << "Deleting backup:" << file_name;
|
|
|
if(!file.remove()) {
|
|
|
- WARN(tr("Unable to remove file %1\nError: %2").arg(filename.fileName(),file.errorString()));
|
|
|
+ WARN(tr("Unable to remove file %1\nError: %2").arg(file_name,file.errorString()));
|
|
|
return;
|
|
|
} else {
|
|
|
INFO(tr("Backup successfully deleted."));
|
|
|
}
|
|
|
|
|
|
- model->removeRow(selectedFileInfo->row());
|
|
|
+ model->removeRow(selectedRows.first());
|
|
|
view->clearSelection();
|
|
|
- selectedFileInfo = nullptr;
|
|
|
+ selectedRows.clear();
|
|
|
}
|
|
|
|
|
|
void BackupWidget::on_createExternalPushButton_clicked()
|