2
2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
* Author: Pete Woods <pete.woods@canonical.com>
19
#include <NetworkManagerDeviceInterface.h>
20
19
#include <NetworkManagerDeviceWirelessInterface.h>
20
#include <NetworkManagerAccessPointInterface.h>
21
21
#include <NetworkPrompt.h>
23
24
#include <NetworkManager.h>
26
27
const QDBusConnection &systemConnection, QObject *parent) :
27
28
QObject(parent), m_sessionConnection(sessionConnection), m_systemConnection(
28
29
systemConnection), m_networkManager(NM_DBUS_SERVICE,
29
NM_DBUS_PATH, m_systemConnection), m_systemDialog(
30
"com.canonical.Unity.SystemDialog",
31
"/com/canonical/Unity/SystemDialog", m_sessionConnection) {
30
NM_DBUS_PATH, m_systemConnection) {
34
33
NetworkPrompt::~NetworkPrompt() {
36
QDBusObjectPath NetworkPrompt::activateAccessPoint(
37
const QDBusObjectPath& accessPointPath,
38
const OrgFreedesktopNetworkManagerDeviceInterface& device,
39
const QDBusObjectPath& devicePath) {
41
qDebug() << "access point: " << accessPointPath.path();
42
QList<QDBusObjectPath> connectionPaths(device.availableConnections());
44
if (connectionPaths.empty()) {
45
// if no existing connections, then add a new one
46
return m_networkManager.AddAndActivateConnection(QVariantMap(),
47
devicePath, accessPointPath);
49
// we already have a connection, so just activate it
50
return m_networkManager.ActivateConnection(connectionPaths.first(),
51
devicePath, accessPointPath);
37
55
void NetworkPrompt::check() {
52
70
QList<QDBusObjectPath> devicePaths(m_networkManager.GetDevices());
72
WiFiMenuPtr wifiMenu(new WiFiMenu());
54
74
for (const QDBusObjectPath &devicePath : devicePaths) {
55
OrgFreedesktopNetworkManagerDeviceInterface device(NM_DBUS_SERVICE,
56
devicePath.path(), m_systemConnection);
57
if (device.deviceType() == NM_DEVICE_TYPE_WIFI) {
75
OrgFreedesktopNetworkManagerDeviceInterface deviceInterface(
76
NM_DBUS_SERVICE, devicePath.path(), m_systemConnection);
77
if (deviceInterface.deviceType() == NM_DEVICE_TYPE_WIFI) {
59
OrgFreedesktopNetworkManagerDeviceWirelessInterface wifiDevice(
79
OrgFreedesktopNetworkManagerDeviceWirelessInterface wifiDeviceInterface(
60
80
NM_DBUS_SERVICE, devicePath.path(), m_systemConnection);
82
DevicePtr device(new Device());
83
device->setPath(devicePath.path().toStdString());
84
wifiMenu->addDevice(device);
62
86
QDBusPendingReply<void> reply(
63
wifiDevice.RequestScan(QVariantMap()));
87
wifiDeviceInterface.RequestScan(QVariantMap()));
88
reply.waitForFinished();
64
90
QList<QDBusObjectPath> accessPointPaths(
65
wifiDevice.GetAccessPoints());
91
wifiDeviceInterface.GetAccessPoints());
67
93
for (const QDBusObjectPath &accessPointPath : accessPointPaths) {
68
qDebug() << "access point: " << accessPointPath.path();
69
QList<QDBusObjectPath> connectionPaths(
70
device.availableConnections());
71
if (connectionPaths.empty()) {
72
// if no existing connections, then add a new one
73
QDBusObjectPath networkConnection(
74
m_networkManager.AddAndActivateConnection(
75
QVariantMap(), devicePath,
78
// we already have a connection, so just activate it
79
QDBusObjectPath networkConnection(
80
m_networkManager.ActivateConnection(
81
connectionPaths.first(), devicePath,
94
OrgFreedesktopNetworkManagerAccessPointInterface accessPointInterface(
95
NM_DBUS_SERVICE, accessPointPath.path(),
98
AccessPointPtr accessPoint(new AccessPoint());
99
accessPoint->setSsid(accessPointInterface.ssid().data());
100
accessPoint->setAdhoc(
101
accessPointInterface.mode()
102
== NM_802_11_MODE_ADHOC);
103
accessPoint->setSecure(
104
accessPointInterface.flags()
105
== NM_802_11_AP_FLAGS_PRIVACY);
106
accessPoint->setBssid(
107
accessPointInterface.hwAddress().toStdString());
108
accessPoint->setPath(accessPointPath.path().toStdString());
109
device->addAccessPoint(accessPoint);
115
MenuExporter exporter(wifiMenu);
116
// activateAccessPoint(accessPointPath, device, devicePath);