not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / solid / networkmanager-0.6 / tests / nmobject.cpp
blob6e34e88b8d78329e49c10cad1adc0fba9fc5ee99
1 #include <QtDBus>
2 #include <QDBusArgument>
3 #include <QMetaType>
4 #include <qdbusextratypes.h>
5 #include <QList>
6 #include <kdebug.h>
8 #include "nmobject.h"
10 void dump(const NMDevice & device)
12 kDebug() << "Object path: " << device.path.path() << "\nInterface: " << device.interface
13 << "\nType: " << device.type << "\nUdi: " << device.udi << "\nActive: "<< device.active
14 << "\nActivation stage: " << device.activationStage << "\nIPV4 address: " << device.ipv4Address
15 << "\nsubnet mask: " << device.subnetMask << "\nBroadcast: " << device.broadcast
16 << "\nroute: " << device.route << "\nprimary dns: " << device.primaryDNS
17 << "\nsecondary dns: " << device.secondaryDNS << "\nmode: " << device.mode
18 << "\nStrength: " << device.strength << "\nLink active: " << device.linkActive
19 << "\nSpeed: " << device.speed << "\nCapabilities: " << device.capabilities
20 << "\nCapabilities type: " << device.capabilitiesType << "\nactive net path: "
21 << device.activeNetPath << "\nNetworks:" << device.networks << endl;
24 void deserialize(const QDBusMessage &message, NMDevice & device)
26 kDebug() << /*"deserialize args: " << message.arguments() << */"signature: " << message.signature();
27 QList<QVariant> args = message.arguments();
28 device.path.setPath(args.takeFirst().toString());
29 device.interface = args.takeFirst().toString();
30 device.type = args.takeFirst().toUInt();
31 device.udi = args.takeFirst().toString();
32 device.active = args.takeFirst().toBool();
33 device.activationStage = args.takeFirst().toUInt();
34 device.ipv4Address = args.takeFirst().toString();
35 device.subnetMask = args.takeFirst().toString();
36 device.broadcast = args.takeFirst().toString();
37 device.hardwareAddress = args.takeFirst().toString();
38 device.route = args.takeFirst().toString();
39 device.primaryDNS = args.takeFirst().toString();
40 device.secondaryDNS = args.takeFirst().toString();
41 device.mode = args.takeFirst().toInt();
42 device.strength = args.takeFirst().toInt();
43 device.linkActive = args.takeFirst().toBool();
44 device.speed = args.takeFirst().toInt();
45 device.capabilities = args.takeFirst().toUInt();
46 device.capabilitiesType = args.takeFirst().toUInt();
47 device.activeNetPath = args.takeFirst().toString();
48 device.networks = args.takeFirst().toStringList();
49 kDebug() << "deserialize: objpath is " << device.path.path() << "'," << device.interface;
52 NMObject::NMObject(int argc, char ** argv) : QCoreApplication(argc, argv)
55 nmIface = new QDBusInterface("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", QDBusConnection::systemBus());
56 nmIface->connection().connect("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "DeviceStrengthChanged", this, SLOT(deviceStrengthChanged(QDBusObjectPath,int)));
57 nmIface->connection().connect("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "WirelessNetworkStrengthChanged", this, SLOT(netStrengthChanged(QDBusObjectPath,QDBusObjectPath,int)));
58 // nmIface->connection().connect("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "WirelessNetworkAppeared", this, SLOT(updateNetwork(QDBusObjectPath,QDBusObjectPath)));
59 nmIface->connection().connect("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "WirelessNetworkAppeared", this, SLOT(wirelessNetworkAppeared(QDBusObjectPath,QDBusObjectPath)));
60 nmIface->connection().connect("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "WirelessNetworkDisappeared", this, SLOT(wirelessNetworkDisappeared(QDBusObjectPath,QDBusObjectPath)));
63 NMObject::~NMObject()
67 void NMObject::showDevices()
69 kDebug() << "Hello, world!";
70 QDBusConnection bus = QDBusConnection::systemBus();
71 QDBusReply<uint> state = nmIface->call("state");
72 if (state.isValid())
73 kDebug() << "State: " << state.value();
74 else
76 QDBusError err = state.error();
77 kDebug() << "error: " << err.name() << "msg: " << err.message();
80 QDBusInterface * deviceIface = new QDBusInterface("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager.Devices", bus);
81 //QDBusMessage deviceList = deviceIface->call("getDevices");
83 qDBusRegisterMetaType<QList<QDBusObjectPath> >();
85 QDBusReply< QList <QDBusObjectPath> > deviceList = deviceIface->call("getDevices");
86 if (true)
88 kDebug() << "NMObject::showDevices() Got device list"; //Signature: " << deviceList.signature() ;
89 QList <QDBusObjectPath> devices = deviceList.value();
90 foreach (QDBusObjectPath op, devices)
92 kDebug() << " " << op.path();
93 QDBusInterface * deviceIface2 = new QDBusInterface("org.freedesktop.NetworkManager", op.path(), "org.freedesktop.NetworkManager.Devices", bus);
94 QDBusMessage reply = deviceIface2->call("getProperties");
95 //kDebug() << " getProperties call" << (reply.isValid() ? "is" : "is not") << " valid.";
96 NMDevice dev;
97 deserialize(reply, dev);
98 dump(dev);
103 void NMObject::netStrengthChanged(QDBusObjectPath devPath, QDBusObjectPath netPath, int strength)
105 kDebug() << "netStrengthChanged() device: " << devPath.path() << " net: " << netPath.path() << " strength: " << strength;
107 void NMObject::deviceStrengthChanged(QDBusObjectPath objPath, int strength)
109 kDebug() << "deviceStrengthChanged() obj: " << objPath.path() << " strength: " << strength;
111 void NMObject::updateNetwork(QDBusObjectPath objPath, QDBusObjectPath netPath)
113 kDebug() << "updateNetwork() obj: " << objPath.path() << " net: " << netPath.path();
115 void NMObject::wirelessNetworkAppeared(QDBusObjectPath objPath, QDBusObjectPath netPath)
117 kDebug() << "wirelessNetworkAppeared() obj: " << objPath.path() << " net: " << netPath.path();
119 void NMObject::wirelessNetworkDisappeared(QDBusObjectPath objPath, QDBusObjectPath netPath)
121 kDebug() << "wirelessNetworkDisappeared() obj: " << objPath.path() << " net: " << netPath.path();
124 #include "nmobject.moc"