2019-01-06 23:30:38 +01:00
|
|
|
|
#include "progress_dialog.h"
|
2017-11-25 14:01:35 +01:00
|
|
|
|
|
2019-01-06 22:32:23 +01:00
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
2019-09-11 09:55:43 +02:00
|
|
|
|
progress_dialog::progress_dialog(const QString &windowTitle, const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent, Qt::WindowFlags flags)
|
2018-06-09 16:27:56 +02:00
|
|
|
|
: QProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, flags)
|
2017-11-25 14:01:35 +01:00
|
|
|
|
{
|
2019-09-11 09:55:43 +02:00
|
|
|
|
setWindowTitle(windowTitle);
|
2019-01-06 22:32:23 +01:00
|
|
|
|
setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width());
|
2019-09-11 09:55:43 +02:00
|
|
|
|
setValue(0);
|
2019-01-06 22:32:23 +01:00
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
connect(this, &QProgressDialog::canceled, this, &QProgressDialog::deleteLater);
|
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
m_tb_button = std::make_unique<QWinTaskbarButton>();
|
2018-06-16 16:34:55 +02:00
|
|
|
|
m_tb_button->setWindow(parent ? parent->windowHandle() : windowHandle());
|
2017-11-25 14:01:35 +01:00
|
|
|
|
m_tb_progress = m_tb_button->progress();
|
2018-06-09 16:27:56 +02:00
|
|
|
|
m_tb_progress->setRange(minimum, maximum);
|
2017-11-25 14:01:35 +01:00
|
|
|
|
m_tb_progress->setVisible(true);
|
|
|
|
|
|
#elif HAVE_QTDBUS
|
|
|
|
|
|
UpdateProgress(0);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
progress_dialog::~progress_dialog()
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
m_tb_progress->hide();
|
|
|
|
|
|
#elif HAVE_QTDBUS
|
|
|
|
|
|
UpdateProgress(0);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void progress_dialog::SetValue(int progress)
|
|
|
|
|
|
{
|
2018-06-09 16:27:56 +02:00
|
|
|
|
const int value = std::clamp(progress, minimum(), maximum());
|
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
|
#ifdef _WIN32
|
2018-06-09 16:27:56 +02:00
|
|
|
|
m_tb_progress->setValue(value);
|
2017-11-25 14:01:35 +01:00
|
|
|
|
#elif HAVE_QTDBUS
|
2018-06-09 16:27:56 +02:00
|
|
|
|
UpdateProgress(value);
|
2017-11-25 14:01:35 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2018-06-09 16:27:56 +02:00
|
|
|
|
QProgressDialog::setValue(value);
|
2017-11-25 14:01:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_QTDBUS
|
|
|
|
|
|
void progress_dialog::UpdateProgress(int progress, bool disable)
|
|
|
|
|
|
{
|
|
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(
|
|
|
|
|
|
QStringLiteral("/"),
|
|
|
|
|
|
QStringLiteral("com.canonical.Unity.LauncherEntry"),
|
|
|
|
|
|
QStringLiteral("Update"));
|
|
|
|
|
|
QVariantMap properties;
|
|
|
|
|
|
if (disable)
|
|
|
|
|
|
properties.insert(QStringLiteral("progress-visible"), false);
|
|
|
|
|
|
else
|
|
|
|
|
|
properties.insert(QStringLiteral("progress-visible"), true);
|
|
|
|
|
|
//Progress takes a value from 0.0 to 0.1
|
2018-06-09 16:27:56 +02:00
|
|
|
|
properties.insert(QStringLiteral("progress"), (double)progress / (double)maximum());
|
2017-11-25 14:01:35 +01:00
|
|
|
|
message << QStringLiteral("application://rpcs3.desktop") << properties;
|
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|