File indexing completed on 2024-03-24 17:13:58

0001 /*
0002  *   SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "ExternalAppModule.h"
0008 
0009 #include <KCModuleInfo>
0010 #include <KIO/ApplicationLauncherJob>
0011 #include <KIO/JobUiDelegateFactory>
0012 
0013 ExternalAppModule::ExternalAppModule(QWidget *parent, const KService::Ptr &module)
0014     : module(module)
0015 {
0016     Q_UNUSED(parent)
0017 
0018     firstShow = true;
0019     externalModule.setupUi(this);
0020     QString moduleName = module->name();
0021     if (moduleName.isEmpty()) {
0022         moduleName = module->property(QStringLiteral("X-KDE-PluginInfo-Name"), QMetaType::QString).toString();
0023         if (!moduleName.isEmpty()) {
0024             qWarning() << "Reading deprecated X-KDE-PluginInfo-Name property from ExternalAppModule, use Name property instead";
0025         }
0026     }
0027     externalModule.LblText->setText(i18n("%1 is an external application and has been automatically launched", moduleName));
0028     externalModule.PbRelaunch->setText(i18n("Relaunch %1", moduleName));
0029     connect(externalModule.PbRelaunch, &QPushButton::clicked, this, &ExternalAppModule::runExternal);
0030 }
0031 
0032 ExternalAppModule::~ExternalAppModule()
0033 {
0034 }
0035 
0036 void ExternalAppModule::showEvent(QShowEvent *event)
0037 {
0038     if (firstShow) {
0039         runExternal();
0040         firstShow = false;
0041     }
0042     QWidget::showEvent(event);
0043 }
0044 
0045 void ExternalAppModule::runExternal()
0046 {
0047     KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(module);
0048     job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
0049     job->start();
0050 }