void tst_QBluetoothHostInfo::tst_construction() { QFETCH(QString, btAddress); QFETCH(QString, name); QFETCH(bool, validBtAddress); QBluetoothAddress empty; QVERIFY(empty.isNull()); QBluetoothHostInfo setter; QBluetoothAddress addr(btAddress); setter.setName(name); setter.setAddress(addr); QCOMPARE(setter.name(), name); QCOMPARE(setter.address().toString(), btAddress); QCOMPARE(setter.address().isNull(), !validBtAddress); setter.setAddress(empty); QCOMPARE(setter.name(), name); QCOMPARE(setter.address().toString(), QString("00:00:00:00:00:00")); QCOMPARE(setter.address().isNull(), true); setter.setName(QString()); QCOMPARE(setter.name(), QString()); QCOMPARE(setter.address().toString(), QString("00:00:00:00:00:00")); QCOMPARE(setter.address().isNull(), true); setter.setAddress(addr); QCOMPARE(setter.name(), QString()); QCOMPARE(setter.address().toString(), btAddress); QCOMPARE(setter.address().isNull(), !validBtAddress); }
void tst_QBluetoothHostInfo::tst_name() { QFETCH(QString, name); QBluetoothHostInfo info; QString result = info.name(); QVERIFY(result.isNull()); QVERIFY(result.isEmpty()); info.setName(name); QCOMPARE(info.name(), name); }
void tst_QBluetoothHostInfo::tst_copy() { QBluetoothHostInfo original; original.setAddress(QBluetoothAddress("11:22:33:44:55:66")); original.setName(QStringLiteral("FunkyName")); QBluetoothHostInfo assignConstructor(original); QCOMPARE(assignConstructor.name(), original.name()); QCOMPARE(assignConstructor.address(), original.address()); QBluetoothHostInfo assignOperator; assignOperator = original; QCOMPARE(assignOperator.name(), original.name()); QCOMPARE(assignOperator.address(), original.address()); }
BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) : QDialog(parent), ui(new Ui::BtDeviceSelectionDialog), remoteDeviceDiscoveryAgent(0) { ui->setupUi(this); // Quit button callbacks QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); connect(quit, SIGNAL(activated()), this, SLOT(reject())); connect(ui->quit, SIGNAL(clicked()), this, SLOT(reject())); // Translate the UI labels ui->localDeviceDetails->setTitle(tr("Local Bluetooth device details")); ui->selectDeviceLabel->setText(tr("Select device:")); ui->deviceAddressLabel->setText(tr("Address:")); ui->deviceNameLabel->setText(tr("Name:")); ui->deviceState->setText(tr("Bluetooth powered on")); ui->changeDeviceState->setText(tr("Turn on/off")); ui->discoveredDevicesLabel->setText(tr("Discovered devices")); ui->scan->setText(tr("Scan")); ui->clear->setText(tr("Clear")); ui->save->setText(tr("Save")); ui->save->setDefault(true); ui->quit->setText(tr("Quit")); // Disable the save button because there is no device selected ui->save->setEnabled(false); // Add event for item selection connect(ui->discoveredDevicesList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentItemChanged(QListWidgetItem*,QListWidgetItem*))); // Initialize the local Bluetooth device localDevice = new QBluetoothLocalDevice(); // Populate the list with local bluetooth devices QList<QBluetoothHostInfo> localAvailableDevices = localDevice->allDevices(); int availableDevicesSize = localAvailableDevices.size(); if (availableDevicesSize > 1) { int defaultDeviceIndex = -1; for (int it = 0; it < availableDevicesSize; it++) { QBluetoothHostInfo localAvailableDevice = localAvailableDevices.at(it); ui->localSelectedDevice->addItem(localAvailableDevice.name(), QVariant::fromValue(localAvailableDevice.address())); if (localDevice->address() == localAvailableDevice.address()) defaultDeviceIndex = it; } // Positionate the current index to the default device and register to index changes events ui->localSelectedDevice->setCurrentIndex(defaultDeviceIndex); connect(ui->localSelectedDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(localDeviceChanged(int))); } else {
void Chat::newAdapterSelected() { const int newAdapterIndex = adapterFromUserSelection(); if (currentAdapterIndex != newAdapterIndex) { server->stopServer(); currentAdapterIndex = newAdapterIndex; const QBluetoothHostInfo info = localAdapters.at(currentAdapterIndex); QBluetoothLocalDevice adapter(info.address()); adapter.setHostMode(QBluetoothLocalDevice::HostDiscoverable); server->startServer(info.address()); localName = info.name(); } }
BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) : QDialog(parent), ui(new Ui::BtDeviceSelectionDialog), remoteDeviceDiscoveryAgent(0) { ui->setupUi(this); // Quit button callbacks QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); connect(quit, SIGNAL(activated()), this, SLOT(reject())); connect(ui->quit, SIGNAL(clicked()), this, SLOT(reject())); // Translate the UI labels ui->localDeviceDetails->setTitle(tr("Local Bluetooth device details")); ui->selectDeviceLabel->setText(tr("Select device:")); ui->deviceAddressLabel->setText(tr("Address:")); ui->deviceNameLabel->setText(tr("Name:")); ui->deviceState->setText(tr("Bluetooth powered on")); ui->changeDeviceState->setText(tr("Turn on/off")); ui->discoveredDevicesLabel->setText(tr("Discovered devices")); ui->scan->setText(tr("Scan")); ui->clear->setText(tr("Clear")); ui->save->setText(tr("Save")); ui->quit->setText(tr("Quit")); // Disable the save button because there is no device selected ui->save->setEnabled(false); // Add event for item selection connect(ui->discoveredDevicesList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*))); #if defined(Q_OS_WIN) ULONG ulRetCode = SUCCESS; WSADATA WSAData = { 0 }; // Initialize WinSock and ask for version 2.2. ulRetCode = WSAStartup(MAKEWORD(2, 2), &WSAData); if (ulRetCode != SUCCESS) { QMessageBox::critical(this, "Bluetooth", tr("Could not initialize Winsock version 2.2"), QMessageBox::Ok); return; } // Initialize the device discovery agent initializeDeviceDiscoveryAgent(); // On Windows we cannot select a device or show information about the local device ui->localDeviceDetails->hide(); #else // Initialize the local Bluetooth device localDevice = new QBluetoothLocalDevice(); // Populate the list with local bluetooth devices QList<QBluetoothHostInfo> localAvailableDevices = localDevice->allDevices(); int availableDevicesSize = localAvailableDevices.size(); if (availableDevicesSize > 1) { int defaultDeviceIndex = -1; for (int it = 0; it < availableDevicesSize; it++) { QBluetoothHostInfo localAvailableDevice = localAvailableDevices.at(it); ui->localSelectedDevice->addItem(localAvailableDevice.name(), QVariant::fromValue(localAvailableDevice.address())); if (localDevice->address() == localAvailableDevice.address()) defaultDeviceIndex = it; } // Positionate the current index to the default device and register to index changes events ui->localSelectedDevice->setCurrentIndex(defaultDeviceIndex); connect(ui->localSelectedDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(localDeviceChanged(int))); } else {