File indexing completed on 2024-07-14 15:48:18

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 #ifndef PLASMA_NM_VPN_UI_PLUGIN_H
0009 #define PLASMA_NM_VPN_UI_PLUGIN_H
0010 
0011 #include <QMessageBox>
0012 #include <QObject>
0013 #include <QVariant>
0014 
0015 #include <NetworkManagerQt/ConnectionSettings>
0016 #include <NetworkManagerQt/GenericTypes>
0017 #include <NetworkManagerQt/VpnSetting>
0018 
0019 #include <KPluginFactory>
0020 
0021 #include "settingwidget.h"
0022 
0023 #include "nm-connection.h"
0024 
0025 /**
0026  * Plugin for UI elements for VPN configuration
0027  */
0028 class Q_DECL_EXPORT VpnUiPlugin : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     enum ErrorType { NoError, NotImplemented, Error };
0033 
0034     explicit VpnUiPlugin(QObject *parent = nullptr, const QVariantList & = QVariantList());
0035     ~VpnUiPlugin() override;
0036 
0037     virtual SettingWidget *widget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent) = 0;
0038     virtual SettingWidget *askUser(const NetworkManager::VpnSetting::Ptr &setting, const QStringList &hints, QWidget *parent) = 0;
0039 
0040     /**
0041      * Suggested file name to save the exported connection configuration.
0042      * Try not to use space, parenthesis, or any other Unix unfriendly file name character.
0043      */
0044     virtual QString suggestedFileName(const NetworkManager::ConnectionSettings::Ptr &connection) const = 0;
0045     /**
0046      * File extension to be used in QFileDialog when selecting the file to import.
0047      * The format is: *.<extension> [*.<extension> ...]. For instance: '*.pcf'
0048      */
0049     virtual QStringList supportedFileExtensions() const;
0050 
0051     struct ImportResult {
0052     private:
0053         NMConnection *m_connection;
0054         ErrorType m_error = NoError;
0055         QString m_errorMessage;
0056 
0057     public:
0058         operator bool() const;
0059 
0060         QString errorMessage() const;
0061 
0062         NMConnection *connection() const;
0063 
0064         static ImportResult fail(const QString &errorMessage);
0065 
0066         static ImportResult pass(NMConnection *connection);
0067 
0068         static ImportResult notImplemented();
0069     };
0070 
0071     virtual ImportResult importConnectionSettings(const QString &fileName);
0072 
0073     struct ExportResult {
0074     private:
0075         ErrorType m_error = NoError;
0076         QString m_errorMessage;
0077 
0078     public:
0079         operator bool() const;
0080 
0081         QString errorMessage() const;
0082 
0083         static ExportResult pass();
0084 
0085         static ExportResult fail(const QString &errorMessage);
0086 
0087         static ExportResult notImplemented();
0088     };
0089 
0090     virtual ExportResult exportConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connection, const QString &fileName);
0091 
0092     virtual QMessageBox::StandardButtons suggestedAuthDialogButtons() const;
0093 
0094     static KPluginFactory::Result<VpnUiPlugin> loadPluginForType(QObject *parent, const QString &serviceType);
0095 };
0096 
0097 #endif // PLASMA_NM_VPN_UI_PLUGIN_H