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