2
* Copyright (C) 2014 Canonical, Ltd.
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/>.
17
* Jussi Pakkanen <jussi.pakkanen@canonical.com>
20
#include "eventprinter.h"
24
#include "ofonomodemmodem.h"
25
#include "ofonomodemnetworkregistration.h"
26
#include "ofonomodemsimmanager.h"
27
#include "ofonoroot.h"
28
#include "urfkillroot.h"
29
#include "urfkillswitch.h"
31
EventPrinter::EventPrinter(QObject *parent) : QObject(parent) {
32
urfkill = new UrfkillRoot(URFKILL_SERVICE, URFKILL_OBJECT, QDBusConnection::systemBus(), this);
33
btkill = new UrfkillSwitch(URFKILL_SERVICE, URFKILL_BLUETOOTH_OBJECT, QDBusConnection::systemBus(), this);
34
wlankill = new UrfkillSwitch(URFKILL_SERVICE, URFKILL_WLAN_OBJECT, QDBusConnection::systemBus(), this);
35
nmroot = new NetworkManagerRoot(NM_SERVICE, NM_OBJECT, QDBusConnection::systemBus(), this);
37
connect(urfkill, SIGNAL(FlightModeChanged(bool)), this, SLOT(flightModeChanged(bool)));
38
connect(btkill, SIGNAL(StateChanged()), this, SLOT(btKillswitchChanged()));
39
connect(wlankill, SIGNAL(StateChanged()), this, SLOT(wlanKillswitchChanged()));
40
connect(nmroot, SIGNAL(StateChanged(uint)), this, SLOT(nmStateChanged(uint)));
41
connect(nmroot, SIGNAL(PropertiesChanged(const QVariantMap&)), this, SLOT(nmPropertiesChanged(const QVariantMap&)));
43
OfonoRoot ofono(OFONO_SERVICE, OFONO_OBJECT, QDBusConnection::systemBus(), nullptr);
44
auto modems = ofono.GetModems().value();
45
if(modems.length() > 0) {
46
modem1 = new OfonoModemModem(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
47
connect(modem1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
48
SLOT(modem1PropertyChanged(const QString, const QDBusVariant)));
49
simman1 = new OfonoModemSimManager(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
50
connect(simman1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
51
SLOT(simman1PropertyChanged(const QString, const QDBusVariant)));
52
netreg1 = new OfonoModemNetworkRegistration(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
53
connect(netreg1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
54
SLOT(netreg1PropertyChanged(const QString, const QDBusVariant)));
60
if(modems.length() > 1) {
61
modem2 = new OfonoModemModem(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
62
connect(modem2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
63
SLOT(modem2PropertyChanged(const QString, const QDBusVariant)));
64
simman2 = new OfonoModemSimManager(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
65
connect(simman2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
66
SLOT(simman2PropertyChanged(const QString, const QDBusVariant)));
67
netreg2 = new OfonoModemNetworkRegistration(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
68
connect(netreg2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
69
SLOT(netreg2PropertyChanged(const QString, const QDBusVariant)));
76
EventPrinter::~EventPrinter() {
79
void EventPrinter::flightModeChanged(bool newMode) {
80
printf("Flight mode changed to: %d\n", newMode);
83
void EventPrinter::btKillswitchChanged() {
84
printf("Bluetooth killswitch changed to: %d\n", btkill->state());
87
void EventPrinter::wlanKillswitchChanged() {
88
printf("Wlan killswitch changed to: %d\n", wlankill->state());
91
void EventPrinter::nmStateChanged(uint new_state) {
92
printf("NetworkManager state changed to: %d\n", new_state);
95
void EventPrinter::nmPropertiesChanged(const QVariantMap &props) {
96
const static QString activeConnections("ActiveConnections");
97
const static QString primaryConnectionType("PrimaryConnectionType");
98
printf("NetworkManager properties changed:\n");
99
for(const auto &p : props.keys()) {
100
if(p == activeConnections || p == primaryConnectionType)
102
printf(" %s %s\n", p.toUtf8().data(), props[p].toString().toUtf8().data());
105
auto i = props.find(activeConnections);
106
if(i != props.end()) {
107
activeConnectionsChanged(*i);
109
i = props.find(primaryConnectionType);
110
if(i != props.end()) {
111
primaryConnectionTypeChanged(i->toString());
115
void EventPrinter::primaryConnectionTypeChanged(const QString &type) {
116
printf("NetworkManager primary connection type changed to %s.\n", type.toUtf8().data());
119
void EventPrinter::activeConnectionsChanged(const QVariant &/*list*/) {
120
// list.value<QList<QDBusObjectPath>>() does not work for some reason
121
// so grab again over dbus. Yes it sucks.
122
printf(" ActiveConnections (now have %d)\n", nmroot->activeConnections().size());
125
void EventPrinter::modem1PropertyChanged(const QString name, const QDBusVariant value) {
126
modemPropertyChanged(1, name, value);
129
void EventPrinter::modem2PropertyChanged(const QString name, const QDBusVariant value) {
130
modemPropertyChanged(2, name, value);
133
void EventPrinter::modemPropertyChanged(const int modem, const QString &name, const QDBusVariant &value) {
134
auto str = value.variant().toString();
135
if(str.length() > 0) {
138
printf("Ofono modem %d property %s changed%s.\n", modem, name.toUtf8().data(), str.toUtf8().data());
141
void EventPrinter::simman1PropertyChanged(const QString name, const QDBusVariant value) {
142
simmanPropertyChanged(1, name, value);
145
void EventPrinter::simman2PropertyChanged(const QString name, const QDBusVariant value) {
146
simmanPropertyChanged(2, name, value);
149
void EventPrinter::simmanPropertyChanged(const int simman, const QString &name, const QDBusVariant &value) {
150
if(name == "PinRequired") {
151
printf("Ofono modem %d pin required changed to %s.\n", simman, value.variant().toString().toUtf8().data());
155
void EventPrinter::netreg1PropertyChanged(const QString name, const QDBusVariant value) {
156
netregPropertyChanged(1, name, value);
159
void EventPrinter::netreg2PropertyChanged(const QString name, const QDBusVariant value) {
160
netregPropertyChanged(2, name, value);
163
void EventPrinter::netregPropertyChanged(const int netreg, const QString &name, const QDBusVariant &value) {
165
if(name == "Strength") {
166
valuetext = QString::number(value.variant().toInt());
168
valuetext = value.variant().toString();
171
printf("Ofono network registration %d property %s changed to %s.\n", netreg, name.toUtf8().data(), valuetext.toUtf8().data());