File indexing completed on 2024-12-08 08:02:36

0001 /*
0002     SPDX-FileCopyrightText: 2008 Will Stephenson <wstephenson@kde.org>
0003     SPDX-FileCopyrightText: 2013 Lukáš Tinkl <ltinkl@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "vpnuiplugin.h"
0009 
0010 #include <KLocalizedString>
0011 #include <KPluginMetaData>
0012 
0013 VpnUiPlugin::VpnUiPlugin(QObject *parent, const QVariantList & /*args*/)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 VpnUiPlugin::~VpnUiPlugin() = default;
0019 
0020 QMessageBox::StandardButtons VpnUiPlugin::suggestedAuthDialogButtons() const
0021 {
0022     return QMessageBox::Ok | QMessageBox::Cancel;
0023 }
0024 
0025 QStringList VpnUiPlugin::supportedFileExtensions() const
0026 {
0027     return {};
0028 }
0029 
0030 KPluginFactory::Result<VpnUiPlugin> VpnUiPlugin::loadPluginForType(QObject *parent, const QString &serviceType)
0031 {
0032     auto filter = [serviceType](const KPluginMetaData &md) {
0033         return md.value(QStringLiteral("X-NetworkManager-Services")) == serviceType;
0034     };
0035 
0036     const QList<KPluginMetaData> offers = KPluginMetaData::findPlugins(QStringLiteral("plasma/network/vpn"), filter);
0037 
0038     if (offers.isEmpty()) {
0039         KPluginFactory::Result<VpnUiPlugin> result;
0040         result.errorReason = KPluginFactory::INVALID_PLUGIN;
0041         result.errorText = QStringLiteral("No VPN plugin found for type %1").arg(serviceType);
0042         result.errorString = i18n("No VPN plugin found for type %1", serviceType);
0043 
0044         return result;
0045     }
0046 
0047     return KPluginFactory::instantiatePlugin<VpnUiPlugin>(offers.first(), parent);
0048 }
0049 
0050 VpnUiPlugin::ImportResult VpnUiPlugin::importConnectionSettings(const QString &fileName)
0051 {
0052     Q_UNUSED(fileName);
0053     return VpnUiPlugin::ImportResult::notImplemented();
0054 }
0055 
0056 VpnUiPlugin::ExportResult VpnUiPlugin::exportConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connection, const QString &fileName)
0057 {
0058     Q_UNUSED(connection);
0059     Q_UNUSED(fileName);
0060     return VpnUiPlugin::ExportResult::notImplemented();
0061 }
0062 
0063 VpnUiPlugin::ImportResult::operator bool() const
0064 {
0065     return m_error == NoError;
0066 }
0067 
0068 QString VpnUiPlugin::ImportResult::errorMessage() const
0069 {
0070     return m_errorMessage;
0071 }
0072 
0073 NMConnection *VpnUiPlugin::ImportResult::connection() const
0074 {
0075     return m_connection;
0076 }
0077 
0078 VpnUiPlugin::ImportResult VpnUiPlugin::ImportResult::fail(const QString &errorMessage)
0079 {
0080     ImportResult result;
0081     result.m_error = Error;
0082     result.m_errorMessage = errorMessage;
0083 
0084     return result;
0085 }
0086 
0087 VpnUiPlugin::ImportResult VpnUiPlugin::ImportResult::pass(NMConnection *connection)
0088 {
0089     ImportResult result;
0090     result.m_connection = connection;
0091 
0092     return result;
0093 }
0094 
0095 VpnUiPlugin::ImportResult VpnUiPlugin::ImportResult::notImplemented()
0096 {
0097     VpnUiPlugin::ImportResult result;
0098     result.m_error = NotImplemented;
0099     result.m_errorMessage = i18n("Importing this type of VPN is not implemented");
0100 
0101     return result;
0102 }
0103 
0104 VpnUiPlugin::ExportResult::operator bool() const
0105 {
0106     return m_error == NoError;
0107 }
0108 
0109 QString VpnUiPlugin::ExportResult::errorMessage() const
0110 {
0111     return m_errorMessage;
0112 }
0113 
0114 VpnUiPlugin::ExportResult VpnUiPlugin::ExportResult::pass()
0115 {
0116     return ExportResult();
0117 }
0118 
0119 VpnUiPlugin::ExportResult VpnUiPlugin::ExportResult::notImplemented()
0120 {
0121     ExportResult result;
0122     result.m_error = NotImplemented;
0123     result.m_errorMessage = i18n("Not implemented");
0124 
0125     return result;
0126 }
0127 
0128 VpnUiPlugin::ExportResult VpnUiPlugin::ExportResult::fail(const QString &errorMessage)
0129 {
0130     ExportResult result;
0131     result.m_error = Error;
0132     result.m_errorMessage = errorMessage;
0133 
0134     return result;
0135 }
0136 
0137 #include "moc_vpnuiplugin.cpp"