diff --git a/src/backend/backend.pri b/src/backend/backend.pri index feb4853f..10314e58 100644 --- a/src/backend/backend.pri +++ b/src/backend/backend.pri @@ -4,6 +4,7 @@ include(dbus-interface/dbus-interface.pri) HEADERS += \ $$PWD/dbusadaptor.h \ + $$PWD/vpndbusadaptor.h \ $$PWD/kylinarping.h \ $$PWD/kylinipv4arping.h \ $$PWD/kylinipv6arping.h \ @@ -13,6 +14,7 @@ HEADERS += \ SOURCES += \ $$PWD/dbusadaptor.cpp \ + $$PWD/vpndbusadaptor.cpp \ $$PWD/kylinipv4arping.cpp \ $$PWD/kylinipv6arping.cpp \ $$PWD/sysdbusregister.cpp \ diff --git a/src/frontend/frontend.pri b/src/frontend/frontend.pri index 02e96103..fb35339b 100644 --- a/src/frontend/frontend.pri +++ b/src/frontend/frontend.pri @@ -13,11 +13,11 @@ FORMS += \ HEADERS += \ $$PWD/customstyle.h \ $$PWD/mainwindow.h \ - $$PWD/vpnmainwindow.h \ - $$PWD/wificonfigdialog.h + $$PWD/wificonfigdialog.h \ + $$PWD/vpnobject.h SOURCES += \ $$PWD/customstyle.cpp \ $$PWD/mainwindow.cpp \ - $$PWD/vpnmainwindow.cpp \ - $$PWD/wificonfigdialog.cpp + $$PWD/wificonfigdialog.cpp \ + $$PWD/vpnobject.cpp diff --git a/src/frontend/single-pages/singlepage.cpp b/src/frontend/single-pages/singlepage.cpp index 2e059cac..848adfe3 100644 --- a/src/frontend/single-pages/singlepage.cpp +++ b/src/frontend/single-pages/singlepage.cpp @@ -24,14 +24,17 @@ #include #include +#include + SinglePage::SinglePage(QWidget *parent) : QWidget(parent) { initUI(); + initWindowProperties(); + initTransparency(); } SinglePage::~SinglePage() { - delete m_netDivider; } void SinglePage::initUI() @@ -41,45 +44,64 @@ void SinglePage::initUI() m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING); this->setLayout(m_mainLayout); - m_netFrame = new QFrame(this); - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT); - m_netLayout = new QVBoxLayout(m_netFrame); - m_netLayout->setContentsMargins(NET_LAYOUT_MARGINS); - m_netFrame->setLayout(m_netLayout); - - m_netLabel = new QLabel(m_netFrame); - m_netLabel->setContentsMargins(TEXT_MARGINS); - m_netLabel->setFixedHeight(TEXT_HEIGHT); - - m_netListArea = new QWidget(m_netFrame); - m_netAreaLayout = new QVBoxLayout(m_netListArea); - m_netAreaLayout->setSpacing(MAIN_LAYOUT_SPACING); - m_netAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); - - m_netLayout->addWidget(m_netLabel); - m_netLayout->addWidget(m_netListArea); + m_titleFrame = new QFrame(this); + m_titleFrame->setFixedHeight(TITLE_FRAME_HEIGHT); + m_titleLayout = new QHBoxLayout(m_titleFrame); + m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS); + m_titleFrame->setLayout(m_titleLayout); + m_titleLabel = new QLabel(m_titleFrame); + m_titleLayout->addWidget(m_titleLabel); + m_titleLayout->addStretch(); m_netDivider = new Divider(this); + + m_listFrame = new QFrame(this); + m_listLayout = new QVBoxLayout(m_listFrame); + m_listLayout->setContentsMargins(NET_LAYOUT_MARGINS); + m_listFrame->setLayout(m_listLayout); + m_listWidget = new QListWidget(m_listFrame); + m_listLayout->addWidget(m_listWidget); + + m_setDivider = new Divider(this); + m_settingsFrame = new QFrame(this); m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT); - m_settingsLayout = new QHBoxLayout(m_settingsFrame); m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS); - m_settingsLabel = new KyLable(m_settingsFrame); m_settingsLabel->setCursor(Qt::PointingHandCursor); m_settingsLabel->setText(tr("Settings")); m_settingsLabel->setScaledContents(true); - m_settingsLayout->addWidget(m_settingsLabel); m_settingsLayout->addStretch(); m_settingsFrame->setLayout(m_settingsLayout); - m_mainLayout->addWidget(m_netFrame); - m_mainLayout->addStretch(); + m_mainLayout->addWidget(m_titleFrame); m_mainLayout->addWidget(m_netDivider); + m_mainLayout->addWidget(m_listFrame); + m_mainLayout->addWidget(m_setDivider); m_mainLayout->addWidget(m_settingsFrame); +} +void SinglePage::initWindowProperties() +{ + QPalette pal = m_listFrame->palette(); + pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 + m_listFrame->setPalette(pal); + + this->setFixedWidth(MAX_WIDTH); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setProperty("useStyleWindowManager", false); //禁用拖动 + //绘制毛玻璃特效 + QString platform = QGuiApplication::platformName(); + if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) + { + QPainterPath path; + auto rect = this->rect(); + path.addRoundedRect(rect, 12, 12); + path.addRect(rect); + KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊 + } } void SinglePage::showDesktopNotify(const QString &message, QString soundName) @@ -107,3 +129,57 @@ void SinglePage::showDesktopNotify(const QString &message, QString soundName) iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args); } +void SinglePage::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::transparent); + QColor col = qApp->palette().window().color(); + + QPainterPath rectPath; + + col.setAlphaF(m_transparency); + rectPath.addRoundedRect(this->rect(),12,12); + + painter.setBrush(col); + painter.drawPath(rectPath); + KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(rectPath.toFillPolygon().toPolygon())); //背景模糊 +} + +void SinglePage::initTransparency() +{ + if(QGSettings::isSchemaInstalled(QByteArray(TRANSPARENCY_GSETTINGS))) { + m_transGsettings = new QGSettings(QByteArray(TRANSPARENCY_GSETTINGS)); + if(m_transGsettings->keys().contains(TRANSPARENCY)) { + m_transparency = m_transGsettings->get(TRANSPARENCY).toDouble() + 0.15; + m_transparency = (m_transparency > 1) ? 1 : m_transparency; + connect(m_transGsettings, &QGSettings::changed, this, &SinglePage::onTransChanged); + } + } +} + +void SinglePage::onTransChanged() +{ + m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; + m_transparency = (m_transparency > 1) ? 1 : m_transparency; + paintWithTrans(); +} + +void SinglePage::paintWithTrans() +{ + QPalette pal = this->palette(); + QColor color = qApp->palette().base().color(); + color.setAlphaF(m_transparency); + pal.setColor(QPalette::Window, color); + this->setPalette(pal); +} + +void SinglePage::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) { + this->hide(); + } + return QWidget::keyPressEvent(event); +} + + diff --git a/src/frontend/single-pages/singlepage.h b/src/frontend/single-pages/singlepage.h index 3859f67d..f180434d 100644 --- a/src/frontend/single-pages/singlepage.h +++ b/src/frontend/single-pages/singlepage.h @@ -34,29 +34,19 @@ #include #include #include "kylinnetworkdeviceresource.h" +#include "firewalldialog.h" #include "kwidget.h" #include "kswitchbutton.h" -//#include "kborderlessbutton.h" using namespace kdk; #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 -#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 +#define TITLE_FRAME_HEIGHT 60 //TabWidget的tab和widget有间隙,和设计稿看起来一致就不能设为设计稿里的高度 #define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define DEVICE_LAYOUT_MARGINS 24,0,24,8 -#define DEVICE_COMBOBOX_WIDTH 180 -#define ACTIVE_NET_LAYOUT_MARGINS 8,8,8,8 -#define NET_LAYOUT_MARGINS 8,8,0,1 -#define NET_LAYOUT_SPACING 8 -#define NET_LIST_SPACING 0 -#define TEXT_MARGINS 16,0,0,0 +#define NET_LAYOUT_MARGINS 8,8,8,8 #define TEXT_HEIGHT 20 -//#define SCROLL_AREA_HEIGHT 200 #define SETTINGS_LAYOUT_MARGINS 23,0,24,0 -#define TRANSPARENT_COLOR QColor(0,0,0,0) -#define INACTIVE_AREA_MIN_HEIGHT 170 -#define ACTIVE_AREA_MAX_HEIGHT 92 #define MAX_ITEMS 4 #define MAX_WIDTH 412 @@ -64,6 +54,9 @@ using namespace kdk; #define SCROLL_STEP 4 +#define TRANSPARENCY "transparency" +#define TRANSPARENCY_GSETTINGS "org.ukui.control-center.personalise" + class SinglePage : public QWidget { Q_OBJECT @@ -73,41 +66,48 @@ public: static void showDesktopNotify(const QString &message, QString soundName); - void hideSetting() { - if (nullptr != m_settingsFrame) { - m_settingsFrame->hide(); - m_netDivider->hide(); - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT + 100); - } - } - void showSetting() { - if (nullptr != m_settingsFrame) { - m_netFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT); - m_settingsFrame->show(); - m_netDivider->show(); - } - } - Q_SIGNALS: void activateFailed(QString errorMessage); void deactivateFailed(QString errorMessage); +private Q_SLOTS: + void onTransChanged(); + +protected: + void paintEvent(QPaintEvent *event); + void keyPressEvent(QKeyEvent *event); + protected: void initUI(); + void initTransparency(); + void paintWithTrans(); + + +private: + void initWindowProperties(); + +protected: QVBoxLayout * m_mainLayout = nullptr; - QFrame * m_netFrame = nullptr; - QVBoxLayout * m_netLayout = nullptr; - QLabel * m_netLabel = nullptr; - QWidget * m_netListArea = nullptr; - QVBoxLayout * m_netAreaLayout = nullptr; + QLabel * m_titleLabel = nullptr; + QFrame * m_titleFrame = nullptr; + QHBoxLayout * m_titleLayout = nullptr; - Divider * m_netDivider = nullptr; + QFrame * m_listFrame = nullptr; + QListWidget * m_listWidget = nullptr; + QVBoxLayout * m_listLayout = nullptr; QFrame * m_settingsFrame = nullptr; QHBoxLayout * m_settingsLayout = nullptr; KyLable * m_settingsLabel = nullptr; + Divider * m_netDivider = nullptr; + Divider * m_setDivider = nullptr; + + + QGSettings * m_transGsettings = nullptr; + double m_transparency = 1.0; //透明度 + }; #endif // TABPAGE_H diff --git a/src/frontend/single-pages/vpnpage.cpp b/src/frontend/single-pages/vpnpage.cpp index 8272d9e9..14e11d0c 100644 --- a/src/frontend/single-pages/vpnpage.cpp +++ b/src/frontend/single-pages/vpnpage.cpp @@ -18,35 +18,21 @@ * */ #include "vpnpage.h" +#include "networkmodeconfig.h" #include #include +#include "windowmanager/windowmanager.h" -#define MAIN_LAYOUT_MARGINS 0,0,0,0 -#define MAIN_LAYOUT_SPACING 0 -#define TITLE_FRAME_HEIGHT 52 -#define TITLE_LAYOUT_MARGINS 24,0,24,0 -#define LAN_LIST_SPACING 0 -#define TEXT_MARGINS 16,0,0,0 -#define SETTINGS_LAYOUT_MARGINS 24,16,24,16 -#define TRANSPARENT_COLOR QColor(0,0,0,0) -#define ITEM_HEIGHT 48 - - -#define LOG_FLAG "[VpnPage]" - -const QString EMPTY_CONNECT_UUID = "emptyconnect"; - -const QString WIRED_SWITCH = "wiredswitch"; VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) { m_activeResourse = new KyActiveConnectResourse(this); m_connectResourse = new KyConnectResourse(this); -// m_deviceResource = new KyNetworkDeviceResourse(this); -// m_wiredConnectOperation = new KyWiredConnectOperation(this); + m_wiredConnectOperation = new KyWiredConnectOperation(this); initUI(); initVpnArea(); + installEventFilter(this); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &VpnPage::onConnectionStateChange); connect(m_activeResourse, &KyActiveConnectResourse::activeConnectRemove, this, [=] (QString activeConnectUuid) { @@ -57,8 +43,8 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &VpnPage::onRemoveConnection); connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &VpnPage::onUpdateConnection); -// connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); -// connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); + connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); + connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); } VpnPage::~VpnPage() @@ -114,10 +100,11 @@ void VpnPage::constructActiveConnectionArea() { QList activedList; QList netList; + QGSettings vpnGsettings(GSETTINGS_VPNICON_VISIBLE); activedList.clear(); netList.clear(); - clearConnectionMap(m_activeConnectionMap, m_vpnListWidget); + clearConnectionMap(m_activeConnectionMap, m_listWidget); m_connectResourse->getVpnAndVirtualConnections(netList); KyConnectItem *p_newItem = nullptr; @@ -126,73 +113,66 @@ void VpnPage::constructActiveConnectionArea() KyConnectItem *p_netConnectionItem = netList.at(index); p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); if (p_newItem == nullptr) { - qDebug()<<"---cxc---"<m_connectUuid<m_connectName<m_connectState; if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { qDebug()<m_connectUuid; } - QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget); + QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_listWidget); m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); } else { - qDebug()<<"---cxc---"<m_connectUuid<m_connectName<m_connectState; if (m_activeConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { qDebug()<m_connectUuid; } -// p_netConnectionItem->m_connectState = NetworkManager::ActiveConnection::Activated; - QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget); + QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); m_activeConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); } delete p_netConnectionItem; p_netConnectionItem = nullptr; } - } - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); + if (vpnGsettings.keys().contains(QString(VISIBLE))) { + vpnGsettings.set(VISIBLE, true); + } } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); - } - return; -} - -void VpnPage::constructConnectionArea() -{ - QList netList; - - netList.clear(); - clearConnectionMap(m_netConnectionMap, m_vpnListWidget); - - m_connectResourse->getVpnAndVirtualConnections(netList); - qDebug() << "[VpnPage]construct connection area get connection list size:" << netList.size(); - if (!netList.isEmpty()) { - for (int index = 0; index < netList.size(); index++) { - KyConnectItem *p_netConnectionItem = netList.at(index); - qDebug()<<"[VpnPage] construct connection area add deactive item"<m_connectName; - QListWidgetItem *p_listWidgetItem = addNewItem(p_netConnectionItem, m_vpnListWidget); - if (m_netConnectionMap.contains(p_netConnectionItem->m_connectUuid)) { - qDebug()<m_connectUuid; - } - m_netConnectionMap.insert(p_netConnectionItem->m_connectUuid, p_listWidgetItem); - - delete p_netConnectionItem; - p_netConnectionItem = nullptr; - + if (vpnGsettings.keys().contains(QString(VISIBLE))) { + vpnGsettings.set(VISIBLE, false); } } - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); + + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); + m_listFrame->setFixedWidth(MAX_WIDTH); } - return; } void VpnPage::initVpnArea() { - m_netFrame->show(); constructActiveConnectionArea(); -// constructConnectionArea(); +} - return; +void VpnPage::resetPageHight() +{ + int height = 0; + int count = m_listWidget->count(); + m_listFrame->setFixedHeight((count >= 4) ? (MAX_ITEMS * ITEM_HEIGHT + ITEM_SPACE) : (count * ITEM_HEIGHT + ITEM_SPACE)); + + if (count == 0) { + m_listWidget->setHidden(true); + m_listFrame->setHidden(true); + m_netDivider->setHidden(true); + } else { + m_listWidget->show(); + m_listFrame->show(); + m_netDivider->show(); + } + + for (int i = 0; i < m_mainLayout->count(); i ++) { + QWidget *w = m_mainLayout->itemAt(i)->widget(); + if (w != nullptr && w->isHidden() != true) { + height += w->height(); + } + } + this->setFixedHeight(height + PAGE_SPACE); } bool VpnPage::removeConnectionItem(QMap &connectMap, @@ -214,8 +194,8 @@ bool VpnPage::removeConnectionItem(QMap &connectMap, p_listWidgetItem = nullptr; iter = connectMap.erase(iter); - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); } return true; } @@ -230,9 +210,11 @@ void VpnPage::onRemoveConnection(QString path) //删除时后端会 qDebug() << "[VpnPage] emit lanRemove because onRemoveConnection " << path; Q_EMIT vpnRemove(path); - if (removeConnectionItem(m_netConnectionMap, m_vpnListWidget, path)) { - return; - } + removeConnectionItem(m_netConnectionMap, m_listWidget, path); + removeConnectionItem(m_activeConnectionMap, m_listWidget, path); + resetPageHight(); + resetWindowPosition(); + this->update(); } void VpnPage::onAddConnection(QString uuid) //新增一个有线连接,将其加入到激活列表 @@ -250,7 +232,7 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线 sendVpnAddSignal(p_newItem); qDebug()<<"[VpnPage] Add a new connection, name:"<m_connectName; - QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget); + QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); if (m_netConnectionMap.contains(p_newItem->m_connectUuid)) { qDebug()<m_connectUuid; } @@ -258,9 +240,12 @@ void VpnPage::onAddConnection(QString uuid) //新增一个有线 delete p_newItem; p_newItem = nullptr; - if (m_vpnListWidget->count() > MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); + if (m_listWidget->count() >= MAX_ITEMS) { + m_listFrame->setFixedWidth(MAX_WIDTH); } + resetPageHight(); + resetWindowPosition(); + this->update(); return; } @@ -272,20 +257,14 @@ void VpnPage::onShowControlCenter() void VpnPage::initUI() { - m_netLabel->setText(tr("VPN Connection")); - m_vpnListWidget = new QListWidget(m_netListArea); - m_vpnListWidget->setFrameShape(QFrame::Shape::NoFrame); - m_vpnListWidget->setSpacing(LAN_LIST_SPACING); - m_vpnListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_vpnListWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); - m_vpnListWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框 - m_vpnListWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP); - m_vpnListWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); - m_netAreaLayout->addWidget(m_vpnListWidget); + m_titleLabel->setText(tr("VPN")); - QPalette pal = m_vpnListWidget->palette(); - pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明 - m_vpnListWidget->setPalette(pal); + m_listWidget->setFrameShape(QFrame::Shape::NoFrame); + m_listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_listWidget->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); + m_listWidget->verticalScrollBar()->setProperty("drawScrollBarGroove",false); //去除滚动条的外侧黑框 + m_listWidget->verticalScrollBar()->setSingleStep(SCROLL_STEP); + m_listWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); m_settingsLabel->setText(tr("VPN Settings")); m_settingsLabel->installEventFilter(this); @@ -295,9 +274,9 @@ QListWidgetItem *VpnPage::insertNewItem(KyConnectItem *itemData, QListWidget *li { int index = 0; - for(index = 0; index < m_vpnListWidget->count(); index++) { - QListWidgetItem *p_listWidgetItem = m_vpnListWidget->item(index); - VpnListItem *p_lanItem = (VpnListItem *)m_vpnListWidget->itemWidget(p_listWidgetItem); + for(index = 0; index < m_listWidget->count(); index++) { + QListWidgetItem *p_listWidgetItem = m_listWidget->item(index); + VpnListItem *p_lanItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem); QString name1 = p_lanItem->getConnectionName(); QString name2 = itemData->m_connectName; if (QString::compare(name1, name2, Qt::CaseInsensitive) > 0) { @@ -322,7 +301,7 @@ QListWidgetItem *VpnPage::addNewItem(KyConnectItem *itemData, QListWidget *listW { QListWidgetItem *p_listWidgetItem = new QListWidgetItem(); p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable)); - p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT)); + p_listWidgetItem->setSizeHint(QSize(listWidget->width() - 16, ITEM_HEIGHT)); listWidget->addItem(p_listWidgetItem); VpnListItem *p_lanItem = nullptr; if (itemData != nullptr) { @@ -343,13 +322,13 @@ void VpnPage::updateActivatedConnectionArea(KyConnectItem *p_newItem) return; } - deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); + deleteConnectionMapItem(m_netConnectionMap, m_listWidget, p_newItem->m_connectUuid); qDebug()<<"[VpnPage]update active connection item"<m_connectName; - deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); - QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_vpnListWidget); + deleteConnectionMapItem(m_activeConnectionMap, m_listWidget, p_newItem->m_connectUuid); + QListWidgetItem *p_listWidgetItem = addNewItem(p_newItem, m_listWidget); m_activeConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); } return; @@ -361,18 +340,16 @@ void VpnPage::updateConnectionArea(KyConnectItem *p_newItem) return; } - deleteConnectionMapItem(m_activeConnectionMap, m_vpnListWidget, p_newItem->m_connectUuid); + deleteConnectionMapItem(m_activeConnectionMap, m_listWidget, p_newItem->m_connectUuid); qDebug()<<"[VpnPage] update connection item"<m_connectName; - QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_vpnListWidget); + QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_listWidget); m_netConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); - if (m_vpnListWidget->count() <= MAX_ITEMS) { - m_vpnListWidget->setFixedWidth(MIN_WIDTH); + if (m_listWidget->count() <= MAX_ITEMS) { + m_listFrame->setFixedWidth(MIN_WIDTH); } else { - m_vpnListWidget->setFixedWidth(MAX_WIDTH); + m_listFrame->setFixedWidth(MAX_WIDTH); } - - return; } void VpnPage::updateConnectionState(QMap &connectMap, @@ -386,24 +363,21 @@ void VpnPage::updateConnectionState(QMap &connectMap p_lanItem->updateConnectionState(state); } - return; } void VpnPage::onConnectionStateChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason) + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) { - qDebug()<<"--cxc--"<isVirtualConncection(uuid)) { - qDebug() << "[VpnPage] connection state change signal but not wired"; + qDebug() << "[VpnPage] connection state change signal but not vpn"; return; } sendVpnStateChangeSignal(uuid, (ConnectState)state); if (m_activeConnectionMap.keys().contains(uuid) && state == NetworkManager::ActiveConnection::State::Activated) { - qDebug()<<"--cxc--"<m_connectName; updateActivatedConnectionArea(p_newItem); - updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); + updateConnectionState(m_activeConnectionMap, m_listWidget, uuid, (ConnectState)state); } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { p_newItem = m_connectResourse->getConnectionItemByUuid(uuid); qDebug() << "[VpnPage] deactivated reason" << reason; @@ -434,14 +408,15 @@ void VpnPage::onConnectionStateChange(QString uuid, ssid = p_newItem->m_connectName; updateConnectionArea(p_newItem); - updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); + updateConnectionState(m_netConnectionMap, m_listWidget, uuid, (ConnectState)state); + NetworkModeConfig::getInstance()->breakNetworkConnect(uuid, deviceName, ssid); } else if (state == NetworkManager::ActiveConnection::State::Activating) { - updateConnectionState(m_netConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); + updateConnectionState(m_netConnectionMap, m_listWidget, uuid, (ConnectState)state); } else if (state == NetworkManager::ActiveConnection::State::Deactivating) { - updateConnectionState(m_activeConnectionMap, m_vpnListWidget, uuid, (ConnectState)state); + updateConnectionState(m_activeConnectionMap, m_listWidget, uuid, (ConnectState)state); } - Q_EMIT vpnActiveConnectionStateChanged(deviceName, uuid, state); + Q_EMIT vpnActiveConnectionStateChanged(uuid, state); if (p_newItem) { delete p_newItem; @@ -451,17 +426,24 @@ void VpnPage::onConnectionStateChange(QString uuid, return; } - -void VpnPage::getVirtualList(QMap > &map) +void VpnPage::getVirtualList(QVector &vector) { QList netConnectList; - QVector vector; + vector.clear(); m_connectResourse->getVpnAndVirtualConnections(netConnectList); //未激活列表的显示 if (!netConnectList.isEmpty()) { for (int i = 0; i < netConnectList.size(); i++) { - vector.clear(); - vector.append(QStringList()<m_connectName<m_connectUuid << netConnectList.at(i)->m_connectPath); - map.insert(netConnectList.at(i)->m_connectUuid, vector); + KyConnectItem *p_newItem = nullptr; + KyConnectItem *p_netConnectionItem = netConnectList.at(i); + p_newItem = m_activeResourse->getActiveConnectionByUuid(p_netConnectionItem->m_connectUuid); + NetworkManager::ActiveConnection::State state = p_netConnectionItem->m_connectState; + if (p_newItem != nullptr) { + state = NetworkManager::ActiveConnection::Activated; + } + vector.append(QStringList() << netConnectList.at(i)->m_connectName + << netConnectList.at(i)->m_connectUuid + << netConnectList.at(i)->m_connectPath + << QString::number(state)); } } return; @@ -471,7 +453,7 @@ void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) { QStringList info; info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; - Q_EMIT vpnUpdate(p_connectItem->m_ifaceName, info); + Q_EMIT vpnUpdate(info); return; } @@ -479,9 +461,18 @@ void VpnPage::sendVpnUpdateSignal(KyConnectItem *p_connectItem) void VpnPage::sendVpnAddSignal(KyConnectItem *p_connectItem) { QStringList info; - info << p_connectItem->m_connectName << p_connectItem->m_connectUuid << p_connectItem->m_connectPath; + KyConnectItem *p_newItem = nullptr; + p_newItem = m_activeResourse->getActiveConnectionByUuid(p_connectItem->m_connectUuid); + NetworkManager::ActiveConnection::State state = p_connectItem->m_connectState; + if (p_newItem != nullptr) { + state = NetworkManager::ActiveConnection::Activated; + } + info << p_connectItem->m_connectName + << p_connectItem->m_connectUuid + << p_connectItem->m_connectPath + << QString::number(state); qDebug() << "[VpnPage] emit vpnAdd because addConnection "; - Q_EMIT vpnAdd(p_connectItem->m_ifaceName, info); + Q_EMIT vpnAdd(info); return; } @@ -505,11 +496,11 @@ void VpnPage::updateConnectionProperty(KyConnectItem *p_connectItem) if (m_netConnectionMap.contains(newUuid)) { QListWidgetItem *p_listWidgetItem = m_netConnectionMap.value(newUuid); - VpnListItem *p_lanItem = (VpnListItem*)m_vpnListWidget->itemWidget(p_listWidgetItem); + VpnListItem *p_lanItem = (VpnListItem*)m_listWidget->itemWidget(p_listWidgetItem); if (p_connectItem->m_connectName != p_lanItem->getConnectionName()){ //只要名字改变就要删除,重新插入,主要是为了排序 - deleteConnectionMapItem(m_netConnectionMap, m_vpnListWidget, newUuid); - QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget); + deleteConnectionMapItem(m_netConnectionMap, m_listWidget, newUuid); + QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_listWidget); if (m_netConnectionMap.contains(newUuid)) { qDebug()<m_ifaceName.isEmpty()) { - QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_vpnListWidget); + QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_listWidget); if (m_netConnectionMap.contains(newUuid)) { qDebug()<itemWidget(p_listWidgetItem); + VpnListItem *p_lanItem = (VpnListItem *)m_listWidget->itemWidget(p_listWidgetItem); if (p_lanItem->getConnectionName() != p_connectItem->m_connectName) { p_lanItem->updateConnectionName(p_connectItem->m_connectName); } @@ -552,7 +543,7 @@ void VpnPage::updateActiveConnectionProperty(KyConnectItem *p_connectItem) void VpnPage::onUpdateConnection(QString uuid) { - if (!m_connectResourse->isWiredConnection(uuid)) { + if (!m_connectResourse->isVirtualConncection(uuid)) { return; } @@ -595,25 +586,37 @@ bool VpnPage::eventFilter(QObject *watched, QEvent *event) } } + if (event->type() == QEvent::ActivationChange) { + if(QApplication::activeWindow() != this) { + hide(); + } + } + return QWidget::eventFilter(watched, event); } +void VpnPage::deleteVpn(const QString &connUuid) +{ + qDebug() << "[VpnPage] deleteVpn" << connUuid; + if (connUuid == nullptr) { + return; + } + m_wiredConnectOperation->deleteWiredConnect(connUuid); +} + void VpnPage::activateVpn(const QString& connUuid) { -// qDebug() << "[VpnPage] activateVpn" << connUuid; -// if (!m_deviceResource->wiredDeviceIsCarriered(devName)) { -// qDebug() << LOG_FLAG << devName << "is not carried, so can not activate connection"; -// this->showDesktopNotify(tr("Wired Device not carried"), "networkwrong"); -// } else { -// m_wiredConnectOperation->activateConnection(connUuid, devName); -// } + if (m_netConnectionMap.contains(connUuid)) { + qDebug() << "[VpnPage] activateVpn" << connUuid; + m_wiredConnectOperation->activateVpnConnection(connUuid); + } } void VpnPage::deactivateVpn(const QString& connUuid) { qDebug() << "[VpnPage] deactivateVpn" << connUuid; QString name(""); -// m_wiredConnectOperation->deactivateWiredConnection(name, connUuid); + m_wiredConnectOperation->deactivateWiredConnection(name, connUuid); } void VpnPage::showDetailPage(QString devName, QString uuid) @@ -645,12 +648,73 @@ void VpnPage::showDetailPage(QString devName, QString uuid) #endif } -bool VpnPage::vpnIsConnected() +void VpnPage::showUI() { - if (m_activeResourse->wiredConnectIsActived()) { - return true; - } else { - return false; + //2209中窗管在hide界面时会刷新属性,需要重新设置无图标属性 + const KWindowInfo info(this->winId(), NET::WMState); + if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) { + KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager); } + + resetPageHight(); + + showNormal(); + raise(); + activateWindow(); + resetWindowPosition(); + return; } +void VpnPage::resetWindowPosition() +{ + +#define MARGIN 4 +#define PANEL_TOP 1 +#define PANEL_LEFT 2 +#define PANEL_RIGHT 3 +//#define PANEL_BOTTOM 4 + if (!m_positionInterface) { + m_positionInterface = new QDBusInterface("org.ukui.panel", + "/panel/position", + "org.ukui.panel", + QDBusConnection::sessionBus()); + } + QRect rect; + QDBusReply reply = m_positionInterface->call("GetPrimaryScreenGeometry"); + //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 + if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) { + qCritical() << QDBusConnection::sessionBus().lastError().message(); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height())); + return; + } + QVariantList position_list = reply.value(); + int position = position_list.at(4).toInt(); + switch(position){ + case PANEL_TOP: + //任务栏位于上方 + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + MARGIN, + this->width(), this->height()); + break; + //任务栏位于左边 + case PANEL_LEFT: + rect = QRect(position_list.at(0).toInt() + MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + //任务栏位于右边 + case PANEL_RIGHT: + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + //任务栏位于下方 + default: + rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, + position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, + this->width(), this->height()); + break; + } + kdk::WindowManager::setGeometry(this->windowHandle(), rect); + qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; +} diff --git a/src/frontend/single-pages/vpnpage.h b/src/frontend/single-pages/vpnpage.h index ddb212ff..e9f03b2c 100644 --- a/src/frontend/single-pages/vpnpage.h +++ b/src/frontend/single-pages/vpnpage.h @@ -29,11 +29,22 @@ #include #include +#include + #include "list-items/listitem.h" #include "list-items/vpnlistitem.h" #include "single-pages/singlepage.h" #define VPNPAGE_LAYOUT_MARGINS 0,0,0,0 +#define VPN_LIST_SPACING 0 +#define ITEM_HEIGHT 50 +#define ITEM_SPACE 16 +#define PAGE_SPACE 22 + +#define LOG_FLAG "[VpnPage]" + +#define VISIBLE "visible" +const QByteArray GSETTINGS_VPNICON_VISIBLE = "org.ukui.kylin-nm.vpnicon"; class VpnListItem; @@ -45,19 +56,19 @@ public: ~VpnPage(); //for dbus - void getVirtualList(QMap > &map); + void getVirtualList(QVector &vector); + void deleteVpn(const QString &connUuid); void activateVpn(const QString& connUuid); void deactivateVpn(const QString& connUuid); void showDetailPage(QString devName, QString uuid); - bool vpnIsConnected(); - protected: bool eventFilter(QObject *watched, QEvent *event); private: void initUI(); void initVpnArea(); + void resetPageHight(); inline void initDeviceCombox() { return; } @@ -66,7 +77,6 @@ private: bool removeConnectionItem(QMap &connectMap, QListWidget *lanListWidget, QString path); - void constructConnectionArea(); void constructActiveConnectionArea(); void updateConnectionArea(KyConnectItem *p_newItem); @@ -86,16 +96,20 @@ private: void deleteConnectionMapItem(QMap &connectMap, QListWidget *lanListWidget, QString uuid); -Q_SIGNALS: - void vpnAdd(QString devName, QStringList info); - void vpnRemove(QString dbusPath); - void vpnUpdate(QString devName, QStringList info); + void resetWindowPosition(); - void vpnActiveConnectionStateChanged(QString interface, QString uuid, int status); + +Q_SIGNALS: + void vpnAdd(QStringList info); + void vpnRemove(QString dbusPath); + void vpnUpdate(QStringList info); + + void vpnActiveConnectionStateChanged(QString uuid, int status); void vpnConnectChanged(int state); private Q_SLOTS: - void onConnectionStateChange(QString uuid, NetworkManager::ActiveConnection::State state, + void onConnectionStateChange(QString uuid, + NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); void onAddConnection(QString uuid); @@ -104,21 +118,20 @@ private Q_SLOTS: void onShowControlCenter(); -// void onStateChange(); - private: - QListWidget * m_vpnListWidget = nullptr; - -// KyNetworkDeviceResourse *m_deviceResource = nullptr; -// KyWiredConnectOperation *m_wiredConnectOperation = nullptr; + KyWiredConnectOperation *m_wiredConnectOperation = nullptr; KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 QMap m_netConnectionMap; QMap m_activeConnectionMap; + QDBusInterface * m_positionInterface = nullptr; + + + public Q_SLOTS: - inline void onDeviceComboxIndexChanged(int currentIndex) { return; } + void showUI(); }; #endif // LANPAGE_H diff --git a/src/frontend/vpnmainwindow.cpp b/src/frontend/vpnmainwindow.cpp deleted file mode 100644 index e9c9b591..00000000 --- a/src/frontend/vpnmainwindow.cpp +++ /dev/null @@ -1,717 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * Copyright (C) 2022 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 "vpnmainwindow.h" -#include "customstyle.h" -#include -#include -#include -#include -#include -#include - -#include "kylinnetworkdeviceresource.h" -#include "../backend/dbus-interface/kylinagentinterface.h" - -#include "ukuistylehelper/ukuistylehelper.h" -#include "windowmanager/windowmanager.h" -#include "kysdk/kysdk-system/libkysysinfo.h" - -#define MAINWINDOW_WIDTH 420 -#define MAINWINDOW_HEIGHT 300 -#define VPN_LAYOUT_MARGINS 0,12,0,12 -#define THEME_SCHAME "org.ukui.style" -#define COLOR_THEME "styleName" - -const QString v10Sp1 = "V10SP1"; -const QString intel = "V10SP1-edu"; - -#define KEY_PRODUCT_FEATURES "PRODUCT_FEATURES" - -#include -#include - -vpnMainWindow::vpnMainWindow(QWidget *parent): QMainWindow(parent) -{ - firstlyStart(); -} - -/** - * @brief vpnMainWindow::showMainwindow show主窗口,同时也作为dbus接口提供给外部组件调用 - */ -void vpnMainWindow::showMainwindow() -{ - if (!m_loadFinished) { - m_secondaryStartTimer->stop(); - secondaryStart(); - } - - /** - * 设置主界面跳过任务栏和分页器的属性,隐藏再次展示有可能辉冲刷掉该属性,需要展示时重新设置 - */ - QString platform = QGuiApplication::platformName(); - if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) - { - const KWindowInfo info(this->winId(), NET::WMState); - if (!info.hasState(NET::SkipTaskbar) || !info.hasState(NET::SkipPager)) { - KWindowSystem::setState(this->winId(), NET::SkipTaskbar | NET::SkipPager); - } - } - - this->showByWaylandHelper(); - this->raise(); - this->activateWindow(); - Q_EMIT this->mainWindowVisibleChanged(true); -#ifdef WITHKYSEC -// if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){ -// if (nullptr != m_vpnPage) { -// m_vpnPage->hideSetting(); -// } -// } else { -// if (nullptr != m_vpnPage) { -// m_vpnPage->showSetting(); -// } -// } -#endif - -} - -/** - * @brief MainWindow::hideMainwindow 隐藏主页面时要进行的操作,后续可以添加到此函数 - */ -void vpnMainWindow::hideMainwindow() -{ - this->hide(); - Q_EMIT this->mainWindowVisibleChanged(false); -} - -///** -// * @brief MainWindow::setWiredDefaultDevice 设置有线设备默认网卡 -// */ -//void MainWindow::setWiredDefaultDevice(QString deviceName) -//{ -//// m_vpnPage->updateDefaultDevice(deviceName); -//} - -/** - * @brief MainWindow::firstlyStart 一级启动,执行重要且不耗时的启动操作 - */ -void vpnMainWindow::firstlyStart() -{ - initWindowProperties(); - initTransparency(); - initUI(); - initDbusConnnect(); - initWindowTheme(); - initTrayIcon(); - initPlatform(); - installEventFilter(this); - m_secondaryStartTimer = new QTimer(this); - connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() { - m_secondaryStartTimer->stop(); - secondaryStart();//满足条件后执行比较耗时的二级启动 - }); - m_secondaryStartTimer->start(5 * 1000); - - m_createPagePtrMap.clear(); -} - -/** - * @brief vpnMainWindow::secondaryStart 二级启动,可以将较耗时的初始化操作放到此处执行 - */ -void vpnMainWindow::secondaryStart() -{ - if (m_loadFinished) - return; - m_loadFinished = true; -} - -/** - * @brief vpnMainWindow::initPlatform 初始化平台信息 - */ -void vpnMainWindow::initPlatform() -{ - char* projectName = kdk_system_get_projectName(); - QString strProjectName(projectName); - free(projectName); - projectName = NULL; - if(v10Sp1.compare(strProjectName,Qt::CaseInsensitive) == 0) { - unsigned int feature = kdk_system_get_productFeatures(); - if (feature == 3) { - m_isShowInCenter = true; - } - } else if (intel.compare(strProjectName,Qt::CaseInsensitive) == 0) { - m_isShowInCenter = true; - } - qDebug() << "projectName" << projectName << m_isShowInCenter; -} - -/** - * @brief vpnMainWindow::initWindowProperties 初始化一些窗口属性 - */ -void vpnMainWindow::initWindowProperties() -{ - this->setWindowTitle(tr("kylin-vpn")); -// this->setFixedSize(MAINWINDOW_WIDTH, MAINWINDOW_HEIGHT); -// //绘制毛玻璃特效 -// this->setAttribute(Qt::WA_TranslucentBackground, true); //透明 - this->setFocusPolicy(Qt::NoFocus); - - QString platform = QGuiApplication::platformName(); - if(!platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) - { - QPainterPath path; - auto rect = this->rect(); - // path.addRoundedRect(rect, 12, 12); - path.addRect(rect); - KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); //背景模糊 - } -} - -void vpnMainWindow::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; - painter.setPen(Qt::transparent); -// auto rect = this->rect(); -// painter.drawRoundedRect(rect, 12, 12); //窗口圆角 -} - -void vpnMainWindow::initTransparency() -{ - if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) { - m_transGsettings = new QGSettings(TRANSPARENCY_GSETTINGS); - if(m_transGsettings->keys().contains(QString("transparency"))) { - m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; - m_transparency = (m_transparency > 1) ? 1 : m_transparency; - connect(m_transGsettings, &QGSettings::changed, this, &vpnMainWindow::onTransChanged); - } - } -} - -void vpnMainWindow::onTransChanged() -{ - m_transparency = m_transGsettings->get("transparency").toDouble() + 0.15; - m_transparency = (m_transparency > 1) ? 1 : m_transparency; - paintWithTrans(); -} - -void vpnMainWindow::paintWithTrans() -{ - QPalette pal = this->palette(); - QColor color = qApp->palette().base().color(); - color.setAlphaF(m_transparency); - pal.setColor(QPalette::Window, color); - this->setPalette(pal); -} - -/** - * @brief vpnMainWindow::initUI 初始化窗口内控件 - */ -void vpnMainWindow::initUI() -{ - m_vpnWidget = new QWidget(this); - this->setCentralWidget(m_vpnWidget); - m_vpnLayout = new QVBoxLayout(m_vpnWidget); - m_vpnLayout->setContentsMargins(VPN_LAYOUT_MARGINS); - m_vpnWidget->setLayout(m_vpnLayout); - m_vpnWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题 - - m_vpnPage = new VpnPage(m_vpnWidget); - m_vpnLayout->addWidget(m_vpnPage); - - paintWithTrans(); -} - -/** - * @brief vpnMainWindow::initTrayIcon 初始化托盘图标和托盘右键菜单 - */ -void vpnMainWindow::initTrayIcon() -{ - m_vpnTrayIcon = new QSystemTrayIcon(this); - m_vpnTrayIconMenu = new QMenu(); -// m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); -// m_showSettingsAction = new QAction(tr("Settings"),this); - - m_vpnTrayIcon->setToolTip(QString(tr("vpn tool"))); - m_vpnTrayIcon->setIcon(QIcon::fromTheme("ukui-vpn-symbolic")); -// m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); -//// m_vpnTrayIconMenu->addAction(m_showMainwindowAction); -// m_vpnTrayIconMenu->addAction(m_showSettingsAction); -// m_vpnTrayIcon->setContextMenu(m_vpnTrayIconMenu); -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); -// m_iconStatus = IconActiveType::LAN_CONNECTED; -// onRefreshTrayIcon(); - - connect(m_vpnTrayIcon, &QSystemTrayIcon::activated, this, &vpnMainWindow::onTrayIconActivated); -//// connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled); -// connect(m_showSettingsAction, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled); - m_vpnTrayIcon->show(); -} - -void vpnMainWindow::initDbusConnnect() -{ -// connect(m_vpnPage, &LanPage::deviceStatusChanged, this, &MainWindow::deviceStatusChanged); -// connect(m_vpnPage, &LanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); -// connect(m_vpnPage, &LanPage::activateFailed, this, &MainWindow::activateFailed); -// connect(m_vpnPage, &LanPage::deactivateFailed, this, &MainWindow::deactivateFailed); - - connect(m_vpnPage, &VpnPage::vpnAdd, this, &vpnMainWindow::vpnAdd); - connect(m_vpnPage, &VpnPage::vpnRemove, this, &vpnMainWindow::vpnRemove); - connect(m_vpnPage, &VpnPage::vpnUpdate, this, &vpnMainWindow::vpnUpdate); - connect(m_vpnPage, &VpnPage::vpnActiveConnectionStateChanged, this, &vpnMainWindow::vpnActiveConnectionStateChanged); -// connect(m_vpnPage, &LanPage::lanConnectChanged, this, &MainWindow::onLanConnectStatusToChangeTrayIcon); - -// //模式切换 -// QDBusConnection::sessionBus().connect(QString("com.kylin.statusmanager.interfacer"), -// QString("/"), -// QString("com.kylin.statusmanager.interface"), -// QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); -} - -/** - * @brief vpnMainWindow::resetWindowPosition 重新计算窗口位置 - */ -void vpnMainWindow::resetWindowPosition() -{ - - if (m_isShowInCenter) { - QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); - QRect rect((availableGeometry.width() - this->width())/2, (availableGeometry.height() - this->height())/2, - this->width(), this->height()); - kdk::WindowManager::setGeometry(this->windowHandle(), rect); - - return; - } - -#define MARGIN 4 -#define PANEL_TOP 1 -#define PANEL_LEFT 2 -#define PANEL_RIGHT 3 -//#define PANEL_BOTTOM 4 - if (!m_positionInterface) { - m_positionInterface = new QDBusInterface("org.ukui.panel", - "/panel/position", - "org.ukui.panel", - QDBusConnection::sessionBus()); - } - QRect rect; - QDBusReply reply = m_positionInterface->call("GetPrimaryScreenGeometry"); - //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 - if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) { - qCritical() << QDBusConnection::sessionBus().lastError().message(); - kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height())); - return; - } - QVariantList position_list = reply.value(); - int position = position_list.at(4).toInt(); - switch(position){ - case PANEL_TOP: - //任务栏位于上方 - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + MARGIN, - this->width(), this->height()); - break; - //任务栏位于左边 - case PANEL_LEFT: - rect = QRect(position_list.at(0).toInt() + MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - //任务栏位于右边 - case PANEL_RIGHT: - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - //任务栏位于下方 - default: - rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, - position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, - this->width(), this->height()); - break; - } - kdk::WindowManager::setGeometry(this->windowHandle(), rect); - qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; -} - -///** -// * @brief MainWindow::resetTrayIconTool 重新获取网络连接状态并重新设置图标和tooltip -// */ -//void MainWindow::resetTrayIconTool() -//{ -// //ZJP_TODO 检测当前连接的是有线还是无线,是否可用,设置图标和tooltip,图标最好提前define -//// int connectivity = objKyDBus->getNetworkConectivity(); -//// qDebug() << "Value of current network Connectivity property : "<< connectivity; -//// switch (connectivity) { -//// case UnknownConnectivity: -//// case Portal: -//// case Limited: -//// setTrayIcon(iconLanOnlineNoInternet); -//// trayIcon->setToolTip(QString(tr("Network Connected But Can Not Access Internet"))); -//// break; -//// case NoConnectivity: -//// case Full: -//// setTrayIcon(iconLanOnline); -//// trayIcon->setToolTip(QString(tr("kylin-nm"))); -//// break; -//// } -// qDebug() << "Has set tray icon to be XXX." << Q_FUNC_INFO << __LINE__; -//} - - -/** - * @brief vpnMainWindow::initWindowTheme 初始化窗口主题并创建信号槽 - */ -void vpnMainWindow::initWindowTheme() -{ - const QByteArray style_id(THEME_SCHAME); - if (QGSettings::isSchemaInstalled(style_id)) { - m_styleGsettings = new QGSettings(style_id); - connect(m_styleGsettings, &QGSettings::changed, this, &vpnMainWindow::onThemeChanged); - } else { - qWarning() << "Gsettings interface \"org.ukui.style\" is not exist!" << Q_FUNC_INFO << __LINE__; - } -} - -///** -// * @brief MainWindow::resetWindowTheme 读取和设置窗口主题 -// */ -//void MainWindow::resetWindowTheme() -//{ -// if (!m_styleGsettings) { return; } -// QString currentTheme = m_styleGsettings->get(COLOR_THEME).toString(); -// auto app = static_cast(QCoreApplication::instance()); -// if(currentTheme == "ukui-dark" || currentTheme == "ukui-black"){ -// app->setStyle(new CustomStyle("ukui-dark")); -// qDebug() << "Has set color theme to ukui-dark." << Q_FUNC_INFO << __LINE__; -// Q_EMIT qApp->paletteChanged(qApp->palette()); -// return; -// } -// app->setStyle(new CustomStyle("ukui-light")); -// qDebug() << "Has set color theme to " << currentTheme << Q_FUNC_INFO << __LINE__; -// Q_EMIT qApp->paletteChanged(qApp->palette()); -// return; -//} - -///** -// * @brief MainWindow::showControlCenter 打开控制面板网络界面 -// */ -//void MainWindow::showControlCenter() -//{ -// QProcess process; -// if (!m_vpnPage->lanIsConnected() && m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activated)){ -// process.startDetached("ukui-control-center -m wlanconnect"); -// } else { -// process.startDetached("ukui-control-center -m netconnect"); -// } -//} - -void vpnMainWindow::showByWaylandHelper() -{ - //去除窗管标题栏,传入参数为QWidget* - kdk::UkuiStyleHelper::self()->removeHeader(this); - this->show(); - resetWindowPosition(); - //设置窗体位置,传入参数为QWindow*,QRect - -} - -void vpnMainWindow::setCentralWidgetType(IconActiveType iconStatus) -{ - if (iconStatus == WLAN_CONNECTED || iconStatus == WLAN_CONNECTED_LIMITED) { -// m_vpnWidget->setCurrentIndex(WLAN_PAGE_INDEX); - } else if (iconStatus == ACTIVATING) { -// if (m_wlanWidget->checkWlanStatus(NetworkManager::ActiveConnection::State::Activating)) { -// m_vpnWidget->setCurrentIndex(WLAN_PAGE_INDEX); -// } else { -// m_vpnWidget->setCurrentIndex(LAN_PAGE_INDEX); -// } - } else { -// m_vpnWidget->setCurrentIndex(LAN_PAGE_INDEX); - } -} - -/** - * @brief vpnMainWindow::onTrayIconActivated 点击托盘图标的槽函数 - */ -void vpnMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) -{ - setCentralWidgetType(m_iconStatus); - switch(reason) { - case QSystemTrayIcon::Context: - m_vpnTrayIconMenu->popup(QCursor::pos()); - break; - case QSystemTrayIcon::Trigger: - if (this->isVisible()) { - qDebug() << "Received signal of tray icon activated, will hide mainwindow." << Q_FUNC_INFO << __LINE__; - hideMainwindow(); - return; - } - qDebug() << "Received signal of tray icon activated, will show mainwindow." << Q_FUNC_INFO << __LINE__; - this->showMainwindow(); - break; - - default: - break; - } -// if (reason == QSystemTrayIcon::ActivationReason::Context) { -// m_vpnTrayIconMenu->popup(QCursor::pos()); -// } else { -// if (this->isVisible()) { -// qDebug() << "Received signal of tray icon activated, will hide mainwindow." << Q_FUNC_INFO << __LINE__; -// hideMainwindow(); -// return; -// } -// qDebug() << "Received signal of tray icon activated, will show mainwindow." << Q_FUNC_INFO << __LINE__; -// this->showMainwindow(); -// } -} - -//void MainWindow::onShowMainwindowActionTriggled() -//{ -// showMainwindow(); -//} - -//void MainWindow::onShowSettingsActionTriggled() -//{ -// showControlCenter(); -//} - -void vpnMainWindow::onThemeChanged(const QString &key) -{ - if (key == COLOR_THEME) { - qDebug() << "Received signal of theme changed, will reset theme." << Q_FUNC_INFO << __LINE__; - paintWithTrans(); - Q_EMIT qApp->paletteChanged(qApp->palette()); - } else { - qDebug() << "Received signal of theme changed, key=" << key << " will do nothing." << Q_FUNC_INFO << __LINE__; - } -} - -void vpnMainWindow::onRefreshTrayIcon() -{ - //更新托盘图标显示 -// m_iconTimer->stop(); -// if (m_vpnPage->lanIsConnected()) { -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-connected-symbolic")); -// m_iconStatus = IconActiveType::LAN_CONNECTED; -// } else { -// m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); -// m_iconStatus = IconActiveType::NOT_CONNECTED; -// } - - NetworkManager::Connectivity connecttivity; - if (connecttivity != NetworkManager::Connectivity::Full) { - if (m_iconStatus == IconActiveType::LAN_CONNECTED) { - m_vpnTrayIcon->setIcon(QIcon::fromTheme("network-error-symbolic")); - m_iconStatus = IconActiveType::LAN_CONNECTED_LIMITED; - } - } -} - -//void vpnMainWindow::onSetTrayIconLoading() -//{ -// if (m_currentIconIndex > 11) { -// m_currentIconIndex = 0; -// } -// m_vpnTrayIcon->setIcon(m_loadIcons.at(m_currentIconIndex)); -// m_iconStatus = IconActiveType::ACTIVATING; -// m_currentIconIndex ++; -//} - -//void MainWindow::onLanConnectStatusToChangeTrayIcon(int state) -//{ -// qDebug() << "lan state:" << state << Q_FUNC_INFO << __LINE__; -// if (state==1 || state==3){ -// m_lanIsLoading = true; -// m_iconTimer->start(LOADING_TRAYICON_TIMER_MS); -// } else { -// m_lanIsLoading = false; -// if (m_wlanIsLoading == false) { -// onRefreshTrayIcon(); -// } -// } -//} - -//void MainWindow::onTabletModeChanged(bool mode) -//{ -// qDebug() << "TabletMode change" << mode; -// Q_UNUSED(mode) -// //模式切换时,隐藏主界面 -// hideMainwindow(); -//} - -//void MainWindow::onShowMainWindow(int type) -//{ -// m_vpnWidget->setCurrentIndex(type); - -// if(QApplication::activeWindow() != this) { -// this->showMainwindow(); -// } -//} - -//void MainWindow::onConnectivityChanged(NetworkManager::Connectivity connectivity) -//{ -// if (!m_vpnTrayIcon) { -// return; -// } - -// if (m_iconStatus == ACTIVATING) { -// return; -// } - -// onRefreshTrayIcon(); -//} - -///** -// * @brief MainWindow::keyPressEvent 按esc键关闭主界面 -// * @param event -// */ -//void MainWindow::keyPressEvent(QKeyEvent *event) -//{ -// if (event->key() == Qt::Key_Escape) { -// hideMainwindow(); -// } -// return QWidget::keyPressEvent(event); -//} - -///** -// * @brief MainWindow::eventFilter 事件过滤器 -// * @param watched -// * @param event -// * @return -// */ -bool vpnMainWindow::eventFilter(QObject *watched, QEvent *event) -{ - if (event->type() == QEvent::ActivationChange) { - if(QApplication::activeWindow() != this) { - hideMainwindow(); - } - } - return QMainWindow::eventFilter(watched,event); -} - -void vpnMainWindow::getVirtualList(QMap> &map) -{ - map.clear(); - if (nullptr != m_vpnPage) { - m_vpnPage->getVirtualList(map); - } -} - -//void MainWindow::setWiredDeviceEnable(const QString& devName, bool enable) -//{ -// m_vpnPage->setWiredDeviceEnable(devName, enable); -//} -//void MainWindow::showPropertyWidget(QString devName, QString ssid) -//{ -// KyNetworkDeviceResourse *devResourse = new KyNetworkDeviceResourse(); -// QStringList wiredDeviceList; -// wiredDeviceList.clear(); -// devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDeviceList); -// if (wiredDeviceList.contains(devName)) { -// qDebug() << "showPropertyWidget device type wired device name " << devName << " uuid " << ssid; -// m_vpnPage->showDetailPage(devName, ssid); -// delete devResourse; -// devResourse = nullptr; -// return; -// } - -// QStringList wirelessDeviceList; -// wirelessDeviceList.clear(); -// devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDeviceList); -// if (wirelessDeviceList.contains(devName)) { -// qDebug() << "showPropertyWidget device type wireless device name " << devName << " ssid " << ssid; -// m_wlanWidget->showDetailPage(devName, ssid); -// delete devResourse; -// devResourse = nullptr; -// return; -// } - -// qWarning() << "showPropertyWidget no such device " << devName; -// delete devResourse; -// devResourse = nullptr; -//} - -//void MainWindow::showCreateWiredConnectWidget(const QString devName) -//{ -// qDebug() << "showCreateWiredConnectWidget! devName = " << devName; -// if (m_createPagePtrMap.contains(devName)) { -// if (m_createPagePtrMap[devName] != nullptr) { -// qDebug() << "showCreateWiredConnectWidget" << devName << "already create,just raise"; - -// KWindowSystem::raiseWindow(m_createPagePtrMap[devName]->winId()); -// return; -// } -// } -// NetDetail *netDetail = new NetDetail(devName, "", "", false, false, true, this); -// connect(netDetail, &NetDetail::createPageClose, [&](QString interfaceName){ -// if (m_createPagePtrMap.contains(interfaceName)) { -// m_createPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_createPagePtrMap.insert(devName, netDetail); -// netDetail->show(); -//} - -//void MainWindow::showAddOtherWlanWidget(QString devName) -//{ -// qDebug() << "showAddOtherWlanWidget! devName = " << devName; -// if (m_addOtherPagePtrMap.contains(devName)) { -// if (m_addOtherPagePtrMap[devName] != nullptr) { -// qDebug() << "showAddOtherWlanWidget" << devName << "already create,just raise"; - -// KWindowSystem::raiseWindow(m_addOtherPagePtrMap[devName]->winId()); -// return; -// } -// } - -//#if 0 -// NetDetail *netDetail = new NetDetail(devName, "", "", false, true, true, this); -// connect(netDetail, &NetDetail::createPageClose, [&](QString interfaceName){ -// if (m_addOtherPagePtrMap.contains(interfaceName)) { -// m_addOtherPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_addOtherPagePtrMap.insert(devName, netDetail); -// netDetail->show(); -//#endif - -// JoinHiddenWiFiPage *hiddenWiFi =new JoinHiddenWiFiPage(devName); -// connect(hiddenWiFi, &JoinHiddenWiFiPage::hiddenWiFiPageClose, [&](QString interfaceName){ -// if (m_addOtherPagePtrMap.contains(interfaceName)) { -// m_addOtherPagePtrMap[interfaceName] = nullptr; -// } -// }); -// m_addOtherPagePtrMap.insert(devName, hiddenWiFi); -// connect(hiddenWiFi, &JoinHiddenWiFiPage::showWlanList, this, &MainWindow::onShowMainWindow); -// hiddenWiFi->show(); -//} - -//有线连接断开 -void vpnMainWindow::activateVpn(const QString& connUuid) -{ - m_vpnPage->activateVpn(connUuid); -} -void vpnMainWindow::deactivateVpn(const QString& connUuid) -{ - m_vpnPage->deactivateVpn(connUuid); -} - diff --git a/src/frontend/vpnmainwindow.h b/src/frontend/vpnmainwindow.h deleted file mode 100644 index 4a898413..00000000 --- a/src/frontend/vpnmainwindow.h +++ /dev/null @@ -1,167 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * Copyright (C) 2022 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 VPNMAINWINDOW_H -#define VPNMAINWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vpnpage.h" -#include "mainwindow.h" - -#ifdef WITHKYSEC -#include -#include -#endif - -//enum IconActiveType { -// NOT_CONNECTED = 0, -// LAN_CONNECTED, -// WLAN_CONNECTED, -// LAN_CONNECTED_LIMITED, -// WLAN_CONNECTED_LIMITED, -// ACTIVATING, -//}; - -//const QByteArray TRANSPARENCY_GSETTINGS = "org.ukui.control-center.personalise"; - -class VpnPage; - -class vpnMainWindow : public QMainWindow -{ - Q_OBJECT -public: - explicit vpnMainWindow(QWidget *parent = nullptr); - void showMainwindow(); - void hideMainwindow(); - - void getVirtualList(QMap> &map); - -// void setWiredDefaultDevice(QString deviceName); - -// //有线连接断开 - void activateVpn(const QString& connUuid); - void deactivateVpn(const QString& connUuid); - -// //唤起属性页 根据网卡类型 参数2 为ssid/uuid -// void showPropertyWidget(QString devName, QString ssid); -// //唤起新建有线连接界面 -// void showCreateWiredConnectWidget(const QString devName); - -Q_SIGNALS: -// //设备插拔 -// void deviceStatusChanged(); -// //设备名称变化 -// void deviceNameChanged(QString oldName, QString newName, int type); - void vpnAdd(QString devName, QStringList info); - void vpnRemove(QString dbusPath); - void vpnUpdate(QString devName, QStringList info); - void vpnActiveConnectionStateChanged(QString devName, QString uuid, int status); -// void activateFailed(QString errorMessage); -// void deactivateFailed(QString errorMessage); - void mainWindowVisibleChanged(const bool &visible); -// //列表排序 -// void timeToUpdate(); -public Q_SLOTS: - -protected: -// void keyPressEvent(QKeyEvent *event); - bool eventFilter(QObject *watched, QEvent *event) override; - void paintEvent(QPaintEvent *event); - -private: - void firstlyStart(); //一级启动 - void secondaryStart(); //二级启动 - bool m_loadFinished = false; //是否二级启动已执行完 - QTimer * m_secondaryStartTimer = nullptr; //执行二级启动的倒计时 - void initPlatform(); - void initWindowProperties(); - void initTransparency(); - void paintWithTrans(); - void initUI(); - void initDbusConnnect(); - void initTrayIcon(); -// void resetTrayIconTool(); - void initWindowTheme(); -// void resetWindowTheme(); -// void showControlCenter(); - void showByWaylandHelper(); - void setCentralWidgetType(IconActiveType iconStatus); - double m_transparency=1.0; //透明度 - QGSettings * m_transGsettings; //透明度配置文件 - int m_currentIconIndex = 0; - QList m_loadIcons; - QTimer *m_iconTimer = nullptr; - -// //主窗口的主要构成控件 - QWidget * m_vpnWidget = nullptr; -// QHBoxLayout * m_tabBarLayout = nullptr; - QLabel * m_lanLabel = nullptr; - VpnPage * m_vpnPage = nullptr; - QVBoxLayout * m_vpnLayout = nullptr; - - //监听主题的Gsettings - QGSettings * m_styleGsettings = nullptr; - -// //获取和重置窗口位置 - void resetWindowPosition(); - QDBusInterface * m_positionInterface = nullptr; - -// //托盘图标,托盘图标右键菜单 - QSystemTrayIcon * m_vpnTrayIcon = nullptr; - QMenu * m_vpnTrayIconMenu = nullptr; -// QAction * m_showMainwindowAction = nullptr; -// QAction * m_showSettingsAction = nullptr; - -// bool m_lanIsLoading = false; - - bool m_isShowInCenter = false; - - IconActiveType m_iconStatus = IconActiveType::NOT_CONNECTED; - - QMap m_createPagePtrMap; -//// QMap m_addOtherPagePtrMap; -// QMap m_addOtherPagePtrMap; - -public Q_SLOTS: -// void onShowMainWindow(int type); - -private Q_SLOTS: - void onTransChanged(); - void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); -// void onShowMainwindowActionTriggled(); -// void onShowSettingsActionTriggled(); - void onThemeChanged(const QString &key); - void onRefreshTrayIcon(); -// void onSetTrayIconLoading(); -// void onLanConnectStatusToChangeTrayIcon(int state); -// void onWlanConnectStatusToChangeTrayIcon(int state); -// void onConnectivityChanged(NetworkManager::Connectivity connectivity); -// void onTabletModeChanged(bool mode); -}; - -#endif // MAINWINDOW_H diff --git a/src/main.cpp b/src/main.cpp index bf2a23bf..33c8f724 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,8 @@ */ #include "mainwindow.h" -#include "vpnmainwindow.h" #include "dbusadaptor.h" +#include "vpndbusadaptor.h" #include #include #include "qt-single-application.h" @@ -30,6 +30,8 @@ #include "xatom-helper.h" #endif +#include "vpnobject.h" + #define LOG_IDENT "ukui_kylin_nm" const QString QT_TRANSLATE_FILE = "/usr/share/qt5/translations/qt_zh_CN.qm"; @@ -148,19 +150,11 @@ int main(int argc, char *argv[]) ::usleep(1000); } - vpnMainWindow vpnwindow; - vpnwindow.setProperty("useStyleWindowManager", false); //禁用拖动 - MainWindow w; a.setActivationWindow(&w); w.setProperty("useStyleWindowManager", false); //禁用拖动 - //设置窗口无边框,阴影 -// MotifWmHints window_hints; -// window_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; -// window_hints.functions = MWM_FUNC_ALL; -// window_hints.decorations = MWM_DECOR_BORDER; -// XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), window_hints); + vpnObject vnpobject; w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint/* | Qt::X11BypassWindowManagerHint*/); @@ -168,8 +162,13 @@ int main(int argc, char *argv[]) DbusAdaptor adaptor(&w); Q_UNUSED(adaptor); + VpnDbusAdaptor vpnAdaptor(&vnpobject); + Q_UNUSED(vpnAdaptor); + auto connection = QDBusConnection::sessionBus(); - if (!connection.registerService("com.kylin.network") || !connection.registerObject("/com/kylin/network", &w)) { + if (!connection.registerService("com.kylin.network") + || !connection.registerObject("/com/kylin/network", &w) + || !connection.registerObject("/com/kylin/vpnTool", &vnpobject)) { qCritical() << "QDbus register service failed reason:" << connection.lastError(); }