Commit 52bd6afb authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Use usableAdapter instead of defaultAdapter

defaultAdapter has been removed from BlueZ5 because it was problematic,
we had our share of problems with it so we implemented usableAdapter
which basically does what defaultAdapter does but additionally checks
isPowered.

CCBUG:314356
parent e4d1cfb4
......@@ -30,13 +30,13 @@
using namespace BlueDevil;
AudioHelper::AudioHelper(const KUrl& address) {
if (!BlueDevil::Manager::self()->defaultAdapter()) {
if (!BlueDevil::Manager::self()->usableAdapter()) {
qDebug() << "No Adapters found";
qApp->exit();
return;
}
Device *device = Manager::self()->defaultAdapter()->deviceForAddress(address.host().replace("-", ":"));
Device *device = Manager::self()->usableAdapter()->deviceForAddress(address.host().replace("-", ":"));
if(device->isPaired()) {
QString constraint("'00001108-0000-1000-8000-00805F9B34FB' in [X-BlueDevil-UUIDS]");
......
......@@ -32,13 +32,13 @@
using namespace BlueDevil;
InputHelper::InputHelper(const KUrl& address) {
if (!BlueDevil::Manager::self()->defaultAdapter()) {
if (!BlueDevil::Manager::self()->usableAdapter()) {
qDebug() << "No Adapters found";
qApp->exit();
return;
}
Device *device = Manager::self()->defaultAdapter()->deviceForAddress(address.host().replace("-", ":"));
Device *device = Manager::self()->usableAdapter()->deviceForAddress(address.host().replace("-", ":"));
device->UUIDs();
WizardAgent *agent = new WizardAgent(qApp);
......
......@@ -32,13 +32,13 @@
using namespace BlueDevil;
NetworkDUNHelper::NetworkDUNHelper(const KUrl& address) {
if (!BlueDevil::Manager::self()->defaultAdapter()) {
if (!BlueDevil::Manager::self()->usableAdapter()) {
qDebug() << "No Adapters found";
qApp->exit();
return;
}
Device *device = Manager::self()->defaultAdapter()->deviceForAddress(address.host().replace("-", ":"));
Device *device = Manager::self()->usableAdapter()->deviceForAddress(address.host().replace("-", ":"));
if(device->isPaired()) {
QString constraint("'00001103-0000-1000-8000-00805F9B34FB' in [X-BlueDevil-UUIDS]");
......
......@@ -32,13 +32,13 @@
using namespace BlueDevil;
NetworkPANUHelper::NetworkPANUHelper(const KUrl& address) {
if (!BlueDevil::Manager::self()->defaultAdapter()) {
if (!BlueDevil::Manager::self()->usableAdapter()) {
qDebug() << "No Adapters found";
qApp->exit();
return;
}
Device *device = Manager::self()->defaultAdapter()->deviceForAddress(address.host().replace("-", ":"));
Device *device = Manager::self()->usableAdapter()->deviceForAddress(address.host().replace("-", ":"));
if(device->isPaired()) {
QString constraint("'00001116-0000-1000-8000-00805F9B34FB' in [X-BlueDevil-UUIDS]");
......
......@@ -40,7 +40,7 @@ DiscoverWidget::DiscoverWidget(QWidget* parent)
connect(deviceList, SIGNAL(itemActivated(QListWidgetItem*)), this,
SLOT(itemSelected(QListWidgetItem*)));
connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(QVariantMap)), this,
connect(Manager::self()->usableAdapter(), SIGNAL(deviceFound(QVariantMap)), this,
SLOT(deviceFound(QVariantMap)));
startScan();
......@@ -55,19 +55,19 @@ void DiscoverWidget::startScan()
deviceList->clear();
stopScan();
QList <Device *> knownDevices = Manager::self()->defaultAdapter()->devices();
QList <Device *> knownDevices = Manager::self()->usableAdapter()->devices();
Q_FOREACH(Device *device, knownDevices) {
if (device->UUIDs().contains("00001105-0000-1000-8000-00805F9B34FB", Qt::CaseInsensitive)) {
deviceFound(device);
}
}
Manager::self()->defaultAdapter()->startDiscovery();
Manager::self()->usableAdapter()->startDiscovery();
}
void DiscoverWidget::stopScan()
{
if (Manager::self()->defaultAdapter()) {
Manager::self()->defaultAdapter()->stopDiscovery();
if (Manager::self()->usableAdapter()) {
Manager::self()->usableAdapter()->stopDiscovery();
}
}
......@@ -117,7 +117,7 @@ void DiscoverWidget::deviceFoundGeneric(QString address, QString name, QString i
m_itemRelation[address]->setData(Qt::UserRole+1, origName);
if (deviceList->currentItem() == m_itemRelation[address]) {
emit deviceSelected(Manager::self()->defaultAdapter()->deviceForAddress(address));
emit deviceSelected(Manager::self()->usableAdapter()->deviceForAddress(address));
}
return;
}
......@@ -132,5 +132,5 @@ void DiscoverWidget::deviceFoundGeneric(QString address, QString name, QString i
void DiscoverWidget::itemSelected(QListWidgetItem* item)
{
emit deviceSelected(Manager::self()->defaultAdapter()->deviceForAddress(item->data(Qt::UserRole).toString()));
emit deviceSelected(Manager::self()->usableAdapter()->deviceForAddress(item->data(Qt::UserRole).toString()));
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ ConnectingPage::ConnectingPage(QWidget* parent): QWizardPage(parent)
void ConnectingPage::initializePage()
{
Manager::self()->defaultAdapter()->stopDiscovery();
Manager::self()->usableAdapter()->stopDiscovery();
Device *device = static_cast<SendFileWizard* >(wizard())->device();
connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecting to %1...", device->name()));
......
......@@ -47,7 +47,7 @@ SendFileWizard::SendFileWizard(const QString& deviceInfo, const QStringList& fil
, m_device(0)
, m_job(0)
{
if (!BlueDevil::Manager::self()->defaultAdapter()) {
if (!BlueDevil::Manager::self()->usableAdapter()) {
kDebug() << "No Adapters found";
qApp->exit();
return;
......@@ -132,9 +132,9 @@ void SendFileWizard::setDevice(QString deviceUrl)
deviceUrl.replace(":", "-");
deviceUrl.prepend("bluetooth:");
KUrl url(deviceUrl);
device = Manager::self()->defaultAdapter()->deviceForAddress(url.host().replace("-", ":"));
device = Manager::self()->usableAdapter()->deviceForAddress(url.host().replace("-", ":"));
} else {
device = Manager::self()->defaultAdapter()->deviceForUBI(deviceUrl);
device = Manager::self()->usableAdapter()->deviceForUBI(deviceUrl);
}
if (!device->isReady()) {
......
......@@ -66,7 +66,7 @@ Authorize::Authorize()
void Authorize::trust()
{
qDebug() << "Trusted";
BlueDevil::Manager::self()->defaultAdapter()->deviceForUBI(qApp->arguments()[2])->setTrusted(true);
BlueDevil::Manager::self()->usableAdapter()->deviceForUBI(qApp->arguments()[2])->setTrusted(true);
qApp->exit(0);
}
......
......@@ -51,7 +51,7 @@ ServerSession::ServerSession(const QString& path, const QString& bluetoothAddres
m_deleteLater = false;
m_doNotDelete = false;
m_bluetoothDevice = BlueDevil::Manager::self()->defaultAdapter()->deviceForAddress(bluetoothAddress);
m_bluetoothDevice = BlueDevil::Manager::self()->usableAdapter()->deviceForAddress(bluetoothAddress);
QDBusConnection* dbus = new QDBusConnection("dbus");
QDBusConnection dbusConnection = dbus->connectToBus(QDBusConnection::SessionBus, "dbus");
m_dbusServerSession = new org::openobex::ServerSession("org.openobex", path, dbusConnection,
......
......@@ -62,19 +62,19 @@ void Service::launchServer()
connect(m_watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(openobexUnregistered()));
}
if (BlueDevil::Manager::self()->defaultAdapter()) {
if (BlueDevil::Manager::self()->usableAdapter()) {
FileReceiverSettings::self()->readConfig();
if (FileReceiverSettings::enabled()) {
if (!m_server) {
kDebug() << "Launching Server";
m_server = new OpenObex::Server(BlueDevil::Manager::self()->defaultAdapter()->address());
m_server = new OpenObex::Server(BlueDevil::Manager::self()->usableAdapter()->address());
}
}
if (FileReceiverSettings::shareEnabled()) {
if (!m_serverftp) {
kDebug() << "Launching FileSharing";
m_serverftp = new OpenObex::ServerFtp(BlueDevil::Manager::self()->defaultAdapter()->address());
m_serverftp = new OpenObex::ServerFtp(BlueDevil::Manager::self()->usableAdapter()->address());
}
}
} else{
......
......@@ -92,14 +92,14 @@ BlueDevilDaemon::BlueDevilDaemon(QObject *parent, const QList<QVariant>&)
aboutData.addAuthor(ki18n("Eduardo Robles Elvira"), ki18n("Maintainer"), "edulix@gmail.com",
"http://blog.edulix.es");
connect(Manager::self(), SIGNAL(defaultAdapterChanged(Adapter*)),
this, SLOT(defaultAdapterChanged(Adapter*)));
connect(Manager::self(), SIGNAL(usableAdapterChanged(Adapter*)),
this, SLOT(usableAdapterChanged(Adapter*)));
connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(Device*)), this, SLOT(deviceFound(Device*)));
connect(&d->m_timer, SIGNAL(timeout()), Manager::self()->defaultAdapter(), SLOT(stopDiscovery()));
connect(Manager::self()->usableAdapter(), SIGNAL(deviceFound(Device*)), this, SLOT(deviceFound(Device*)));
connect(&d->m_timer, SIGNAL(timeout()), Manager::self()->usableAdapter(), SLOT(stopDiscovery()));
d->m_status = Private::Offline;
if (Manager::self()->defaultAdapter()) {
if (Manager::self()->usableAdapter()) {
onlineMode();
}
}
......@@ -125,7 +125,7 @@ QMapDeviceInfo BlueDevilDaemon::knownDevices()
{
QMapDeviceInfo devices;
QList <Device* > list = Manager::self()->defaultAdapter()->devices();
QList <Device* > list = Manager::self()->usableAdapter()->devices();
kDebug() << "List: " << list.length();
DeviceInfo info;
Q_FOREACH(const Device* device, list) {
......@@ -137,7 +137,7 @@ QMapDeviceInfo BlueDevilDaemon::knownDevices()
if (!d->m_timer.isActive()) {
kDebug() << "Start Discovery";
Manager::self()->defaultAdapter()->startStableDiscovery();
Manager::self()->usableAdapter()->startStableDiscovery();
d->m_discovered.clear();
d->m_timer.start();
}
......@@ -154,7 +154,7 @@ void BlueDevilDaemon::stopDiscovering()
{
kDebug() << "Stopping discovering";
d->m_timer.stop();
Manager::self()->defaultAdapter()->stopDiscovery();
Manager::self()->usableAdapter()->stopDiscovery();
}
bool BlueDevilDaemon::isServiceStarted()
......@@ -182,7 +182,7 @@ void BlueDevilDaemon::onlineMode()
d->m_bluezAgent = new BluezAgent(new QObject());
connect(d->m_bluezAgent, SIGNAL(agentReleased()), this, SLOT(agentReleased()));
d->m_adapter = Manager::self()->defaultAdapter();
d->m_adapter = Manager::self()->usableAdapter();
FileReceiverSettings::self()->readConfig();
if (!isServiceStarted() && FileReceiverSettings::self()->enabled()) {
......@@ -259,7 +259,7 @@ void BlueDevilDaemon::agentReleased()
//TODO think what to do
}
void BlueDevilDaemon::defaultAdapterChanged(Adapter *adapter)
void BlueDevilDaemon::usableAdapterChanged(Adapter *adapter)
{
//if we have an adapter, remove it and offline the KDED for a moment
if (d->m_adapter) {
......
......@@ -79,7 +79,7 @@ private Q_SLOTS:
* Called when the default adapter changes, re-initialize the kded with the new
* default adapter
*/
void defaultAdapterChanged(Adapter *adapter);
void usableAdapterChanged(Adapter *adapter);
/**
* When the agent is released this is called to unload it
......
......@@ -38,7 +38,7 @@ BluezAgent::BluezAgent(QObject *parent)
return;
}
m_adapter = BlueDevil::Manager::self()->defaultAdapter();
m_adapter = BlueDevil::Manager::self()->usableAdapter();
m_adapter->registerAgent(AGENT_PATH, BlueDevil::Adapter::DisplayYesNo);
m_process = new QProcess(this);
......@@ -49,9 +49,9 @@ BluezAgent::BluezAgent(QObject *parent)
void BluezAgent::unregister()
{
qDebug() << "Unregistering object";
BlueDevil::Adapter *const defaultAdapter = BlueDevil::Manager::self()->defaultAdapter();
if (defaultAdapter) {
defaultAdapter->unregisterAgent(AGENT_PATH);
BlueDevil::Adapter *const usableAdapter = BlueDevil::Manager::self()->usableAdapter();
if (usableAdapter) {
usableAdapter->unregisterAgent(AGENT_PATH);
}
QDBusConnection::systemBus().unregisterObject(AGENT_PATH);
parent()->deleteLater();
......
......@@ -82,11 +82,11 @@ ObexFtpDaemon::ObexFtpDaemon(QObject *parent, const QList<QVariant>&)
aboutData.addAuthor(ki18n("Alejandro Fiestas Olivares"), ki18n("Maintainer"), "afiestas@kde.org",
"http://www.afiestas.org");
connect(Manager::self(), SIGNAL(defaultAdapterChanged(Adapter*)),
this, SLOT(defaultAdapterChanged(Adapter*)));
connect(Manager::self(), SIGNAL(usableAdapterChanged(Adapter*)),
this, SLOT(usableAdapterChanged(Adapter*)));
d->m_status = Private::Offline;
if (Manager::self()->defaultAdapter()) {
if (Manager::self()->usableAdapter()) {
onlineMode();
}
......@@ -140,7 +140,7 @@ void ObexFtpDaemon::offlineMode()
d->m_status = Private::Offline;
}
void ObexFtpDaemon::defaultAdapterChanged(Adapter *adapter)
void ObexFtpDaemon::usableAdapterChanged(Adapter *adapter)
{
if (adapter) {
onlineMode();
......
......@@ -73,7 +73,7 @@ private Q_SLOTS:
* Called when the default adapter changes, re-initialize the kded with the new
* default adapter
*/
void defaultAdapterChanged(Adapter *adapter);
void usableAdapterChanged(Adapter *adapter);
void SessionConnected(QDBusObjectPath path);
......
......@@ -53,10 +53,10 @@ QList< QAction* > SendFileItemAction::actions(const KFileItemListProperties& fil
hack->m_fileItemInfos = fileItemInfos;
//If there is no adaptor, there is no bluetooth
if (!Manager::self()->defaultAdapter()) {
if (!Manager::self()->usableAdapter()) {
return list;
}
Adapter *adapter = Manager::self()->defaultAdapter();
Adapter *adapter = Manager::self()->usableAdapter();
QAction *menuAction = new QAction(KIcon("preferences-system-bluetooth"), i18n("Send via Bluetooth"), hack);
QMenu *menu = new QMenu();
......
......@@ -117,7 +117,7 @@ AdapterSettings::AdapterSettings(Adapter *adapter, KCModule *parent)
connect(m_discoverTime, SIGNAL(valueChanged(int)), this, SLOT(slotSettingsChanged()));
connect(m_powered, SIGNAL(stateChanged(int)), this, SLOT(slotSettingsChanged()));
if (BlueDevil::Manager::self()->defaultAdapter() == adapter) {
if (BlueDevil::Manager::self()->usableAdapter() == adapter) {
setTitle(i18n("Default adapter: %1 (%2)", adapter->name(), adapter->address()));
} else {
setTitle(i18n("Adapter: %1 (%2)", adapter->name(), adapter->address()));
......@@ -202,7 +202,7 @@ void AdapterSettings::readChanges()
m_powered->setChecked(m_poweredOrig);
m_discoverTimeLabel->setText(i18np("1 minute", "%1 minutes", m_discoverTime->value()));
if (BlueDevil::Manager::self()->defaultAdapter() == m_adapter) {
if (BlueDevil::Manager::self()->usableAdapter() == m_adapter) {
setTitle(i18n("Default adapter: %1 (%2)", m_adapter->name(), m_adapter->address()));
} else {
setTitle(i18n("Adapter: %1 (%2)", m_adapter->name(), m_adapter->address()));
......@@ -263,12 +263,12 @@ KCMBlueDevilAdapters::KCMBlueDevilAdapters(QWidget *parent, const QVariantList&)
this, SLOT(updateAdapters()));
connect(BlueDevil::Manager::self(), SIGNAL(adapterRemoved(Adapter*)),
this, SLOT(updateAdapters()));
connect(BlueDevil::Manager::self(), SIGNAL(defaultAdapterChanged(Adapter*)),
this, SLOT(defaultAdapterChanged(Adapter*)));
connect(BlueDevil::Manager::self(), SIGNAL(usableAdapterChanged(Adapter*)),
this, SLOT(usableAdapterChanged(Adapter*)));
BlueDevil::Adapter *const defaultAdapter = BlueDevil::Manager::self()->defaultAdapter();
if (defaultAdapter) {
connect(defaultAdapter, SIGNAL(discoverableChanged(bool)),
BlueDevil::Adapter *const usableAdapter = BlueDevil::Manager::self()->usableAdapter();
if (usableAdapter) {
connect(usableAdapter, SIGNAL(discoverableChanged(bool)),
this, SLOT(adapterDiscoverableChanged()));
}
......@@ -298,7 +298,7 @@ void KCMBlueDevilAdapters::updateAdapters()
QTimer::singleShot(300, this, SLOT(updateInformationState()));
}
void KCMBlueDevilAdapters::defaultAdapterChanged(Adapter *adapter)
void KCMBlueDevilAdapters::usableAdapterChanged(Adapter *adapter)
{
if (adapter) {
connect(adapter, SIGNAL(discoverableChanged(bool)),
......
......@@ -108,7 +108,7 @@ public:
private Q_SLOTS:
void updateAdapters();
void defaultAdapterChanged(Adapter *adapter);
void usableAdapterChanged(Adapter *adapter);
void adapterDiscoverableChanged();
void generateNoAdaptersMessage();
void updateInformationState();
......
......@@ -382,14 +382,14 @@ KCMBlueDevilDevices::KCMBlueDevilDevices(QWidget *parent, const QVariantList&)
setLayout(layout);
//Logic
connect(BlueDevil::Manager::self(), SIGNAL(defaultAdapterChanged(Adapter*)),
this, SLOT(defaultAdapterChanged(Adapter*)));
connect(BlueDevil::Manager::self(), SIGNAL(usableAdapterChanged(Adapter*)),
this, SLOT(usableAdapterChanged(Adapter*)));
BlueDevil::Adapter *const defaultAdapter = BlueDevil::Manager::self()->defaultAdapter();
if (defaultAdapter) {
connect(defaultAdapter, SIGNAL(discoverableChanged(bool)),
BlueDevil::Adapter *const usableAdapter = BlueDevil::Manager::self()->usableAdapter();
if (usableAdapter) {
connect(usableAdapter, SIGNAL(discoverableChanged(bool)),
this, SLOT(adapterDiscoverableChanged()));
connect(defaultAdapter, SIGNAL(devicesChanged(QList<Device*>)),
connect(usableAdapter, SIGNAL(devicesChanged(QList<Device*>)),
this, SLOT(adapterDevicesChanged(QList<Device*>)));
}
......@@ -489,10 +489,10 @@ void KCMBlueDevilDevices::removeDevice()
QString ubi = device->UBI();
if (KMessageBox::questionYesNo(this, i18n("Are you sure that you want to remove device \"%1\" from the list of known devices?", device->alias()),
i18nc("Title of window that asks for confirmation when removing a device", "Device removal")) == KMessageBox::Yes) {
QList<Device *> deviceList = BlueDevil::Manager::self()->defaultAdapter()->devices();
QList<Device *> deviceList = BlueDevil::Manager::self()->usableAdapter()->devices();
Q_FOREACH(Device *item, deviceList) {
if (item->UBI() == ubi) {
BlueDevil::Manager::self()->defaultAdapter()->removeDevice(device);
BlueDevil::Manager::self()->usableAdapter()->removeDevice(device);
return;
}
}
......@@ -515,7 +515,7 @@ void KCMBlueDevilDevices::launchWizard()
wizard.startDetached();
}
void KCMBlueDevilDevices::defaultAdapterChanged(Adapter *adapter)
void KCMBlueDevilDevices::usableAdapterChanged(Adapter *adapter)
{
if (adapter) {
connect(adapter, SIGNAL(discoverableChanged(bool)),
......@@ -567,10 +567,10 @@ void KCMBlueDevilDevices::generateNoDevicesMessage()
void KCMBlueDevilDevices::fillRemoteDevicesModelInformation()
{
m_devicesModel->removeRows(0, m_devicesModel->rowCount());
Adapter *defaultAdapter = BlueDevil::Manager::self()->defaultAdapter();
Adapter *usableAdapter = BlueDevil::Manager::self()->usableAdapter();
QList<Device*> deviceList;
if (defaultAdapter) {
deviceList = defaultAdapter->devices();
if (usableAdapter) {
deviceList = usableAdapter->devices();
}
if (deviceList.isEmpty()) {
generateNoDevicesMessage();
......@@ -652,8 +652,8 @@ void KCMBlueDevilDevices::updateInformationState()
m_devices->setEnabled(false);
if (m_isEnabled) {
BlueDevil::Adapter *const defaultAdapter = BlueDevil::Manager::self()->defaultAdapter();
if (defaultAdapter) {
BlueDevil::Adapter *const usableAdapter = BlueDevil::Manager::self()->usableAdapter();
if (usableAdapter) {
m_addDevice->setEnabled(true);
m_devices->setEnabled(true);
}
......
......@@ -63,7 +63,7 @@ private Q_SLOTS:
void disconnectDevice();
void launchWizard();
void defaultAdapterChanged(Adapter *adapter);
void usableAdapterChanged(Adapter *adapter);
void adapterDiscoverableChanged();
void adapterDevicesChanged(const QList<Device*> &devices);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment