2016-08-01 10:58:10 +08:00
|
|
|
#include "trashplugin.h"
|
|
|
|
|
|
|
|
TrashPlugin::TrashPlugin(QObject *parent)
|
|
|
|
: QObject(parent),
|
2016-09-20 14:42:22 +08:00
|
|
|
m_trashWidget(new TrashWidget),
|
|
|
|
m_tipsLabel(new QLabel)
|
2016-08-01 10:58:10 +08:00
|
|
|
{
|
2016-10-29 10:18:30 +08:00
|
|
|
m_tipsLabel->setObjectName("trash");
|
2016-09-20 14:42:22 +08:00
|
|
|
m_tipsLabel->setStyleSheet("color:white;"
|
2017-03-29 10:48:42 +08:00
|
|
|
"padding: 0 3px;");
|
2016-09-20 14:42:22 +08:00
|
|
|
|
2016-09-19 14:11:18 +08:00
|
|
|
connect(m_trashWidget, &TrashWidget::requestContextMenu, this, &TrashPlugin::showContextMenu);
|
2016-08-01 10:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString TrashPlugin::pluginName() const
|
|
|
|
{
|
|
|
|
return "trash";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrashPlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return m_trashWidget;
|
|
|
|
}
|
|
|
|
|
2016-09-20 14:42:22 +08:00
|
|
|
QWidget *TrashPlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return m_tipsLabel;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
// return m_trashWidget->popupApplet();
|
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);
|
|
|
|
|
2016-08-08 19:19:11 +08:00
|
|
|
// return QString();
|
2017-02-13 16:47:44 +08:00
|
|
|
return "gvfs-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();
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:36:18 +08:00
|
|
|
void TrashPlugin::refershIcon(const QString &itemKey)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-08-09 16:01:28 +08:00
|
|
|
int TrashPlugin::itemSortKey(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
// always place at last
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
|
|
|
{
|
|
|
|
if (displayMode == Dock::Fashion)
|
|
|
|
m_proxyInter->itemAdded(this, QString());
|
|
|
|
else
|
|
|
|
m_proxyInter->itemRemoved(this, QString());
|
|
|
|
}
|
2016-09-19 14:11:18 +08:00
|
|
|
|
|
|
|
void TrashPlugin::showContextMenu()
|
|
|
|
{
|
|
|
|
m_proxyInter->requestContextMenu(this, QString());
|
|
|
|
}
|