Qt: Fix message dialog progress bars never reaching 100%

and clean up a bit
This commit is contained in:
Megamouse 2018-06-04 10:21:44 +02:00 committed by kd-11
parent da9affb348
commit 38e88253cc
2 changed files with 15 additions and 14 deletions

View File

@ -39,6 +39,7 @@ void msg_dialog_frame::Create(const std::string& msg)
text = new QLabel("", m_dialog); text = new QLabel("", m_dialog);
bar = new QProgressBar(m_dialog); bar = new QProgressBar(m_dialog);
bar->setRange(0, m_gauge_max); bar->setRange(0, m_gauge_max);
bar->setValue(0);
bar->setFixedWidth(barWidth()); bar->setFixedWidth(barWidth());
bar->setAlignment(Qt::AlignCenter); bar->setAlignment(Qt::AlignCenter);
@ -66,7 +67,7 @@ void msg_dialog_frame::Create(const std::string& msg)
m_tb_progress->setVisible(true); m_tb_progress->setVisible(true);
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
UpdateProgress(0); UpdateProgress(0);
progressValue = new int(0); progressValue = 0;
#endif #endif
} }
@ -321,12 +322,9 @@ msg_dialog_frame::~msg_dialog_frame()
m_tb_button->deleteLater(); m_tb_button->deleteLater();
} }
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
if (progressValue) UpdateProgress(0, false);
{
UpdateProgress(0, false);
delete progressValue;
}
#endif #endif
if (m_dialog) if (m_dialog)
{ {
m_dialog->deleteLater(); m_dialog->deleteLater();
@ -358,7 +356,7 @@ void msg_dialog_frame::ProgressBarReset(u32 index)
{ {
if (index == 0 && m_gauge1) if (index == 0 && m_gauge1)
{ {
m_gauge1->reset(); m_gauge1->setValue(0);
#ifdef _WIN32 #ifdef _WIN32
m_tb_progress->reset(); m_tb_progress->reset();
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
@ -368,7 +366,7 @@ void msg_dialog_frame::ProgressBarReset(u32 index)
if (index == 1 && m_gauge2) if (index == 1 && m_gauge2)
{ {
m_gauge2->reset(); m_gauge2->setValue(0);
} }
} }
@ -382,8 +380,8 @@ void msg_dialog_frame::ProgressBarInc(u32 index, u32 delta)
#ifdef _WIN32 #ifdef _WIN32
m_tb_progress->setValue(m_tb_progress->value() + delta); m_tb_progress->setValue(m_tb_progress->value() + delta);
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
*progressValue += delta; progressValue += delta;
UpdateProgress(*progressValue); UpdateProgress(progressValue);
#endif #endif
} }
@ -413,9 +411,12 @@ void msg_dialog_frame::ProgressBarSetLimit(u32 index, u32 limit)
#ifdef HAVE_QTDBUS #ifdef HAVE_QTDBUS
void msg_dialog_frame::UpdateProgress(int progress, bool disable) void msg_dialog_frame::UpdateProgress(int progress, bool disable)
{ {
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/"), QDBusMessage message = QDBusMessage::createSignal
QStringLiteral("com.canonical.Unity.LauncherEntry"), (
QStringLiteral("Update")); QStringLiteral("/"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update")
);
QVariantMap properties; QVariantMap properties;
if (disable) if (disable)
properties.insert(QStringLiteral("progress-visible"), false); properties.insert(QStringLiteral("progress-visible"), false);

View File

@ -39,7 +39,7 @@ class msg_dialog_frame : public QObject, public MsgDialogBase
QWinTaskbarProgress* m_tb_progress = nullptr; QWinTaskbarProgress* m_tb_progress = nullptr;
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
int* progressValue = nullptr; int progressValue = 0;
#endif #endif
custom_dialog* m_dialog =nullptr; custom_dialog* m_dialog =nullptr;
QLabel* m_text = nullptr; QLabel* m_text = nullptr;