x-tools/Source/Optional/bluetooth/sakbluetoothdeviceInfocombobox.cc
2024-03-20 20:01:09 +08:00

110 lines
2.8 KiB
C++

/***************************************************************************************************
* Copyright 2023 x-tools-author(x-tools@outlook.com). All rights reserved.
*
* The file is encoded using "utf8 with bom", it is a part of xTools project.
*
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#include "sakbluetoothdeviceInfocombobox.h"
#include <QBluetoothDeviceInfo>
#include <QMessageBox>
SAKBluetoothDeviceInfoComboBox::SAKBluetoothDeviceInfoComboBox(QWidget* parent)
: xToolsComboBox(parent)
, mScanner(Q_NULLPTR)
{
#if 0
mScanner = new SAKBleScanner(this);
connect(mScanner, &SAKBleScanner::finished,
this, &SAKBluetoothDeviceInfoComboBox::onFinished);
connect(mScanner, &SAKBleScanner::started,
this, &SAKBluetoothDeviceInfoComboBox::started);
connect(mScanner, &SAKBleScanner::deviceDiscovered,
this, &SAKBluetoothDeviceInfoComboBox::onDeviceDiscovered);
connect(mScanner, &SAKBleScanner::errorOccurred,
this, &SAKBluetoothDeviceInfoComboBox::onErrorOccurred);
#endif
}
SAKBluetoothDeviceInfoComboBox::~SAKBluetoothDeviceInfoComboBox()
{
#if 0
mScanner->stopDiscover();
#endif
}
void SAKBluetoothDeviceInfoComboBox::startDiscover()
{
#if 0
clear();
mScanner->startDiscover();
#endif
}
void SAKBluetoothDeviceInfoComboBox::stopDiscover()
{
#if 0
mScanner->stopDiscover();
#endif
}
bool SAKBluetoothDeviceInfoComboBox::isActive()
{
#if 0
return mScanner->isActive();
#endif
return false;
}
void SAKBluetoothDeviceInfoComboBox::setTimeoutInterval(int interval)
{
#if 0
mScanner->setTimeoutInterval(interval);
#endif
}
void SAKBluetoothDeviceInfoComboBox::setNameFiltter(const QString& filtter)
{
// mScanner->setNameFiltter(filtter);
}
void SAKBluetoothDeviceInfoComboBox::changeEvent(QEvent* event)
{
xToolsComboBox::changeEvent(event);
if ((event->type() == QEvent::EnabledChange) && isEnabled()) {
onFinished();
}
}
void SAKBluetoothDeviceInfoComboBox::onFinished()
{
// if (!isEnabled()) {
// return;
// }
// clear();
// auto infos = mScanner->devicesInfoList();
// for (auto &info : infos) {
// QString name = mScanner->deviceName(info);
// addItem(name, info);
// }
// emit finished();
}
void SAKBluetoothDeviceInfoComboBox::onDeviceDiscovered(const QBluetoothDeviceInfo& info)
{
if (!isEnabled()) {
return;
}
addItem(info.name(), QVariant::fromValue(info));
}
void SAKBluetoothDeviceInfoComboBox::onErrorOccurred(const QString& errStr)
{
QMessageBox::warning(this, tr("Error Occurred"), errStr);
}