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 public:
73  explicit BackupWidget(QWidget *parent = nullptr);
74  ~BackupWidget();
75 
79  static const QString backupName();
80 
84  static const QString absoluteBackupPath();
85 
86 private slots:
87  void on_tableView_clicked(const QModelIndex &index);
88 
92  void on_createLocalPushButton_clicked();
93 
97  void on_restoreLocalPushButton_clicked();
98 
102  void on_deleteSelectedPushButton_clicked();
103 
107  void on_createExternalPushButton_clicked();
108 
112  void on_restoreExternalPushButton_clicked();
113 
117  void on_aboutPushButton_clicked();
118 
119 private:
120  Ui::BackupWidget *ui;
121 
122  QStandardItemModel *model;
123  QTableView *view;
124  AFileStandardItem *selectedFileInfo = nullptr; // Only the first column is necessary for
125  // any operation and it is encapsulated in the
126  // AFileStandardItem class
127  void refresh();
128 
129 protected:
133  void changeEvent(QEvent* event) override;
134 };
135 
136 #endif // BACKUPWIDGET_H
Simple QStandardItem subclass to encapsulate necessary file info. Using only a QStandardItem would me...
Definition: backupwidget.h:40
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:48
The BackupWidget is the interface for the user to create and restore backups of the database.
Definition: backupwidget.h:70
static const QString backupName()
Generates a filename for creating a backup.
Definition: backupwidget.cpp:88
static const QString absoluteBackupPath()
Generates the absolute path for a new local backup file.
Definition: backupwidget.cpp:80
void changeEvent(QEvent *event) override
Handles change events, like updating the UI to new localisation.
Definition: backupwidget.cpp:50