2023-02-16 13:51:55 +08:00
|
|
|
// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2017-09-18 14:33:44 +08:00
|
|
|
|
2016-08-01 10:58:10 +08:00
|
|
|
#include "trashplugin.h"
|
2020-06-29 15:35:51 +08:00
|
|
|
#include "../../widgets/tipswidget.h"
|
2023-12-07 16:04:05 +08:00
|
|
|
#include "imageutil.h"
|
2016-08-01 10:58:10 +08:00
|
|
|
|
2018-09-19 10:56:17 +08:00
|
|
|
#include <DApplication>
|
2021-01-20 17:53:52 +08:00
|
|
|
#include <DDesktopServices>
|
2022-12-01 12:38:38 +08:00
|
|
|
#include <DGuiApplicationHelper>
|
|
|
|
|
|
|
|
#include <QPainter>
|
2018-09-19 10:56:17 +08:00
|
|
|
|
2019-02-27 14:14:45 +08:00
|
|
|
#define PLUGIN_STATE_KEY "enable"
|
|
|
|
|
2018-09-19 10:56:17 +08:00
|
|
|
DWIDGET_USE_NAMESPACE
|
2022-12-01 12:38:38 +08:00
|
|
|
DGUI_USE_NAMESPACE
|
2018-09-19 10:56:17 +08:00
|
|
|
|
2020-06-29 15:35:51 +08:00
|
|
|
using namespace Dock;
|
|
|
|
|
2016-08-01 10:58:10 +08:00
|
|
|
TrashPlugin::TrashPlugin(QObject *parent)
|
2019-09-06 15:28:22 +08:00
|
|
|
: QObject(parent)
|
|
|
|
, m_trashWidget(nullptr)
|
2019-09-27 11:41:21 +08:00
|
|
|
, m_tipsLabel(new TipsWidget)
|
2016-08-01 10:58:10 +08:00
|
|
|
{
|
2020-07-16 14:28:02 +08:00
|
|
|
m_tipsLabel->setObjectName("trash");
|
2016-08-01 10:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString TrashPlugin::pluginName() const
|
|
|
|
{
|
|
|
|
return "trash";
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:14:45 +08:00
|
|
|
const QString TrashPlugin::pluginDisplayName() const
|
|
|
|
{
|
|
|
|
return tr("Trash");
|
|
|
|
}
|
|
|
|
|
2016-08-01 10:58:10 +08:00
|
|
|
void TrashPlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
2018-11-08 11:39:26 +08:00
|
|
|
// transfex config
|
|
|
|
QSettings settings("deepin", "dde-dock-trash");
|
|
|
|
if (QFile::exists(settings.fileName())) {
|
|
|
|
const QString &key = QString("pos_%1_%2").arg(pluginName()).arg(displayMode());
|
|
|
|
proxyInter->saveValue(this, key, settings.value(key));
|
|
|
|
|
|
|
|
QFile::remove(settings.fileName());
|
|
|
|
}
|
|
|
|
|
2018-09-19 10:56:17 +08:00
|
|
|
// blumia: we are using i10n translation from DFM so...
|
|
|
|
QString applicationName = qApp->applicationName();
|
|
|
|
qApp->setApplicationName("dde-file-manager");
|
|
|
|
qDebug() << qApp->loadTranslator();
|
|
|
|
qApp->setApplicationName(applicationName);
|
2016-08-01 10:58:10 +08:00
|
|
|
|
2018-09-19 10:56:17 +08:00
|
|
|
m_proxyInter = proxyInter;
|
2019-09-06 15:28:22 +08:00
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
if (m_trashWidget.isNull())
|
|
|
|
m_trashWidget.reset(new TrashWidget);
|
2019-09-06 15:28:22 +08:00
|
|
|
|
2016-08-09 16:01:28 +08:00
|
|
|
displayModeChanged(displayMode());
|
2016-08-01 10:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *TrashPlugin::itemWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
return m_trashWidget.data();
|
2016-08-01 10:58:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 14:42:22 +08:00
|
|
|
QWidget *TrashPlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2021-09-03 13:31:32 +08:00
|
|
|
if (m_trashWidget->getDragging()) {
|
2021-10-13 11:01:29 +08:00
|
|
|
m_tipsLabel->setText(tr("Move to Trash"));
|
2021-09-03 13:31:32 +08:00
|
|
|
return m_tipsLabel.data();
|
|
|
|
}
|
|
|
|
|
2016-09-20 14:42:22 +08:00
|
|
|
const int count = m_trashWidget->trashItemCount();
|
|
|
|
if (count < 2)
|
2016-11-17 15:27:42 +08:00
|
|
|
m_tipsLabel->setText(tr("Trash - %1 file").arg(count));
|
2016-09-20 14:42:22 +08:00
|
|
|
else
|
2016-11-17 15:27:42 +08:00
|
|
|
m_tipsLabel->setText(tr("Trash - %1 files").arg(count));
|
2016-09-20 14:42:22 +08:00
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
return m_tipsLabel.data();
|
2016-09-20 14:42:22 +08:00
|
|
|
}
|
|
|
|
|
2016-08-01 14:26:15 +08:00
|
|
|
QWidget *TrashPlugin::itemPopupApplet(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2016-08-08 19:19:11 +08:00
|
|
|
return nullptr;
|
2016-08-01 14:26:15 +08:00
|
|
|
}
|
|
|
|
|
2016-08-01 10:58:10 +08:00
|
|
|
const QString TrashPlugin::itemCommand(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
2021-01-20 17:53:52 +08:00
|
|
|
DDesktopServices::showFolder(QUrl("trash:///"));
|
2016-08-01 10:58:10 +08:00
|
|
|
|
2021-01-20 17:53:52 +08:00
|
|
|
return QString();
|
|
|
|
// return "gio open trash:///";
|
2016-08-01 10:58:10 +08:00
|
|
|
}
|
2016-08-09 16:01:28 +08:00
|
|
|
|
2016-09-19 14:11:18 +08:00
|
|
|
const QString TrashPlugin::itemContextMenu(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2016-09-19 15:06:25 +08:00
|
|
|
return m_trashWidget->contextMenu();
|
|
|
|
}
|
|
|
|
|
2018-12-04 16:05:15 +08:00
|
|
|
void TrashPlugin::refreshIcon(const QString &itemKey)
|
2017-03-20 10:36:18 +08:00
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
m_trashWidget->updateIcon();
|
|
|
|
}
|
|
|
|
|
2016-09-19 15:06:25 +08:00
|
|
|
void TrashPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
m_trashWidget->invokeMenuItem(menuId, checked);
|
2016-09-19 14:11:18 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 14:14:45 +08:00
|
|
|
bool TrashPlugin::pluginIsDisable()
|
|
|
|
{
|
|
|
|
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrashPlugin::pluginStateSwitched()
|
|
|
|
{
|
|
|
|
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
|
|
|
|
|
|
|
|
if (pluginIsDisable()) {
|
|
|
|
m_proxyInter->itemRemoved(this, pluginName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-03 16:08:12 +08:00
|
|
|
if (m_trashWidget) {
|
2019-02-27 14:14:45 +08:00
|
|
|
m_proxyInter->itemAdded(this, pluginName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 16:01:28 +08:00
|
|
|
int TrashPlugin::itemSortKey(const QString &itemKey)
|
|
|
|
{
|
2020-01-11 10:35:29 +08:00
|
|
|
const QString &key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
|
|
|
|
return m_proxyInter->getValue(this, key, 7).toInt();
|
2018-09-19 10:56:17 +08:00
|
|
|
}
|
2016-08-09 16:01:28 +08:00
|
|
|
|
2018-09-19 10:56:17 +08:00
|
|
|
void TrashPlugin::setSortKey(const QString &itemKey, const int order)
|
|
|
|
{
|
2020-01-11 10:35:29 +08:00
|
|
|
const QString &key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
|
2018-11-08 11:39:26 +08:00
|
|
|
m_proxyInter->saveValue(this, key, order);
|
2016-08-09 16:01:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
|
|
|
{
|
2021-05-25 13:05:45 +08:00
|
|
|
Q_UNUSED(displayMode);
|
|
|
|
|
2019-02-27 14:14:45 +08:00
|
|
|
if (pluginIsDisable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-22 10:44:04 +08:00
|
|
|
m_proxyInter->itemAdded(this, pluginName());
|
2016-08-09 16:01:28 +08:00
|
|
|
}
|
2019-09-30 15:39:03 +08:00
|
|
|
|
|
|
|
void TrashPlugin::pluginSettingsChanged()
|
|
|
|
{
|
|
|
|
refreshPluginItemsVisible();
|
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
QIcon TrashPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType)
|
2022-11-23 05:27:16 +00:00
|
|
|
{
|
2022-12-01 12:38:38 +08:00
|
|
|
if (dockPart == DockPart::DCCSetting) {
|
2023-12-07 16:04:05 +08:00
|
|
|
auto pixmap = ImageUtil::loadSvg(":/icons/dcc_trash.svg", QSize(18, 18));
|
2022-12-01 12:38:38 +08:00
|
|
|
if (themeType == DGuiApplicationHelper::ColorType::LightType)
|
2023-12-07 16:04:05 +08:00
|
|
|
return pixmap;
|
2022-12-01 12:38:38 +08:00
|
|
|
|
|
|
|
QPainter pa(&pixmap);
|
|
|
|
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
|
|
|
pa.fillRect(pixmap.rect(), Qt::white);
|
|
|
|
return pixmap;
|
|
|
|
}
|
2022-11-23 05:27:16 +00:00
|
|
|
|
|
|
|
return QIcon();
|
|
|
|
}
|
|
|
|
|
2022-11-28 14:37:54 +08:00
|
|
|
PluginFlags TrashPlugin::flags() const
|
|
|
|
{
|
|
|
|
return PluginFlag::Type_Tool
|
|
|
|
| PluginFlag::Attribute_CanSetting;
|
|
|
|
}
|
|
|
|
|
2019-09-30 15:39:03 +08:00
|
|
|
void TrashPlugin::refreshPluginItemsVisible()
|
|
|
|
{
|
|
|
|
if (pluginIsDisable()) {
|
|
|
|
m_proxyInter->itemRemoved(this, pluginName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_trashWidget) {
|
|
|
|
m_proxyInter->itemAdded(this, pluginName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|