2020-12-05 13:08:24 +01:00
|
|
|
#include "progress_dialog.h"
|
2017-11-25 14:01:35 +01:00
|
|
|
|
2021-09-29 21:47:04 +02:00
|
|
|
#include <QApplication>
|
2019-01-06 22:32:23 +01:00
|
|
|
#include <QLabel>
|
|
|
|
|
|
2020-02-22 20:42:49 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <QWinTHumbnailToolbutton>
|
|
|
|
|
#elif HAVE_QTDBUS
|
|
|
|
|
#include <QtDBus/QDBusMessage>
|
|
|
|
|
#include <QtDBus/QDBusConnection>
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-29 21:28:51 +02:00
|
|
|
progress_dialog::progress_dialog(const QString& windowTitle, const QString& labelText, const QString& cancelButtonText, int minimum, int maximum, bool delete_on_close, 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);
|
2020-11-19 20:18:50 +01:00
|
|
|
setMinimumSize(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width(), sizeHint().height());
|
2019-09-11 09:55:43 +02:00
|
|
|
setValue(0);
|
2019-01-06 22:32:23 +01:00
|
|
|
setWindowModality(Qt::WindowModal);
|
2020-01-07 22:44:23 +01:00
|
|
|
|
|
|
|
|
if (delete_on_close)
|
|
|
|
|
{
|
|
|
|
|
connect(this, &QProgressDialog::canceled, this, &QProgressDialog::deleteLater);
|
|
|
|
|
}
|
2019-01-06 22:32:23 +01:00
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
#ifdef _WIN32
|
2021-09-29 21:28:51 +02:00
|
|
|
// Try to find a window handle first
|
|
|
|
|
QWindow* handle = windowHandle();
|
|
|
|
|
|
|
|
|
|
for (QWidget* ancestor = this; !handle && ancestor;)
|
|
|
|
|
{
|
|
|
|
|
if (ancestor = static_cast<QWidget*>(ancestor->parent()))
|
|
|
|
|
{
|
|
|
|
|
handle = ancestor->windowHandle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
m_tb_button = std::make_unique<QWinTaskbarButton>();
|
2021-09-29 21:28:51 +02:00
|
|
|
m_tb_button->setWindow(handle);
|
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);
|
2021-09-29 21:28:51 +02:00
|
|
|
m_tb_progress->show();
|
2017-11-25 14:01:35 +01:00
|
|
|
#elif HAVE_QTDBUS
|
2021-09-26 00:51:18 +02:00
|
|
|
UpdateProgress(0, true);
|
2017-11-25 14:01:35 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progress_dialog::~progress_dialog()
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
2020-07-01 20:46:49 +02:00
|
|
|
// QWinTaskbarProgress::hide() will crash if the application is already about to close, even if the object is not null.
|
|
|
|
|
if (!QCoreApplication::closingDown())
|
|
|
|
|
{
|
|
|
|
|
m_tb_progress->hide();
|
|
|
|
|
}
|
2017-11-25 14:01:35 +01:00
|
|
|
#elif HAVE_QTDBUS
|
2021-09-26 00:58:27 +02:00
|
|
|
QDBusMessage message = QDBusMessage::createSignal(
|
|
|
|
|
QStringLiteral("/"),
|
|
|
|
|
QStringLiteral("com.canonical.Unity.LauncherEntry"),
|
|
|
|
|
QStringLiteral("Update"));
|
|
|
|
|
QVariantMap properties;
|
|
|
|
|
properties.insert(QStringLiteral("urgent"), false);
|
|
|
|
|
properties.insert(QStringLiteral("progress"), 0);
|
2021-09-26 00:51:18 +02:00
|
|
|
properties.insert(QStringLiteral("progress-visible"), false);
|
2021-09-26 00:58:27 +02:00
|
|
|
message << QStringLiteral("application://rpcs3.desktop") << properties;
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
2017-11-25 14:01:35 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 21:28:51 +02:00
|
|
|
void progress_dialog::SetRange(int min, int max)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
m_tb_progress->setRange(min, max);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
QProgressDialog::setRange(min, max);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
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
|
2021-09-26 00:51:18 +02:00
|
|
|
UpdateProgress(value, true);
|
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
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
void progress_dialog::SignalFailure() const
|
2019-10-05 17:22:40 +02:00
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
m_tb_progress->stop();
|
2021-09-26 00:58:27 +02:00
|
|
|
#elif HAVE_QTDBUS
|
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(
|
|
|
|
|
QStringLiteral("/"),
|
|
|
|
|
QStringLiteral("com.canonical.Unity.LauncherEntry"),
|
|
|
|
|
QStringLiteral("Update"));
|
|
|
|
|
QVariantMap properties;
|
|
|
|
|
properties.insert(QStringLiteral("urgent"), true);
|
|
|
|
|
message << QStringLiteral("application://rpcs3.desktop") << properties;
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
2019-10-05 17:22:40 +02:00
|
|
|
#endif
|
2021-09-29 21:47:04 +02:00
|
|
|
|
|
|
|
|
QApplication::beep();
|
2019-10-05 17:22:40 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
#ifdef HAVE_QTDBUS
|
2021-09-26 00:51:18 +02:00
|
|
|
void progress_dialog::UpdateProgress(int progress, bool progress_visible)
|
2017-11-25 14:01:35 +01:00
|
|
|
{
|
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(
|
|
|
|
|
QStringLiteral("/"),
|
|
|
|
|
QStringLiteral("com.canonical.Unity.LauncherEntry"),
|
|
|
|
|
QStringLiteral("Update"));
|
|
|
|
|
QVariantMap properties;
|
2021-09-26 00:51:18 +02:00
|
|
|
// Progress takes a value from 0.0 to 0.1
|
2019-12-04 21:56:19 +01:00
|
|
|
properties.insert(QStringLiteral("progress"), 1. * progress / maximum());
|
2021-09-26 00:51:18 +02:00
|
|
|
properties.insert(QStringLiteral("progress-visible"), progress_visible);
|
2017-11-25 14:01:35 +01:00
|
|
|
message << QStringLiteral("application://rpcs3.desktop") << properties;
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
|
}
|
|
|
|
|
#endif
|