AssetImporterManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <QMainWindow>
  11. #include <AssetImporter/UI/SelectDestinationDialog.h>
  12. #endif
  13. class QStringList;
  14. class QFile;
  15. class QFileDialog;
  16. enum class ImportFilesMethod
  17. {
  18. CopyFiles,
  19. MoveFiles
  20. };
  21. enum class ProcessFilesMethod
  22. {
  23. OverwriteFile,
  24. KeepBothFile,
  25. SkipProcessingFile,
  26. OverwriteAllFiles,
  27. KeepBothAllFiles,
  28. SkipProcessingAllFiles,
  29. Cancel,
  30. Default
  31. };
  32. class AssetImporterManager
  33. : public QObject
  34. {
  35. Q_OBJECT
  36. public:
  37. explicit AssetImporterManager(QWidget* parent = nullptr);
  38. ~AssetImporterManager();
  39. // Modal, but blocking.
  40. void Exec(); // for browsing files
  41. void Exec(const QStringList& dragAndDropFileList); // for drag and drop
  42. void Exec(const QStringList& dragAndDropFileList, const QString& suggestedPath);
  43. Q_SIGNALS:
  44. void StartAssetImporter();
  45. void StopAssetImporter();
  46. void AssetImportingComplete();
  47. private Q_SLOTS:
  48. void reject();
  49. void CompleteAssetImporting(bool wasSuccessful = true);
  50. void OnDragAndDropFiles(const QStringList* fileList);
  51. void OnBrowseDestinationFilePath(QLineEdit* destinationLineEdit);
  52. void OnCopyFiles();
  53. void OnMoveFiles();
  54. bool OnOverwriteFiles(QString relativePath, QString oldAbsolutePath);
  55. bool OnKeepBothFiles(QString relativePath, QString oldAbsolutePath);
  56. void OnOpenLogDialog();
  57. void OnSetDestinationDirectory(QString destinationDirectory);
  58. private:
  59. void OnOpenSelectDestinationDialog();
  60. ProcessFilesMethod OnOpenFilesAlreadyExistDialog(QString message, int numberOfFiles);
  61. ProcessFilesMethod UpdateProcessFileMethod(ProcessFilesMethod processMethod, bool applyToAll);
  62. bool ProcessFileMethod(ProcessFilesMethod processMethod, QString relativePath, QString oldAbsolutePath);
  63. void ProcessCopyFiles();
  64. void ProcessMoveFiles();
  65. bool Copy(QString relativePath, QString oldAbsolutePath, QString destinationAbsolutePath);
  66. bool Move(QString relativePath, QString oldAbsolutePath, QString destinationAbsolutePath);
  67. bool Overwrite(QString relativePath, QString oldAbsolutePath, QString destinationAbsolutePath);
  68. bool GetAndCheckAllFilesInFolder(QString path);
  69. void RemoveOldPath(QString oldAbsolutePath, QString oldRelativePath);
  70. void SetDestinationFileWritable(QFile& destinationFile);
  71. QString CreateFileNameWithNumber(int number, QString fileName, int index, QString extension);
  72. QString GenerateAbsolutePath(QString relativePath);
  73. QString GetFileName(QString path);
  74. ImportFilesMethod m_importMethod;
  75. // Key = absolute path, Value = relative path
  76. QMap<QString, QString> m_pathMap;
  77. QString m_destinationRootDirectory;
  78. QFileDialog* m_fileDialog{ nullptr };
  79. QString m_gameRootAbsPath;
  80. QString m_currentAbsolutePath;
  81. QString m_suggestedInitialPath;
  82. };