add more spacing
[personal-kdebase.git] / workspace / solid / solidshell / solid-network.cpp
blob362f94bdb997d658dd0769b340bf6c1c15bfa7d7
1 /* This file is part of the KDE project
2 Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library 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 GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "solid-network.h"
23 #include <QString>
24 #include <QStringList>
25 #include <QMetaProperty>
26 #include <QMetaEnum>
27 #include <QTimer>
29 #include <kcomponentdata.h>
30 #include <kcmdlineargs.h>
31 #include <klocale.h>
32 #include <k3socketaddress.h>
33 #include <kdebug.h>
35 #include <solid/device.h>
36 #include <solid/genericinterface.h>
37 #include <solid/storageaccess.h>
38 #include <solid/opticaldrive.h>
40 #include <solid/control/ifaces/authentication.h>
41 #include <solid/control/networkmanager.h>
42 #include <solid/control/networkinterface.h>
43 #include <solid/control/wirednetworkinterface.h>
44 #include <solid/control/wirelessnetworkinterface.h>
45 #include <solid/control/wirelessaccesspoint.h>
47 #include <kjob.h>
50 #include <iostream>
51 using namespace std;
53 static const char appName[] = "solid-network";
54 static const char programName[] = I18N_NOOP("solid-network");
56 static const char description[] = I18N_NOOP("KDE tool for querying and controlling your network interfaces from the command line");
58 static const char version[] = "0.1";
60 std::ostream &operator<<(std::ostream &out, const QString &msg)
62 return (out << msg.toLocal8Bit().constData());
65 std::ostream &operator<<(std::ostream &out, const QVariant &value)
67 switch (value.type())
69 case QVariant::StringList:
71 out << "{";
73 QStringList list = value.toStringList();
75 QStringList::ConstIterator it = list.constBegin();
76 QStringList::ConstIterator end = list.constEnd();
78 for (; it!=end; ++it)
80 out << "'" << *it << "'";
82 if (it+1!=end)
84 out << ", ";
88 out << "} (string list)";
89 break;
91 case QVariant::Bool:
92 out << (value.toBool()?"true":"false") << " (bool)";
93 break;
94 case QVariant::Int:
95 out << value.toString()
96 << " (0x" << QString::number(value.toInt(), 16) << ") (int)";
97 break;
98 default:
99 out << "'" << value.toString() << "' (string)";
100 break;
103 return out;
106 std::ostream &operator<<(std::ostream &out, const Solid::Device &device)
108 out << " parent = " << QVariant(device.parentUdi()) << endl;
109 out << " vendor = " << QVariant(device.vendor()) << endl;
110 out << " product = " << QVariant(device.product()) << endl;
112 int index = Solid::DeviceInterface::staticMetaObject.indexOfEnumerator("Type");
113 QMetaEnum typeEnum = Solid::DeviceInterface::staticMetaObject.enumerator(index);
115 for (int i=0; i<typeEnum.keyCount(); i++)
117 Solid::DeviceInterface::Type type = (Solid::DeviceInterface::Type)typeEnum.value(i);
118 const Solid::DeviceInterface *interface = device.asDeviceInterface(type);
120 if (interface)
122 const QMetaObject *meta = interface->metaObject();
124 for (int i=meta->propertyOffset(); i<meta->propertyCount(); i++)
126 QMetaProperty property = meta->property(i);
127 out << " " << QString(meta->className()).mid(7) << "." << property.name()
128 << " = ";
130 QVariant value = property.read(interface);
132 if (property.isEnumType()) {
133 QMetaEnum metaEnum = property.enumerator();
134 out << "'" << metaEnum.valueToKeys(value.toInt()).constData() << "'"
135 << " (0x" << QString::number(value.toInt(), 16) << ") ";
136 if (metaEnum.isFlag()) {
137 out << "(flag)";
138 } else {
139 out << "(enum)";
141 out << endl;
142 } else {
143 out << value << endl;
149 return out;
152 std::ostream &operator<<(std::ostream &out, const QMap<QString,QVariant> &properties)
154 QMap<QString, QVariant>::ConstIterator it = properties.constBegin(), itEnd = properties.constEnd();
155 for ( ; it != itEnd; ++it)
157 out << " " << it.key() << " = " << it.value() << endl;
160 return out;
163 std::ostream &operator<<(std::ostream &out, const Solid::Control::NetworkInterface &networkdevice)
165 out << " UNI = " << QVariant(networkdevice.uni()) << endl;
166 out << " Type = " << (networkdevice.type() == Solid::Control::NetworkInterface::Ieee8023 ? "Wired" : "802.11 Wireless") << endl;
167 out << " Active = " << (networkdevice.isActive() ? "Yes" : "No") << endl;
168 out << " Interface Name = " << networkdevice.interfaceName() << endl;
169 out << " Driver = " << networkdevice.driver() << endl;
170 //out << " HW Address = " << networkdevice. // TODO add to solid API.
171 out << "\n Capabilities:" << endl;
172 out << " Supported = " << (networkdevice.capabilities() & Solid::Control::NetworkInterface::IsManageable ? "Yes" : "No") << endl;
173 out << " Speed = " << networkdevice.designSpeed() << endl;
174 #if 0
175 if (networkdevice.type() == Solid::Control::NetworkInterface::Ieee8023) {
177 out << " Carrier Detect = " << (networkdevice.capabilities() & Solid::Control::NetworkInterface::SupportsCarrierDetect ? "Yes" : "No") << endl;
179 else {
180 out << " Wireless Scan = " << (networkdevice.capabilities() & Solid::Control::NetworkInterface::SupportsWirelessScan ? "Yes" : "No") << endl;
182 out << " Link Up = " << (networkdevice.isLinkUp() ? "Yes" : "No") << endl;
183 #endif
185 return out;
188 std::ostream &operator<<(std::ostream &out, const Solid::Control::AccessPoint &ap)
190 out << " UNI = " << QVariant(ap.uni()) << endl;
191 out << " SSID = " << QVariant(ap.ssid()) << endl;
192 out << " MAC Address = " << QVariant(ap.hardwareAddress()) << endl;
193 out << " Frequency (MHz) = " << ap.frequency() << endl;
194 out << " Max BitRate (Kb/s) = " << ap.maxBitRate() << endl;
195 out << " Signal Strength = " << ap.signalStrength() << endl;
196 out << " Mode = ";
197 switch (ap.mode())
199 case Solid::Control::WirelessNetworkInterface::Unassociated:
200 cout << "Unassociated" << endl;
201 break;
202 case Solid::Control::WirelessNetworkInterface::Adhoc:
203 cout << "Ad-hoc" << endl;
204 break;
205 case Solid::Control::WirelessNetworkInterface::Managed:
206 cout << "Infrastructure" << endl;
207 break;
208 case Solid::Control::WirelessNetworkInterface::Master:
209 cout << "Master" << endl;
210 break;
211 case Solid::Control::WirelessNetworkInterface::Repeater:
212 cout << "Repeater" << endl;
213 break;
214 default:
215 cout << "Unknown" << endl;
216 cerr << "Unknown network operation mode: " << ap.mode() << endl;
217 break;
219 out << " Capabilities = ";
220 const Solid::Control::AccessPoint::Capabilities cap = ap.capabilities();
221 if (cap)
223 if (cap & Solid::Control::AccessPoint::Privacy)
224 out << "Privacy,";
225 out << endl;
227 else
229 out << "(No Capabilities)" << endl;
231 out << " WPA Options = ";
232 const Solid::Control::AccessPoint::WpaFlags wpaFlags = ap.wpaFlags();
233 if (wpaFlags)
235 if (wpaFlags & Solid::Control::AccessPoint::PairWep40)
236 out << "PairWep40,";
237 if (wpaFlags & Solid::Control::AccessPoint::PairWep104)
238 out << "PairWep104,";
239 if (wpaFlags & Solid::Control::AccessPoint::PairTkip)
240 out << "PairTkip,";
241 if (wpaFlags & Solid::Control::AccessPoint::PairCcmp)
242 out << "PairCcmp,";
243 if (wpaFlags & Solid::Control::AccessPoint::GroupWep40)
244 out << "GroupWep40,";
245 if (wpaFlags & Solid::Control::AccessPoint::GroupWep104)
246 out << "GroupWep104,";
247 if (wpaFlags & Solid::Control::AccessPoint::GroupTkip)
248 out << "GroupTkip,";
249 if (wpaFlags & Solid::Control::AccessPoint::GroupCcmp)
250 out << "GroupCcmp,";
251 if (wpaFlags & Solid::Control::AccessPoint::KeyMgmtPsk)
252 out << "KeyMgmtPsk,";
253 if (wpaFlags & Solid::Control::AccessPoint::KeyMgmt8021x)
254 out << "KeyMgmt8021x,";
255 out << endl;
257 else
259 out << "(No Options)" << endl;
261 out << " RSN Options = ";
262 const Solid::Control::AccessPoint::WpaFlags rsnFlags = ap.rsnFlags();
263 if (rsnFlags)
265 if (rsnFlags & Solid::Control::AccessPoint::PairWep40)
266 out << "PairWep40,";
267 if (rsnFlags & Solid::Control::AccessPoint::PairWep104)
268 out << "PairWep104,";
269 if (rsnFlags & Solid::Control::AccessPoint::PairTkip)
270 out << "PairTkip,";
271 if (rsnFlags & Solid::Control::AccessPoint::PairCcmp)
272 out << "PairCcmp,";
273 if (rsnFlags & Solid::Control::AccessPoint::GroupWep40)
274 out << "GroupWep40,";
275 if (rsnFlags & Solid::Control::AccessPoint::GroupWep104)
276 out << "GroupWep104,";
277 if (rsnFlags & Solid::Control::AccessPoint::GroupTkip)
278 out << "GroupTkip,";
279 if (rsnFlags & Solid::Control::AccessPoint::GroupCcmp)
280 out << "GroupCcmp,";
281 if (rsnFlags & Solid::Control::AccessPoint::KeyMgmtPsk)
282 out << "KeyMgmtPsk,";
283 if (rsnFlags & Solid::Control::AccessPoint::KeyMgmt8021x)
284 out << "KeyMgmt8021x,";
285 out << endl;
287 else
289 out << "(No Options)" << endl;
291 return out;
294 std::ostream &operator<<(std::ostream &out, const Solid::Control::WirelessNetworkInterface &network)
296 out << static_cast<const Solid::Control::NetworkInterface&>(network);
297 out << endl;
298 out << " Mode = ";
299 switch (network.mode())
301 case Solid::Control::WirelessNetworkInterface::Unassociated:
302 cout << "Unassociated" << endl;
303 break;
304 case Solid::Control::WirelessNetworkInterface::Adhoc:
305 cout << "Ad-hoc" << endl;
306 break;
307 case Solid::Control::WirelessNetworkInterface::Managed:
308 cout << "Infrastructure" << endl;
309 break;
310 case Solid::Control::WirelessNetworkInterface::Master:
311 cout << "Master" << endl;
312 break;
313 case Solid::Control::WirelessNetworkInterface::Repeater:
314 cout << "Repeater" << endl;
315 break;
316 default:
317 cout << "Unknown" << endl;
318 cerr << "Unknown network operation mode: " << network.mode() << endl;
319 break;
321 out << " Bit Rate = " << network.bitRate() << endl;
322 out << " Hardware Address = " << network.hardwareAddress() << endl;
323 out << " Active Access Point= " << qVariantFromValue(network.activeAccessPoint()) << endl;
324 out << " Capabilities = ";
325 const Solid::Control::WirelessNetworkInterface::Capabilities cap = network.wirelessCapabilities();
326 if (cap)
328 if (cap & Solid::Control::WirelessNetworkInterface::Wpa)
329 out << "WPA,";
330 if (cap & Solid::Control::WirelessNetworkInterface::Wep40)
331 out << "WEP40,";
332 if (cap & Solid::Control::WirelessNetworkInterface::Wep104)
333 out << "WEP104,";
334 if (cap & Solid::Control::WirelessNetworkInterface::Tkip)
335 out << "TKIP,";
336 if (cap & Solid::Control::WirelessNetworkInterface::Ccmp)
337 out << "CCMP,";
338 if (cap & Solid::Control::WirelessNetworkInterface::Rsn)
339 out << "RSN,";
340 out << endl;
342 else
344 out << "(No Capabilities)" << endl;
346 return out;
349 std::ostream &operator<<(std::ostream &out, const Solid::Control::WiredNetworkInterface &network)
351 out << static_cast<const Solid::Control::NetworkInterface&>(network);
352 out << endl;
353 out << " Hardware Address = " << network.hardwareAddress() << endl;
354 out << " Bit Rate = " << network.bitRate() << endl;
355 out << " Carrier = " << qVariantFromValue(network.carrier()) << endl;
356 return out;
360 void checkArgumentCount(int min, int max)
362 int count = KCmdLineArgs::parsedArgs()->count();
364 if (count < min)
366 cerr << i18n("Syntax Error: Not enough arguments") << endl;
367 ::exit(1);
370 if ((max > 0) && (count > max))
372 cerr << i18n("Syntax Error: Too many arguments") << endl;
373 ::exit(1);
377 int main(int argc, char **argv)
379 KCmdLineArgs::init(argc, argv, appName, 0, ki18n(programName), version, ki18n(description), false);
382 KCmdLineOptions options;
384 options.add("commands", ki18n("Show available commands by domains"));
386 options.add("+command", ki18n("Command (see --commands)"));
388 options.add("+[arg(s)]", ki18n("Arguments for command"));
390 KCmdLineArgs::addCmdLineOptions(options);
392 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
394 KComponentData componentData(appName);
396 if (args->isSet("commands"))
398 KCmdLineArgs::enable_i18n();
400 cout << endl << i18n("Syntax:") << endl << endl;
402 cout << " solid-network listdevices" << endl;
403 cout << i18n(" # List the network devices present.\n") << endl;
405 cout << " solid-network listnetworks 'uni'" << endl;
406 cout << i18n(" # List the networks known to the device specified by 'uni'.\n") << endl;
408 cout << " solid-network query (status|wireless|wireless-hardware)|(interface 'uni')|(network 'device-uni' 'network-uni')" << endl;
409 cout << i18n(" # Query whether networking features are active or not.\n"
410 " # - If the 'status' option is given, return whether\n"
411 " # networking is enabled for the system\n"
412 " # - If the 'wireless' option is given, return whether\n"
413 " # wireless is enabled for the system\n"
414 " # - If the 'wireless-hardware' option is given,\n"
415 " # return whether the wireless hardware is enabled\n"
416 " # - If the 'interface' option is given, print the\n"
417 " # properties of the network interface that 'uni' refers to.\n"
418 " # - If the 'network' option is given, print the\n"
419 " # properties of the network on 'device-uni' that 'network-uni' refers to.\n") << endl;
421 cout << " solid-network set wireless (enabled|disabled)" << endl;
422 cout << i18n(" # Enable or disable networking on this system.\n") << endl;
424 cout << " solid-network set networking (enabled|disabled)" << endl;
425 cout << i18n(" # Enable or disable networking on this system.\n") << endl;
427 cout << " solid-network set network 'device-uni' 'network-uni' [authentication 'key']" << endl;
428 cout << i18n(" # Activate the network 'network-uni' on 'device-uni'.\n"
429 " # Optionally, use WEP128, open-system encryption with hex key 'key'. (Hardcoded)\n"
430 " # Where 'authentication' is one of:\n"
431 " # wep hex64|ascii64|hex128|ascii128|passphrase64|passphrase128 'key' [open|shared]\n"
432 " # wpapsk wpa|wpa2 tkip|ccmp-aes password\n"
433 " # wpaeap UNIMPLEMENTED IN SOLIDSHELL\n") << endl;
435 cout << endl;
437 return 0;
440 return SolidNetwork::doIt() ? 0 : 1;
443 bool SolidNetwork::doIt()
445 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
446 checkArgumentCount(1, 0);
448 QString command(args->arg(0));
450 int fake_argc = 0;
451 char **fake_argv = 0;
452 SolidNetwork shell(fake_argc, fake_argv);
454 if (command == "query")
456 checkArgumentCount(2, 4);
457 QString what(args->arg(1));
458 if (what == "status")
459 return shell.netmgrNetworkingEnabled();
460 else if (what == "wireless")
461 return shell.netmgrWirelessEnabled();
462 else if (what == "wireless-hardware")
463 return shell.netmgrWirelessHardwareEnabled();
464 else if (what == "interface")
466 checkArgumentCount(3, 3);
467 QString uni(args->arg(2));
468 return shell.netmgrQueryNetworkInterface(uni);
470 else if (what == "network")
472 checkArgumentCount(4, 4);
473 QString dev(args->arg(2));
474 QString uni(args->arg(3));
475 return shell.netmgrQueryNetwork(dev, uni);
477 else
478 cerr << i18n("Syntax Error: Unknown option '%1'", what) << endl;
480 else if (command == "set")
482 checkArgumentCount(3, 9);
483 QString what(args->arg(1));
484 QString how(args->arg(2));
485 if (what == "networking")
487 bool enabled;
488 if (how == "enabled")
490 enabled = true;
492 else if (how == "disabled")
494 enabled = false;
496 else
498 cerr << i18n("Syntax Error: Unknown option '%1'", how) << endl;
499 return false;
501 shell.netmgrChangeNetworkingEnabled(enabled);
502 return true;
504 else if (what == "wireless")
506 bool enabled;
507 if (how == "enabled")
509 enabled = true;
511 else if (how == "disabled")
513 enabled = false;
515 else
517 cerr << i18n("Syntax Error: Unknown option '%1'", how) << endl;
518 return false;
520 shell.netmgrChangeWirelessEnabled(enabled);
521 return true;
523 /*cout << " solid-network set network 'device-uni' 'network-uni' [authentication 'key']" << endl; */
524 /*wep hex64|ascii64|hex128|ascii128|passphrase 'key' [open|shared] */
525 /* wpaeap UNIMPLEMENTED */
526 else if (what == "network")
528 cerr << i18n("Not implemented");
529 #if 0 // probably won't be reimplemented since solidshell can't provide a persistent settings service...
530 checkArgumentCount(4, 9);
531 QString dev(args->arg(2));
532 QString uni(args->arg(3));
533 Solid::Control::Authentication * auth = 0;
534 QMap<QString,QString> secrets;
536 if (KCmdLineArgs::parsedArgs()->count() > 4)
538 QString hasAuth = args->arg(4);
539 if (hasAuth == "authentication")
541 //encrypted network
542 QString authScheme = args->arg(5);
543 if (authScheme == "wep")
545 Solid::Control::AuthenticationWep *wepAuth = new Solid::Control::AuthenticationWep();
546 QString keyType = args->arg(6);
547 if (keyType == "hex64")
549 wepAuth->setType(Solid::Control::AuthenticationWep::WepHex);
550 wepAuth->setKeyLength(64);
552 else if (keyType == "ascii64")
554 wepAuth->setType(Solid::Control::AuthenticationWep::WepAscii);
555 wepAuth->setKeyLength(64);
557 else if (keyType == "hex128")
559 wepAuth->setType(Solid::Control::AuthenticationWep::WepHex);
560 wepAuth->setKeyLength(128);
562 else if (keyType == "ascii128")
564 wepAuth->setType(Solid::Control::AuthenticationWep::WepAscii);
565 wepAuth->setKeyLength(128);
567 else if (keyType == "passphrase64")
569 wepAuth->setType(Solid::Control::AuthenticationWep::WepPassphrase);
570 wepAuth->setKeyLength(64);
572 else if (keyType == "passphrase128")
574 wepAuth->setType(Solid::Control::AuthenticationWep::WepPassphrase);
575 wepAuth->setKeyLength(128);
577 else
579 cerr << i18n("Unrecognised WEP type '%1'", keyType) << endl;
580 delete wepAuth;
581 return false;
584 QString key = args->arg(7);
585 secrets.insert("key", key);
586 wepAuth->setSecrets(secrets);
588 QString method = args->arg(8);
589 if (method == "open")
590 wepAuth->setMethod(Solid::Control::AuthenticationWep::WepOpenSystem);
591 else if (method == "shared")
592 wepAuth->setMethod(Solid::Control::AuthenticationWep::WepSharedKey);
593 else
595 cerr << i18n("Unrecognised WEP method '%1'", method) << endl;
596 delete wepAuth;
597 return false;
599 auth = wepAuth;
601 else if (authScheme == "wpapsk")
603 /* wpapsk wpa|wpa2 tkip|ccmp-aes password */
604 Solid::Control::AuthenticationWpaPersonal *wpapAuth = new Solid::Control::AuthenticationWpaPersonal();
605 QString version = args->arg(6);
606 if (version == "wpa")
607 wpapAuth->setVersion(Solid::Control::AuthenticationWpaPersonal::Wpa1);
608 else if (version == "wpa2")
609 wpapAuth->setVersion(Solid::Control::AuthenticationWpaPersonal::Wpa1);
610 else
612 cerr << i18n("Unrecognised WPA version '%1'", version) << endl;
613 delete wpapAuth;
614 return false;
616 QString protocol = args->arg(7);
617 if (protocol == "tkip")
618 wpapAuth->setProtocol(Solid::Control::AuthenticationWpaPersonal::WpaTkip);
619 else if (protocol == "ccmp-aes")
620 wpapAuth->setProtocol(Solid::Control::AuthenticationWpaPersonal::WpaCcmpAes);
621 else
623 cerr << i18n("Unrecognised WPA encryption protocol '%1'", protocol) << endl;
624 delete wpapAuth;
625 return false;
627 QString key = args->arg(8);
628 secrets.insert("key", key);
629 wpapAuth->setSecrets(secrets);
630 auth = wpapAuth;
632 else
634 cerr << i18n("Unimplemented auth scheme '%1'", args->arg(5)) << endl;
635 return false;
639 else
641 //unencrypted network
642 auth = new Solid::Control::AuthenticationNone;
645 return shell.netmgrActivateNetwork(dev, uni, auth);
646 delete auth;
647 #endif
649 else
651 cerr << i18n("Syntax Error: Unknown object '%1'", what) << endl;
652 return false;
655 else if (command == "listdevices")
657 return shell.netmgrList();
659 else if (command == "listnetworks")
661 checkArgumentCount(2, 2);
662 QString device(args->arg(1));
663 return shell.netmgrListNetworks(device);
665 else
667 cerr << i18n("Syntax Error: Unknown command '%1'" , command) << endl;
670 return false;
673 bool SolidNetwork::netmgrNetworkingEnabled()
675 if (Solid::Control::NetworkManager::isNetworkingEnabled())
676 cout << i18n("networking: is enabled")<< endl;
677 else
678 cout << i18n("networking: is not enabled")<< endl;
679 return Solid::Control::NetworkManager::isNetworkingEnabled();
682 bool SolidNetwork::netmgrWirelessEnabled()
684 if (Solid::Control::NetworkManager::isWirelessEnabled())
685 cout << i18n("wireless: is enabled")<< endl;
686 else
687 cout << i18n("wireless: is not enabled")<< endl;
688 return Solid::Control::NetworkManager::isWirelessEnabled();
691 bool SolidNetwork::netmgrWirelessHardwareEnabled()
693 if (Solid::Control::NetworkManager::isWirelessHardwareEnabled())
694 cout << i18n("wireless hardware: is enabled")<< endl;
695 else
696 cout << i18n("wireless hardware: is not enabled")<< endl;
697 return Solid::Control::NetworkManager::isWirelessHardwareEnabled();
700 bool SolidNetwork::netmgrChangeNetworkingEnabled(bool enabled)
702 Solid::Control::NetworkManager::setNetworkingEnabled(enabled);
703 return true;
706 bool SolidNetwork::netmgrChangeWirelessEnabled(bool enabled)
708 Solid::Control::NetworkManager::setWirelessEnabled(enabled);
709 return true;
712 bool SolidNetwork::netmgrList()
714 const Solid::Control::NetworkInterfaceList all = Solid::Control::NetworkManager::networkInterfaces();
716 cerr << "debug: network interface list contains: " << all.count() << " entries" << endl;
717 foreach (const Solid::Control::NetworkInterface *device, all)
719 cout << "UNI = '" << device->uni() << "'" << endl;
721 return true;
724 bool SolidNetwork::netmgrListNetworks(const QString & deviceUni)
726 Solid::Control::NetworkInterface * device = Solid::Control::NetworkManager::findNetworkInterface(deviceUni);
727 Solid::Control::WirelessNetworkInterface * wifiDev = qobject_cast<Solid::Control::WirelessNetworkInterface *>(device );
728 if (wifiDev) {
730 Solid::Control::AccessPointList aps = wifiDev->accessPoints();
731 foreach (const QString &apUni, aps)
733 cout << "NETWORK UNI = '" << apUni << "'" << endl;
736 return true;
738 return false;
741 bool SolidNetwork::netmgrQueryNetworkInterface(const QString & deviceUni)
743 cerr << "SolidNetwork::netmgrQueryNetworkInterface()" << endl;
744 Solid::Control::NetworkInterface * device = Solid::Control::NetworkManager::findNetworkInterface(deviceUni);
745 if (!device) {
746 cerr << "No such interface: " << deviceUni << endl;
747 return false;
749 Solid::Control::WirelessNetworkInterface * wifiDev = qobject_cast<Solid::Control::WirelessNetworkInterface *>(device);
750 Solid::Control::WiredNetworkInterface * wiredDev = qobject_cast<Solid::Control::WiredNetworkInterface *>(device);
751 if (wifiDev) {
752 cout << *wifiDev << endl;
753 } else if (wiredDev) {
754 cout << *wiredDev << endl;
755 } else {
756 cout << *device << endl;
758 return true;
761 bool SolidNetwork::netmgrQueryNetwork(const QString & deviceUni, const QString & apUni)
763 cerr << "SolidNetwork::netmgrQueryNetwork()" << endl;
764 Solid::Control::NetworkInterface * device = Solid::Control::NetworkManager::findNetworkInterface(deviceUni);
765 Solid::Control::WirelessNetworkInterface * wifiDev = qobject_cast<Solid::Control::WirelessNetworkInterface *>(device );
766 if (wifiDev) {
767 Solid::Control::AccessPoint * ap = wifiDev->findAccessPoint( apUni );
768 if ( ap ) {
769 cout << *ap << endl;
770 return true;
773 return false;
776 #if 0
777 bool SolidNetwork::netmgrActivateNetwork(const QString & deviceUni, const QString & networkUni, Solid::Control::Authentication * auth)
779 Solid::Control::NetworkInterface * device = Solid::Control::NetworkManager::findNetworkInterface(deviceUni);
780 Solid::Control::Network * network = device.findNetwork(networkUni);
781 Solid::Control::WirelessNetwork * wlan = 0;
782 if (( wlan = qobject_cast<Solid::Control::WirelessNetwork *>(network)))
784 wlan->setAuthentication(auth);
785 wlan->setActivated(true);
787 else
788 network->setActivated(true);
789 return true;
791 #endif
793 void SolidNetwork::connectJob(KJob *job)
795 connect(job, SIGNAL(result(KJob *)),
796 this, SLOT(slotResult(KJob *)));
797 connect(job, SIGNAL(percent(KJob *, unsigned long)),
798 this, SLOT(slotPercent(KJob *, unsigned long)));
799 connect(job, SIGNAL(infoMessage(KJob *, const QString &, const QString &)),
800 this, SLOT(slotInfoMessage(KJob *, const QString &)));
803 void SolidNetwork::slotPercent(KJob */*job */, unsigned long percent)
805 cout << i18n("Progress: %1%" , percent) << endl;
808 void SolidNetwork::slotInfoMessage(KJob */*job */, const QString &message)
810 cout << i18n("Info: %1" , message) << endl;
813 void SolidNetwork::slotResult(KJob *job)
815 m_error = 0;
817 if (job->error())
819 m_error = job->error();
820 m_errorString = job->errorString();
823 m_loop.exit();
826 void SolidNetwork::slotStorageResult(Solid::ErrorType error, const QVariant &errorData)
828 if (error) {
829 m_error = 1;
830 m_errorString = errorData.toString();
832 m_loop.exit();
835 #include "solid-network.moc"