window-importer.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******************************************************************************
  2. Copyright (C) 2019-2020 by Dillon Pentz <dillon@vodbox.io>
  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 "obs-app.hpp"
  16. #include "window-basic-main.hpp"
  17. #include <QPointer>
  18. #include <QStyledItemDelegate>
  19. #include <QFileInfo>
  20. #include "ui_OBSImporter.h"
  21. class ImporterModel;
  22. class OBSImporter : public QDialog {
  23. Q_OBJECT
  24. QPointer<ImporterModel> optionsModel;
  25. std::unique_ptr<Ui::OBSImporter> ui;
  26. public:
  27. explicit OBSImporter(QWidget *parent = nullptr);
  28. void addImportOption(QString path, bool automatic);
  29. protected:
  30. virtual void dropEvent(QDropEvent *ev) override;
  31. virtual void dragEnterEvent(QDragEnterEvent *ev) override;
  32. public slots:
  33. void browseImport();
  34. void importCollections();
  35. void dataChanged();
  36. };
  37. class ImporterModel : public QAbstractTableModel {
  38. Q_OBJECT
  39. friend class OBSImporter;
  40. public:
  41. ImporterModel(QObject *parent = 0) : QAbstractTableModel(parent) {}
  42. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  43. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  44. QVariant data(const QModelIndex &index, int role) const;
  45. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  46. Qt::ItemFlags flags(const QModelIndex &index) const;
  47. bool setData(const QModelIndex &index, const QVariant &value, int role);
  48. private:
  49. struct ImporterEntry {
  50. QString path;
  51. QString program;
  52. QString name;
  53. bool selected;
  54. bool empty;
  55. };
  56. QList<ImporterEntry> options;
  57. void checkInputPath(int row);
  58. };
  59. class ImporterEntryPathItemDelegate : public QStyledItemDelegate {
  60. Q_OBJECT
  61. public:
  62. ImporterEntryPathItemDelegate();
  63. virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */,
  64. const QModelIndex &index) const override;
  65. virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override;
  66. virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
  67. virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
  68. const QModelIndex &index) const override;
  69. private:
  70. const char *PATH_LIST_PROP = "pathList";
  71. void handleBrowse(QWidget *container);
  72. void handleClear(QWidget *container);
  73. private slots:
  74. void updateText();
  75. };