Feature:Add wireless card selection.
This commit is contained in:
parent
ff1d61317b
commit
8412fea1db
|
@ -46,6 +46,7 @@ void TabPage::initUI()
|
|||
connect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &TabPage::onDeviceComboxIndexChanged);
|
||||
|
||||
m_activatedNetFrame = new QFrame(this);
|
||||
m_activatedNetFrame->setMaximumHeight(ACTIVE_AREA_MAX_HEIGHT);
|
||||
m_activatedNetLayout = new QVBoxLayout(m_activatedNetFrame);
|
||||
m_activatedNetLayout->setContentsMargins(ACTIVE_NET_LAYOUT_MARGINS);
|
||||
m_activatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
//#define SCROLL_AREA_HEIGHT 200
|
||||
#define SETTINGS_LAYOUT_MARGINS 24,16,24,16
|
||||
#define TRANSPARENT_COLOR QColor(0,0,0,0)
|
||||
#define INACTIVE_AREA_MIN_HEIGHT 100
|
||||
#define INACTIVE_AREA_MIN_HEIGHT 150
|
||||
#define ACTIVE_AREA_MAX_HEIGHT 100
|
||||
|
||||
enum KyDeviceType
|
||||
{
|
||||
|
|
|
@ -13,11 +13,10 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
|||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_netDeviceResource=new KyNetworkDeviceResourse(this);
|
||||
m_apConnectResource = new KyConnectResourse(this);
|
||||
devList.empty();
|
||||
m_devList.empty();
|
||||
initDevice();
|
||||
m_wirelessConnectOpreation = new KyWirelessConnectOperation(this);
|
||||
initWlanUI();
|
||||
initDeviceCombox();
|
||||
//要在initUI之后调用,保证UI的信号槽顺利绑定
|
||||
initConnections();
|
||||
initTimer();
|
||||
|
@ -139,11 +138,11 @@ void WlanPage::initDevice()
|
|||
m_settings->beginGroup("DEFAULTCARD");
|
||||
QString key("wireless");
|
||||
QString deviceName = m_settings->value(key, "").toString();
|
||||
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList);
|
||||
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList);
|
||||
if (deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wireless card is null";
|
||||
if (!devList.isEmpty()) {
|
||||
deviceName = devList.at(0);
|
||||
if (!m_devList.isEmpty()) {
|
||||
deviceName = m_devList.at(0);
|
||||
m_settings->setValue(key, deviceName);
|
||||
}
|
||||
}
|
||||
|
@ -153,12 +152,21 @@ void WlanPage::initDevice()
|
|||
m_settings->sync();
|
||||
delete m_settings;
|
||||
m_settings = nullptr;
|
||||
|
||||
//获取完m_devList后调用,减少重复获取
|
||||
initDeviceCombox();
|
||||
}
|
||||
|
||||
void WlanPage::initDeviceCombox()
|
||||
{
|
||||
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框
|
||||
if (m_devList.length() <= 1) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
foreach (QString device, m_devList) {
|
||||
m_deviceComboBox->addItem(device, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,6 +174,9 @@ void WlanPage::initDeviceCombox()
|
|||
*/
|
||||
void WlanPage::getActiveWlan()
|
||||
{
|
||||
if (!m_activatedNetListWidget) {
|
||||
return;
|
||||
}
|
||||
QMap<QString,QStringList> actMap;
|
||||
m_activatedNetListWidget->clear();
|
||||
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
|
||||
|
@ -219,6 +230,9 @@ void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
|||
*/
|
||||
void WlanPage::getAllWlan()
|
||||
{
|
||||
if (!m_inactivatedNetListWidget) {
|
||||
return;
|
||||
}
|
||||
qDebug() << "Started loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
|
||||
m_inactivatedNetListWidget->clear();
|
||||
m_itemsMap.clear();
|
||||
|
@ -298,13 +312,22 @@ void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devi
|
|||
if (deviceType != NetworkManager::Device::Type::Wifi) {
|
||||
return;
|
||||
}
|
||||
devList << deviceName;
|
||||
m_devList << deviceName;
|
||||
if (getDefaultDevice().isEmpty())
|
||||
{
|
||||
updateDefaultDevice(deviceName);
|
||||
setDefaultDevice(WIRELESS, deviceName);
|
||||
|
||||
}
|
||||
|
||||
//往下拉框添加新的网卡
|
||||
if (m_deviceComboBox->findData(deviceName) == -1) {
|
||||
if (m_devList.length() > 1 && !m_deviceFrame->isVisible()) {
|
||||
m_deviceFrame->show();
|
||||
}
|
||||
m_deviceComboBox->addItem(deviceName, deviceName);
|
||||
}
|
||||
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
|
||||
|
@ -323,10 +346,20 @@ void WlanPage::onDeviceRemove(QString deviceName)
|
|||
updateDefaultDevice(newDefaultDevice);
|
||||
setDefaultDevice(WIRELESS, newDefaultDevice);
|
||||
}
|
||||
if (devList.contains(deviceName)) {
|
||||
devList.removeOne(deviceName);
|
||||
|
||||
if (m_devList.contains(deviceName)) {
|
||||
m_devList.removeOne(deviceName);
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
|
||||
//从下拉框删除已消失的网卡
|
||||
if (m_deviceComboBox->findData(deviceName) != -1) {
|
||||
if (m_devList.length() <= 1 && m_deviceFrame->isVisible()) {
|
||||
m_deviceFrame->hide();
|
||||
}
|
||||
m_deviceComboBox->removeItem(m_deviceComboBox->findData(deviceName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
||||
|
@ -336,12 +369,17 @@ void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
|||
setDefaultDevice(WIRELESS, newName);
|
||||
}
|
||||
|
||||
if (devList.contains(oldName)) {
|
||||
devList.removeOne(oldName);
|
||||
devList.append(newName);
|
||||
if (m_devList.contains(oldName)) {
|
||||
m_devList.removeOne(oldName);
|
||||
m_devList.append(newName);
|
||||
qDebug() << "WlanPage emit deviceNameUpdate " << oldName << newName;
|
||||
emit deviceNameChanged(oldName, newName);
|
||||
}
|
||||
|
||||
if (m_deviceComboBox->findData(oldName) != -1) {
|
||||
m_deviceComboBox->removeItem(m_deviceComboBox->findData(oldName));
|
||||
m_deviceComboBox->addItem(newName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||
|
@ -457,7 +495,15 @@ void WlanPage::onWlanSwitchStatusChanged(const bool &checked)
|
|||
|
||||
void WlanPage::onDeviceComboxIndexChanged(int currentIndex)
|
||||
{
|
||||
if (!m_deviceComboBox || currentIndex < 0) {
|
||||
return;
|
||||
}
|
||||
//TODO 设备变更时更新设备和列表
|
||||
QString currentDevice = m_deviceComboBox->itemText(currentIndex);
|
||||
qDebug() << "Current device changed! device = " << currentDevice << Q_FUNC_INFO << __LINE__;
|
||||
defaultDevice = currentDevice;
|
||||
getActiveWlan();
|
||||
getAllWlan();
|
||||
}
|
||||
|
||||
//申请触发扫描,初始化执行&定时执行
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
QLabel * m_hiddenWlanLabel = nullptr;
|
||||
|
||||
QString m_activatedWlanSSid;
|
||||
QStringList devList;
|
||||
QStringList m_devList;
|
||||
|
||||
KyWirelessNetResource *m_resource = nullptr;
|
||||
KyActiveConnectResourse *m_connectResource = nullptr;
|
||||
|
|
|
@ -42,7 +42,6 @@ void RadioItemButton::setButtonIcon(const QIcon &icon)
|
|||
if (icon.isNull()) {
|
||||
return;
|
||||
}
|
||||
//ZJP_TODO 绘制圆形按钮
|
||||
m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue