1 /* Copyright 2013-2019 MultiMC Contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <QDialog>
19 #include <memory>
20 
21 class Task;
22 
23 namespace Ui
24 {
25 class ProgressDialog;
26 }
27 
28 class ProgressDialog : public QDialog
29 {
30     Q_OBJECT
31 
32 public:
33     explicit ProgressDialog(QWidget *parent = 0);
34     ~ProgressDialog();
35 
36     void updateSize();
37 
38     int execWithTask(Task *task);
39     int execWithTask(std::unique_ptr<Task> &&task);
40     int execWithTask(std::unique_ptr<Task> &task);
41 
42     void setSkipButton(bool present, QString label = QString());
43 
44     Task *getTask();
45 
46 public
47 slots:
48     void onTaskStarted();
49     void onTaskFailed(QString failure);
50     void onTaskSucceeded();
51 
52     void changeStatus(const QString &status);
53     void changeProgress(qint64 current, qint64 total);
54 
55 
56 private
57 slots:
58     void on_skipButton_clicked(bool checked);
59 
60 protected:
61     virtual void keyPressEvent(QKeyEvent *e);
62     virtual void closeEvent(QCloseEvent *e);
63 
64 private:
65     bool handleImmediateResult(QDialog::DialogCode &result);
66 
67 private:
68     Ui::ProgressDialog *ui;
69 
70     Task *task;
71 };
72