* BUG:#180680 完成控制面板面板架构前后端分离以及单元测试

* BUG:#194394域用户通过控制面板修改自身密码时,提示语为英文
* 需求号: 无
* 其他改动说明:无
This commit is contained in:
zhoubin 2023-11-15 18:18:25 +08:00
parent ef03b50f61
commit da2451b24d
23 changed files with 1208 additions and 385 deletions

View File

@ -19,6 +19,8 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
LIBS += -lpam
# 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.

View File

@ -1,3 +1,148 @@
/*change otheruser password on pam*/
#include <stdio.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <glib.h>
#include <string.h>
static const char *new_password = "";
static char *error = "";
static int ni_conv (int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
struct pam_response *responses;
int count;
// assert (NULL != non_interactive_password);
if (num_msg <= 0 || num_msg >= PAM_MAX_NUM_MSG) {
printf("bad number of messages %d <= 0 || >= %d\n", num_msg, PAM_MAX_NUM_MSG);
*resp = NULL;
return PAM_CONV_ERR;
}
responses = (struct pam_response *) calloc ((size_t) num_msg, sizeof (*responses));
if (NULL == responses) {
return PAM_BUF_ERR;
}
//循环每个消息
for (count=0; count < num_msg; count++) {
//初始化响应变量
responses[count].resp_retcode = 0;
// printf("message[%d]: %d %s\n", count, msg[count]->msg_style, msg[count]->msg);
//根据消息类型处理消息
switch (msg[count]->msg_style) {
//回显消息,从标准输入获取数据并显示在屏幕上,一般是交互的名称信息,如用户名等
case PAM_PROMPT_ECHO_ON:
fprintf (stderr, "PAM modules requesting echoing are not supported.\n");
goto failed_conversation;
//从标准输入获取不回显数据,一般是输入密码
case PAM_PROMPT_ECHO_OFF:
responses[count].resp = strdup (new_password);
if (NULL == responses[count].resp) {
goto failed_conversation;
}
break;
//回显PAM模块传递的错误消息
case PAM_ERROR_MSG:
if ((NULL == msg[count]->msg)) {
goto failed_conversation;
} else {
error = strdup(msg[count]->msg);
}
responses[count].resp = NULL;
break;
//回显PAM模块传递的文本消息
case PAM_TEXT_INFO:
if ((NULL == msg[count]->msg)) {
goto failed_conversation;
} else {
error = strdup(msg[count]->msg);
}
responses[count].resp = NULL;
break;
default:
(void) fprintf (stderr, ("conversation type %d not supported.\n"), msg[count]->msg_style);
goto failed_conversation;
}
}
*resp = responses;
return PAM_SUCCESS;
failed_conversation:
for (count=0; count < num_msg; count++) {
if (NULL != responses[count].resp) {
memset (responses[count].resp, 0, strlen (responses[count].resp));
free (responses[count].resp);
responses[count].resp = NULL;
}
}
free (responses);
*resp = NULL;
return PAM_CONV_ERR;
}
struct pam_conv conv;
int main(int argc, char *argv[])
{
int ret = 0;
pam_handle_t * pamh = NULL;
char * username;
if (argc == 3) {
username = argv[1];
new_password = argv[2];
} else {
printf("missing parameter!\n");
return -1;
}
//会话函数传递到PAM模块中在模块中通过pam_get_item获取并调用
conv.conv = ni_conv;
conv.appdata_ptr = NULL;
//
if ((pam_start("passwd", username, &conv, &pamh)) != PAM_SUCCESS){
return 0;
}
//
ret = pam_chauthtok(pamh, 0);
if (ret == PAM_SUCCESS){
if (error != "") {
printf("%s\n", error);
free(error);
}
} else {
if (error == "") {
printf("Unable to modify password!\n");
} else {
printf("%s\n", error);
free(error);
}
}
//结束PAM
ret = pam_end(pamh, ret);
return ret;
}
/*end pam*/
#include <QCoreApplication>
#include <glib.h>
@ -8,22 +153,22 @@ PasswdHandler *passwd_handler = NULL;
static void auth_cb (PasswdHandler *passwd_handler, GError *error, gpointer user_data);
static void chpasswd_cb (PasswdHandler *passwd_handler, GError *error, gpointer user_data);
int main(int argc, char *argv[])
{
//int main(int argc, char *argv[])
//{
if (argc != 3)
{
return -1;
}
// if (argc != 3)
// {
// return -1;
// }
QCoreApplication a(argc, argv);
// QCoreApplication a(argc, argv);
passwd_handler = passwd_init();
// passwd_handler = passwd_init();
passwd_change_password(passwd_handler, argv[1], argv[2], chpasswd_cb, NULL);
// passwd_change_password(passwd_handler, argv[1], argv[2], chpasswd_cb, NULL);
return a.exec();
}
// return a.exec();
//}
static void
auth_cb (PasswdHandler *passwd_handler, GError *error, gpointer user_data)

View File

@ -19,6 +19,8 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
LIBS += -lpam
# 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.

View File

@ -3,27 +3,178 @@
#include <glib.h>
#include "run-passwd.h"
/*using pam change password*/
#include <stdio.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <string.h>
static const char *non_interactive_password = "";
static const char *new_password = "";
static int isCurrentPwd = 0;
static char *error = "";
static int changeCurrent_conv (int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
struct pam_response *responses;
int count;
// assert (NULL != non_interactive_password);
if (num_msg <= 0 || num_msg >= PAM_MAX_NUM_MSG) {
printf("bad number of messages %d <= 0 || >= %d\n", num_msg, PAM_MAX_NUM_MSG);
*resp = NULL;
return PAM_CONV_ERR;
}
responses = (struct pam_response *) calloc ((size_t) num_msg, sizeof (*responses));
if (NULL == responses) {
return PAM_BUF_ERR;
}
//循环每个消息
for (count=0; count < num_msg; count++) {
//初始化响应变量
responses[count].resp_retcode = 0;
// printf("message[%d]: %d %s\n", count, msg[count]->msg_style, msg[count]->msg);
//根据消息类型处理消息
switch (msg[count]->msg_style) {
//回显消息,从标准输入获取数据并显示在屏幕上,一般是交互的名称信息,如用户名等
case PAM_PROMPT_ECHO_ON:
fprintf (stderr, "PAM modules requesting echoing are not supported.\n");
goto failed_conversation;
//从标准输入获取不回显数据,一般是输入密码
case PAM_PROMPT_ECHO_OFF:
if (isCurrentPwd == 0){
isCurrentPwd = 1;
responses[count].resp = strdup (non_interactive_password);
} else {
responses[count].resp = strdup (new_password);
}
if (NULL == responses[count].resp) {
goto failed_conversation;
}
break;
//回显PAM模块传递的错误消息
case PAM_ERROR_MSG:
if ((NULL == msg[count]->msg)) {
goto failed_conversation;
} else {
error = strdup(msg[count]->msg);
}
responses[count].resp = NULL;
break;
//回显PAM模块传递的文本消息
case PAM_TEXT_INFO:
if ((NULL == msg[count]->msg)) {
goto failed_conversation;
} else {
error = strdup(msg[count]->msg);
}
responses[count].resp = NULL;
break;
default:
(void) fprintf (stderr, ("conversation type %d not supported.\n"), msg[count]->msg_style);
goto failed_conversation;
}
}
*resp = responses;
return PAM_SUCCESS;
failed_conversation:
for (count=0; count < num_msg; count++) {
if (NULL != responses[count].resp) {
memset (responses[count].resp, 0, strlen (responses[count].resp));
free (responses[count].resp);
responses[count].resp = NULL;
}
}
free (responses);
*resp = NULL;
return PAM_CONV_ERR;
}
int main(int argc, char *argv[])
{
struct pam_conv conv;
int ret = 0;
pam_handle_t * pamh = NULL;
const char *username = g_get_user_name();
if (argc == 3) {
non_interactive_password = argv[1];
new_password = argv[2];
} else {
printf("missing parameter!\n");
return -1;
}
//会话函数传递到PAM模块中在模块中通过pam_get_item获取并调用
conv.conv = changeCurrent_conv;
conv.appdata_ptr = NULL;
//
if ((pam_start("passwd", username, &conv, &pamh)) != PAM_SUCCESS){
return 0;
}
//
ret = pam_chauthtok(pamh, 0);
if (ret == PAM_SUCCESS){
if (error != "") {
printf("%s\n", error);
free(error);
}
} else {
if (error == "") {
printf("Unable to modify password!\n");
} else {
printf("%s\n", error);
free(error);
}
}
//结束PAM
ret = pam_end(pamh, ret);
return ret;
}
/*end pam*/
PasswdHandler *passwd_handler = NULL;
static void auth_cb (PasswdHandler *passwd_handler, GError *error, gpointer user_data);
static void chpasswd_cb (PasswdHandler *passwd_handler, GError *error, gpointer user_data);
int main(int argc, char *argv[])
{
//int main(int argc, char *argv[])
//{
if (argc != 3)
{
return -1;
}
// if (argc != 3)
// {
// return -1;
// }
QCoreApplication a(argc, argv);
// QCoreApplication a(argc, argv);
passwd_handler = passwd_init ();
// passwd_handler = passwd_init ();
passwd_authenticate (passwd_handler, argv[1], auth_cb, argv[2]);
// passwd_authenticate (passwd_handler, argv[1], auth_cb, argv[2]);
return a.exec();
}
// return a.exec();
//}
static void
auth_cb (PasswdHandler *passwd_handler,

View File

@ -194,10 +194,10 @@ void AuthPAM::onSockRead()
Q_EMIT showPrompt(message.msg, Auth::PromptTypeQuestion);
break;
case PAM_ERROR_MSG:
Q_EMIT showMessage(message.msg, Auth::MessageTypeInfo);
Q_EMIT showMessage(message.msg, Auth::MessageTypeError);
break;
case PAM_TEXT_INFO:
Q_EMIT showMessage(message.msg, Auth::MessageTypeError);
Q_EMIT showMessage(message.msg, Auth::MessageTypeInfo);
break;
}
}

View File

@ -34,7 +34,8 @@ void Widget::onShowMessage(const QString &message, Auth::MessageType type)
{
// qDebug() << "showMessage" << message;
accountlock = true;
printf("%s\n", message.toUtf8().data());
showMsg = message;
// printf("%s\n", message.toUtf8().data());
}
void Widget::onShowPrompt(const QString &prompt, Auth::PromptType type)
@ -44,14 +45,11 @@ void Widget::onShowPrompt(const QString &prompt, Auth::PromptType type)
void Widget::onAuthComplete()
{
if (!accountlock){
if(auth->isAuthenticated()){
// qDebug() << "Succes!\n";
// printf("Succes!\n");
} else {
if(!auth->isAuthenticated()) {
if (showMsg == "") {
printf("Failed!\n");
// qDebug() << "Failed!";
} else {
printf("%s\n", showMsg.toUtf8().data());
}
}

View File

@ -21,6 +21,8 @@ private:
bool accountlock;
QString showMsg = "";
private Q_SLOTS:
void onShowMessage(const QString &message, Auth::MessageType type);
void onShowPrompt(const QString &prompt, Auth::PromptType type);

View File

@ -0,0 +1,291 @@
{
"Name": "org.ukui.ukcc.session",
"Path": "/",
"Interfaces": "org.ukui.ukcc.session.interface",
"ukcc": [
{
"name": "account",
"visible": true,
"module_type": 0,
"theme_icon_name": "kylin-settings-account",
"local_icon_name": ":/img/homepage/kylin-settings-account.png",
"name_locale": {
"zh_CN" : "账户",
"en_US" : "Account",
"bo_CN" : "རྩིས་ཐོ།",
"mn_MN" : "ᠳᠠᠩᠰᠠ",
"zh_HK" : "賬戶"
},
"childnode": [
{
"name": "userinfo",
"visible": true
},
{
"name": "biometric"
},
{
"name": "networkaccount"
}
]
},
{
"name": "system",
"module_type": 1,
"theme_icon_name": "kylin-settings-system",
"local_icon_name": ":/img/homepage/kylin-settings-system.png",
"name_locale": {
"zh_CN" : "系统",
"en_US" : "System",
"bo_CN" : "ལམ་ལུགས།",
"mn_MN" : "ᠰᠢᠰᠲ᠋ᠧᠮ",
"zh_HK" : "系統"
},
"childnode": [
{
"name": "display"
},
{
"name": "audio"
},
{
"name": "power"
},
{
"name": "notice"
},
{
"name": "vino"
},
{
"name": "about"
},
{
"name": "touchCalibrate"
}
]
},
{
"name": "devices",
"module_type": 2,
"theme_icon_name": "kylin-settings-devices",
"local_icon_name": ":/img/homepage/kylin-settings-devices.png",
"name_locale": {
"zh_CN" : "设备",
"en_US" : "Devices",
"bo_CN" : "སྒྲིག་ཆས།",
"mn_MN" : "ᠳᠦᠬᠦᠬᠡᠷᠦᠮᠵᠢ",
"zh_HK" : "設備"
},
"childnode": [
{
"name": "blueTooth"
},
{
"name": "printer"
},
{
"name": "mouse"
},
{
"name": "touchpad"
},
{
"name": "touchScreen"
},
{
"name": "keyboard"
},
{
"name": "shortcut"
},
{
"name": ""
},
{
"name": "projection"
}
]
},
{
"name": "network",
"module_type": 3,
"theme_icon_name": "kylin-settings-network",
"local_icon_name": ":/img/homepage/kylin-settings-network.png",
"name_locale": {
"zh_CN" : "网络",
"en_US" : "Network",
"bo_CN" : "དྲ་རྒྱ།",
"mn_MN" : "ᠰᠦᠯᠵᠢᠶᠡᠨ ᠤ᠋ ᠪᠠᠢᠳᠠᠯ",
"zh_HK" : "網絡"
},
"childnode": [
{
"name": "netconnect"
},
{
"name": "wlanconnect"
},
{
"name": ""
},
{
"name": "proxy"
},
{
"name": "vpn"
},
{
"name": "mobilehotspot"
}
]
},
{
"name": "personalized",
"module_type": 4,
"theme_icon_name": "kylin-settings-personalized",
"local_icon_name": ":/img/homepage/kylin-settings-personalized.png",
"name_locale": {
"zh_CN" : "个性化",
"en_US" : "Personalized",
"bo_CN" : "རང་གཤིས་ཅན་",
"mn_MN" : "ᠦᠪᠡᠷᠮᠢᠴᠡᠬᠦᠯᠬᠦ",
"zh_HK" : "個性化"
},
"childnode": [
{
"name": "wallpaper"
},
{
"name": "theme"
},
{
"name": "screenlock"
},
{
"name": "screensaver"
},
{
"name": "fonts"
}
]
},
{
"name": "datetime",
"module_type": 5,
"theme_icon_name": "kylin-settings-datetime",
"local_icon_name": ":/img/homepage/kylin-settings-datetime.png",
"name_locale": {
"zh_CN" : "时间语言",
"en_US" : "Datetime",
"bo_CN" : "དུས་ཚོད་ཀྱི་དུས་ཚོད།",
"mn_MN" : "ᠴᠠᠭ ᠬᠤᠭᠤᠴᠠᠭᠠᠨ ᠤ᠋ ᠦᠭᠡ ᠬᠡᠯᠡ",
"zh_HK" : "時間語言"
},
"childnode": [
{
"name": "date"
},
{
"name": "area"
}
]
},
{
"name": "update",
"module_type": 6,
"theme_icon_name": "kylin-settings-update",
"local_icon_name": ":/img/homepage/kylin-settings-update.png",
"name_locale": {
"zh_CN" : "更新",
"en_US" : "Update",
"bo_CN" : "གསར་སྒྱུར།",
"mn_MN" : "ᠰᠢᠨᠡᠳᠬᠡᠬᠦ",
"zh_HK" : "更新"
},
"childnode": [
{
"name": "upgrade"
},
{
"name": "backup"
}
]
},
{
"name": "security",
"module_type": 7,
"theme_icon_name": "kylin-settings-security",
"local_icon_name": ":/img/homepage/kylin-settings-security.png",
"name_locale": {
"zh_CN" : "安全",
"en_US" : "Security",
"bo_CN" : "བདེ་འཇགས།",
"mn_MN" : "ᠠᠮᠤᠷ ᠳᠦᠪᠰᠢᠨ ᠰᠢᠨᠵᠢ",
"zh_HK" : "安全"
},
"childnode": [
{
"name": "securitycenter"
}
]
},
{
"name": "application",
"module_type": 8,
"theme_icon_name": "kylin-settings-application",
"local_icon_name": ":/img/homepage/kylin-settings-application.png",
"name_locale": {
"zh_CN" : "应用",
"en_US" : "Application",
"bo_CN" : "རེ་འདུན་ཞུ་ཡིག",
"mn_MN" : "ᠬᠡᠷᠡᠭᠯᠡᠬᠡᠨ ᠤ᠋ ᠰᠣᠹᠲ",
"zh_HK" : "應用"
},
"childnode": [
{
"name": "autoboot"
},
{
"name": "defaultapp"
}
]
},
{
"name": "search_f",
"module_type": 9,
"theme_icon_name": "kylin-settings-search",
"local_icon_name": ":/img/homepage/kylin-settings-search.png",
"name_locale": {
"zh_CN" : "搜索",
"en_US" : "Investigation",
"bo_CN" : "བརྟག་དཔྱད།",
"mn_MN" : "ᠬᠠᠢᠬᠤ",
"zh_HK" : "搜索"
},
"childnode": [
{
"name": "search"
}
]
},
{
"name": "commoninfo",
"module_type": 10,
"theme_icon_name": "kylin-settings-commoninfo",
"local_icon_name": ":/img/homepage/kylin-settings-commoninfo.png",
"name_locale": {
"zh_CN" : "通用",
"en_US" : "Commoninfo",
"bo_CN" : "ཀུན་སྤྱོད་",
"mn_MN" : "ᠨᠡᠢᠳᠡᠮ ᠬᠡᠷᠡᠭᠯᠡᠬᠦ",
"zh_HK" : "通用"
},
"childnode": [
{
"name": "boot"
}
]
}
]
}

10
debian/changelog vendored
View File

@ -1,3 +1,13 @@
ukui-control-center (4.10.0.0-ok1.8) nile; urgency=medium
* BUG:#180680 完成控制面板面板架构前后端分离以及单元测试
* BUG:#194394域用户通过控制面板修改自身密码时提示语为英文
* 需求号: 无
* 其他改动说明:无
* 其他改动影响域:无,重新编译,commit:b366d347
-- zhoubin <zhoubin@kylinos.cn> Wed, 15 Nov 2023 18:17:18 +0800
ukui-control-center (4.10.0.0-ok1.7) nile; urgency=medium
* BUG:#I7U9XD在设置时间同步模式调用dbus失败时会反选

4
debian/control vendored
View File

@ -7,7 +7,6 @@ Build-Depends: debhelper-compat (= 12),
libqt5svg5-dev,
libgsettings-qt-dev,
libglib2.0-dev,
libmatekbd-dev,
libqt5x11extras5-dev,
libxklavier-dev,
libkf5screen-dev,
@ -18,7 +17,6 @@ Build-Depends: debhelper-compat (= 12),
libkf5globalaccel-dev,
qtdeclarative5-dev,
libdconf-dev,
libmatemixer-dev,
libxml2-dev,
qtbase5-dev,
libx11-dev,
@ -33,7 +31,6 @@ Build-Depends: debhelper-compat (= 12),
libupower-glib-dev,
libpam0g-dev,
libukui-log4qt-dev[!sw64],
libmate-desktop-dev,
libddcutil-dev(>=0.9.9-5kylin1),
libkylin-chkname-dev,
libcups2-dev,
@ -63,7 +60,6 @@ Depends: ${shlibs:Depends},
ukui-biometric-manager(>=1.0.1-1kylin1~46),
openkylin-theme
Suggests: gsettings-desktop-schemas,
mate-desktop-common,
ukui-power-manager(>=2.1.29~rc11),
ukui-session-manager,
ukui-screensaver,

View File

@ -17,3 +17,4 @@ usr/share/ukui/faces/*
usr/share/ukui-control-center/shell/res/i18n/*
usr/share/ukui-control-center/shell/res/*
usr/lib/*/ukui-control-center/*.so
usr/share/ukui-control-center/data/*

View File

@ -4,6 +4,8 @@ set -e
glib-compile-schemas /usr/share/glib-2.0/schemas/
chmod u+s /usr/bin/changeuserpwd
if [ -x /usr/share/kylin-system-updater/kylin-reboot-required ];then
/usr/share/kylin-system-updater/kylin-reboot-required
fi

View File

@ -18,6 +18,7 @@
#include <QPainter>
#include <QPainterPath>
#include <QProcess>
#ifdef signals
@ -379,7 +380,6 @@ void ChangeUserPwd::setupConnect(){
isChecking = false;
} else {
//修改密码
QString output;
QString currentPwd = currentPwdLineEdit->text();
int ci = 0;
for (ci = 0; ci < currentPwd.count(); ci++){
@ -405,25 +405,24 @@ void ChangeUserPwd::setupConnect(){
char * cmd = g_strdup_printf("/usr/bin/changeuserpwd %s %s", currentPwd.toLatin1().data(), newPwd.toLatin1().data());
FILE *stream = NULL;
char buf[256] = {0};
FILE * stream;
QString result;
char output[256];
if ((stream = popen(cmd, "r" )) == NULL){
return;
if ((stream = popen(cmd, "r")) != NULL){
while(fgets(output, 256, stream) != NULL){
result = QString(output).simplified();
}
pclose(stream);
}
while(fgets(buf, 256, stream) != NULL){
output = QString(buf).simplified();
}
pclose(stream);
this->accept();
if (isDomainUser(g_get_user_name())) {
QString primaryText;
primaryText = output.simplified().isEmpty() ? tr("Pwd Changed Succes") : output;
qDebug() << "output of changeUserpwd = " << output;
primaryText = result.simplified().isEmpty() ? tr("Pwd Changed Succes") : output;
qDebug() << "output of changeUserpwd = " << result;
QMessageBox::warning(NULL, "", primaryText, QMessageBox::Yes);
}
}

View File

@ -51,7 +51,7 @@ public:
#ifdef Nile
PasswordLabel *getPwdLabel() {return mPwdinputLabel;}
#else
PasswordLabel *getPwdLabel() {return mPwdstrLabel;}
QLabel *getPwdLabel() {return mPwdstrLabel;}
#endif
QPushButton *getPwdEditBtn() {return mPwdEditBtn;}

View File

@ -20,7 +20,7 @@ INCLUDEPATH += ../libukcc/interface/ \
# 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 Nile
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += PLUGIN_INSTALL_DIRS='\\"$$[QT_INSTALL_LIBS]/ukui-control-center\\"'
DEFINES += PLUGIN_INSTALL_UPDATE='\\"$$[QT_INSTALL_LIBS]/ukui-control-center/V2.0\\"'

View File

@ -27,15 +27,31 @@ QMap<QString, QVariant> ukccSessionServer::getJsonInfo(const QString &configFile
for (int i = 0 ; i < obj.size(); i++) {
QJsonObject faObj= obj[i].toObject();
moduleMap.insert(faObj["name"].toString(), faObj["visible"].toVariant());
if (!faObj.contains("name")) {
continue;
}
QString name = faObj["name"].toString();
bool visible = true;
if (faObj.contains("visible")) {
visible = faObj["visible"].toBool();
}
moduleMap.insert(name, visible);
QJsonArray childNodeAry = faObj["childnode"].toArray();
for (int j = 0; j < childNodeAry.size(); j++) {
QString modeName = childNodeAry.at(j).toObject().value("name").toString();
QJsonObject childObj= childNodeAry.at(j).toObject();
if (!childObj.contains("name")) {
continue;
}
QString modeName = childObj["name"].toString();
bool modeVisiable = true;
if (childObj.contains("visible")) {
modeVisiable = childObj["visible"].toBool();
}
QString modeSet = modeName + "Settings";
QVariant modeVisiable = childNodeAry.at(j).toObject().value("visible").toVariant();
moduleMap.insert(modeName, modeVisiable);
moduleMap.insert(modeSet, childNodeAry.at(j).toObject().value(modeSet).toString());
if (childObj.contains(modeSet)) {
moduleMap.insert(modeSet, childObj[modeSet].toString());
}
}
}
}
@ -116,8 +132,13 @@ QString ukccSessionServer::GetSecurityConfigPath() {
}
QString userFilename = QDir::homePath() + "/.config/ukui-control-center-security-config.json";
QFile userFile(userFilename);
if (userFile.exists()) {
return userFilename;
}
return userFilename;
QString moduleFileName = "/usr/share/ukui-control-center/data/ukui-control-center-config.json";
return moduleFileName;
}
void ukccSessionServer::monitoFileChanged()

View File

@ -32,18 +32,19 @@
#include <QSvgRenderer>
#include "mainwindow.h"
#include "utils/keyvalueconverter.h"
#include "utils/functionselect.h"
#include "interface/ukcccommon.h"
using namespace ukcc;
#include "flowlayout.h"
#include "utils/modulefactory.h"
#define STYLE_FONT_SCHEMA "org.ukui.style"
const QStringList KexcludeModule{"update","security","application","search_f"};
HomePageWidget::HomePageWidget(QWidget *parent) :
HomePageWidget::HomePageWidget(QWidget *parent, QMap<QString, QGSettings *> map) :
QWidget(parent),
vecGsettins(map),
ui(new Ui::HomePageWidget)
{
qApp->installEventFilter(this);
@ -72,23 +73,18 @@ void HomePageWidget::initUI() {
flowLayout->setContentsMargins(70, 0, 70, 0);
mModuleMap = UkccCommon::getModuleHideStatus();
//构建枚举键值转换对象
KeyValueConverter * kvConverter = new KeyValueConverter(); //继承QObjectNo Delete
//初始化功能列表数据
FunctionSelect::loadHomeModule();
QSignalMapper * moduleSignalMapper = new QSignalMapper(this);
list_path = FunctionSelect::listExistsCustomNoticePath(PLUGINS_PATH);
for (int moduleIndex = 0; moduleIndex < TOTALMODULES; moduleIndex++) {
//获取插件QMap
QMap<QString, QObject *> moduleMap;
moduleMap = pmainWindow->exportModule(moduleIndex);
int totalModule = ModulesFactory::size();
for(int index = 0; index < totalModule; index++) {
ModuleInfo *curModuleInfo = ModulesFactory::getModuleInfoByIndex(index);
if (curModuleInfo == nullptr) {
continue;
}
//获取当前模块名
QString modulenameString = kvConverter->keycodeTokeystring(moduleIndex).toLower();
QString modulenamei18nString = kvConverter->keycodeTokeyi18nstring(moduleIndex);
const QString locale = QLocale::system().name();
QString modulenamei18nString = curModuleInfo->getModuleNameLocale(locale);
QString modulenameString = curModuleInfo->moduleName;
if ((mModuleMap.keys().contains(modulenameString) && !mModuleMap[modulenameString].toBool())
|| (UkccCommon::isTablet() && KexcludeModule.contains(modulenameString))) {
continue;
@ -124,7 +120,6 @@ void HomePageWidget::initUI() {
//内容Widget的构建
QPushButton * widget = new QPushButton();
QString moduleName = modulenameString;
QString picModuleName = modulenameString;
widget->setMinimumWidth(300);
widget->setMinimumHeight(97);
@ -144,8 +139,8 @@ void HomePageWidget::initUI() {
logoLabel->setFixedSize(48, 48);
logoLabel->setObjectName("logoLabel");
logoLabel->setScaledContents(true);
QString themeIconName = QString("kylin-settings-%1").arg(picModuleName);
QString localIconName = QString(":/img/homepage/%1.png").arg(themeIconName);
QString themeIconName = curModuleInfo->themeIconName;
QString localIconName = curModuleInfo->localIconName;
logoLabel->setPixmap(QIcon::fromTheme(themeIconName,QIcon(localIconName))
.pixmap(logoLabel->size()));
const QByteArray settingId(STYLE_FONT_SCHEMA);
@ -171,34 +166,23 @@ void HomePageWidget::initUI() {
uint AllWidth = 0;
QList<TristateLabel *> Labels;
//循环填充模块下属功能
if (moduleIndex >= FunctionSelect::funcinfoListHomePage.size()) {
continue;
}
QList<FuncInfo> tmpList = FunctionSelect::funcinfoListHomePage[moduleIndex];
QList<PluginInfo> tmpList = curModuleInfo->pluginInfoList;
int showModuleCount = 0;
for (int funcIndex = 0; funcIndex < tmpList.size(); funcIndex++){
FuncInfo single = tmpList.at(funcIndex);
QGSettings *plugin_settings = setGsettingsPath(list_path, single.nameString);
vecGsettins.insert(single.nameString, plugin_settings);
//跳过插件不存在的功能项
if (!moduleMap.contains(single.namei18nString)){
continue;
}
PluginInfo single = tmpList.at(funcIndex);
//跳过不在首页显示的功能
if (!single.mainShow)
continue;
showModuleCount++;
if (mModuleMap.keys().contains(single.nameString.toLower())) {
if (!mModuleMap[single.nameString.toLower()].toBool()) {
continue;
}
}
QObject* pluginObj = ModulesFactory::getPluginObjectByName(single.namei18nString);
if (pluginObj == nullptr) {
continue;
}
QString textName = single.namei18nString;
TristateLabel *label = new TristateLabel(textName, widget);
@ -213,20 +197,20 @@ void HomePageWidget::initUI() {
}
// 监听该插件是否启用
if (plugin_settings) {
if (vecGsettins.contains(single.oriNameString)) {
// 插件未启用直接隐藏该label
if (!plugin_settings->get(SHOW_KEY).toBool())
if (!vecGsettins[single.oriNameString]->get(SHOW_KEY).toBool())
label->setVisible(false);
connect(plugin_settings, &QGSettings::changed,[=](QString key){
connect(vecGsettins[single.oriNameString], &QGSettings::changed,[=](QString key){
if (key == SHOW_KEY) {
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(moduleMap.value(single.namei18nString));
bool isShow = pluginInstance->isEnable() && vecGsettins[single.nameString]->get(SHOW_KEY).toBool();
CommonInterface* pluginInstance = qobject_cast<CommonInterface*>(pluginObj);
bool isShow = pluginInstance->isEnable() && vecGsettins[single.oriNameString]->get(SHOW_KEY).toBool();
// 动态调整在首页显示的插件池
if (isShow) {
mLabels[moduleIndex].insert(funcIndex, label);
mLabels[index].insert(funcIndex, label);
int MWidth = 0;
for (TristateLabel * label : mLabels[moduleIndex]) {
for (TristateLabel * label : mLabels[index]) {
if ((MWidth += label->width() + funcHorLayout->spacing()) < 198) {
label->setVisible(true);
} else {
@ -234,7 +218,7 @@ void HomePageWidget::initUI() {
}
}
} else {
mLabels[moduleIndex].removeOne(label);
mLabels[index].removeOne(label);
label->setVisible(false);
}
}
@ -242,15 +226,16 @@ void HomePageWidget::initUI() {
}
connect(label, SIGNAL(clicked()), moduleSignalMapper, SLOT(map()));
moduleSignalMapper->setMapping(label, moduleMap[single.namei18nString]);
moduleSignalMapper->setMapping(label, pluginObj);
funcHorLayout->addWidget(label);
++showModuleCount;
}
mLabels.append(Labels);
funcHorLayout->addStretch();
// 下属无插件,不显示
if (FunctionSelect::funcinfoListHomePage[moduleIndex].size() == 0 || showModuleCount == 0) {
if (curModuleInfo->pluginInfoList.size() == 0 || showModuleCount == 0) {
widget->setVisible(false);
continue;
}
@ -260,7 +245,7 @@ void HomePageWidget::initUI() {
connect(stylesettings,&QGSettings::changed, [=](QString key) {
if ("systemFont" == key || "systemFontSize" == key) {
int MWidth = 0;
for (TristateLabel * label : mLabels[moduleIndex]) {
for (TristateLabel * label : mLabels[index]) {
QFontMetrics fontMetrics(this->font());
int fontSize = fontMetrics.width(label->text());
label->setFixedWidth(fontSize);
@ -273,12 +258,10 @@ void HomePageWidget::initUI() {
}
});
connect(widget, &QPushButton::clicked, [=]() {
int moduleIndex = kvConverter->keystringTokeycode(moduleName);
//获取模块的第一项跳转
QString firstFunc;
QList<FuncInfo> tmpList = FunctionSelect::funcinfoListHomePage[moduleIndex];
for (FuncInfo tmpStruct : tmpList) {
QList<PluginInfo> tmpList = curModuleInfo->pluginInfoList;
for (PluginInfo tmpStruct : tmpList) {
bool isIntel = UkccCommon::isTablet();
if ((isIntel && tmpStruct.namei18nString == "User Info")
@ -289,6 +272,10 @@ void HomePageWidget::initUI() {
if (!tmpStruct.isEnable) {
continue;
}
QObject* pluginObj = ModulesFactory::getPluginObjectByName(tmpStruct.namei18nString);
if (pluginObj == nullptr) {
continue;
}
// 若该插件不启用,跳转为下一项
if (vecGsettins.contains(tmpStruct.nameString)) {
@ -299,15 +286,12 @@ void HomePageWidget::initUI() {
}
}
}
if (moduleMap.keys().contains(tmpStruct.namei18nString)) {
if (mModuleMap.isEmpty() || !mModuleMap.contains(tmpStruct.nameString.toLower()) || mModuleMap[tmpStruct.nameString.toLower()].toBool()) {
firstFunc = tmpStruct.namei18nString;
UkccCommon::buriedSettings(tmpStruct.nameString, nullptr, "home clicked");
//跳转
pmainWindow->functionBtnClicked(moduleMap.value(firstFunc));
break;
}
if (mModuleMap.isEmpty() || !mModuleMap.contains(tmpStruct.nameString.toLower()) || mModuleMap[tmpStruct.nameString.toLower()].toBool()) {
firstFunc = tmpStruct.namei18nString;
UkccCommon::buriedSettings(tmpStruct.nameString, nullptr, "home clicked");
//跳转
pmainWindow->functionBtnClicked(pluginObj);
break;
}
}
});

View File

@ -60,7 +60,7 @@ class HomePageWidget : public QWidget
Q_OBJECT
public:
explicit HomePageWidget(QWidget *parent = 0);
explicit HomePageWidget(QWidget *parent = nullptr, QMap<QString, QGSettings *> map = {});
~HomePageWidget();
public:
@ -72,7 +72,6 @@ private:
QPixmap drawSymbolicColoredPixmap(const QPixmap &source, COLOR color);
bool eventFilter(QObject *watched, QEvent *event);
public:
QList<char *> list_path;
QMap<QString, QGSettings *> vecGsettins;
private:
Ui::HomePageWidget *ui;

View File

@ -19,8 +19,6 @@
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "utils/keyvalueconverter.h"
#include "utils/functionselect.h"
#include "interface/ukcccommon.h"
using namespace ukcc;
#include "imageutil.h"
@ -47,6 +45,8 @@ using namespace ukcc;
#include "iconbutton.h"
#include "lightlabel.h"
#include "../../shell/customstyle.h"
#include "utils/modulefactory.h"
#include "utils/functionselect.h"
#define THEME_QT_SCHEMA "org.ukui.style"
@ -84,6 +84,7 @@ MainWindow::MainWindow(QWidget *parent) :
qApp->installEventFilter(this);
qApp->setStyle(new InternalStyle("ukui"));
is_ExitPower = isExitsPower();
pluginPathList = FunctionSelect::listExistsCustomNoticePath(PLUGINS_PATH);
if (UkccCommon::isOpenkylin()) {
connect(WindowManager::self(),&WindowManager::windowAdded,this,[=](const WindowId& windowId){
if (getpid() == WindowManager::getPid(windowId)) {
@ -104,44 +105,15 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
//执行插件的析构函数
QMap<QString, QObject *> moduleMap;
for (int type = 0; type < TOTALMODULES; type++) {
moduleMap = this->exportModule(type);
QMap<QString, QObject*>::const_iterator it;
for (it = moduleMap.constBegin(); it != moduleMap.constEnd(); ++it) {
CommonInterface *pluginInstance = qobject_cast<CommonInterface *>(it.value());
if (pluginInstance) {
qInfo()<<"~exit && delete-plugin:"<<pluginInstance->name();
delete pluginInstance;
pluginInstance = nullptr;
}
}
}
ModulesFactory::pluginDelete();
qInfo()<<"~exit ukui-control-center";
delete ui;
ui = nullptr;
}
void MainWindow::bootOptionsFilter(QString opt, bool firstIn) {
int moduleNum;
bool isExitsModule = false;
QString funcStr;
QString funcName;
QList<FuncInfo> pFuncStructList;
for (int i = 0; i < FunctionSelect::funcinfoList.size(); i++) {
for (int j = 0; j < FunctionSelect::funcinfoList[i].size(); j++) {
if (!FunctionSelect::funcinfoList[i][j].nameString.compare(opt, Qt::CaseInsensitive)) {
moduleNum = FunctionSelect::funcinfoList[i][j].type;
funcStr = FunctionSelect::funcinfoList[i][j].namei18nString;
funcName = FunctionSelect::funcinfoList[i][j].nameString;
pFuncStructList = FunctionSelect::funcinfoList[i];
isExitsModule = true;
break;
}
}
}
if (!isExitsModule) {
PluginInfo* pluginInfo = ModulesFactory::getPluginInfoByName(opt);
if (pluginInfo == nullptr) {
//避免无限循环的风险
if (UkccCommon::isTablet()) {
if (firstIn) {
@ -151,29 +123,21 @@ void MainWindow::bootOptionsFilter(QString opt, bool firstIn) {
}
return ;
}
QMap<QString, QObject *> pluginsObjMap = modulesList.at(moduleNum);
if (pluginsObjMap.keys().contains(funcStr)){
QString pluginName = pluginInfo->nameString;
QString moduleName = ModulesFactory::getModuleNamebyName(pluginName);
QObject* pluginObj = ModulesFactory::getPluginObjectByName(pluginInfo->namei18nString);
if (pluginObj != nullptr) {
if (m_ModuleMap.isEmpty()) {
//开始跳转
functionBtnClicked(pluginsObjMap.value(funcStr));
functionBtnClicked(pluginObj);
return ;
} else {
QString superordinate = "";
for (auto it : moduleSuperordinate) {
if (it.first == funcName) {
superordinate = it.second;
break;
}
}
qDebug() << "module:" << funcName.toLower() << ";superordinate:" << superordinate.toLower();
qDebug() << "module:" << pluginName.toLower() << ";superordinate:" << moduleName;
// 若跳转节点或跳转节点父节点不存在直接跳转,不受管控文件控制,若存在,则根据管控文件判断是否被禁用
if (!m_ModuleMap.contains(funcName.toLower()) || !m_ModuleMap.contains(superordinate.toLower())
|| (m_ModuleMap[funcName.toLower()].toBool() && m_ModuleMap[superordinate.toLower()].toBool())) {
if (!m_ModuleMap.contains(pluginName.toLower()) || !m_ModuleMap.contains(moduleName)
|| (m_ModuleMap[pluginName.toLower()].toBool() && m_ModuleMap[moduleName].toBool())) {
//开始跳转
functionBtnClicked(pluginsObjMap.value(funcStr));
functionBtnClicked(pluginObj);
return ;
}
}
@ -276,11 +240,8 @@ void MainWindow::initUI() {
initTileBar();
initStyleSheet();
//初始化功能列表数据
FunctionSelect::initValue();
//构建枚举键值转换对象
kvConverter = new KeyValueConverter(); //继承QObjectNo Delete
// 一级菜单配置加载
ModulesFactory::loadConfig();
//加载插件
loadPlugins();
@ -329,7 +290,7 @@ void MainWindow::initUI() {
});
//加载首页Widget
homepageWidget = new HomePageWidget(this);
homepageWidget = new HomePageWidget(this, vecGsettins);
homepageWidget->installEventFilter(this);
ui->stackedWidget->addWidget(homepageWidget);
ui->stackedWidget->setFocusPolicy(Qt::ClickFocus);
@ -476,7 +437,6 @@ void MainWindow::initTileBar() {
});
m_searchWidget->setFixedWidth(240);
titleLayout->addWidget(mTitleIcon);
titleLayout->addSpacing(8);
titleLayout->addWidget(titleLabel);
@ -607,18 +567,12 @@ void MainWindow::setBtnLayout(QPushButton * &pBtn) {
void MainWindow::loadPlugins()
{
for (int index = 0; index < TOTALMODULES; index++){
QMap<QString, QObject *> pluginsMaps;
modulesList.append(pluginsMaps);
}
bool installed = (QCoreApplication::applicationDirPath() == QDir(("/usr/bin")).canonicalPath());
if (installed) {
pluginsDir = QDir(PLUGIN_INSTALL_DIRS);
} else {
pluginsDir = QDir(qApp->applicationDirPath() + "/plugins");
}
loadUpdatePlugins();
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
@ -669,15 +623,14 @@ void MainWindow::determinePlugin(const QString &fileName, const QDir &dir)
return;
}
modulesList[pluginInstance->pluginTypes()].insert(pluginInstance->plugini18nName(), plugin);
qDebug() << "Load Plugin :" << pluginInstance->plugini18nName();
QGSettings *pluginSettings = setGsettingsPath(pluginPathList, pluginInstance->name());
vecGsettins.insert(pluginInstance->name(), pluginSettings);
qDebug() << "Load Plugin :" << kvConverter->keycodeTokeyi18nstring(pluginInstance->pluginTypes()) << "->" << pluginInstance->plugini18nName() ;
m_searchWidget->addModulesName(pluginInstance->name(), pluginInstance->plugini18nName(), pluginInstance->translationPath());
int moduletypeInt = pluginInstance->pluginTypes();
if (!moduleIndexList.contains(moduletypeInt))
moduleIndexList.append(moduletypeInt);
ModulesFactory::loadPluginInfo(plugin);
if (pluginInstance->isEnable() && pluginSettings->get(SHOW_KEY).toBool()) {
m_searchWidget->addModulesName(pluginInstance->name(), pluginInstance->plugini18nName(), pluginInstance->translationPath());
}
} else {
//如果加载错误且文件后缀为so输出错误
if (fileName.endsWith(".so"))
@ -710,7 +663,7 @@ void MainWindow::initLeftsideBar()
scrollArea = new KNavigationBar(ui->leftBotWidget);
connect(this,&MainWindow::specifiedPluginLoaded,this,[=](CommonInterface * pluginInstance){
int type = TOTALMODULES;
int type = ModulesFactory::size();
QString typeName = tr("Specified");
QStandardItem *specifiedPlugin = new QStandardItem(pluginInstance->icon(), pluginInstance->plugini18nName());
@ -723,39 +676,35 @@ void MainWindow::initLeftsideBar()
pluginInstance->pluginBtn = specifiedPlugin;
});
for(int type = 0; type < TOTALMODULES; type++) {
int totalModule = ModulesFactory::size();
for(int index = 0; index < totalModule; index++) {
//循环构建左侧边栏一级菜单按钮
if (moduleIndexList.contains(type)){
QString mnameString = kvConverter->keycodeTokeystring(type);
QString mnamei18nString = kvConverter->keycodeTokeyi18nstring(type); //设置TEXT
QList<FuncInfo> moduleList = FunctionSelect::funcinfoList[type];
for (int funcIndex = 0; funcIndex < moduleList.size(); funcIndex++) {
FuncInfo single = moduleList.at(funcIndex);
QPair<QString, QString> data;
data.first = single.nameString;
data.second = mnameString;
moduleSuperordinate.append(data);
}
if (m_ModuleMap.keys().contains(mnameString.toLower())) {
if (!m_ModuleMap[mnameString.toLower()].toBool()) {
ModuleInfo *curModuleInfo = ModulesFactory::getModuleInfoByIndex(index);
if (curModuleInfo == nullptr) {
continue;
}
int type = curModuleInfo->moduleType;
if (ModulesFactory::checkModuleType(type)){ // 一级菜单不会有多个
QString mnameString = curModuleInfo->moduleName;
const QString locale = QLocale::system().name();
QString mnamei18nString = curModuleInfo->getModuleNameLocale(locale);
if (m_ModuleMap.keys().contains(mnameString)) {
if (!m_ModuleMap[mnameString].toBool()) {
continue;
}
}
QMap<QString, QObject *> moduleMap;
moduleMap = this->exportModule(type);
QList<QStandardItem *> secondList;
QList<FuncInfo> functionStructList = FunctionSelect::funcinfoList[type];
QList<PluginInfo> functionStructList = curModuleInfo->pluginInfoList;
if (functionStructList.size() <= 0) { // 下属无插件,不显示
continue;
}
int showModuleCount = 0;
for (int funcIndex = 0; funcIndex < functionStructList.size(); funcIndex++) {
FuncInfo single = functionStructList.at(funcIndex);
PluginInfo single = functionStructList.at(funcIndex);
//跳过插件不存在的功能项
if (!moduleMap.contains(single.namei18nString) || !single.isEnable) {
if (!ModulesFactory::checkPluginExist(single.namei18nString) || !single.isEnable) {
continue;
}
@ -774,20 +723,23 @@ void MainWindow::initLeftsideBar()
}
//填充左侧菜单
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(moduleMap.value(single.namei18nString));
QObject* pluginObj = ModulesFactory::getPluginObjectByName(single.namei18nString);
if (pluginObj == nullptr) {
continue;
}
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(pluginObj);
QStandardItem *pluginItem = new QStandardItem(pluginInstance->icon(), single.namei18nString);
secondList << pluginItem;
pluginItem->setData(type, Qt::UserRole+1);
pluginItem->setData(single.namei18nString, Qt::UserRole+2);
pluginInstance->pluginBtn = pluginItem;
pluginInstance->pluginBtn = pluginItem;
// 初始化插件状态
QGSettings *msettings = nullptr;
int row = scrollArea->model()->rowCount() + secondList.count();
if (homepageWidget->vecGsettins.contains(single.nameString)) {
msettings = homepageWidget->vecGsettins[single.nameString];
if (vecGsettins.contains(single.oriNameString)) {
msettings = vecGsettins[single.oriNameString];
if (msettings && plgIsVisiable) {
connect(msettings , &QGSettings::changed,[=](QString key){
connect(msettings, &QGSettings::changed,[=](QString key){
bool visible = !pluginInstance->isEnable() ? false : msettings->get(SHOW_KEY).toBool();
qDebug() << "isEnable = " << pluginInstance->isEnable();
if (key == SHOW_KEY) {
@ -795,22 +747,28 @@ void MainWindow::initLeftsideBar()
ui->stackedWidget->setCurrentIndex(0);
}
scrollArea->listview()->setRowHidden(row, !visible);
m_searchWidget->hiddenSearchItem(single.namei18nString, msettings->get(SHOW_KEY).toBool());
m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? single.namei18nString : single.oriNameString, msettings->get(SHOW_KEY).toBool());
} else {
m_searchWidget->hiddenSearchItem(single.namei18nString, msettings->get(SHOW_KEY).toBool());
m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? single.namei18nString : single.oriNameString, msettings->get(SHOW_KEY).toBool());
}
});
bool isShow = !pluginInstance->isEnable() ? false : msettings->get(SHOW_KEY).toBool();
qDebug() << "Load Plugin : " << single.namei18nString << "isShow:" <<isShow << "isEnable:" << single.isEnable;
scrollArea->listview()->setRowHidden(row, !isShow);
m_searchWidget->hiddenSearchItem(single.namei18nString, msettings->get(SHOW_KEY).toBool());
m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? single.namei18nString : single.oriNameString, msettings->get(SHOW_KEY).toBool());
}
}
++showModuleCount;
}
// 下属无插件,不显示
if (curModuleInfo->pluginInfoList.size() == 0 || showModuleCount == 0 || secondList.size() == 0) {
continue;
}
scrollArea->addGroupItems(secondList, mnamei18nString);
for (int funcIndex = 0; funcIndex < functionStructList.size(); funcIndex++) {
FuncInfo single = functionStructList.at(funcIndex);
PluginInfo single = functionStructList.at(funcIndex);
if (!single.isEnable) {
QList<QStandardItem *> itemList = scrollArea->model()->findItems(single.namei18nString);
if (!itemList.isEmpty()) {
@ -823,137 +781,46 @@ void MainWindow::initLeftsideBar()
}
connect(scrollArea->listview(), &QListView::clicked, this, [=](const QModelIndex &index){
QMap<QString, QObject *> moduleMap;
moduleMap = this->exportModule(index.data(Qt::UserRole+1).toInt());
qDebug() << "moduleMap = " << moduleMap;
qDebug() << "index = " << index.data(Qt::UserRole+2).toString();
QString moduleName = index.data(Qt::UserRole+2).toString();
QString pluginil8Name = index.data(Qt::UserRole+2).toString();
QObject* pluginObj = ModulesFactory::getPluginObjectByName(pluginil8Name);
if (pluginObj != nullptr) {
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(pluginObj);
if (pluginInstance) {
modulepageWidget->refreshPluginWidget(pluginInstance);
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(moduleMap.value(moduleName));
if (pluginInstance) {
modulepageWidget->refreshPluginWidget(pluginInstance);
// 埋点点击左侧导航插件
UkccCommon::buriedSettings(pluginInstance->name(), nullptr, QString("left clicked"));
// 埋点点击左侧导航插件
UkccCommon::buriedSettings(pluginInstance->name(), nullptr, QString("left clicked"));
}
}
});
ui->leftBotLayout->addWidget(scrollArea);
}
QPushButton * MainWindow::buildLeftsideBtn(QString bname,QString tipName, QIcon icon) {
int itype = kvConverter->keystringTokeycode(bname);
QPushButton * leftsidebarBtn = new QPushButton();
leftsidebarBtn->setAttribute(Qt::WA_DeleteOnClose);
leftsidebarBtn->setCheckable(true);
if (UkccCommon::isTablet()) {
leftsidebarBtn->setFixedSize(230,48);
} else {
leftsidebarBtn->setFixedSize(230,40); //一级菜单按钮显示的宽度
QGSettings *MainWindow::setGsettingsPath(QList<char *> list, QString name)
{
// 为每个插件创建动态QGSettings对象用于监听插件是否隐藏
QByteArray ba;
char *path;
ba = (QString("%1%2").arg(name).arg("/")).toUtf8();
path = ba.data();
const QByteArray id(PLUGINS_SCHEMA);
if (!QGSettings::isSchemaInstalled(id)) {
return nullptr;
}
QGSettings *settings = nullptr;
QString plugin = QString("%1%2%3").arg(PLUGINS_PATH).arg(name).arg("/");
settings = new QGSettings(id, plugin.toUtf8().data(), this);
IconButton * iconBtn = new IconButton(bname, icon, leftsidebarBtn);
iconBtn->setCheckable(true);
iconBtn->setFixedSize(QSize(16, 16));
iconBtn->setFocusPolicy(Qt::NoFocus);
iconBtn->reLoadIcon();
static QString hoverColor;
static QString clickColor;
if (QGSettings::isSchemaInstalled("org.ukui.style")) {
QGSettings *qtSettings = new QGSettings("org.ukui.style", QByteArray(), this);
if (qtSettings->keys().contains("styleName")) {
hoverColor = pluginBtnHoverColor(qtSettings->get("style-name").toString(), true);
clickColor = pluginBtnHoverColor(qtSettings->get("style-name").toString(), false);
if (!leftsidebarBtn->isChecked())
leftsidebarBtn->setStyleSheet(QString("QPushButton:hover{background-color:%1;border-radius: 6px;}"
"QPushButton:pressed{background-color:%2;border-radius: 6px;}").arg(hoverColor).arg(clickColor));
//判断是否已存在该路径,不存在则赋初值
for (int j = 0; j < list.count(); j++) {
if (!qstrcmp(path, list.at(j))){
return settings;
}
connect(qtSettings, &QGSettings::changed, this, [=,&hoverColor](const QString &key) {
if (key == "styleName") {
iconBtn->reLoadIcon();
hoverColor = this->pluginBtnHoverColor(qtSettings->get("style-name").toString(), true);
clickColor = pluginBtnHoverColor(qtSettings->get("style-name").toString(), false);
if (!leftsidebarBtn->isChecked())
leftsidebarBtn->setStyleSheet(QString("QPushButton:hover{background-color:%1;border-radius: 6px;}"
"QPushButton:pressed{background-color:%2;border-radius: 6px;}").arg(hoverColor).arg(clickColor));
} else if (key == "themeColor" && leftsidebarBtn->isChecked()) {
leftsidebarBtn->toggled(true);
}
});
}
QLabel * textLabel = new QLabel(leftsidebarBtn);
textLabel->setFixedWidth(leftsidebarBtn->width() - 40);
QFontMetrics fontMetrics(textLabel->font());
int fontSize = fontMetrics.width(tipName);
if (fontSize > textLabel->width()) {
textLabel->setText(fontMetrics.elidedText(tipName, Qt::ElideRight, textLabel->width()));
} else {
textLabel->setText(tipName);
}
const QByteArray styleID(THEME_QT_SCHEMA);
QGSettings *stylesettings = new QGSettings(styleID, QByteArray(), this);
connect(stylesettings,&QGSettings::changed,[=](QString key)
{
if("systemFont" == key || "systemFontSize" == key)
{
QFontMetrics fontMetrics_1(textLabel->font());
int fontSize_1 = fontMetrics_1.width(tipName);
if (fontSize_1 > textLabel->width()) {
qDebug()<<textLabel->width();
textLabel->setText(fontMetrics_1.elidedText(tipName, Qt::ElideRight, textLabel->width()));
} else {
textLabel->setText(tipName);
}
}
});
QSizePolicy textLabelPolicy = textLabel->sizePolicy();
textLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
textLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
textLabel->setSizePolicy(textLabelPolicy);
textLabel->setScaledContents(true);
leftMicBtnGroup->addButton(iconBtn, itype);
connect(iconBtn, &QPushButton::toggled, this, [=] (bool checked) {
iconBtn->reLoadIcon();
if (checked) {
textLabel->setStyleSheet("color:white");
} else {
textLabel->setStyleSheet("color:palette(windowText)");
}
});
connect(iconBtn, &QPushButton::clicked, leftsidebarBtn, &QPushButton::click);
connect(leftsidebarBtn, &QPushButton::toggled, this, [=](bool checked) {
iconBtn->setChecked(checked);
if (checked) {
leftsidebarBtn->setStyleSheet("QPushButton:checked{background-color: palette(highlight);border-radius: 6px;}");
textLabel->setStyleSheet("color:white");
} else {
leftsidebarBtn->setStyleSheet(QString("QPushButton:hover{background-color:%1;border-radius: 6px;}"
"QPushButton:pressed{background-color:%2;border-radius: 6px;}").arg(hoverColor).arg(clickColor));
textLabel->setStyleSheet("color:palette(windowText)");
}
});
QHBoxLayout * btnHorLayout = new QHBoxLayout();
btnHorLayout->setContentsMargins(14,0,0,0);
btnHorLayout->addWidget(iconBtn, Qt::AlignCenter);
btnHorLayout->addWidget(textLabel);
btnHorLayout->addStretch();
btnHorLayout->setSpacing(8);
leftsidebarBtn->setLayout(btnHorLayout);
return leftsidebarBtn;
settings->set(PLUGIN_NAME, name);
settings->set(SHOW_KEY, true);
return settings;
}
bool MainWindow::isExitsCloudAccount() {
@ -1098,14 +965,6 @@ void MainWindow::setModuleBtnHightLight(int id) {
leftMicBtnGroup->button(id)->setChecked(true);
}
QMap<QString, QObject *> MainWindow::exportModule(int type) {
QMap<QString, QObject *> emptyMaps;
if (type < modulesList.length())
return modulesList[type];
else
return emptyMaps;
}
void MainWindow::pluginBtnClicked(QObject *plugin) {
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
@ -1150,29 +1009,19 @@ void MainWindow::sltMessageReceived(const QString &msg) {
}
void MainWindow::switchPage(QString moduleName, QString jumpMoudle, QString jumpText) {
for (int i = 0; i < modulesList.length(); i++) {
auto modules = modulesList.at(i);
//开始跳转
if (modules.keys().contains(moduleName)) {
if (m_ModuleMap.isEmpty()) {
functionBtnClicked(modules.value(moduleName));
return ;
} else {
QString superordinate = "";
for (auto it : moduleSuperordinate) {
if (it.first == jumpMoudle) {
superordinate = it.second;
break;
}
}
// 若跳转节点或跳转节点父节点不存在直接跳转,不受管控文件控制,若存在,则根据管控文件判断是否被禁用
if (!m_ModuleMap.contains(jumpMoudle.toLower()) || !m_ModuleMap.contains(superordinate.toLower())
//开始跳转
QObject* pluginObj = ModulesFactory::getPluginObjectByName(moduleName);
if (pluginObj != nullptr) {
if (m_ModuleMap.isEmpty()) {
functionBtnClicked(pluginObj);
return;
} else {
QString superordinate = ModulesFactory::getModuleNamebyName(jumpMoudle);
// 若跳转节点或跳转节点父节点不存在直接跳转,不受管控文件控制,若存在,则根据管控文件判断是否被禁用
if (!m_ModuleMap.contains(jumpMoudle.toLower()) || !m_ModuleMap.contains(superordinate.toLower())
|| (m_ModuleMap[jumpMoudle.toLower()].toBool() && m_ModuleMap[superordinate.toLower()].toBool())) {
functionBtnClicked(modules.value(moduleName));
return ;
}
functionBtnClicked(pluginObj);
return;
}
}
}

View File

@ -46,7 +46,6 @@
class QLabel;
class QPushButton;
class QButtonGroup;
class KeyValueConverter;
using namespace kdk;
namespace Ui {
@ -62,7 +61,6 @@ public:
~MainWindow();
public:
QMap<QString, QObject *> exportModule(int);
void setModuleBtnHightLight(int id);
void bootOptionsFilter(QString opt, bool firstIn = true); // 模块跳转
void moveEvent(QMoveEvent *event);
@ -85,11 +83,7 @@ private:
QDir pluginsDir;
QDir updatePluginDir;
QList<int> moduleIndexList;
QList<QMap<QString, QObject *>> modulesList;
QList<QPair<QString, QString>> moduleSuperordinate;
KeyValueConverter * kvConverter;
SearchWidget * m_searchWidget;
QPushButton *backBtn;
@ -115,6 +109,8 @@ private:
bool isTabletMode = false;
QList<WindowId> m_listWinIds;
QMap<QString, QGSettings *> vecGsettins;
QList<char *> pluginPathList;
private:
void initUI();
@ -125,7 +121,7 @@ private:
void determinePlugin(const QString& fileName, const QDir& dir);
void loadSpecifiedPlugin(QString pluginFullName);
void initLeftsideBar();
QPushButton * buildLeftsideBtn(QString bname, QString tipName, QIcon icon);
QGSettings *setGsettingsPath(QList<char *> list , QString name);
bool isExitsCloudAccount();
bool isExitsPower();
bool isExitWirelessDevice();

View File

@ -25,7 +25,6 @@
#include "mainwindow.h"
#include "interface.h"
#include "utils/keyvalueconverter.h"
#include "utils/functionselect.h"
#include "interface/ukcccommon.h"
using namespace ukcc;

View File

@ -0,0 +1,275 @@
#include "modulefactory.h"
#include <QDir>
#include <QSettings>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QByteArray>
#include <QJsonParseError>
#include <QJsonObject>
#include "interface.h"
int ModulesFactory::totalModule;
QList<int> ModulesFactory::moduleTypeList;
QList<QPair<QString, QString>> ModulesFactory::pluginToModuleNameList;
QVector<ModuleInfo *> ModulesFactory::moduleInfoVec;
QMap<int, QMap<QString, QObject *>> ModulesFactory::moduleTypeToPluginMap;
const QString MODULEPATH = "/usr/share/ukui-control-center/data/ukui-control-center-config.json";
ModulesFactory::ModulesFactory() {
clear();
}
ModulesFactory::~ModulesFactory() {
clear();
}
void ModulesFactory::clear() {
totalModule = 0;
moduleInfoVec.clear();
moduleTypeList.clear();
moduleTypeToPluginMap.clear();
pluginToModuleNameList.clear();
}
int ModulesFactory::size() {
return totalModule;
}
void ModulesFactory::loadConfig() {
QFile file(MODULEPATH);
moduleInfoVec.clear();
if (!file.exists()) {
qDebug() << "file not exist:" << MODULEPATH;
return;
}
file.open(QIODevice::ReadOnly);
QByteArray readBy = file.readAll();
QJsonParseError error;
QJsonDocument moduleDoc = QJsonDocument::fromJson(readBy, &error);
if (error.error != QJsonParseError::NoError) {
qDebug() << "ModuleFactory parseJson failed:" << error.errorString();
return;
}
QJsonObject modulesObj = moduleDoc.object();
if (!modulesObj.contains("ukcc")) {
qDebug() << "ModuleFactory has not ukcc item";
return;
}
QJsonArray moduleArr = modulesObj.value("ukcc").toArray();
totalModule = moduleArr.size();
for (int order = 0; order < totalModule; order++) {
QJsonObject moduleObj = moduleArr[order].toObject();
QString moduleName = moduleObj["name"].toString().toLower();
QString localIconName = moduleObj["local_icon_name"].toString();
QString themeIconName = moduleObj["theme_icon_name"].toString();
int moduleType = moduleObj["module_type"].toInt();
QJsonObject localeObj = moduleObj.value("name_locale").toObject();
int moduleOrder = order;
ModuleInfo* curModuleInfo = new ModuleInfo(moduleName, moduleOrder, moduleType, themeIconName, localIconName);
if (curModuleInfo == nullptr) {
continue;
}
int totalLocale = localeObj.size();
for (int localeIdx = 0; localeIdx < totalLocale; ++localeIdx) {
QString key = localeObj.keys().at(localeIdx);
QString value = localeObj[key].toString();
curModuleInfo->appendNameLocale(key, value);
}
QJsonArray pluginArr = moduleObj.value("childnode").toArray();
int totalPlugin = pluginArr.size();
for (int pluginIdx = 0; pluginIdx < totalPlugin; ++pluginIdx) {
QJsonObject pluginObj = pluginArr[pluginIdx].toObject();
if (!pluginObj.keys().contains("name")) {
continue;
}
QString pluginname = pluginObj["name"].toString().toLower();
curModuleInfo->appendPluginNameList(pluginIdx, pluginname);
}
moduleInfoVec.append(curModuleInfo);
}
std::sort(moduleInfoVec.begin(), moduleInfoVec.end(),
[&](const ModuleInfo* lModuleInfo, const ModuleInfo* rModuleInfo) {
if (lModuleInfo->moduleOrder != rModuleInfo->moduleOrder) {
return lModuleInfo->moduleOrder < rModuleInfo->moduleOrder;
}
return false;
});
foreach (ModuleInfo* moduleInfo, moduleInfoVec) {
QMap<QString, QObject*> pluginsMaps;
int moduleType = moduleInfo->moduleType;
moduleTypeToPluginMap.insert(moduleType, pluginsMaps);
qDebug() << "modulename: " <<moduleInfo->moduleName << moduleInfo->moduleOrder;
}
totalModule = moduleInfoVec.size();
file.close();
}
void ModulesFactory::loadPluginInfo(QObject* pluginObj) {
if (!pluginObj) {
return;
}
CommonInterface* pluginInstance = qobject_cast<CommonInterface*>(pluginObj);
if (!pluginInstance) {
return;
}
QString name = pluginInstance->name().toLower();
QString i18nName = pluginInstance->plugini18nName();
int moduleType = pluginInstance->pluginTypes();
bool isShow = pluginInstance->isShowOnHomePage();
bool isEnable = pluginInstance->isEnable();
ModuleInfo* moduleInfo = getModuleInfoByType(moduleType);
if (moduleInfo == nullptr) {
return;
}
QList<QString>& pluginName = moduleInfo->pluginNameList;
QList<PluginInfo>& pluginInfoList = moduleInfo->pluginInfoList;
// 查找当前加载的插件序号i
int pluginIdx = 0;
for (; pluginIdx < pluginName.size(); pluginIdx++) {
if (name.compare(pluginName.at(pluginIdx), Qt::CaseInsensitive) == 0) {
break;
}
}
PluginInfo pluginInfo;
pluginInfo.oriNameString = pluginInstance->name();
pluginInfo.nameString = name;
pluginInfo.namei18nString = i18nName;
pluginInfo.type = moduleType;
pluginInfo.mainShow = isShow;
pluginInfo.isEnable = isEnable;
QPair<QString, QString> data;
data.first = pluginInfo.nameString;
data.second = moduleInfo->moduleName;
pluginToModuleNameList.append(data);
if (!moduleTypeList.contains(pluginInfo.type)) {
moduleTypeList.append(pluginInfo.type);
}
int pluginInfoListSize = pluginInfoList.size();
if (pluginInfoListSize == 0) {
pluginInfoList.append(pluginInfo);
} else {
bool isInsert = false;
// 遍历原有list对比pluginInfo的序号与list中每个元素序号的关系
for (int preItemIndex = pluginInfoListSize - 1; preItemIndex >= 0; preItemIndex--) {
int nItemIndex = 0;
for (nItemIndex = 0; nItemIndex < pluginName.count(); nItemIndex++) {
if (pluginInfoList[preItemIndex].nameString.toLower().compare(pluginName.at(nItemIndex).toLower(), Qt::CaseInsensitive) == 0) {
break;
}
}
// 原有list元素序号小于新的module序号将module插入该元素之后
if (nItemIndex <= pluginIdx) {
pluginInfoList.insert(preItemIndex + 1, pluginInfo);
isInsert = true;
break;
}
}
if (!isInsert) {
pluginInfoList.insert(0, pluginInfo);
}
}
moduleTypeToPluginMap[moduleType].insert(i18nName, pluginObj);
}
QString ModulesFactory::getModuleNamebyName(QString pluginName) {
QString moduleName = "";
for (auto it : pluginToModuleNameList) {
if (it.first.toLower() == pluginName.toLower()) {
moduleName = it.second;
break;
}
}
return moduleName;
}
PluginInfo* ModulesFactory::getPluginInfoByName(QString pluginName) {
for (int moduleIdx = 0; moduleIdx < totalModule; moduleIdx++) {
for (int pluginIdx = 0; pluginIdx < moduleInfoVec.at(moduleIdx)->pluginInfoList.size(); pluginIdx++) {
if (!moduleInfoVec.at(moduleIdx)->pluginInfoList[pluginIdx].nameString.compare(pluginName, Qt::CaseInsensitive)) {
return &moduleInfoVec.at(moduleIdx)->pluginInfoList[pluginIdx];
}
}
}
return nullptr;
}
QObject* ModulesFactory::getPluginObjectByName(QString pluginil8Name) {
for (int idx = 0; idx < moduleTypeToPluginMap.size(); ++idx) {
if (moduleTypeToPluginMap[idx].contains(pluginil8Name)) {
return moduleTypeToPluginMap[idx][pluginil8Name];
}
}
return nullptr;
}
QObject* ModulesFactory::getPluginObjectByType(int moduleType, QString pluginil8Name) {
if (moduleTypeToPluginMap.contains(moduleType)) {
return nullptr;
}
QMap<QString, QObject*> curPluginMap = moduleTypeToPluginMap[moduleType];
if (!curPluginMap.empty() && curPluginMap.keys().contains(pluginil8Name)) {
return curPluginMap.value(pluginil8Name);
}
return nullptr;
}
ModuleInfo* ModulesFactory::getModuleInfoByIndex(int index) {
if (!checkModuleIndex(index)) {
return nullptr;
}
return moduleInfoVec[index];
}
ModuleInfo* ModulesFactory::getModuleInfoByType(int moduleType) {
for (int moduleIdx = 0; moduleIdx < totalModule; moduleIdx++) {
int curModuleType = moduleInfoVec[moduleIdx]->moduleType;
if (moduleType != curModuleType) {
continue;
}
return moduleInfoVec[moduleIdx];
}
return nullptr;
}
bool ModulesFactory::checkPluginExist(QString pluginil8Name) {
for (int idx = 0; idx < moduleTypeToPluginMap.size(); ++idx) {
if (moduleTypeToPluginMap[idx].contains(pluginil8Name)) {
return true;
}
}
return false;
}
bool ModulesFactory::checkModuleIndex(int index) {
int moduleSize = moduleInfoVec.size();
if (index >= 0 && index < moduleSize) {
return true;
}
return false;
}
bool ModulesFactory::checkModuleType(int moduleType) {
return moduleTypeList.contains(moduleType);
}
void ModulesFactory::pluginDelete() {
QMap<QString, QObject*> moduleMap;
for (auto plugin : moduleTypeList) {
if (!moduleTypeToPluginMap.contains(plugin)) {
continue;
}
moduleMap = moduleTypeToPluginMap[plugin];
QMap<QString, QObject*>::const_iterator it;
for (it = moduleMap.constBegin(); it != moduleMap.constEnd(); ++it) {
CommonInterface* pluginInstance = qobject_cast<CommonInterface*>(it.value());
if (pluginInstance) {
qInfo() << "~exit && delete-plugin:" << pluginInstance->name();
delete pluginInstance;
pluginInstance = nullptr;
}
}
}
}

101
shell/utils/modulefactory.h Normal file
View File

@ -0,0 +1,101 @@
#ifndef MODULEFACTORY_H
#define MODULEFACTORY_H
#include <QObject>
#include <QMetaEnum>
#include <QVector>
#include <QMap>
#include <QStack>
//#include "interface.h"
#include <QDebug>
struct PluginInfo {
int type;
int index;
bool mainShow;
bool isEnable;
QString oriNameString;
QString nameString;
QString namei18nString;
};
struct ModuleInfo {
ModuleInfo(QString modulename, int moduleorder,int moduletype,
QString themeiconname, QString localiconname) {
clear();
moduleName = modulename;
moduleOrder = moduleorder;
localIconName = localiconname;
themeIconName = themeiconname;
moduleType = moduletype;
}
~ModuleInfo() {
clear();
}
void clear() {
moduleOrder = -1;
moduleType = -1;
moduleName.clear();
moduleLocaleMap.clear();
pluginNameList.clear();
pluginInfoList.clear();
localIconName.clear();
themeIconName.clear();
}
void appendNameLocale(QString key, QString value) {
moduleLocaleMap.insert(key, value);
}
void appendPluginNameList(int index, QString value) {
pluginNameList.insert(index, value);
}
QString getModuleNameLocale(const QString locale) {
QString moduleName = "";
if (moduleLocaleMap.find(locale) != moduleLocaleMap.end()) {
moduleName = moduleLocaleMap[locale];
}
return moduleName;
}
int moduleOrder;
int moduleType;
QString moduleName;
QString themeIconName;
QString localIconName;
QMap<QString, QString> moduleLocaleMap;
QList<QString> pluginNameList;
QList<PluginInfo> pluginInfoList;
};
class ModulesFactory : public QObject {
Q_OBJECT
public:
explicit ModulesFactory();
~ModulesFactory();
public:
static void loadConfig();
static void loadPluginInfo(QObject* pluginObj);
static ModuleInfo* getModuleInfoByIndex(int index);
static ModuleInfo* getModuleInfoByType(int moduleType);
static QString getModuleNamebyName(QString pluginName);
static QObject* getPluginObjectByName(QString pluginil8Name);
static QObject* getPluginObjectByType(int moduleType, QString pluginil8Name);
static PluginInfo* getPluginInfoByName(QString pluginName);
static bool checkModuleType(int moduleType);
static bool checkPluginExist(QString pluginil8Name);
static void pluginDelete();
static int size();
private:
static void clear();
static bool checkModuleIndex(int index);
private:
static int totalModule;
static QVector<ModuleInfo *> moduleInfoVec;
static QList<int> moduleTypeList;
static QList<QPair<QString, QString>> pluginToModuleNameList;
static QMap<int, QMap<QString, QObject *>> moduleTypeToPluginMap;
};
#endif // MODULEFACTORY_H