Fix:bug #86143#85706#85134

This commit is contained in:
king 2021-10-20 16:54:17 +08:00
parent 00e1271c30
commit 28793b319f
6 changed files with 62 additions and 12 deletions

View File

@ -152,6 +152,21 @@ void MainWindow::initUI()
*/
void MainWindow::initTrayIcon()
{
loadIcons.append(QIcon::fromTheme("kylin-network-1"));
loadIcons.append(QIcon::fromTheme("kylin-network-2"));
loadIcons.append(QIcon::fromTheme("kylin-network-3"));
loadIcons.append(QIcon::fromTheme("kylin-network-4"));
loadIcons.append(QIcon::fromTheme("kylin-network-5"));
loadIcons.append(QIcon::fromTheme("kylin-network-6"));
loadIcons.append(QIcon::fromTheme("kylin-network-7"));
loadIcons.append(QIcon::fromTheme("kylin-network-8"));
loadIcons.append(QIcon::fromTheme("kylin-network-9"));
loadIcons.append(QIcon::fromTheme("kylin-network-10"));
loadIcons.append(QIcon::fromTheme("kylin-network-11"));
loadIcons.append(QIcon::fromTheme("kylin-network-12"));
iconTimer = new QTimer(this);
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
m_trayIcon = new QSystemTrayIcon();
m_trayIconMenu = new QMenu();
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
@ -187,17 +202,17 @@ void MainWindow::initDbusConnnect()
connect(m_lanWidget, &LanPage::lanRemove, this, &MainWindow::lanRemove);
connect(m_lanWidget, &LanPage::lanUpdate, this, &MainWindow::lanUpdate);
connect(m_lanWidget, &LanPage::lanActiveConnectionStateChanged, this, &MainWindow::lanActiveConnectionStateChanged);
connect(m_lanWidget, &LanPage::lanConnectChanged, this, &MainWindow::onRefreshTrayIcon);
connect(m_lanWidget, &LanPage::lanConnectChanged, this, &MainWindow::onLanConnectStatusToChangeTrayIcon);
connect(m_wlanWidget, &WlanPage::wlanAdd, this, &MainWindow::wlanAdd);
connect(m_wlanWidget, &WlanPage::wlanRemove, this, &MainWindow::wlanRemove);
connect(m_wlanWidget, &WlanPage::wlanActiveConnectionStateChanged, this, &MainWindow::wlanactiveConnectionStateChanged);
connect(m_wlanWidget, &WlanPage::wlanConnectChanged, this, &MainWindow::onWlanConnectStatusToChangeTrayIcon);
connect(m_wlanWidget, &WlanPage::hotspotDeactivated, this, &MainWindow::hotspotDeactivated);
connect(m_wlanWidget, &WlanPage::hotspotActivated, this, &MainWindow::hotspotActivated);
connect(m_wlanWidget, &WlanPage::secuTypeChange, this, &MainWindow::secuTypeChange);
connect(m_wlanWidget, &WlanPage::signalStrengthChange, this, &MainWindow::signalStrengthChange);
connect(m_wlanWidget, &WlanPage::wlanConnectChanged, this, &MainWindow::onRefreshTrayIcon);
}
/**
@ -366,11 +381,43 @@ void MainWindow::onRefreshTrayIcon()
{
//更新托盘图标显示
if (m_lanWidget->lanIsConnected()) {
iconTimer->stop();
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
} else if (m_wlanWidget->wlanIsConnected()){
iconTimer->stop();
m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic"));
} else {
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
iconTimer->stop();
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
}
}
void MainWindow::onSetTrayIconLoading()
{
if (currentIconIndex > 11) {
currentIconIndex = 0;
}
m_trayIcon->setIcon(loadIcons.at(currentIconIndex));
currentIconIndex ++;
}
void MainWindow::onLanConnectStatusToChangeTrayIcon(int state)
{
qDebug() << "lan state:" << state << Q_FUNC_INFO << __LINE__;
if (state==1 || state==3){
iconTimer->start(60);
} else {
onRefreshTrayIcon();
}
}
void MainWindow::onWlanConnectStatusToChangeTrayIcon(int state)
{
qDebug() << "wlan state:" << state << Q_FUNC_INFO << __LINE__;
if (state==1 || state==3){
iconTimer->start(60);
} else {
onRefreshTrayIcon();
}
}

View File

@ -98,6 +98,9 @@ private:
void initWindowTheme();
void resetWindowTheme();
void showControlCenter();
int currentIconIndex=0;
QList<QIcon> loadIcons;
QTimer *iconTimer = nullptr;
//主窗口的主要构成控件
QTabWidget * m_centralWidget = nullptr;
@ -127,6 +130,9 @@ private slots:
void onShowSettingsActionTriggled();
void onThemeChanged(const QString &key);
void onRefreshTrayIcon();
void onSetTrayIconLoading();
void onLanConnectStatusToChangeTrayIcon(int state);
void onWlanConnectStatusToChangeTrayIcon(int state);
};
#endif // MAINWINDOW_H

View File

@ -841,7 +841,7 @@ void LanPage::onUpdateLanlist(QString uuid,
emit lanActiveConnectionStateChanged(devName, uuid, state);
}
emit this->lanConnectChanged();
emit this->lanConnectChanged(state);
return;
}

View File

@ -82,7 +82,7 @@ signals:
void lanUpdate(QString devName, QStringList info);
void lanActiveConnectionStateChanged(QString interface, QString uuid, int status);
void lanConnectChanged();
void lanConnectChanged(int state);
private slots:
void onUpdateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);

View File

@ -429,14 +429,12 @@ void WlanPage::initWlanArea()
constructActivateConnectionArea();
m_inactivatedNetFrame->show();
m_inactivatedNetDivider->show();
constructWirelessNetArea();
} else {
m_activatedNetFrame->hide();
m_activatedNetDivider->hide();
m_inactivatedNetFrame->hide();
m_inactivatedNetDivider->hide();
}
return;
@ -870,7 +868,7 @@ void WlanPage::onConnectionStateChanged(QString uuid,
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Activating);
}
}
emit this->wlanConnectChanged(state);
return;
}
@ -975,7 +973,7 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
//m_netSwitch->setSwitchStatus(isWifiOn);
//m_netSwitch->setEnabled(isWifiOn);
m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn);
emit this->wlanConnectChanged();
// emit this->wlanConnectChanged();
}
return;
@ -1226,10 +1224,9 @@ bool WlanPage::wlanIsConnected()
{
if (m_activateConnectionItemMap.isEmpty()) {
return false;
} else if (m_activateConnectionItemMap.contains(EMPTY_SSID)) {
} else if (m_activateConnectionItemMap.contains(EMPTY_SSID)) {;
return false;
}
return true;
}

View File

@ -58,7 +58,7 @@ signals:
void signalStrengthChange(QString devName, QString ssid, int strength);
void secuTypeChange(QString devName, QString ssid, QString secuType);
void hiddenWlanClicked();
void wlanConnectChanged();
void wlanConnectChanged(int state);
public slots:
void onMainWindowVisibleChanged(const bool &visible);