1
0

window-missing-files.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /******************************************************************************
  2. Copyright (C) 2019 by Dillon Pentz <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QPointer>
  16. #include <QStyledItemDelegate>
  17. #include "obs-app.hpp"
  18. #include "ui_OBSMissingFiles.h"
  19. class MissingFilesModel;
  20. enum MissingFilesState { Missing, Found, Replaced, Cleared };
  21. Q_DECLARE_METATYPE(MissingFilesState);
  22. class OBSMissingFiles : public QDialog {
  23. Q_OBJECT
  24. Q_PROPERTY(QIcon warningIcon READ GetWarningIcon WRITE SetWarningIcon
  25. DESIGNABLE true)
  26. QPointer<MissingFilesModel> filesModel;
  27. std::unique_ptr<Ui::OBSMissingFiles> ui;
  28. public:
  29. explicit OBSMissingFiles(obs_missing_files_t *files,
  30. QWidget *parent = nullptr);
  31. virtual ~OBSMissingFiles() override;
  32. void addMissingFile(const char *originalPath, const char *sourceName);
  33. QIcon GetWarningIcon();
  34. void SetWarningIcon(const QIcon &icon);
  35. private:
  36. void saveFiles();
  37. void browseFolders();
  38. obs_missing_files_t *fileStore;
  39. public slots:
  40. void dataChanged();
  41. };
  42. class MissingFilesModel : public QAbstractTableModel {
  43. Q_OBJECT
  44. friend class OBSMissingFiles;
  45. public:
  46. explicit MissingFilesModel(QObject *parent = 0);
  47. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  48. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  49. int found() const;
  50. QVariant data(const QModelIndex &index, int role) const;
  51. QVariant headerData(int section, Qt::Orientation orientation,
  52. int role = Qt::DisplayRole) const;
  53. Qt::ItemFlags flags(const QModelIndex &index) const;
  54. bool setData(const QModelIndex &index, const QVariant &value, int role);
  55. bool loop = true;
  56. QIcon warningIcon;
  57. private:
  58. struct MissingFileEntry {
  59. MissingFilesState state = MissingFilesState::Missing;
  60. QString source;
  61. QString originalPath;
  62. QString newPath;
  63. };
  64. QList<MissingFileEntry> files;
  65. void fileCheckLoop(QList<MissingFileEntry> files, QString path,
  66. bool skipPrompt);
  67. };
  68. class MissingFilesPathItemDelegate : public QStyledItemDelegate {
  69. Q_OBJECT
  70. public:
  71. MissingFilesPathItemDelegate(bool isOutput, const QString &defaultPath);
  72. virtual QWidget *createEditor(QWidget *parent,
  73. const QStyleOptionViewItem & /* option */,
  74. const QModelIndex &index) const override;
  75. virtual void setEditorData(QWidget *editor,
  76. const QModelIndex &index) const override;
  77. virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
  78. const QModelIndex &index) const override;
  79. virtual void paint(QPainter *painter,
  80. const QStyleOptionViewItem &option,
  81. const QModelIndex &index) const override;
  82. private:
  83. bool isOutput;
  84. QString defaultPath;
  85. const char *PATH_LIST_PROP = "pathList";
  86. void handleBrowse(QWidget *container);
  87. void handleClear(QWidget *container);
  88. };