openPilotLog
backupwidget.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2021 Felix Turowsky
4  *
5  *This program is free software: you can redistribute it and/or modify
6  *it under the terms of the GNU General Public License as published by
7  *the Free Software Foundation, either version 3 of the License, or
8  *(at your option) any later version.
9  *
10  *This program is distributed in the hope that it will be useful,
11  *but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *GNU General Public License for more details.
14  *
15  *You should have received a copy of the GNU General Public License
16  *along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef BACKUPWIDGET_H
19 #define BACKUPWIDGET_H
20 
21 #include "src/classes/astandardpaths.h"
22 
23 #include <QWidget>
24 #include <QStandardItemModel>
25 #include <QFileSystemModel>
26 #include <QFileSystemWatcher>
27 #include <QTableView>
28 
29 namespace Ui {
30 class BackupWidget;
31 }
32 
40 class AFileStandardItem : public QStandardItem {
41 private:
42  QFileInfo fileInfo;
43 public:
44  AFileStandardItem(const QIcon& icon, const QString& filename, const AStandardPaths::Directories dir)
45  : QStandardItem(icon, filename),
46  fileInfo(QFileInfo(AStandardPaths::asChildOfDir(dir, filename)))
47  {}
48  AFileStandardItem(const QIcon& icon, const QFileInfo file_info)
49  : QStandardItem(icon, file_info.baseName()),
50  fileInfo(QFileInfo(file_info))
51  {}
52 
53 
54  const QFileInfo& info() const
55  {
56  return fileInfo;
57  }
58 };
59 
69 class BackupWidget : public QWidget
70 {
71  Q_OBJECT
72 
73 public:
74  explicit BackupWidget(QWidget *parent = nullptr);
75  ~BackupWidget();
76 
77 private slots:
78  void on_tableView_clicked(const QModelIndex &index);
79 
83  void on_createLocalPushButton_clicked();
84 
88  void on_restoreLocalPushButton_clicked();
89 
93  void on_deleteSelectedPushButton_clicked();
94 
98  void on_createExternalPushButton_clicked();
99 
103  void on_restoreExternalPushButton_clicked();
104 
108  void on_aboutPushButton_clicked();
109 
110 private:
111  Ui::BackupWidget *ui;
112 
113  QStandardItemModel *model;
114  QTableView *view;
115  AFileStandardItem *selectedFileInfo = nullptr; // Only the first column is necessary for
116  // any operation and it is encapsulated in the
117  // AFileStandardItem class
118  void refresh();
119 
123  const QString backupName();
124 
128  const QString absoluteBackupPath();
129 
130 protected:
134  void changeEvent(QEvent* event) override;
135 };
136 
137 #endif // BACKUPWIDGET_H
AFileStandardItem
Simple QStandardItem subclass to encapsulate necessary file info. Using only a QStandardItem would me...
Definition: backupwidget.h:40
BackupWidget
The BackupWidget is the interface for the user to create and restore backups of the database.
Definition: backupwidget.h:70
AStandardPaths::asChildOfDir
static const QString asChildOfDir(Directories location, const QString &filename)
Returns a string of the absolute path to directory location concatenated with filename.
Definition: astandardpaths.cpp:46
BackupWidget::changeEvent
void changeEvent(QEvent *event) override
Handles change events, like updating the UI to new localisation.
Definition: backupwidget.cpp:50