From ee66a8e297b1142e03f737a6b7dab9aa4aaba6af Mon Sep 17 00:00:00 2001 From: Lu Zhen Date: Wed, 21 Feb 2024 13:11:24 +0800 Subject: [PATCH] feat: [extension] add unload operation Log: Change-Id: I337b89ffd993c42492a821138951578530c80d53 --- assets/configures/deepin-unioncode.elf | Bin 60 -> 0 bytes src/plugins/core/gui/plugindetailsview.cpp | 44 +++++++++++++++++--- src/plugins/core/gui/plugindetailsview.h | 9 +++- src/plugins/core/gui/pluginitemdelegate.cpp | 24 +++++++---- 4 files changed, 64 insertions(+), 13 deletions(-) delete mode 100644 assets/configures/deepin-unioncode.elf diff --git a/assets/configures/deepin-unioncode.elf b/assets/configures/deepin-unioncode.elf deleted file mode 100644 index 0b92e797e0c5224688f168ccfd1abc7fe9f7fece..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 60 zcmWe&U|>)HVn!fNNlh)t%+oE+%goP9&QD2AG)gf`Gf6QqNw!EaNi$8hOfgP1PBTuk MOf^q7Og2pg0IJ6jDF6Tf diff --git a/src/plugins/core/gui/plugindetailsview.cpp b/src/plugins/core/gui/plugindetailsview.cpp index 081eb185e..7c584e794 100644 --- a/src/plugins/core/gui/plugindetailsview.cpp +++ b/src/plugins/core/gui/plugindetailsview.cpp @@ -2,11 +2,13 @@ // // SPDX-License-Identifier: GPL-3.0-or-later #include "plugindetailsview.h" +#include "framework/lifecycle/lifecycle.h" #include #include #include #include +#include #include #include @@ -22,6 +24,8 @@ DetailsView::DetailsView(QWidget *parent) void DetailsView::update(const dpf::PluginMetaObjectPointer &metaInfo) { + pluginMetaInfo = metaInfo; + if (metaInfo.isNull()) return; @@ -48,6 +52,21 @@ void DetailsView::update(const dpf::PluginMetaObjectPointer &metaInfo) updateMetaInfo.description = metaInfo->description(); metaInfoLabel->setText(updateMetaInfo.toHtml()); + + bool pluginIsEnabled = pluginMetaInfo->isEnabledBySettings(); + updateLoadBtnDisplay(pluginIsEnabled); +} + +void DetailsView::changeLoadBtnState() +{ + if (pluginMetaInfo.isNull()) + return; + + bool isEnabled = !pluginMetaInfo->isEnabledBySettings(); + updateLoadBtnDisplay(isEnabled); + + pluginMetaInfo->setEnabledBySettings(isEnabled); + dpf::LifeCycle::getPluginManagerInstance()->writeSettings(); } void DetailsView::setupUi() @@ -57,13 +76,22 @@ void DetailsView::setupUi() mainLayout->setMargin(0); auto detailLayout = new QHBoxLayout(this); + auto midLayout = new QVBoxLayout(this); + midLayout->setSpacing(0); + midLayout->setMargin(0); metaInfoLabel = new DLabel(this); metaInfoLabel->setText(MetaInfo().toHtml()); metaInfoLabel->setOpenExternalLinks(true); metaInfoLabel->setWordWrap(true); + midLayout->addWidget(metaInfoLabel); + + loadBtn = new DPushButton(this); + loadBtn->setToolTip(tr("reLaunch when changed!")); + connect(loadBtn, &DPushButton::clicked, this, &DetailsView::changeLoadBtnState); + midLayout->addWidget(loadBtn, 0, Qt::AlignLeft); - QLabel *iconLabel = new QLabel(this); - iconLabel->setPixmap(QIcon::fromTheme("plugins-navigation").pixmap(QSize(128, 128))); + QLabel *logoLabel = new QLabel(this); + logoLabel->setPixmap(QIcon::fromTheme("plugins-navigation").pixmap(QSize(128, 128))); auto webViewLayout = new QHBoxLayout(this); QWebEngineView *webView = new QWebEngineView(this); @@ -73,9 +101,15 @@ void DetailsView::setupUi() webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); webViewLayout->addWidget(webView); - detailLayout->addWidget(iconLabel); - detailLayout->addWidget(metaInfoLabel, 1); - detailLayout->setContentsMargins(64, 10, 0, 0); + detailLayout->addWidget(logoLabel); + detailLayout->addLayout(midLayout, 1); + detailLayout->setContentsMargins(64, 10, 0, 10); mainLayout->addLayout(detailLayout); mainLayout->addLayout(webViewLayout); } + +void DetailsView::updateLoadBtnDisplay(bool isEnabled) +{ + QString loadOperation = isEnabled ? tr("unload") : tr("load"); + loadBtn->setText(loadOperation); +} diff --git a/src/plugins/core/gui/plugindetailsview.h b/src/plugins/core/gui/plugindetailsview.h index e11161eb3..10855bfae 100644 --- a/src/plugins/core/gui/plugindetailsview.h +++ b/src/plugins/core/gui/plugindetailsview.h @@ -52,7 +52,7 @@ class DetailsView : public DTK_WIDGET_NAMESPACE::DWidget "" + tr("License") + ":" + license + "" "" + tr("Description") + ":" + description + "" "" + tr("Dependency") + ":" + dependency + "" - "

" + "
" "" ""; return html; @@ -63,10 +63,17 @@ class DetailsView : public DTK_WIDGET_NAMESPACE::DWidget void update(const dpf::PluginMetaObjectPointer &metaInfo); +private slots: + void changeLoadBtnState(); + private: void setupUi(); + void updateLoadBtnDisplay(bool isEnabled); DTK_WIDGET_NAMESPACE::DLabel *metaInfoLabel {nullptr}; + DTK_WIDGET_NAMESPACE::DPushButton *loadBtn {nullptr}; + dpf::PluginMetaObjectPointer pluginMetaInfo; + }; #endif // PLUGINDETAILSVIEW_H diff --git a/src/plugins/core/gui/pluginitemdelegate.cpp b/src/plugins/core/gui/pluginitemdelegate.cpp index 218172055..6bab892d0 100644 --- a/src/plugins/core/gui/pluginitemdelegate.cpp +++ b/src/plugins/core/gui/pluginitemdelegate.cpp @@ -58,8 +58,9 @@ QSize PluginItemDelegate::sizeHint(const QStyleOptionViewItem &option, return DStyledItemDelegate::sizeHint(option, index); } -void PluginItemDelegate::paintItemBackground(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const +void PluginItemDelegate::paintItemBackground(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const { painter->save(); @@ -93,8 +94,9 @@ void PluginItemDelegate::paintItemBackground(QPainter *painter, const QStyleOpti painter->restore(); } -QRectF PluginItemDelegate::paintItemIcon(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const +QRectF PluginItemDelegate::paintItemIcon(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const { Q_UNUSED(index); @@ -135,8 +137,14 @@ QRectF PluginItemDelegate::paintItemIcon(QPainter *painter, const QStyleOptionVi return iconRect; } -QPixmap PluginItemDelegate::getIconPixmap(const QIcon &icon, const QSize &size, qreal pixelRatio = 1.0, QIcon::Mode mode, QIcon::State state) +QPixmap PluginItemDelegate::getIconPixmap(const QIcon &icon, + const QSize &size, + qreal pixelRatio = 1.0, + QIcon::Mode mode, + QIcon::State state) { + Q_UNUSED(pixelRatio) + if (icon.isNull()) return QPixmap(); @@ -149,8 +157,10 @@ QPixmap PluginItemDelegate::getIconPixmap(const QIcon &icon, const QSize &size, return px; } -void PluginItemDelegate::paintItemColumn(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index, const QRectF &iconRect) const +void PluginItemDelegate::paintItemColumn(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index, + const QRectF &iconRect) const { painter->save();