connectivity-api
connectivity.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authors:
17  * Pete Woods <pete.woods@canonical.com>
18  */
19 
20 #pragma once
21 
22 #include <QAbstractListModel>
23 #include <QDBusConnection>
24 #include <QObject>
25 #include <QStringList>
26 #include <functional>
27 #include <memory>
28 
29 #include <unity/util/DefinesPtrs.h>
30 
32 
33 namespace connectivityqt
34 {
35 
36 class Q_DECL_EXPORT Connectivity: public QObject
37 {
38  Q_OBJECT
39 
40 public:
41  UNITY_DEFINES_PTRS(Connectivity);
42 
43  Q_DISABLE_COPY(Connectivity)
44 
45  Q_ENUMS(Limitations)
46  Q_ENUMS(Status)
47 
48  static void registerMetaTypes();
49 
55  enum class Limitations
56  {
61  Bandwith
62  };
63 
69  enum class Status
70  {
71  Offline,
72  Connecting,
73  Online
74  };
75 
76  Connectivity(const QDBusConnection& sessionConnection = QDBusConnection::sessionBus(), QObject* parent = 0);
77 
78  Connectivity(const std::function<void(QObject*)>& objectOwner,
79  const QDBusConnection& sessionConnection = QDBusConnection::sessionBus(),
80  QObject* parent = 0);
81 
82  ~Connectivity();
83 
84  Q_PROPERTY(bool flightMode READ flightMode WRITE setFlightMode NOTIFY flightModeUpdated)
85  Q_PROPERTY(bool FlightMode READ flightMode WRITE setFlightMode NOTIFY flightModeUpdated)
86  bool flightMode() const;
87 
88  Q_PROPERTY(bool online READ online NOTIFY onlineUpdated)
89  bool online() const;
90 
91  Q_PROPERTY(bool limitedBandwith READ limitedBandwith NOTIFY limitedBandwithUpdated)
92  bool limitedBandwith() const;
93 
94  Q_PROPERTY(QVector<Limitations> Limitations READ limitations NOTIFY limitationsUpdated)
95  QVector<Limitations> limitations() const;
96 
97  Q_PROPERTY(connectivityqt::Connectivity::Status Status READ status NOTIFY statusUpdated)
98  Status status() const;
99 
100  Q_PROPERTY(bool wifiEnabled READ wifiEnabled WRITE setwifiEnabled NOTIFY wifiEnabledUpdated)
101  Q_PROPERTY(bool WifiEnabled READ wifiEnabled WRITE setwifiEnabled NOTIFY wifiEnabledUpdated)
102  bool wifiEnabled() const;
103 
104  Q_PROPERTY(bool UnstoppableOperationHappening READ unstoppableOperationHappening NOTIFY unstoppableOperationHappeningUpdated)
105  bool unstoppableOperationHappening() const;
106 
107  Q_PROPERTY(bool FlightModeSwitchEnabled READ flightModeSwitchEnabled NOTIFY flightModeSwitchEnabledUpdated)
108  Q_PROPERTY(bool flightModeSwitchEnabled READ flightModeSwitchEnabled NOTIFY flightModeSwitchEnabledUpdated)
109  bool flightModeSwitchEnabled() const;
110 
111  Q_PROPERTY(bool WifiSwitchEnabled READ wifiSwitchEnabled NOTIFY wifiSwitchEnabledUpdated)
112  Q_PROPERTY(bool wifiSwitchEnabled READ wifiSwitchEnabled NOTIFY wifiSwitchEnabledUpdated)
113  bool wifiSwitchEnabled() const;
114 
115  Q_PROPERTY(bool HotspotSwitchEnabled READ hotspotSwitchEnabled NOTIFY hotspotSwitchEnabledUpdated)
116  Q_PROPERTY(bool hotspotSwitchEnabled READ hotspotSwitchEnabled NOTIFY hotspotSwitchEnabledUpdated)
117  bool hotspotSwitchEnabled() const;
118 
119  Q_PROPERTY(bool modemAvailable READ modemAvailable NOTIFY modemAvailableUpdated)
120  bool modemAvailable() const;
121 
122  Q_PROPERTY(QByteArray hotspotSsid READ hotspotSsid WRITE setHotspotSsid NOTIFY hotspotSsidUpdated)
123  QByteArray hotspotSsid() const;
124 
125  Q_PROPERTY(QString hotspotPassword READ hotspotPassword WRITE setHotspotPassword NOTIFY hotspotPasswordUpdated)
126  QString hotspotPassword() const;
127 
128  Q_PROPERTY(bool hotspotEnabled READ hotspotEnabled WRITE setHotspotEnabled NOTIFY hotspotEnabledUpdated)
129  bool hotspotEnabled() const;
130 
131  Q_PROPERTY(QString hotspotMode READ hotspotMode WRITE setHotspotMode NOTIFY hotspotModeUpdated)
132  QString hotspotMode() const;
133 
134  Q_PROPERTY(QString hotspotAuth READ hotspotAuth WRITE setHotspotAuth NOTIFY hotspotAuthUpdated)
135  QString hotspotAuth() const;
136 
137  Q_PROPERTY(bool hotspotStored READ hotspotStored NOTIFY hotspotStoredUpdated)
138  bool hotspotStored() const;
139 
140  Q_PROPERTY(bool Initialized READ isInitialized NOTIFY initialized)
141  bool isInitialized() const;
142 
143  Q_PROPERTY(QAbstractItemModel* vpnConnections READ vpnConnections NOTIFY vpnConnectionsUpdated)
144  QAbstractItemModel* vpnConnections() const;
145 
146 public Q_SLOTS:
147  void setFlightMode(bool enabled);
148 
149  void setwifiEnabled(bool enabled);
150 
151  void setHotspotEnabled(bool active);
152 
153  void setHotspotSsid(const QByteArray& ssid);
154 
155  void setHotspotPassword(const QString& password);
156 
157  void setHotspotMode(const QString& mode);
158 
159  void setHotspotAuth(const QString& auth);
160 
161 Q_SIGNALS:
162  void flightModeUpdated(bool);
163 
164  void onlineUpdated(bool value);
165 
166  void limitedBandwithUpdated(bool value);
167 
168  void limitationsUpdated(const QVector<Limitations>&);
169 
170  void statusUpdated(connectivityqt::Connectivity::Status value);
171 
172  void wifiEnabledUpdated(bool);
173 
174  void unstoppableOperationHappeningUpdated(bool);
175 
176  void flightModeSwitchEnabledUpdated(bool);
177 
178  void wifiSwitchEnabledUpdated(bool);
179 
180  void hotspotSwitchEnabledUpdated(bool);
181 
182  void hotspotSsidUpdated(const QByteArray& name);
183 
184  void hotspotPasswordUpdated(const QString& password);
185 
186  void modemAvailableUpdated(bool);
187 
188  void hotspotEnabledUpdated(bool);
189 
190  void hotspotModeUpdated(const QString& mode);
191 
192  void hotspotAuthUpdated(const QString& auth);
193 
194  void hotspotStoredUpdated(bool);
195 
196  void reportError(int reason);
197 
198  void initialized();
199 
200  void vpnConnectionsUpdated(QAbstractItemModel*);
201 
202 protected:
203  class Priv;
204  std::shared_ptr<Priv> d;
205 };
206 
207 }
208 
209 Q_DECLARE_METATYPE(connectivityqt::Connectivity::Limitations)
210 Q_DECLARE_METATYPE(QVector<connectivityqt::Connectivity::Limitations>)
211 Q_DECLARE_METATYPE(connectivityqt::Connectivity::Status)
212 
STL namespace.
Definition: connectivity.cpp:32
Definition: connectivity.h:36
Limitations
enum for networking limitations
Definition: connectivity.h:55
Status
enum for networking status
Definition: connectivity.h:69