backupwidget.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BACKUPWIDGET_H
  2. #define BACKUPWIDGET_H
  3. #include "src/classes/astandardpaths.h"
  4. #include <QWidget>
  5. #include <QStandardItemModel>
  6. #include <QFileSystemModel>
  7. #include <QFileSystemWatcher>
  8. #include <QTableView>
  9. namespace Ui {
  10. class BackupWidget;
  11. }
  12. /*!
  13. * \brief Simple QStandardItem subclass to encapsulate necessary file info.
  14. * Using only a QStandardItem would mean that the full path should be inputted
  15. * as data and of course displayed by default. However this way we create
  16. * the absolute path in the fileInfo attribute for further use while
  17. * displaying only the base name.
  18. */
  19. class AFileStandardItem : public QStandardItem {
  20. private:
  21. QFileInfo fileInfo;
  22. public:
  23. AFileStandardItem(const QIcon& icon, const QString& filename, const AStandardPaths::Directories dir)
  24. : QStandardItem(icon, filename),
  25. fileInfo(QFileInfo(AStandardPaths::asChildOfDir(dir, filename)))
  26. {}
  27. AFileStandardItem(const QIcon& icon, const QFileInfo file_info)
  28. : QStandardItem(icon, file_info.baseName()),
  29. fileInfo(QFileInfo(file_info))
  30. {}
  31. const QFileInfo& info() const
  32. {
  33. return fileInfo;
  34. }
  35. };
  36. class BackupWidget : public QWidget
  37. {
  38. Q_OBJECT
  39. public:
  40. explicit BackupWidget(QWidget *parent = nullptr);
  41. ~BackupWidget();
  42. private slots:
  43. void on_tableView_clicked(const QModelIndex &index);
  44. void on_createLocalPushButton_clicked();
  45. void on_restoreLocalPushButton_clicked();
  46. void on_deleteSelectedPushButton_clicked();
  47. void on_createExternalPushButton_clicked();
  48. void on_restoreExternalPushButton_clicked();
  49. void on_aboutPushButton_clicked();
  50. private:
  51. Ui::BackupWidget *ui;
  52. QStandardItemModel *model;
  53. QTableView *view;
  54. AFileStandardItem *selectedFileInfo = nullptr; // Only the first column is necessary for
  55. // any operation and it is encapsulated in the
  56. // AFileStandardItem class
  57. void refresh();
  58. /*!
  59. * \brief Generates a filename for creating a backup
  60. */
  61. const QString backupName();
  62. /*!
  63. * \brief Generates the absolute path for a new backup file.
  64. */
  65. const QString absoluteBackupPath();
  66. };
  67. #endif // BACKUPWIDGET_H