MissingFilesPathItemDelegate.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 DESIGNABLE true)
  25. QPointer<MissingFilesModel> filesModel;
  26. std::unique_ptr<Ui::OBSMissingFiles> ui;
  27. public:
  28. explicit OBSMissingFiles(obs_missing_files_t *files, QWidget *parent = nullptr);
  29. virtual ~OBSMissingFiles() override;
  30. void addMissingFile(const char *originalPath, const char *sourceName);
  31. QIcon GetWarningIcon();
  32. void SetWarningIcon(const QIcon &icon);
  33. private:
  34. void saveFiles();
  35. void browseFolders();
  36. obs_missing_files_t *fileStore;
  37. public slots:
  38. void dataChanged();
  39. };
  40. class MissingFilesModel : public QAbstractTableModel {
  41. Q_OBJECT
  42. friend class OBSMissingFiles;
  43. public:
  44. explicit MissingFilesModel(QObject *parent = 0);
  45. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  46. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  47. int found() const;
  48. QVariant data(const QModelIndex &index, int role) const;
  49. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  50. Qt::ItemFlags flags(const QModelIndex &index) const;
  51. bool setData(const QModelIndex &index, const QVariant &value, int role);
  52. bool loop = true;
  53. QIcon warningIcon;
  54. private:
  55. struct MissingFileEntry {
  56. MissingFilesState state = MissingFilesState::Missing;
  57. QString source;
  58. QString originalPath;
  59. QString newPath;
  60. };
  61. QList<MissingFileEntry> files;
  62. void fileCheckLoop(QList<MissingFileEntry> files, QString path, bool skipPrompt);
  63. };
  64. class MissingFilesPathItemDelegate : public QStyledItemDelegate {
  65. Q_OBJECT
  66. public:
  67. MissingFilesPathItemDelegate(bool isOutput, const QString &defaultPath);
  68. virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */,
  69. const QModelIndex &index) const override;
  70. virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override;
  71. virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
  72. virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
  73. const QModelIndex &index) const override;
  74. private:
  75. bool isOutput;
  76. QString defaultPath;
  77. const char *PATH_LIST_PROP = "pathList";
  78. void handleBrowse(QWidget *container);
  79. void handleClear(QWidget *container);
  80. };