File indexing completed on 2024-04-21 05:36:41
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 <KIO/ApplicationLauncherJob> 0010 #include <KIO/JobUiDelegateFactory> 0011 #include <QDebug> 0012 0013 ExternalAppModule::ExternalAppModule(const KService::Ptr &service) 0014 : moduleService(service) 0015 { 0016 firstShow = true; 0017 externalModule.setupUi(this); 0018 QString moduleName = moduleService->name(); 0019 if (moduleName.isEmpty()) { 0020 moduleName = moduleService->property<QString>(QStringLiteral("X-KDE-PluginInfo-Name")); 0021 if (!moduleName.isEmpty()) { 0022 qWarning() << "Reading deprecated X-KDE-PluginInfo-Name property from ExternalAppModule, use Name property instead"; 0023 } 0024 } 0025 externalModule.LblText->setText(i18n("%1 is an external application and has been automatically launched", moduleName)); 0026 externalModule.PbRelaunch->setText(i18n("Relaunch %1", moduleName)); 0027 connect(externalModule.PbRelaunch, &QPushButton::clicked, this, &ExternalAppModule::runExternal); 0028 } 0029 0030 ExternalAppModule::~ExternalAppModule() 0031 { 0032 } 0033 0034 void ExternalAppModule::showEvent(QShowEvent *event) 0035 { 0036 if (firstShow) { 0037 runExternal(); 0038 firstShow = false; 0039 } 0040 QWidget::showEvent(event); 0041 } 0042 0043 void ExternalAppModule::runExternal() 0044 { 0045 auto job = new KIO::ApplicationLauncherJob(moduleService); 0046 job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); 0047 job->start(); 0048 } 0049 0050 #include "moc_ExternalAppModule.cpp"