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

0001 // SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
0002 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #pragma once
0006 
0007 #include <ModemManagerQt/Manager>
0008 #include <ModemManagerQt/Modem3Gpp>
0009 
0010 #include <NetworkManagerQt/Connection>
0011 #include <NetworkManagerQt/ModemDevice>
0012 
0013 #include <QObject>
0014 #include <qqmlregistration.h>
0015 
0016 #include "profilesettings.h"
0017 
0018 // We make the assumption that there is only one modem.
0019 class SignalIndicator : public QObject
0020 {
0021     Q_OBJECT
0022     QML_ELEMENT
0023     QML_SINGLETON
0024 
0025     Q_PROPERTY(int strength READ strength NOTIFY strengthChanged)
0026     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0027     Q_PROPERTY(bool modemAvailable READ modemAvailable NOTIFY modemAvailableChanged)
0028     Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
0029     Q_PROPERTY(bool simEmpty READ simEmpty NOTIFY simEmptyChanged)
0030 
0031     Q_PROPERTY(bool mobileDataSupported READ mobileDataSupported NOTIFY mobileDataSupportedChanged)
0032     Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged)
0033 
0034     Q_PROPERTY(bool needsAPNAdded READ needsAPNAdded NOTIFY mobileDataEnabledChanged)
0035     Q_PROPERTY(QList<ProfileSettings *> profiles READ profileList NOTIFY profileListChanged)
0036     Q_PROPERTY(QString activeConnectionUni READ activeConnectionUni NOTIFY activeConnectionUniChanged)
0037 
0038 public:
0039     SignalIndicator(QObject *parent = nullptr);
0040 
0041     int strength() const;
0042     QString name() const;
0043     bool modemAvailable() const;
0044     bool simLocked() const;
0045     bool simEmpty() const;
0046     bool mobileDataSupported() const;
0047     bool mobileDataEnabled() const;
0048     bool needsAPNAdded() const;
0049     QString activeConnectionUni() const;
0050 
0051     void setMobileDataEnabled(bool enabled);
0052 
0053     // connection profiles
0054     QList<ProfileSettings *> &profileList();
0055     void refreshProfiles();
0056     Q_INVOKABLE void activateProfile(const QString &connectionUni);
0057     Q_INVOKABLE void addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType);
0058     Q_INVOKABLE void removeProfile(const QString &connectionUni);
0059     Q_INVOKABLE void updateProfile(const QString &connectionUni,
0060                                    const QString &name,
0061                                    const QString &apn,
0062                                    const QString &username,
0063                                    const QString &password,
0064                                    const QString &networkType);
0065 
0066 Q_SIGNALS:
0067     void strengthChanged();
0068     void nameChanged();
0069     void modemAvailableChanged();
0070     void simLockedChanged();
0071     void simEmptyChanged();
0072     void mobileDataSupportedChanged();
0073     void mobileDataEnabledChanged();
0074     void profileListChanged();
0075     void activeConnectionUniChanged();
0076 
0077 private:
0078     NetworkManager::ModemDevice::Ptr m_nmModem;
0079     ModemManager::ModemDevice::Ptr m_modemDevice;
0080     ModemManager::Modem::Ptr m_modem;
0081     ModemManager::Modem3gpp::Ptr m_3gppModem;
0082 
0083     QList<ProfileSettings *> m_profileList;
0084 
0085     void updateModemManagerModem();
0086     void updateNetworkManagerModem();
0087 };