• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

solid-bluetooth.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
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 #include "solid-bluetooth.h"
00021 
00022 
00023 #include <QString>
00024 #include <QStringList>
00025 #include <QMetaProperty>
00026 #include <QMetaEnum>
00027 #include <QTimer>
00028 
00029 #include <kcomponentdata.h>
00030 #include <kcmdlineargs.h>
00031 #include <klocale.h>
00032 #include <k3socketaddress.h>
00033 #include <kdebug.h>
00034 
00035 #include <solid/device.h>
00036 #include <solid/genericinterface.h>
00037 #include <solid/storageaccess.h>
00038 #include <solid/opticaldrive.h>
00039 
00040 #include <solid/control/bluetoothmanager.h>
00041 #include <solid/control/bluetoothinterface.h>
00042 #include <solid/control/bluetoothremotedevice.h>
00043 #include <solid/control/bluetoothinputdevice.h>
00044 
00045 #include <kjob.h>
00046 
00047 
00048 #include <iostream>
00049 using namespace std;
00050 
00051 static const char appName[] = "solid-bluetooth";
00052 static const char programName[] = I18N_NOOP("solid-bluetooth");
00053 
00054 static const char description[] = I18N_NOOP("KDE tool for querying and controlling your hardware from the command line");
00055 
00056 static const char version[] = "0.1";
00057 
00058 std::ostream &operator<<(std::ostream &out, const QString &msg)
00059 {
00060     return (out << msg.toLocal8Bit().constData());
00061 }
00062 
00063 std::ostream &operator<<(std::ostream &out, const QVariant &value)
00064 {
00065     switch (value.type())
00066     {
00067     case QVariant::StringList:
00068     {
00069         out << "{";
00070 
00071         QStringList list = value.toStringList();
00072 
00073         QStringList::ConstIterator it = list.constBegin();
00074         QStringList::ConstIterator end = list.constEnd();
00075 
00076         for (; it!=end; ++it)
00077         {
00078             out << "'" << *it << "'";
00079 
00080             if (it+1!=end)
00081             {
00082                 out << ", ";
00083             }
00084         }
00085 
00086         out << "}  (string list)";
00087         break;
00088     }
00089     case QVariant::Bool:
00090         out << (value.toBool()?"true":"false") << "  (bool)";
00091         break;
00092     case QVariant::Int:
00093         out << value.toString()
00094             << "  (0x" << QString::number(value.toInt(), 16) << ")  (int)";
00095         break;
00096     default:
00097         out << "'" << value.toString() << "'  (string)";
00098         break;
00099     }
00100 
00101     return out;
00102 }
00103 
00104 std::ostream &operator<<(std::ostream &out, const Solid::Device &device)
00105 {
00106     out << "  parent = " << QVariant(device.parentUdi()) << endl;
00107     out << "  vendor = " << QVariant(device.vendor()) << endl;
00108     out << "  product = " << QVariant(device.product()) << endl;
00109 
00110     int index = Solid::DeviceInterface::staticMetaObject.indexOfEnumerator("Type");
00111     QMetaEnum typeEnum = Solid::DeviceInterface::staticMetaObject.enumerator(index);
00112 
00113     for (int i=0; i<typeEnum.keyCount(); i++)
00114     {
00115         Solid::DeviceInterface::Type type = (Solid::DeviceInterface::Type)typeEnum.value(i);
00116         const Solid::DeviceInterface *interface = device.asDeviceInterface(type);
00117 
00118         if (interface)
00119         {
00120             const QMetaObject *meta = interface->metaObject();
00121 
00122             for (int i=meta->propertyOffset(); i<meta->propertyCount(); i++)
00123             {
00124                 QMetaProperty property = meta->property(i);
00125                 out << "  " << QString(meta->className()).mid(7) << "." << property.name()
00126                     << " = ";
00127 
00128                 QVariant value = property.read(interface);
00129 
00130                 if (property.isEnumType()) {
00131                     QMetaEnum metaEnum = property.enumerator();
00132                     out << "'" << metaEnum.valueToKeys(value.toInt()).constData() << "'"
00133                         << "  (0x" << QString::number(value.toInt(), 16) << ")  ";
00134                     if (metaEnum.isFlag()) {
00135                         out << "(flag)";
00136                     } else {
00137                         out << "(enum)";
00138                     }
00139                     out << endl;
00140                 } else {
00141                     out << value << endl;
00142                 }
00143             }
00144         }
00145     }
00146 
00147     return out;
00148 }
00149 
00150 std::ostream &operator<<(std::ostream &out, const QMap<QString,QVariant> &properties)
00151 {
00152     foreach (const QString& key, properties.keys())
00153     {
00154         out << "  " << key << " = " << properties[key] << endl;
00155     }
00156 
00157     return out;
00158 }
00159 
00160 void checkArgumentCount(int min, int max)
00161 {
00162     int count = KCmdLineArgs::parsedArgs()->count();
00163 
00164     if (count < min)
00165     {
00166         cerr << i18n("Syntax Error: Not enough arguments") << endl;
00167         ::exit(1);
00168     }
00169 
00170     if ((max > 0) && (count > max))
00171     {
00172         cerr << i18n("Syntax Error: Too many arguments") << endl;
00173         ::exit(1);
00174     }
00175 }
00176 
00177 int main(int argc, char **argv)
00178 {
00179   KCmdLineArgs::init(argc, argv, appName, 0, ki18n(programName), version, ki18n(description), false);
00180 
00181 
00182   KCmdLineOptions options;
00183 
00184   options.add("commands", ki18n("Show available commands by domains"));
00185 
00186   options.add("+command", ki18n("Command (see --commands)"));
00187 
00188   options.add("+[arg(s)]", ki18n("Arguments for command"));
00189 
00190   KCmdLineArgs::addCmdLineOptions(options);
00191 
00192   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00193 
00194   KComponentData componentData(appName);
00195 
00196   if (args->isSet("commands"))
00197   {
00198       KCmdLineArgs::enable_i18n();
00199 
00200       cout << endl << i18n("Syntax:") << endl << endl;
00201 
00202       cout << "  solid-bluetooth listadapters" << endl;
00203       cout << i18n("             # List bluetooth adapters/interfaces\n") << endl;
00204 
00205       cout << "  solid-bluetooth defaultadapter" << endl;
00206       cout << i18n("             # List bluetooth default adapter/interface\n") << endl;
00207 
00208       cout << "  solid-bluetooth createdevice (interface 'ubi') 'remote-mac'" << endl;
00209       cout << i18n("             # Request to create a remote bluetooth device on the bus\n") << endl;
00210 
00211       cout << "  solid-bluetooth removedevice (interface 'ubi') 'remote-mac'" << endl;
00212       cout << i18n("             # Request to remove the remote bluetooth device from the bus\n") << endl;
00213 
00214       cout << "  solid-bluetooth getproperties (interface 'ubi') " << endl;
00215       cout << i18n("             # Request the properties from the bluetooth adapter\n") << endl;
00216 
00217 
00218 /*
00219       cout << "  solid-bluetooth getremotename (interface 'ubi') 'remote-mac'" << endl;
00220       cout << i18n("             # Query the name from the remote device 'remote-mac' with 'ubi'\n") << endl;
00221 
00222       cout << "  solid-bluetooth query (address|bondings|connections|name) (interface 'ubi')" << endl;
00223       cout << i18n("             # Query information about the bluetooth adapter/interface with 'ubi'\n") << endl;
00224 
00225       cout << "  solid-bluetooth set (mode|name) (interface 'ubi') 'value'" << endl;
00226       cout << i18n("             # Set the bluetooth adapter name.\n"
00227                     "             # Set the bluetooth adapter mode. Where 'value' is one of:\n"
00228                     "             # off|connectable|discoverable\n") << endl;
00229 
00230       cout << "  solid-bluetooth scan (interface 'ubi')" << endl;
00231       cout << i18n("             # Scan for bluetooth remote devices.\n") << endl;
00232 
00233       cout << "  solid-bluetooth input listdevices" << endl;
00234       cout << i18n("             # List configured input devices.\n") << endl;
00235 
00236       cout << "  solid-bluetooth input (setup|remove|connect|disconnect) (device 'ubi')" << endl;
00237       cout << i18n("             # Setup bluetooth input device.\n"
00238                     "             # Remove configuration of remote input device.\n"
00239                     "             # Connect or disconnect bluetooth input device.\n") << endl;
00240 
00241       cout << "  solid-bluetooth remote (createbonding|removebonding|hasbonding) (device 'ubi')" << endl;
00242       cout << i18n("             # Create bonding (pairing) with bluetooth remote device.\n"
00243                     "             # Remove bonding of bluetooth remote device.\n"
00244                     "             # Check for bonding of bluetooth remote device.\n") << endl;
00245 */
00246       return 0;
00247   }
00248 
00249   return SolidBluetooth::doIt() ? 0 : 1;
00250 }
00251 
00252 bool SolidBluetooth::doIt()
00253 {
00254     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00255     checkArgumentCount(1, 0);
00256 
00257     QString command(args->arg(0));
00258 
00259     int fake_argc = 0;
00260     char **fake_argv = 0;
00261     SolidBluetooth shell(fake_argc, fake_argv);
00262 
00263     if (command == "listadapters")
00264     {
00265         return shell.bluetoothListAdapters();
00266     } 
00267     else if (command == "defaultadapter")
00268     {
00269         return shell.bluetoothDefaultAdapter();
00270     }
00271     else if (command == "createdevice")
00272     {
00273         checkArgumentCount(3, 3);
00274         QString adapterUbi(args->arg(1));
00275         QString mac(args->arg(2));      
00276         return shell.bluetoothCreateDevice(adapterUbi, mac);
00277     }
00278     else if (command == "removedevice")
00279     {
00280         checkArgumentCount(3, 3);
00281         QString adapterUbi(args->arg(1));
00282         QString remoteUbi(args->arg(2));        
00283         return shell.bluetoothRemoveDevice(adapterUbi, remoteUbi);
00284     }
00285     else if (command == "getproperties")
00286     {
00287         checkArgumentCount(2, 2);
00288         QString ubi (args->arg(1));
00289         return shell.bluetoothGetProperties(ubi);
00290     }
00291 
00292 
00293 
00294 #if 0    
00295     else if (command == "getremotename")
00296     {
00297         checkArgumentCount(3, 3);
00298         QString adapterUbi(args->arg(1));
00299         QString mac(args->arg(2));      
00300         return shell.bluetoothGetRemoteName(adapterUbi, mac);
00301     }
00302     else if (command == "set")
00303     {
00304         checkArgumentCount(4, 4);
00305         QString what(args->arg(1));
00306         QString ubi(args->arg(2));
00307         QString value(args->arg(3));
00308 
00309         if (what == "name")
00310         {
00311             return shell.bluetoothAdapterSetName(ubi, value);
00312         }
00313         else if (what == "mode")
00314         {
00315             return shell.bluetoothAdapterSetMode(ubi, value);
00316         }
00317 
00318     }
00319     else if (command == "query")
00320     {
00321         checkArgumentCount(3, 3);
00322         QString what(args->arg(1));
00323         QString ubi(args->arg(2));
00324 
00325         if (what == "mode")
00326         {
00327             return shell.bluetoothAdapterMode(ubi);
00328         }
00329         else if (what == "address")
00330         {
00331             return shell.bluetoothAdapterAddress(ubi);
00332         }
00333         else if (what == "name")
00334         {
00335             return shell.bluetoothAdapterName(ubi);
00336         }
00337         else if (what == "connections")
00338         {
00339             return shell.bluetoothAdapterListConnections(ubi);
00340         }
00341         else if (what == "bondings")
00342         {
00343             return shell.bluetoothAdapterListBondings(ubi);
00344         }
00345 
00346     }
00347     else if (command == "scan")
00348     {
00349         checkArgumentCount(2, 2);
00350         QString ubi (args->arg(1));
00351         return shell.bluetoothAdapterScan(ubi);
00352     }
00353     else if (command == "input")
00354     {
00355         checkArgumentCount(2, 3);
00356         QString what (args->arg(1));
00357 
00358         if (what == "listdevices")
00359         {
00360             return shell.bluetoothInputListDevices();
00361         }
00362 
00363         checkArgumentCount(3, 3);
00364         QString ubi (args->arg(2));
00365 
00366         if (what == "setup")
00367         {
00368             return shell.bluetoothInputSetup(ubi);
00369         }
00370         else if (what == "remove")
00371         {
00372             return shell.bluetoothInputRemoveSetup(ubi);
00373         }
00374         else if (what == "connect")
00375         {
00376             return shell.bluetoothInputConnect(ubi);
00377         }
00378         else if (what == "disconnect")
00379         {
00380             return shell.bluetoothInputDisconnect(ubi);
00381         }
00382     }
00383     else if (command == "remote" && args->count() >= 3)
00384     {
00385         checkArgumentCount(4, 4);
00386         QString what (args->arg(1));
00387         QString adapter (args->arg(2));
00388         QString remote (args->arg(3));
00389 
00390         if (what == "createbonding")
00391         {
00392             return shell.bluetoothRemoteCreateBonding(adapter, remote);
00393         }
00394         else if (what == "removebonding")
00395         {
00396             return shell.bluetoothRemoteRemoveBonding(adapter, remote);
00397         }
00398         else if (what == "hasbonding")
00399         {
00400             return shell.bluetoothRemoteHasBonding(adapter, remote);
00401         }
00402 
00403     }
00404 #endif    
00405     else
00406     {
00407         cerr << i18n("Syntax Error: Unknown command '%1'" , command) << endl;
00408     }
00409 
00410     return false;
00411 }
00412 
00413 bool SolidBluetooth::bluetoothListAdapters()
00414 {
00415     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00416 
00417     foreach (Solid::Control::BluetoothInterface device, manager.bluetoothInterfaces())
00418     {
00419         cout << "UBI = '" << device.ubi() << "'" << endl;
00420     }
00421     return true;
00422 }
00423 
00424 bool SolidBluetooth::bluetoothDefaultAdapter()
00425 {
00426     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00427 
00428     cout << "UBI = '" <<  manager.defaultInterface() << "'" << endl;
00429 
00430     return true;
00431 }
00432 
00433 bool SolidBluetooth::bluetoothCreateDevice(const QString &adapterUbi, const QString &/*mac*/)
00434 {
00435     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00436     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00437 //    QString remoteDeviceUBI = adapter.createDevice(mac);
00438 //    cout << "Remote Device UBI: " << remoteDeviceUBI << endl;
00439     return true;
00440 }
00441 
00442 bool SolidBluetooth::bluetoothRemoveDevice(const QString &adapterUbi, const QString &/*remoteDeviceUbi*/)
00443 {
00444     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00445     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00446 //    adapter.removeDevice(remoteDeviceUbi);
00447     return true;
00448 }
00449 
00450 bool SolidBluetooth::bluetoothGetProperties(const QString &adapterUbi)
00451 {
00452     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00453     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00454     QMap<QString,QVariant> props = adapter.getProperties();
00455     foreach (QString valName, props.keys()) {
00456         cout << valName << ": " << props[valName] << endl;
00457     }
00458     return true;
00459 }
00460 
00461 
00462 #if 0
00463 bool SolidBluetooth::bluetoothGetRemoteName(const QString &adapterUbi, const QString &mac)
00464 {
00465     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00466     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00467 
00468     cout << "Name = '" <<  adapter.getRemoteName(mac) << "'" << endl;
00469 
00470     return true;
00471 }
00472 
00473 bool SolidBluetooth::bluetoothAdapterAddress(const QString &ubi)
00474 {
00475     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00476     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00477 
00478     cout << "'" <<  adapter.address() << "'" << endl;
00479 
00480     return true;
00481 }
00482 
00483 bool SolidBluetooth::bluetoothAdapterName(const QString &ubi)
00484 {
00485     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00486     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00487 
00488     cout << "'" <<  adapter.name() << "'" << endl;
00489 
00490     return true;
00491 }
00492 
00493 bool SolidBluetooth::bluetoothAdapterSetName(const QString &ubi, const QString &name)
00494 {
00495     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00496     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00497 
00498     adapter.setName(name);
00499 
00500     return true;
00501 }
00502 
00503 bool SolidBluetooth::bluetoothAdapterMode(const QString &ubi)
00504 {
00505     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00506     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00507 
00508     cout << "'" <<  adapter.mode() << "'" << endl;
00509 
00510     return true;
00511 }
00512 
00513 bool SolidBluetooth::bluetoothAdapterSetMode(const QString &ubi, const QString &mode)
00514 {
00515     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00516     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00517     Solid::Control::BluetoothInterface::Mode modeEnum(Solid::Control::BluetoothInterface::Off);
00518     if (mode == "off")
00519     {
00520         modeEnum = Solid::Control::BluetoothInterface::Off;
00521     }
00522     else if (mode == "connectable")
00523     {
00524         modeEnum = Solid::Control::BluetoothInterface::Connectable;
00525     }
00526     else if (mode == "discoverable")
00527     {
00528         modeEnum = Solid::Control::BluetoothInterface::Discoverable;
00529     }
00530     adapter.setMode(modeEnum);
00531 
00532     return true;
00533 }
00534 
00535 bool SolidBluetooth::bluetoothAdapterListConnections(const QString &ubi)
00536 {
00537     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00538     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00539 
00540     const Solid::Control::BluetoothRemoteDeviceList all = adapter.listConnections();
00541 
00542     cout << "Current connections of Bluetooth Adapter: " << ubi << endl;
00543     foreach (const Solid::Control::BluetoothRemoteDevice device, all)
00544     {
00545         cout << "UBI = '" << device.ubi() << "'" << endl;
00546     }
00547     return true;
00548 }
00549 
00550 bool SolidBluetooth::bluetoothAdapterListBondings(const QString &ubi)
00551 {
00552     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00553     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00554 
00555     const QStringList all = adapter.listBondings();
00556 
00557     cout << "Current bonded/paired remote bluetooth devices of Bluetooth Adapter: " << ubi << endl;
00558     foreach (const QString device, all)
00559     {
00560         cout << "UBI = '" << device << "'" << endl;
00561     }
00562     return true;
00563 }
00564 
00565 bool SolidBluetooth::bluetoothAdapterScan(const QString &ubi)
00566 {
00567     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00568     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(ubi);
00569 
00570     connect(&adapter, SIGNAL(remoteDeviceFound(const QString &, int, int)),
00571            this, SLOT(slotBluetoothDeviceFound(const QString &, int, int)));
00572     connect(&adapter, SIGNAL(discoveryCompleted()),
00573            this, SLOT(slotBluetoothDiscoveryCompleted()));
00574 
00575     adapter.discoverDevices();
00576     // Workaround for the fakebluetooth backend... quit the discovery after 30 seconds
00577     QTimer::singleShot(30000, this, SLOT(slotBluetoothDiscoveryCompleted()));
00578     cout << "Searching ..." << endl;
00579     m_loop.exec();
00580 
00581     return true;
00582 }
00583 
00584 void SolidBluetooth::slotBluetoothDeviceFound(const QString &ubi, int deviceClass, int rssi)
00585 {
00586     cout << QString("['%1','%2','%3']").arg(ubi).arg(deviceClass).arg(rssi) << endl;
00587 }
00588 
00589 void SolidBluetooth::slotBluetoothDiscoveryCompleted()
00590 {
00591     kDebug() ;
00592     m_loop.exit();
00593 }
00594 
00595 bool SolidBluetooth::bluetoothInputListDevices()
00596 {
00597     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00598     const Solid::Control::BluetoothInputDeviceList all = manager.bluetoothInputDevices();
00599 
00600     foreach (const Solid::Control::BluetoothInputDevice device, all)
00601     {
00602         cout << "UBI = '" << device.ubi() << "'" << endl;
00603     }
00604 
00605     return true;
00606 }
00607 
00608 bool SolidBluetooth::bluetoothInputSetup(const QString &deviceUbi)
00609 {
00610     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00611     KJob *job = manager.setupInputDevice(deviceUbi);
00612 
00613     if (job==0)
00614     {
00615         cerr << i18n("Error: unsupported operation!") << endl;
00616         return false;
00617     }
00618 
00619     connectJob(job);
00620 
00621     job->start();
00622     m_loop.exec();
00623 
00624     if (m_error)
00625     {
00626         cerr << i18n("Error: %1" , m_errorString) << endl;
00627         return false;
00628     }
00629 
00630     return true;
00631 }
00632 
00633 bool SolidBluetooth::bluetoothInputRemoveSetup(const QString &deviceUbi)
00634 {
00635     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00636 
00637     manager.removeInputDevice(deviceUbi);
00638 
00639     return true;
00640 }
00641 
00642 bool SolidBluetooth::bluetoothInputConnect(const QString &deviceUbi)
00643 {
00644     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00645     Solid::Control::BluetoothInputDevice device = manager.findBluetoothInputDevice(deviceUbi);
00646 
00647     device.slotConnect();
00648 
00649     return true;
00650 }
00651 
00652 bool SolidBluetooth::bluetoothInputDisconnect(const QString &deviceUbi)
00653 {
00654     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00655     Solid::Control::BluetoothInputDevice device = manager.findBluetoothInputDevice(deviceUbi);
00656 
00657     device.slotDisconnect();
00658 
00659     return true;
00660 }
00661 
00662 bool SolidBluetooth::bluetoothRemoteCreateBonding(const QString &adapterUbi, const QString &deviceUbi)
00663 {
00664     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00665     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00666     Solid::Control::BluetoothRemoteDevice device = adapter.findBluetoothRemoteDevice(deviceUbi);
00667 
00668     KJob *job = device.createBonding();
00669 
00670     connectJob(job);
00671 
00672     job->start();
00673     m_loop.exec();
00674 
00675     if (m_error)
00676     {
00677         cerr << i18n("Error: %1" , m_errorString) << endl;
00678         return false;
00679     }
00680 
00681     return true;
00682 }
00683 
00684 bool SolidBluetooth::bluetoothRemoteRemoveBonding(const QString &adapterUbi, const QString &deviceUbi)
00685 {
00686     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00687     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00688     Solid::Control::BluetoothRemoteDevice device = adapter.findBluetoothRemoteDevice(deviceUbi);
00689 
00690     device.removeBonding();
00691 
00692     return true;
00693 }
00694 
00695 bool SolidBluetooth::bluetoothRemoteHasBonding(const QString &adapterUbi, const QString &deviceUbi)
00696 {
00697     Solid::Control::BluetoothManager &manager = Solid::Control::BluetoothManager::self();
00698     Solid::Control::BluetoothInterface adapter = manager.findBluetoothInterface(adapterUbi);
00699     Solid::Control::BluetoothRemoteDevice device = adapter.findBluetoothRemoteDevice(deviceUbi);
00700 
00701     if (device.hasBonding())
00702     {
00703         cout << "'" << deviceUbi << "' is bonded/paired." << endl;
00704     } else {
00705         cout << "'" << deviceUbi << "' is not bonded/paired." << endl;
00706     }
00707 
00708     return true;
00709 }
00710 
00711 void SolidBluetooth::connectJob(KJob *job)
00712 {
00713     connect(job, SIGNAL(result(KJob *)),
00714              this, SLOT(slotResult(KJob *)));
00715     connect(job, SIGNAL(percent(KJob *, unsigned long)),
00716              this, SLOT(slotPercent(KJob *, unsigned long)));
00717     connect(job, SIGNAL(infoMessage(KJob *, const QString &, const QString &)),
00718              this, SLOT(slotInfoMessage(KJob *, const QString &)));
00719 }
00720 
00721 void SolidBluetooth::slotPercent(KJob */*job */, unsigned long percent)
00722 {
00723     cout << i18n("Progress: %1%" , percent) << endl;
00724 }
00725 
00726 void SolidBluetooth::slotInfoMessage(KJob */*job */, const QString &message)
00727 {
00728     cout << i18n("Info: %1" , message) << endl;
00729 }
00730 
00731 void SolidBluetooth::slotResult(KJob *job)
00732 {
00733     m_error = 0;
00734 
00735     if (job->error())
00736     {
00737         m_error = job->error();
00738         m_errorString = job->errorString();
00739     }
00740 
00741     m_loop.exit();
00742 }
00743 
00744 void SolidBluetooth::slotStorageResult(Solid::ErrorType error, const QVariant &errorData)
00745 {
00746     if (error) {
00747         m_error = 1;
00748         m_errorString = errorData.toString();
00749     }
00750     m_loop.exit();
00751 }
00752 #endif
00753 
00754 #include "solid-bluetooth.moc"

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal