Solid
Tutorial 5
Back to Overview | Tutorial 1 | Tutorial 2 | Tutorial 3 | Tutorial 4 | Tutorial 5
00001 /* This file is part of the KDE project 00002 Copyright (C) 2007 Christopher Blauvelt <cblauvelt@gmail.com> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 00018 */ 00019 00020 //QT specific includes 00021 #include <QList> 00022 00023 //solid specific includes 00024 #include <solid/deviceinterface.h> 00025 #include <solid/networking.h> 00026 #include <solid/device.h> 00027 #include <solid/networkinterface.h> 00028 00029 //kde specific includes 00030 #include <kcomponentdata.h> 00031 #include <kcmdlineargs.h> 00032 #include <klocale.h> 00033 #include <kdebug.h> 00034 00035 #include <iostream> 00036 00037 using namespace std; 00038 00039 int main(int args, char **argv) 00040 { 00041 KComponentData data("tutorial5"); 00042 00043 //get a Network Device 00044 QList<Solid::Device> netlist = Solid::Device::listFromType(Solid::DeviceInterface::NetworkInterface, QString()); 00045 00046 //check to see if no network devices were found 00047 if(netlist.empty()) 00048 { 00049 kDebug() << "No network devices found!"; 00050 return 0; 00051 } 00052 00053 Solid::Device device = netlist[0]; 00054 Solid::NetworkInterface *netdev = device.as<Solid::NetworkInterface>(); 00055 //keep the program from crashing in the event that there's a bug in solid 00056 if(!netdev) 00057 { 00058 kDebug() << "Device could not be converted. There is a bug."; 00059 return 0; 00060 } 00061 00062 kDebug() << "The iface of " << device.udi() << " is " << netdev->ifaceName(); 00063 00064 return 0; 00065 } 00066 00067 #include "tutorial5.moc"