resolve conflict

This commit is contained in:
zhangyuanyuan1 2022-04-24 17:32:13 +08:00
commit dc84210007
13 changed files with 309 additions and 38 deletions

202
README.md
View File

@ -1,15 +1,189 @@
# NAME
kylin-nm - kylin network monitor used in ubuntu-kylin operation system
# DESCRIPTION
kylin-nm is a Qt based applet and uses some interface provided by NetworkManager.
It provides a GUI for users to connect or disconnect wired or wireless network which managed by NetworkManager.
Users can also create new wired network and configure a old network.
By click button at left bottom in the main window, a network configure window of NetworkManager will show in the screen.
Users can get some information about network directly by clicking one item in the network list, these information shown in extension area.
## kylin-nm介绍
### 简介
麒麟网络工具kylin-network-manager简称kylin-nm是操作系统的网络前端其主要功能有
1、托盘栏图标及右键菜单
查看当前网络状态
左键点击托盘网络图标显示kylin-nm主界面
右键点击托盘网络图标显示右键菜单
2、对有线网络的管理
有线网络界面管理
连接/断开网络
网线拔插
多有线网卡支持
打开或关闭有线开关
查看或修改无线网络基本信息
3、对无线网络的管理
切换及刷新无线界面
查看无线网络列表
连接/断开无需密码的无线网
连接/断开有密码类型的无线网
无线网卡插拔
多无线网卡支持
打开或关闭无线开关
查看或修改无线网络基本信息
4、连接隐藏无线网络
连接无安全性的无线网络
连接WPA及WPA2个人安全性的无线网络
连接WPA及WPA2企业安全性的无线网络
连接WPA3个人安全性的无线网络
5、窗口样式调节
深色与浅色窗口样式切换
调节网络工具窗口透明度
普通窗口与具有毛玻璃效果的窗口的切换
### 运行
麒麟网络工具的进程为kylin-nm默认开机自启依赖NetworkManger
### 命令行和dbus接口
kylin-nm进程的命令行如下
Usage: kylin-nm
#### dbus接口
DBUS类型SESSION BUS
DBUS名称com.kylin.network
OBJECT路径/
接口名称com.kylin.network
#### dbus方法
getWirelessList
参数:无
返回值QMap<QString, QVector<QStringList>>
键:网卡名称
值:无线网络的集合(第一项为已连接网络信息,若无连接则为"--",否则为"名称/信号强度/加密类型/Uuid/是否为本机开放热点";其余为未连接的网络信息,为"名称/信号强度/加密类型/是否为本机开放热点"
功能:获取无线列表及每个对应无线网络的信号强度、加密类型等信息。
getWiredList
参数:无
返回值QMap<QString, QVector<QStringList>>
键:网卡名称
值:有线网络的集合("名称/UUID/对应DBUS路径"),若无已连接网络则第一项默认为"--"
功能获取有线列表及每个对应的有线网络的uuid及dbus路径
setWiredSwitchEnable(bool enable)
参数:(bool开启有线总开关true关闭有线总开关false
返回值:无
功能:打开或关闭有线总开关
setWirelessSwitchEnable(bool enable)
参数:(bool开启无线总开关true关闭无线总开关false
返回值:无
功能:打开或关闭无线总开关
setDeviceEnable(QString devName, bool enable)
参数QStringdevName 设备名称bool enable 开启/关闭
返回值:无
功能:打开或关闭单个有线网卡开关
activateConnectint type, QString devName, QString ssid
参数:根据网卡类型 参数1 0:lan 1:wlan 参数2网卡名称 参数3uuid/ssid
返回值:无
功能:激活一个网络连接
deActivateConnect(int type, QString devName, QString ssid)
参数:根据网卡类型 参数1 0:lan 1:wlan 参数2网卡名称 参数3uuid/ssid
返回值:无
功能:断开一个网络连接
getDeviceListAndEnabled(int devType)
参数int devType 0:lan 1:wlan
返回值QMap<QString, bool>
键:设备名称
bool 开启true关闭 false
功能:获取设备列表和启用/禁用状态
getWirelessDeviceCap
返回值QMap<QString, int>
键:设备名称
int 0不支持热点 3支持2.4GHz 7支持5GHz&&2.4Ghz
功能:获取无线设备能力(2.4G/5G)
showPropertyWidget(QString devName, QString ssid)
参数QString devName 设备名称 QString ssid 根据网卡类型 有线为uuid/无线为ssid
返回值:无
功能:唤起对应网络连接的属性页,可以对基础信息的显示或修改
showCreateWiredConnectWidget(QString devName)
参数QString devName 有线网卡名称
返回值:无
功能:唤起新建有线连接界面
activeWirelessAp(const QString apName,
const QString apPassword,
const QString band,
const QString apDevice)
参数QString apName 热点名称
QString apPassword 热点密码
QString band 频带
QString apDevice
返回值:无
功能:开启移动热点
deactiveWirelessAp(const QString apName, const QString uuid)
参数QStringList名称/密码/设备名称/状态/UUID/频带)
返回值:无
功能: 断开移动热点
getStoredApInfo
参数QStringList名称/密码/设备名称/状态/UUID/频带)
返回值:无
功能:获取已保存的移动热点信息
getApInfoBySsid(QString devName, QString ssid)
参数QString devName 设备名称 QString ssid
返回值:无
功能:通过名称获取已保存的移动热点信息
reScan()
参数:无
返回值:无
功能:申请重新进行无线扫描
keyRingInit()
参数QString apName 热点名称 QString uuid
返回值:无
功能:断开移动热点
keyRingClear()
参数:无
返回值:无
功能: 断开移动热点
### 原理与主要使用的技术
kylin-nm主要与NetworkManager进行交互通过对应的dbus信号驱动UI界面的更新。并通过提供的dbus方法来进行网络相关功能的调用。
麒麟网络工具按照功能划分成两层UI层和逻辑层。UI层实现网络资源的显示以及用户的交互逻辑层通过NetworkManager提供的Dbus接口完成网络资源的管理及其配置。
### 配置文件
kylin-nm的配置文件保存在如下路径
~/.config/ukui/kylin-nm.conf 有线无线开关状态 设备状态
org.ukui.kylin-nm.switch 对应的gsetting值 (有线无线开关状态)
### 编译
cd kylin-nm
mkdir build
cd build
qmake ..
make
sudo make install 
### 运行命令
./kylin-nm
### 调试
kylin-nm目前并采用ukui-log4qt模块的日志功能。日志默认保存在~/.log/kylin-nm.log中
# BUILD KYLIN-NM
down the source sode
install dependency packages(see cntrol files in the debian directory)
execute debuild command in the root directory of project
execute sudo dpkg -i packagename.deb to install

1
debian/control vendored
View File

@ -24,6 +24,7 @@ Build-Depends: debhelper (>=9),
libukcc-dev (>= 3.1.1+1217),
libukui-log4qt-dev,
libkysdk-applications,
libukui-common-dev,
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ukui/kylin-nm

View File

@ -197,10 +197,10 @@ private:
public:
static KyNetworkResourceManager* m_pInstance;
NetworkManager::ActiveConnection::List m_activeConns;
NetworkManager::Connection::List m_connections;
NetworkManager::Device::List m_devices;
NetworkManager::WirelessNetwork::List m_wifiNets;
NetworkManager::ActiveConnection::List m_activeConns; //已连接资源类
NetworkManager::Connection::List m_connections; //配置文件资源类
NetworkManager::Device::List m_devices; //设备类
NetworkManager::WirelessNetwork::List m_wifiNets; //无线热点类
};

View File

@ -103,6 +103,27 @@ void KyWiredConnectOperation::updateWiredConnect(const QString &connectUuid, con
mapmap1["ipv4"] = map1;
}
if (mapmap1.contains("ipv6")) {
QVariantMap map2 = mapmap1.value(QLatin1String("ipv6"));
bool isAuto = false;
if (map2.contains("method") && map2["method"] == "auto") {
qDebug() << "[KyWiredConnectOperation] set ipv6 method auto, clear address-data && addresses && gateway";
isAuto = true;
}
if (isAuto) {
if (map2.contains("address-data")) {
map2.remove("address-data");
}
if (map2.contains("addresses")) {
map2.remove("addresses");
}
if (map2.contains("gateway")) {
map2.remove("gateway");
}
}
mapmap1["ipv6"] = map2;
}
connectPtr->update(mapmap1);
return ;

View File

@ -228,6 +228,10 @@ QStringList DbusAdaptor::getApInfoBySsid(QString devName, QString ssid)
return list;
}
void DbusAdaptor::showKylinNM(int type)
{
parent()->onShowMainWindow(type);
}
//扫描
void DbusAdaptor::reScan()

View File

@ -86,6 +86,8 @@ public Q_SLOTS: // METHODS
//keyring
void keyRingInit();
void keyRingClear();
//just show
void showKylinNM(int type);
Q_SIGNALS: // SIGNALS
// void wirelessActivating(QString devName, QString ssid);
// void wiredActivating(QString devName, QString ssid);

View File

@ -234,7 +234,7 @@ void WlanListItem::initWlanUI()
m_pwdLineEdit = new QLineEdit(m_pwdFrame);
m_pwdLineEdit->setFixedWidth(LINEEDIT_WIDTH);
m_pwdLineEdit->setAttribute(Qt::WA_InputMethodEnabled, false);
// m_pwdLineEdit->setAttribute(Qt::WA_InputMethodEnabled, false);
m_pwdLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
QRegExp rx("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/]+$");

View File

@ -17,8 +17,10 @@
#define THEME_SCHAME "org.ukui.style"
#define COLOR_THEME "styleName"
#define LAN_PAGE_INDEX 0
#define WLAN_PAGE_INDEX 1
const QString v10Sp1 = "V10SP1";
const QString intel = "V10SP1-edu";
#define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES"
#include <kwindowsystem.h>
#include <kwindowsystem_export.h>
@ -89,6 +91,7 @@ void MainWindow::firstlyStart()
initDbusConnnect();
initWindowTheme();
initTrayIcon();
initPlatform();
installEventFilter(this);
m_secondaryStartTimer = new QTimer(this);
connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() {
@ -113,6 +116,23 @@ void MainWindow::secondaryStart()
m_loadFinished = true;
}
/**
* @brief MainWindow::initWindowProperties
*/
void MainWindow::initPlatform()
{
if(v10Sp1.compare(KDKGetPrjCodeName().c_str(),Qt::CaseInsensitive) == 0) {
QString feature = KDKGetOSRelease(KEY_PRODUCT_FEATURES).c_str();
if (feature.toInt() == 3) {
m_isShowInCenter = true;
}
} else if (intel.compare(KDKGetPrjCodeName().c_str(),Qt::CaseInsensitive) == 0) {
m_isShowInCenter = true;
}
qDebug() << KDKGetPrjCodeName().c_str() << KDKGetOSRelease(KEY_PRODUCT_FEATURES).c_str() << "m_isShowInCenter" << m_isShowInCenter;
}
/**
* @brief MainWindow::initWindowProperties
*/
@ -277,8 +297,14 @@ void MainWindow::initDbusConnnect()
connect(m_wlanWidget, &WlanPage::secuTypeChange, this, &MainWindow::secuTypeChange);
connect(m_wlanWidget, &WlanPage::signalStrengthChange, this, &MainWindow::signalStrengthChange);
connect(m_wlanWidget, &WlanPage::timeToUpdate , this, &MainWindow::timeToUpdate);
connect(m_wlanWidget, &WlanPage::showMainWindow, this, &MainWindow::onShowByWlanPage);
connect(m_wlanWidget, &WlanPage::showMainWindow, this, &MainWindow::onShowMainWindow);
connect(m_wlanWidget, &WlanPage::connectivityChanged, this, &MainWindow::onConnectivityChanged);
//模式切换
QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"),
QString("/"),
QString("com.kylin.statusmanager.interface"),
QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool)));
}
/**
@ -286,6 +312,13 @@ void MainWindow::initDbusConnnect()
*/
void MainWindow::resetWindowPosition()
{
if (m_isShowInCenter) {
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
this->move((availableGeometry.width() - this->width())/2, (availableGeometry.height() - this->height())/2);
return;
}
#define MARGIN 4
#define PANEL_TOP 1
#define PANEL_LEFT 2
@ -518,16 +551,20 @@ void MainWindow::onWlanConnectStatusToChangeTrayIcon(int state)
}
}
void MainWindow::onShowByWlanPage()
void MainWindow::onTabletModeChanged(bool mode)
{
m_centralWidget->setCurrentIndex(WLAN_PAGE_INDEX);
qDebug() << "TabletMode change" << mode;
Q_UNUSED(mode)
//模式切换时,隐藏主界面
hideMainwindow();
}
void MainWindow::onShowMainWindow(int type)
{
m_centralWidget->setCurrentIndex(type);
if(QApplication::activeWindow() != this) {
this->resetWindowPosition();
this->showNormal();
this->raise();
this->activateWindow();
emit this->mainWindowVisibleChanged(true);
this->showMainwindow();
}
}

View File

@ -10,9 +10,11 @@
#include <QAction>
#include <QDBusInterface>
#include <QMap>
#include <QScreen>
#include "lanpage.h"
#include "wlanpage.h"
#include "netdetails/netdetail.h"
#include <ukuisdk/kylin-com4cxx.h>
enum IconActiveType {
NOT_CONNECTED = 0,
@ -108,6 +110,7 @@ private:
void secondaryStart(); //二级启动
bool m_loadFinished = false; //是否二级启动已执行完
QTimer * m_secondaryStartTimer = nullptr; //执行二级启动的倒计时
void initPlatform();
void initWindowProperties();
void initTransparency();
void paintWithTrans();
@ -149,10 +152,15 @@ private:
bool m_lanIsLoading = false;
bool m_wlanIsLoading = false;
bool m_isShowInCenter = false;
IconActiveType iconStatus = IconActiveType::NOT_CONNECTED;
QMap<QString, NetDetail*> m_createPagePtrMap;
public slots:
void onShowMainWindow(int type);
private slots:
void onTransChanged();
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
@ -163,8 +171,8 @@ private slots:
void onSetTrayIconLoading();
void onLanConnectStatusToChangeTrayIcon(int state);
void onWlanConnectStatusToChangeTrayIcon(int state);
void onShowByWlanPage();
void onConnectivityChanged(NetworkManager::Connectivity connectivity);
void onTabletModeChanged(bool mode);
};
#endif // MAINWINDOW_H

View File

@ -1292,7 +1292,7 @@ void WlanPage::activateWirelessConnection(const QString& devName, const QString&
QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, QPoint(0,0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::postEvent(p_wlanItem, event);
emit showMainWindow();
emit showMainWindow(WLAN_PAGE_INDEX);
} else {
qDebug() << "[WlanPage]activateWirelessConnection no such " << ssid << "in" << devName;
}

View File

@ -19,6 +19,9 @@
#define MORE_TEXT_MARGINS 16,0,0,0
#define SCROLLAREA_HEIGHT 200
#define LAN_PAGE_INDEX 0
#define WLAN_PAGE_INDEX 1
class WlanListItem;
class WlanPage : public TabPage
@ -64,7 +67,7 @@ signals:
void wlanConnectChanged(int state);
void timeToUpdate();
void showMainWindow();
void showMainWindow(int type);
void connectivityChanged(NetworkManager::Connectivity connectivity);

View File

@ -88,14 +88,35 @@ 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);
if (a.isRunning()) {
a.sendMessage("raise_window_noop");
return EXIT_SUCCESS;
}
QApplication::setQuitOnLastWindowClosed(false);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "kylinnm"));
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption swOption(QStringLiteral("sw"),QCoreApplication::translate("main", "show kylin-nm wifi page"));
QCommandLineOption snOption(QStringLiteral("sn"),QCoreApplication::translate("main", "show kylin-nm lan page"));
parser.addOptions({swOption,snOption});
parser.process(a);
QDBusInterface interface("com.kylin.network",
"/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if(interface.isValid()) {
if (parser.isSet(swOption))
{
interface.call(QStringLiteral("showKylinNM"),1);
} else {
interface.call(QStringLiteral("showKylinNM"),0);
}
return 0;
}
QThread thread;
KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance();
p_networkResource->moveToThread(&thread);

View File

@ -18,7 +18,7 @@ PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 gset
INCLUDEPATH += /usr/include/KF5/NetworkManagerQt
LIBS += -L/usr/lib/ -lgsettings-qt -lX11 -lKF5NetworkManagerQt -lukui-log4qt
LIBS += -L/usr/lib/ -lgsettings-qt -lX11 -lKF5NetworkManagerQt -lukui-log4qt -lukui-com4c -lukui-com4cxx
#LIBS += -lkysec
target.path = /usr/bin
target.source += $$TARGET