1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 #pragma once
26 
27 #include "itemlibraryassetimporter.h"
28 #include "modelnode.h"
29 
30 #include <QDialog>
31 #include <QJsonObject>
32 #include <QSet>
33 
34 namespace Utils {
35 class OutputFormatter;
36 }
37 
38 namespace QmlDesigner {
39 class ItemLibraryAssetImporter;
40 
41 namespace Ui {
42 class ItemLibraryAssetImportDialog;
43 }
44 
45 class ItemLibraryAssetImportDialog : public QDialog
46 {
47     Q_OBJECT
48 
49 public:
50     explicit ItemLibraryAssetImportDialog(const QStringList &importFiles,
51                                           const QString &defaulTargetDirectory,
52                                           const QVariantMap &supportedExts,
53                                           const QVariantMap &supportedOpts,
54                                           const QJsonObject &defaultOpts,
55                                           const QSet<QString> &preselectedFilesForOverwrite,
56                                           QWidget *parent = nullptr);
57     ~ItemLibraryAssetImportDialog();
58 
59     static void updateImport(const ModelNode &updateNode,
60                              const QVariantMap &supportedExts,
61                              const QVariantMap &supportedOpts);
62 
63 protected:
64     void resizeEvent(QResizeEvent *event) override;
65 
66 private slots:
67     void addError(const QString &error, const QString &srcPath = {});
68     void addWarning(const QString &warning, const QString &srcPath = {});
69     void addInfo(const QString &info, const QString &srcPath = {});
70 
71 private:
72     void setCloseButtonState(bool importing);
73 
74     void onImport();
75     void setImportProgress(int value, const QString &text);
76     void onImportNearlyFinished();
77     void onImportFinished();
78     void onClose();
79 
80     void createTab(const QString &tabLabel, int optionsIndex, const QJsonObject &groups);
81     void updateUi();
82 
83     Ui::ItemLibraryAssetImportDialog *ui = nullptr;
84     Utils::OutputFormatter *m_outputFormatter = nullptr;
85 
86     QStringList m_quick3DFiles;
87     QString m_quick3DImportPath;
88     ItemLibraryAssetImporter m_importer;
89     QVector<QJsonObject> m_importOptions;
90     QHash<QString, int> m_extToImportOptionsMap;
91     int m_optionsHeight = 0;
92     int m_optionsRows = 0;
93     QSet<QString> m_preselectedFilesForOverwrite;
94 };
95 }
96