- 简要展示激活信息,提供激活信息入口 - 修复部分代码问题 - 调整控制中心弹窗按钮问题 - 修复快捷键 提取desktop entry Exec过滤%u,%f问题 - 修复检查出内存泄漏的问题
430 lines
16 KiB
Diff
430 lines
16 KiB
Diff
From 19ed0f093a304c99f7b54dc66ef0c05ceb3162bd Mon Sep 17 00:00:00 2001
|
|
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
|
Date: Mon, 7 Nov 2022 15:44:34 +0800
|
|
Subject: [PATCH 1/5] feat(license): briefly displays the license
|
|
information,provide access to the activation interface
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 简要展示激活信息,提供激活信息入口
|
|
---
|
|
plugins/system/CMakeLists.txt | 6 +
|
|
.../data/com.kylinsec.Kiran.LicenseObject.xml | 45 +++++++
|
|
.../system-information/system-information.cpp | 124 +++++++++++++++---
|
|
.../system-information/system-information.h | 8 +-
|
|
.../system-information/system-information.ui | 85 ++++++++++++
|
|
5 files changed, 249 insertions(+), 19 deletions(-)
|
|
create mode 100644 plugins/system/data/com.kylinsec.Kiran.LicenseObject.xml
|
|
|
|
diff --git a/plugins/system/CMakeLists.txt b/plugins/system/CMakeLists.txt
|
|
index fb49f4b..619f469 100644
|
|
--- a/plugins/system/CMakeLists.txt
|
|
+++ b/plugins/system/CMakeLists.txt
|
|
@@ -18,9 +18,15 @@ file(GLOB_RECURSE SYSTEM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
|
|
|
qt5_create_translation(SYSTEM_QM ${CMAKE_CURRENT_SOURCE_DIR} .//translations/kiran-cpanel-system.zh_CN.ts)
|
|
|
|
+kiran_qt5_add_dbus_interface_ex(LICENSE_DBUS_SRC
|
|
+ data/com.kylinsec.Kiran.LicenseObject.xml
|
|
+ dbus_license_dbus
|
|
+ DBusLicenseObject)
|
|
+
|
|
add_library(${TARGET_NAME} SHARED
|
|
${SYSTEM_SRC}
|
|
${SYSTEM_QM}
|
|
+ ${LICENSE_DBUS_SRC}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/data/res.qrc)
|
|
|
|
target_include_directories(${TARGET_NAME} PRIVATE
|
|
diff --git a/plugins/system/data/com.kylinsec.Kiran.LicenseObject.xml b/plugins/system/data/com.kylinsec.Kiran.LicenseObject.xml
|
|
new file mode 100644
|
|
index 0000000..cf3760f
|
|
--- /dev/null
|
|
+++ b/plugins/system/data/com.kylinsec.Kiran.LicenseObject.xml
|
|
@@ -0,0 +1,45 @@
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
|
+<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
|
+ <interface name="com.kylinsec.Kiran.LicenseObject">
|
|
+
|
|
+ <method name="GetLicense">
|
|
+ <arg name="license_json" direction="out" type="s">
|
|
+ <summary>The license info contain activation status, service status, activation code, machine code and activation type etc..</summary>
|
|
+ </arg>
|
|
+ <description>Get the license info.</description>
|
|
+ </method>
|
|
+
|
|
+ <method name="ActivateByActivationCode">
|
|
+ <arg name="activation_code" direction="in" type="s">
|
|
+ <summary>The activation code.</summary>
|
|
+ </arg>
|
|
+ <description>Activate by activation code.</description>
|
|
+ </method>
|
|
+
|
|
+ <method name="ActivateByUsbKey">
|
|
+ <arg name="ukey_json" direction="out" type="s">
|
|
+ <summary>The usb key info contain authorized points and remaining points.</summary>
|
|
+ </arg>
|
|
+ <description>Activate by usb key.</description>
|
|
+ </method>
|
|
+
|
|
+ <method name="ActivateOnLine">
|
|
+ <arg name="host" direction="in" type="s">
|
|
+ <summary>The host used to request activation code.</summary>
|
|
+ </arg>
|
|
+ <arg name="service_uid" direction="in" type="s">
|
|
+ <summary>The service uid to request activation code.</summary>
|
|
+ </arg>
|
|
+ <description>Activate on-line.</description>
|
|
+ </method>
|
|
+
|
|
+ <signal name="LicenseChanged">
|
|
+ <arg name="placeholder" type="b">
|
|
+ <summary>The placeholder.</summary>
|
|
+ </arg>
|
|
+ <description>The license info is changed, you need call function GetLicense to get the newest license info.</description>
|
|
+ </signal>
|
|
+
|
|
+ </interface>
|
|
+</node>
|
|
diff --git a/plugins/system/src/pages/system-information/system-information.cpp b/plugins/system/src/pages/system-information/system-information.cpp
|
|
index 4409040..bf36086 100644
|
|
--- a/plugins/system/src/pages/system-information/system-information.cpp
|
|
+++ b/plugins/system/src/pages/system-information/system-information.cpp
|
|
@@ -14,11 +14,14 @@
|
|
|
|
#include "system-information.h"
|
|
#include "dbus-wrapper/system-info-dbus.h"
|
|
+#include "dbus_license_dbus.h"
|
|
#include "license-agreement.h"
|
|
#include "ui_system-information.h"
|
|
|
|
-
|
|
#include <kiran-log/qt5-log-i.h>
|
|
+#include <style-property.h>
|
|
+#include <QDBusConnection>
|
|
+#include <QDBusConnectionInterface>
|
|
#include <QDateTime>
|
|
#include <QDesktopWidget>
|
|
#include <QFont>
|
|
@@ -26,7 +29,10 @@
|
|
#include <QJsonObject>
|
|
#include <QJsonValue>
|
|
#include <QPainter>
|
|
-#include <style-property.h>
|
|
+#include <QDateTime>
|
|
+#include <QProcess>
|
|
+#include <kiran-message-box.h>
|
|
+
|
|
#define HOST_NAME "host_name"
|
|
#define ARCH "arch"
|
|
#define KERNEL_VERSION "kernel_version"
|
|
@@ -34,7 +40,7 @@
|
|
#define KERNEL_RELEASE "kernel_release"
|
|
#define PRODUCT_RELEASE "product_release"
|
|
|
|
-SystemInformation::SystemInformation(QWidget *parent)
|
|
+SystemInformation::SystemInformation(QWidget* parent)
|
|
: QWidget(parent), ui(new Ui::SystemInformation), hostNameWidget(nullptr), licenseAgreement(nullptr)
|
|
{
|
|
ui->setupUi(this);
|
|
@@ -78,9 +84,10 @@ void SystemInformation::init()
|
|
});
|
|
// clang-format on
|
|
connect(ui->btn_change_name, &QPushButton::clicked, this, &SystemInformation::handleChangeHostName);
|
|
- Kiran::StylePropertyHelper::setButtonType(ui->btn_change_name,Kiran::BUTTON_Default);
|
|
- Kiran::StylePropertyHelper::setButtonType(ui->btn_EULA,Kiran::BUTTON_Default);
|
|
- Kiran::StylePropertyHelper::setButtonType(ui->btn_version_license,Kiran::BUTTON_Default);
|
|
+ Kiran::StylePropertyHelper::setButtonType(ui->btn_change_name, Kiran::BUTTON_Default);
|
|
+ Kiran::StylePropertyHelper::setButtonType(ui->btn_EULA, Kiran::BUTTON_Default);
|
|
+ Kiran::StylePropertyHelper::setButtonType(ui->btn_version_license, Kiran::BUTTON_Default);
|
|
+ Kiran::StylePropertyHelper::setButtonType(ui->btn_license_show, Kiran::BUTTON_Default);
|
|
}
|
|
|
|
bool SystemInformation::initUI()
|
|
@@ -97,7 +104,7 @@ bool SystemInformation::initUI()
|
|
}
|
|
else
|
|
{
|
|
- QString hostname,arch,systemVersion,kernelVersion;
|
|
+ QString hostname, arch, systemVersion, kernelVersion;
|
|
parseSoftwareInfoJson(systemInfoJson,
|
|
hostname,
|
|
arch,
|
|
@@ -108,16 +115,26 @@ bool SystemInformation::initUI()
|
|
ui->lab_system_arch_info->setText(arch);
|
|
ui->lab_system_version_info->setText(systemVersion);
|
|
ui->lab_core_version_info->setText(kernelVersion);
|
|
+ }
|
|
|
|
+ QString licenseDesc;
|
|
+ if (!checkLicensEnable() || !getLicenseDesc(licenseDesc))
|
|
+ {
|
|
+ ui->widget_license->setVisible(false);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ ui->lab_license_status->setText(licenseDesc);
|
|
+ connect(ui->btn_license_show, &QPushButton::clicked, this, &SystemInformation::handleShowLicenseDialog);
|
|
}
|
|
|
|
- QList<QLabel *> labels = {ui->lab_name_info,ui->lab_core_version_info, ui->lab_system_arch_info,ui->lab_system_version_info};
|
|
- for (auto label : labels)
|
|
+ QList<QLabel*> labels = {ui->lab_name_info, ui->lab_core_version_info, ui->lab_system_arch_info, ui->lab_system_version_info, ui->lab_license_status};
|
|
+ for (QLabel* label : labels)
|
|
{
|
|
label->setStyleSheet("color:#919191;font-family: \"Noto Sans CJK SC regular\";");
|
|
}
|
|
|
|
- auto kiranFrames = findChildren<KiranFrame *>();
|
|
+ auto kiranFrames = findChildren<KiranFrame*>();
|
|
for (auto frame : kiranFrames)
|
|
{
|
|
frame->setRadius(6);
|
|
@@ -151,25 +168,90 @@ void SystemInformation::parseSoftwareInfoJson(QString jsonString,
|
|
return;
|
|
}
|
|
QJsonObject rootObject = jsonDocument.object();
|
|
- if( rootObject.contains("host_name") && rootObject["host_name"].isString() )
|
|
+ if (rootObject.contains("host_name") && rootObject["host_name"].isString())
|
|
{
|
|
hostName = rootObject["host_name"].toString();
|
|
}
|
|
- if( rootObject.contains("arch") && rootObject["arch"].isString() )
|
|
+ if (rootObject.contains("arch") && rootObject["arch"].isString())
|
|
{
|
|
arch = rootObject["arch"].toString();
|
|
}
|
|
- if( rootObject.contains("product_release") && rootObject["product_release"].isString() )
|
|
+ if (rootObject.contains("product_release") && rootObject["product_release"].isString())
|
|
{
|
|
systemVersion = rootObject["product_release"].toString();
|
|
}
|
|
- if( rootObject.contains("kernal_name") && rootObject["kernal_name"].isString() &&
|
|
- rootObject.contains("kernel_release") && rootObject["kernel_release"].isString() )
|
|
+ if (rootObject.contains("kernal_name") && rootObject["kernal_name"].isString() &&
|
|
+ rootObject.contains("kernel_release") && rootObject["kernel_release"].isString())
|
|
{
|
|
kernelVersion = rootObject["kernal_name"].toString() + " " + rootObject["kernel_release"].toString();
|
|
}
|
|
}
|
|
|
|
+bool SystemInformation::checkLicensEnable()
|
|
+{
|
|
+ QDBusConnection dbusConn = QDBusConnection::systemBus();
|
|
+ return dbusConn.interface()->isServiceRegistered("com.kylinsec.Kiran.LicenseManager");
|
|
+}
|
|
+
|
|
+bool SystemInformation::getLicenseDesc(QString& licenseStatus)
|
|
+{
|
|
+ DBusLicenseObject dBusLicenseObject("com.kylinsec.Kiran.LicenseManager",
|
|
+ "/com/kylinsec/Kiran/LicenseObject/KylinSecOS",
|
|
+ QDBusConnection::systemBus());
|
|
+ auto reply = dBusLicenseObject.GetLicense();
|
|
+ reply.waitForFinished();
|
|
+ if (reply.isError())
|
|
+ {
|
|
+ KLOG_ERROR() << "KylinSecOS GetLicense failed:" << reply.error();
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ QString licenseJson = reply.value();
|
|
+ QJsonDocument jsonDocument = QJsonDocument::fromJson(licenseJson.toUtf8());
|
|
+ QJsonObject rootObj = jsonDocument.object();
|
|
+ QStringList keys = rootObj.keys();
|
|
+
|
|
+ QSet<QString> keySet = {"expired_time","activation_status"};
|
|
+ for( auto key:keySet )
|
|
+ {
|
|
+ if( !keys.contains(key) )
|
|
+ {
|
|
+ KLOG_ERROR() << "KylinSecOS GetLicense missing key:" << key;
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ QVariant expiredTimeVar = rootObj["expired_time"].toVariant();
|
|
+ qlonglong expiredTimeSinceEpoch = expiredTimeVar.toULongLong();
|
|
+
|
|
+ QVariant activationStatusVar = rootObj["activation_status"].toVariant();
|
|
+ qulonglong activationStatus = activationStatusVar.toULongLong();
|
|
+
|
|
+ QDateTime expiredTime = QDateTime::fromSecsSinceEpoch(expiredTimeSinceEpoch);
|
|
+ if (activationStatus == 0) //未激活
|
|
+ {
|
|
+ licenseStatus = tr("UnActivated");
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
+
|
|
+ if( currentDateTime > expiredTime ) //激活码已过期
|
|
+ {
|
|
+ licenseStatus = tr("Activation code has expired");
|
|
+ }
|
|
+ else if( expiredTime.date().year() >= 2100 ) //永久激活
|
|
+ {
|
|
+ licenseStatus = tr("Permanently activated");
|
|
+ }
|
|
+ else //已激活
|
|
+ {
|
|
+ licenseStatus = tr("Activated");
|
|
+ }
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
/**
|
|
* @brief SystemInformation::onBtnchangeHostName: 当点击更改用户名后的槽函数
|
|
*/
|
|
@@ -200,13 +282,21 @@ void SystemInformation::updateHostName(bool isChanged, QString name)
|
|
}
|
|
}
|
|
|
|
+void SystemInformation::handleShowLicenseDialog()
|
|
+{
|
|
+ if( !QProcess::startDetached("/usr/bin/ksl-os-gui") )
|
|
+ {
|
|
+ KiranMessageBox::message(this, tr("Error"), tr("Failed to open the license activator"),KiranMessageBox::Ok);
|
|
+ }
|
|
+}
|
|
+
|
|
/**
|
|
* @brief 事件监听,当收到激活向导窗口或者授权信息窗口的关闭事件时,释放窗口内存
|
|
* @param obj 事件对象
|
|
* @param obj 事件
|
|
* @return 是否过滤
|
|
*/
|
|
-bool SystemInformation::eventFilter(QObject *obj, QEvent *event)
|
|
+bool SystemInformation::eventFilter(QObject* obj, QEvent* event)
|
|
{
|
|
if (obj == hostNameWidget && event->type() == QEvent::Close)
|
|
{
|
|
@@ -218,5 +308,5 @@ bool SystemInformation::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
QSize SystemInformation::sizeHint() const
|
|
{
|
|
- return {500,657};
|
|
+ return {500, 657};
|
|
}
|
|
diff --git a/plugins/system/src/pages/system-information/system-information.h b/plugins/system/src/pages/system-information/system-information.h
|
|
index c15561c..d46ad74 100644
|
|
--- a/plugins/system/src/pages/system-information/system-information.h
|
|
+++ b/plugins/system/src/pages/system-information/system-information.h
|
|
@@ -43,9 +43,13 @@ private:
|
|
QString &systemVersion,
|
|
QString &kernelVersion);
|
|
|
|
-private slots :
|
|
- void handleChangeHostName(void);
|
|
+ bool checkLicensEnable();
|
|
+ bool getLicenseDesc(QString& licenseStatus);
|
|
+
|
|
+private slots:
|
|
+ void handleChangeHostName(void);
|
|
void updateHostName(bool isChanged, QString name);
|
|
+ void handleShowLicenseDialog();
|
|
|
|
protected:
|
|
bool eventFilter(QObject *obj, QEvent *event);
|
|
diff --git a/plugins/system/src/pages/system-information/system-information.ui b/plugins/system/src/pages/system-information/system-information.ui
|
|
index b036ab6..7dd5cdd 100644
|
|
--- a/plugins/system/src/pages/system-information/system-information.ui
|
|
+++ b/plugins/system/src/pages/system-information/system-information.ui
|
|
@@ -423,6 +423,91 @@
|
|
</layout>
|
|
</widget>
|
|
</item>
|
|
+ <item>
|
|
+ <widget class="KiranFrame" name="widget_license" native="true">
|
|
+ <property name="minimumSize">
|
|
+ <size>
|
|
+ <width>0</width>
|
|
+ <height>40</height>
|
|
+ </size>
|
|
+ </property>
|
|
+ <property name="maximumSize">
|
|
+ <size>
|
|
+ <width>16777215</width>
|
|
+ <height>40</height>
|
|
+ </size>
|
|
+ </property>
|
|
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
|
|
+ <property name="spacing">
|
|
+ <number>0</number>
|
|
+ </property>
|
|
+ <property name="leftMargin">
|
|
+ <number>10</number>
|
|
+ </property>
|
|
+ <property name="topMargin">
|
|
+ <number>0</number>
|
|
+ </property>
|
|
+ <property name="rightMargin">
|
|
+ <number>10</number>
|
|
+ </property>
|
|
+ <property name="bottomMargin">
|
|
+ <number>0</number>
|
|
+ </property>
|
|
+ <item>
|
|
+ <widget class="QLabel" name="label_2">
|
|
+ <property name="text">
|
|
+ <string>Activation status:</string>
|
|
+ </property>
|
|
+ </widget>
|
|
+ </item>
|
|
+ <item>
|
|
+ <spacer name="horizontalSpacer_5">
|
|
+ <property name="orientation">
|
|
+ <enum>Qt::Horizontal</enum>
|
|
+ </property>
|
|
+ <property name="sizeHint" stdset="0">
|
|
+ <size>
|
|
+ <width>40</width>
|
|
+ <height>20</height>
|
|
+ </size>
|
|
+ </property>
|
|
+ </spacer>
|
|
+ </item>
|
|
+ <item>
|
|
+ <widget class="QLabel" name="lab_license_status">
|
|
+ <property name="text">
|
|
+ <string>TextLabel</string>
|
|
+ </property>
|
|
+ </widget>
|
|
+ </item>
|
|
+ <item>
|
|
+ <widget class="QPushButton" name="btn_license_show">
|
|
+ <property name="sizePolicy">
|
|
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
+ <horstretch>0</horstretch>
|
|
+ <verstretch>0</verstretch>
|
|
+ </sizepolicy>
|
|
+ </property>
|
|
+ <property name="minimumSize">
|
|
+ <size>
|
|
+ <width>56</width>
|
|
+ <height>28</height>
|
|
+ </size>
|
|
+ </property>
|
|
+ <property name="maximumSize">
|
|
+ <size>
|
|
+ <width>56</width>
|
|
+ <height>28</height>
|
|
+ </size>
|
|
+ </property>
|
|
+ <property name="text">
|
|
+ <string>Show</string>
|
|
+ </property>
|
|
+ </widget>
|
|
+ </item>
|
|
+ </layout>
|
|
+ </widget>
|
|
+ </item>
|
|
<item>
|
|
<widget class="KiranFrame" name="widget_EULA" native="true">
|
|
<property name="minimumSize">
|
|
--
|
|
2.33.0
|
|
|