- 简要展示激活信息,提供激活信息入口 - 修复部分代码问题 - 调整控制中心弹窗按钮问题 - 修复快捷键 提取desktop entry Exec过滤%u,%f问题 - 修复检查出内存泄漏的问题
631 lines
22 KiB
Diff
631 lines
22 KiB
Diff
From d1f1a182b540ae4b9c1c6fb35aa4ac0b5caebc9e Mon Sep 17 00:00:00 2001
|
||
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
||
Date: Mon, 14 Nov 2022 17:55:08 +0800
|
||
Subject: [PATCH 5/5] refactor(*): Reconstruct the code structure
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 重构代码结构,简化解析IconTheme json字符串的代码
|
||
---
|
||
include/panel-interface.h | 2 +
|
||
include/plugin-interface-v2.h | 4 +-
|
||
include/plugin-subitem-interface.h | 2 +-
|
||
launcher/src/main.cpp | 1 -
|
||
lib/common-widgets/hover-tips/hover-tips.cpp | 7 +-
|
||
.../kiran-module-widget.cpp | 23 ++--
|
||
.../src/kiran-cpanel-appearance.cpp | 67 ---------
|
||
.../appearance/src/kiran-cpanel-appearance.h | 60 --------
|
||
.../appearance/src/kiran-cpanel-appearance.ui | 130 ------------------
|
||
.../pages/theme/icon-themes/icon-themes.cpp | 79 ++++++-----
|
||
.../src/pages/theme/icon-themes/icon-themes.h | 2 +-
|
||
11 files changed, 69 insertions(+), 308 deletions(-)
|
||
delete mode 100644 plugins/appearance/src/kiran-cpanel-appearance.cpp
|
||
delete mode 100644 plugins/appearance/src/kiran-cpanel-appearance.h
|
||
delete mode 100644 plugins/appearance/src/kiran-cpanel-appearance.ui
|
||
|
||
diff --git a/include/panel-interface.h b/include/panel-interface.h
|
||
index 6276649..d352ed4 100644
|
||
--- a/include/panel-interface.h
|
||
+++ b/include/panel-interface.h
|
||
@@ -22,7 +22,9 @@ namespace KiranControlPanel
|
||
class PanelInterface
|
||
{
|
||
public:
|
||
+ //通知控制中心主面板功能项信息变化
|
||
virtual void handlePluginSubItemInfoChanged(const QString& subItemID) = 0;
|
||
+ //通知控制中心主面板 功能项 发生改变,调用该接口,控制中心将重新加载该插件下的功能项信息
|
||
virtual void handlePluginSubItemChanged() = 0;
|
||
};
|
||
} // namespace KiranControlPanel
|
||
diff --git a/include/plugin-interface-v2.h b/include/plugin-interface-v2.h
|
||
index 19b0824..2643ffc 100644
|
||
--- a/include/plugin-interface-v2.h
|
||
+++ b/include/plugin-interface-v2.h
|
||
@@ -38,8 +38,8 @@ public:
|
||
//主面板调用该接口取消掉该插件初始化做的操作并卸载该插件
|
||
virtual void uninit() = 0;
|
||
|
||
- // 功能项数组,生存周期由插件维护
|
||
- // 功能项发生变更时,应调用init时传入KcpInterface接口,通知主面板相关信息变更,及时加载新的功能项信息
|
||
+ // 功能项数组
|
||
+ // 功能项发生变更时,应调用init时传入KcpInterface接口,通知主面板功能项发生变更,及时同步功能项
|
||
virtual QVector<KiranControlPanel::SubItemPtr> getSubItems() = 0;
|
||
};
|
||
} // namespace KiranControlPanel
|
||
diff --git a/include/plugin-subitem-interface.h b/include/plugin-subitem-interface.h
|
||
index b28be7e..01fc608 100644
|
||
--- a/include/plugin-subitem-interface.h
|
||
+++ b/include/plugin-subitem-interface.h
|
||
@@ -46,7 +46,7 @@ public:
|
||
// QVector< 显示文本(已翻译),搜索跳转标识ID >
|
||
virtual QVector<QPair<QString, QString>> getSearchKeys() = 0;
|
||
|
||
- //创建显示控件
|
||
+ //创建该功能项显示控件,释放由控制中心主面板决定
|
||
virtual QWidget* createWidget() = 0;
|
||
|
||
//跳转至自定义搜索项
|
||
diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp
|
||
index 7bb78f2..eaeee99 100644
|
||
--- a/launcher/src/main.cpp
|
||
+++ b/launcher/src/main.cpp
|
||
@@ -119,7 +119,6 @@ int main(int argc, char *argv[])
|
||
w.setIcon(titleIcon);
|
||
w.setSubItems(plugin.getSubItems());
|
||
w.resize(w.sizeHint());
|
||
- KLOG_DEBUG() << "sizeHint:" << w.sizeHint();
|
||
|
||
QScreen* screen = QApplication::screenAt(QCursor::pos());
|
||
QRect screenGeometry = screen->geometry();
|
||
diff --git a/lib/common-widgets/hover-tips/hover-tips.cpp b/lib/common-widgets/hover-tips/hover-tips.cpp
|
||
index 61821dc..569290a 100644
|
||
--- a/lib/common-widgets/hover-tips/hover-tips.cpp
|
||
+++ b/lib/common-widgets/hover-tips/hover-tips.cpp
|
||
@@ -39,7 +39,7 @@ void HoverTips::show(HoverTipsTypeEnum typeEnum, const QString &msg)
|
||
auto iter = m_tipsTypeIconMap.find(typeEnum);
|
||
if (iter == m_tipsTypeIconMap.end())
|
||
{
|
||
- KLOG_WARNING() << "invalid type enum";
|
||
+ KLOG_WARNING() << "HoverTips: invalid type enum" << typeEnum;
|
||
return;
|
||
}
|
||
|
||
@@ -66,9 +66,10 @@ void HoverTips::updatePostion()
|
||
{
|
||
if (parentWidget() == nullptr)
|
||
{
|
||
- KLOG_WARNING() << "hover tips parnetwidget is null";
|
||
+ KLOG_WARNING() << "HoverTips: parnetwidget is null,don't update position";
|
||
return;
|
||
}
|
||
+
|
||
this->move((parentWidget()->width() - width()) / 2,
|
||
(parentWidget()->height() - height()) / 2);
|
||
}
|
||
@@ -97,7 +98,7 @@ void HoverTips::setIcon(HoverTips::HoverTipsTypeEnum typeEnum, const QString &ic
|
||
QPixmap pixmap;
|
||
if (!pixmap.load(icon) || pixmap.isNull())
|
||
{
|
||
- KLOG_WARNING() << "load icon failed.";
|
||
+ KLOG_WARNING() << "HoverTips: load icon" << icon << "failed.";
|
||
return;
|
||
}
|
||
m_tipsTypeIconMap[typeEnum] = icon;
|
||
diff --git a/lib/common-widgets/kiran-module-widget/kiran-module-widget.cpp b/lib/common-widgets/kiran-module-widget/kiran-module-widget.cpp
|
||
index 629bf83..6ddb2bd 100644
|
||
--- a/lib/common-widgets/kiran-module-widget/kiran-module-widget.cpp
|
||
+++ b/lib/common-widgets/kiran-module-widget/kiran-module-widget.cpp
|
||
@@ -42,9 +42,12 @@ KiranModuleWidget::~KiranModuleWidget()
|
||
|
||
void KiranModuleWidget::clear()
|
||
{
|
||
- disconnect(m_category, &Category::subItemAdded, this, &KiranModuleWidget::handleCategorySubItemAdded);
|
||
- disconnect(m_category, &Category::subItemDeleted, this, &KiranModuleWidget::handleCategorySubItemDeleted);
|
||
- disconnect(m_category, &Category::subItemInfoChanged, this, &KiranModuleWidget::handleCategorySubItemInfoChanged);
|
||
+ if (m_category != nullptr)
|
||
+ {
|
||
+ disconnect(m_category, &Category::subItemAdded, this, &KiranModuleWidget::handleCategorySubItemAdded);
|
||
+ disconnect(m_category, &Category::subItemDeleted, this, &KiranModuleWidget::handleCategorySubItemDeleted);
|
||
+ disconnect(m_category, &Category::subItemInfoChanged, this, &KiranModuleWidget::handleCategorySubItemInfoChanged);
|
||
+ }
|
||
|
||
ui->list_subItems->clear();
|
||
ui->widget_siderbar->hide();
|
||
@@ -96,7 +99,7 @@ void KiranModuleWidget::appendListWidgetItem(KiranControlPanel::SubItemPtr subit
|
||
item->setWeight(subitem->getWeight());
|
||
if (icon.isNull())
|
||
{
|
||
- KLOG_WARNING() << "can't find subitem icon:" << name << icon;
|
||
+ KLOG_WARNING() << "KiranModuleWidget: can't find subitem icon:" << name << icon;
|
||
}
|
||
else
|
||
{
|
||
@@ -154,7 +157,7 @@ void KiranModuleWidget::handleCurrentItemChanged()
|
||
auto selectedItems = ui->list_subItems->selectedItems();
|
||
if (selectedItems.size() != 1)
|
||
{
|
||
- KLOG_ERROR() << "sider bar size != 1";
|
||
+ KLOG_ERROR() << "KiranModuleWidget: sider bar size != 1";
|
||
return;
|
||
}
|
||
|
||
@@ -162,21 +165,21 @@ void KiranModuleWidget::handleCurrentItemChanged()
|
||
|
||
if (m_currentSubItem.first == selectedItem)
|
||
{
|
||
- KLOG_DEBUG() << "subitem not changed,ignore 'itemSelectionChanged' signal!";
|
||
+ KLOG_DEBUG() << "KiranModuleWidget: subitem not changed,ignore 'itemSelectionChanged' signal!";
|
||
return;
|
||
}
|
||
|
||
auto mapIter = m_subItemsMap.find(selectedItem);
|
||
if (mapIter == m_subItemsMap.end())
|
||
{
|
||
- KLOG_WARNING() << "can't find KiranControlPanel::SubItemPtr by QListWidgetItem," << selectedItem->text();
|
||
+ KLOG_WARNING() << "KiranModuleWidget: can't find KiranControlPanel::SubItemPtr by QListWidgetItem," << selectedItem->text();
|
||
return;
|
||
}
|
||
|
||
KiranControlPanel::SubItemPtr pluginSubitem = *mapIter;
|
||
if (checkHasUnSaved())
|
||
{
|
||
- KLOG_DEBUG() << "switch subitem to:" << pluginSubitem->getName() << "reject";
|
||
+ KLOG_DEBUG() << "KiranModuleWidget: switch subitem to:" << pluginSubitem->getName() << "reject";
|
||
m_currentSubItem.first->setSelected(true);
|
||
return;
|
||
}
|
||
@@ -194,12 +197,12 @@ void KiranModuleWidget::handleCurrentItemChanged()
|
||
QWidget *widget = pluginSubitem->createWidget();
|
||
if (widget)
|
||
{
|
||
- KLOG_DEBUG() << "sub item widget sizeHint:" << widget->sizeHint();
|
||
+ KLOG_DEBUG() << "KiranModuleWidget: sub item widget sizeHint:" << widget->sizeHint();
|
||
ui->centerLayout->addWidget(widget);
|
||
}
|
||
else
|
||
{
|
||
- KLOG_ERROR() << "can't get subitem widget:" << pluginSubitem->getName() << pluginSubitem->getID();
|
||
+ KLOG_ERROR() << "KiranModuleWidget: can't get subitem widget:" << pluginSubitem->getName() << pluginSubitem->getID();
|
||
}
|
||
|
||
m_subItemWidget = widget;
|
||
diff --git a/plugins/appearance/src/kiran-cpanel-appearance.cpp b/plugins/appearance/src/kiran-cpanel-appearance.cpp
|
||
deleted file mode 100644
|
||
index 3dee3c6..0000000
|
||
--- a/plugins/appearance/src/kiran-cpanel-appearance.cpp
|
||
+++ /dev/null
|
||
@@ -1,67 +0,0 @@
|
||
-/**
|
||
- * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
|
||
- * kiran-control-panel is licensed under Mulan PSL v2.
|
||
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
- * You may obtain a copy of Mulan PSL v2 at:
|
||
- * http://license.coscl.org.cn/MulanPSL2
|
||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||
- * See the Mulan PSL v2 for more details.
|
||
- *
|
||
- * Author: yuanxing <yuanxing@kylinsec.com.cn>
|
||
- */
|
||
-
|
||
-#include "kiran-cpanel-appearance.h"
|
||
-#include <QListWidgetItem>
|
||
-#include "ui_kiran-cpanel-appearance.h"
|
||
-
|
||
-KiranCpanelAppearance::KiranCpanelAppearance(QWidget *parent) : KiranTitlebarWindow(parent),
|
||
- ui(new Ui::KiranCpanelAppearance)
|
||
-{
|
||
- ui->setupUi(getWindowContentWidget());
|
||
- initUI();
|
||
-
|
||
- connect(ui->listWidget, &KiranSidebarWidget::itemClicked,
|
||
- [=](QListWidgetItem *item) {
|
||
- int row = ui->listWidget->row(item);
|
||
- ui->stackedWidget->setCurrentIndex(row);
|
||
- //TODO:后续根据需求确定是否切换列表项时需要指定第一页
|
||
- if (row == ITEM_BACKGROUND)
|
||
- ;
|
||
- else if (row == ITEM_THEME)
|
||
- {
|
||
- ui->page_theme->setPage(0);
|
||
- }
|
||
- else
|
||
- {
|
||
- };
|
||
- });
|
||
-}
|
||
-
|
||
-KiranCpanelAppearance::~KiranCpanelAppearance()
|
||
-{
|
||
- delete ui;
|
||
-}
|
||
-
|
||
-bool KiranCpanelAppearance::initUI()
|
||
-{
|
||
- //TODO:connect dbus if faile return false;
|
||
- setIcon(QIcon::fromTheme("kcp-appearance"));
|
||
-
|
||
- ui->listWidget->setIconSize(QSize(16, 16));
|
||
- addSidebarItem(tr("Wallpaper Setting"), ":/images/wallpaper.svg");
|
||
- addSidebarItem(tr("Theme Setting"), ":/images/themes.svg");
|
||
- addSidebarItem(tr("Font Setting"), ":/images/themes.svg");
|
||
-
|
||
- ui->listWidget->setCurrentRow(0);
|
||
- return true;
|
||
-}
|
||
-
|
||
-void KiranCpanelAppearance::addSidebarItem(QString text, QString icon)
|
||
-{
|
||
- QListWidgetItem *item = new QListWidgetItem(ui->listWidget);
|
||
- item->setIcon(QIcon(icon));
|
||
- item->setText(text);
|
||
- ui->listWidget->addItem(item);
|
||
-}
|
||
diff --git a/plugins/appearance/src/kiran-cpanel-appearance.h b/plugins/appearance/src/kiran-cpanel-appearance.h
|
||
deleted file mode 100644
|
||
index a5edb7c..0000000
|
||
--- a/plugins/appearance/src/kiran-cpanel-appearance.h
|
||
+++ /dev/null
|
||
@@ -1,60 +0,0 @@
|
||
-/**
|
||
- * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
|
||
- * kiran-control-panel is licensed under Mulan PSL v2.
|
||
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
- * You may obtain a copy of Mulan PSL v2 at:
|
||
- * http://license.coscl.org.cn/MulanPSL2
|
||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||
- * See the Mulan PSL v2 for more details.
|
||
- *
|
||
- * Author: yuanxing <yuanxing@kylinsec.com.cn>
|
||
- */
|
||
-
|
||
-#ifndef KIRANCPANELAPPEARANCE_H
|
||
-#define KIRANCPANELAPPEARANCE_H
|
||
-#include <kiran-titlebar-window.h>
|
||
-
|
||
-#include <QWidget>
|
||
-
|
||
-namespace Ui
|
||
-{
|
||
-class KiranCpanelAppearance;
|
||
-}
|
||
-
|
||
-enum pages
|
||
-{
|
||
- PAGE_BACKGROUND = 0,
|
||
- PAGE_THEME,
|
||
- PAGE_FONT,
|
||
- PAGE_BACKGROND_SELECT,
|
||
- PAGE_ICON_THEME,
|
||
- PAGE_CURSOR_THEME
|
||
-};
|
||
-
|
||
-enum items
|
||
-{
|
||
- ITEM_BACKGROUND = 0,
|
||
- ITEM_THEME,
|
||
- ITEM_FONT
|
||
-};
|
||
-
|
||
-class QListWidgetItem;
|
||
-class KiranCpanelAppearance : public KiranTitlebarWindow
|
||
-{
|
||
- Q_OBJECT
|
||
-
|
||
-public:
|
||
- explicit KiranCpanelAppearance(QWidget *parent = 0);
|
||
- ~KiranCpanelAppearance();
|
||
-
|
||
-private:
|
||
- bool initUI();
|
||
- void addSidebarItem(QString, QString);
|
||
-
|
||
-private:
|
||
- Ui::KiranCpanelAppearance *ui;
|
||
-};
|
||
-
|
||
-#endif // KIRANCPANELAPPEARANCE_H
|
||
diff --git a/plugins/appearance/src/kiran-cpanel-appearance.ui b/plugins/appearance/src/kiran-cpanel-appearance.ui
|
||
deleted file mode 100644
|
||
index d2cdea5..0000000
|
||
--- a/plugins/appearance/src/kiran-cpanel-appearance.ui
|
||
+++ /dev/null
|
||
@@ -1,130 +0,0 @@
|
||
-<?xml version="1.0" encoding="UTF-8"?>
|
||
-<ui version="4.0">
|
||
- <class>KiranCpanelAppearance</class>
|
||
- <widget class="QWidget" name="KiranCpanelAppearance">
|
||
- <property name="geometry">
|
||
- <rect>
|
||
- <x>0</x>
|
||
- <y>0</y>
|
||
- <width>712</width>
|
||
- <height>591</height>
|
||
- </rect>
|
||
- </property>
|
||
- <property name="windowTitle">
|
||
- <string>KiranCpanelAppearance</string>
|
||
- </property>
|
||
- <layout class="QHBoxLayout" name="horizontalLayout">
|
||
- <property name="spacing">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="leftMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="topMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="rightMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="bottomMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <item>
|
||
- <widget class="QWidget" name="widget_sidebar" native="true">
|
||
- <property name="sizePolicy">
|
||
- <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||
- <horstretch>0</horstretch>
|
||
- <verstretch>0</verstretch>
|
||
- </sizepolicy>
|
||
- </property>
|
||
- <layout class="QVBoxLayout" name="verticalLayout">
|
||
- <property name="leftMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="topMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="rightMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="bottomMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <item>
|
||
- <widget class="KiranSidebarWidget" name="listWidget">
|
||
- <property name="sizePolicy">
|
||
- <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||
- <horstretch>0</horstretch>
|
||
- <verstretch>0</verstretch>
|
||
- </sizepolicy>
|
||
- </property>
|
||
- <property name="maximumSize">
|
||
- <size>
|
||
- <width>282</width>
|
||
- <height>16777215</height>
|
||
- </size>
|
||
- </property>
|
||
- </widget>
|
||
- </item>
|
||
- </layout>
|
||
- </widget>
|
||
- </item>
|
||
- <item>
|
||
- <widget class="QWidget" name="widget_page" native="true">
|
||
- <layout class="QVBoxLayout" name="verticalLayout_2">
|
||
- <property name="spacing">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="leftMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="topMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="rightMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <property name="bottomMargin">
|
||
- <number>0</number>
|
||
- </property>
|
||
- <item>
|
||
- <widget class="QStackedWidget" name="stackedWidget">
|
||
- <widget class="Wallpaper" name="page_wallpaper"/>
|
||
- <widget class="Themes" name="page_theme"/>
|
||
- <widget class="Fonts" name="page_font"/>
|
||
- </widget>
|
||
- </item>
|
||
- </layout>
|
||
- </widget>
|
||
- </item>
|
||
- </layout>
|
||
- </widget>
|
||
- <layoutdefault spacing="6" margin="11"/>
|
||
- <customwidgets>
|
||
- <customwidget>
|
||
- <class>KiranSidebarWidget</class>
|
||
- <extends>QListWidget</extends>
|
||
- <header location="global">/usr/include/kiranwidgets-qt5/kiran-sidebar-widget.h</header>
|
||
- </customwidget>
|
||
- <customwidget>
|
||
- <class>Fonts</class>
|
||
- <extends>QWidget</extends>
|
||
- <header>pages/font/fonts.h</header>
|
||
- <container>1</container>
|
||
- </customwidget>
|
||
- <customwidget>
|
||
- <class>Themes</class>
|
||
- <extends>QWidget</extends>
|
||
- <header>pages/theme/themes.h</header>
|
||
- <container>1</container>
|
||
- </customwidget>
|
||
- <customwidget>
|
||
- <class>Wallpaper</class>
|
||
- <extends>QWidget</extends>
|
||
- <header>pages/wallpaper/wallpaper.h</header>
|
||
- <container>1</container>
|
||
- </customwidget>
|
||
- </customwidgets>
|
||
- <resources/>
|
||
- <connections/>
|
||
-</ui>
|
||
diff --git a/plugins/appearance/src/pages/theme/icon-themes/icon-themes.cpp b/plugins/appearance/src/pages/theme/icon-themes/icon-themes.cpp
|
||
index 184ae66..6e6f614 100644
|
||
--- a/plugins/appearance/src/pages/theme/icon-themes/icon-themes.cpp
|
||
+++ b/plugins/appearance/src/pages/theme/icon-themes/icon-themes.cpp
|
||
@@ -13,9 +13,11 @@
|
||
*/
|
||
|
||
#include "icon-themes.h"
|
||
+
|
||
#include <kiran-log/qt5-log-i.h>
|
||
#include <kiran-session-daemon/appearance-i.h>
|
||
#include <kiranwidgets-qt5/kiran-message-box.h>
|
||
+
|
||
#include <QDir>
|
||
#include <QIcon>
|
||
#include <QJsonArray>
|
||
@@ -23,6 +25,7 @@
|
||
#include <QJsonObject>
|
||
#include <QJsonParseError>
|
||
#include <QVBoxLayout>
|
||
+
|
||
#include "../theme-widget-group.h"
|
||
#include "../theme-widget.h"
|
||
#include "dbus-interface/appearance-global-info.h"
|
||
@@ -49,7 +52,7 @@ IconThemes::~IconThemes()
|
||
|
||
bool IconThemes::initUI()
|
||
{
|
||
- if (!getIconThemes(APPEARANCE_THEME_TYPE_ICON))
|
||
+ if (!getIconThemes())
|
||
{
|
||
return false;
|
||
}
|
||
@@ -84,10 +87,10 @@ void IconThemes::updateIconTheme(QString newIconTheme)
|
||
* @return true 成功
|
||
* false 失败
|
||
*/
|
||
-bool IconThemes::getIconThemes(int themeType)
|
||
+bool IconThemes::getIconThemes()
|
||
{
|
||
QString iconThemesJson = nullptr;
|
||
- if (!AppearanceGlobalInfo::instance()->getAllThemes(themeType, iconThemesJson))
|
||
+ if (!AppearanceGlobalInfo::instance()->getAllThemes(APPEARANCE_THEME_TYPE_ICON, iconThemesJson))
|
||
{
|
||
return false;
|
||
}
|
||
@@ -103,44 +106,51 @@ int IconThemes::getJsonValueFromString(QString jsonString)
|
||
{
|
||
QJsonParseError jsonError;
|
||
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonString.toLocal8Bit().data(), &jsonError);
|
||
+
|
||
if (jsonDocument.isNull() || jsonError.error != QJsonParseError::NoError)
|
||
{
|
||
- KLOG_ERROR() << " please check the string " << jsonString.toLocal8Bit().data();
|
||
+ KLOG_ERROR() << "parse icon theme json failed," << jsonString << jsonError.errorString() << jsonError.error;
|
||
+ return -1;
|
||
+ }
|
||
+
|
||
+ if( !jsonDocument.isArray() )
|
||
+ {
|
||
+ return 0;
|
||
+ }
|
||
+
|
||
+ QJsonArray array = jsonDocument.array();
|
||
+ if( array.size() < 1 )
|
||
+ {
|
||
return -1;
|
||
}
|
||
- if (jsonDocument.isArray())
|
||
+
|
||
+ for (int i = 0; i < array.size();i++)
|
||
{
|
||
- QJsonArray array = jsonDocument.array();
|
||
- int iconThemesNum = array.size();
|
||
- if (iconThemesNum < 1)
|
||
- return -1;
|
||
- for (int i = 0; i < iconThemesNum; i++)
|
||
+ QJsonValue value = array.at(i);
|
||
+ if( value.type() != QJsonValue::Object )
|
||
{
|
||
- QJsonValue value = array.at(i);
|
||
- if (value.type() == QJsonValue::Object)
|
||
- {
|
||
- QJsonObject themeInfoObj = value.toObject();
|
||
- if (themeInfoObj.contains("name"))
|
||
- {
|
||
- QJsonValue themeValue = themeInfoObj.value("name");
|
||
- if (themeValue.isString())
|
||
- {
|
||
- QString name = themeValue.toVariant().toString();
|
||
- m_iconThemes.insert(i, name);
|
||
- }
|
||
- }
|
||
- if (themeInfoObj.contains("path"))
|
||
- {
|
||
- QJsonValue themeValue = themeInfoObj.value("path");
|
||
- if (themeValue.isString())
|
||
- {
|
||
- QString path = themeValue.toVariant().toString();
|
||
- m_iconThemesPath.insert(i, path);
|
||
- }
|
||
- }
|
||
- }
|
||
+ continue;
|
||
}
|
||
+
|
||
+ QJsonObject themeInfoObj = value.toObject();
|
||
+ if( !themeInfoObj.contains("name") || !themeInfoObj.contains("path") )
|
||
+ {
|
||
+ KLOG_WARNING() << "parse getAllThemes json failed,Missing specific key(name/path)";
|
||
+ continue;
|
||
+ }
|
||
+ if( !themeInfoObj["name"].isString() || !themeInfoObj["path"].isString() )
|
||
+ {
|
||
+ KLOG_WARNING() << "parse getAllThemes json failed,Wrong key format(name/path)";
|
||
+ continue;
|
||
+ }
|
||
+
|
||
+ QString name = themeInfoObj["name"].toString();
|
||
+ m_iconThemes.append(name);
|
||
+
|
||
+ QString path = themeInfoObj["path"].toString();
|
||
+ m_iconThemesPath.append(path);
|
||
}
|
||
+
|
||
return m_iconThemes.size();
|
||
}
|
||
|
||
@@ -153,8 +163,10 @@ void IconThemes::createIconWidgets()
|
||
QVBoxLayout *vLayout = new QVBoxLayout(ui->widget_icon);
|
||
vLayout->setMargin(0);
|
||
vLayout->setSpacing(4);
|
||
+
|
||
for (int i = 0; i < m_iconThemes.size(); i++)
|
||
{
|
||
+
|
||
if (m_iconThemes.at(i).startsWith("Kiran", Qt::CaseInsensitive))
|
||
{
|
||
QString path = m_iconThemesPath.at(i) + "/apps/scalable/";
|
||
@@ -238,6 +250,7 @@ void IconThemes::createIconWidgets()
|
||
continue;
|
||
}
|
||
}
|
||
+
|
||
connect(m_iconThemeWidgetGroup, &ThemeWidgetGroup::themeWidgetChange,
|
||
[=](ThemeWidget *preWidget, ThemeWidget *currWidget) {
|
||
if (currWidget->getTheme() == m_currentIconTheme)
|
||
diff --git a/plugins/appearance/src/pages/theme/icon-themes/icon-themes.h b/plugins/appearance/src/pages/theme/icon-themes/icon-themes.h
|
||
index 1e57ee0..3a86516 100644
|
||
--- a/plugins/appearance/src/pages/theme/icon-themes/icon-themes.h
|
||
+++ b/plugins/appearance/src/pages/theme/icon-themes/icon-themes.h
|
||
@@ -34,7 +34,7 @@ public:
|
||
void updateIconTheme(QString newIconTheme);
|
||
|
||
private:
|
||
- bool getIconThemes(int themeType);
|
||
+ bool getIconThemes();
|
||
int getJsonValueFromString(QString jsonString);
|
||
void createIconWidgets();
|
||
|
||
--
|
||
2.33.0
|
||
|