fix:wired switch failed.
bug link:http://172.17.66.192/biz/bug-view-81530.html http://172.17.66.192/biz/bug-view-80919.html
This commit is contained in:
parent
0b22f57104
commit
f2d2f401a9
|
@ -21,29 +21,20 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
|||
m_activeResourse = new KyActiveConnectResourse(this);
|
||||
m_connectResourse = new KyConnectResourse(this);
|
||||
m_device = new KyNetworkDeviceResourse(this);
|
||||
m_nullLanItem = new LanListItem();
|
||||
|
||||
m_devList.empty();
|
||||
initDeviceState();
|
||||
|
||||
initUI();
|
||||
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
initNetSwitch();
|
||||
} else {
|
||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||
}
|
||||
|
||||
initNetSwitch();
|
||||
initDeviceCombox();
|
||||
initList(m_deviceName);
|
||||
|
||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
||||
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::connectionUpdateSlot);
|
||||
|
||||
// connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::onLanDataChange);
|
||||
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
|
||||
|
@ -57,14 +48,34 @@ LanPage::~LanPage()
|
|||
|
||||
}
|
||||
|
||||
void LanPage::initDeviceState()
|
||||
{
|
||||
QMap<QString, bool> deviceStateMap;
|
||||
|
||||
getDeviceEnableState(WIRED, deviceStateMap);
|
||||
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
QMap<QString, bool>::iterator iter = deviceStateMap.begin();
|
||||
while (iter != deviceStateMap.end()) {
|
||||
if (!iter.value()) {
|
||||
wiredOperation.closeWiredNetworkWithDevice(iter.key());
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::initNetSwitch()
|
||||
{
|
||||
if (m_switchGsettings->keys().contains(WIRED_SWITCH)) {
|
||||
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
|
||||
initDeviceCombox();
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged);
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
if (m_switchGsettings->keys().contains(WIRED_SWITCH)) {
|
||||
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged);
|
||||
}
|
||||
connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked);
|
||||
} else {
|
||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||
}
|
||||
connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked);
|
||||
}
|
||||
|
||||
void LanPage::onSwithGsettingsChanged(const QString &key)
|
||||
|
@ -72,20 +83,26 @@ void LanPage::onSwithGsettingsChanged(const QString &key)
|
|||
if (key == WIRED_SWITCH) {
|
||||
m_netSwitch->blockSignals(true);
|
||||
|
||||
qDebug()<<"[LanPage] SwitchButton statue changed to ::" <<m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
qDebug()<<"[LanPage] SwitchButton statue changed to:"
|
||||
<< m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
|
||||
QStringList deviceList;
|
||||
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, deviceList);
|
||||
|
||||
bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
if (isOn) {
|
||||
for (int index = 0; index < m_devList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] open wired device "<< m_devList.at(index);
|
||||
wiredOperation.openWiredNetworkWithDevice(m_devList.at(index));
|
||||
for (int index = 0; index < deviceList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] open wired device "<< deviceList.at(index);
|
||||
wiredOperation.openWiredNetworkWithDevice(deviceList.at(index));
|
||||
saveDeviceEnableState(deviceList.at(index), true);
|
||||
}
|
||||
} else {
|
||||
for (int index = 0; index < m_devList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] close wired device "<< m_devList.at(index);
|
||||
wiredOperation.closeWiredNetworkWithDevice(m_devList.at(index));
|
||||
for (int index = 0; index < deviceList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] close wired device "<< deviceList.at(index);
|
||||
wiredOperation.closeWiredNetworkWithDevice(deviceList.at(index));
|
||||
saveDeviceEnableState(deviceList.at(index), false);
|
||||
}
|
||||
}
|
||||
initDeviceCombox();
|
||||
|
@ -99,9 +116,9 @@ void LanPage::onLanSwitchClicked()
|
|||
qDebug()<<"[LanPage] On lan switch button clicked! Status:" <<m_netSwitch->getSwitchStatus();
|
||||
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
m_switchGsettings->set(WIRED_SWITCH,true);
|
||||
m_switchGsettings->set(WIRED_SWITCH, true);
|
||||
} else {
|
||||
m_switchGsettings->set(WIRED_SWITCH,false);
|
||||
m_switchGsettings->set(WIRED_SWITCH, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +178,6 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线
|
|||
addNewItem(newItem, m_inactivatedLanListWidget);
|
||||
m_deactiveMap.insert(newItem, m_listWidgetItem);
|
||||
}
|
||||
|
||||
} else {
|
||||
qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!";
|
||||
}
|
||||
|
@ -171,17 +187,19 @@ void LanPage::initDeviceCombox()
|
|||
{
|
||||
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态
|
||||
QMap<QString, bool> deviceMap;
|
||||
getDeviceEnableState(0,deviceMap);
|
||||
QStringList enableDevice;
|
||||
m_deviceComboBox->clear();
|
||||
m_devList.clear();
|
||||
enableDevice.clear();
|
||||
|
||||
if (!m_switchGsettings) {
|
||||
qDebug() << "[LanPage]:m_switchGsettings is null" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
m_deviceComboBox->clear();
|
||||
m_devList.clear();
|
||||
enableDevice.clear();
|
||||
|
||||
getDeviceEnableState(WIRED, deviceMap);
|
||||
|
||||
bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
if (!isOn) {
|
||||
m_deviceFrame->hide();
|
||||
|
@ -189,6 +207,7 @@ void LanPage::initDeviceCombox()
|
|||
m_inactivatedNetFrame->hide();
|
||||
m_activatedNetDivider->hide();
|
||||
m_inactivatedNetDivider->hide();
|
||||
m_deviceName = "";
|
||||
} else {
|
||||
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, m_devList);
|
||||
for (int i=0; i<m_devList.size(); ++i) {
|
||||
|
@ -201,6 +220,7 @@ void LanPage::initDeviceCombox()
|
|||
enableDevice << m_devList.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage]device num:" << enableDevice.count();
|
||||
if (enableDevice.count() == 0) {
|
||||
m_deviceFrame->show();
|
||||
|
@ -210,12 +230,15 @@ void LanPage::initDeviceCombox()
|
|||
m_inactivatedNetFrame->hide();
|
||||
m_activatedNetDivider->hide();
|
||||
m_inactivatedNetDivider->hide();
|
||||
m_deviceName = "";
|
||||
return;
|
||||
}
|
||||
|
||||
m_activatedNetFrame->show();
|
||||
m_inactivatedNetFrame->show();
|
||||
m_activatedNetDivider->show();
|
||||
m_inactivatedNetDivider->show();
|
||||
|
||||
if (enableDevice.count() == 1) {
|
||||
m_deviceFrame->hide();
|
||||
m_deviceName = enableDevice.at(0);
|
||||
|
@ -225,15 +248,18 @@ void LanPage::initDeviceCombox()
|
|||
m_deviceFrame->show();
|
||||
m_tipsLabel->hide();
|
||||
m_deviceComboBox->show();
|
||||
for (int j=0; j<enableDevice.count(); ++j) {
|
||||
m_deviceComboBox->addItem(enableDevice.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage]Current device:" << m_deviceComboBox->currentText();
|
||||
m_deviceName = m_deviceComboBox->currentText();
|
||||
initList(m_deviceName);
|
||||
for (int j=0; j<enableDevice.count(); ++j) {
|
||||
m_deviceComboBox->addItem(enableDevice.at(j));
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage]Current device:" << m_deviceComboBox->currentText();
|
||||
m_deviceName = m_deviceComboBox->currentText();
|
||||
initList(m_deviceName);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType)
|
||||
|
@ -341,9 +367,9 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
|||
m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
|
||||
listWidget->addItem(m_listWidgetItem);
|
||||
|
||||
m_testLanItem = new LanListItem(itemData, m_deviceName);
|
||||
LanListItem *p_lanItem = new LanListItem(itemData, m_deviceName);
|
||||
qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName;
|
||||
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||
listWidget->setItemWidget(m_listWidgetItem, p_lanItem);
|
||||
}
|
||||
|
||||
void LanPage::initList(QString m_deviceName) //程序拉起,初始化显示
|
||||
|
@ -473,8 +499,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
@ -623,13 +648,15 @@ void LanPage::connectionUpdateSlot(QString uuid)
|
|||
void LanPage::setWiredDeviceEnable(const QString& devName, bool enable)
|
||||
{
|
||||
saveDeviceEnableState(devName, enable);
|
||||
initDeviceCombox();
|
||||
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
if (enable) {
|
||||
wiredOperation.openWiredNetworkWithDevice(devName);
|
||||
} else {
|
||||
wiredOperation.closeWiredNetworkWithDevice(devName);
|
||||
}
|
||||
|
||||
initDeviceCombox();
|
||||
}
|
||||
|
||||
void LanPage::activateWired(const QString& devName, const QString& connUuid)
|
||||
|
@ -661,11 +688,14 @@ void LanPage::showDetailPage(QString devName, QString uuid)
|
|||
{
|
||||
KyConnectItem *item = nullptr;
|
||||
bool isActive = true;
|
||||
|
||||
item = m_activeResourse->getActiveConnectionByUuid(uuid, devName);
|
||||
if (nullptr == item) {
|
||||
item = m_connectResourse->getConnectionItemByUuid(uuid, devName);
|
||||
if (nullptr == item) {
|
||||
qWarning()<<"[LanPage] GetConnectionItemByUuid is empty when showDetailPage";
|
||||
qWarning()<<"[LanPage] GetConnectionItemByUuid is empty when showDetailPage."
|
||||
<<"device name"<<devName
|
||||
<<"connect uuid"<<uuid;
|
||||
return;
|
||||
}
|
||||
isActive= false;
|
||||
|
@ -673,6 +703,7 @@ void LanPage::showDetailPage(QString devName, QString uuid)
|
|||
|
||||
NetDetail *netDetail = new NetDetail(devName, item->m_connectName, uuid, isActive, false, false, this);
|
||||
netDetail->show();
|
||||
|
||||
delete item;
|
||||
item = nullptr;
|
||||
}
|
||||
|
|
|
@ -28,12 +28,15 @@ public:
|
|||
void deactivateWired(const QString& devName, const QString& connUuid);
|
||||
void showDetailPage(QString devName, QString uuid);
|
||||
void setWiredDeviceEnable(const QString& devName, bool enable);
|
||||
|
||||
signals:
|
||||
void lanAdd(QString devName, QStringList info);
|
||||
void lanRemove(QString dbusPath);
|
||||
void lanUpdate(QString devName, QStringList info);
|
||||
void lanActiveConnectionStateChanged(QString interface, QString uuid, int status);
|
||||
|
||||
private:
|
||||
void initDeviceState();
|
||||
void initDeviceCombox();
|
||||
void initUI();
|
||||
void initList(QString m_deviceName);
|
||||
|
@ -45,7 +48,6 @@ private:
|
|||
QListWidget * m_inactivatedLanListWidget = nullptr;
|
||||
|
||||
LanListItem * m_nullLanItem = nullptr;
|
||||
LanListItem * m_testLanItem = nullptr;
|
||||
QListWidgetItem *m_nullItem = nullptr;
|
||||
QListWidgetItem *m_listWidgetItem = nullptr;
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
|
|||
// QApplication a(argc, argv);
|
||||
QString id = QString("kylin-nm"+ QLatin1String(getenv("DISPLAY")));
|
||||
QtSingleApplication a(id, argc, argv);
|
||||
// qInstallMessageHandler(messageOutput);
|
||||
qInstallMessageHandler(messageOutput);
|
||||
if (a.isRunning()) {
|
||||
auto connection = QDBusConnection::sessionBus();
|
||||
QDBusInterface iface("com.kylin.network",
|
||||
|
|
Loading…
Reference in New Issue