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"
24 #include <QStringList>
25 #include <QMetaProperty>
29 #include <kcomponentdata.h>
30 #include <kcmdlineargs.h>
32 #include <k3socketaddress.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>
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
)
69 case QVariant::StringList
:
73 QStringList list
= value
.toStringList();
75 QStringList::ConstIterator it
= list
.constBegin();
76 QStringList::ConstIterator end
= list
.constEnd();
80 out
<< "'" << *it
<< "'";
88 out
<< "} (string list)";
92 out
<< (value
.toBool()?"true":"false") << " (bool)";
95 out
<< value
.toString()
96 << " (0x" << QString::number(value
.toInt(), 16) << ") (int)";
99 out
<< "'" << value
.toString() << "' (string)";
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
);
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()
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()) {
143 out
<< value
<< endl
;
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
;
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
;
175 if (networkdevice
.type() == Solid::Control::NetworkInterface::Ieee8023
) {
177 out
<< " Carrier Detect = " << (networkdevice
.capabilities() & Solid::Control::NetworkInterface::SupportsCarrierDetect
? "Yes" : "No") << endl
;
180 out
<< " Wireless Scan = " << (networkdevice
.capabilities() & Solid::Control::NetworkInterface::SupportsWirelessScan
? "Yes" : "No") << endl
;
182 out
<< " Link Up = " << (networkdevice
.isLinkUp() ? "Yes" : "No") << endl
;
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
;
199 case Solid::Control::WirelessNetworkInterface::Unassociated
:
200 cout
<< "Unassociated" << endl
;
202 case Solid::Control::WirelessNetworkInterface::Adhoc
:
203 cout
<< "Ad-hoc" << endl
;
205 case Solid::Control::WirelessNetworkInterface::Managed
:
206 cout
<< "Infrastructure" << endl
;
208 case Solid::Control::WirelessNetworkInterface::Master
:
209 cout
<< "Master" << endl
;
211 case Solid::Control::WirelessNetworkInterface::Repeater
:
212 cout
<< "Repeater" << endl
;
215 cout
<< "Unknown" << endl
;
216 cerr
<< "Unknown network operation mode: " << ap
.mode() << endl
;
219 out
<< " Capabilities = ";
220 const Solid::Control::AccessPoint::Capabilities cap
= ap
.capabilities();
223 if (cap
& Solid::Control::AccessPoint::Privacy
)
229 out
<< "(No Capabilities)" << endl
;
231 out
<< " WPA Options = ";
232 const Solid::Control::AccessPoint::WpaFlags wpaFlags
= ap
.wpaFlags();
235 if (wpaFlags
& Solid::Control::AccessPoint::PairWep40
)
237 if (wpaFlags
& Solid::Control::AccessPoint::PairWep104
)
238 out
<< "PairWep104,";
239 if (wpaFlags
& Solid::Control::AccessPoint::PairTkip
)
241 if (wpaFlags
& Solid::Control::AccessPoint::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
)
249 if (wpaFlags
& Solid::Control::AccessPoint::GroupCcmp
)
251 if (wpaFlags
& Solid::Control::AccessPoint::KeyMgmtPsk
)
252 out
<< "KeyMgmtPsk,";
253 if (wpaFlags
& Solid::Control::AccessPoint::KeyMgmt8021x
)
254 out
<< "KeyMgmt8021x,";
259 out
<< "(No Options)" << endl
;
261 out
<< " RSN Options = ";
262 const Solid::Control::AccessPoint::WpaFlags rsnFlags
= ap
.rsnFlags();
265 if (rsnFlags
& Solid::Control::AccessPoint::PairWep40
)
267 if (rsnFlags
& Solid::Control::AccessPoint::PairWep104
)
268 out
<< "PairWep104,";
269 if (rsnFlags
& Solid::Control::AccessPoint::PairTkip
)
271 if (rsnFlags
& Solid::Control::AccessPoint::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
)
279 if (rsnFlags
& Solid::Control::AccessPoint::GroupCcmp
)
281 if (rsnFlags
& Solid::Control::AccessPoint::KeyMgmtPsk
)
282 out
<< "KeyMgmtPsk,";
283 if (rsnFlags
& Solid::Control::AccessPoint::KeyMgmt8021x
)
284 out
<< "KeyMgmt8021x,";
289 out
<< "(No Options)" << endl
;
294 std::ostream
&operator<<(std::ostream
&out
, const Solid::Control::WirelessNetworkInterface
&network
)
296 out
<< static_cast<const Solid::Control::NetworkInterface
&>(network
);
299 switch (network
.mode())
301 case Solid::Control::WirelessNetworkInterface::Unassociated
:
302 cout
<< "Unassociated" << endl
;
304 case Solid::Control::WirelessNetworkInterface::Adhoc
:
305 cout
<< "Ad-hoc" << endl
;
307 case Solid::Control::WirelessNetworkInterface::Managed
:
308 cout
<< "Infrastructure" << endl
;
310 case Solid::Control::WirelessNetworkInterface::Master
:
311 cout
<< "Master" << endl
;
313 case Solid::Control::WirelessNetworkInterface::Repeater
:
314 cout
<< "Repeater" << endl
;
317 cout
<< "Unknown" << endl
;
318 cerr
<< "Unknown network operation mode: " << network
.mode() << endl
;
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();
328 if (cap
& Solid::Control::WirelessNetworkInterface::Wpa
)
330 if (cap
& Solid::Control::WirelessNetworkInterface::Wep40
)
332 if (cap
& Solid::Control::WirelessNetworkInterface::Wep104
)
334 if (cap
& Solid::Control::WirelessNetworkInterface::Tkip
)
336 if (cap
& Solid::Control::WirelessNetworkInterface::Ccmp
)
338 if (cap
& Solid::Control::WirelessNetworkInterface::Rsn
)
344 out
<< "(No Capabilities)" << endl
;
349 std::ostream
&operator<<(std::ostream
&out
, const Solid::Control::WiredNetworkInterface
&network
)
351 out
<< static_cast<const Solid::Control::NetworkInterface
&>(network
);
353 out
<< " Hardware Address = " << network
.hardwareAddress() << endl
;
354 out
<< " Bit Rate = " << network
.bitRate() << endl
;
355 out
<< " Carrier = " << qVariantFromValue(network
.carrier()) << endl
;
360 void checkArgumentCount(int min
, int max
)
362 int count
= KCmdLineArgs::parsedArgs()->count();
366 cerr
<< i18n("Syntax Error: Not enough arguments") << endl
;
370 if ((max
> 0) && (count
> max
))
372 cerr
<< i18n("Syntax Error: Too many arguments") << endl
;
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
;
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));
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
);
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")
488 if (how
== "enabled")
492 else if (how
== "disabled")
498 cerr
<< i18n("Syntax Error: Unknown option '%1'", how
) << endl
;
501 shell
.netmgrChangeNetworkingEnabled(enabled
);
504 else if (what
== "wireless")
507 if (how
== "enabled")
511 else if (how
== "disabled")
517 cerr
<< i18n("Syntax Error: Unknown option '%1'", how
) << endl
;
520 shell
.netmgrChangeWirelessEnabled(enabled
);
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")
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);
579 cerr
<< i18n("Unrecognised WEP type '%1'", keyType
) << endl
;
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
);
595 cerr
<< i18n("Unrecognised WEP method '%1'", method
) << endl
;
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
);
612 cerr
<< i18n("Unrecognised WPA version '%1'", version
) << endl
;
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
);
623 cerr
<< i18n("Unrecognised WPA encryption protocol '%1'", protocol
) << endl
;
627 QString key
= args
->arg(8);
628 secrets
.insert("key", key
);
629 wpapAuth
->setSecrets(secrets
);
634 cerr
<< i18n("Unimplemented auth scheme '%1'", args
->arg(5)) << endl
;
641 //unencrypted network
642 auth
= new Solid::Control::AuthenticationNone
;
645 return shell
.netmgrActivateNetwork(dev
, uni
, auth
);
651 cerr
<< i18n("Syntax Error: Unknown object '%1'", what
) << endl
;
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
);
667 cerr
<< i18n("Syntax Error: Unknown command '%1'" , command
) << endl
;
673 bool SolidNetwork::netmgrNetworkingEnabled()
675 if (Solid::Control::NetworkManager::isNetworkingEnabled())
676 cout
<< i18n("networking: is enabled")<< endl
;
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
;
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
;
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
);
706 bool SolidNetwork::netmgrChangeWirelessEnabled(bool enabled
)
708 Solid::Control::NetworkManager::setWirelessEnabled(enabled
);
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
;
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
);
730 Solid::Control::AccessPointList aps
= wifiDev
->accessPoints();
731 foreach (const QString
&apUni
, aps
)
733 cout
<< "NETWORK UNI = '" << apUni
<< "'" << endl
;
741 bool SolidNetwork::netmgrQueryNetworkInterface(const QString
& deviceUni
)
743 cerr
<< "SolidNetwork::netmgrQueryNetworkInterface()" << endl
;
744 Solid::Control::NetworkInterface
* device
= Solid::Control::NetworkManager::findNetworkInterface(deviceUni
);
746 cerr
<< "No such interface: " << deviceUni
<< endl
;
749 Solid::Control::WirelessNetworkInterface
* wifiDev
= qobject_cast
<Solid::Control::WirelessNetworkInterface
*>(device
);
750 Solid::Control::WiredNetworkInterface
* wiredDev
= qobject_cast
<Solid::Control::WiredNetworkInterface
*>(device
);
752 cout
<< *wifiDev
<< endl
;
753 } else if (wiredDev
) {
754 cout
<< *wiredDev
<< endl
;
756 cout
<< *device
<< endl
;
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
);
767 Solid::Control::AccessPoint
* ap
= wifiDev
->findAccessPoint( apUni
);
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);
788 network
->setActivated(true);
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
)
819 m_error
= job
->error();
820 m_errorString
= job
->errorString();
826 void SolidNetwork::slotStorageResult(Solid::ErrorType error
, const QVariant
&errorData
)
830 m_errorString
= errorData
.toString();
835 #include "solid-network.moc"