Skip to content

Commit

Permalink
feat: [extension] add unload operation
Browse files Browse the repository at this point in the history
Log:
Change-Id: I337b89ffd993c42492a821138951578530c80d53
  • Loading branch information
deepin-mozart committed Feb 21, 2024
1 parent 09b9dad commit 162c3a5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
Binary file removed assets/configures/deepin-unioncode.elf
Binary file not shown.
44 changes: 39 additions & 5 deletions src/plugins/core/gui/plugindetailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "plugindetailsview.h"
#include "framework/lifecycle/lifecycle.h"

#include <DWidget>
#include <DLabel>
#include <DTextEdit>
#include <DListWidget>
#include <DPushButton>

#include <QGridLayout>
#include <QDesktopServices>
Expand All @@ -22,6 +24,8 @@ DetailsView::DetailsView(QWidget *parent)

void DetailsView::update(const dpf::PluginMetaObjectPointer &metaInfo)
{
pluginMetaInfo = metaInfo;

if (metaInfo.isNull())
return;

Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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);
}
9 changes: 8 additions & 1 deletion src/plugins/core/gui/plugindetailsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DetailsView : public DTK_WIDGET_NAMESPACE::DWidget
"<tr><td><strong>" + tr("License") + ":</strong></td><td>" + license + "</td></tr>"
"<tr><td><strong>" + tr("Description") + ":</strong></td><td>" + description + "</td></tr>"
"<tr><td><strong>" + tr("Dependency") + ":</strong></td><td>" + dependency + "</td></tr>"
"</table><br><hr>"
"</table><br>"
"</body>"
"</html>";
return html;
Expand All @@ -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
24 changes: 17 additions & 7 deletions src/plugins/core/gui/pluginitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit 162c3a5

Please sign in to comment.