!64 merge:合并kylin-nm-plugin代码 一起出包

Merge pull request !64 from 赵世旭/0119
This commit is contained in:
赵世旭 2024-01-19 06:13:34 +00:00 committed by Gitee
commit cb621701e4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
72 changed files with 7705 additions and 18 deletions

18
debian/control vendored
View File

@ -26,7 +26,8 @@ Build-Depends: debhelper (>=9),
qtbase5-dev-tools,
qtchooser,
qtscript5-dev,
qttools5-dev-tools
qttools5-dev-tools,
libkylin-nm-base
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ukui/kylin-nm
@ -35,8 +36,8 @@ Vcs-Browser: https://github.com/ukui/kylin-nm
Package: kylin-nm
Architecture: any
Depends: libkysdk-qtwidgets(>= 1.2.0),
libkysdk-waylandhelper(>= 1.2.0kylin2),
Depends: libkysdk-qtwidgets,
libkysdk-waylandhelper,
network-manager (>=1.2.6),
ukui-control-center (>= 3.1.1+1217),
dpkg-dev,
@ -47,3 +48,14 @@ Description: Gui Applet tool for display and edit network simply
Kylin NM is a Applet tool for managing network settings simply.
It has beautiful UI and very comfortable to use.
It's better work together with UKUI.
Package: kylin-nm-plugin
Architecture: any
Depends: libkylin-nm-base,
libkysdk-qtwidgets,
network-manager (>=1.2.6),
${misc:Depends},
${shlibs:Depends}
Description: Gui Applet plugin for display and edit network simply
It has beautiful UI and very comfortable to use.
It's better work together with UKUI.

4
debian/kylin-nm-plugin.install vendored Normal file
View File

@ -0,0 +1,4 @@
usr/lib/liblibnm-icon-kylin.so*
usr/lib/kylin-nm/libnetconnect.so
usr/lib/kylin-nm/libwlanconnect.so
usr/include/kylin-nm/kynetworkicon.h

5
debian/kylin-nm.install vendored Normal file
View File

@ -0,0 +1,5 @@
usr/share/*
usr/lib/x86_64-linux-gnu/*
usr/bin/*
etc/xdg/autostart/*
etc/dbus-1/system.d/com.kylin.network.qt.systemdbus.conf

View File

@ -1,14 +0,0 @@
#!/bin/sh
set -e
PROGRAM=$(dpkg-divert --truename /usr/bin/kylin-nm)
if setcap cap_net_raw+ep $PROGRAM; then
chmod u-s $PROGRAM
fi
echo "kylin nm set cap success"
exit 0

View File

@ -0,0 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
plugins/plugin.pro \
libnm-icon-kylin \

View File

@ -0,0 +1,81 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "imageutil.h"
#include <QPainter>
#include <QDebug>
const QPixmap ImageUtil::loadSvg(const QString &path, const QString color, int size)
{
int origSize = size;
const auto ratio = qApp->devicePixelRatio();
if ( 2 == ratio) {
size += origSize;
} else if (3 == ratio) {
size += origSize;
}
QPixmap pixmap(size, size);
QSvgRenderer renderer(path);
pixmap.fill(Qt::transparent);
QPainter painter;
painter.begin(&pixmap);
renderer.render(&painter);
painter.end();
pixmap.setDevicePixelRatio(ratio);
return drawSymbolicColoredPixmap(pixmap, color);
}
QPixmap ImageUtil::drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor)
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++) {
for (int y = 0; y < img.height(); y++) {
auto color = img.pixelColor(x, y);
if (color.alpha() > 0) {
if ( "white" == cgColor) {
color.setRed(255);
color.setGreen(255);
color.setBlue(255);
img.setPixelColor(x, y, color);
} else if( "black" == cgColor) {
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
} else if ("gray"== cgColor) {
color.setRed(152);
color.setGreen(163);
color.setBlue(164);
img.setPixelColor(x, y, color);
} else if ("blue" == cgColor){
color.setRed(61);
color.setGreen(107);
color.setBlue(229);
img.setPixelColor(x, y, color);
} else {
return source;
}
}
}
}
return QPixmap::fromImage(img);
}

View File

@ -0,0 +1,35 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef IMAGEUTIL_H
#define IMAGEUTIL_H
#include <QPixmap>
#include <QSvgRenderer>
#include <QApplication>
class ImageUtil
{
public:
static const QPixmap loadSvg(const QString &path, const QString color, int size = 16);
static QPixmap drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor);
};
#endif // IMAGEUTIL_H

View File

@ -0,0 +1,406 @@
#include "kynetworkicon.h"
#include "imageutil.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"
static QPalette getPalette(bool isDark)
{
QPalette palette = qApp->palette();
//ukui-light palette UKUI3.1 亮主题色板
QColor windowText_at(38, 38, 38),
windowText_iat(0, 0, 0, 255 * 0.55),
windowText_dis(0, 0, 0, 255 * 0.3),
button_at(230, 230, 230),
button_iat(230, 230, 230),
button_dis(233, 233, 233),
light_at(255, 255, 255),
light_iat(255, 255, 255),
light_dis(242, 242, 242),
midlight_at(218, 218, 218),
midlight_iat(218, 218, 218),
midlight_dis(230, 230, 230),
dark_at(77, 77, 77),
dark_iat(77, 77, 77),
dark_dis(64, 64, 64),
mid_at(115, 115, 115),
mid_iat(115, 115, 115),
mid_dis(102, 102, 102),
text_at(38, 38, 38),
text_iat(38, 38, 38),
text_dis(0, 0, 0, 255 * 0.3),
brightText_at(0, 0, 0),
brightText_iat(0, 0, 0),
brightText_dis(0, 0, 0),
buttonText_at(38, 38, 38),
buttonText_iat(38, 38, 38),
buttonText_dis(179, 179, 179),
base_at(255, 255, 255),
base_iat(245, 245, 245),
base_dis(237, 237, 237),
window_at(245, 245, 245),
window_iat(237, 237, 237),
window_dis(230, 230, 230),
shadow_at(0, 0, 0, 255 * 0.16),
shadow_iat(0, 0, 0, 255 * 0.16),
shadow_dis(0, 0, 0, 255 * 0.21),
highLightText_at(255, 255, 255),
highLightText_iat(255, 255, 255),
highLightText_dis(179, 179, 179),
alternateBase_at(245, 245, 245),
alternateBase_iat(245, 245, 245),
alternateBase_dis(245, 245, 245),
noRale_at(240, 240, 240),
noRole_iat(240, 240, 240),
noRole_dis(217, 217, 217),
toolTipBase_at(255, 255, 255),
toolTipBase_iat(255, 255, 255),
toolTipBase_dis(255, 255, 255),
toolTipText_at(38, 38, 38),
toolTipText_iat(38, 38, 38),
toolTipText_dis(38, 38, 38),
placeholderText_at(0, 0, 0, 255 * 0.35),
placeholderText_iat(0, 0, 0, 255 * 0.35),
placeholderText_dis(0, 0, 0, 255 * 0.3);
//ukui-dark 暗主题色板
if (isDark) {
windowText_at.setRgb(217, 217, 217);
windowText_iat.setRgb(255, 255, 255, 255 * 0.55);
windowText_dis.setRgb(255, 255, 255, 255 * 0.3);
button_at.setRgb(55, 55, 59);
button_iat.setRgb(55, 55, 59);
button_dis.setRgb(46, 46, 46);
light_at.setRgb(255, 255, 255);
light_iat.setRgb(255, 255, 255);
light_dis.setRgb(242, 242, 242);
midlight_at.setRgb(95, 95, 98);
midlight_iat.setRgb(95, 95, 98);
midlight_dis.setRgb(79, 79, 82);
dark_at.setRgb(38, 38, 38);
dark_iat.setRgb(38, 38, 38);
dark_dis.setRgb(26, 26, 26);
mid_at.setRgb(115, 115, 115);
mid_iat.setRgb(115, 115, 115);
mid_dis.setRgb(102, 102, 102);
text_at.setRgb(217, 217, 217);
text_iat.setRgb(217, 217, 217);
text_dis.setRgb(255, 255, 255, 255 * 0.3);
brightText_at.setRgb(255, 255, 255);
brightText_iat.setRgb(255, 255, 255);
brightText_dis.setRgb(255, 255, 255);
buttonText_at.setRgb(217, 217, 217);
buttonText_iat.setRgb(217, 217, 217);
buttonText_dis.setRgb(76, 76, 79);
base_at.setRgb(29, 29, 29);
base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36);
window_at.setRgb(35, 36, 38);
window_iat.setRgb(26, 26, 26);
window_dis.setRgb(18, 18, 18);
shadow_at.setRgb(0, 0, 0, 255 * 0.16);
shadow_iat.setRgb(0, 0, 0, 255 * 0.16);
shadow_dis.setRgb(0, 0, 0, 255 * 0.21);
highLightText_at.setRgb(255, 255, 255);
highLightText_iat.setRgb(255, 255, 255);
highLightText_dis.setRgb(77, 77, 77);
alternateBase_at.setRgb(38, 38, 38);
alternateBase_iat.setRgb(38, 38, 38);
alternateBase_dis.setRgb(38, 38, 38);
noRale_at.setRgb(51, 51, 51);
noRole_iat.setRgb(51, 51, 51);
noRole_dis.setRgb(60, 60, 60);
toolTipBase_at.setRgb(38, 38, 38);
toolTipBase_iat.setRgb(38, 38, 38);
toolTipBase_dis.setRgb(38, 38, 38);
toolTipText_at.setRgb(217, 217, 217);
toolTipText_iat.setRgb(217, 217, 217);
toolTipText_dis.setRgb(217, 217, 217);
placeholderText_at.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_iat.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_dis.setRgb(255, 255, 255, 255 * 0.3);
}
palette.setColor(QPalette::Active, QPalette::WindowText, windowText_at);
palette.setColor(QPalette::Inactive, QPalette::WindowText, windowText_iat);
palette.setColor(QPalette::Disabled, QPalette::WindowText, windowText_dis);
palette.setColor(QPalette::Active, QPalette::Button, button_at);
palette.setColor(QPalette::Inactive, QPalette::Button, button_iat);
palette.setColor(QPalette::Disabled, QPalette::Button, button_dis);
palette.setColor(QPalette::Active, QPalette::Light, light_at);
palette.setColor(QPalette::Inactive, QPalette::Light, light_iat);
palette.setColor(QPalette::Disabled, QPalette::Light, light_dis);
palette.setColor(QPalette::Active, QPalette::Midlight, midlight_at);
palette.setColor(QPalette::Inactive, QPalette::Midlight, midlight_iat);
palette.setColor(QPalette::Disabled, QPalette::Midlight, midlight_dis);
palette.setColor(QPalette::Active, QPalette::Dark, dark_at);
palette.setColor(QPalette::Inactive, QPalette::Dark, dark_iat);
palette.setColor(QPalette::Disabled, QPalette::Dark, dark_dis);
palette.setColor(QPalette::Active, QPalette::Mid, mid_at);
palette.setColor(QPalette::Inactive, QPalette::Mid, mid_iat);
palette.setColor(QPalette::Disabled, QPalette::Mid, mid_dis);
palette.setColor(QPalette::Active, QPalette::Text, text_at);
palette.setColor(QPalette::Inactive, QPalette::Text, text_iat);
palette.setColor(QPalette::Disabled, QPalette::Text, text_dis);
palette.setColor(QPalette::Active, QPalette::BrightText, brightText_at);
palette.setColor(QPalette::Inactive, QPalette::BrightText, brightText_iat);
palette.setColor(QPalette::Disabled, QPalette::BrightText, brightText_dis);
palette.setColor(QPalette::Active, QPalette::ButtonText, buttonText_at);
palette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonText_iat);
palette.setColor(QPalette::Disabled, QPalette::ButtonText, buttonText_dis);
palette.setColor(QPalette::Active, QPalette::Base, base_at);
palette.setColor(QPalette::Inactive, QPalette::Base, base_iat);
palette.setColor(QPalette::Disabled, QPalette::Base, base_dis);
palette.setColor(QPalette::Active, QPalette::Window, window_at);
palette.setColor(QPalette::Inactive, QPalette::Window, window_iat);
palette.setColor(QPalette::Disabled, QPalette::Window, window_dis);
palette.setColor(QPalette::Active, QPalette::Shadow, shadow_at);
palette.setColor(QPalette::Inactive, QPalette::Shadow, shadow_iat);
palette.setColor(QPalette::Disabled, QPalette::Shadow, shadow_dis);
palette.setColor(QPalette::Active, QPalette::HighlightedText, highLightText_at);
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, highLightText_iat);
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highLightText_dis);
palette.setColor(QPalette::Active, QPalette::AlternateBase, alternateBase_at);
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, alternateBase_iat);
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, alternateBase_dis);
palette.setColor(QPalette::Active, QPalette::NoRole, noRale_at);
palette.setColor(QPalette::Inactive, QPalette::NoRole, noRole_iat);
palette.setColor(QPalette::Disabled, QPalette::NoRole, noRole_dis);
palette.setColor(QPalette::Active, QPalette::ToolTipBase, toolTipBase_at);
palette.setColor(QPalette::Inactive, QPalette::ToolTipBase, toolTipBase_iat);
palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, toolTipBase_dis);
palette.setColor(QPalette::Active, QPalette::ToolTipText, toolTipText_at);
palette.setColor(QPalette::Inactive, QPalette::ToolTipText, toolTipText_iat);
palette.setColor(QPalette::Disabled, QPalette::ToolTipText, toolTipText_dis);
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
palette.setColor(QPalette::Active, QPalette::PlaceholderText, placeholderText_at);
palette.setColor(QPalette::Inactive, QPalette::PlaceholderText, placeholderText_iat);
palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, placeholderText_dis);
#endif
return palette;
}
KyNetworkIcon::KyNetworkIcon(QWidget *parent):
QPushButton(parent)
{
qRegisterMetaType<KySecuType>("KyConnectState");
qRegisterMetaType<KySecuType>("KyConnectStatus");
qRegisterMetaType<KyConnectionType>("KyConnectionType");
this->setProperty("useIconHighlightEffect", 0x10);
this->setProperty("needTranslucent", true);
this->setFlat(true);
this->setProperty("useButtonPalette", true);
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
connect(thread, &QThread::started, manager, &KyNetworkManager::kylinNetworkManagerInit);
connect(thread, &QThread::finished, manager, &KyNetworkManager::deleteLater);
connect(thread, &QThread::finished, [=](){
qDebug() << "icon thread quit";
});
thread->start();
while (!manager->isInitFinished()) {
::usleep(1000);
}
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"));
loadingTimer = new QTimer(this);
connect(loadingTimer, &QTimer::timeout, this, &KyNetworkIcon::onSetTrayIconLoading);
manager->getConnectStatus(iconStatus);
updateIcon();
initConnect();
refreshTimer = new QTimer(this);
connect(loadingTimer, &QTimer::timeout, this, &KyNetworkIcon::updateIcon);
refreshTimer->start(10 * 1000);
QPalette pal = qApp->palette();
pal = getPalette(true);
this->setPalette(pal);
this->setCheckable(true);
}
KyNetworkIcon::~KyNetworkIcon()
{
qDebug() << "~KyNetworkIcon 1";
thread->quit();
thread->wait();
delete thread;
thread = nullptr;
qDebug() << "~KyNetworkIcon 2";
}
void KyNetworkIcon::paintEvent(QPaintEvent *event)
{
QPalette pal = qApp->palette();
pal = getPalette(true);
QColor checkedColor = this->palette().brightText().color();
checkedColor.setAlphaF(0.21);
pal.setColor(QPalette::Active, QPalette::Highlight, checkedColor);
this->setPalette(pal);
return QPushButton::paintEvent(event);
}
void KyNetworkIcon::initConnect()
{
connect(manager, &KyNetworkManager::wiredStateChange, this, &KyNetworkIcon::onWiredStateChange);
connect(manager, &KyNetworkManager::wirelessStateChange, this, &KyNetworkIcon::onWirelessStateChange);
connect(manager, &KyNetworkManager::connectStatusChanged , [=](KyConnectStatus status){
iconStatus = status;
updateIcon();
});
}
void KyNetworkIcon::updateIcon()
{
if (loadingTimer->isActive()) {
return;
}
int signalStrength = 0;
QIcon icon;
if (iconStatus == LAN_CONNECTED) {
this->setIcon(QIcon::fromTheme("network-wired-symbolic"));
return;
} else if (iconStatus == WLAN_CONNECTED
|| iconStatus == WLAN_CONNECTED_LIMITED) {
signalStrength = manager->getAcivateWifiSignal();
} else if (iconStatus == NOT_CONNECTED) {
this->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
return;
} else if (iconStatus == LAN_CONNECTED_LIMITED) {
icon = QIcon::fromTheme("network-error-symbolic");
}
if (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 (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);
}
}
this->setIcon(icon);
}
void KyNetworkIcon::startLoading()
{
if (!loadingTimer->isActive()) {
loadingTimer->start(60);
}
}
void KyNetworkIcon::stopLoading()
{
if (loadingTimer->isActive()) {
loadingTimer->stop();
}
}
void KyNetworkIcon::onSetTrayIconLoading()
{
if (currentIconIndex > 11) {
currentIconIndex = 0;
}
this->setIcon(loadIcons.at(currentIconIndex));
currentIconIndex ++;
}
void KyNetworkIcon::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 KyNetworkIcon::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();
}
}

View File

@ -0,0 +1,47 @@
#ifndef KYNETWORKICON_H
#define KYNETWORKICON_H
#include "libnm-base-kylin_global.h"
#include <kylin-nm/kylinnetworkmanager.h>
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QThread>
class LIBNMBASEKYLIN_EXPORT KyNetworkIcon : public QPushButton
{
Q_OBJECT
public:
KyNetworkIcon(QWidget *parent = nullptr);
~KyNetworkIcon();
private:
KyNetworkManager* manager;
QThread* thread;
QTimer *loadingTimer;
QTimer *refreshTimer;
int currentIconIndex=0;
QList<QIcon> loadIcons;
KyConnectStatus iconStatus;
void initConnect();
void startLoading();
void stopLoading();
protected:
void paintEvent(QPaintEvent *);
private Q_SLOTS:
void onSetTrayIconLoading();
void updateIcon();
void onWiredStateChange(QString deviceName, QString uuid, KyConnectState state);
void onWirelessStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state);
};
#endif // KYNETWORKICON_H

View File

@ -0,0 +1,43 @@
QT += core gui widgets dbus network svg
TEMPLATE = lib
DEFINES += LIBNMICONKYLIN_LIBRARY
CONFIG += c++14 qt link_pkgconfig no_keywords
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
PKGCONFIG += kylin-nm-base
#INCLUDEPATH += $$PWD/../libnm-base-kylin/
#INCLUDEPATH += /usr/include/KF5/NetworkManagerQt
#LIBS += -L$$PWD/../libnm-base-kylin/ -l kylin-nm-base
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
kynetworkicon.cpp \
imageutil.cpp
HEADERS += \
kynetworkicon.h \
imageutil.h
# Default rules for deployment.
unix {
target.path = /usr/lib
manager.path = /usr/include/kylin-nm
manager.files = kynetworkicon.h
INSTALLS += manager
}
!isEmpty(target.path): INSTALLS += target

View File

@ -0,0 +1,19 @@
#include "deviceframe.h"
#define LAYOUT_MARGINS 24,0,0,0
#define FRAME_HEIGHT 36
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLabel = new QLabel(this);
deviceLabel->setText(devName);
deviceLabel->setDisabled(true);
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
}

View File

@ -0,0 +1,17 @@
#ifndef DEVICEFRAME_H
#define DEVICEFRAME_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
class DeviceFrame : public QFrame
{
public:
DeviceFrame(QString devName, QWidget *parent = nullptr);
public:
QLabel * deviceLabel = nullptr;
};
#endif // DEVICEFRAME_H

View File

@ -0,0 +1,23 @@
#include "divider.h"
#include <QPainter>
#include <QApplication>
Divider::Divider(QWidget * parent) : QFrame(parent)
{
this->setFixedHeight(1);
}
void Divider::paintEvent(QPaintEvent * e)
{
QPainter p(this);
QColor color = qApp->palette().color(QPalette::BrightText);
color.setAlphaF(0.08);
p.save();
p.setBrush(color);
p.setPen(Qt::transparent);
p.drawRoundedRect(this->rect(), 6, 6);
p.restore();
return QFrame::paintEvent(e);
}

View File

@ -0,0 +1,15 @@
#ifndef DIVIDER_H
#define DIVIDER_H
#include <QFrame>
class Divider : public QFrame
{
public:
Divider(QWidget * parent = nullptr);
~Divider() = default;
protected:
void paintEvent(QPaintEvent *event);
};
#endif // DIVIDER_H

View File

@ -0,0 +1,36 @@
#include "drownlabel.h"
#include "deviceframe.h"
#define ICONSIZE 16,16
DrownLabel::DrownLabel(QString devName, QWidget * parent) : QLabel(parent)
{
m_devName = devName;
setFixedSize(36,36);
loadPixmap(isChecked);
this->setProperty("useIconHighlightEffect", 0x2);
}
DrownLabel::~DrownLabel()
{
}
void DrownLabel::setDropDownStatus(bool status)
{
isChecked = status;
loadPixmap(isChecked);
}
void DrownLabel::loadPixmap(bool isChecked)
{
if (isChecked) {
setPixmap(QIcon::fromTheme("ukui-up-symbolic").pixmap(ICONSIZE));
} else {
setPixmap(QIcon::fromTheme("ukui-down-symbolic").pixmap(ICONSIZE));
}
}
void DrownLabel::mouseReleaseEvent(QMouseEvent *event)
{
emit labelClicked();
QWidget::mouseReleaseEvent(event);
}

View File

@ -0,0 +1,27 @@
#ifndef DROWNLABEL_H
#define DROWNLABEL_H
#include <QObject>
#include <QLabel>
#include <QWidget>
#include <QMouseEvent>
class DrownLabel : public QLabel
{
Q_OBJECT
public:
explicit DrownLabel(QString devName, QWidget * parent = nullptr);
~DrownLabel();
void setDropDownStatus(bool status);
QString m_devName;
bool isChecked = true;
private:
void loadPixmap(bool isChecked);
protected:
virtual void mouseReleaseEvent(QMouseEvent * event);
Q_SIGNALS:
void labelClicked();
};
#endif // DROWNLABEL_H

View File

@ -0,0 +1,39 @@
#include "fixlabel.h"
#include <QGSettings>
FixLabel::FixLabel(QWidget *parent) :
QLabel(parent)
{
const QByteArray id("org.ukui.style");
QGSettings * fontSetting = new QGSettings(id, QByteArray(), this);
connect(fontSetting, &QGSettings::changed,[=](QString key) {
if ("systemFont" == key || "systemFontSize" ==key) {
changedLabelSlot();
}
});
}
void FixLabel::setLabelText(QString text) {
mStr = text;
changedLabelSlot();
}
QString FixLabel::getText(){
return mStr;
}
void FixLabel::changedLabelSlot() {
QFontMetrics fontMetrics(this->font());
int fontSize = fontMetrics.width(mStr);
if (fontSize > this->width()) {
setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width()));
setToolTip(mStr);
} else {
setText(mStr);
setToolTip("");
}
}

View File

@ -0,0 +1,29 @@
#ifndef FIXLABEL_H
#define FIXLABEL_H
#include <QWidget>
#include <QLabel>
class FixLabel : public QLabel
{
Q_OBJECT
public:
explicit FixLabel(QWidget *parent = 0);
public:
void setLabelText(QString text);
QString getText();
private Q_SLOTS:
void changedLabelSlot();
private:
QString mStr;
};
#endif // FIXLABEL_H

View File

@ -0,0 +1,106 @@
#include "infobutton.h"
#include <QEvent>
#include <QPainter>
#include <QApplication>
#include <QDebug>
#include <QPainterPath>
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
#define FOREGROUND_COLOR_NORMAL qApp->palette().text().color()
#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255)
#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255)
#define OUTER_PATH 8,8,16,16
#define INNER_PATH 9,9,14,14
#define TEXT_POS 14,5,16,16,0
#define BUTTON_SIZE 36,36
#define THEME_SCHAME "org.ukui.style"
#define COLOR_THEME "styleName"
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
{
this->setFixedSize(BUTTON_SIZE);
initUI();
const QByteArray style_id(THEME_SCHAME);
if (QGSettings::isSchemaInstalled(style_id)) {
m_styleGsettings = new QGSettings(style_id);
connect(m_styleGsettings, &QGSettings::changed, this, &InfoButton::onGSettingChaned);
} else {
qDebug() << "Gsettings interface \"org.ukui.style\" is not exist!";
}
}
void InfoButton::initUI()
{
this->setFixedSize(BUTTON_SIZE);
m_backgroundColor = BACKGROUND_COLOR;
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
}
void InfoButton::onGSettingChaned(const QString &key)
{
if (key == COLOR_THEME) {
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
this->repaint();
}
}
void InfoButton::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
pal.setColor(QPalette::Base, m_backgroundColor);
pal.setColor(QPalette::Text, m_foregroundColor);
QPainterPath cPath;
cPath.addRect(0, 0, ICON_SIZE);
cPath.addEllipse(0, 0, ICON_SIZE);
QPainterPath outerPath;
outerPath.addEllipse(OUTER_PATH);
QPainterPath innerPath;
innerPath.addEllipse(INNER_PATH);
outerPath -= innerPath;
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
painter.drawPath(cPath);
painter.fillPath(outerPath, pal.color(QPalette::Text));
painter.setPen(m_foregroundColor);
QFont font("Noto Sans CJK SC", 11, QFont::Normal, false);
painter.setFont(font);
painter.drawText(TEXT_POS, "i");
}
void InfoButton::enterEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
}
void InfoButton::leaveEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
this->repaint();
}
void InfoButton::mousePressEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_PRESS;
this->repaint();
return QPushButton::mousePressEvent(event);
}
void InfoButton::mouseReleaseEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
return QPushButton::mouseReleaseEvent(event);
}

View File

@ -0,0 +1,35 @@
#ifndef INFOBUTTON_H
#define INFOBUTTON_H
#include <QPushButton>
#include <QIcon>
#include <QGSettings>
class InfoButton : public QPushButton
{
Q_OBJECT
public:
explicit InfoButton(QWidget * parent = nullptr);
~InfoButton() = default;
protected:
void paintEvent(QPaintEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
void initUI();
private:
QColor m_backgroundColor;
QColor m_foregroundColor;
//监听主题的Gsettings
QGSettings * m_styleGsettings = nullptr;
private Q_SLOTS:
void onGSettingChaned(const QString &key);
};
#endif // INFOBUTTON_H

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/RadioItemButton/radioitembutton.cpp \
HEADERS += \
$$PWD/RadioItemButton/radioitembutton.h \

View File

@ -0,0 +1,183 @@
#include "radioitembutton.h"
#include <QPainter>
//#include <QSvgRenderer>
#include <QApplication>
#include <QStyle>
#include <QDebug>
#include <QPainterPath>
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
{
this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this);
this->setFixedSize(BUTTON_SIZE);
m_iconLabel->setFixedSize(BUTTON_SIZE);
m_iconLabel->setAlignment(Qt::AlignCenter);
setActive(false);
//JXJ_TODO loading动画
connect(qApp, &QApplication::paletteChanged, this, &RadioItemButton::onPaletteChanged);
}
//设置图标
void RadioItemButton::setButtonIcon(const QIcon &icon)
{
if (icon.isNull()) {
return;
}
m_pixmap = icon.pixmap(ICON_SIZE);
refreshButtonIcon();
}
//显示默认图标
void RadioItemButton::setDefaultPixmap()
{
m_iconLabel->setPixmap(m_pixmap);
}
//根据连接状态更改图标颜色
void RadioItemButton::setActive(const bool &isActive)
{
m_isActivated = isActive;
refreshButtonIcon();
}
void RadioItemButton::onPaletteChanged()
{
refreshButtonIcon();
}
void RadioItemButton::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
pal.setColor(QPalette::Base, BACKGROUND_COLOR);
pal.setColor(QPalette::Text, m_backgroundColor);
QPainterPath cPath;
cPath.addRect(0, 0, this->width(), this->height());
cPath.addEllipse(0, 0, this->width(), this->width());
QPainterPath innerPath;
innerPath.addEllipse(0, 0, this->width(), this->width());
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
painter.drawPath(cPath);
painter.fillPath(innerPath, pal.color(QPalette::Text));
}
void RadioItemButton::mousePressEvent(QMouseEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.21);
}
this->update();
return QPushButton::mousePressEvent(event);
}
void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.18);
}
this->update();
return QPushButton::mouseReleaseEvent(event);
}
void RadioItemButton::enterEvent(QEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.32);
}
this->update();
return QPushButton::enterEvent(event);
}
void RadioItemButton::leaveEvent(QEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.18);
}
this->update();
return QPushButton::leaveEvent(event);
}
void RadioItemButton::refreshButtonIcon()
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.18);
// if (qApp->palette().base().color().red() > MIDDLE_COLOR) {
m_iconLabel->setPixmap(m_pixmap);
// } else {
// m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
// }
}
return;
}
const QPixmap RadioItemButton::loadSvg(const QPixmap &source, const PixmapColor &cgColor)
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++) {
for (int y = 0; y < img.height(); y++) {
auto color = img.pixelColor(x, y);
if (color.alpha() > 0) {
switch (cgColor) {
case PixmapColor::WHITE:
color.setRed(255);
color.setGreen(255);
color.setBlue(255);
img.setPixelColor(x, y, color);
break;
case PixmapColor::BLACK:
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
break;
case PixmapColor::GRAY:
color.setRed(152);
color.setGreen(163);
color.setBlue(164);
img.setPixelColor(x, y, color);
break;
case PixmapColor::BLUE:
color.setRed(61);
color.setGreen(107);
color.setBlue(229);
img.setPixelColor(x, y, color);
break;
default:
return source;
break;
}
}
}
}
return QPixmap::fromImage(img);
}

View File

@ -0,0 +1,51 @@
#ifndef NETBUTTON_H
#define NETBUTTON_H
#include <QPushButton>
#include <QIcon>
#include <QLabel>
#include <QTimer>
#include <QVariantAnimation>
#define MIDDLE_COLOR 178
class RadioItemButton : public QPushButton
{
Q_OBJECT
public:
RadioItemButton(QWidget * parent = nullptr);
// ~RadioItemButton();
void setButtonIcon(const QIcon &icon);
void setDefaultPixmap();
void setActive(const bool &isActive);
enum PixmapColor {
WHITE = 0,
BLACK,
GRAY,
BLUE,
};
const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color);
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
private:
bool m_isActivated = false;
QLabel * m_iconLabel = nullptr;
QColor m_backgroundColor;
QPixmap m_pixmap;
void refreshButtonIcon();
private Q_SLOTS:
void onPaletteChanged();
};
#endif // NETBUTTON_H

View File

@ -0,0 +1,327 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "switchbutton.h"
#include <QDebug>
#define THEME_QT_SCHEMA "org.ukui.style"
#define THEME_GTK_SCHEMA "org.mate.interface"
#define TIMER_INTERVAL 5 //每隔5ms动画移动一次
#define MOVING_STEPS 40 //动画总共移动40次
SwitchButton::SwitchButton(QWidget *parent, bool useDisableStyle) :
QWidget(parent)
{
// this->resize(QSize(52, 24));
this->setFixedSize(QSize(50, 24));
checked = false;
hover = false;
disabled = false;
isMoving = false;
isAnimation = true;
m_useDisableStyle = useDisableStyle;
space = 4;
rectRadius = height()/2;
mStep = width()/MOVING_STEPS;//也就是40次动画就可以走完每次时间间隔是固定的5ms
mStartX = 0;
mEndX= 0;
mTimer = new QTimer(this);
mTimer->setInterval(TIMER_INTERVAL);//动画更新时间
connect(mTimer, SIGNAL(timeout()), this, SLOT(updatevalue()));
if(QGSettings::isSchemaInstalled(THEME_GTK_SCHEMA) && QGSettings::isSchemaInstalled(THEME_QT_SCHEMA)) {
QByteArray qtThemeID(THEME_QT_SCHEMA);
QByteArray gtkThemeID(THEME_GTK_SCHEMA);
m_gtkThemeSetting = new QGSettings(gtkThemeID,QByteArray(),this);
m_qtThemeSetting = new QGSettings(qtThemeID,QByteArray(),this);
QString style = m_qtThemeSetting->get("styleName").toString();
changeColor(style);
connect(m_qtThemeSetting,&QGSettings::changed, [this] (const QString &key) {
QString style = m_qtThemeSetting->get("styleName").toString();
if (key == "styleName") {
changeColor(style);
}
});
}
}
SwitchButton::~SwitchButton()
{
}
void SwitchButton::paintEvent(QPaintEvent *){
QPainter painter(this);
//启用反锯齿
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setCompositionMode(QPainter::CompositionMode_Source);
drawBg(&painter);
if(!isAnimation)//动画如果禁用则圆形滑块isMoving始终为false
isMoving =false;
if(isMoving)
animation(&painter);
drawSlider(&painter);
painter.end();
}
void SwitchButton::changeColor(const QString &themes) {
if (hover) {
return ;//在鼠标下,禁止切换颜色鼠标离开时切换颜色
}
if (themes == "ukui-dark" || themes == "ukui-black") {
bgColorOff = QColor(OFF_BG_DARK_COLOR);
bgColorOn = QColor(ON_BG_DARK_COLOR);
rectColorEnabled = QColor(ENABLE_RECT_DARK_COLOR);
rectColorDisabled = QColor(DISABLE_RECT_DARK_COLOR);
sliderColorDisabled = QColor(DISABLE_RECT_DARK_COLOR);
sliderColorEnabled = QColor(ENABLE_RECT_DARK_COLOR);
bgHoverOnColor = QColor(ON_HOVER_BG_DARK_COLOR);
bgHoverOffColor = QColor(OFF_HOVER_BG_DARK_COLOR);
bgColorDisabled = QColor(DISABLE_DARK_COLOR);
} else {
bgColorOff = QColor(OFF_BG_LIGHT_COLOR);
bgColorOn = QColor(ON_BG_LIGHT_COLOR);
rectColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR);
rectColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR);
sliderColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR);
sliderColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR);
bgHoverOnColor = QColor(ON_HOVER_BG_LIGHT_COLOR);
bgHoverOffColor = QColor(OFF_HOVER_BG_LIGHT_COLOR);
bgColorDisabled = QColor(DISABLE_LIGHT_COLOR);
}
}
//动画绘制
void SwitchButton::animation(QPainter *painter){
painter->save();
int h = height();
int w = width();
painter->setPen(Qt::NoPen);
//颜色设置
if(checked){
//开关在左侧时
painter->setBrush(bgColorOn);
rect.setRect(0,0,h+mStartX,h);
}else{
painter->setBrush(bgColorOff);
rect.setRect(mStartX,0,w-mStartX,h);
}
painter->drawRoundedRect(rect,rectRadius,rectRadius);
painter->restore();
}
//绘制背景
void SwitchButton::drawBg(QPainter *painter){
int w = width();
int h = height();
painter->save();
painter->setPen(Qt::NoPen);
if (disabled && m_useDisableStyle) {
painter->setPen(Qt::NoPen);
painter->setBrush(bgColorDisabled);
} else {
if(checked){
if(isMoving){
painter->setBrush(bgColorOff);
rect.setRect(mStartX,0,w-mStartX,h);
}else {
painter->setBrush(bgColorOn);
rect.setRect(0, 0, w, h);
}
}else{
if(isMoving){
painter->setBrush(bgColorOn);
rect.setRect(0,0,mStartX+h,h);
}
else {
painter->setBrush(bgColorOff);
rect.setRect(0, 0, w, h);
}
}
}
//半径为高度的一半
painter->drawRoundedRect(rect,rectRadius,rectRadius);
painter->restore();
}
//绘制滑块,也就是圆形按钮
void SwitchButton::drawSlider(QPainter *painter){
painter->save();
painter->setPen(Qt::NoPen);
if (!disabled || !m_useDisableStyle){
painter->setBrush(sliderColorEnabled);
}
else
painter->setBrush(sliderColorDisabled);
if (disabled) {
if (!checked){
QRect smallRect(8, height() / 2 - 2, 10 , 4);
painter->drawRoundedRect(smallRect,3,3);
}else{
QRect smallRect(width() - 8 * 2, height() / 2 - 2, 10 , 4);
painter->drawRoundedRect(smallRect,3,3);
}
}
QRect rect(0, 0, width(), height());
int sliderWidth = rect.height() - space * 2;
QRect sliderRect(mStartX + space, space, sliderWidth, sliderWidth);
painter->drawEllipse(sliderRect);
painter->restore();
}
void SwitchButton::mousePressEvent(QMouseEvent *){
qDebug()<<isMoving<<checked<<disabled;
if (isMoving) {
return ;
}
if(disabled){
mEndX = 0;
Q_EMIT disabledClick();
return ;
}else{
checked = !checked;
Q_EMIT checkedChanged(checked);
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// endX = width() - height() + space;
//circle in
mEndX = width() - height();
}
else {
mEndX = 0;
}
mTimer->start();
isMoving = true;
}
}
void SwitchButton::resizeEvent(QResizeEvent *){
//每次开始的x坐标都是跳过圆角从直线的地方开始计算
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// startX = width() - height() + space;
//circle in
mStartX = width() - height();
}
else
mStartX = 0;
rectRadius = height()/2;
update();
}
void SwitchButton::enterEvent(QEvent *event) {
bgColorOn = bgHoverOnColor;
bgColorOff = bgHoverOffColor;
hover = true;
update();
return QWidget::enterEvent(event);
}
void SwitchButton::leaveEvent(QEvent *event) {
hover = false;
QString style = m_qtThemeSetting->get("styleName").toString();
changeColor(style);
update();
return QWidget::leaveEvent(event);
}
//根据事件向左还是向右移动
void SwitchButton::updatevalue(){
if (checked)
if (mStartX < mEndX-mStep){
mStartX = mStartX + mStep;
}
else{
mStartX = mEndX;
mTimer->stop();
isMoving = false;
}
else{
if (mStartX > mEndX+mStep){
mStartX = mStartX - mStep;
}
else{
mStartX = mEndX;
mTimer->stop();
isMoving = false;
}
}
update();
}
void SwitchButton::setChecked(bool checked){
if (this->checked != checked){
this->checked = checked;
Q_EMIT checkedChanged(checked);
update();
}
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// endX = width() - height() + space;
//circle in
mEndX = width() - height();
}
else{
mEndX = 0;
}
mTimer->start();
isMoving = true;
}
bool SwitchButton::isChecked(){
return this->checked;
}
void SwitchButton::setDisabledFlag(bool value)
{
disabled = value;
update();
}
bool SwitchButton::getDisabledFlag()
{
return disabled;
}
void SwitchButton::setAnimation(bool on){
isAnimation = on;
}

View File

@ -0,0 +1,121 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H
#include <QWidget>
#include <QTimer>
#include <QPainter>
#include <QPainterPath>
#include <QEvent>
#include <QGSettings/QGSettings>
#define OFF_BG_DARK_COLOR "#404040"
#define OFF_HOVER_BG_DARK_COLOR "#666666"
#define ON_BG_DARK_COLOR "#3790FA"
#define ON_HOVER_BG_DARK_COLOR "#40A9FB"
#define DISABLE_DARK_COLOR "#474747"
#define DISABLE_RECT_DARK_COLOR "#6E6E6E"
#define ENABLE_RECT_DARK_COLOR "#FFFFFF"
#define OFF_BG_LIGHT_COLOR "#E0E0E0"
#define OFF_HOVER_BG_LIGHT_COLOR "#B3B3B3"
#define ON_BG_LIGHT_COLOR "#3790FA"
#define ON_HOVER_BG_LIGHT_COLOR "#40A9FB"
#define DISABLE_LIGHT_COLOR "#E9E9E9"
#define DISABLE_RECT_LIGHT_COLOR "#B3B3B3"
#define ENABLE_RECT_LIGHT_COLOR "#FFFFFF"
class SwitchButton : public QWidget
{
Q_OBJECT
public:
SwitchButton(QWidget *parent = 0, bool useDisableStyle = true);
~SwitchButton();
void setChecked(bool checked);
void setAnimation(bool on);
bool isChecked();
void setDisabledFlag(bool);
bool getDisabledFlag();
protected:
void mousePressEvent(QMouseEvent *);
void resizeEvent(QResizeEvent *);
void paintEvent(QPaintEvent *);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void drawBg(QPainter * painter);
void drawSlider(QPainter * painter);
void changeColor(const QString &themes);
private:
bool checked; //切换的判断
bool disabled;
void animation(QPainter *painter);
QRect rect;
bool isMoving; //滑块动作判断
bool isAnimation; // 是否允许动画执行
QColor bgColorOff;
QColor bgColorOn;
QColor bgHoverOnColor;
QColor bgHoverOffColor;
QColor bgColorDisabled;
QColor sliderColorEnabled;
QColor sliderColorDisabled;
QColor rectColorEnabled;
QColor rectColorDisabled;
QColor sliderColorOff;
QColor sliderColorOn;
QGSettings *m_qtThemeSetting;
QGSettings *m_gtkThemeSetting;
int space; //滑块离背景间隔
int rectRadius; //圆角角度
int mStep; //移动步长
int mStartX;
int mEndX;
bool hover;
QTimer * mTimer;
bool m_useDisableStyle;
private Q_SLOTS:
void updatevalue();
Q_SIGNALS:
void checkedChanged(bool checked);
void disabledClick();
};
#endif // SWITCHBUTTON_H

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/DeviceFrame/deviceframe.cpp \
HEADERS += \
$$PWD/DeviceFrame/deviceframe.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(drownlabel)
SOURCES += \
$$PWD/Divider/divider.cpp \
HEADERS += \
$$PWD/Divider/divider.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(drownlabel)
SOURCES += \
$$PWD/DrownLabel/drownlabel.cpp \
HEADERS += \
$$PWD/DrownLabel/drownlabel.h \

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/FixLabel/fixlabel.cpp \
HEADERS += \
$$PWD/FixLabel/fixlabel.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(infobutton)
SOURCES += \
$$PWD/InfoButton/infobutton.cpp \
HEADERS += \
$$PWD/InfoButton/infobutton.h \

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/Divider/divider.cpp \
HEADERS += \
$$PWD/Divider/divider.h \

View File

@ -0,0 +1,28 @@
#include "itemframe.h"
#define LAYOUT_MARGINS 4,0,12,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
ItemFrame::ItemFrame(QString devName, QWidget *parent) : QFrame(parent)
{
deviceLanLayout = new QVBoxLayout(this);
deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
lanItemFrame = new QFrame(this);
lanItemFrame->setFrameShape(QFrame::Shape::NoFrame);
lanItemLayout = new QVBoxLayout(this);
lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout->setSpacing(0);
deviceLanLayout->setSpacing(0);
setLayout(deviceLanLayout);
lanItemFrame->setLayout(lanItemLayout);
deviceFrame = new DeviceFrame(devName, this);
m_divider = new Divider(this);
deviceLanLayout->addWidget(m_divider);
deviceLanLayout->addWidget(deviceFrame);
deviceLanLayout->addWidget(lanItemFrame);
}

View File

@ -0,0 +1,29 @@
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include <QFrame>
#include <QVBoxLayout>
#include "lanitem.h"
#include "../component/DeviceFrame/deviceframe.h"
#include "../component/Divider/divider.h"
class ItemFrame : public QFrame
{
Q_OBJECT
public:
ItemFrame(QString devName, QWidget *parent = nullptr);
//单设备整体layout
QVBoxLayout * deviceLanLayout = nullptr;
Divider * m_divider;
//单设备名称 单设备开关
DeviceFrame * deviceFrame = nullptr;
//单设备列表Frame
QFrame * lanItemFrame = nullptr;
//单设备列表layout
QVBoxLayout * lanItemLayout = nullptr;
//单设备item列表 key:uuid
QMap<QString, LanItem *> itemMap;
};
#endif // ITEMFRAME_H

View File

@ -0,0 +1,123 @@
#include "lanitem.h"
#include <QPainterPath>
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
#define RADIUS 6.0
LanItem::LanItem(bool isSimple, QWidget *parent)
: QFrame(parent),isSimple(isSimple)
{
this->setFixedSize(404, 48);
QHBoxLayout *mLanLyt = new QHBoxLayout(this);
mLanLyt->setContentsMargins(16,0,0,0);
mLanLyt->setSpacing(0);
radioBtn = new RadioItemButton(this);
titileLabel = new FixLabel(this);
titileLabel->setMinimumWidth(282);
mLanLyt->addWidget(radioBtn);
mLanLyt->addSpacing(10);
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
if (!isSimple) {
infoLabel = new InfoButton(this);
mLanLyt->addSpacing(8);
mLanLyt->addWidget(infoLabel);
connect(infoLabel, &InfoButton::released, this, &LanItem::infoButtonClick);
}
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon);
m_menu = new QMenu(this);//右键菜单
m_menu->setWindowFlag(Qt::X11BypassWindowManagerHint);
connect(m_menu, &QMenu::triggered, this, &LanItem::itemClick);
}
void LanItem::updateIcon()
{
if (currentIconIndex > 6) {
currentIconIndex = 0;
}
radioBtn->setButtonIcon(loadIcons.at(currentIconIndex));
currentIconIndex ++;
}
void LanItem::startLoading()
{
waitTimer->start(FRAME_SPEED);
m_loading = true;
}
void LanItem::stopLoading(){
waitTimer->stop();
m_loading = false;
}
void LanItem::mousePressEvent(QMouseEvent *event)
{
return QFrame::mousePressEvent(event);
}
void LanItem::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton) {
if (!m_menu) {
return QFrame::mouseReleaseEvent(event);
}
m_menu->clear();
if (m_isAcitve || m_loading) {
m_menu->addAction(new QAction(tr("Disconnect"), this));
} else if (!m_isAcitve && !m_loading) {
m_menu->addAction(new QAction(tr("Connect"), this));
}
m_menu->move(cursor().pos());
m_menu->show();
} else {
if (!m_isAcitve && !m_loading) {
Q_EMIT itemClick();
}
}
return QFrame::mouseReleaseEvent(event);
}
void LanItem::enterEvent(QEvent *event)
{
m_isIn = true;
update();
return QFrame::enterEvent(event);
}
void LanItem::leaveEvent(QEvent *event)
{
m_isIn = false;
update();
return QFrame::leaveEvent(event);
}
void LanItem::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
if (m_isIn) {
QColor color(240, 240, 240);
color.setAlphaF(0.39);
painter.setBrush(color);
}
else
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect(rect, RADIUS, RADIUS);
painter.drawPath(path);
return QFrame::paintEvent(event);
}

View File

@ -0,0 +1,103 @@
#ifndef LANITEM_H
#define LANITEM_H
#include <QObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QTimer>
#include <QImage>
#include <QPainter>
#include <QMouseEvent>
#include <QMenu>
#include "../component/InfoButton/infobutton.h"
#include "../component/RadioItemButton/radioitembutton.h"
#include "../component/FixLabel/fixlabel.h"
class LanItem : public QFrame
{
Q_OBJECT
public:
LanItem(bool isSimple, QWidget *parent = nullptr);
void setName(QString name) {
titileLabel->setLabelText(name);
}
QString getName() {
return titileLabel->getText();
}
void setItemIcon(const QIcon &icon) {
radioBtn->setButtonIcon(icon);
}
void setStatus(bool isAcitve){
m_isAcitve = isAcitve;
radioBtn->setActive(isAcitve);
}
bool getStatus(){
return m_isAcitve;
}
bool getIsLoading() {
return m_loading;
}
QString getUuid(){
return m_uuid;
}
void setUuid(QString uuid){
m_uuid = uuid;
}
QString getPath(){
return m_dbusPath;
}
void setPath(QString dbusPath){
m_dbusPath = dbusPath;
}
void startLoading();
void stopLoading();
Q_SIGNALS:
void itemClick();
void infoButtonClick();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
private:
QTimer *waitTimer = nullptr;
QList<QIcon> loadIcons;
int currentIconIndex=0;
QMenu *m_menu = nullptr;
RadioItemButton* radioBtn = nullptr;
InfoButton * infoLabel = nullptr;
FixLabel * titileLabel = nullptr;
bool m_loading = false;
bool m_isAcitve = false;
bool isSimple;
QString m_uuid;
QString m_dbusPath;
bool m_isIn = false;
private Q_SLOTS:
void updateIcon();
};
#endif // LANITEM_H

View File

@ -0,0 +1,873 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "netconnect.h"
#include <QGSettings>
#include <QProcess>
#include <QTimer>
#include <QtDBus>
#include <QDir>
#include <QDebug>
#include <QtAlgorithms>
const QString KLanSymbolic = "network-wired-connected-symbolic";
const QString NoNetSymbolic = "network-wired-disconnected-symbolic";
#define NO_MARGINS 0,0,0,0
#define TOP_MARGINS 0,8,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0
#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙和设计稿看起来一致就不能设为设计稿里的高度
#define TITLE_LAYOUT_MARGINS 24,0,24,0
#define SPACING 8
const QString KEY_WIRED_SWITCH = "wiredswitch";
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
bool checkMapValveContainsTrue(QMap<QString, bool> map) {
if (map.isEmpty()) {
return false;
}
QMap<QString, bool>::iterator iter;
for (iter = map.begin(); iter != map.end(); iter++) {
if (iter.value()) {
return true;
}
}
return false;
}
NetConnect::NetConnect() : mFirstLoad(true) {
QLocale local;
QString locale = local.name();
QTranslator* translator = new QTranslator(this);
if (translator->load(":/translations/"+ locale + ".qm")) {
QApplication::installTranslator(translator);
} else {
qWarning() << "Translations load fail";
}
}
NetConnect::~NetConnect() {
qDebug() << "~NetConnect 1";
if (m_switchGsettings != nullptr) {
delete m_switchGsettings;
m_switchGsettings = nullptr;
}
thread->quit();
thread->wait();
delete thread;
if (pluginWidget != nullptr) {
delete pluginWidget;
}
qDebug() << "~NetConnect 2";
}
QWidget *NetConnect::pluginUi() {
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
pluginWidget->setFixedSize(420, 436);
initUi();
initComponent();
initConnect();
}
return pluginWidget;
}
void NetConnect::setPluginType(PluginType type, bool useSwitch)
{
if (type == SIMPLE) {
m_isSimpleMode = true;
} else {
m_isSimpleMode = false;
}
m_useSwitch = useSwitch;
}
void NetConnect::initUi()
{
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
connect(thread, &QThread::started, manager, &KyNetworkManager::kylinNetworkManagerInit);
connect(thread, &QThread::finished, manager, &KyNetworkManager::deleteLater);
connect(thread, &QThread::finished, [=](){
qDebug() << "NetConnect thread quit";
});
thread->start();
while (!manager->isInitFinished()) {
::usleep(1000);
}
m_mainLayout = new QVBoxLayout(pluginWidget);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
pluginWidget->setLayout(m_mainLayout);
m_titleFrame = new QFrame(pluginWidget);
m_titleFrame->setFixedHeight(53);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("LAN"));
// m_wiredSwitch = new KSwitchButton(pluginWidget);
// m_wiredSwitch->installEventFilter(this);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
// m_titleLayout->addWidget(m_wiredSwitch);
m_titleDivider = new Divider(pluginWidget);
m_titleDivider->hide();
m_scrollFrame = new QFrame(pluginWidget);
if (!m_isSimpleMode) {
m_scrollFrame->setMinimumHeight(330);
} else {
m_scrollFrame->setMinimumHeight(383);
}
m_scrollLayout = new QVBoxLayout(m_scrollFrame);
m_scrollLayout->setContentsMargins(0,0,0,0);
m_scrollLayout->setSpacing(0);
m_scrollFrame->setLayout(m_scrollLayout);
m_scrollArea = new QScrollArea(m_scrollFrame);
m_scrollArea->setFrameShape(QFrame::Shape::NoFrame);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setBackgroundRole(QPalette::Base);
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scrollLayout->addWidget(m_scrollArea);
m_listWidget = new QWidget(pluginWidget);
m_listWidget->setFixedWidth(420);
m_scrollAreaLayout = new QVBoxLayout(m_listWidget);
m_scrollAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_scrollAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_scrollAreaLayout->setAlignment(Qt::AlignTop);
m_listWidget->setLayout(m_scrollAreaLayout);
m_scrollArea->setWidget(m_listWidget);
m_settingsDivider = new Divider(pluginWidget);
m_settingsFrame = new QFrame(pluginWidget);
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_settingsLabel = new KBorderlessButton(m_settingsFrame);
m_settingsLabel->setCursor(Qt::PointingHandCursor);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsLayout->addStretch();
m_settingsFrame->setLayout(m_settingsLayout);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_scrollFrame);
if (!m_isSimpleMode) {
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_settingsDivider);
m_mainLayout->addWidget(m_settingsFrame);
} else {
m_settingsDivider->hide();
m_settingsFrame->hide();
}
QPalette pal = m_scrollArea->palette();
pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
m_scrollArea->setPalette(pal);
}
bool NetConnect::eventFilter(QObject *w, QEvent *e) {
/* if (w == m_wiredSwitch && e->type() == QEvent::MouseButtonRelease) {
if (!m_wiredSwitch->isCheckable()) {
// showDesktopNotify(tr("No ethernet device avaliable"));
qDebug() << "No ethernet device avaliable";
} else {
Q_EMIT setWiredEnabled(!m_wiredSwitch->isChecked());
}
return true;
}*/
return QObject::eventFilter(w,e);
}
void NetConnect::initComponent() {
getDeviceStatusMap(deviceStatusMap);
initNet();
setSwitchStatus();
connect(m_settingsLabel, &KBorderlessButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
runExternalApp();
});
}
void NetConnect::initConnect()
{
connect(manager, &KyNetworkManager::wiredStateChange, this, &NetConnect::onActiveConnectionChanged);
//connect(manager, &KyNetworkManager::deviceStateChange, this, &NetConnect::onDeviceStatusChanged);
connect(manager, &KyNetworkManager::carrierChange, this, &NetConnect::onDeviceCarrierChange);
connect(manager, &KyNetworkManager::wiredConnectionAdd, this, &NetConnect::onLanAdd);
connect(manager, &KyNetworkManager::wiredConnectionUpdate, this, &NetConnect::updateLanInfo);
connect(manager, &KyNetworkManager::connectionRemove, this, &NetConnect::onLanRemove);
connect(manager, &KyNetworkManager::wiredDeviceAdd, this, &NetConnect::onDeviceAdd);
connect(manager, &KyNetworkManager::deviceRemove, this, &NetConnect::onDeviceRemove);
connect(manager, &KyNetworkManager::wiredDeviceUpdate, this, &NetConnect::onDeviceNameChanged);
connect(manager, &KyNetworkManager::deviceManagedChange, this, &NetConnect::onDeviceManagedChange);
connect(manager, &KyNetworkManager::wiredEnabledChanged, this, &NetConnect::onWiredEnabledChanged);
connect(this, &NetConnect::setWiredDeviceEnable, manager, &KyNetworkManager::onSetWiredDeviceEnable);
connect(this, &NetConnect::setWiredEnabled, manager, &KyNetworkManager::onSetWiredEnabled);
connect(this, &NetConnect::activateConnection, manager, &KyNetworkManager::onActivateConnection);
connect(this, &NetConnect::deactivateConnection, manager, &KyNetworkManager::onDeactivateConnection);
connect(this, &NetConnect::deleteConnect, manager, &KyNetworkManager::onDeleteConnect);
connect(this, &NetConnect::updateIpv4AndIpv6SettingInfo, manager, &KyNetworkManager::onUpdateIpv4AndIpv6SettingInfo);
connect(this, &NetConnect::createWiredConnect, manager, &KyNetworkManager::onCreateWiredConnect);
}
//获取网卡列表
void NetConnect::getDeviceStatusMap(QMap<QString, bool> &map)
{
map.clear();
QStringList wiredDevList;
wiredDevList.clear();
manager->getNetworkDeviceList(DEVICE_TYPE_ETHERNET, wiredDevList);
qDebug() << wiredDevList;
if (!wiredDevList.isEmpty()) {
for (int i = 0; i < wiredDevList.size(); ++i) {
QString devName = wiredDevList.at(i);qDebug() << devName;
map.insert(devName, manager->getDeviceManaged(devName));
}
}
}
//lanUpdate
void NetConnect::updateLanInfo(QString deviceName, QString connectUuid, QString connectName, QString connectPath)
{
//设备归属变化 || 有线名称变化
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (deviceName.isEmpty()) {
//变为无指定网卡,所有列表都要添加
if (!iter.value()->itemMap.contains(connectUuid)) {
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
addOneLanFrame(iter.value(), iter.key(), lanInfo);
} else {
if (iter.value()->itemMap[connectUuid]->getName() != connectName) {
qDebug() << "[NetConnect]" << iter.key()
<< iter.value()->itemMap[connectUuid]->getName() << "change to" << connectName;
iter.value()->itemMap[connectUuid]->setName(connectName);
deviceFrameMap[iter.key()]->lanItemLayout->removeWidget(iter.value()->itemMap[connectUuid]);
int index = getInsertPos(connectName, deviceFrameMap[iter.key()]->lanItemLayout);
deviceFrameMap[iter.key()]->lanItemLayout->insertWidget(index,iter.value()->itemMap[connectUuid]);
}
}
} else {
if (iter.key() != deviceName) {
qDebug() << "[NetConnect]" << connectUuid << " not belongs to " << iter.key();
removeOneLanFrame(iter.value(), deviceName, connectUuid);
} else {
if (!iter.value()->itemMap.contains(connectUuid)) {
qDebug() << "[NetConnect]" << connectUuid << " now belongs to " << deviceName;
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
addOneLanFrame(iter.value(), deviceName, lanInfo);
} else {
qDebug() << "[NetConnect]" << deviceName
<< iter.value()->itemMap[connectUuid]->getName() << "change to" << connectName;
if (iter.value()->itemMap[connectUuid]->getName() != connectName) {
iter.value()->itemMap[connectUuid]->setName(connectName);
deviceFrameMap[iter.key()]->lanItemLayout->removeWidget(iter.value()->itemMap[connectUuid]);
int index = getInsertPos(connectName, deviceFrameMap[iter.key()]->lanItemLayout);
deviceFrameMap[iter.key()]->lanItemLayout->insertWidget(index,iter.value()->itemMap[connectUuid]);
}
}
}
}
}
}
//总开关
void NetConnect::setSwitchStatus()
{
/*getDeviceStatusMap(deviceStatusMap);
bool status = checkMapValveContainsTrue(deviceStatusMap);
if (!status) {
// if (manager->getWiredEnabled()) {
// m_wiredSwitch->setCheckable(true);
// m_wiredSwitch->setChecked(true);
// } else {
m_wiredSwitch->setChecked(false);
m_wiredSwitch->setCheckable(false);
// }
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
} else {
m_wiredSwitch->setCheckable(true);
if (manager->getWiredEnabled()) {
m_wiredSwitch->setChecked(true);
showLayout(m_scrollAreaLayout);
m_titleDivider->hide();
} else {
m_wiredSwitch->setChecked(false);
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
}
}*/
}
//总体隐藏
void NetConnect::hideLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i)
{
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->hide();
}
}
//总体显示
void NetConnect::showLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i)
{
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->show();
}
}
//初始化
void NetConnect::initNet()
{
//先构建每个设备的列表头
QStringList deviceList = deviceStatusMap.keys();
for (int i = 0; i < deviceList.size(); ++i) {
addDeviceFrame(deviceList.at(i), deviceStatusMap[deviceList.at(i)]);
}
//再填充每个设备的列表
for (int i = 0; i < deviceList.size(); ++i) {
initNetListFromDevice(deviceList.at(i));
}
}
void NetConnect::runExternalApp()
{
QProcess process;
process.startDetached("ukui-control-center -m netconnect");
}
//激活
void NetConnect::activeConnect(QString uuid, QString deviceName)
{
Q_EMIT activateConnection(uuid, deviceName);
}
//断开
void NetConnect::deActiveConnect(QString uuid)
{
Q_EMIT deactivateConnection(uuid);
}
//初始化设备列表
void NetConnect::initNetListFromDevice(QString deviceName)
{
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName;
if (!deviceFrameMap.contains(deviceName)) {
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " not exist";
return;
}
QMap<QString,QList<KyWiredItem>> wiredMap;
manager->getWiredList(wiredMap);
if (wiredMap.size() == 0) {
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " list empty";
return;
}
QMap<QString,QList<KyWiredItem>>::iterator iter;
for (iter = wiredMap.begin(); iter != wiredMap.end(); iter++) {
if (deviceName == iter.key()) {
QList<KyWiredItem> lanListInfo = iter.value();
//处理列表
for (int i = 0; i < lanListInfo.length(); i++) {
addLanItem(deviceFrameMap[deviceName], deviceName, lanListInfo.at(i));
}
}
}
QList<KyActivateItem> activateList;
manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRED, activateList);
if (activateList.size() != 0) {
onActiveConnectionChanged(deviceName, activateList.at(0).m_uuid, activateList.at(0).m_connStatus);
}
}
//初始化时添加一个项
void NetConnect::addLanItem(ItemFrame *frame, QString devName, KyWiredItem item)
{
if (frame == nullptr) {
return;
}
LanItem * lanItem = new LanItem(m_isSimpleMode, pluginWidget);
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
lanItem->setItemIcon(searchIcon);
lanItem->setName(item.m_connectName);
lanItem->setUuid(item.m_connectUuid);
lanItem->setPath(item.m_connectPath);
//todo show detail page
connect(lanItem, &LanItem::infoButtonClick, this, [=]{
});
lanItem->setStatus(false);
connect(lanItem, &LanItem::itemClick, this, [=] {
if (lanItem->getStatus() || lanItem->getIsLoading()) {
deActiveConnect(lanItem->getUuid());
} else {
activeConnect(lanItem->getUuid(), devName);
}
});
//记录到deviceFrame的itemMap中
deviceFrameMap[devName]->itemMap.insert(item.m_connectUuid, lanItem);
frame->lanItemLayout->addWidget(lanItem);
}
//增加设备
void NetConnect::addDeviceFrame(QString devName, bool isEnable)
{
ItemFrame *itemFrame = new ItemFrame(devName, pluginWidget);
m_scrollAreaLayout->addWidget(itemFrame);
itemFrame->deviceFrame->deviceLabel->setText(devName);
if (isEnable) {
itemFrame->show();
} else {
itemFrame->hide();
}
deviceFrameMap.insert(devName, itemFrame);
deviceStatusMap.insert(devName, true);
}
//减少设备
void NetConnect::removeDeviceFrame(QString devName)
{
if (deviceFrameMap.contains(devName)) {
ItemFrame *item = deviceFrameMap[devName];
if (item->lanItemFrame->layout() != NULL) {
QLayoutItem* layoutItem;
while ((layoutItem = item->lanItemFrame->layout()->takeAt(0)) != NULL) {
delete layoutItem->widget();
delete layoutItem;
layoutItem = nullptr;
}
item->itemMap.clear();
}
delete item;
item = nullptr;
deviceFrameMap.remove(devName);
}
}
//device add or remove=================================
#if 0
void NetConnect::onDeviceStatusChanged()
{
qDebug()<<"[NetConnect]onDeviceStatusChanged";
QEventLoop eventloop;
QTimer::singleShot(300, &eventloop, SLOT(quit()));
eventloop.exec();
QStringList list;
QMap<QString, bool> map;
getDeviceStatusMap(map);
list = map.keys();
QStringList removeList;
QMap<QString, bool> addMap;
//remove的设备
for (int i = 0; i< deviceStatusMap.keys().size(); ++i) {
if (!list.contains(deviceStatusMap.keys().at(i))) {
qDebug() << "[NetConnect]onDeviceStatusChanged " << deviceStatusMap.keys().at(i) << "was removed";
removeList << deviceStatusMap.keys().at(i);
}
}
//add的设备
for (int i = 0; i< list.size(); ++i) {
if (!deviceStatusMap.keys().contains(list.at(i))) {
qDebug() << "[NetConnect]onDeviceStatusChanged " << list.at(i) << "was add, init status" << map[list.at(i)];
addMap.insert(list.at(i),map[list.at(i)]);
}
}
for (int i = 0; i < removeList.size(); ++i) {
removeDeviceFrame(removeList.at(i));
}
QStringList addList = addMap.keys();
for (int i = 0; i < addList.size(); ++i) {
qDebug() << "add a device " << addList.at(i) << "status" << map[addList.at(i)];
addDeviceFrame(addList.at(i));
initNetListFromDevice(addList.at(i));
}
deviceStatusMap = map;
if (deviceStatusMap.isEmpty()) {
wiredSwitch->setDisabledFlag(true);
wiredSwitch->setChecked(false);
} else {
wiredSwitch->setDisabledFlag(false);
setSwitchStatus();
}
}
#endif
void NetConnect::onDeviceNameChanged(QString oldName, QString newName)
{
if (!deviceFrameMap.contains(oldName) || !deviceStatusMap.contains(oldName)) {
qDebug() << "[NetConnect]onDeviceNameChanged no such device " << oldName;
return;
}
if (deviceFrameMap.contains(newName) && deviceStatusMap.contains(newName)) {
qDebug() << "[NetConnect]onDeviceNameChanged already has device " << newName;
return;
}
qDebug() << "[NetConnect]onDeviceNameChanged " << oldName << "change to" << newName;
//shan chu chong jian
removeDeviceFrame(oldName);
removeDeviceFrame(newName);
getDeviceStatusMap(deviceStatusMap);
addDeviceFrame(newName, manager->getDeviceManaged(newName));
initNetListFromDevice(newName);
}
//lan add===============================================================
void NetConnect::onLanAdd(QString devName, QString connectUuid, QString connectName, QString connectPath)
{
qDebug() << "onLanAdd";
if (!devName.isEmpty() && !deviceStatusMap.contains(devName)) {
return;
}
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (devName.isEmpty()) {
addOneLanFrame(iter.value(), iter.key(), lanInfo);
} else if (devName == iter.key()) {
addOneLanFrame(iter.value(), devName, lanInfo);
break;
}
}
}
//wifi remove =============================================================
void NetConnect::onLanRemove(QString lanPath)
{
qDebug() << "onLanRemove";
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
QMap<QString, LanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->getPath() == lanPath) {
qDebug()<<"[NetConnect]lan remove " << lanPath << " find in " << itemIter.value()->getName();
QString key = itemIter.key();
iter.value()->lanItemLayout->removeWidget(itemIter.value());
delete itemIter.value();
iter.value()->itemMap.remove(key);
break;
}
}
}
}
//增加一项
void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringList infoList)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(infoList.at(1))) {
qDebug() << "[NetConnect]Already exist a lan " << infoList.at(1) << " in " << deviceName;
return;
}
qDebug() << "[NetConnect]addOneLanFrame" << deviceName << infoList.at(0);
QString connName = infoList.at(0);
QString connUuid = infoList.at(1);
QString connDbusPath = infoList.at(2);
LanItem * lanItem = new LanItem(m_isSimpleMode, pluginWidget);
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
lanItem->setItemIcon(searchIcon);
lanItem->setName(connName);
lanItem->setUuid(connUuid);
lanItem->setPath(connDbusPath);
// todo open landetail page
if (!m_isSimpleMode) {
connect(lanItem, &LanItem::infoButtonClick, this, [=]{
});
}
lanItem->setStatus(false);
connect(lanItem, &LanItem::itemClick, this, [=] {
if (lanItem->getStatus() || lanItem->getIsLoading()) {
deActiveConnect(lanItem->getUuid());
} else {
activeConnect(lanItem->getUuid(), deviceName);
}
});
//记录到deviceFrame的itemMap中
deviceFrameMap[deviceName]->itemMap.insert(connUuid, lanItem);
int index = getInsertPos(connName, deviceFrameMap[deviceName]->lanItemLayout);
qDebug()<<"[NetConnect]addOneLanFrame " << connName << " to " << deviceName << " list at pos:" << index;
frame->lanItemLayout->insertWidget(index, lanItem);
}
void NetConnect::removeOneLanFrame(ItemFrame *frame, QString deviceName, QString uuid)
{
if (nullptr == frame) {
return;
}
if (!frame->itemMap.contains(uuid)) {
qDebug() << "[NetConnect]not exist a lan " << uuid << " in " << deviceName;
return;
}
qDebug()<<"[NetConnect]removeOneLanFrame " << uuid << " find in " << deviceName;
frame->lanItemLayout->removeWidget(frame->itemMap[uuid]);
delete frame->itemMap[uuid];
frame->itemMap.remove(uuid);
}
//activeconnect status change
void NetConnect::onActiveConnectionChanged(QString deviceName, QString uuid, KyConnectState status)
{
if (uuid.isEmpty()) {
qDebug() << "[NetConnect]onActiveConnectionChanged but uuid is empty";
return;
}
qDebug() << "[NetConnect]onActiveConnectionChanged " << deviceName << uuid << status;
LanItem * item= nullptr;
if (deviceName.isEmpty()) {
if (status != CONNECT_STATE_DEACTIVATED) {
return;
}
//断开时 设备为空 说明此有线未指定设备 添加到所有列表中
QStringList infoList;
QMap<QString, ItemFrame *>::iterator iters;
for (iters = deviceFrameMap.begin(); iters != deviceFrameMap.end(); iters++) {
if (iters.value()->itemMap.contains(uuid)) {
item = iters.value()->itemMap[uuid];
//为断开则重新插入
deviceFrameMap[iters.key()]->lanItemLayout->removeWidget(item);
int index = getInsertPos(item->getName(), deviceFrameMap[iters.key()]->lanItemLayout);
qDebug() << "[NetConnect]reinsert" << item->getName() << "pos" << index << "in" << iters.key() << "because status changes to deactive";
deviceFrameMap[iters.key()]->lanItemLayout->insertWidget(index,item);
itemActiveConnectionStatusChanged(item, status);
}
}
//添加到所有列表中
if (!infoList.isEmpty()) {
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (!iter.value()->itemMap.contains(uuid)) {
addOneLanFrame(iter.value(), iter.key(), infoList);
}
}
}
} else {
if (deviceFrameMap.contains(deviceName)) {
if (deviceFrameMap[deviceName]->itemMap.contains(uuid)) {
item = deviceFrameMap[deviceName]->itemMap[uuid];
if (status == CONNECT_STATE_ACTIVATED) {
//为已连接则放到第一个
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(0,item);
} else if (status == CONNECT_STATE_DEACTIVATED) {
//为断开则重新插入
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
int index = getInsertPos(item->getName(), deviceFrameMap[deviceName]->lanItemLayout);
qDebug() << "[NetConnect]reinsert" << item->getName() << "pos" << index << "in" << deviceName << "because status changes to deactive";
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(index,item);
}
itemActiveConnectionStatusChanged(item, status);
}
} else {
if (status == CONNECT_STATE_ACTIVATED || status == CONNECT_STATE_DEACTIVATED) {
//虚拟网卡处理
QMap<QString, ItemFrame *>::iterator iters;
for (iters = deviceFrameMap.begin(); iters != deviceFrameMap.end(); iters++) {
if (iters.value()->itemMap.contains(uuid)) {
removeOneLanFrame(iters.value(), iters.key(), uuid);
}
}
}
}
}
}
void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, KyConnectState status)
{
if (status == CONNECT_STATE_ACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_ACTIVATED) {
item->stopLoading();
QIcon searchIcon = QIcon::fromTheme(KLanSymbolic);
item->setItemIcon(searchIcon);
item->setStatus(true);
} else if (status == CONNECT_STATE_DEACTIVATING) {
item->startLoading();
} else {
item->stopLoading();
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
item->setItemIcon(searchIcon);
item->setStatus(false);
}
}
int NetConnect::getInsertPos(QString connName, QVBoxLayout* layout)
{
// qDebug() << "[NetConnect]getInsertPos" << connName << deviceName;
// int index = 0;
// QMap<QString,QList<KyWiredItem>> wiredMap;
// manager->getWiredList(wiredMap);
// if (!wiredMap.contains(deviceName)) {
// return 0;
// }
// QList<KyActivateItem> activateList;
// QString name;
// manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRED, activateList);
// if (activateList.size() != 0) {
// name = activateList.at(0).m_connName;
// }
// bool isFind = false;
// for (;index < wiredMap[deviceName].size(); ++index) {
// if (wiredMap[deviceName].at(index).m_connectName == connName) {
// break;
// } else if (wiredMap[deviceName].at(index).m_connectName == name) {
// isFind = true;
// }
// }
// if (!isFind) {
// index++;
// }
// return index;
int index = 0;
for (; index < layout->count(); ++index)
{
QLayoutItem *it = layout->layout()->itemAt(index);
LanItem *item = qobject_cast<LanItem *>(it->widget());
if (QString::compare(connName, item->getName(), Qt::CaseInsensitive) > 0) {
qDebug() << "compare" << connName << item->getName() << index;
continue;
} else {
if (item->getStatus()) {
continue;
}
break;
}
}
return index;
}
void NetConnect::onDeviceCarrierChange(QString deviceName, bool pluged)
{
}
void NetConnect::onDeviceManagedChange(QString deviceName, bool managed)
{
getDeviceStatusMap(deviceStatusMap);
if (deviceFrameMap.contains(deviceName)) {
if (managed) {
deviceFrameMap[deviceName]->show();
} else {
deviceFrameMap[deviceName]->hide();
}
}
setSwitchStatus();
}
void NetConnect::onWiredEnabledChanged(bool enabled)
{
qDebug() << "[NetConnect] wiredEnabledChanged" <<enabled;
// if (m_wiredSwitch->isChecked() == enabled) {
// qDebug() << "return";
// return;
// }
// setSwitchStatus();
}
void NetConnect::onDeviceAdd(QString deviceName)
{
addDeviceFrame(deviceName, manager->getDeviceManaged(deviceName));
initNetListFromDevice(deviceName);
setSwitchStatus();
}
void NetConnect::onDeviceRemove(QString deviceName)
{
if (!deviceFrameMap.contains(deviceName) || !deviceStatusMap.contains(deviceName)) {
return;
}
removeDeviceFrame(deviceName);
setSwitchStatus();
}

View File

@ -0,0 +1,183 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef NETCONNECT_H
#define NETCONNECT_H
#include "kswitchbutton.h"
#include "kborderlessbutton.h"
using namespace kdk;
#include <QObject>
#include <QtPlugin>
#include <QTranslator>
#include <QApplication>
#include <QTimer>
#include <QStringList>
#include <QString>
#include <QGSettings>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMap>
#include <QPropertyAnimation>
#include <QPoint>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <kylin-nm/kylin-nm-interface.h>
#include <kylin-nm/kylinnetworkmanager.h>
#include "lanitem.h"
#include "../component/DeviceFrame/deviceframe.h"
#include "itemframe.h"
#include "../component/Divider/divider.h"
enum {
DISCONNECTED,
NOINTERNET,
CONNECTED
};
class NetConnect : public Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kylin.network")
Q_INTERFACES(Interface)
public:
NetConnect();
~NetConnect();
QWidget * pluginUi() Q_DECL_OVERRIDE; // 插件主界面---setPluginType后调用
void setPluginType(PluginType type, bool useSwitch = true) Q_DECL_OVERRIDE; // 设置插件类型
void setParentWidget(QWidget*){;}
void setWidgetVisable(bool) {;}
private:
bool m_isSimpleMode = true;
bool m_useSwitch = true;
void initUi();
void initComponent();
void initConnect();
void runExternalApp();
// void showDesktopNotify(const QString &message);
//开关相关
void setSwitchStatus();
void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout);
int getInsertPos(QString connName, QVBoxLayout* layout);
void activeConnect(QString uuid, QString deviceName);
void deActiveConnect(QString uuid);
//获取设备列表
void getDeviceStatusMap(QMap<QString, bool> &map);
void initNet();
void initNetListFromDevice(QString deviceName);
//处理列表增加
void addLanItem(ItemFrame *frame, QString devName, KyWiredItem item);
//增加设备
void addDeviceFrame(QString devName, bool isEnable);
//减少设备
void removeDeviceFrame(QString devName);
//增加一项
void addOneLanFrame(ItemFrame *frame, QString devName, QStringList infoList);
//减少一项
void removeOneLanFrame(ItemFrame *frame, QString deviceName, QString uuid);
//单个lan连接状态变化
void itemActiveConnectionStatusChanged(LanItem *item, KyConnectState status);
protected:
bool eventFilter(QObject *w,QEvent *e);
private:
KyNetworkManager* manager;
QThread* thread;
QWidget* pluginWidget = nullptr;
bool mFirstLoad = true;
QVBoxLayout* m_mainLayout = nullptr;
QFrame* m_titleFrame = nullptr;
QHBoxLayout* m_titleLayout = nullptr;
QLabel* m_titleLabel = nullptr;
KSwitchButton* m_wiredSwitch = nullptr;
Divider* m_titleDivider = nullptr;
QFrame* m_scrollFrame = nullptr;
QVBoxLayout* m_scrollLayout = nullptr;
QScrollArea* m_scrollArea = nullptr;
QWidget* m_listWidget = nullptr;
QVBoxLayout* m_scrollAreaLayout = nullptr;
Divider* m_settingsDivider = nullptr;
QFrame* m_settingsFrame = nullptr;
QHBoxLayout* m_settingsLayout = nullptr;
KBorderlessButton* m_settingsLabel = nullptr;
QGSettings *m_switchGsettings = nullptr;
QMap<QString, bool> deviceStatusMap;
QMap<QString, ItemFrame *> deviceFrameMap;
Q_SIGNALS:
//general
void setWiredEnabled(bool enabled);
//有线无线公用
void deleteConnect(const QString &connectUuid);
void activateConnection(const QString connectUuid, const QString deviceName);
void deactivateConnection(const QString &activeConnectUuid);
//wired 单设备启用禁用
void setWiredDeviceEnable(const QString &interface, bool enable);
void createWiredConnect(KyConnectSetting connectSettingsInfo);
void updateIpv4AndIpv6SettingInfo(const QString &uuid, const KyConnectSetting &connectSettingsInfo);
private Q_SLOTS:
void updateLanInfo(QString deviceName, QString connectUuid, QString connectName, QString connectPath);
void onLanAdd(QString devName, QString connectUuid, QString connectName, QString connectPath);
void onLanRemove(QString dbusPath);
void onActiveConnectionChanged(QString deviceName, QString uuid, KyConnectState status);
// void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString);
void onDeviceCarrierChange(QString deviceName, bool pluged);
void onDeviceManagedChange(QString, bool);
void onWiredEnabledChanged(bool);
void onDeviceAdd(QString deviceName);
void onDeviceRemove(QString deviceName);
};
#endif // NETCONNECT_H

View File

@ -0,0 +1,53 @@
QT += widgets network dbus gui core
TEMPLATE = lib
CONFIG += plugin
include(../component/infobutton.pri)
include(../component/divider.pri)
include(../component/deviceframe.pri)
include(../component/RadioItemButton.pri)
include(../component/fixlabel.pri)
TARGET = $$qtLibraryTarget(netconnect)
DESTDIR = ../..
target.path = /usr/lib/kylin-nm
INCLUDEPATH += \
$$PROJECT_COMPONENTSOURCE \
$$PROJECT_ROOTDIR \
LIBS += -L$$[QT_INSTALL_LIBS] -lkylin-nm-base
CONFIG += c++11 \
link_pkgconfig \
no_keywords
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kylin-nm-base
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
itemframe.cpp \
lanitem.cpp \
netconnect.cpp
HEADERS += \
itemframe.h \
lanitem.h \
netconnect.h
INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
translations/bo.ts \
translations/bo_CN.ts
RESOURCES += \
resource.qrc
DISTFILES += \
translations/bo_CN.ts

View File

@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file>translations/zh_CN.qm</file>
<file>translations/tr.qm</file>
<file>translations/bo.qm</file>
<file>translations/bo_CN.qm</file>
</qresource>
</RCC>

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="76"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="78"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.cpp" line="136"/>
<source>LAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="183"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="76"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="78"/>
<source>Connect</source>
<translation></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.cpp" line="136"/>
<source>LAN</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="183"/>
<source>Settings</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="76"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="78"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.cpp" line="136"/>
<source>LAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="183"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="76"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="78"/>
<source>Connect</source>
<translation></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.cpp" line="136"/>
<source>LAN</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="183"/>
<source>Settings</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
netconnect \
wlanconnect \
# mobilehotspot

View File

@ -0,0 +1,49 @@
#include "deviceframe.h"
#include <QPainter>
#include <QPainterPath>
#define LAYOUT_MARGINS 18,0,8,0
#define FRAME_HEIGHT 58
#define LAYOUT_SPACING 16
#define RADIUS 6.0
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFrameShape(QFrame::Box);
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLayout->setSpacing(LAYOUT_SPACING);
deviceLabel = new QLabel(this);
dropDownLabel = new DrownLabel(devName, this);
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
deviceLayout->addWidget(dropDownLabel);
}
DeviceFrame::~DeviceFrame()
{
}
void DeviceFrame::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect (rect, RADIUS, RADIUS);
QRect temp_rect(rect.left(), rect.top() + rect.height()/2, rect.width(), rect.height()/2);
path.addRect(temp_rect);
painter.drawPath(path);
QFrame::paintEvent(event);
}

View File

@ -0,0 +1,30 @@
#ifndef DEVICEFRAME_H
#define DEVICEFRAME_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#include "../component/DrownLabel/drownlabel.h"
class DeviceFrame : public QFrame
{
public:
DeviceFrame(QString devName, QWidget *parent = nullptr);
~DeviceFrame();
public:
//仅设备名称+下拉label
QLabel * deviceLabel = nullptr;
DrownLabel *dropDownLabel = nullptr;
protected:
void paintEvent(QPaintEvent *event);
private:
int frameSize;
};
#endif // DEVICEFRAME_H

View File

@ -0,0 +1,160 @@
#include "enterprisewlanpage.h"
#include <QPainter>
#define MAIN_SIZE_EXPAND 480,550
#define MAIN_SIZE_NARROW 480,340
#define PAGE_LAYOUT_MARGINS 24,0,24,0
#define TOP_LAYOUT_MARGINS 0,14,0,0
#define BOTTOM_LAYOUT_MARGINS 0,24,0,24
#define LABEL_MIN_WIDTH 150
EnterpriseWlanPage::EnterpriseWlanPage(QString ssid, QString device, bool isLockScreen, QWidget *parent)
: m_ssid(ssid), m_deviceName(device), QWidget(parent)
{
initUI();
initConnections();
setAttribute(Qt::WA_DeleteOnClose);
if (isLockScreen) {
setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口
setWindowFlags(Qt::Popup);
}
centerToScreen();
}
void EnterpriseWlanPage::paintEvent(QPaintEvent *event)
{
QPalette pal = qApp->palette();
QColor colorPal = pal.color(QPalette::Background);
//设置窗体为圆角
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setBrush(colorPal);
painter.setPen(Qt::transparent);
auto rect = this->rect();
painter.drawRoundedRect(rect, 12, 12); //窗口圆角
return QWidget::paintEvent(event);
}
void EnterpriseWlanPage::initUI()
{
m_ssidTitleLabel = new QLabel(this);
m_ssidTitleLabel->setMinimumWidth(LABEL_MIN_WIDTH);
m_ssidLabel = new QLabel(this);
m_entSecurityWidget = new EntSecurityWidget(this);
m_cancelBtn = new QPushButton(this);
m_connectBtn = new QPushButton(this);
m_connectBtn->setEnabled(false);
m_ssidWidget = new QWidget(this);
m_btnWidget = new QWidget(this);
m_mainLayout = new QVBoxLayout(this);
this->setLayout(m_mainLayout);
m_mainLayout->setContentsMargins(PAGE_LAYOUT_MARGINS);
m_mainLayout->setSpacing(0);
m_mainLayout->addWidget(m_ssidWidget);
m_mainLayout->addWidget(m_entSecurityWidget);
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_btnWidget);
QHBoxLayout *ssidLayout = new QHBoxLayout(m_ssidWidget);
ssidLayout->setContentsMargins(TOP_LAYOUT_MARGINS);
ssidLayout->addWidget(m_ssidTitleLabel);
ssidLayout->addWidget(m_ssidLabel);
ssidLayout->addStretch();
QHBoxLayout *btnLayout = new QHBoxLayout(m_btnWidget);
btnLayout->setContentsMargins(BOTTOM_LAYOUT_MARGINS);
btnLayout->setSpacing(16);
btnLayout->addStretch();
btnLayout->addWidget(m_cancelBtn);
btnLayout->addWidget(m_connectBtn);
m_ssidTitleLabel->setText(tr("Network name(SSID)")); //网络名(SSID)
m_ssidLabel->setText(m_ssid);
m_cancelBtn->setText(tr("Cancel"));
m_connectBtn->setText(tr("Connect"));
this->setWindowTitle(tr("Connect Enterprise WLAN"));
this->setWindowIcon(QIcon::fromTheme("kylin-network"));
this->setFixedSize(MAIN_SIZE_EXPAND);
}
void EnterpriseWlanPage::initConnections()
{
connect(m_cancelBtn, &QPushButton::clicked, this, &EnterpriseWlanPage::close);
connect(m_connectBtn, &QPushButton::clicked, this, &EnterpriseWlanPage::onBtnConnectClicked);
connect(m_entSecurityWidget, &EntSecurityWidget::eapTypeChanged, this, &EnterpriseWlanPage::onEapTypeChanged);
connect(m_entSecurityWidget, &EntSecurityWidget::setSecuPageState, this, [ = ](bool status) {
m_connectBtn->setEnabled(status);
});
connect(m_entSecurityWidget, &EntSecurityWidget::setSecuPageState, this, [=](bool status) {
m_connectBtn->setEnabled(status);
});
}
void EnterpriseWlanPage::centerToScreen()
{
QDesktopWidget* m = QApplication::desktop();
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
int desk_x = desk_rect.width();
int desk_y = desk_rect.height();
int x = this->width();
int y = this->height();
this->move((desk_x - x)/ 2 , (desk_y - y)/ 2);
}
void EnterpriseWlanPage::onBtnConnectClicked()
{
KyWirelessConnectSetting connSettingInfo;
//基本信息
connSettingInfo.m_ssid = m_ssid;
connSettingInfo.setConnectName(m_ssid);
connSettingInfo.setIfaceName(m_deviceName);
connSettingInfo.m_isAutoConnect = true;
//ipv4 ipv6
connSettingInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP);
connSettingInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP);
KyEapMethodType eapType;
m_entSecurityWidget->getEnterpriseType(eapType);
if (eapType == PEAP) {
KyEapMethodPeapInfo info = m_entSecurityWidget->assemblePeapInfo();
Q_EMIT connectPeapConnect(info, connSettingInfo);
} else if (eapType = TTLS) {
KyEapMethodTtlsInfo info = m_entSecurityWidget->assembleTtlsInfo();
Q_EMIT connectTtlsConnect(info, connSettingInfo);
} else {
qWarning() << "unsupport now!!!";
}
close();
}
void EnterpriseWlanPage::onEapTypeChanged(const KyEapMethodType &type)
{
switch (type) {
case KyEapMethodType::TLS:
this->setFixedSize(MAIN_SIZE_EXPAND);
centerToScreen();
break;
case KyEapMethodType::PEAP:
this->setFixedSize(MAIN_SIZE_NARROW);
centerToScreen();
break;
case KyEapMethodType::TTLS:
this->setFixedSize(MAIN_SIZE_NARROW);
centerToScreen();
break;
default:
break;
}
}

View File

@ -0,0 +1,50 @@
#ifndef ENTERPRISEWLANPAGE_H
#define ENTERPRISEWLANPAGE_H
#include <QWidget>
#include <QDesktopWidget>
#include <QApplication>
#include <kylin-nm/kylinnetworkmanager.h>
#include "entsecuritywidget.h"
class EnterpriseWlanPage : public QWidget
{
Q_OBJECT
public:
EnterpriseWlanPage(QString ssid, QString device, bool isLockScreen, QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event);
private:
void initUI();
void initConnections();
void centerToScreen();
private:
QString m_deviceName;
QString m_ssid;
QLabel *m_ssidTitleLabel;
QLabel *m_ssidLabel;
EntSecurityWidget *m_entSecurityWidget = nullptr;
QPushButton *m_cancelBtn;
QPushButton *m_connectBtn;
QWidget *m_ssidWidget;
QWidget *m_btnWidget;
QVBoxLayout *m_mainLayout;
private Q_SLOTS:
void onBtnConnectClicked();
void onEapTypeChanged(const KyEapMethodType &type);
Q_SIGNALS:
void connectPeapConnect(KyEapMethodPeapInfo info, KyWirelessConnectSetting connSettingInfo);
void connectTtlsConnect(KyEapMethodTtlsInfo info, KyWirelessConnectSetting connSettingInfo);
};
#endif // ENTERPRISEWLANPAGE_H

View File

@ -0,0 +1,572 @@
#include "entsecuritywidget.h"
#include <QFileDialog>
#define LAYOUT_SPACING 16
#define LABEL_MIN_WIDTH 150
#define HORIZON_SPACING 8
#define ROW_MIN_HEIGHT 36
EntSecurityWidget::EntSecurityWidget(bool isLockScreen, QWidget *parent)
: m_isLockScreen(isLockScreen), QWidget(parent)
{
initUI();
initConnect();
}
EntSecurityWidget::~EntSecurityWidget()
{
// if (m_loginHintDialog != nullptr) {
// delete m_loginHintDialog;
// }
}
void EntSecurityWidget::getEnterpriseType(KyEapMethodType &enterpriseType)
{
enterpriseType = (KyEapMethodType)m_eapTypeCombox->currentData().toInt();
}
void EntSecurityWidget::initUI()
{
//企业wifi共有
m_eapTypeLabel = new QLabel(this);
m_eapTypeCombox = new QComboBox(this);
//TLS
m_identityLable = new QLabel(this);
m_domainLable = new QLabel(this);
m_caCertPathLabel = new QLabel(this);
m_caNeedFlagLabel = new QLabel(this);
m_clientCertPathLabel = new QLabel(this);
m_clientPrivateKeyLabel = new QLabel(this);
m_clientPrivateKeyPwdLabel = new QLabel(this);
m_pwdOptionLabel = new QLabel(this);
//TLS
m_identityEdit = new LineEdit(this);
m_domainEdit = new LineEdit(this);
m_caCertPathCombox = new QComboBox(this);
m_caNeedBox = new QCheckBox(this);
m_clientCertPathCombox = new QComboBox(this);
m_clientPrivateKeyCombox = new QComboBox(this);
m_clientPrivateKeyPwdEdit = new KPasswordEdit(this);
m_pwdOptionCombox = new QComboBox(this);
// m_loginHintDialog = new LogHintDialog(this->parentWidget());
//PEAP TTLS共有
m_eapMethodLabel = new QLabel(this);
m_userNameLabel = new QLabel(this);
m_userPwdLabel = new QLabel(this);
m_eapMethodCombox = new QComboBox(this);
m_userNameEdit = new LineEdit(this);
m_userPwdEdit = new KPasswordEdit(this);
QGridLayout *topLayout = new QGridLayout(this);
topLayout->setContentsMargins(0, 16, 0, 0);
topLayout->setColumnMinimumWidth(0, LABEL_MIN_WIDTH);
topLayout->setVerticalSpacing(LAYOUT_SPACING);
// EAP认证 Label和选项框 第0行第0列第1列
topLayout->addWidget(m_eapTypeLabel, 0, 0);
topLayout->addWidget(m_eapTypeCombox, 0, 1);
//内部认证 Label和选项框 第1行第0列第1列
topLayout->addWidget(m_eapMethodLabel, 1, 0);
topLayout->addWidget(m_eapMethodCombox, 1, 1);
//用户名 Label和输入框 第2行第0列第1列
topLayout->addWidget(m_userNameLabel, 2, 0);
topLayout->addWidget(m_userNameEdit, 2, 1);
//密码 Label和密码框 第3行第0列第1列
topLayout->addWidget(m_userPwdLabel, 3, 0);
topLayout->addWidget(m_userPwdEdit, 3, 1);
// 匿名身份 Label和输入框 第4行第0列第1列
topLayout->addWidget(m_identityLable, 4, 0);
topLayout->addWidget(m_identityEdit, 4, 1);
m_tlsWidget = new QWidget(this);
QGridLayout *bottomLayout = new QGridLayout(m_tlsWidget);
bottomLayout->setContentsMargins(0, 0, 0, 0);
bottomLayout->setColumnMinimumWidth(0, LABEL_MIN_WIDTH);
bottomLayout->setVerticalSpacing(8);
// 域 Label和输入框 第0行第0列第1列
bottomLayout->addWidget(m_domainLable, 0, 0);
bottomLayout->addWidget(m_domainEdit, 0, 1);
// CA证书选项框及CheckBox布局
QWidget *CaWidget = new QWidget(this);
QGridLayout *checkLayout = new QGridLayout(CaWidget);
checkLayout->setContentsMargins(0, 0, 0, 0);
checkLayout->setVerticalSpacing(0);
checkLayout->setColumnMinimumWidth(0, 16);
checkLayout->addWidget(m_caCertPathCombox, 0, 0, 1, 2);
checkLayout->addWidget(m_caNeedBox, 1, 0);
checkLayout->addWidget(m_caNeedFlagLabel, 1, 1);
// CA证书 Label第1行第0列
bottomLayout->addWidget(m_caCertPathLabel, 1, 0);
// CA证书选项框 不需要CA证书复选框 从第6行第1列开始占2行1列
bottomLayout->addWidget(CaWidget, 1, 1, 2, 1);
// 用户证书 Label和选项框 第3行第0列第1列
bottomLayout->addWidget(m_clientCertPathLabel, 3, 0);
bottomLayout->addWidget(m_clientCertPathCombox, 3, 1);
// 用户私钥 Label和选项框 第4行第0列第1列
bottomLayout->addWidget(m_clientPrivateKeyLabel, 4, 0);
bottomLayout->addWidget(m_clientPrivateKeyCombox, 4, 1);
// 私钥密码 Label和密码框 第5行第0列第1列
bottomLayout->addWidget(m_clientPrivateKeyPwdLabel, 5, 0);
bottomLayout->addWidget(m_clientPrivateKeyPwdEdit, 5, 1);
// 密码选项 Label和选项框 第6行第0列第1列
bottomLayout->addWidget(m_pwdOptionLabel, 6, 0);
bottomLayout->addWidget(m_pwdOptionCombox, 6, 1);
topLayout->addWidget(m_tlsWidget, 5, 0, 6,2);
//企业wifi共有
m_eapTypeLabel->setText(tr("EAP type"));
//TLS
m_identityLable->setText(tr("Identity"));
m_domainLable->setText(tr("Domain"));
m_caCertPathLabel->setText(tr("CA certficate"));
m_caNeedFlagLabel->setText(tr("no need for CA certificate"));
m_clientCertPathLabel->setText(tr("User certificate"));
m_clientPrivateKeyLabel->setText(tr("User private key"));
m_clientPrivateKeyPwdLabel->setText(tr("User key password"));
m_pwdOptionLabel->setText(tr("Password options"));
QString hint = tr("Required");
m_identityEdit->setPlaceholderText(tr("Required")); //必填
m_clientPrivateKeyPwdEdit->setPlaceholderText(hint);
//PEAP TTLS共有
m_eapMethodLabel->setText(tr("Ineer authentication"));
m_userNameLabel->setText(tr("Usename"));
m_userPwdLabel->setText(tr("Password"));
m_userNameEdit->setPlaceholderText(tr("Required"));
m_userPwdEdit->setPlaceholderText(hint);
m_eapTypeCombox->addItem("TLS", TLS);
m_eapTypeCombox->addItem("PEAP", PEAP);
m_eapTypeCombox->addItem("TTLS", TTLS);
m_eapTypeCombox->setCurrentIndex(TLS);
//TLS
m_caCertPathCombox->addItem(tr("None"), QString(tr("None"))); //无
if (!m_isLockScreen)
m_caCertPathCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择...
else
m_caCertPathCombox->addItem(tr("Please log in to the system first."), QString(tr("Please log in to the system first.")));
m_clientCertPathCombox->addItem(tr("None"), QString(tr("None"))); //无
if (!m_isLockScreen)
m_clientCertPathCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择...
else
m_clientCertPathCombox->addItem(tr("Please log in to the system first."), QString(tr("Please log in to the system first.")));
m_clientPrivateKeyCombox->addItem(tr("None"), QString(tr("None"))); //无
if (!m_isLockScreen)
m_clientPrivateKeyCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择...
else
m_clientPrivateKeyCombox->addItem(tr("Please log in to the system first."), QString(tr("Please log in to the system first.")));
m_pwdOptionCombox->addItem(tr("Store passwords only for this user"), QString(tr("Store passwords only for this user"))); //仅为该用户存储密码
m_pwdOptionCombox->addItem(tr("Store passwords for all users"), QString(tr("Store passwords for all users"))); //存储所有用户的密码
m_pwdOptionCombox->addItem(tr("Ask this password every time"), QString(tr("Ask this password every time"))); //每次询问这个密码
QRegExp rx("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/]+$");
QRegExpValidator *latitude = new QRegExpValidator(rx, this);
m_clientPrivateKeyPwdEdit->setValidator(latitude);
m_userPwdEdit->setValidator(latitude);
//禁用ClearBtn按钮
m_clientPrivateKeyPwdEdit->setClearButtonEnabled(false);
m_userPwdEdit->setClearButtonEnabled(false);
showTls();
}
void EntSecurityWidget::initConnect()
{
//EAP方式变化
connect(m_eapTypeCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EntSecurityWidget::onEapTypeComboxIndexChanged);
connect(m_caNeedBox, &QCheckBox::clicked, this, &EntSecurityWidget::onCaNeedBoxClicked);
connect(m_caCertPathCombox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &EntSecurityWidget::onCaCertPathComboxIndexChanged);
connect(m_clientCertPathCombox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &EntSecurityWidget::onClientCertPathComboxIndexChanged);
connect(m_clientPrivateKeyCombox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &EntSecurityWidget::onClientPrivateKeyComboxIndexChanged);
connect(m_eapTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn()));
connect(m_identityEdit, &LineEdit::textChanged, this, &EntSecurityWidget::setEnableOfSaveBtn);
connect(m_caCertPathCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(m_caNeedBox, &QCheckBox::stateChanged, this, &EntSecurityWidget::setEnableOfSaveBtn);
connect(m_clientCertPathCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(m_clientPrivateKeyCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn()));
connect(m_clientPrivateKeyPwdEdit, &LineEdit::textChanged, this, &EntSecurityWidget::setEnableOfSaveBtn);
connect(m_eapMethodCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn()));
connect(m_userNameEdit, &LineEdit::textChanged, this, &EntSecurityWidget::setEnableOfSaveBtn);
connect(m_userPwdEdit, &LineEdit::textChanged, this, &EntSecurityWidget::setEnableOfSaveBtn);
// connect(m_loginHintDialog, &LogHintDialog::LogHintDialogClosed, this, &EntSecurityWidget::setComboxIndex);
}
void EntSecurityWidget::showTls()
{
//TLS
m_identityLable->show();
m_identityEdit->show();
m_tlsWidget->show();
//PEAP TTLS共有
m_eapMethodLabel->hide();
m_userNameLabel->hide();
m_userPwdLabel->hide();
m_eapMethodCombox->hide();
m_userNameEdit->hide();
m_userPwdEdit->hide();
}
void EntSecurityWidget::showPeapOrTtls()
{
//TLS
m_identityLable->hide();
m_identityEdit->hide();
m_tlsWidget->hide();
//PEAP TTLS共有
m_eapMethodLabel->show();
m_userNameLabel->show();
m_userPwdLabel->show();
m_eapMethodCombox->show();
m_userNameEdit->show();
m_userPwdEdit->show();
}
bool EntSecurityWidget::checkConnectBtnIsEnabled()
{
int type = m_eapTypeCombox->currentData().toInt();
if (type == TLS) {
return false;
if (m_identityEdit->text().isEmpty()) {
qDebug() << "tls identity is empty";
return false;
}
QFile cafile(m_caCertPathCombox->currentText());
if(!m_caNeedBox->isChecked() && !cafile.exists()) {
qDebug() << "ca cert filepath " << m_caCertPathCombox->currentText() << " is invalid";
return false;
}
QFile cliCafile(m_clientCertPathCombox->currentText());
if(!cliCafile.exists()) {
qDebug() << "client cert filepath " << m_clientCertPathCombox->currentText() << " is invalid";
return false;
}
QFile cliKeyfile(m_clientPrivateKeyCombox->currentText());
if(!cliKeyfile.exists()) {
qDebug() << "client private key filepath " << m_clientPrivateKeyCombox->currentText() << " is invalid";
return false;
}
if(m_clientPrivateKeyPwdEdit->text().isEmpty()) {
qDebug() << "client Private Key password is empty";
return false;
}
} else if (type == PEAP || type == TTLS) {
if(m_userNameEdit->text().isEmpty() || m_userPwdEdit->text().isEmpty()) {
qDebug() << "user name or user password is empty";
return false;
}
}
return true;
}
void EntSecurityWidget::onEapTypeComboxIndexChanged()
{
qDebug() << "onEapTypeComboxIndexChanged";
int index = m_eapTypeCombox->currentData().toInt();
if (index == TLS) {
showTls();
Q_EMIT this->eapTypeChanged(TLS);
} else if (index == PEAP) {
showPeapOrTtls();
m_eapMethodCombox->clear();
m_eapMethodCombox->addItem("MSCHAPv2", MSCHAPV2_PEAP);
m_eapMethodCombox->addItem("MD5", MD5_PEAP);
m_eapMethodCombox->addItem("GTC", GTC_PEAP);
Q_EMIT this->eapTypeChanged(PEAP);
} else if (index == TTLS) {
showPeapOrTtls();
m_eapMethodCombox->clear();
m_eapMethodCombox->addItem("pap", PAP);
m_eapMethodCombox->addItem("mschap", MSCHAP);
m_eapMethodCombox->addItem("mschapv2(eap)", MSCHAPV2_EAP);
m_eapMethodCombox->addItem("mschapv2", MSCHAPV2);
m_eapMethodCombox->addItem("chap", CHAP);
m_eapMethodCombox->addItem("md5(eap)", MD5_EAP);
m_eapMethodCombox->addItem("gtc(eap)", GTC_EAP);
Q_EMIT this->eapTypeChanged(TTLS);
}
}
void EntSecurityWidget::setEnableOfSaveBtn()
{
Q_EMIT setSecuPageState(checkConnectBtnIsEnabled());
}
void EntSecurityWidget::onCaNeedBoxClicked()
{
if (m_caNeedBox->isChecked()) {
m_caCertPathCombox->setItemText(0, tr("None"));
m_caCertPathCombox->setEnabled(false);
} else {
m_caCertPathCombox->setEnabled(true);
}
}
void EntSecurityWidget::onCaCertPathComboxIndexChanged(QString str)
{
if (m_isLockScreen) {
if (m_caCertPathCombox->isEnabled()) {
// m_loginHintDialog->show();
}
} else {
if (str.contains("Choose from file...") || str.contains("从文件选择..."))
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///",
tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)"));
if (!fileName.isNull()) {
QStringList nameList = fileName.split("/");
m_caCertPathCombox->blockSignals(true);
m_caCertPathCombox->setItemText(0, fileName);
m_caCertPathCombox->setCurrentIndex(0);
m_caCertPathCombox->blockSignals(false);
} else {
m_caCertPathCombox->blockSignals(true);
m_caCertPathCombox->setItemText(0, tr("None"));
m_caCertPathCombox->setCurrentIndex(0);
m_caCertPathCombox->blockSignals(false);
}
} else {
qWarning() << "Choose file is null or unvalible";
}
}
}
void EntSecurityWidget::onClientCertPathComboxIndexChanged(QString str)
{
if (m_isLockScreen) {
if (m_clientCertPathCombox->isEnabled()) {
// m_loginHintDialog->show();
}
} else {
if (str.contains("Choose from file...") || str.contains("从文件选择..."))
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///",
tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)"));
if (!fileName.isNull()) {
m_clientCertPathCombox->blockSignals(true);
m_clientCertPathCombox->setItemText(0, fileName);
m_clientCertPathCombox->setCurrentIndex(0);
m_clientCertPathCombox->blockSignals(false);
} else {
m_clientCertPathCombox->blockSignals(true);
m_clientCertPathCombox->setItemText(0, tr("None"));
m_clientCertPathCombox->setCurrentIndex(0);
m_clientCertPathCombox->blockSignals(false);
}
} else {
qWarning() << "Choose file is null or unvalible";
}
}
}
void EntSecurityWidget::onClientPrivateKeyComboxIndexChanged(QString str)
{
if (m_isLockScreen) {
if (m_clientPrivateKeyCombox->isEnabled()) {
// m_loginHintDialog->show();
}
} else {
if (str.contains("Choose from file...") || str.contains("从文件选择..."))
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///",
tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)"));
if (!fileName.isNull()) {
QStringList nameList = fileName.split("/");
m_clientPrivateKeyCombox->blockSignals(true);
m_clientPrivateKeyCombox->setItemText(0, fileName);
m_clientPrivateKeyCombox->setCurrentIndex(0);
m_clientPrivateKeyCombox->blockSignals(false);
} else {
m_clientPrivateKeyCombox->blockSignals(true);
m_clientPrivateKeyCombox->setItemText(0, tr("None"));
m_clientPrivateKeyCombox->setCurrentIndex(0);
m_clientPrivateKeyCombox->blockSignals(false);
}
} else {
qWarning() << "Choose file is null or unvalible";
}
}
}
void EntSecurityWidget::setComboxIndex()
{
if (m_caCertPathCombox->isEnabled()) {
m_caCertPathCombox->setCurrentIndex(0);
}
if (m_clientCertPathCombox->isEnabled()) {
m_clientCertPathCombox->setCurrentIndex(0);
}
if (m_clientPrivateKeyCombox->isEnabled()) {
m_clientPrivateKeyCombox->setCurrentIndex(0);
}
}
KyEapMethodPeapInfo EntSecurityWidget::assemblePeapInfo()
{
KyEapMethodPeapInfo info;
switch (m_eapMethodCombox->currentIndex()) {
case 0:
info.phase2AuthMethod = KyAuthMethodMschapv2;
break;
case 1:
info.phase2AuthMethod = KyAuthMethodMd5;
break;
case 2:
info.phase2AuthMethod = KyAuthMethodGtc;
break;
default:
break;
}
info.userName = m_userNameEdit->text();
info.userPWD = m_userPwdEdit->text();
info.m_passwdFlag = NetworkManager::Setting::None;
// switch (m_pwdOptionCombox->currentIndex()) {
// case 0:
// info.m_passwdFlag = NetworkManager::Setting::AgentOwned;
// info.userPWD = m_userPwdEdit->text();
// break;
// case 1:
// info.m_passwdFlag = NetworkManager::Setting::None;
// info.userPWD = m_userPwdEdit->text();
// break;
// case 2:
// info.m_passwdFlag = NetworkManager::Setting::NotSaved;
// break;
// default:
// break;
// }
return info;
}
KyEapMethodTtlsInfo EntSecurityWidget::assembleTtlsInfo()
{
KyEapMethodTtlsInfo info;
switch (m_eapMethodCombox->currentIndex()) {
case PAP:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodPap;
break;
case MSCHAP:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodChap;
break;
case MSCHAPV2_EAP:
info.authType = AUTH_EAP;
info.authEapMethod = KyAuthEapMethodMschapv2;
break;
case MSCHAPV2:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodMschapv2;
break;
case CHAP:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodChap;
break;
case MD5_EAP:
info.authType = AUTH_EAP;
info.authEapMethod = KyAuthEapMethodMd5;
break;
case GTC_EAP:
info.authType = AUTH_EAP;
info.authEapMethod = KyAuthEapMethodGtc;
break;
default:
break;
}
info.userName = m_userNameEdit->text();
info.m_passwdFlag = NetworkManager::Setting::None;
info.userPWD = m_userPwdEdit->text();
// switch (m_pwdOptionCombox->currentIndex()) {
// case 0:
// info.m_passwdFlag = NetworkManager::Setting::AgentOwned;
// info.userPWD = m_userPwdEdit->text();
// break;
// case 1:
// info.m_passwdFlag = NetworkManager::Setting::None;
// info.userPWD = m_userPwdEdit->text();
// break;
// case 2:
// info.m_passwdFlag = NetworkManager::Setting::NotSaved;
// break;
// default:
// break;
// }
return info;
}
#define ICON_SIZE 16,16
LogHintDialog::LogHintDialog(QWidget *parent) : KDialog(parent)
{
//弹窗 TLS添加本地文件 登录系统提示
m_iconLabel = new QLabel(this);
m_contentLabel = new QLabel(this);
m_confirmBtn = new QPushButton(this);
m_dialogLayout = new QVBoxLayout(this);
m_dialogLayout->setContentsMargins(20, 0, 24, 23);
m_dialogLayout->setSpacing(0);
this->setFixedSize(420, 168);
this->closeButton();
QIcon m_icon = QIcon::fromTheme("dialog-warning");
m_iconLabel->setPixmap(m_icon.pixmap(ICON_SIZE));
m_contentLabel->setText(tr("Please log in to the system first."));
m_confirmBtn->setText(tr("Confirm"));
QWidget *tipWidget = new QWidget(this);
QHBoxLayout *tipLayout = new QHBoxLayout(tipWidget);
tipLayout->addWidget(m_iconLabel);
tipLayout->addWidget(m_contentLabel);
tipLayout->addStretch();
QWidget *btnWidget = new QWidget(this);
QHBoxLayout *btnLayout = new QHBoxLayout(btnWidget);
btnLayout->addStretch();
btnLayout->addWidget(m_confirmBtn);
m_dialogLayout->addWidget(tipWidget);
m_dialogLayout->addStretch();
m_dialogLayout->addWidget(btnWidget);
this->mainWidget()->setLayout(m_dialogLayout);
connect(m_confirmBtn, &QPushButton::clicked, this, [=] {
Q_EMIT LogHintDialogClosed();
close();
});
connect(this->closeButton(), &QPushButton::clicked, this, [=] {
Q_EMIT LogHintDialogClosed();
close();
});
}

View File

@ -0,0 +1,159 @@
#ifndef ENTSECURITYWIDGET_H
#define ENTSECURITYWIDGET_H
#include <QWidget>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
#include <QLineEdit>
#include <QDialog>
//#include "coninfo.h"
#include "kwidget.h"
#include "kpasswordedit.h"
#include "kdialog.h"
#include "kballontip.h"
#include "kylin-nm/depend/kyenterpricesettinginfo.h"
using namespace kdk;
// ------------------------"coninfo.h"------------------------------
enum PeapInnerType
{
MSCHAPV2_PEAP = 0,
MD5_PEAP,
GTC_PEAP,
};
enum TtlsInnerType
{
PAP = 0,
MSCHAP,
MSCHAPV2_EAP,
MSCHAPV2,
CHAP,
MD5_EAP,
GTC_EAP
};
class LineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit LineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {}
~LineEdit() {}
protected:
void contextMenuEvent(QContextMenuEvent *event) {
QMenu *menu = createStandardContextMenu();//默认的标准右键菜单,如果不需要刻意完全自己实现
menu->setPalette(this->palette());
menu->exec(event->globalPos());
delete menu;
}
};
// ------------------------------------------------------
class LogHintDialog : public KDialog
{
Q_OBJECT
public:
LogHintDialog(QWidget *parent = nullptr);
private:
QLabel * m_iconLabel = nullptr;
QLabel * m_contentLabel = nullptr;
QPushButton *m_confirmBtn;
QVBoxLayout *m_dialogLayout;
Q_SIGNALS:
void LogHintDialogClosed();
};
class EntSecurityWidget : public QWidget
{
Q_OBJECT
public:
EntSecurityWidget(bool isLockScreen, QWidget *parent = nullptr);
~EntSecurityWidget();
// void setTlsInfo(KyEapMethodTlsInfo &info);
// void setPeapInfo(KyEapMethodPeapInfo &info);
// void setTtlsInfo(KyEapMethodTtlsInfo &info);
KyEapMethodPeapInfo assemblePeapInfo();
KyEapMethodTtlsInfo assembleTtlsInfo();
void getEnterpriseType(KyEapMethodType &enterpriseType);
private:
void initUI();
void initConnect();
void showTls();
void showPeapOrTtls();
public:
bool checkConnectBtnIsEnabled();
private:
//企业wifi共有
QLabel *m_eapTypeLabel;
QComboBox *m_eapTypeCombox;
//TLS
QLabel *m_identityLable;
QLabel *m_domainLable;
QLabel *m_caCertPathLabel;
QLabel *m_caNeedFlagLabel;
QLabel *m_clientCertPathLabel;
QLabel *m_clientPrivateKeyLabel;
QLabel *m_clientPrivateKeyPwdLabel;
QLabel *m_pwdOptionLabel;
//PEAP TTLS共有
QLabel *m_eapMethodLabel;
QLabel *m_userNameLabel;
QLabel *m_userPwdLabel;
//TLS
LineEdit *m_identityEdit;
LineEdit *m_domainEdit;
QComboBox *m_caCertPathCombox;
QCheckBox *m_caNeedBox;
QComboBox *m_clientCertPathCombox;
QComboBox *m_clientPrivateKeyCombox;
KPasswordEdit *m_clientPrivateKeyPwdEdit = nullptr;
QComboBox *m_pwdOptionCombox;
QWidget *m_tlsWidget;
// LogHintDialog *m_loginHintDialog = nullptr;
bool m_isLockScreen;
//PEAP && TTLS
QComboBox *m_eapMethodCombox;
LineEdit *m_userNameEdit;
KPasswordEdit *m_userPwdEdit = nullptr;
private Q_SLOTS:
void onEapTypeComboxIndexChanged();
void setEnableOfSaveBtn();
void onCaNeedBoxClicked();
void onCaCertPathComboxIndexChanged(QString str);
void onClientCertPathComboxIndexChanged(QString str);
void onClientPrivateKeyComboxIndexChanged(QString str);
void setComboxIndex();
Q_SIGNALS:
void setSecuPageState(bool);
void eapTypeChanged(const KyEapMethodType &type);
};
#endif // ENTSECURITYWIDGET_H

View File

@ -0,0 +1,12 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/enterprisewlanpage.cpp \
$$PWD/entsecuritywidget.cpp \
$$PWD/hiddenwifipage.cpp \
HEADERS += \
$$PWD/enterprisewlanpage.h \
$$PWD/entsecuritywidget.h \
$$PWD/hiddenwifipage.h \

View File

@ -0,0 +1,364 @@
#include "hiddenwifipage.h"
#include <QPainter>
#define WINDOW_WIDTH 480
#define MIN_WINDOW_HEIGHT 328
#define PEAP_WINDOW_HEIGHT 494
#define MAX_WINDOW_HEIGHT 540
#define PAGE_LAYOUT_MARGINS 0,0,0,0
#define TOP_LAYOUT_MARGINS 24,14,24,24
#define BOTTOM_LAYOUT_MARGINS 24,24,24,24
#define LAYOUT_SPACING 16
#define LABEL_MIN_WIDTH 150
#define MAX_NAME_LENGTH 32
#define PSK_SCRO_HEIGHT 182
#define PEAP_SCRO_HEIGHT 348
#define TLS_SCRO_HEIGHT 540
HiddenWiFiPage::HiddenWiFiPage(QString interface, bool isLockScreen, QWidget *parent)
: m_deviceName(interface),
QWidget(parent)
{
initUI();
initComponent();
setFixedWidth(WINDOW_WIDTH);
setAttribute(Qt::WA_DeleteOnClose);
if (isLockScreen) {
setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口
setWindowFlags(Qt::Popup);
}
setJoinBtnEnable();
centerToScreen();
}
HiddenWiFiPage::~HiddenWiFiPage()
{
delete m_bottomDivider;
}
void HiddenWiFiPage::getSecuType(KySecuType &secuType)
{
secuType = (KySecuType)m_secuTypeCombox->currentData().toInt();
}
void HiddenWiFiPage::paintEvent(QPaintEvent *event)
{
QPalette pal = qApp->palette();
QColor colorPal = pal.color(QPalette::Background);
//设置窗体为圆角
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setBrush(colorPal);
painter.setPen(Qt::transparent);
auto rect = this->rect();
painter.drawRoundedRect(rect, 12, 12); //窗口圆角
return QWidget::paintEvent(event);
}
bool HiddenWiFiPage::eventFilter(QObject *w, QEvent *event)
{
return QWidget::eventFilter(w, event);
}
void HiddenWiFiPage::setBtnEnable(bool on)
{
m_cancelBtn->setEnabled(on);
m_joinBtn->setEnabled(on);
}
void HiddenWiFiPage::initUI()
{
m_topWidget = new QWidget(this);
m_centerWidget = new QWidget(this);
m_bottomWidget = new QWidget(this);
m_secuWidget = new EntSecurityWidget(true, this);
m_descriptionLabel = new QLabel(this);
m_nameLabel = new QLabel(this);
m_secuTypeLabel = new QLabel(this);
m_pwdLabel = new QLabel(this);
m_emptyLabel = new QLabel(this);
m_checkLabel = new QLabel(this);
m_nameEdit =new LineEdit(this);
m_secuTypeCombox = new QComboBox(this);
m_pwdEdit = new KPasswordEdit(this);
m_rememberCheckBox = new QCheckBox(this);
m_bottomDivider = new Divider(this);
// m_showListBtn = new KBorderlessButton(this);
m_cancelBtn =new QPushButton(this);
m_joinBtn =new QPushButton(this);
m_scrollArea = new QScrollArea(this);
m_scrollArea->setFrameShape(QFrame::NoFrame);
m_scrollArea->setWidget(m_centerWidget);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// m_scrollArea->setStyleSheet("QWidget{border:1px solid rgba(255,0,0,1);}");//测试用
m_pageLayout = new QVBoxLayout(this);
m_pageLayout->setContentsMargins(PAGE_LAYOUT_MARGINS);
m_pageLayout->setSpacing(0);
m_pageLayout->addWidget(m_topWidget);
m_pageLayout->addWidget(m_scrollArea);
m_pageLayout->addWidget(m_bottomDivider);
m_pageLayout->addWidget(m_bottomWidget);
m_topLayout = new QHBoxLayout(m_topWidget);
m_topLayout->setContentsMargins(TOP_LAYOUT_MARGINS);
m_topLayout->setSpacing(0);
m_topLayout->addWidget(m_descriptionLabel);
m_topLayout->addStretch();
m_centerVBoxLayout = new QVBoxLayout(m_centerWidget);
m_centerVBoxLayout->setContentsMargins(24, 0, 24, 8);
m_centerVBoxLayout->setSpacing(0);
QWidget *centerWidget = new QWidget(this);
QGridLayout *centerLayout = new QGridLayout(centerWidget);
centerLayout->setContentsMargins(PAGE_LAYOUT_MARGINS);
centerLayout->setColumnMinimumWidth(0, LABEL_MIN_WIDTH);
centerLayout->setVerticalSpacing(LAYOUT_SPACING);
//SSID Label和输入框 第0行第0列第1列
centerLayout->addWidget(m_nameLabel, 0, 0);
centerLayout->addWidget(m_nameEdit, 0, 1);
//安全性 Label和选项框 第1行第0列第1列
centerLayout->addWidget(m_secuTypeLabel, 1, 0);
centerLayout->addWidget(m_secuTypeCombox, 1, 1);
//密码 Label和密码框 第2行第0列第1列
centerLayout->addWidget(m_pwdLabel, 2, 0);
centerLayout->addWidget(m_pwdEdit, 2, 1);
//记住该网络复选框
QWidget *checkWidget = new QWidget(this);
QHBoxLayout *checkLayout = new QHBoxLayout(checkWidget);
checkLayout->setContentsMargins(PAGE_LAYOUT_MARGINS);
m_emptyLabel->setMinimumWidth(LABEL_MIN_WIDTH);
m_rememberCheckBox->setChecked(true);
checkLayout->addWidget(m_emptyLabel);
checkLayout->addWidget(m_rememberCheckBox);
checkLayout->addWidget(m_checkLabel);
checkLayout->addStretch();
m_centerVBoxLayout->addWidget(centerWidget);
m_centerVBoxLayout->addWidget(m_secuWidget);
m_centerVBoxLayout->addWidget(checkWidget);
m_centerVBoxLayout->addStretch();
//底部按钮
m_bottomLayout = new QHBoxLayout(m_bottomWidget);
m_bottomLayout->setContentsMargins(BOTTOM_LAYOUT_MARGINS);
m_bottomLayout->setSpacing(LAYOUT_SPACING);
// m_bottomLayout->addWidget(m_showListBtn);
m_bottomLayout->addStretch();
m_bottomLayout->addWidget(m_cancelBtn);
m_bottomLayout->addWidget(m_joinBtn);
m_secuTypeCombox->addItem(tr("None"),NONE);
m_secuTypeCombox->addItem(tr("WPA&WPA2 Personal"),WPA_AND_WPA2_PERSONAL);
m_secuTypeCombox->addItem(tr("WPA&WPA2 Enterprise"), WPA_AND_WPA2_ENTERPRISE);
m_secuTypeCombox->addItem(tr("WPA3 Personal"), WPA3_PERSONAL);
//请输入您想要加入网络的名称和安全类型
m_descriptionLabel->setText(tr("Please enter the network name and security type"));
QFont font = m_descriptionLabel->font();
font.setWeight(75);
m_descriptionLabel->setFont(font);
m_nameLabel->setText(tr("Network name(SSID)")); //网络名(SSID)
m_secuTypeLabel->setText(tr("Security type")); //安全性
m_pwdLabel->setText(tr("Password")); //密码
m_checkLabel->setText(tr("Remember the Network")); //记住该网络
// m_showListBtn->setText(tr("Show Network List")); //显示网络列表
m_cancelBtn->setText(tr("Cancel"));
m_joinBtn->setText(tr("Join"));
m_nameEdit->setMaxLength(MAX_NAME_LENGTH);
m_nameEdit->setPlaceholderText(tr("Required")); //必填
QString hint = tr("Required");
m_pwdEdit->setPlaceholderText(hint);
QRegExp rx("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/]+$");
QRegExpValidator *latitude = new QRegExpValidator(rx, this);
m_pwdEdit->setValidator(latitude);
m_pwdEdit->setClearButtonEnabled(false); //禁用ClearBtn按钮
this->setWindowTitle(tr("Find and Join Wi-Fi"));
this->setWindowIcon(QIcon::fromTheme("kylin-network"));
QPalette pa = m_scrollArea->palette();
pa.setBrush(QPalette::Window, Qt::transparent);
m_scrollArea->setPalette(pa);
showNone();
}
void HiddenWiFiPage::centerToScreen()
{
QDesktopWidget* m = QApplication::desktop();
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
int desk_x = desk_rect.width();
int desk_y = desk_rect.height();
int x = this->width();
int y = this->height();
this->move((desk_x - x)/ 2 , (desk_y - y)/ 2);
}
void HiddenWiFiPage::initComponent()
{
connect(m_cancelBtn, &QPushButton::clicked, this, [=] {
close();
});
connect(m_joinBtn, SIGNAL(clicked()), this, SLOT(on_btnJoin_clicked()));
//安全类型变化
connect(m_secuTypeCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &HiddenWiFiPage::onSecuTypeComboxIndexChanged);
//按钮状态变化
connect(m_nameEdit, &LineEdit::textChanged, this, &HiddenWiFiPage::setJoinBtnEnable);
connect(m_pwdEdit, &LineEdit::textChanged, this, &HiddenWiFiPage::setJoinBtnEnable);
connect(m_secuTypeCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &HiddenWiFiPage::setJoinBtnEnable);
connect(m_secuWidget, &EntSecurityWidget::setSecuPageState, this, [=](bool status) {
m_isSecuOk = status;
setJoinBtnEnable();
});
connect(m_secuWidget, &EntSecurityWidget::eapTypeChanged, this, [=](KyEapMethodType type) {
setWindowWidth(type);
});
}
void HiddenWiFiPage::showNone()
{
this->setFixedHeight(MIN_WINDOW_HEIGHT);
m_centerWidget->setFixedSize(WINDOW_WIDTH, PSK_SCRO_HEIGHT);
m_secuWidget->hide();
m_pwdLabel->hide();
m_pwdEdit->hide();
m_rememberCheckBox->hide();
m_checkLabel->hide();
}
void HiddenWiFiPage::showPsk()
{
this->setFixedHeight(MIN_WINDOW_HEIGHT);
m_centerWidget->setFixedSize(WINDOW_WIDTH, PSK_SCRO_HEIGHT);
m_pwdLabel->show();
m_pwdEdit->show();
m_rememberCheckBox->show();
m_checkLabel->show();
m_secuWidget->hide();
}
void HiddenWiFiPage::showEnt()
{
KyEapMethodType eapType;
m_secuWidget->getEnterpriseType(eapType);
setWindowWidth(eapType);
m_secuWidget->show();
m_rememberCheckBox->show();
m_checkLabel->show();
m_pwdLabel->hide();
m_pwdEdit->hide();
}
void HiddenWiFiPage::setJoinBtnEnable()
{
if (m_nameEdit->text().isEmpty()) {
qDebug() << "network name is empty";
m_isJoinBtnEnable = false;
} else {
int index = m_secuTypeCombox->currentData().toInt();
if (index == NONE) {
if (!m_nameEdit->text().isEmpty()) {
m_isJoinBtnEnable = true;
}
} else if (index == WPA_AND_WPA2_PERSONAL || index == WPA3_PERSONAL) {
if (m_pwdEdit->text().isEmpty() || m_pwdEdit->text().length() < 8 ) {
qDebug() << "password is empty or length < 8";
m_isJoinBtnEnable = false;
} else {
m_isJoinBtnEnable = true;
}
} else if (index == WPA_AND_WPA2_ENTERPRISE) {
m_isJoinBtnEnable = m_isSecuOk;
}
}
qDebug() << "setJoinBtnEnable "<< m_isJoinBtnEnable;
m_joinBtn->setEnabled(m_isJoinBtnEnable);
}
void HiddenWiFiPage::setWindowWidth(KyEapMethodType eapType)
{
int type = eapType;
if (type == TLS) {
this->setFixedHeight(MAX_WINDOW_HEIGHT);
m_centerWidget->setFixedSize(WINDOW_WIDTH, TLS_SCRO_HEIGHT);
} else if (type == PEAP || type == TTLS) {
this->setFixedHeight(PEAP_WINDOW_HEIGHT);
m_centerWidget->setFixedSize(WINDOW_WIDTH, PEAP_SCRO_HEIGHT);
}
}
void HiddenWiFiPage::on_btnJoin_clicked()
{
qDebug() << "on_btnJoin_clicked";
KyWirelessConnectSetting connSettingInfo;
//基本信息
connSettingInfo.m_ssid = m_nameEdit->text();
connSettingInfo.setConnectName(connSettingInfo.m_ssid);
connSettingInfo.setIfaceName(m_deviceName);
connSettingInfo.isHidden = true;
connSettingInfo.m_isAutoConnect = m_rememberCheckBox->isChecked();
connSettingInfo.m_secretFlag = 0;
//ipv4 ipv6
connSettingInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP);
connSettingInfo.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP);
int index = m_secuTypeCombox->currentData().toInt();
if (index == NONE) {
Q_EMIT connectHideNormalConnect(connSettingInfo, NONE);
} else if (index == WPA_AND_WPA2_PERSONAL || index == WPA3_PERSONAL) {
connSettingInfo.m_psk = m_pwdEdit->text();
Q_EMIT connectHideNormalConnect(connSettingInfo, (KySecuType)index);
} else if (index == WPA_AND_WPA2_ENTERPRISE) {
KyEapMethodType eapType;
m_secuWidget->getEnterpriseType(eapType);
if (eapType == PEAP) {
KyEapMethodPeapInfo info = m_secuWidget->assemblePeapInfo();
Q_EMIT connectHidePeapConnect(info, connSettingInfo);
} else if (eapType = TTLS) {
KyEapMethodTtlsInfo info = m_secuWidget->assembleTtlsInfo();
Q_EMIT connectHideTtlsConnect(info, connSettingInfo);
} else {
qWarning() << "unsupport now!!!";
}
}
close();
}
void HiddenWiFiPage::onSecuTypeComboxIndexChanged()
{
int index = m_secuTypeCombox->currentData().toInt();
if (index == WPA_AND_WPA2_PERSONAL || index == WPA3_PERSONAL) {
showPsk();
} else if (index == WPA_AND_WPA2_ENTERPRISE) {
showEnt();
} else if (index == NONE) {
showNone();
}
centerToScreen();
}

View File

@ -0,0 +1,97 @@
#ifndef HIDDENWIFIPAGE_H
#define HIDDENWIFIPAGE_H
#include <QWidget>
#include <QDesktopWidget>
#include <QApplication>
#include <QFormLayout>
#include <QGridLayout>
#include <QLabel>
#include <QComboBox>
#include <QCheckBox>
#include <QPushButton>
#include <QScrollArea>
//#include "coninfo.h"
#include "../component/Divider/divider.h"
#include "kwidget.h"
#include "kpasswordedit.h"
#include "kborderlessbutton.h"
#include "entsecuritywidget.h"
#include "kylin-nm/depend/kywirelessconnectoperation.h"
using namespace kdk;
class HiddenWiFiPage : public QWidget
{
Q_OBJECT
public:
HiddenWiFiPage(QString interface, bool isLockScreen, QWidget *parent = nullptr);
~HiddenWiFiPage();
void getSecuType(KySecuType &secuType);
protected:
void paintEvent(QPaintEvent *event);
bool eventFilter(QObject *w, QEvent *event);
private:
void initUI();
void centerToScreen();
void initComponent();
void showNone();
void showPsk();
void showEnt();
void setBtnEnable(bool on);
void setJoinBtnEnable();
void setWindowWidth(KyEapMethodType eapType);
private:
QWidget *m_topWidget;
QWidget *m_centerWidget;
QWidget *m_bottomWidget;
EntSecurityWidget *m_secuWidget;
QLabel *m_descriptionLabel;
QLabel *m_nameLabel;
QLabel *m_secuTypeLabel;
QLabel *m_pwdLabel;
QLabel *m_emptyLabel;
QLabel *m_checkLabel;
LineEdit *m_nameEdit;
QComboBox *m_secuTypeCombox;
KPasswordEdit *m_pwdEdit = nullptr;
QCheckBox *m_rememberCheckBox = nullptr;
Divider *m_bottomDivider = nullptr;
// KBorderlessButton *m_showListBtn;
QPushButton *m_cancelBtn;
QPushButton *m_joinBtn;
QScrollArea *m_scrollArea;
QVBoxLayout *m_pageLayout;
QHBoxLayout *m_topLayout;
QVBoxLayout *m_centerVBoxLayout;
QHBoxLayout *m_bottomLayout;
bool m_isJoinBtnEnable;
bool m_isSecuOk = false;
QString m_deviceName;
private Q_SLOTS:
void on_btnJoin_clicked();
void onSecuTypeComboxIndexChanged();
Q_SIGNALS:
void connectHidePeapConnect(KyEapMethodPeapInfo info, KyWirelessConnectSetting connSettingInfo);
void connectHideTtlsConnect(KyEapMethodTtlsInfo info, KyWirelessConnectSetting connSettingInfo);
void connectHideNormalConnect(KyWirelessConnectSetting connSettingInfo, KySecuType type);
};
#endif // HIDDENWIFIPAGE_H

View File

@ -0,0 +1,107 @@
#include "itemframe.h"
#include <QPainter>
#include <QPainterPath>
#define LAYOUT_MARGINS 2,0,12,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
#define RADIUS 6.0
AddNetItem::AddNetItem(QWidget *parent) : QFrame(parent)
{
this->setFixedSize(404, 48);
QHBoxLayout *m_mainLayout = new QHBoxLayout(this);
m_mainLayout->setContentsMargins(0,0,0,0);
titleLabel = new QLabel(this);
titleLabel->setText(tr("Add Others..."));
m_mainLayout->addSpacing(16);
m_mainLayout->addWidget(titleLabel);
m_mainLayout->addStretch();
this->setLayout(m_mainLayout);
}
void AddNetItem::mouseReleaseEvent(QMouseEvent *event)
{
Q_EMIT itemClick();
return QFrame::mouseReleaseEvent(event);
}
void AddNetItem::enterEvent(QEvent *event)
{
m_isIn = true;
update();
return QFrame::enterEvent(event);
}
void AddNetItem::leaveEvent(QEvent *event)
{
m_isIn = false;
update();
return QFrame::leaveEvent(event);
}
void AddNetItem::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
if (m_isIn) {
QColor color(240, 240, 240);
color.setAlphaF(0.39);
painter.setBrush(color);
}
else
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect(rect, RADIUS, RADIUS);
painter.drawPath(path);
return QFrame::paintEvent(event);
}
ItemFrame::ItemFrame(QString devName, QWidget *parent) : QFrame(parent)
{
deviceLanLayout = new QVBoxLayout(this);
deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
lanItemFrame = new QFrame(this);
lanItemFrame->setFrameShape(QFrame::Shape::NoFrame);
lanItemFrame->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout = new QVBoxLayout(this);
lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout->setSpacing(0);
deviceLanLayout->setSpacing(0);
setLayout(deviceLanLayout);
lanItemFrame->setLayout(lanItemLayout);
deviceFrame = new DeviceFrame(devName, this);
m_divider = new Divider(this);
addNetItem = new AddNetItem(this);
deviceLanLayout->addWidget(m_divider);
deviceLanLayout->addWidget(deviceFrame);
deviceLanLayout->addWidget(lanItemFrame);
deviceLanLayout->addWidget(addNetItem);
connect(addNetItem, &AddNetItem::itemClick, this, &ItemFrame::addNetItemClick);
}
void ItemFrame::showJoinPage(QWidget *widget)
{
if (nullptr != joinPage) {
joinPage->show();
} else {
joinPage = new HiddenWiFiPage(deviceFrame->deviceLabel->text(), true, widget);
connect(joinPage, &HiddenWiFiPage::destroyed, [=](){
joinPage->disconnect(this);
joinPage = nullptr;
});
connect(joinPage, &HiddenWiFiPage::connectHideNormalConnect, this, &ItemFrame::connectHideNormalConnect);
connect(joinPage, &HiddenWiFiPage::connectHideTtlsConnect, this, &ItemFrame::connectHideTtlsConnect);
connect(joinPage, &HiddenWiFiPage::connectHidePeapConnect, this, &ItemFrame::connectHidePeapConnect);
joinPage->show();
}
}

View File

@ -0,0 +1,64 @@
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include <QFrame>
#include <QVBoxLayout>
#include "wlanitem.h"
#include "../component/DeviceFrame/deviceframe.h"
#include "../component/Divider/divider.h"
#include "hiddenwifi/hiddenwifipage.h"
class AddNetItem : public QFrame
{
Q_OBJECT
public:
AddNetItem(QWidget *parent = nullptr);
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
QLabel* titleLabel = nullptr;
bool m_isIn = false;
Q_SIGNALS:
void itemClick();
};
class ItemFrame : public QFrame
{
Q_OBJECT
public:
ItemFrame(QString devName, QWidget *parent = nullptr);
//单设备整体layout
QVBoxLayout * deviceLanLayout = nullptr;
//单设备名称+下拉按钮Frame
Divider * m_divider;
DeviceFrame * deviceFrame = nullptr;
//单设备列表Frame
QFrame * lanItemFrame = nullptr;
//单设备列表layout
QVBoxLayout * lanItemLayout = nullptr;
//单设备item列表
QMap<QString, WlanItem *> itemMap;
//加入其他网络
AddNetItem * addNetItem = nullptr;
//已激活uuid
QString uuid = "";
public Q_SLOTS:
void showJoinPage(QWidget *);
private:
HiddenWiFiPage* joinPage = nullptr;
Q_SIGNALS:
void addNetItemClick();
void connectHidePeapConnect(KyEapMethodPeapInfo info, KyWirelessConnectSetting connSettingInfo);
void connectHideTtlsConnect(KyEapMethodTtlsInfo info, KyWirelessConnectSetting connSettingInfo);
void connectHideNormalConnect(KyWirelessConnectSetting connSettingInfo, KySecuType type);
};
#endif // ITEMFRAME_H

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>translations/wlan_zh_CN.qm</file>
<file>translations/wlan_bo_CN.qm</file>
</qresource>
</RCC>

View File

@ -0,0 +1,273 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>AddNetItem</name>
<message>
<location filename="../itemframe.cpp" line="15"/>
<source>Add Others...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntSecurityWidget</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="125"/>
<source>EAP type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="127"/>
<source>Identity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="128"/>
<source>Domain</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="129"/>
<source>CA certficate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="130"/>
<source>no need for CA certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="131"/>
<source>User certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="132"/>
<source>User private key</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="133"/>
<source>User key password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="134"/>
<source>Password options</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="136"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="137"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="145"/>
<source>Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="141"/>
<source>Ineer authentication</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="142"/>
<source>Usename</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="143"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="154"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="160"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="166"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="326"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="352"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="380"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="409"/>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="156"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="162"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="168"/>
<source>Choose from file...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="158"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="164"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="170"/>
<source>Please log in to the system first.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="172"/>
<source>Store passwords only for this user</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="173"/>
<source>Store passwords for all users</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="174"/>
<source>Ask this password every time</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="342"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="371"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="399"/>
<source>Choose a CA certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="343"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="372"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="400"/>
<source>CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EnterpriseWlanPage</name>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="78"/>
<source>Network name(SSID)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="80"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="81"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="83"/>
<source>Connect Enterprise WLAN</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>HiddenWiFiPage</name>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="162"/>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="163"/>
<source>WPA&amp;WPA2 Personal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="164"/>
<source>WPA&amp;WPA2 Enterprise</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="165"/>
<source>WPA3 Personal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="168"/>
<source>Please enter the network name and security type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="172"/>
<source>Network name(SSID)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="173"/>
<source>Security type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="174"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="175"/>
<source>Remember the Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="177"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="178"/>
<source>Join</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="181"/>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="182"/>
<source>Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="190"/>
<source>Find and Join Wi-Fi</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>LogHintDialog</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="543"/>
<source>Please log in to the system first.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="544"/>
<source>Confirm</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.cpp" line="186"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="234"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>WlanItem</name>
<message>
<location filename="../wlanitem.cpp" line="75"/>
<location filename="../wlanitem.cpp" line="173"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="95"/>
<source>Auto Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="171"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,273 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="bo_CN">
<context>
<name>AddNetItem</name>
<message>
<location filename="../itemframe.cpp" line="15"/>
<source>Add Others...</source>
<translation>...</translation>
</message>
</context>
<context>
<name>EntSecurityWidget</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="125"/>
<source>EAP type</source>
<translation>EAP </translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="127"/>
<source>Identity</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="128"/>
<source>Domain</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="129"/>
<source>CA certficate</source>
<translation>CA certficate</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="130"/>
<source>no need for CA certificate</source>
<translation>CAཡི</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="131"/>
<source>User certificate</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="132"/>
<source>User private key</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="133"/>
<source>User key password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="134"/>
<source>Password options</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="136"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="137"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="145"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="141"/>
<source>Ineer authentication</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="142"/>
<source>Usename</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="143"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="154"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="160"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="166"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="326"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="352"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="380"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="409"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="156"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="162"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="168"/>
<source>Choose from file...</source>
<translation>...</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="158"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="164"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="170"/>
<source>Please log in to the system first.</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="172"/>
<source>Store passwords only for this user</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="173"/>
<source>Store passwords for all users</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="174"/>
<source>Ask this password every time</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="342"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="371"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="399"/>
<source>Choose a CA certificate</source>
<translation>CAཡི</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="343"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="372"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="400"/>
<source>CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)</source>
<translation>CA (*.pem *.der *.p12 *.crt *.cer *.pfx)</translation>
</message>
</context>
<context>
<name>EnterpriseWlanPage</name>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="78"/>
<source>Network name(SSID)</source>
<translation> (SSID)</translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="80"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="81"/>
<source>Connect</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="83"/>
<source>Connect Enterprise WLAN</source>
<translation>WLANས </translation>
</message>
</context>
<context>
<name>HiddenWiFiPage</name>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="162"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="163"/>
<source>WPA&amp;WPA2 Personal</source>
<translation>WPA&amp;WPA2མི</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="164"/>
<source>WPA&amp;WPA2 Enterprise</source>
<translation>WPA&amp;WPA2 </translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="165"/>
<source>WPA3 Personal</source>
<translation>WPA3མི</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="168"/>
<source>Please enter the network name and security type</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="172"/>
<source>Network name(SSID)</source>
<translation> (SSID)</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="173"/>
<source>Security type</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="174"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="175"/>
<source>Remember the Network</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="177"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="178"/>
<source>Join</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="181"/>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="182"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="190"/>
<source>Find and Join Wi-Fi</source>
<translation>WI-FIལ</translation>
</message>
</context>
<context>
<name>LogHintDialog</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="543"/>
<source>Please log in to the system first.</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="544"/>
<source>Confirm</source>
<translation></translation>
</message>
</context>
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.cpp" line="186"/>
<source>WLAN</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="234"/>
<source>Settings</source>
<translation></translation>
</message>
</context>
<context>
<name>WlanItem</name>
<message>
<location filename="../wlanitem.cpp" line="75"/>
<location filename="../wlanitem.cpp" line="173"/>
<source>Connect</source>
<translation></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="95"/>
<source>Auto Connect</source>
<translation></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="171"/>
<source>Disconnect</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,273 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>AddNetItem</name>
<message>
<location filename="../itemframe.cpp" line="15"/>
<source>Add Others...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntSecurityWidget</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="125"/>
<source>EAP type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="127"/>
<source>Identity</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="128"/>
<source>Domain</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="129"/>
<source>CA certficate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="130"/>
<source>no need for CA certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="131"/>
<source>User certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="132"/>
<source>User private key</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="133"/>
<source>User key password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="134"/>
<source>Password options</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="136"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="137"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="145"/>
<source>Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="141"/>
<source>Ineer authentication</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="142"/>
<source>Usename</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="143"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="154"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="160"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="166"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="326"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="352"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="380"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="409"/>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="156"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="162"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="168"/>
<source>Choose from file...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="158"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="164"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="170"/>
<source>Please log in to the system first.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="172"/>
<source>Store passwords only for this user</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="173"/>
<source>Store passwords for all users</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="174"/>
<source>Ask this password every time</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="342"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="371"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="399"/>
<source>Choose a CA certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="343"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="372"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="400"/>
<source>CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EnterpriseWlanPage</name>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="78"/>
<source>Network name(SSID)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="80"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="81"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="83"/>
<source>Connect Enterprise WLAN</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>HiddenWiFiPage</name>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="162"/>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="163"/>
<source>WPA&amp;WPA2 Personal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="164"/>
<source>WPA&amp;WPA2 Enterprise</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="165"/>
<source>WPA3 Personal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="168"/>
<source>Please enter the network name and security type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="172"/>
<source>Network name(SSID)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="173"/>
<source>Security type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="174"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="175"/>
<source>Remember the Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="177"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="178"/>
<source>Join</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="181"/>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="182"/>
<source>Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="190"/>
<source>Find and Join Wi-Fi</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>LogHintDialog</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="543"/>
<source>Please log in to the system first.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="544"/>
<source>Confirm</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.cpp" line="186"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="234"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>WlanItem</name>
<message>
<location filename="../wlanitem.cpp" line="75"/>
<location filename="../wlanitem.cpp" line="173"/>
<source>Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="95"/>
<source>Auto Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="171"/>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,277 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>AddNetItem</name>
<message>
<location filename="../itemframe.cpp" line="15"/>
<source>Add Others...</source>
<translation>...</translation>
</message>
</context>
<context>
<name>EntSecurityWidget</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="125"/>
<source>EAP type</source>
<translation>EAP认证</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="127"/>
<source>Identity</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="128"/>
<source>Domain</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="129"/>
<source>CA certficate</source>
<translation>CA证书</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="130"/>
<source>no need for CA certificate</source>
<translation>CA证书</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="131"/>
<source>User certificate</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="132"/>
<source>User private key</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="133"/>
<source>User key password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="134"/>
<source>Password options</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="136"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="137"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="145"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="141"/>
<source>Ineer authentication</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="142"/>
<source>Usename</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="143"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="154"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="160"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="166"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="326"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="352"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="380"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="409"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="156"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="162"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="168"/>
<source>Choose from file...</source>
<translation>...</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="158"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="164"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="170"/>
<source>Please log in to the system first.</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="172"/>
<source>Store passwords only for this user</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="173"/>
<source>Store passwords for all users</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="174"/>
<source>Ask this password every time</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="342"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="371"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="399"/>
<source>Choose a CA certificate</source>
<translation>CA证书</translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="343"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="372"/>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="400"/>
<source>CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)</source>
<translation>CA (*.pem *.der *.p12 *.crt *.cer *.pfx)</translation>
</message>
</context>
<context>
<name>EnterpriseWlanPage</name>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="78"/>
<source>Network name(SSID)</source>
<translation>SSID</translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="80"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="81"/>
<source>Connect</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/enterprisewlanpage.cpp" line="83"/>
<source>Connect Enterprise WLAN</source>
<translation></translation>
</message>
</context>
<context>
<name>HiddenWiFiPage</name>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="162"/>
<source>None</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="163"/>
<source>WPA&amp;WPA2 Personal</source>
<translation>WPA&amp;WPA2个人</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="164"/>
<source>WPA&amp;WPA2 Enterprise</source>
<translation>WPA&amp;WPA2企业</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="165"/>
<source>WPA3 Personal</source>
<translation>WPA3个人</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="168"/>
<source>Please enter the network name and security type</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="172"/>
<source>Network name(SSID)</source>
<translation>SSID</translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="173"/>
<source>Security type</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="174"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="175"/>
<source>Remember the Network</source>
<translation></translation>
</message>
<message>
<source>Show Network List</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="177"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="178"/>
<source>Join</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="181"/>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="182"/>
<source>Required</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/hiddenwifipage.cpp" line="190"/>
<source>Find and Join Wi-Fi</source>
<translation>Wi-Fi</translation>
</message>
</context>
<context>
<name>LogHintDialog</name>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="543"/>
<source>Please log in to the system first.</source>
<translation></translation>
</message>
<message>
<location filename="../hiddenwifi/entsecuritywidget.cpp" line="544"/>
<source>Confirm</source>
<translation></translation>
</message>
</context>
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.cpp" line="186"/>
<source>WLAN</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="234"/>
<source>Settings</source>
<translation></translation>
</message>
</context>
<context>
<name>WlanItem</name>
<message>
<location filename="../wlanitem.cpp" line="75"/>
<location filename="../wlanitem.cpp" line="173"/>
<source>Connect</source>
<translation></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="95"/>
<source>Auto Connect</source>
<translation></translation>
</message>
<message>
<location filename="../wlanitem.cpp" line="171"/>
<source>Disconnect</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,993 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "wlanconnect.h"
#include <QGSettings>
#include <QProcess>
#include <QTimer>
#include <QtDBus>
#include <QDir>
#include <QDebug>
#include <QtAlgorithms>
#define SCANTIMER 20 * 1000
#define UPDATETIMER 10 * 1000
#define SPACING 8
const QString KWifiSymbolic = "network-wireless-signal-excellent";
const QString KWifiLockSymbolic = "network-wireless-secure-signal-excellent";
const QString KWifiGood = "network-wireless-signal-good";
const QString KWifiLockGood = "network-wireless-secure-signal-good";
const QString KWifiOK = "network-wireless-signal-ok";
const QString KWifiLockOK = "network-wireless-secure-signal-ok";
const QString KWifiLow = "network-wireless-signal-low";
const QString KWifiLockLow = "network-wireless-secure-signal-low";
const QString KWifiNone = "network-wireless-signal-none";
const QString KWifiLockNone = "network-wireless-secure-signal-none";
const QString KApSymbolic = "network-wireless-hotspot-symbolic";
const QString IsApConnection = "1";
#define NO_MARGINS 0,0,0,0
#define TOP_MARGINS 0,8,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0
#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙和设计稿看起来一致就不能设为设计稿里的高度
#define TITLE_LAYOUT_MARGINS 24,0,24,0
bool intThan(int sign1, int sign2)
{
return sign1 < sign2;
}
//void WlanConnect::showDesktopNotify(const QString &message)
//{
// QDBusInterface iface("org.freedesktop.Notifications",
// "/org/freedesktop/Notifications",
// "org.freedesktop.Notifications",
// QDBusConnection::sessionBus());
// QList<QVariant> args;
// args<<(tr("ukui control center"))
// <<((unsigned int) 0)
// <<QString("/usr/share/icons/ukui-icon-theme-default/24x24/devices/gnome-dev-ethernet.png")
// <<tr("ukui control center desktop message") //显示的是什么类型的信息
// <<message //显示的具体信息
// <<QStringList()
// <<QVariantMap()
// <<(int)-1;
// iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
//}
WlanConnect::WlanConnect() : m_firstLoad(true)
{
//dbus类型注册
qRegisterMetaType<KyWirelessConnectSetting>("KyWirelessConnectSetting");
qRegisterMetaType<KySecuType>("KySecuType");
qRegisterMetaType<QList<KyActivateItem>>("QList<KyActivateItem>");
qRegisterMetaType<QList<KyWirelessNetItem>>("QList<KyWirelessNetItem>");
qRegisterMetaType<KyEapMethodPeapInfo>("KyEapMethodPeapInfo");
qRegisterMetaType<KyEapMethodTtlsInfo>("KyEapMethodTtlsInfo");
QLocale local;
QString locale = local.name();
QTranslator* translator = new QTranslator(this);
if (translator->load(":/translations/wlan_"+ locale + ".qm")) {
QApplication::installTranslator(translator);
} else {
qWarning() << "Translations load fail";
}
}
WlanConnect::~WlanConnect()
{
qDebug() << "~WlanConnect 1";
//启动keyring进程
QDBusInterface interface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if (interface.isValid()) {
interface.call("keyRingInit");
}
thread->quit();
thread->wait();
delete thread;
if (pluginWidget != nullptr) {
delete pluginWidget;
}
qDebug() << "~WlanConnect 2";
}
QWidget *WlanConnect::pluginUi() {
if (m_firstLoad) {
m_firstLoad = false;
//停止keyring进程
QDBusInterface interface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if (interface.isValid()) {
interface.call("keyRingClear");
}
KylinAgent* agent = new KylinAgent(this);
agent->setParentWidget(parentWidget);
agent->startKylinAgent();
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
pluginWidget->setFixedSize(420, 436);
initUi();
initComponent();
initConnect();
}
return pluginWidget;
}
void WlanConnect::setParentWidget(QWidget* widget){
if (parentWidget != nullptr) {
return;
}
parentWidget = widget;
}
void WlanConnect::setWidgetVisable(bool visable) {
if (pluginWidget == nullptr) {
return;
}
if (deviceFrameMap.isEmpty()) {
return;
}
if (visable) {
return;
}
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
QMap<QString, WlanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
itemIter.value()->setExpend(false);
}
}
}
void WlanConnect::setPluginType(PluginType type, bool useSwitch)
{
Q_UNUSED(useSwitch)
if (type == SIMPLE) {
m_isSimpleMode = true;
} else {
m_isSimpleMode = false;
}
}
void WlanConnect::initUi()
{
pluginWidget->setFixedSize(420,436);
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
connect(thread, &QThread::started, manager, &KyNetworkManager::kylinNetworkManagerInit);
connect(thread, &QThread::finished, manager, &KyNetworkManager::deleteLater);
connect(thread, &QThread::finished, [=](){
qDebug() << "WlanConnect thread quit";
});
thread->start();
while (!manager->isInitFinished()) {
::usleep(1000);
}
m_mainLayout = new QVBoxLayout(pluginWidget);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
pluginWidget->setLayout(m_mainLayout);
m_titleFrame = new QFrame(pluginWidget);
m_titleFrame->setFixedHeight(53);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("WLAN"));
m_wirelessSwitch = new KSwitchButton(pluginWidget);
m_wirelessSwitch->installEventFilter(this);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
m_titleLayout->addWidget(m_wirelessSwitch);
m_titleDivider = new Divider(pluginWidget);
m_titleDivider->hide();
m_scrollFrame = new QFrame(pluginWidget);
if (m_isSimpleMode) {
m_scrollFrame->setFixedHeight(383);
} else {
m_scrollFrame->setFixedHeight(330);
}
m_scrollLayout = new QVBoxLayout(m_scrollFrame);
m_scrollLayout->setContentsMargins(0,0,0,0);
m_scrollLayout->setSpacing(0);
m_scrollFrame->setLayout(m_scrollLayout);
m_scrollArea = new QScrollArea(m_scrollFrame);
m_scrollArea->setFrameShape(QFrame::Shape::NoFrame);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setBackgroundRole(QPalette::Base);
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scrollArea->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_scrollLayout->addWidget(m_scrollArea);
m_listWidget = new QWidget(pluginWidget);
m_listWidget->setFixedWidth(420);
m_scrollAreaLayout = new QVBoxLayout(m_listWidget);
m_scrollAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_scrollAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_scrollAreaLayout->setAlignment(Qt::AlignTop);
m_listWidget->setLayout(m_scrollAreaLayout);
m_scrollArea->setWidget(m_listWidget);
m_settingsDivider = new Divider(pluginWidget);
m_settingsFrame = new QFrame(pluginWidget);
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_settingsLabel = new KBorderlessButton(m_settingsFrame);
m_settingsLabel->setCursor(Qt::PointingHandCursor);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsLayout->addStretch();
m_settingsFrame->setLayout(m_settingsLayout);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_scrollFrame);
if (!m_isSimpleMode) {
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_settingsDivider);
m_mainLayout->addWidget(m_settingsFrame);
} else {
m_settingsDivider->hide();
m_settingsFrame->hide();
}
QPalette pal = m_scrollArea->palette();
pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
m_scrollArea->setPalette(pal);
}
bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w == m_wirelessSwitch && e->type() == QEvent::MouseButtonRelease) {
if (!m_wirelessSwitch->isCheckable()) {
// showDesktopNotify(tr("No wireless device avaliable"));
} else {
Q_EMIT setWirelessNetworkEnabled(!m_wirelessSwitch->isChecked());
}
return true;
}
return QObject::eventFilter(w,e);
}
void WlanConnect::initComponent() {
m_wirelessSwitch->blockSignals(true);
m_wirelessSwitch->setChecked(manager->getWirelessEnabled());
m_wirelessSwitch->blockSignals(false);
getDeviceList(deviceList);
if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
m_wirelessSwitch->setChecked(false);
m_wirelessSwitch->setCheckable(false);
qDebug() << "m_wirelessSwitch setCheckable setChecked" << false;
}
initNet();
if (!m_wirelessSwitch->isChecked() || deviceList.isEmpty()) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
}
connect(m_settingsLabel, &KBorderlessButton::clicked, this, [=]() {
runExternalApp();
});
}
void WlanConnect::initConnect()
{
connect(manager, &KyNetworkManager::wirelessStateChange, this, &WlanConnect::onActiveConnectionChanged);
connect(manager, &KyNetworkManager::deviceStateChange, this, &WlanConnect::onDeviceStatusChanged);
connect(manager, &KyNetworkManager::wifiEnabledChanged, this, &WlanConnect::onWifiEnabledChanged);
connect(manager, &KyNetworkManager::secuTypeChange, this, &WlanConnect::onNetworkSecuTypeChange);
connect(manager, &KyNetworkManager::wirelessConnectionRemove, this, &WlanConnect::onWirelessConnectionRemove);
connect(manager, &KyNetworkManager::wirelessConnectionAdd, this, &WlanConnect::onWirelessConnectionAdd);
connect(manager, &KyNetworkManager::wirelessConnectionUpdate, this, &WlanConnect::onWirelessConnectionUpdate);
connect(manager, &KyNetworkManager::wirelessDeviceAdd, this, &WlanConnect::onWirelessDeviceAdd);
connect(manager, &KyNetworkManager::deviceRemove, this, &WlanConnect::onWirelessDeviceRemove);
connect(manager, &KyNetworkManager::wirelessDeviceNameUpdate, this, &WlanConnect::onDeviceNameChanged);
connect(manager, &KyNetworkManager::wifiNetworkAdd, this, &WlanConnect::onNetworkAdd);
connect(manager, &KyNetworkManager::wifiNetworkRemove, this, &WlanConnect::onNetworkRemove);
connect(manager, &KyNetworkManager::wifiNetworkUpdate, this, &WlanConnect::onNetworkUpdate);
connect(manager, &KyNetworkManager::updateWifiList, this, &WlanConnect::updateList);
connect(this, &WlanConnect::requestWirelessScan, manager, &KyNetworkManager::onRequestWirelessScan);
connect(this, &WlanConnect::activateConnection, manager, &KyNetworkManager::onActivateConnection);
connect(this, &WlanConnect::deactivateConnection, manager, &KyNetworkManager::onDeactivateConnection);
connect(this,&WlanConnect::addAndActivateNormalWifi, manager, &KyNetworkManager::onAddAndActivateNormalWifi);
connect(this, &WlanConnect::setWirelessNetworkEnabled, manager, &KyNetworkManager::onSetWirelessNetworkEnabled);
connect(this, &WlanConnect::deleteConnect, manager, &KyNetworkManager::onDeleteConnect);
//定时20s扫描
m_scanTimer = new QTimer(this);
m_scanTimer->start(SCANTIMER);
connect(m_scanTimer, &QTimer::timeout, this, &WlanConnect::reScan);
//10s重新排序
// m_updateTimer = new QTimer(this);
// m_updateTimer->start(UPDATETIMER);
// connect(m_updateTimer, &QTimer::timeout, this, &WlanConnect::updateList);
reScan();
}
void WlanConnect::reScan()
{
Q_EMIT requestWirelessScan();
}
//更新列表顺序 ->从so中重新拿 然后插+更新icon
void WlanConnect::updateList(QString devName, QList<KyActivateItem> connectItemList, QList<KyWirelessNetItem> list)
{
if (!m_wirelessSwitch->isChecked()) {
return;
}
if (!deviceFrameMap.keys().contains(devName)) {
return;
}
resortWifiList(deviceFrameMap[devName], connectItemList, list);
}
void WlanConnect::resortWifiList(ItemFrame *frame, QList<KyActivateItem> connectItemList, QList<KyWirelessNetItem> list)
{
qDebug() << "resortWifiList" << frame->deviceFrame->deviceLabel->text();
if(nullptr == frame || frame->lanItemLayout->count() <= 0) {
return;
}
int frameIndex = 0;
QString activateSsid = "";
for (int i = 0; i < connectItemList.size(); ++i) {
if (connectItemList.at(i).m_connStatus == CONNECT_STATE_ACTIVATED) {
activateSsid = connectItemList.at(i).m_ssid;
for (int i = 0; i < list.size(); ++i) {
if (list.at(i).m_NetSsid == activateSsid) {
updateIcon(frame->itemMap[list.at(i).m_NetSsid],
list.at(i).m_signalStrength,
list.at(i).m_secuType,
list.at(i).m_isApConnection);
break;
}
}
frameIndex++;
qDebug() << "resortWifiList no" << frameIndex << activateSsid << list.at(i).m_signalStrength;
break;
}
}
for (int listIndex = 0; listIndex < list.size(); ++listIndex) {
if (frameIndex > frame->lanItemLayout->count() - 1) {
return;
}
if (frame->itemMap.contains(list.at(listIndex).m_NetSsid) && list.at(listIndex).m_NetSsid != activateSsid) {
frame->lanItemLayout->removeWidget(frame->itemMap[list.at(listIndex).m_NetSsid]);
frame->lanItemLayout->insertWidget(frameIndex, frame->itemMap[list.at(listIndex).m_NetSsid]);
if (!frame->itemMap[list.at(listIndex).m_NetSsid]->getIsLoading()) {
updateIcon(frame->itemMap[list.at(listIndex).m_NetSsid],
list.at(listIndex).m_signalStrength,
list.at(listIndex).m_secuType,
list.at(listIndex).m_isApConnection);
}
frameIndex++;
qDebug() << "resortWifiList no" << frameIndex << list.at(listIndex).m_NetSsid << list.at(listIndex).m_signalStrength;
} else {
qDebug() << "not find " << list.at(listIndex).m_NetSsid << " in current list, ignore";
}
}
qDebug() << "resort finish";
}
void WlanConnect::updateIcon(WlanItem *item, int signalStrength, QString security, bool isApConnection)
{
qDebug() << "updateIcon" << item->getName();
int sign = setSignal(signalStrength);
bool isLock = true;
if (security.isEmpty()) {
isLock = false;
} else {
isLock = true;
}
QString iconamePath;
if (isApConnection) {
iconamePath = KApSymbolic;
} else {
iconamePath = wifiIcon(isLock, sign);
}
QIcon searchIcon = QIcon::fromTheme(iconamePath);
item->setItemIcon(searchIcon);
qDebug() << "updateIcon" << item->getName() << " finish";
}
//device status change
void WlanConnect::onDeviceStatusChanged()
{
}
void WlanConnect::onDeviceNameChanged(QString oldName, QString newName)
{
qDebug() << "============onDeviceNameChanged" << oldName << newName;
if (!deviceFrameMap.contains(oldName) || !deviceList.contains(oldName)) {
qWarning() << "[WlanConnect]onDeviceNameChanged no such device " << oldName;
return;
}
if (deviceFrameMap.contains(newName) && deviceList.contains(newName)) {
qWarning() << "[WlanConnect]onDeviceNameChanged already has device " << newName;
return;
}
removeDeviceFrame(oldName);
getDeviceList(deviceList);
if (deviceList.contains(newName)) {
addDeviceFrame(newName);
initNetListFromDevice(newName);
setSwitchStatus(manager->getWirelessEnabled());
}
}
//activeconnect status change
void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, KyConnectState status)
{
qDebug() << "onActiveConnectionChanged" << ssid << status;
if (!m_wirelessSwitch->isChecked()) {
return;
}
if (uuid.isEmpty()) {
return;
}
WlanItem * item= nullptr;
//device ssid 有可能均为空
if (deviceName.isEmpty() || ssid.isEmpty()) {
if (status == CONNECT_STATE_ACTIVATING || status == CONNECT_STATE_ACTIVATED) {
return;
}
QMap<QString, ItemFrame*>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (uuid == iter.value()->uuid) {
QMap<QString, WlanItem*>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->getUuid() == uuid ) {
item = itemIter.value();
break;
}
}
break;
}
}
} else {
if (!deviceFrameMap.contains(deviceName)) {
return;
}
for (int i = 0; i < deviceFrameMap[deviceName]->itemMap.size(); ++i) {
if (deviceFrameMap[deviceName]->itemMap.contains(ssid)) {
item = deviceFrameMap[deviceName]->itemMap[ssid];
if (status == CONNECT_STATE_ACTIVATED || status == CONNECT_STATE_ACTIVATING) {
deviceFrameMap[deviceName]->itemMap[ssid]->setUuid(uuid);
deviceFrameMap[deviceName]->uuid = uuid;
if (status == CONNECT_STATE_ACTIVATED) {
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(0,item);
}
} else if (status == CONNECT_STATE_DEACTIVATED) {
deviceFrameMap[deviceName]->uuid.clear();
}
break;
}
}
}
if (nullptr != item) {
itemActiveConnectionStatusChanged(item, status);
if (status == CONNECT_STATE_ACTIVATED ||
status == CONNECT_STATE_DEACTIVATED) {
QList<KyWirelessNetItem> list;
manager->getWifiNetworkList(deviceName, list);
for (int i = 0; i < list.size(); ++i) {
if (list.at(i).m_NetSsid == ssid) {
updateIcon(item,list.at(i).m_signalStrength,list.at(i).m_secuType,list.at(i).m_isApConnection);
break;
}
}
}
}
}
//wifi add==============================================================
void WlanConnect::onNetworkAdd(QString deviceName, KyWirelessNetItem wlanInfo)
{
qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo.m_NetSsid;
if(!m_wirelessSwitch->isChecked() || deviceName.isEmpty()) {
return;
}
if (!deviceList.contains(deviceName)) {
qDebug() << "[WlanConnect]onNetworkAdd not contain " << deviceName << "then add";
deviceList.append(deviceName);
addDeviceFrame(deviceName);
onNetworkAdd(deviceName, wlanInfo);
return;
}
insertOneWlanFrame(deviceFrameMap[deviceName], deviceName, wlanInfo);
}
//wifi remove =============================================================
void WlanConnect::onNetworkRemove(QString deviceName, QString wlannName)
{
//当前无此设备 忽略
if (deviceName.isEmpty() || !deviceFrameMap.contains(deviceName)) {
qWarning() << "[WlanConnect]recieve network remove,but no such device:" << deviceName;
return;
}
qDebug()<<"[WlanConnect]Wifi remove device:" << deviceName << ",wlan name:" << wlannName;
removeOneWlanFrame(deviceFrameMap[deviceName], deviceName, wlannName);
}
//wifi secu Update =============================================================
void WlanConnect::onNetworkUpdate(QString deviceName, QString wlannName, KyWirelessNetItem item)
{
//当前无此设备 忽略
if (deviceName.isEmpty() || !deviceFrameMap.contains(deviceName)) {
qWarning() << "[WlanConnect]recieve network update,but no such device:" << deviceName;
return;
}
qDebug()<<"[WlanConnect]Wifi update device:" << deviceName << ",wlan name:" << wlannName;
bool isFind = false;
QMap<QString, WlanItem*>::iterator itemIter;
for (itemIter = deviceFrameMap[deviceName]->itemMap.begin(); itemIter != deviceFrameMap[deviceName]->itemMap.end(); ++itemIter) {
if (itemIter.value()->getName() == wlannName) {
itemIter.value()->setSecuType(item.m_secuType);
isFind = true;
break;
}
}
if (!isFind) {
insertOneWlanFrame(deviceFrameMap[deviceName], deviceName, item);
}
}
//获取设备列表=======================================================
void WlanConnect::getDeviceList(QStringList &list)
{
manager->getNetworkDeviceList(DEVICE_TYPE_WIFI, list);
}
//设置开关
void WlanConnect::setSwitchStatus(bool status)
{
m_wirelessSwitch->setCheckable(true);
m_wirelessSwitch->blockSignals(true);
m_wirelessSwitch->setChecked(status);
m_wirelessSwitch->blockSignals(false);
if (!status) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
} else {
showLayout(m_scrollAreaLayout);
m_titleDivider->hide();
}
}
//初始化整体列表和单设备列表
void WlanConnect::initNet() {
//先构建每个设备的列表头
qDebug() << deviceList <<deviceList.size();
for (int i = 0; i < deviceList.size(); ++i) {
addDeviceFrame(deviceList.at(i));
}
//再填充每个设备的列表
for (int i = 0; i < deviceList.size(); ++i) {
initNetListFromDevice(deviceList.at(i));
}
}
//初始化设备列表
void WlanConnect::initNetListFromDevice(QString deviceName)
{
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName;
if (!m_wirelessSwitch->isChecked()) {
qWarning() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off";
return;
}
if (!deviceFrameMap.contains(deviceName)) {
qWarning() << "[WlanConnect]initNetListFromDevice " << deviceName << " not exist";
return;
}
QList<KyWirelessNetItem> list;
manager->getWifiNetworkList(deviceName, list);
for (int i = 0; i < list.size(); ++i) {
KyWirelessNetItem item = list.at(i);
addOneWlanFrame(deviceFrameMap[deviceName], deviceName, item);
}
QList<KyActivateItem> activateList;
manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRELESS, activateList);
if (activateList.size() != 0) {
onActiveConnectionChanged(deviceName,activateList.at(0).m_ssid, activateList.at(0).m_uuid, activateList.at(0).m_connStatus);
}
}
//高级设置
void WlanConnect::runExternalApp() {
QProcess process;
process.startDetached("ukui-control-center -m wlanconnect");
}
//根据信号强度分级+安全性分图标
QString WlanConnect::wifiIcon(bool isLock, int strength) {
switch (strength) {
case 1:
return isLock ? KWifiLockSymbolic : KWifiSymbolic;
case 2:
return isLock ? KWifiLockGood : KWifiGood;
case 3:
return isLock ? KWifiLockOK : KWifiOK;
case 4:
return isLock ? KWifiLockLow : KWifiLow;
case 5:
return isLock ? KWifiLockNone : KWifiNone;
default:
return "";
}
}
//根据信号强度分级
int WlanConnect::setSignal(int signal) {
int signalLv = 0;
if (signal > 75) {
signalLv = 1;
} else if (signal > 55 && signal <= 75) {
signalLv = 2;
} else if (signal > 35 && signal <= 55) {
signalLv = 3;
} else if (signal > 15 && signal <= 35) {
signalLv = 4;
} else if (signal <= 15) {
signalLv = 5;
}
return signalLv;
}
//隐藏
void WlanConnect::hideLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i) {
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->hide();
}
}
//显示
void WlanConnect::showLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i) {
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->show();
}
}
//增加设备
void WlanConnect::addDeviceFrame(QString devName)
{
qDebug() << "[WlanConnect]addDeviceFrame " << devName;
ItemFrame *itemFrame = new ItemFrame(devName, pluginWidget);
m_scrollAreaLayout->addWidget(itemFrame);
itemFrame->deviceFrame->deviceLabel->setText(devName);
deviceFrameMap.insert(devName, itemFrame);
if (deviceList.indexOf(devName) < 0) {
deviceList << devName;
}
connect(itemFrame, &ItemFrame::addNetItemClick , [=](){
//加入网络
itemFrame->showJoinPage(parentWidget);
});
connect(itemFrame, &ItemFrame::connectHideNormalConnect, manager, &KyNetworkManager::onAddAndActivateNormalWifi);
connect(itemFrame, &ItemFrame::connectHideTtlsConnect, manager, &KyNetworkManager::onAddAndActiveWirelessEnterPriseTtlsConnect);
connect(itemFrame, &ItemFrame::connectHidePeapConnect, manager, &KyNetworkManager::onAddAndActiveWirelessEnterPrisePeapConnect);
}
//减少设备
void WlanConnect::removeDeviceFrame(QString devName)
{
qDebug() << "[WlanConnect]removeDeviceFrame " << devName;
if (deviceFrameMap.contains(devName)) {
ItemFrame *item = deviceFrameMap[devName];
if (item->lanItemFrame->layout() != NULL) {
QLayoutItem* layoutItem;
while ((layoutItem = item->lanItemFrame->layout()->takeAt(0)) != NULL) {
delete layoutItem->widget();
delete layoutItem;
}
item->itemMap.clear();
}
delete item;
item = nullptr;
item->disconnect(this);
deviceFrameMap.remove(devName);
}
// getDeviceList(deviceList);
deviceList.removeOne(devName);
}
//增加ap
void WlanConnect::addOneWlanFrame(ItemFrame *frame, QString deviceName, KyWirelessNetItem &wlanInfo)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(wlanInfo.m_NetSsid)) {
qDebug() << "[WlanConnect]Already exist a wifi " << wlanInfo.m_NetSsid << " in " << deviceName;
return;
}
//设置单项的信息
int sign = setSignal(wlanInfo.m_signalStrength);
WlanItem * wlanItem = new WlanItem(m_isSimpleMode, pluginWidget);
QString iconamePath;
if (wlanInfo.m_isApConnection) {
iconamePath = KApSymbolic;
} else {
iconamePath = wifiIcon(!wlanInfo.m_secuType.isEmpty(), sign);
}
QIcon searchIcon = QIcon::fromTheme(iconamePath);
wlanItem->setItemIcon(searchIcon);
wlanItem->setName(wlanInfo.m_NetSsid);
wlanItem->setSecuType(wlanInfo.m_secuType);
wlanItem->setUuid(wlanInfo.m_connectUuid);
wlanItem->setPath(wlanInfo.m_dbusPath);
wlanItem->setInterface(deviceName);
connect(wlanItem, &WlanItem::infoButtonClick, this, [=]{
//todo 详情页
});
connect(wlanItem, &WlanItem::itemClick, this, [=] {
if (wlanItem->getStatus() || wlanItem->getIsLoading()) {
Q_EMIT deactivateConnection(wlanItem->getUuid());
} else {
if (wlanItem->getExpend()) {
wlanItem->setExpend(false);
} else {
//先看加密类型 再看是否已有配置
if (!wlanItem->getUuid().isEmpty()) {
activateConnection(wlanItem->getUuid(), wlanItem->getInterface());
} else {
if (wlanItem->getSecuType().isEmpty()) {
KyWirelessConnectSetting sett;
KySecuType secuType = KySecuType::NONE;
sett.m_ssid = wlanItem->getName();
sett.m_ifaceName = wlanItem->getInterface();
Q_EMIT addAndActivateNormalWifi(sett, secuType);
} else {
if (wlanItem->getSecuType().indexOf("802.1X") != -1) {
//todo 企业网页面
wlanItem->showEnterPricePage(deviceName, parentWidget);
} else {
wlanItem->setExpend(true);
setOtherItemExpandedFalse(deviceName, wlanInfo.m_NetSsid);
}
}
}
}
}
});
connect(wlanItem, &WlanItem::connectButtonClick, this, [=](QString password, bool isAutoConnect) {
KySecuType secuType;
if (wlanItem->getSecuType().indexOf("WPA3")) {
secuType = KySecuType::WPA3_PERSONAL;
} else {
secuType = KySecuType::WPA_AND_WPA2_PERSONAL;
}
KyWirelessConnectSetting sett;
sett.m_ssid = wlanItem->getName();
sett.m_psk = password;
sett.m_isAutoConnect = isAutoConnect;
sett.m_ifaceName = wlanItem->getInterface();
Q_EMIT addAndActivateNormalWifi(sett, secuType);
wlanItem->setExpend(false);
});
connect(wlanItem, &WlanItem::connectPeapConnect, manager, &KyNetworkManager::onAddAndActiveWirelessEnterPrisePeapConnect);
connect(wlanItem, &WlanItem::connectTtlsConnect, manager, &KyNetworkManager::onAddAndActiveWirelessEnterPriseTtlsConnect);
connect(wlanItem, &WlanItem::passwordFocusIn, this, &WlanConnect::needShowVirtualKeyboard);
//记录到deviceFrame的itemMap中
deviceFrameMap[deviceName]->itemMap.insert(wlanInfo.m_NetSsid, wlanItem);
qDebug()<<"add " << wlanInfo.m_NetSsid << " to " << deviceName << " list";
frame->lanItemLayout->addWidget(wlanItem);
}
//减少ap
void WlanConnect::removeOneWlanFrame(ItemFrame *frame, QString deviceName, QString ssid)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(ssid)) {
qDebug() << "[WlanConnect]removeOneWlanFrame " << deviceName << ssid;
frame->lanItemLayout->removeWidget(frame->itemMap[ssid]);
delete frame->itemMap[ssid];
frame->itemMap.remove(ssid);
}
}
void WlanConnect::insertOneWlanFrame(ItemFrame *frame, QString devName, KyWirelessNetItem &wlanInfo)
{
addOneWlanFrame(frame, devName, wlanInfo);
}
void WlanConnect::itemActiveConnectionStatusChanged(WlanItem *item, int status)
{
if (status == CONNECT_STATE_ACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_ACTIVATED) {
item->stopLoading();
item->setStatus(true);
} else if (status == CONNECT_STATE_DEACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_DEACTIVATED) {
item->stopLoading();
item->setStatus(false);
}
}
void WlanConnect::onNetworkSecuTypeChange(QString deviceName, QString ssid, QString securityType)
{
Q_UNUSED(deviceName)
Q_UNUSED(ssid)
Q_UNUSED(securityType)
}
void WlanConnect::onWifiEnabledChanged(bool status)
{
// if (m_wirelessSwitch->isCheckable()) {
setSwitchStatus(status);
// }
}
void WlanConnect::onWirelessConnectionRemove(QString deviceName, QString ssid)
{
qDebug() << "onWirelessConnectionRemove" << deviceName << ssid;
WlanItem *item = findItem(deviceName,ssid);
if (nullptr == item) {
return;
}
if (item->getStatus()) {
onActiveConnectionChanged(deviceName, ssid, item->getUuid(), CONNECT_STATE_DEACTIVATED);
}
item->setUuid("");
item->setPath("");
}
void WlanConnect::onWirelessConnectionAdd(QString deviceName, QString ssid, QString uuid, QString dbusPath)
{
qDebug() << "onWirelessConnectionAdd" << deviceName << ssid;
WlanItem *item = findItem(deviceName,ssid);
if (nullptr == item) {
return;
}
if (!item->getUuid().isEmpty()
&& !item->getPath().isEmpty())
item->setUuid(uuid);
item->setPath(dbusPath);
}
void WlanConnect::onWirelessConnectionUpdate(QString deviceName, QString ssid, QString uuid, QString dbusPath, KySecuType connectSecuType)
{
}
void WlanConnect::onWirelessDeviceAdd(QString deviceName)
{
addDeviceFrame(deviceName);
setSwitchStatus(manager->getWirelessEnabled());
}
void WlanConnect::onWirelessDeviceRemove(QString deviceName)
{
if (!deviceFrameMap.contains(deviceName) || deviceList.indexOf(deviceName) < 0) {
return;
}
removeDeviceFrame(deviceName);
if (deviceList.isEmpty()) {
setSwitchStatus(false);
m_wirelessSwitch->setCheckable(false);
}
}
WlanItem* WlanConnect::findItem(QString devName, QString ssid)
{
if (!deviceFrameMap.contains(devName)) {
return nullptr;
}
if (!deviceFrameMap[devName]->itemMap.contains(ssid)) {
return nullptr;
}
return deviceFrameMap[devName]->itemMap[ssid];
}
void WlanConnect::setOtherItemExpandedFalse(QString devName, QString ssid)
{
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (iter.key() != devName) {
QMap<QString, WlanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
itemIter.value()->setExpend(false);
}
} else {
QMap<QString, WlanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->getName() != ssid) {
itemIter.value()->setExpend(false);
}
}
}
}
}

View File

@ -0,0 +1,197 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef WLANCONNECT_H
#define WLANCONNECT_H
#include "kswitchbutton.h"
#include "kborderlessbutton.h"
using namespace kdk;
#include <QObject>
#include <QtPlugin>
#include <QNetworkInterface>
#include <QtNetwork/QNetworkConfigurationManager>
#include <QtNetwork/QtNetwork>
#include <QTimer>
#include <QStringList>
#include <QString>
#include <QGSettings>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMap>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <kylin-nm/kylin-nm-interface.h>
#include <kylin-nm/kylinnetworkmanager.h>
#include <kylin-nm/kylin-agent/kylinagent.h>
#include "../component/DeviceFrame/deviceframe.h"
#include "itemframe.h"
#include "wlanitem.h"
#include "hiddenwifi/enterprisewlanpage.h"
class WlanConnect : public Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kylin.network")
Q_INTERFACES(Interface)
public:
WlanConnect();
~WlanConnect();
QWidget * pluginUi() Q_DECL_OVERRIDE; // 插件主界面---setPluginType后调用
void setPluginType(PluginType type, bool useSwitch = true) Q_DECL_OVERRIDE; // 设置插件类型
void setParentWidget(QWidget*);
void setWidgetVisable(bool);
private:
bool m_isSimpleMode = true;
void initUi();
void initComponent();
void initConnect();
void runExternalApp();
void initSearchText();
// void showDesktopNotify(const QString &message);
void updateIcon(WlanItem *item, int signalStrength, QString security, bool isApConnection);
void resortWifiList(ItemFrame *frame, QList<KyActivateItem> connectItemList, QList<KyWirelessNetItem> list);
//单wifi图标
int setSignal(int lv);
QString wifiIcon(bool isLock, int strength);
//开关相关
void setSwitchStatus(bool status);
void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout);
//获取设备列表
void getDeviceList(QStringList &list);
//初始化设备wifi列表
void initNet();
void initNetListFromDevice(QString deviceName);
//增加设备
void addDeviceFrame(QString devName);
//减少设备
void removeDeviceFrame(QString devName);
//无序增加ap
void addOneWlanFrame(ItemFrame *frame, QString deviceName, KyWirelessNetItem &wlanInfo);
//减少ap
void removeOneWlanFrame(ItemFrame *frame, QString deviceName, QString ssid);
//有序增加ap
void insertOneWlanFrame(ItemFrame *frame, QString devName, KyWirelessNetItem &wlanInfo);
//单个wifi连接状态变化
void itemActiveConnectionStatusChanged(WlanItem *item, int status);
void setOtherItemExpandedFalse(QString devName, QString ssid);
protected:
bool eventFilter(QObject *w,QEvent *e);
private:
KyNetworkManager* manager;
QThread* thread;
QWidget* parentWidget = nullptr;
QWidget* pluginWidget = nullptr;
//设备列表
QStringList deviceList;
//设备名 + 单设备frame
QMap<QString, ItemFrame *> deviceFrameMap;
QTimer * m_scanTimer = nullptr;
QTimer * m_updateTimer = nullptr;
bool m_firstLoad = true;
QVBoxLayout* m_mainLayout = nullptr;
QFrame* m_titleFrame = nullptr;
QHBoxLayout* m_titleLayout = nullptr;
QLabel* m_titleLabel = nullptr;
KSwitchButton* m_wirelessSwitch = nullptr;
Divider* m_titleDivider = nullptr;
QFrame* m_scrollFrame = nullptr;
QVBoxLayout* m_scrollLayout = nullptr;
QScrollArea* m_scrollArea = nullptr;
QWidget* m_listWidget = nullptr;
QVBoxLayout* m_scrollAreaLayout = nullptr;
Divider* m_settingsDivider = nullptr;
QFrame* m_settingsFrame = nullptr;
QHBoxLayout* m_settingsLayout = nullptr;
KBorderlessButton* m_settingsLabel = nullptr;
WlanItem* findItem(QString devName, QString ssid);
Q_SIGNALS:
void requestWirelessScan();
void setWirelessNetworkEnabled(bool enabled);
//=======================连接/断开操作====================
void activateConnection(const QString connectUuid, const QString deviceName);
void deactivateConnection(const QString &activeConnectUuid);
//连接无本地配置的非企业网热点
void addAndActivateNormalWifi(KyWirelessConnectSetting connSettingInfo, KySecuType type);
// //连接无本地配置的企业网热点
// void addAndActiveWirelessEnterPriseTlsConnect(KyEapMethodTlsInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
// void addAndActiveWirelessEnterPrisePeapConnect(KyEapMethodPeapInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
// void addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
void deleteConnect(QString uuid);
private Q_SLOTS:
void onNetworkAdd(QString deviceName, KyWirelessNetItem wlanInfo);
void onNetworkRemove(QString deviceName, QString wlannName);
void onNetworkUpdate(QString deviceName, QString wlannName, KyWirelessNetItem secuType);
void onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, KyConnectState status);
void updateList(QString devName, QList<KyActivateItem> connectItemList, QList<KyWirelessNetItem> list);
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString);
void reScan();
void onNetworkSecuTypeChange(QString deviceName, QString ssid, QString securityType);
void onWifiEnabledChanged(bool);
void onWirelessConnectionRemove(QString deviceName, QString ssid);
void onWirelessConnectionAdd(QString deviceName, QString ssid, QString uuid, QString dbusPath);
void onWirelessConnectionUpdate(QString deviceName, QString ssid, QString uuid, QString dbusPath, KySecuType connectSecuType);
void onWirelessDeviceAdd(QString deviceName);
void onWirelessDeviceRemove(QString deviceName);
};
#endif // WLANCONNECT_H

View File

@ -0,0 +1,55 @@
QT += widgets network dbus gui core
TEMPLATE = lib
CONFIG += plugin
include(../component/infobutton.pri)
include(../component/divider.pri)
include(../component/deviceframe.pri)
include(../component/RadioItemButton.pri)
include(../component/fixlabel.pri)
include(hiddenwifi/hiddenwifi.pri)
TARGET = $$qtLibraryTarget(wlanconnect)
DESTDIR = ../..
target.path = /usr/lib/kylin-nm
INCLUDEPATH += \
$$PROJECT_COMPONENTSOURCE \
$$PROJECT_ROOTDIR \
LIBS += -L$$[QT_INSTALL_LIBS] -lkylin-nm-base -lkylin-keyring
CONFIG += c++11 \
link_pkgconfig \
no_keywords
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kylin-nm-base \
libsecret-1
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
itemframe.cpp \
wlanconnect.cpp \
wlanitem.cpp
HEADERS += \
itemframe.h \
wlanconnect.h \
wlanitem.h
INSTALLS += target \
TRANSLATIONS += \
translations/wlan_zh_CN.ts \
translations/wlan_tr.ts \
translations/wlan_bo.ts \
translations/wlan_bo_CN.ts
RESOURCES += \
resource.qrc
DISTFILES += \
translations/wlan_bo_CN.ts

View File

@ -0,0 +1,278 @@
#include "wlanitem.h"
#include <QPainter>
#include <QRegExpValidator>
#include <QPainterPath>
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
#define RADIUS 6.0
#define UNEXPEND_HEIGHT 48
#define EXPEND_HEIGHT 120
#define ENABLE_BUTTON_COLOR qApp->palette().highlight().color()
#define UNABLE_BUTTON_COLOR qApp->palette().button().color()
WlanItem::WlanItem(bool isSimple, QWidget *parent)
: isSimple(isSimple), QFrame(parent)
{
this->setFixedSize(404, UNEXPEND_HEIGHT);
QVBoxLayout *m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(16,0,0,0);
m_mainLayout->setSpacing(0);
//icon + name
m_nameFrame = new QFrame(this);
QHBoxLayout *lanLyt = new QHBoxLayout(m_nameFrame);
lanLyt->setContentsMargins(0,8,16,4);
lanLyt->setSpacing(0);
radioBtn = new RadioItemButton(this);
titileLabel = new FixLabel(this);
titileLabel->setMinimumWidth(282);;
lanLyt->addWidget(radioBtn);
lanLyt->addSpacing(10);
lanLyt->addWidget(titileLabel,Qt::AlignLeft);
lanLyt->addStretch();
if (!isSimple) {
infoLabel = new InfoButton(this);
lanLyt->addSpacing(8);
lanLyt->addWidget(infoLabel);
connect(infoLabel, &InfoButton::released, this, &WlanItem::infoButtonClick);
}
m_expendFrame = new QFrame(this);
QVBoxLayout *expendnLyt = new QVBoxLayout(m_expendFrame);
expendnLyt->setContentsMargins(40, 0, 16, 0);
expendnLyt->setSpacing(0);
//pwdline + connect Button
m_pwdFrame = new QFrame(m_expendFrame);
m_pwdFrameLyt = new QHBoxLayout(m_pwdFrame);
m_pwdFrameLyt->setContentsMargins(0,0,0,0);
m_pwdFrameLyt->setSpacing(0);
m_pwdFrame->setLayout(m_pwdFrameLyt);
m_pwdLineEdit = new KPasswordEdit(m_pwdFrame);
m_pwdLineEdit->setState(Ordinary);
// m_pwdLineEdit->setEchoModeBtnVisible(true);
m_pwdLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
QRegExp rx("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/]+$");
QRegExpValidator *latitude = new QRegExpValidator(rx, this);
m_pwdLineEdit->setValidator(latitude);
m_pwdLineEdit->installEventFilter(this);
connect(m_pwdLineEdit, &KPasswordEdit::textChanged, this, &WlanItem::onPwdEditorTextChanged);
m_pwdLineEdit->setFixedSize(228, 36);
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
m_pwdFrameLyt->addWidget(m_pwdLineEdit);
m_pwdFrameLyt->addSpacing(8);
m_connectButton = new QPushButton(m_pwdFrame);
m_connectButton->setFixedSize(96, 36);
m_connectButton->setText(tr("Connect"));
m_connectButton->setEnabled(false);
connect(m_connectButton, &QPushButton::clicked, this, &WlanItem::onConnectButtonClicked);
m_pwdFrameLyt->addWidget(m_connectButton);
//自动连接选择区域UI
m_autoConnectFrame = new QFrame(m_expendFrame);
m_autoConnectFrameLyt = new QHBoxLayout(m_autoConnectFrame);
m_autoConnectFrameLyt->setContentsMargins(0,8,150,8);
m_autoConnectFrameLyt->setSpacing(0);
m_autoConnectFrame->setLayout(m_autoConnectFrameLyt);
m_autoConnectCheckBox = new QCheckBox(m_autoConnectFrame);
m_autoConnectCheckBox->setChecked(true);
m_autoConnectCheckBox->setFixedSize(16, 16);
m_autoConnectFrameLyt->addWidget(m_autoConnectCheckBox);
m_autoConnectFrameLyt->addSpacing(8);
m_autoConnectLabel = new QLabel(m_autoConnectFrame);
m_autoConnectLabel->setText(tr("Auto Connect"));
m_autoConnectFrameLyt->addWidget(m_autoConnectLabel);
expendnLyt->addWidget(m_pwdFrame);
expendnLyt->addWidget(m_autoConnectFrame);
m_mainLayout->addWidget(m_nameFrame);
m_mainLayout->addWidget(m_expendFrame);
m_expendFrame->hide();
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon);
m_menu = new QMenu(this);//右键菜单
m_menu->setWindowFlag(Qt::X11BypassWindowManagerHint);
connect(m_menu, &QMenu::triggered, this, &WlanItem::itemClick);
}
void WlanItem::updateIcon()
{
if (currentIconIndex > 6) {
currentIconIndex = 0;
}
radioBtn->setButtonIcon(loadIcons.at(currentIconIndex));
currentIconIndex ++;
}
void WlanItem::showEnterPricePage(QString devName, QWidget *widget)
{
if (nullptr != m_enterPirsePage) {
m_enterPirsePage->show();
} else {
QString ssid = getName();
m_enterPirsePage = new EnterpriseWlanPage(ssid, devName, true, widget);
connect(m_enterPirsePage, &EnterpriseWlanPage::destroyed, [=](){
m_enterPirsePage->disconnect(this);
m_enterPirsePage = nullptr;
});
connect(m_enterPirsePage, &EnterpriseWlanPage::connectPeapConnect, this, &WlanItem::connectPeapConnect);
connect(m_enterPirsePage, &EnterpriseWlanPage::connectTtlsConnect, this, &WlanItem::connectTtlsConnect);
m_enterPirsePage->show();
}
}
void WlanItem::startLoading()
{
waitTimer->start(FRAME_SPEED);
m_loading = true;
}
void WlanItem::stopLoading(){
waitTimer->stop();
m_loading = false;
}
void WlanItem::mousePressEvent(QMouseEvent *event)
{
return QFrame::mousePressEvent(event);
}
void WlanItem::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton) {
if (!m_menu) {
return QFrame::mouseReleaseEvent(event);
}
m_menu->clear();
if (m_isAcitve || m_loading) {
m_menu->addAction(new QAction(tr("Disconnect"), this));
} else if (!m_isAcitve && !m_loading) {
m_menu->addAction(new QAction(tr("Connect"), this));
}
m_menu->move(cursor().pos());
m_menu->show();
} else {
if (!m_isAcitve && !m_loading) {
Q_EMIT itemClick();
}
}
return QFrame::mouseReleaseEvent(event);
}
void WlanItem::enterEvent(QEvent *event)
{
m_isIn = true;
update();
return QFrame::enterEvent(event);
}
void WlanItem::leaveEvent(QEvent *event)
{
m_isIn = false;
update();
return QFrame::leaveEvent(event);
}
void WlanItem::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
if (m_expendFrame && m_expendFrame->isVisible() && m_pwdLineEdit->text().length() >= 8) {
onConnectButtonClicked();
}
}
return QFrame::keyPressEvent(event);
}
void WlanItem::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
if (m_isIn) {
QColor color(240, 240, 240);
color.setAlphaF(0.39);
painter.setBrush(color);
}
else
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect(rect, RADIUS, RADIUS);
painter.drawPath(path);
return QFrame::paintEvent(event);
}
bool WlanItem::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_pwdLineEdit && event->type() == QEvent::FocusIn) {
Q_EMIT passwordFocusIn();
}
return QFrame::eventFilter(watched,event);
}
void WlanItem::setExpend(bool enable)
{
if (enable) {
this->setFixedHeight(EXPEND_HEIGHT);
m_expendFrame->show();
m_pwdLineEdit->setFocus();
} else {
m_expendFrame->hide();
this->setFixedHeight(UNEXPEND_HEIGHT);
m_pwdLineEdit->clear();
m_pwdLineEdit->setState(Ordinary);
}
}
bool WlanItem::getExpend()
{
return !m_expendFrame->isHidden();
}
void WlanItem::onPwdEditorTextChanged()
{
QPalette btnPal;
if (m_pwdLineEdit->text().length() < 8) {
m_connectButton->setEnabled(false);
btnPal.setColor(QPalette::Button, UNABLE_BUTTON_COLOR);
m_connectButton->setPalette(btnPal);
} else {
m_connectButton->setEnabled(true);
btnPal.setColor(QPalette::Button, ENABLE_BUTTON_COLOR);
m_connectButton->setPalette(btnPal);
}
}
void WlanItem::onConnectButtonClicked()
{
connectButtonClick(m_pwdLineEdit->text(), m_autoConnectCheckBox->isChecked());
}

View File

@ -0,0 +1,160 @@
#ifndef WLANITEM_H
#define WLANITEM_H
#include <QObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QTimer>
#include <QDebug>
#include <QImage>
#include <QMouseEvent>
#include <QMenu>
#include <QCheckBox>
#include "../component/InfoButton/infobutton.h"
#include "../component/RadioItemButton/radioitembutton.h"
#include "../component/FixLabel/fixlabel.h"
#include "kpasswordedit.h"
#include "hiddenwifi/enterprisewlanpage.h"
using namespace kdk;
class WlanItem : public QFrame
{
Q_OBJECT
public:
WlanItem(bool isSimple, QWidget *parent = nullptr);
public:
void setName(QString name) {
titileLabel->setLabelText(name);
}
QString getName() {
return titileLabel->getText();
}
void setItemIcon(const QIcon &icon) {
radioBtn->setButtonIcon(icon);
}
void setStatus(bool isAcitve){
m_isAcitve = isAcitve;
radioBtn->setActive(isAcitve);
}
bool getStatus(){
return m_isAcitve;
}
bool getIsLoading() {
return m_loading;
}
QString getUuid(){
return m_uuid;
}
void setUuid(QString uuid){
m_uuid = uuid;
}
QString getPath(){
return m_dbusPath;
}
void setPath(QString dbusPath){
m_dbusPath = dbusPath;
}
QString getSecuType(){
return m_secutype;
}
void setSecuType(QString &secuType){
m_secutype = secuType;
}
QString getInterface(){
return m_interface;
}
void setInterface(QString &interface){
m_interface = interface;
}
void setPasswordError(QString pwd) {
m_pwdLineEdit->setState(LoginFailed);
m_pwdLineEdit->setText(pwd);
}
void showEnterPricePage(QString devName, QWidget *widget);
void startLoading();
void stopLoading();
void setExpend(bool);
bool getExpend();
Q_SIGNALS:
void itemClick();
void infoButtonClick();
void connectButtonClick(QString , bool);
void passwordFocusIn();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
private:
QTimer *waitTimer = nullptr;
QList<QIcon> loadIcons;
int currentIconIndex=0;
QMenu *m_menu = nullptr;
RadioItemButton* radioBtn = nullptr;
InfoButton * infoLabel = nullptr;
FixLabel * titileLabel = nullptr;
bool isSimple;
bool m_isAcitve = false;
bool m_loading = false;
bool m_isExpand = false;
QString m_uuid = "";
QString m_dbusPath ="";
//ap类型
QString m_secutype = "";
QString m_interface = "";
QFrame* m_nameFrame = nullptr;
QFrame* m_expendFrame = nullptr;
QFrame* m_pwdFrame = nullptr;
QFrame* m_autoConnectFrame = nullptr;
KPasswordEdit* m_pwdLineEdit = nullptr;
QPushButton* m_connectButton = nullptr;
QCheckBox* m_autoConnectCheckBox = nullptr;
QLabel* m_autoConnectLabel = nullptr;
QHBoxLayout* m_autoConnectFrameLyt = nullptr;
QHBoxLayout* m_pwdFrameLyt = nullptr;
EnterpriseWlanPage* m_enterPirsePage = nullptr;
bool m_isIn = false;
private Q_SLOTS:
void updateIcon();
// void onMenuTriggered(QAction *action);
void onPwdEditorTextChanged();
void onConnectButtonClicked();
Q_SIGNALS:
void connectPeapConnect(KyEapMethodPeapInfo info, KyWirelessConnectSetting connSettingInfo);
void connectTtlsConnect(KyEapMethodTtlsInfo info, KyWirelessConnectSetting connSettingInfo);
};
#endif // WLANITEM_H

View File

@ -1,6 +1,5 @@
TEMPLATE = subdirs
CONFIG += \
ordered \
qt \
@ -10,5 +9,6 @@ SUBDIRS = \
src-vpn/src-vpn.pro \
src \
sys-dbus-register \
kylin-nm-plugin/kylin-nm-plugin.pro \
QT += widgets