UpdateInfo: add action to start maintenance tool

Change-Id: Icb37dc0f5634ccd11aa34aa8dc256bf796301b2f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-09-14 15:34:49 +02:00
parent 24cd57ea45
commit 55b17f8908
3 changed files with 37 additions and 13 deletions

View File

@@ -476,7 +476,9 @@ bool MenuActionContainer::updateInternal()
} }
} else if (auto command = qobject_cast<Command *>(item)) { } else if (auto command = qobject_cast<Command *>(item)) {
actions.removeAll(command->action()); actions.removeAll(command->action());
if (command->isActive()) { if (command->isActive()
&& !(HostOsInfo::isMacHost()
&& command->action()->menuRole() == QAction::ApplicationSpecificRole)) {
hasitems = true; hasitems = true;
break; break;
} }

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "updateinfoplugin.h" #include "updateinfoplugin.h"
#include "updateinfotr.h"
#include "settingspage.h" #include "settingspage.h"
#include "updateinfotools.h" #include "updateinfotools.h"
@@ -47,6 +48,7 @@ const quint32 OneMinute = 60000;
const quint32 OneHour = 3600000; const quint32 OneHour = 3600000;
const char InstallUpdates[] = "UpdateInfo.InstallUpdates"; const char InstallUpdates[] = "UpdateInfo.InstallUpdates";
const char InstallQtUpdates[] = "UpdateInfo.InstallQtUpdates"; const char InstallQtUpdates[] = "UpdateInfo.InstallQtUpdates";
const char M_MAINTENANCE_TOOL[] = "QtCreator.Menu.Tools.MaintenanceTool";
using namespace Core; using namespace Core;
using namespace Utils; using namespace Utils;
@@ -324,12 +326,28 @@ bool UpdateInfoPlugin::initialize(const QStringList & /* arguments */, QString *
(void) new SettingsPage(this); (void) new SettingsPage(this);
auto mtools = ActionManager::actionContainer(Constants::M_TOOLS);
ActionContainer *mmaintenanceTool = ActionManager::createMenu(M_MAINTENANCE_TOOL);
mmaintenanceTool->setOnAllDisabledBehavior(Core::ActionContainer::Hide);
mmaintenanceTool->menu()->setTitle(Tr::tr("Qt Maintenance Tool")); mtools->addMenu(mmaintenanceTool);
QAction *checkForUpdatesAction = new QAction(tr("Check for Updates"), this); QAction *checkForUpdatesAction = new QAction(tr("Check for Updates"), this);
checkForUpdatesAction->setMenuRole(QAction::ApplicationSpecificRole); checkForUpdatesAction->setMenuRole(QAction::ApplicationSpecificRole);
Core::Command *checkForUpdatesCommand = Core::ActionManager::registerAction(checkForUpdatesAction, "Updates.CheckForUpdates"); Core::Command *checkForUpdatesCommand
connect(checkForUpdatesAction, &QAction::triggered, this, &UpdateInfoPlugin::startCheckForUpdates); = Core::ActionManager::registerAction(checkForUpdatesAction, "Updates.CheckForUpdates");
ActionContainer *const helpContainer = ActionManager::actionContainer(Core::Constants::M_HELP); connect(checkForUpdatesAction, &QAction::triggered,
helpContainer->addAction(checkForUpdatesCommand, Constants::G_HELP_UPDATES); this, &UpdateInfoPlugin::startCheckForUpdates);
mmaintenanceTool->addAction(checkForUpdatesCommand);
QAction *startMaintenanceToolAction = new QAction(Tr::tr("Start Maintenance Tool"), this);
startMaintenanceToolAction->setMenuRole(QAction::ApplicationSpecificRole);
Core::Command *startMaintenanceToolCommand
= Core::ActionManager::registerAction(startMaintenanceToolAction,
"Updates.StartMaintenanceTool");
connect(startMaintenanceToolAction, &QAction::triggered, this, [this]() {
startMaintenanceTool({});
});
mmaintenanceTool->addAction(startMaintenanceToolCommand);
return true; return true;
} }
@@ -458,16 +476,19 @@ QDate UpdateInfoPlugin::nextCheckDate(CheckUpdateInterval interval) const
return d->m_lastCheckDate.addMonths(1); return d->m_lastCheckDate.addMonths(1);
} }
void UpdateInfoPlugin::startUpdater() void UpdateInfoPlugin::startMaintenanceTool(const QStringList &args) const
{ {
Utils::QtcProcess::startDetached( QtcProcess::startDetached(CommandLine{FilePath::fromString(d->m_maintenanceTool), args});
{Utils::FilePath::fromString(d->m_maintenanceTool), {"--updater"}});
} }
void UpdateInfoPlugin::startPackageManager() void UpdateInfoPlugin::startUpdater() const
{ {
Utils::QtcProcess::startDetached( startMaintenanceTool({"--updater"});
{Utils::FilePath::fromString(d->m_maintenanceTool), {"--start-package-manager"}}); }
void UpdateInfoPlugin::startPackageManager() const
{
startMaintenanceTool({"--start-package-manager"});
} }
} //namespace Internal } //namespace Internal

View File

@@ -63,8 +63,9 @@ private:
void stopAutoCheckForUpdates(); void stopAutoCheckForUpdates();
void doAutoCheckForUpdates(); void doAutoCheckForUpdates();
void startUpdater(); void startMaintenanceTool(const QStringList &args) const;
void startPackageManager(); void startUpdater() const;
void startPackageManager() const;
void stopCheckForUpdates(); void stopCheckForUpdates();
void checkForUpdatesFinished(); void checkForUpdatesFinished();