File indexing completed on 2024-12-08 13:24:48

0001 /*
0002     SPDX-FileCopyrightText: 2013-2016 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PLASMA_NM_CONNECTION_EDITOR_BASE_H
0008 #define PLASMA_NM_CONNECTION_EDITOR_BASE_H
0009 
0010 #include <QDBusPendingCallWatcher>
0011 #include <QWidget>
0012 
0013 #include <NetworkManagerQt/ConnectionSettings>
0014 
0015 class ConnectionWidget;
0016 class SettingWidget;
0017 class WifiSecurity;
0018 
0019 class Q_DECL_EXPORT ConnectionEditorBase : public QWidget
0020 {
0021     Q_OBJECT
0022 public:
0023     explicit ConnectionEditorBase(const NetworkManager::ConnectionSettings::Ptr &connection, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0024     explicit ConnectionEditorBase(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0025     ~ConnectionEditorBase() override;
0026 
0027     // When reimplementing do not forget to call the base method as well to initialize widgets
0028     virtual void setConnection(const NetworkManager::ConnectionSettings::Ptr &connection);
0029 
0030     NMVariantMapMap setting() const;
0031 
0032     // Returns whether the editor is fully initialized (including secrets)
0033     bool isInitialized() const;
0034 
0035     // Returns whether the filled values are valid
0036     bool isValid() const;
0037 
0038 Q_SIGNALS:
0039     // The default value is supposed to be false, watch this property for validity change after
0040     // proper initialization with secrets
0041     void validityChanged(bool valid);
0042 
0043     // Emitted when user changed configuration
0044     void settingChanged();
0045 
0046 private Q_SLOTS:
0047     void replyFinished(QDBusPendingCallWatcher *watcher);
0048     void validChanged(bool valid);
0049     void onAllUsersChanged();
0050 
0051 protected:
0052     // Subclassed widget is supposed to take care of layouting for setting widgets
0053     virtual void addWidget(QWidget *widget, const QString &text) = 0;
0054 
0055     // Subclassed widget is supposed to provide an UI (input label) for editing connection name separately
0056     virtual QString connectionName() const = 0;
0057 
0058     // Subclassed widget is supposed to call initialization after the UI is initialized
0059     void initialize();
0060 
0061 private:
0062     bool m_initialized;
0063     bool m_valid;
0064     int m_pendingReplies;
0065     NetworkManager::ConnectionSettings::Ptr m_connection;
0066     ConnectionWidget *m_connectionWidget = nullptr;
0067     QList<SettingWidget *> m_settingWidgets;
0068     WifiSecurity *m_wifiSecurity = nullptr;
0069 
0070     void addConnectionWidget(ConnectionWidget *widget, const QString &text);
0071     void addSettingWidget(SettingWidget *widget, const QString &text);
0072 };
0073 
0074 #endif // PLASMA_NM_CONNECTION_EDITOR_BASE_H