|
1 | 1 | #include "updateinfodialog.h" |
2 | 2 | #include "ui_updateinfodialog.h" |
3 | 3 | #include <QGuiApplication> |
4 | | -#include <QScreen> |
| 4 | +#include <QMessageBox> |
5 | 5 | #include "messagemaster.h" |
6 | 6 | using namespace QtAutoUpdater; |
7 | 7 |
|
@@ -44,28 +44,79 @@ UpdateInfoDialog::~UpdateInfoDialog() |
44 | 44 | delete ui; |
45 | 45 | } |
46 | 46 |
|
47 | | -UpdateInfoDialog::DialogResult UpdateInfoDialog::showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable, QWidget *parent) |
| 47 | +UpdateInfoDialog::DialogResult UpdateInfoDialog::showUpdateInfo(QList<Updater::UpdateInfo> updates, bool &runAsAdmin, bool editable, bool detailed, QWidget *parent) |
48 | 48 | { |
49 | | - UpdateInfoDialog dialog(parent); |
50 | | - |
51 | | - for(Updater::UpdateInfo info : updates) { |
52 | | - QTreeWidgetItem *item = new QTreeWidgetItem(dialog.ui->updateListTreeWidget); |
53 | | - item->setText(0, info.name); |
54 | | - item->setText(1, info.version.toString()); |
55 | | - item->setText(2, getByteText(info.size)); |
56 | | - item->setToolTip(2, tr("%L1 Bytes").arg(info.size)); |
57 | | - } |
58 | | - dialog.ui->updateListTreeWidget->resizeColumnToContents(0); |
59 | | - dialog.ui->updateListTreeWidget->resizeColumnToContents(1); |
60 | | - dialog.ui->updateListTreeWidget->resizeColumnToContents(2); |
| 49 | + if(!detailed) { |
| 50 | + QMessageBox mBox(parent); |
| 51 | + mBox.setWindowModality(parent ? Qt::WindowModal : Qt::ApplicationModal);//TODO master dialog |
| 52 | + mBox.setWindowFlags(mBox.windowFlags() & ~Qt::WindowContextHelpButtonHint); |
| 53 | + mBox.setIcon(QMessageBox::Information); |
| 54 | + mBox.setWindowTitle(tr("Check for Updates")); |
| 55 | + mBox.setWindowIcon(QIcon(QStringLiteral(":/updaterIcons/update.ico"))); |
| 56 | + mBox.setText(QStringLiteral("<b>") + |
| 57 | + tr("Updates for %1 are available!") |
| 58 | + .arg(QGuiApplication::applicationDisplayName()) + |
| 59 | + QStringLiteral("</b>")); |
| 60 | + mBox.setInformativeText(tr("There are new updates available! You can install them now or later.")); |
| 61 | + QStringList details; |
| 62 | + for(Updater::UpdateInfo info : updates) { |
| 63 | + details << tr("%1 v%2 — %3") |
| 64 | + .arg(info.name) |
| 65 | + .arg(info.version.toString()) |
| 66 | + .arg(getByteText(info.size)); |
| 67 | + } |
| 68 | + mBox.setDetailedText(details.join(QLatin1Char('\n'))); |
| 69 | + |
| 70 | + QCheckBox *cBox = new QCheckBox(tr("Run with &elevated rights"), &mBox); |
| 71 | + cBox->setEnabled(editable); |
| 72 | + cBox->setChecked(runAsAdmin); |
| 73 | + mBox.setCheckBox(cBox); |
| 74 | + |
| 75 | + mBox.setDefaultButton(mBox.addButton(tr("Install Now"), QMessageBox::AcceptRole)); |
| 76 | + mBox.addButton(tr("Install On Exit"), QMessageBox::ActionRole); |
| 77 | + mBox.setEscapeButton(mBox.addButton(tr("Install later"), QMessageBox::RejectRole)); |
| 78 | + |
| 79 | + DialogResult res; |
| 80 | + mBox.exec(); |
| 81 | + switch (mBox.buttonRole(mBox.clickedButton())) { |
| 82 | + case QMessageBox::AcceptRole: |
| 83 | + res = InstallNow; |
| 84 | + break; |
| 85 | + case QMessageBox::ActionRole: |
| 86 | + res = InstallLater; |
| 87 | + break; |
| 88 | + case QMessageBox::RejectRole: |
| 89 | + res = NoInstall; |
| 90 | + break; |
| 91 | + default: |
| 92 | + Q_UNREACHABLE(); |
| 93 | + } |
61 | 94 |
|
62 | | - dialog.ui->runAdminCheckBox->setEnabled(editable); |
63 | | - dialog.ui->runAdminCheckBox->setChecked(runAsAdmin); |
| 95 | + if(editable && res != NoInstall) |
| 96 | + runAsAdmin = cBox->isChecked(); |
| 97 | + return res; |
| 98 | + } else { |
| 99 | + UpdateInfoDialog dialog(parent); |
64 | 100 |
|
65 | | - DialogResult res = (DialogResult)dialog.exec(); |
66 | | - if(editable && res != NoInstall) |
67 | | - runAsAdmin = dialog.ui->runAdminCheckBox->isChecked(); |
68 | | - return res; |
| 101 | + for(Updater::UpdateInfo info : updates) { |
| 102 | + QTreeWidgetItem *item = new QTreeWidgetItem(dialog.ui->updateListTreeWidget); |
| 103 | + item->setText(0, info.name); |
| 104 | + item->setText(1, info.version.toString()); |
| 105 | + item->setText(2, getByteText(info.size)); |
| 106 | + item->setToolTip(2, tr("%L1 Bytes").arg(info.size)); |
| 107 | + } |
| 108 | + dialog.ui->updateListTreeWidget->resizeColumnToContents(0); |
| 109 | + dialog.ui->updateListTreeWidget->resizeColumnToContents(1); |
| 110 | + dialog.ui->updateListTreeWidget->resizeColumnToContents(2); |
| 111 | + |
| 112 | + dialog.ui->runAdminCheckBox->setEnabled(editable); |
| 113 | + dialog.ui->runAdminCheckBox->setChecked(runAsAdmin); |
| 114 | + |
| 115 | + DialogResult res = (DialogResult)dialog.exec(); |
| 116 | + if(editable && res != NoInstall) |
| 117 | + runAsAdmin = dialog.ui->runAdminCheckBox->isChecked(); |
| 118 | + return res; |
| 119 | + } |
69 | 120 | } |
70 | 121 |
|
71 | 122 | void QtAutoUpdater::UpdateInfoDialog::on_acceptButton_clicked() |
|
0 commit comments