mainwindow暂存

This commit is contained in:
zhangyuanyuan1 2023-04-03 10:12:48 +08:00
parent 4c8b7a37c3
commit f13e392f14
6 changed files with 347 additions and 202 deletions

View File

@ -1,23 +1,24 @@
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
include(tools/tools.pri) #include(tools/tools.pri)
include(xatom/xatom.pri) #include(xatom/xatom.pri)
include(tab-pages/tab-pages.pri) #include(tab-pages/tab-pages.pri)
include(list-items/list-items.pri) #include(list-items/list-items.pri)
include(netdetails/netdetails.pri) #include(netdetails/netdetails.pri)
include(enterprise-wlan/enterprise-wlan.pri) #include(enterprise-wlan/enterprise-wlan.pri)
include(single-pages/single-pages.pri) #include(single-pages/single-pages.pri)
include(networkmode/networkmode.pri)
FORMS += \ FORMS += \
$$PWD/wificonfigdialog.ui # $$PWD/wificonfigdialog.ui
HEADERS += \ HEADERS += \
$$PWD/customstyle.h \ $$PWD/customstyle.h \
$$PWD/mainwindow.h \ $$PWD/mainwindow.h \
$$PWD/wificonfigdialog.h \ # $$PWD/wificonfigdialog.h \
$$PWD/vpnobject.h # $$PWD/vpnobject.h
SOURCES += \ SOURCES += \
$$PWD/customstyle.cpp \ $$PWD/customstyle.cpp \
$$PWD/mainwindow.cpp \ $$PWD/mainwindow.cpp \
$$PWD/wificonfigdialog.cpp \ # $$PWD/wificonfigdialog.cpp \
$$PWD/vpnobject.cpp # $$PWD/vpnobject.cpp

View File

@ -9,12 +9,14 @@
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include "kylinnetworkdeviceresource.h" //#include "kylinnetworkdeviceresource.h"
#include "../backend/dbus-interface/kylinagentinterface.h" //#include "../backend/dbus-interface/kylinagentinterface.h"
#include "ukuistylehelper/ukuistylehelper.h" #include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h" #include "windowmanager/windowmanager.h"
#include <kwindowsystem.h>
#include <kwindowsystem_export.h>
#include "kysdk/kysdk-system/libkysysinfo.h"
#define MAINWINDOW_WIDTH 420 #define MAINWINDOW_WIDTH 420
#define MAINWINDOW_HEIGHT 476 #define MAINWINDOW_HEIGHT 476
@ -28,12 +30,33 @@ const QString intel = "V10SP1-edu";
#define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES" #define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES"
#include <kwindowsystem.h> #define LAN_PAGE_INDEX 0
#include <kwindowsystem_export.h> #define WLAN_PAGE_INDEX 1
#include "kysdk/kysdk-system/libkysysinfo.h"
#define EXCELLENT_SIGNAL 80
#define GOOD_SIGNAL 55
#define OK_SIGNAL 30
#define LOW_SIGNAL 5
#define NONE_SIGNAL 0
#define EXCELLENT_SIGNAL_ICON "network-wireless-signal-excellent-symbolic"
#define GOOD_SIGNAL_ICON "network-wireless-signal-good-symbolic"
#define OK_SIGNAL_ICON "network-wireless-signal-ok-symbolic"
#define LOW_SIGNAL_ICON "network-wireless-signal-weak-symbolic"
#define NONE_SIGNAL_ICON "network-wireless-signal-none-symbolic"
#define EXCELLENT_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-excellent-error-symbolic"
#define GOOD_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-good-error-symbolic"
#define OK_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-ok-error-symbolic"
#define LOW_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-weak-error-symbolic"
#define NONE_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-none-error-symbolic"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{ {
qRegisterMetaType<KyConnectState>("KyConnectState");
qRegisterMetaType<KyConnectStatus>("KyConnectStatus");
qRegisterMetaType<KyConnectionType>("KyConnectionType");
firstlyStart(); firstlyStart();
} }
@ -66,17 +89,17 @@ void MainWindow::showMainwindow()
#ifdef WITHKYSEC #ifdef WITHKYSEC
if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){ if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){
if (nullptr != m_wlanWidget) { if (nullptr != m_wlanWidget) {
m_wlanWidget->hideSetting(); //todo m_wlanWidget->hideSetting();
} }
if (nullptr != m_lanWidget) { if (nullptr != m_lanWidget) {
m_lanWidget->hideSetting(); //todo m_lanWidget->hideSetting();
} }
} else { } else {
if (nullptr != m_wlanWidget) { if (nullptr != m_wlanWidget) {
m_wlanWidget->showSetting(); //todo m_wlanWidget->showSetting();
} }
if (nullptr != m_lanWidget) { if (nullptr != m_lanWidget) {
m_lanWidget->showSetting(); //todo m_lanWidget->showSetting();
} }
} }
#endif #endif
@ -129,10 +152,12 @@ void MainWindow::firstlyStart()
}); });
m_secondaryStartTimer->start(5 * 1000); m_secondaryStartTimer->start(5 * 1000);
m_createPagePtrMap.clear(); m_networkMode = new NetworkModeConfig(this);
m_networkMode->initWiredNetworkMode();
m_networkMode->initWirelessNetworkMode();
//加载key ring //加载key ring
agent_init(); // agent_init();
// system("kylin-keyring --start &");
} }
/** /**
@ -243,26 +268,23 @@ void MainWindow::initUI()
this->setCentralWidget(m_centralWidget); this->setCentralWidget(m_centralWidget);
m_centralWidget->tabBar()->setFixedWidth(this->width()+1); m_centralWidget->tabBar()->setFixedWidth(this->width()+1);
m_centralWidget->tabBar()->setProperty("setRadius", 12); m_centralWidget->tabBar()->setProperty("setRadius", 12);
m_lanWidget = new LanPage(m_centralWidget);
m_wlanWidget = new WlanPage(m_centralWidget);
connect(this, &MainWindow::mainWindowVisibleChanged, m_wlanWidget, &WlanPage::onMainWindowVisibleChanged);
// m_centralWidget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN"));
// m_centralWidget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN"));
loadLanPlugin();
loadWlanPlugin();
m_centralWidget->addTab(m_lanWidget, tr("")); m_centralWidget->addTab(m_lanWidget, tr(""));
m_centralWidget->addTab(m_wlanWidget, tr("")); m_centralWidget->addTab(m_wlanWidget, tr(""));
m_lanLabel = new QLabel(tr("LAN"), m_centralWidget);
m_lanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_wlanLabel = new QLabel(tr("WLAN"), m_centralWidget);
m_wlanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_tabBarLayout = new QHBoxLayout(this); m_tabBarLayout = new QHBoxLayout(this);
m_tabBarLayout->setContentsMargins(LAYOUT_MARGINS); m_tabBarLayout->setContentsMargins(LAYOUT_MARGINS);
m_lanLabel = new QLabel(tr("LAN"));
m_lanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_wlanLabel = new QLabel(tr("WLAN"));
m_wlanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_tabBarLayout->addWidget(m_lanLabel); m_tabBarLayout->addWidget(m_lanLabel);
m_tabBarLayout->addWidget(m_wlanLabel); m_tabBarLayout->addWidget(m_wlanLabel);
m_centralWidget->tabBar()->setLayout(m_tabBarLayout); m_centralWidget->tabBar()->setLayout(m_tabBarLayout);
m_centralWidget->tabBar()->setProperty("useTabbarSeparateLine", false); // 去掉中间的分割线 m_centralWidget->tabBar()->setProperty("useTabbarSeparateLine", false); // 去掉中间的分割线
m_centralWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题 m_centralWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题
connect(m_centralWidget, &QTabWidget::currentChanged, m_wlanWidget, &WlanPage::onWlanPageVisibleChanged);
paintWithTrans(); paintWithTrans();
} }
@ -295,20 +317,29 @@ void MainWindow::registerTrayIcon()
*/ */
void MainWindow::initTrayIcon() void MainWindow::initTrayIcon()
{ {
loadIcons.append(QIcon::fromTheme("kylin-network-1")); m_thread = new QThread;
loadIcons.append(QIcon::fromTheme("kylin-network-2")); m_manager = new KyNetworkManager();
loadIcons.append(QIcon::fromTheme("kylin-network-3")); m_manager->moveToThread(m_thread);
loadIcons.append(QIcon::fromTheme("kylin-network-4")); connect(m_thread, &QThread::started, m_manager, &KyNetworkManager::kylinNetworkManagerInit);
loadIcons.append(QIcon::fromTheme("kylin-network-5")); connect(m_thread, &QThread::finished, m_manager, &KyNetworkManager::deleteLater);
loadIcons.append(QIcon::fromTheme("kylin-network-6")); m_thread->start();
loadIcons.append(QIcon::fromTheme("kylin-network-7"));
loadIcons.append(QIcon::fromTheme("kylin-network-8")); while (!m_manager->isInitFinished()) {
loadIcons.append(QIcon::fromTheme("kylin-network-9")); ::usleep(1000);
loadIcons.append(QIcon::fromTheme("kylin-network-10")); }
loadIcons.append(QIcon::fromTheme("kylin-network-11"));
loadIcons.append(QIcon::fromTheme("kylin-network-12")); m_loadIcons.append(QIcon::fromTheme("kylin-network-1"));
iconTimer = new QTimer(this); m_loadIcons.append(QIcon::fromTheme("kylin-network-2"));
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading); m_loadIcons.append(QIcon::fromTheme("kylin-network-3"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-4"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-5"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-6"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-7"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-8"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-9"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-10"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-11"));
m_loadIcons.append(QIcon::fromTheme("kylin-network-12"));
m_trayIconMenu = new QMenu(); m_trayIconMenu = new QMenu();
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
@ -316,19 +347,32 @@ void MainWindow::initTrayIcon()
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
// m_trayIconMenu->addAction(m_showMainwindowAction); // m_trayIconMenu->addAction(m_showMainwindowAction);
m_trayIconMenu->addAction(m_showSettingsAction); m_trayIconMenu->addAction(m_showSettingsAction);
m_trayIcon->setContextMenu(m_trayIconMenu); m_trayIcon->setContextMenu(m_trayIconMenu);
iconStatus = IconActiveType::LAN_CONNECTED;
onRefreshTrayIcon(); m_loadingTimer = new QTimer(this);
connect(m_loadingTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
m_refreshTimer = new QTimer(this);
connect(m_refreshTimer, &QTimer::timeout, this, &MainWindow::updateIcon);
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated); connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
// connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled); // connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled);
connect(m_showSettingsAction, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled); connect(m_showSettingsAction, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled);
connect(m_manager, &KyNetworkManager::wiredStateChange, this, &MainWindow::onWiredStateChange);
connect(m_manager, &KyNetworkManager::wirelessStateChange, this, &MainWindow::onWirelessStateChange);
connect(m_manager, &KyNetworkManager::connectStatusChanged , [=](KyConnectStatus status){
m_iconStatus = status;
updateIcon();
});
m_manager->getConnectStatus(m_iconStatus);
updateIcon();
m_refreshTimer->start(10 * 1000);
m_trayIcon->show(); m_trayIcon->show();
} }
void MainWindow::initDbusConnnect() void MainWindow::initDbusConnnect()
{ {
#if 0
connect(m_lanWidget, &LanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged); connect(m_lanWidget, &LanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged);
connect(m_lanWidget, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); connect(m_lanWidget, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged);
connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged); connect(m_wlanWidget, &WlanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged);
@ -357,7 +401,7 @@ void MainWindow::initDbusConnnect()
connect(m_wlanWidget, &WlanPage::timeToUpdate , this, &MainWindow::timeToUpdate); connect(m_wlanWidget, &WlanPage::timeToUpdate , this, &MainWindow::timeToUpdate);
connect(m_wlanWidget, &WlanPage::showMainWindow, this, &MainWindow::onShowMainWindow); connect(m_wlanWidget, &WlanPage::showMainWindow, this, &MainWindow::onShowMainWindow);
connect(m_wlanWidget, &WlanPage::connectivityChanged, this, &MainWindow::onConnectivityChanged); connect(m_wlanWidget, &WlanPage::connectivityChanged, this, &MainWindow::onConnectivityChanged);
#endif
//模式切换 //模式切换
QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"), QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"),
QString("/"), QString("/"),
@ -497,7 +541,7 @@ void MainWindow::resetWindowTheme()
void MainWindow::showControlCenter() void MainWindow::showControlCenter()
{ {
QProcess process; QProcess process;
if (!m_lanWidget->lanIsConnected() && m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){ if (m_iconStatus == WLAN_CONNECTED || m_iconStatus == WLAN_CONNECTED_LIMITED){
process.startDetached("ukui-control-center -m wlanconnect"); process.startDetached("ukui-control-center -m wlanconnect");
} else { } else {
process.startDetached("ukui-control-center -m netconnect"); process.startDetached("ukui-control-center -m netconnect");
@ -514,6 +558,74 @@ void MainWindow::showByWaylandHelper()
} }
void MainWindow::loadLanPlugin()
{
m_lanWidget = new QWidget(this);
QPluginLoader lanPageLoader("/home/kylin/kylin-nm-plugin/build-kylin-nm-unknown-Debug/libnetconnect.so");//有线
if (lanPageLoader.load()) {
QObject * plugin = lanPageLoader.instance();
if (plugin) {
Interface * lanPluginInstance = qobject_cast<Interface *>(plugin);
// 插件是否启用
if (!lanPluginInstance) {
return;
}
lanPluginInstance->setPluginType(COMPLEX, true);
m_lanWidget = lanPluginInstance->pluginUi();
lanPluginInstance->setParentWidget(m_centralWidget);
} else {
qDebug() << "Load lanPage Failed: " << lanPageLoader.errorString() << "\n";
return;
}
} else {
qDebug() << "Load lanPage Failed: " << lanPageLoader.errorString() << "\n";
return;
}
}
void MainWindow::loadWlanPlugin()
{
m_wlanWidget = new QWidget(this);
QPluginLoader wlanPageLoader("/home/kylin/kylin-nm-plugin/build-kylin-nm-unknown-Debug/libwlanconnect.so");//无线
if (wlanPageLoader.load()) {
QObject * plugin = wlanPageLoader.instance();
if (plugin) {
Interface * wlanPluginInstance = qobject_cast<Interface *>(plugin);
// 插件是否启用
if (!wlanPluginInstance) {
return;
}
wlanPluginInstance->setPluginType(COMPLEX, true);
m_wlanWidget = wlanPluginInstance->pluginUi();
wlanPluginInstance->setParentWidget(m_centralWidget);
} else {
qDebug() << "Load wlanPage Failed: " << wlanPageLoader.errorString() << "\n";
return;
}
} else {
qDebug() << "Load wlanPage Failed: " << wlanPageLoader.errorString() << "\n";
return;
}
}
void MainWindow::startLoading()
{
if (!m_loadingTimer->isActive()) {
m_loadingTimer->start(60);
}
}
void MainWindow::stopLoading()
{
if (m_loadingTimer->isActive()) {
m_loadingTimer->stop();
}
}
/** /**
* @brief MainWindow::onTrayIconActivated * @brief MainWindow::onTrayIconActivated
*/ */
@ -554,73 +666,92 @@ void MainWindow::onThemeChanged(const QString &key)
} }
} }
void MainWindow::onRefreshTrayIcon()
{
//更新托盘图标显示
iconTimer->stop();
if (m_lanWidget->lanIsConnected()) {
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED;
} else if (m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){
m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-connected-symbolic"));
iconStatus = IconActiveType::WLAN_CONNECTED;
} else {
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
iconStatus = IconActiveType::NOT_CONNECTED;
}
NetworkManager::Connectivity connecttivity;
m_wlanWidget->getConnectivity(connecttivity);
if (connecttivity != NetworkManager::Connectivity::Full) {
if (iconStatus == IconActiveType::LAN_CONNECTED) {
m_trayIcon->setIcon(QIcon::fromTheme("network-error-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED_LIMITED;
} else if (iconStatus == IconActiveType::WLAN_CONNECTED) {
//todo 信号强度
m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-error-symbolic"));
iconStatus = IconActiveType::WLAN_CONNECTED_LIMITED;
}
}
}
void MainWindow::onSetTrayIconLoading() void MainWindow::onSetTrayIconLoading()
{ {
if (currentIconIndex > 11) { if (m_currentIconIndex > 11) {
currentIconIndex = 0; m_currentIconIndex = 0;
} }
m_trayIcon->setIcon(loadIcons.at(currentIconIndex)); m_trayIcon->setIcon(m_loadIcons.at(m_currentIconIndex));
iconStatus = IconActiveType::ACTIVATING; m_currentIconIndex ++;
currentIconIndex ++;
} }
void MainWindow::onLanConnectStatusToChangeTrayIcon(int state) //更新托盘图标显示
void MainWindow::updateIcon()
{ {
qDebug() << "lan state:" << state << Q_FUNC_INFO << __LINE__; if (m_loadingTimer->isActive()) {
if (state==1 || state==3){
m_lanIsLoading = true;
iconTimer->start(LOADING_TRAYICON_TIMER_MS);
} else {
m_lanIsLoading = false;
if (m_wlanIsLoading == false) {
onRefreshTrayIcon();
}
}
}
void MainWindow::onWlanConnectStatusToChangeTrayIcon(int state)
{
qDebug() << "wlan state:" << state << Q_FUNC_INFO << __LINE__;
if (state==1 || state==3){
m_wlanIsLoading = true;
iconTimer->start(LOADING_TRAYICON_TIMER_MS);
} else {
if (m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activating)) {
return; return;
} }
m_wlanIsLoading = false; int signalStrength = 0;
if (m_lanIsLoading == false) { QIcon icon;
onRefreshTrayIcon();
if (m_iconStatus == LAN_CONNECTED) {
icon = QIcon::fromTheme("network-wired-symbolic");
m_trayIcon->setIcon(icon);
return;
} else if (m_iconStatus == WLAN_CONNECTED
|| m_iconStatus == WLAN_CONNECTED_LIMITED) {
signalStrength = m_manager->getAcivateWifiSignal();
} else if (m_iconStatus == NOT_CONNECTED) {
icon = QIcon::fromTheme("network-wired-disconnected-symbolic");
m_trayIcon->setIcon(icon);
return;
} else if (m_iconStatus == LAN_CONNECTED_LIMITED) {
icon = QIcon::fromTheme("network-error-symbolic");
} }
if (m_iconStatus == WLAN_CONNECTED) {
if (signalStrength > EXCELLENT_SIGNAL){
icon = QIcon::fromTheme(EXCELLENT_SIGNAL_ICON);
} else if (signalStrength > GOOD_SIGNAL) {
icon = QIcon::fromTheme(GOOD_SIGNAL_ICON);
} else if (signalStrength > OK_SIGNAL) {
icon = QIcon::fromTheme(OK_SIGNAL_ICON);
} else if (signalStrength > LOW_SIGNAL) {
icon = QIcon::fromTheme(LOW_SIGNAL_ICON);
} else {
icon = QIcon::fromTheme(NONE_SIGNAL_ICON);
}
} else if (m_iconStatus == WLAN_CONNECTED_LIMITED) {
if (signalStrength > EXCELLENT_SIGNAL){
icon = QIcon::fromTheme(EXCELLENT_SIGNAL_LIMIT_ICON);
} else if (signalStrength > GOOD_SIGNAL) {
icon = QIcon::fromTheme(GOOD_SIGNAL_LIMIT_ICON);
} else if (signalStrength > OK_SIGNAL) {
icon = QIcon::fromTheme(OK_SIGNAL_LIMIT_ICON);
} else if (signalStrength > LOW_SIGNAL) {
icon = QIcon::fromTheme(LOW_SIGNAL_LIMIT_ICON);
} else {
icon = QIcon::fromTheme(NONE_SIGNAL_LIMIT_ICON);
}
}
m_trayIcon->setIcon(icon);
}
void MainWindow::onWiredStateChange(QString deviceName, QString uuid, KyConnectState state)
{
Q_UNUSED(deviceName)
Q_UNUSED(uuid)
if (state == CONNECT_STATE_ACTIVATING
|| state == CONNECT_STATE_DEACTIVATING) {
startLoading();
} else {
stopLoading();
updateIcon();
}
}
void MainWindow::onWirelessStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state)
{
Q_UNUSED(deviceName)
Q_UNUSED(ssid)
Q_UNUSED(uuid)
if (state == CONNECT_STATE_ACTIVATING
|| state == CONNECT_STATE_DEACTIVATING) {
startLoading();
} else {
stopLoading();
updateIcon();
} }
} }
@ -641,19 +772,6 @@ void MainWindow::onShowMainWindow(int type)
} }
} }
void MainWindow::onConnectivityChanged(NetworkManager::Connectivity connectivity)
{
if (!m_trayIcon) {
return;
}
if (iconStatus == ACTIVATING) {
return;
}
onRefreshTrayIcon();
}
/** /**
* @brief MainWindow::keyPressEvent esc键关闭主界面 * @brief MainWindow::keyPressEvent esc键关闭主界面
* @param event * @param event
@ -681,7 +799,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
} }
return QMainWindow::eventFilter(watched,event); return QMainWindow::eventFilter(watched,event);
} }
#if 0
/** /**
* @brief MainWindow::getWirelessList wifi列表dbus调用 * @brief MainWindow::getWirelessList wifi列表dbus调用
* @param map * @param map
@ -689,9 +807,9 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
void MainWindow::getWirelessList(QMap<QString, QVector<QStringList> > &map) void MainWindow::getWirelessList(QMap<QString, QVector<QStringList> > &map)
{ {
map.clear(); map.clear();
if (nullptr != m_wlanWidget) { // if (nullptr != m_wlanWidget) {
m_wlanWidget->getWirelessList(map); // m_wlanWidget->getWirelessList(map);
} // }
} }
/** /**
@ -701,9 +819,9 @@ void MainWindow::getWirelessList(QMap<QString, QVector<QStringList> > &map)
void MainWindow::getWiredList(QMap<QString, QVector<QStringList>> &map) void MainWindow::getWiredList(QMap<QString, QVector<QStringList>> &map)
{ {
map.clear(); map.clear();
if (nullptr != m_lanWidget) { // if (nullptr != m_lanWidget) {
m_lanWidget->getWiredList(map); // m_lanWidget->getWiredList(map);
} // }
} }
/** /**
@ -714,7 +832,7 @@ void MainWindow::getWiredList(QMap<QString, QVector<QStringList>> &map)
*/ */
void MainWindow::activeWirelessAp(const QString apName, const QString apPassword, const QString band, const QString apDevice) void MainWindow::activeWirelessAp(const QString apName, const QString apPassword, const QString band, const QString apDevice)
{ {
m_wlanWidget->activeWirelessAp(apName, apPassword, band, apDevice); // m_wlanWidget->activeWirelessAp(apName, apPassword, band, apDevice);
} }
/** /**
@ -723,7 +841,7 @@ void MainWindow::activeWirelessAp(const QString apName, const QString apPassword
*/ */
void MainWindow::deactiveWirelessAp(const QString apName, const QString uuid) void MainWindow::deactiveWirelessAp(const QString apName, const QString uuid)
{ {
m_wlanWidget->deactiveWirelessAp(apName, uuid); // m_wlanWidget->deactiveWirelessAp(apName, uuid);
} }
/** /**
@ -732,24 +850,25 @@ void MainWindow::deactiveWirelessAp(const QString apName, const QString uuid)
*/ */
void MainWindow::getApInfoBySsid(QString devName, QString ssid, QStringList &list) void MainWindow::getApInfoBySsid(QString devName, QString ssid, QStringList &list)
{ {
m_wlanWidget->getApInfoBySsid(devName, ssid, list); // m_wlanWidget->getApInfoBySsid(devName, ssid, list);
} }
void MainWindow::getStoredApInfo(QStringList &list) void MainWindow::getStoredApInfo(QStringList &list)
{ {
m_wlanWidget->getStoredApInfo(list); // m_wlanWidget->getStoredApInfo(list);
} }
//无线开关 //无线开关
void MainWindow::setWirelessSwitchEnable(bool enable) void MainWindow::setWirelessSwitchEnable(bool enable)
{ {
m_wlanWidget->setWirelessSwitchEnable(enable); // m_wlanWidget->setWirelessSwitchEnable(enable);
} }
void MainWindow::setWiredDeviceEnable(const QString& devName, bool enable) void MainWindow::setWiredDeviceEnable(const QString& devName, bool enable)
{ {
m_lanWidget->setWiredDeviceEnable(devName, enable); // m_lanWidget->setWiredDeviceEnable(devName, enable);
} }
void MainWindow::showPropertyWidget(QString devName, QString ssid) void MainWindow::showPropertyWidget(QString devName, QString ssid)
{ {
KyNetworkDeviceResourse *devResourse = new KyNetworkDeviceResourse(); KyNetworkDeviceResourse *devResourse = new KyNetworkDeviceResourse();
@ -825,47 +944,48 @@ void MainWindow::showAddOtherWlanWidget(QString devName)
void MainWindow::getWirelessDeviceCap(QMap<QString, int> &map) void MainWindow::getWirelessDeviceCap(QMap<QString, int> &map)
{ {
m_wlanWidget->getWirelessDeviceCap(map); // m_wlanWidget->getWirelessDeviceCap(map);
} }
//有线连接删除 //有线连接删除
void MainWindow::deleteWired(const QString &connUuid) void MainWindow::deleteWired(const QString &connUuid)
{ {
m_lanWidget->deleteWired(connUuid); // m_lanWidget->deleteWired(connUuid);
} }
//有线连接断开 //有线连接断开
void MainWindow::activateWired(const QString& devName, const QString& connUuid) void MainWindow::activateWired(const QString& devName, const QString& connUuid)
{ {
m_lanWidget->activateWired(devName, connUuid); // m_lanWidget->activateWired(devName, connUuid);
} }
void MainWindow::deactivateWired(const QString& devName, const QString& connUuid) void MainWindow::deactivateWired(const QString& devName, const QString& connUuid)
{ {
m_lanWidget->deactivateWired(devName, connUuid); // m_lanWidget->deactivateWired(devName, connUuid);
} }
//无线连接断开 //无线连接断开
void MainWindow::activateWireless(const QString& devName, const QString& ssid) void MainWindow::activateWireless(const QString& devName, const QString& ssid)
{ {
m_wlanWidget->activateWirelessConnection(devName, ssid); // m_wlanWidget->activateWirelessConnection(devName, ssid);
} }
void MainWindow::deactivateWireless(const QString& devName, const QString& ssid) void MainWindow::deactivateWireless(const QString& devName, const QString& ssid)
{ {
m_wlanWidget->deactivateWirelessConnection(devName, ssid); // m_wlanWidget->deactivateWirelessConnection(devName, ssid);
} }
void MainWindow::rescan() void MainWindow::rescan()
{ {
m_wlanWidget->requestScan(); // m_wlanWidget->requestScan();
} }
void MainWindow::keyRingInit() void MainWindow::keyRingInit()
{ {
agent_init(); // agent_init();
} }
void MainWindow::keyRingClear() void MainWindow::keyRingClear()
{ {
agent_clear(); // agent_clear();
} }
#endif

View File

@ -11,28 +11,28 @@
#include <QDBusInterface> #include <QDBusInterface>
#include <QMap> #include <QMap>
#include <QScreen> #include <QScreen>
#include "lanpage.h" #include <QHBoxLayout>
#include "wlanpage.h" #include <QLabel>
#include "netdetails/netdetail.h" #include <QThread>
#include <QPluginLoader>
#include <kylin-nm/kylin-nm-interface.h>
#include <kylin-nm/kylinnetworkmanager.h>
//安全中心-网络防火墙模式配置
#include "networkmodeconfig.h"
#ifdef WITHKYSEC #ifdef WITHKYSEC
#include <kysec/libkysec.h> #include <kysec/libkysec.h>
#include <kysec/status.h> #include <kysec/status.h>
#endif #endif
enum IconActiveType { enum DeviceType
NOT_CONNECTED = 0, {
LAN_CONNECTED, WIRED,
WLAN_CONNECTED, WIRELESS
LAN_CONNECTED_LIMITED,
WLAN_CONNECTED_LIMITED,
ACTIVATING,
}; };
const QByteArray TRANSPARENCY_GSETTINGS = "org.ukui.control-center.personalise"; const QByteArray TRANSPARENCY_GSETTINGS = "org.ukui.control-center.personalise";
class LanPage;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -44,7 +44,7 @@ public:
void setWiredDefaultDevice(QString deviceName); void setWiredDefaultDevice(QString deviceName);
void setWirelessDefaultDevice(QString deviceName); void setWirelessDefaultDevice(QString deviceName);
//for dbus #if 0
void getWirelessList(QMap<QString, QVector<QStringList> > &map); void getWirelessList(QMap<QString, QVector<QStringList> > &map);
void getWiredList(QMap<QString, QVector<QStringList>> &map); void getWiredList(QMap<QString, QVector<QStringList>> &map);
//开启热点 //开启热点
@ -54,6 +54,7 @@ public:
//获取热点 //获取热点
void getStoredApInfo(QStringList &list); void getStoredApInfo(QStringList &list);
void getApInfoBySsid(QString devName, QString ssid, QStringList &list); void getApInfoBySsid(QString devName, QString ssid, QStringList &list);
//删除有线连接 //删除有线连接
void deleteWired(const QString& connUuid); void deleteWired(const QString& connUuid);
//有线连接断开 //有线连接断开
@ -63,16 +64,16 @@ public:
void activateWireless(const QString& devName, const QString& ssid); void activateWireless(const QString& devName, const QString& ssid);
void deactivateWireless(const QString& devName, const QString& ssid); void deactivateWireless(const QString& devName, const QString& ssid);
//无线总开关 //无线总开关
void setWirelessSwitchEnable(bool enable); // void setWirelessSwitchEnable(bool enable);
void setWiredDeviceEnable(const QString& devName, bool enable); void setWiredDeviceEnable(const QString& devName, bool enable);
//唤起属性页 根据网卡类型 参数2 为ssid/uuid //唤起属性页 根据网卡类型 参数2 为ssid/uuid
void showPropertyWidget(QString devName, QString ssid); // void showPropertyWidget(QString devName, QString ssid);
//唤起新建有线连接界面 //唤起新建有线连接界面
void showCreateWiredConnectWidget(const QString devName); // void showCreateWiredConnectWidget(const QString devName);
//唤起加入其他无线网络界面 //唤起加入其他无线网络界面
void showAddOtherWlanWidget(QString devName); // void showAddOtherWlanWidget(QString devName);
void getWirelessDeviceCap(QMap<QString, int> &map); void getWirelessDeviceCap(QMap<QString, int> &map);
@ -80,8 +81,10 @@ public:
void keyRingInit(); void keyRingInit();
void keyRingClear(); void keyRingClear();
#endif
signals: signals:
void mainWindowVisibleChanged(const bool &visible);
#if 0
//设备插拔 //设备插拔
void deviceStatusChanged(); void deviceStatusChanged();
//设备名称变化 //设备名称变化
@ -96,18 +99,16 @@ signals:
void lanActiveConnectionStateChanged(QString devName, QString uuid, int status); void lanActiveConnectionStateChanged(QString devName, QString uuid, int status);
void activateFailed(QString errorMessage); void activateFailed(QString errorMessage);
void deactivateFailed(QString errorMessage); void deactivateFailed(QString errorMessage);
//热点断开
void hotspotDeactivated(QString devName, QString ssid); void hotspotDeactivated(QString devName, QString ssid);
void hotspotActivated(QString devName, QString ssid, QString uuid); void hotspotActivated(QString devName, QString ssid, QString uuid);
//信号强度变化 //信号强度变化
void signalStrengthChange(QString devName, QString ssid, int strength); void signalStrengthChange(QString devName, QString ssid, int strength);
//安全性变化 //安全性变化
void secuTypeChange(QString devName, QString ssid, QString secuType); void secuTypeChange(QString devName, QString ssid, QString secuType);
void mainWindowVisibleChanged(const bool &visible);
//列表排序 //列表排序
void timeToUpdate(); void timeToUpdate();
public slots: #endif
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
bool eventFilter(QObject *watched, QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override;
@ -131,11 +132,13 @@ private:
void resetWindowTheme(); void resetWindowTheme();
void showControlCenter(); void showControlCenter();
void showByWaylandHelper(); void showByWaylandHelper();
void loadLanPlugin(); //加载有线网络插件
void loadWlanPlugin(); //加载无线网络插件
void startLoading();
void stopLoading();
double m_transparency=1.0; //透明度 double m_transparency=1.0; //透明度
QGSettings * m_transGsettings; //透明度配置文件 QGSettings * m_transGsettings; //透明度配置文件
int currentIconIndex=0;
QList<QIcon> loadIcons;
QTimer *iconTimer = nullptr;
//主窗口的主要构成控件 //主窗口的主要构成控件
QTabWidget * m_centralWidget = nullptr; QTabWidget * m_centralWidget = nullptr;
@ -143,8 +146,8 @@ private:
QLabel * m_lanLabel = nullptr; QLabel * m_lanLabel = nullptr;
QLabel * m_wlanLabel = nullptr; QLabel * m_wlanLabel = nullptr;
LanPage * m_lanWidget = nullptr; QWidget * m_lanWidget = nullptr;
WlanPage * m_wlanWidget = nullptr; QWidget * m_wlanWidget = nullptr;
//监听主题的Gsettings //监听主题的Gsettings
QGSettings * m_styleGsettings = nullptr; QGSettings * m_styleGsettings = nullptr;
@ -166,10 +169,15 @@ private:
bool m_isShowInCenter = false; bool m_isShowInCenter = false;
IconActiveType iconStatus = IconActiveType::NOT_CONNECTED; QTimer * m_loadingTimer = nullptr;
QTimer * m_refreshTimer = nullptr;
QList<QIcon> m_loadIcons;
int m_currentIconIndex=0;
KyConnectStatus m_iconStatus;
KyNetworkManager * m_manager = nullptr;
QThread * m_thread = nullptr;
QMap<QString, NetDetail*> m_createPagePtrMap; NetworkModeConfig *m_networkMode;
QMap<QString, NetDetail*> m_addOtherPagePtrMap;
public slots: public slots:
void onShowMainWindow(int type); void onShowMainWindow(int type);
@ -180,11 +188,10 @@ private slots:
void onShowMainwindowActionTriggled(); void onShowMainwindowActionTriggled();
void onShowSettingsActionTriggled(); void onShowSettingsActionTriggled();
void onThemeChanged(const QString &key); void onThemeChanged(const QString &key);
void onRefreshTrayIcon();
void onSetTrayIconLoading(); void onSetTrayIconLoading();
void onLanConnectStatusToChangeTrayIcon(int state); void updateIcon();
void onWlanConnectStatusToChangeTrayIcon(int state); void onWiredStateChange(QString deviceName, QString uuid, KyConnectState state);
void onConnectivityChanged(NetworkManager::Connectivity connectivity); void onWirelessStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state);
void onTabletModeChanged(bool mode); void onTabletModeChanged(bool mode);
}; };

View File

@ -17,20 +17,26 @@
*/ */
#include "mainwindow.h" #include "mainwindow.h"
#include "dbusadaptor.h" //#include "dbusadaptor.h"
#include <QTranslator> #include <QTranslator>
#include <QLocale> #include <QLocale>
#include "qt-single-application.h" #include "qt-single-application.h"
#include <QDebug> #include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QFile> #include <QFile>
#include <QDateTime>
#include <QStandardPaths>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <ukui-log4qt.h> #include <ukui-log4qt.h>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
#include "xatom-helper.h" #include "xatom-helper.h"
#endif #endif
#include "vpnobject.h" //#include "vpnobject.h"
#include "vpndbusadaptor.h" //#include "vpndbusadaptor.h"
#include "kylinnmdbus.h"
#include "kylinnmuidbus.h"
#define LOG_IDENT "ukui_kylin_nm" #define LOG_IDENT "ukui_kylin_nm"
@ -119,11 +125,11 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
QThread thread; // QThread thread;
KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance(); // KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance();
p_networkResource->moveToThread(&thread); // p_networkResource->moveToThread(&thread);
QObject::connect(&thread, SIGNAL(started()), p_networkResource, SLOT(onInitNetwork())); // QObject::connect(&thread, SIGNAL(started()), p_networkResource, SLOT(onInitNetwork()));
thread.start(); // thread.start();
// Internationalization // Internationalization
QString locale = QLocale::system().name(); QString locale = QLocale::system().name();
@ -146,31 +152,41 @@ int main(int argc, char *argv[])
qWarning() << "QtBase Translations load fail"; qWarning() << "QtBase Translations load fail";
} }
while (!p_networkResource->NetworkManagerIsInited()) { // while (!p_networkResource->NetworkManagerIsInited()) {
::usleep(1000); // ::usleep(1000);
} // }
MainWindow w; MainWindow w;
a.setActivationWindow(&w); a.setActivationWindow(&w);
w.setProperty("useStyleWindowManager", false); //禁用拖动 w.setProperty("useStyleWindowManager", false); //禁用拖动
vpnObject vnpobject; // vpnObject vnpobject;
w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint/* | Qt::X11BypassWindowManagerHint*/); w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint/* | Qt::X11BypassWindowManagerHint*/);
DbusAdaptor adaptor(&w); // DbusAdaptor adaptor(&w);
Q_UNUSED(adaptor); // Q_UNUSED(adaptor);
VpnDbusAdaptor vpnAdaptor(&vnpobject); // VpnDbusAdaptor vpnAdaptor(&vnpobject);
Q_UNUSED(vpnAdaptor); // Q_UNUSED(vpnAdaptor);
auto connection = QDBusConnection::sessionBus(); auto connection = QDBusConnection::sessionBus();
if (!connection.registerService("com.kylin.network") // if (!connection.registerService("com.kylin.network")
|| !connection.registerObject("/com/kylin/network", &w) // || !connection.registerObject("/com/kylin/network", &w)
|| !connection.registerObject("/com/kylin/vpnTool", &vnpobject)) { // || !connection.registerObject("/com/kylin/vpnTool", &vnpobject)) {
// qCritical() << "QDbus register service failed reason:" << connection.lastError();
// }
if (!connection.registerService("com.kylin.network")) {
qCritical() << "QDbus register service failed reason:" << connection.lastError(); qCritical() << "QDbus register service failed reason:" << connection.lastError();
} }
KylinNmDbus dbusObject(&w);
//注册对象路径把类KylinNmDbus所有槽函数导出为object的method
connection.registerObject("/com/kylin/network", &dbusObject,
QDBusConnection::ExportAllSlots| QDBusConnection :: ExportAllSignals);
KylinNmUiDbus uiDbusObject(&w);
connection.registerObject("/com/kylin/network/interface", &uiDbusObject,
QDBusConnection::ExportAllSlots| QDBusConnection :: ExportAllSignals);
return a.exec(); return a.exec();
} }

View File

@ -50,7 +50,7 @@
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusReply> #include <QDBusReply>
#include <QMainWindow> #include <QMainWindow>
#include "../mainwindow.h" #include "../frontend/mainwindow.h"
/*! /*!

View File

@ -15,7 +15,7 @@ CONFIG += c++14 qt warn_on link_pkgconfig
#CONFIG += release #CONFIG += release
PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 gsettings-qt libcap kysdk-qtwidgets kysdk-waylandhelper PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 gsettings-qt libcap kysdk-qtwidgets kysdk-waylandhelper
PKGCONFIG +=kysdk-sysinfo PKGCONFIG +=kysdk-sysinfo kylin-nm-base
INCLUDEPATH += /usr/include/KF5/NetworkManagerQt INCLUDEPATH += /usr/include/KF5/NetworkManagerQt
@ -50,8 +50,9 @@ QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS)
QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS) QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS)
include(singleapplication/qt-single-application.pri) include(singleapplication/qt-single-application.pri)
include(backend/backend.pri) #include(backend/backend.pri)
include(frontend/frontend.pri) include(frontend/frontend.pri)
include(kylin-nm-dbus/kylin-nm-dbus.pri)
RESOURCES += \ RESOURCES += \
../nmqrc.qrc ../nmqrc.qrc