bug 164390(需求) 任务栏托盘网络连接工具提示不准确
This commit is contained in:
parent
1af6a8b036
commit
6bf77f302f
|
@ -29,6 +29,7 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare
|
|||
{
|
||||
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
|
||||
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
|
||||
qRegisterMetaType<NetworkManager::Connectivity>("NetworkManager::Connectivity");
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
m_deviceMap.clear();
|
||||
|
@ -249,6 +250,41 @@ qulonglong KyNetworkDeviceResourse::getDeviceTxRefreshRate(QString deviceName)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void KyNetworkDeviceResourse::getDeviceConnectivity(const QString &deviceName, NetworkManager::Connectivity &connectivity)
|
||||
{
|
||||
connectivity = NetworkManager::Connectivity::UnknownConnectivity;
|
||||
QString dbusPath;
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
if (connectDevice->isValid()) {
|
||||
dbusPath = connectDevice->uni();
|
||||
} else {
|
||||
qWarning() << "[KyNetworkDeviceResourse] can not find device " << deviceName;
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusInterface *ip4ConnectivityDbus = new QDBusInterface("org.freedesktop.NetworkManager",
|
||||
dbusPath,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
if (ip4ConnectivityDbus == nullptr || !ip4ConnectivityDbus->isValid()) {
|
||||
qWarning() << "[KyNetworkDeviceResourse] get device properties failed";
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusReply<QVariant> reply = ip4ConnectivityDbus->call("Get", "org.freedesktop.NetworkManager.Device", "Ip4Connectivity");
|
||||
|
||||
if (reply.isValid()) {
|
||||
connectivity = (NetworkManager::Connectivity) reply.value().toUInt();
|
||||
} else {
|
||||
qWarning() << "[KyNetworkDeviceResourse] get device properties failed";
|
||||
}
|
||||
|
||||
delete ip4ConnectivityDbus;
|
||||
ip4ConnectivityDbus = nullptr;
|
||||
}
|
||||
|
||||
bool KyNetworkDeviceResourse::getActiveConnectionInfo(const QString devName, int &signalStrength, QString &uni, QString &secuType)
|
||||
{
|
||||
signalStrength = 0;
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
qulonglong getDeviceRxRefreshRate(QString deviceName);
|
||||
qulonglong getDeviceTxRefreshRate(QString deviceName);
|
||||
|
||||
void getDeviceConnectivity(const QString &deviceName, NetworkManager::Connectivity &connectivity);
|
||||
|
||||
private:
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
|
|
|
@ -329,7 +329,7 @@ void MainWindow::initTrayIcon()
|
|||
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
|
||||
m_showSettingsAction = new QAction(tr("Settings"),this);
|
||||
|
||||
m_trayIcon->setToolTip(QString(tr("Network tool")));
|
||||
// m_trayIcon->setToolTip(QString(tr("Network tool")));
|
||||
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
|
||||
// m_trayIconMenu->addAction(m_showMainwindowAction);
|
||||
m_trayIconMenu->addAction(m_showSettingsAction);
|
||||
|
@ -376,6 +376,11 @@ void MainWindow::initDbusConnnect()
|
|||
connect(m_wlanWidget, &WlanPage::showMainWindow, this, &MainWindow::onShowMainWindow);
|
||||
connect(m_wlanWidget, &WlanPage::connectivityChanged, this, &MainWindow::onConnectivityChanged);
|
||||
|
||||
connect(m_lanWidget, &LanPage::lanConnectChanged, this, &MainWindow::onRefreshTrayIconTooltip);
|
||||
connect(m_lanWidget, &LanPage::deviceStatusChanged, this, &MainWindow::onRefreshTrayIconTooltip);
|
||||
connect(m_wlanWidget, &WlanPage::wlanConnectChanged, this, &MainWindow::onRefreshTrayIconTooltip);
|
||||
connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::onRefreshTrayIconTooltip);
|
||||
|
||||
//模式切换
|
||||
QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"),
|
||||
QString("/"),
|
||||
|
@ -555,6 +560,35 @@ void MainWindow::setCentralWidgetType(IconActiveType iconStatus)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::assembleTrayIconTooltip 整理托盘图标tooltip内容
|
||||
* @param map <网卡名,网络状态>
|
||||
* @param tip tooltip
|
||||
*/
|
||||
void MainWindow::assembleTrayIconTooltip(QMap<QString, QString> &map, QString &tip)
|
||||
{
|
||||
if (map.isEmpty()) {
|
||||
tip = QString(tr("Network tool"));
|
||||
return;
|
||||
}
|
||||
QMap<QString, QString>::iterator iter = map.begin();
|
||||
if (map.size() == 1) {
|
||||
tip = map.value(iter.key());
|
||||
} else if (map.size() > 1) {
|
||||
tip = "";
|
||||
int count = 0;
|
||||
while (iter != map.end()) {
|
||||
count += 1;
|
||||
tip += QString(tr("Network Card")) + QString("%1").arg(count) + "\n" + map.value(iter.key());
|
||||
++iter;
|
||||
|
||||
if (iter != map.end()) {
|
||||
tip += "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::onTrayIconActivated 点击托盘图标的槽函数
|
||||
*/
|
||||
|
@ -652,6 +686,7 @@ void MainWindow::onRefreshTrayIcon()
|
|||
m_trayIcon->setIcon(QIcon::fromTheme(NONE_SIGNAL_LIMIT_ICON));
|
||||
}
|
||||
}
|
||||
onRefreshTrayIconTooltip();
|
||||
}
|
||||
|
||||
void MainWindow::onSetTrayIconLoading()
|
||||
|
@ -703,6 +738,44 @@ void MainWindow::onTabletModeChanged(bool mode)
|
|||
hideMainwindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MainWindow::onRefreshTrayIconTooltip 根据托盘图标调整其tooltip
|
||||
*/
|
||||
void MainWindow::onRefreshTrayIconTooltip()
|
||||
{
|
||||
if (!m_trayIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString trayIconToolTip = "";
|
||||
QMap<QString, QString> lanMap;
|
||||
QMap<QString, QString> wlanMap;
|
||||
switch(iconStatus) {
|
||||
case IconActiveType::NOT_CONNECTED:
|
||||
trayIconToolTip = QString(tr("Not connected to the network"));
|
||||
break;
|
||||
|
||||
case LAN_CONNECTED:
|
||||
case IconActiveType::LAN_CONNECTED_LIMITED:
|
||||
m_lanWidget->getWiredDeviceConnectState(lanMap);
|
||||
assembleTrayIconTooltip(lanMap, trayIconToolTip);
|
||||
break;
|
||||
|
||||
case IconActiveType::WLAN_CONNECTED:
|
||||
case IconActiveType::WLAN_CONNECTED_LIMITED:
|
||||
m_wlanWidget->getWirelssDeviceConnectState(wlanMap);
|
||||
assembleTrayIconTooltip(wlanMap, trayIconToolTip);
|
||||
break;
|
||||
|
||||
case IconActiveType::ACTIVATING:
|
||||
default:
|
||||
trayIconToolTip = QString(tr("Network tool"));
|
||||
break;
|
||||
}
|
||||
|
||||
m_trayIcon->setToolTip(trayIconToolTip);
|
||||
}
|
||||
|
||||
void MainWindow::onShowMainWindow(int type)
|
||||
{
|
||||
if (type == LANPAGE || type == WLANPAGE) {
|
||||
|
|
|
@ -161,6 +161,7 @@ private:
|
|||
void showControlCenter();
|
||||
void showByWaylandHelper();
|
||||
void setCentralWidgetType(IconActiveType iconStatus);
|
||||
void assembleTrayIconTooltip(QMap<QString, QString> &map, QString &tip);
|
||||
double m_transparency=1.0; //透明度
|
||||
QGSettings * m_transGsettings; //透明度配置文件
|
||||
int currentIconIndex=0;
|
||||
|
@ -215,6 +216,7 @@ private Q_SLOTS:
|
|||
void onWlanConnectStatusToChangeTrayIcon(int state);
|
||||
void onConnectivityChanged(NetworkManager::Connectivity connectivity);
|
||||
void onTabletModeChanged(bool mode);
|
||||
void onRefreshTrayIconTooltip();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -1303,6 +1303,38 @@ bool LanPage::lanIsConnected()
|
|||
}
|
||||
}
|
||||
|
||||
void LanPage::getWiredDeviceConnectState(QMap<QString, QString> &map)
|
||||
{
|
||||
map.clear();
|
||||
if (m_enableDeviceList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto devname : m_enableDeviceList) {
|
||||
NetworkManager::Connectivity state;
|
||||
QList<KyConnectItem *> activedList;
|
||||
m_deviceResource->getDeviceConnectivity(devname, state);
|
||||
|
||||
if (state < NetworkManager::Connectivity::Full) {
|
||||
m_activeResourse->getActiveConnectionList(devname, NetworkManager::ConnectionSettings::Wired, activedList);
|
||||
if (!activedList.isEmpty()) {
|
||||
map.insert(devname, QString(tr("Connected: ")) + activedList.at(0)->m_connectName + QString(tr("(Limited)")));
|
||||
} else {
|
||||
map.insert(devname, tr("Not Connected"));
|
||||
}
|
||||
|
||||
} else if (state == NetworkManager::Connectivity::Full) {
|
||||
m_activeResourse->getActiveConnectionList(devname, NetworkManager::ConnectionSettings::Wired, activedList);
|
||||
if (!activedList.isEmpty()) {
|
||||
map.insert(devname, QString(tr("Connected: ")) + activedList.at(0)->m_connectName);
|
||||
}
|
||||
|
||||
} else {
|
||||
qDebug() << devname << " Network connectivity is unknown.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::showRate()
|
||||
{
|
||||
//定时获取网速
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
void setWiredDeviceEnable(const QString& devName, bool enable);
|
||||
|
||||
bool lanIsConnected();
|
||||
void getWiredDeviceConnectState(QMap<QString, QString> &map);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
|
|
@ -1657,3 +1657,35 @@ int WlanPage::getAcivateWifiSignal()
|
|||
{
|
||||
return m_activatedConnectResource->getAcivateWifiSignal();
|
||||
}
|
||||
|
||||
void WlanPage::getWirelssDeviceConnectState(QMap<QString, QString> &map)
|
||||
{
|
||||
map.clear();
|
||||
if (m_devList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto devname : m_devList) {
|
||||
NetworkManager::Connectivity state;
|
||||
KyWirelessNetItem wirelessNetItem;
|
||||
if (!m_netDeviceResource->getDeviceManaged(devname)) {
|
||||
continue;
|
||||
}
|
||||
m_netDeviceResource->getDeviceConnectivity(devname, state);
|
||||
if (state < NetworkManager::Connectivity::Full) {
|
||||
if (m_wirelessNetResource->getActiveWirelessNetItem(devname, wirelessNetItem)) {
|
||||
map.insert(devname, QString(tr("Connected: ")) + wirelessNetItem.m_connName + QString(tr("(Limited)")));
|
||||
} else {
|
||||
map.insert(devname, tr("Not Connected"));
|
||||
}
|
||||
|
||||
} else if (state == NetworkManager::Connectivity::Full) {
|
||||
if (m_wirelessNetResource->getActiveWirelessNetItem(devname, wirelessNetItem)) {
|
||||
map.insert(devname, QString(tr("Connected: ")) + wirelessNetItem.m_connName);
|
||||
}
|
||||
|
||||
} else {
|
||||
qDebug() << devname << " Network connectivity is unknown.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,9 @@ public:
|
|||
|
||||
int getAcivateWifiSignal();
|
||||
|
||||
//无线网卡连通性
|
||||
void getWirelssDeviceConnectState(QMap<QString, QString> &map);
|
||||
|
||||
Q_SIGNALS:
|
||||
void oneItemExpanded(const QString &ssid);
|
||||
void wlanAdd(QString devName, QStringList info);
|
||||
|
|
|
@ -761,6 +761,18 @@
|
|||
<source>LAN Connected Successfully</source>
|
||||
<translation type="vanished">སྐུད་ཡོད་དྲ་བ་སྦྲེལ་ཡོད།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Connected: </source>
|
||||
<translation>འབྲེལ་མཐུད་བྱུང་ཡོད།: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not Connected</source>
|
||||
<translation>འབྲེལ་མཐུད་མ་བྱས་པ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>(Limited)</source>
|
||||
<translation>(དྲ་བར་ཚོད་འཛིན་ཐེབས་པ་རེད།)</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ListItem</name>
|
||||
|
@ -810,6 +822,14 @@
|
|||
<source>Network tool</source>
|
||||
<translation>དྲ་རྒྱའི་ལག་ཆ་</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Network Card</source>
|
||||
<translation>དྲ་བྱང་།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not connected to the network</source>
|
||||
<translation>དྲ་རྒྱ་དང་སྦྲེལ་མཐུད་མ་བྱས་པ།</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NetDetail</name>
|
||||
|
@ -1415,6 +1435,18 @@
|
|||
<source>WLAN Disconnected Successfully</source>
|
||||
<translation>སྐུད་མེད་དྲ་རྒྱ་ཆད་སོང་།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Connected: </source>
|
||||
<translation>འབྲེལ་མཐུད་བྱུང་ཡོད།: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not Connected</source>
|
||||
<translation>འབྲེལ་མཐུད་མ་བྱས་པ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>(Limited)</source>
|
||||
<translation>(དྲ་བར་ཚོད་འཛིན་ཐེབས་པ་རེད།)</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>WpaWifiDialog</name>
|
||||
|
|
|
@ -761,6 +761,18 @@
|
|||
<source>LAN Connected Successfully</source>
|
||||
<translation type="vanished">有线网络已连接</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Connected: </source>
|
||||
<translation>已连接: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not Connected</source>
|
||||
<translation>未连接</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>(Limited)</source>
|
||||
<translation>(网络受限)</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ListItem</name>
|
||||
|
@ -810,6 +822,14 @@
|
|||
<source>Network tool</source>
|
||||
<translation>网络工具</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Network Card</source>
|
||||
<translation>网卡</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not connected to the network</source>
|
||||
<translation>未连接网络</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NetDetail</name>
|
||||
|
@ -1407,6 +1427,18 @@
|
|||
<source>WLAN Disconnected Successfully</source>
|
||||
<translation>无线网络已断开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Connected: </source>
|
||||
<translation>已连接: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Not Connected</source>
|
||||
<translation>未连接</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>(Limited)</source>
|
||||
<translation>(网络受限)</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>WpaWifiDialog</name>
|
||||
|
|
Loading…
Reference in New Issue