!21 修复 PC模式下,任务栏无网络图标

Merge pull request !21 from zy-yuan1/eap3
This commit is contained in:
zhaoshixu 2023-01-06 08:21:00 +00:00 committed by Gitee
commit d1c1e02b4f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 29 additions and 4 deletions

View File

@ -115,6 +115,7 @@ void MainWindow::firstlyStart()
{
initWindowProperties();
initTransparency();
registerTrayIcon();
initUI();
initDbusConnnect();
initWindowTheme();
@ -265,6 +266,30 @@ void MainWindow::initUI()
paintWithTrans();
}
/**
* @brief MainWindow::registerTrayIcon
*/
void MainWindow::registerTrayIcon()
{
m_registerCount++;
if (QSystemTrayIcon::isSystemTrayAvailable() || m_registerCount > 10) {
m_trayIcon = new QSystemTrayIcon();
if (nullptr == m_trayIcon) {
qWarning()<< "分配空间trayIcon失败";
return ;
}
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
} else {
if (m_registerCount <= 10) {
QTimer::singleShot(m_intervalTime,[this] {
registerTrayIcon();
});
}
}
}
/**
* @brief MainWindow::initTrayIcon
*/
@ -285,17 +310,14 @@ void MainWindow::initTrayIcon()
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);
m_showSettingsAction = new QAction(tr("Settings"),this);
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
// m_trayIconMenu->addAction(m_showMainwindowAction);
m_trayIconMenu->addAction(m_showSettingsAction);
m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED;
onRefreshTrayIcon();

View File

@ -124,6 +124,7 @@ private:
void paintWithTrans();
void initUI();
void initDbusConnnect();
void registerTrayIcon();
void initTrayIcon();
void resetTrayIconTool();
void initWindowTheme();
@ -157,6 +158,8 @@ private:
QMenu * m_trayIconMenu = nullptr;
QAction * m_showMainwindowAction = nullptr;
QAction * m_showSettingsAction = nullptr;
uint m_intervalTime = 100;
uint m_registerCount = 0;
bool m_lanIsLoading = false;
bool m_wlanIsLoading = false;