2011-12-09 14:27:12 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 14:19:34 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-20 07:11:55 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-12-09 14:27:12 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtBluetooth module of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
|
|
|
** You may use this file under the terms of the BSD license as follows:
|
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
2012-09-20 07:11:55 +00:00
|
|
|
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
|
|
|
** of its contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
|
|
|
**
|
2011-12-09 14:27:12 +00:00
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2012-01-24 03:05:07 +00:00
|
|
|
**
|
2011-12-09 14:27:12 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "remoteselector.h"
|
|
|
|
#include "ui_remoteselector.h"
|
|
|
|
|
|
|
|
#include <qbluetoothdeviceinfo.h>
|
|
|
|
#include <qbluetoothaddress.h>
|
2013-08-29 12:46:56 +00:00
|
|
|
#include <qbluetoothlocaldevice.h>
|
2011-12-09 14:27:12 +00:00
|
|
|
|
2013-09-05 11:32:00 +00:00
|
|
|
QT_USE_NAMESPACE
|
2011-12-09 14:27:12 +00:00
|
|
|
|
2013-09-23 11:52:35 +00:00
|
|
|
RemoteSelector::RemoteSelector(const QBluetoothAddress &localAdapter, QWidget *parent)
|
2013-08-29 12:46:56 +00:00
|
|
|
: QDialog(parent), ui(new Ui::RemoteSelector)
|
2011-12-09 14:27:12 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2013-09-23 11:52:35 +00:00
|
|
|
m_discoveryAgent = new QBluetoothServiceDiscoveryAgent(localAdapter);
|
2013-08-29 12:46:56 +00:00
|
|
|
|
2011-12-09 14:27:12 +00:00
|
|
|
connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
|
|
|
|
this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
|
|
|
|
connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished()));
|
2013-09-23 12:55:35 +00:00
|
|
|
connect(m_discoveryAgent, SIGNAL(canceled()), this, SLOT(discoveryFinished()));
|
2011-12-09 14:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteSelector::~RemoteSelector()
|
|
|
|
{
|
|
|
|
delete ui;
|
2013-08-29 12:46:56 +00:00
|
|
|
delete m_discoveryAgent;
|
2011-12-09 14:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::startDiscovery(const QBluetoothUuid &uuid)
|
|
|
|
{
|
2013-09-23 12:55:35 +00:00
|
|
|
ui->status->setText(tr("Scanning..."));
|
2011-12-09 14:27:12 +00:00
|
|
|
if (m_discoveryAgent->isActive())
|
|
|
|
m_discoveryAgent->stop();
|
|
|
|
|
|
|
|
ui->remoteDevices->clear();
|
|
|
|
|
|
|
|
m_discoveryAgent->setUuidFilter(uuid);
|
2014-04-11 08:05:45 +00:00
|
|
|
m_discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
|
2011-12-09 14:27:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::stopDiscovery()
|
|
|
|
{
|
|
|
|
if (m_discoveryAgent){
|
|
|
|
m_discoveryAgent->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QBluetoothServiceInfo RemoteSelector::service() const
|
|
|
|
{
|
|
|
|
return m_service;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::serviceDiscovered(const QBluetoothServiceInfo &serviceInfo)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
qDebug() << "Discovered service on"
|
|
|
|
<< serviceInfo.device().name() << serviceInfo.device().address().toString();
|
|
|
|
qDebug() << "\tService name:" << serviceInfo.serviceName();
|
|
|
|
qDebug() << "\tDescription:"
|
|
|
|
<< serviceInfo.attribute(QBluetoothServiceInfo::ServiceDescription).toString();
|
|
|
|
qDebug() << "\tProvider:"
|
|
|
|
<< serviceInfo.attribute(QBluetoothServiceInfo::ServiceProvider).toString();
|
|
|
|
qDebug() << "\tL2CAP protocol service multiplexer:"
|
|
|
|
<< serviceInfo.protocolServiceMultiplexer();
|
|
|
|
qDebug() << "\tRFCOMM server channel:" << serviceInfo.serverChannel();
|
|
|
|
#endif
|
|
|
|
QMapIterator<QListWidgetItem *, QBluetoothServiceInfo> i(m_discoveredServices);
|
|
|
|
while (i.hasNext()){
|
|
|
|
i.next();
|
|
|
|
if (serviceInfo.device().address() == i.value().device().address()){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString remoteName;
|
|
|
|
if (serviceInfo.device().name().isEmpty())
|
|
|
|
remoteName = serviceInfo.device().address().toString();
|
|
|
|
else
|
|
|
|
remoteName = serviceInfo.device().name();
|
|
|
|
|
|
|
|
QListWidgetItem *item =
|
|
|
|
new QListWidgetItem(QString::fromLatin1("%1 %2").arg(remoteName,
|
|
|
|
serviceInfo.serviceName()));
|
|
|
|
|
|
|
|
m_discoveredServices.insert(item, serviceInfo);
|
|
|
|
ui->remoteDevices->addItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::discoveryFinished()
|
|
|
|
{
|
|
|
|
ui->status->setText(tr("Select the chat service to connect to."));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::on_remoteDevices_itemActivated(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
qDebug() << "got click" << item->text();
|
|
|
|
m_service = m_discoveredServices.value(item);
|
2015-01-26 07:47:06 +00:00
|
|
|
if (m_discoveryAgent->isActive())
|
|
|
|
m_discoveryAgent->stop();
|
2011-12-09 14:27:12 +00:00
|
|
|
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSelector::on_cancelButton_clicked()
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|