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  bool flightMode() const;
86 
87  Q_PROPERTY(bool online READ online NOTIFY onlineUpdated)
88  bool online() const;
89 
90  Q_PROPERTY(bool limitedBandwith READ limitedBandwith NOTIFY limitedBandwithUpdated)
91  bool limitedBandwith() const;
92 
93  Q_PROPERTY(QVector<Limitations> Limitations READ limitations NOTIFY limitationsUpdated)
94  QVector<Limitations> limitations() const;
95 
96  Q_PROPERTY(connectivityqt::Connectivity::Status status READ status NOTIFY statusUpdated)
98 
99  Q_PROPERTY(bool wifiEnabled READ wifiEnabled WRITE setwifiEnabled NOTIFY wifiEnabledUpdated)
100  bool wifiEnabled() const;
101 
102  Q_PROPERTY(bool unstoppableOperationHappening READ unstoppableOperationHappening NOTIFY unstoppableOperationHappeningUpdated)
103  bool unstoppableOperationHappening() const;
104 
105  Q_PROPERTY(bool flightModeSwitchEnabled READ flightModeSwitchEnabled NOTIFY flightModeSwitchEnabledUpdated)
106  bool flightModeSwitchEnabled() const;
107 
108  Q_PROPERTY(bool wifiSwitchEnabled READ wifiSwitchEnabled NOTIFY wifiSwitchEnabledUpdated)
109  bool wifiSwitchEnabled() const;
110 
111  Q_PROPERTY(bool hotspotSwitchEnabled READ hotspotSwitchEnabled NOTIFY hotspotSwitchEnabledUpdated)
112  bool hotspotSwitchEnabled() const;
113 
114  Q_PROPERTY(bool modemAvailable READ modemAvailable NOTIFY modemAvailableUpdated)
115  bool modemAvailable() const;
116 
117  Q_PROPERTY(QByteArray hotspotSsid READ hotspotSsid WRITE setHotspotSsid NOTIFY hotspotSsidUpdated)
118  QByteArray hotspotSsid() const;
119 
120  Q_PROPERTY(QString hotspotPassword READ hotspotPassword WRITE setHotspotPassword NOTIFY hotspotPasswordUpdated)
121  QString hotspotPassword() const;
122 
123  Q_PROPERTY(bool hotspotEnabled READ hotspotEnabled WRITE setHotspotEnabled NOTIFY hotspotEnabledUpdated)
124  bool hotspotEnabled() const;
125 
126  Q_PROPERTY(QString hotspotMode READ hotspotMode WRITE setHotspotMode NOTIFY hotspotModeUpdated)
127  QString hotspotMode() const;
128 
129  Q_PROPERTY(QString hotspotAuth READ hotspotAuth WRITE setHotspotAuth NOTIFY hotspotAuthUpdated)
130  QString hotspotAuth() const;
131 
132  Q_PROPERTY(bool hotspotStored READ hotspotStored NOTIFY hotspotStoredUpdated)
133  bool hotspotStored() const;
134 
135  Q_PROPERTY(bool initialized READ isInitialized NOTIFY initialized)
136  bool isInitialized() const;
137 
138  Q_PROPERTY(QAbstractItemModel* vpnConnections READ vpnConnections NOTIFY vpnConnectionsUpdated)
139  QAbstractItemModel* vpnConnections() const;
140 
141 public Q_SLOTS:
142  void setFlightMode(bool enabled);
143 
144  void setwifiEnabled(bool enabled);
145 
146  void setHotspotEnabled(bool active);
147 
148  void setHotspotSsid(const QByteArray& ssid);
149 
150  void setHotspotPassword(const QString& password);
151 
152  void setHotspotMode(const QString& mode);
153 
154  void setHotspotAuth(const QString& auth);
155 
156 Q_SIGNALS:
157  void flightModeUpdated(bool);
158 
159  void onlineUpdated(bool value);
160 
161  void limitedBandwithUpdated(bool value);
162 
163  void limitationsUpdated(const QVector<Limitations>&);
164 
165  void statusUpdated(connectivityqt::Connectivity::Status value);
166 
167  void wifiEnabledUpdated(bool);
168 
169  void unstoppableOperationHappeningUpdated(bool);
170 
171  void flightModeSwitchEnabledUpdated(bool);
172 
173  void wifiSwitchEnabledUpdated(bool);
174 
175  void hotspotSwitchEnabledUpdated(bool);
176 
177  void hotspotSsidUpdated(const QByteArray& name);
178 
179  void hotspotPasswordUpdated(const QString& password);
180 
181  void modemAvailableUpdated(bool);
182 
183  void hotspotEnabledUpdated(bool);
184 
185  void hotspotModeUpdated(const QString& mode);
186 
187  void hotspotAuthUpdated(const QString& auth);
188 
189  void hotspotStoredUpdated(bool);
190 
191  void reportError(int reason);
192 
193  void initialized();
194 
195  void vpnConnectionsUpdated(QAbstractItemModel*);
196 
197 protected:
198  class Priv;
199  std::shared_ptr<Priv> d;
200 };
201 
202 }
203 
205 Q_DECLARE_METATYPE(QVector<connectivityqt::Connectivity::Limitations>)
206 Q_DECLARE_METATYPE(connectivityqt::Connectivity::Status)
207 
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
std::shared_ptr< Priv > d
Definition: connectivity.h:198