Install: Use QMessageBox as fallback

Use a QMessageBox if the InfoBar would be hidden.

Change-Id: I29f10a3af6123dcf7811db68b967259f990c5a66
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-30 09:57:40 +02:00
parent 7944ae0600
commit 1058f12a93

View File

@@ -17,8 +17,10 @@
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <utils/unarchiver.h> #include <utils/unarchiver.h>
#include <QApplication>
#include <QJsonDocument> #include <QJsonDocument>
#include <QLabel> #include <QLabel>
#include <QMessageBox>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QtConcurrent> #include <QtConcurrent>
@@ -301,41 +303,71 @@ void addInstallModule()
installOptionsList.append({url, name, version}); installOptionsList.append({url, name, version});
} }
auto install = [&state, pluginSpec, installOptionsList, callback]() {
auto tree = state.createTree();
auto progress = new TaskProgress(tree);
progress->setDisplayName(Tr::tr("Installing package(s) %1").arg("..."));
tree->setRecipe(
installRecipe(pluginSpec->appDataPath, installOptionsList, callback));
tree->start();
};
auto denied = [callback]() { callback(false, "User denied installation"); };
if (QApplication::activeModalWidget()) {
auto msgBox = new QMessageBox(
QMessageBox::Question,
Tr::tr("Install package"),
msg,
QMessageBox::Yes | QMessageBox::No,
Core::ICore::dialogParent());
const QString details
= Tr::tr("The plugin \"%1\" would like to install the following "
"package(s):\n\n")
.arg(pluginSpec->name)
+ Utils::transform(installOptionsList, [](const InstallOptions &options) {
return QString("* %1 - %2 (from: %3)")
.arg(options.name, options.version, options.url.toString());
}).join("\n");
msgBox->setDetailedText(details);
auto guard = pluginSpec->connectionGuard.get();
QObject::connect(msgBox, &QMessageBox::accepted, guard, install);
QObject::connect(msgBox, &QMessageBox::rejected, guard, denied);
msgBox->show();
return;
}
const Utils::Id infoBarId = Utils::Id::fromString( const Utils::Id infoBarId = Utils::Id::fromString(
"Install" + pluginSpec->name + QString::number(qHash(installOptionsList))); "Install" + pluginSpec->name + QString::number(qHash(installOptionsList)));
InfoBarEntry entry(infoBarId, msg, InfoBarEntry::GlobalSuppression::Enabled); InfoBarEntry entry(infoBarId, msg, InfoBarEntry::GlobalSuppression::Enabled);
entry.addCustomButton( entry.addCustomButton(Tr::tr("Install"), [install, infoBarId]() {
Tr::tr("Install"), install();
[infoBarId, &state, pluginSpec, installOptionsList, callback]() { Core::ICore::infoBar()->removeInfo(infoBarId);
auto tree = state.createTree(); });
auto progress = new TaskProgress(tree); entry.setCancelButtonInfo(denied);
progress->setDisplayName(Tr::tr("Installing package(s) %1").arg("..."));
tree->setRecipe( const QString details
installRecipe(pluginSpec->appDataPath, installOptionsList, callback)); = Tr::tr("The plugin \"**%1**\" would like to install the following "
tree->start(); "package(s):\n\n")
.arg(pluginSpec->name)
Core::ICore::infoBar()->removeInfo(infoBarId); + Utils::transform(installOptionsList, [](const InstallOptions &options) {
}); return QString("* %1 - %2 (from: [%3](%3))")
entry.setCancelButtonInfo( .arg(options.name, options.version, options.url.toString());
[callback]() { callback(false, "User denied installation"); }); }).join("\n");
entry.setDetailsWidgetCreator([pluginSpec, installOptionsList]() -> QWidget * {
const QString markdown
= Tr::tr("The plugin \"**%1**\" would like to install the following "
"package(s):\n\n")
.arg(pluginSpec->name)
+ Utils::transform(installOptionsList, [](const InstallOptions &options) {
return QString("* %1 - %2 (from: [%3](%3))")
.arg(options.name, options.version, options.url.toString());
}).join("\n");
entry.setDetailsWidgetCreator([details]() -> QWidget * {
QLabel *list = new QLabel(); QLabel *list = new QLabel();
list->setTextFormat(Qt::TextFormat::MarkdownText); list->setTextFormat(Qt::TextFormat::MarkdownText);
list->setText(markdown); list->setText(details);
list->setMargin(StyleHelper::SpacingTokens::ExPaddingGapS); list->setMargin(StyleHelper::SpacingTokens::ExPaddingGapS);
return list; return list;
}); });