mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
chore(trash): now trash plugin is a part of dde-dock
Change-Id: I27d74962726a3b4dc5fe85a56e72a36bd5edbcd8
This commit is contained in:
parent
f73428a465
commit
33e0ac383b
Notes:
gerrit
2018-09-19 13:10:48 +08:00
Verified+1: <jenkins@deepin.com> Code-Review+2: Gary Wang <wzc782970009@gmail.com> Submitted-by: Gary Wang <wzc782970009@gmail.com> Submitted-at: Wed, 19 Sep 2018 13:10:47 +0800 Reviewed-on: https://cr.deepin.io/38531 Project: dde/dde-dock Branch: refs/heads/master
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@ build*/
|
|||||||
CMakeLists.txt.user*
|
CMakeLists.txt.user*
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
*.qm
|
*.qm
|
||||||
|
.directory
|
||||||
|
|
||||||
# binary file
|
# binary file
|
||||||
dde-dock
|
dde-dock
|
||||||
|
9
debian/control
vendored
9
debian/control
vendored
@ -21,16 +21,15 @@ Homepage: http://www.deepin.org/
|
|||||||
Package: dde-dock
|
Package: dde-dock
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: ${shlibs:Depends}, ${misc:Depends}, deepin-menu
|
Depends: ${shlibs:Depends}, ${misc:Depends}, deepin-menu
|
||||||
Recommends: dde-disk-mount-plugin,
|
Recommends: dde-disk-mount-plugin
|
||||||
dde-trash-plugin
|
|
||||||
Conflicts: dde-workspace (<< 2.90.5),
|
Conflicts: dde-workspace (<< 2.90.5),
|
||||||
dde-dock-applets
|
dde-dock-applets, dde-trash-plugin
|
||||||
Replaces: dde-dock-applets
|
Replaces: dde-dock-applets
|
||||||
Description: deepin desktop-environment - dock module
|
Description: deepin desktop-environment - dock module
|
||||||
Deepin desktop environment 2015 - dock module.
|
Deepin desktop environment - dock module.
|
||||||
|
|
||||||
Package: dde-dock-dev
|
Package: dde-dock-dev
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||||
Description: deepin desktop-environment - dock module development files
|
Description: deepin desktop-environment - dock module development files
|
||||||
Deepin desktop environment 2015 - dock module development files.
|
Deepin desktop environment - dock module development files.
|
||||||
|
@ -5,5 +5,5 @@ add_subdirectory("network")
|
|||||||
add_subdirectory("shutdown")
|
add_subdirectory("shutdown")
|
||||||
add_subdirectory("sound")
|
add_subdirectory("sound")
|
||||||
add_subdirectory("system-tray")
|
add_subdirectory("system-tray")
|
||||||
#add_subdirectory("trash")
|
add_subdirectory("trash")
|
||||||
add_subdirectory("keyboard-layout")
|
add_subdirectory("keyboard-layout")
|
||||||
|
@ -9,23 +9,16 @@ file(GLOB SRCS "*.h" "*.cpp")
|
|||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
find_package(Qt5Widgets REQUIRED)
|
find_package(Qt5Widgets REQUIRED)
|
||||||
find_package(Qt5Svg REQUIRED)
|
find_package(Qt5Svg REQUIRED)
|
||||||
find_package(Qt5DBus REQUIRED)
|
|
||||||
find_package(DtkWidget REQUIRED)
|
find_package(DtkWidget REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
|
|
||||||
|
|
||||||
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
|
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
|
||||||
add_library(${PLUGIN_NAME} SHARED ${SRCS})
|
add_library(${PLUGIN_NAME} SHARED ${SRCS})
|
||||||
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
|
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
|
||||||
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
|
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
|
||||||
${DFrameworkDBus_INCLUDE_DIRS}
|
|
||||||
${Qt5DBus_INCLUDE_DIRS}
|
|
||||||
../../interfaces)
|
../../interfaces)
|
||||||
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||||||
${DtkWidget_LIBRARIES}
|
${DtkWidget_LIBRARIES}
|
||||||
${DFrameworkDBus_LIBRARIES}
|
|
||||||
${Qt5Widgets_LIBRARIES}
|
${Qt5Widgets_LIBRARIES}
|
||||||
${Qt5DBus_LIBRARIES}
|
|
||||||
${Qt5Svg_LIBRARIES}
|
${Qt5Svg_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,14 +32,16 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include <ddialog.h>
|
#include <ddialog.h>
|
||||||
|
#include <DTrashManager>
|
||||||
|
#include <DDesktopServices>
|
||||||
|
|
||||||
#include <com_deepin_daemon_soundeffect.h>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
|
const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
|
||||||
|
const QDir::Filters ItemsShouldCount = QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot;
|
||||||
|
|
||||||
using SoundEffectInter = com::deepin::daemon::SoundEffect;
|
|
||||||
|
|
||||||
PopupControlWidget::PopupControlWidget(QWidget *parent)
|
PopupControlWidget::PopupControlWidget(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
@ -73,54 +80,56 @@ const QString PopupControlWidget::trashDir()
|
|||||||
|
|
||||||
void PopupControlWidget::openTrashFloder()
|
void PopupControlWidget::openTrashFloder()
|
||||||
{
|
{
|
||||||
QProcess *proc = new QProcess;
|
QProcess::startDetached("gio", QStringList() << "open" << "trash:///");
|
||||||
|
|
||||||
connect(proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished), proc, &QProcess::deleteLater);
|
|
||||||
|
|
||||||
proc->startDetached("gvfs-open trash:///");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupControlWidget::clearTrashFloder()
|
void PopupControlWidget::clearTrashFloder()
|
||||||
{
|
{
|
||||||
|
QString ClearTrashMutliple = qApp->translate("DialogManager", "Are you sure to empty %1 items?");
|
||||||
|
|
||||||
// show confrim dialog
|
// show confrim dialog
|
||||||
bool accept = false;
|
DDialog d;
|
||||||
const int itemCount = trashItemCount();
|
QStringList buttonTexts;
|
||||||
const QStringList btns = {tr("Cancel"), tr("Empty")};
|
buttonTexts << qApp->translate("DialogManager", "Cancel") << qApp->translate("DialogManager", "Delete");
|
||||||
|
|
||||||
DDialog *dialog = new DDialog(nullptr);
|
if (!d.parentWidget()) {
|
||||||
dialog->addButtons(btns);
|
d.setWindowFlags(d.windowFlags() | Qt::WindowStaysOnTopHint);
|
||||||
dialog->setIconPixmap(QIcon::fromTheme("user-trash-full").pixmap(48, 48));
|
}
|
||||||
dialog->setMessage(tr("This action cannot be restored"));
|
|
||||||
if (itemCount == 1)
|
|
||||||
dialog->setTitle(tr("Are you sure to empty 1 item ?"));
|
|
||||||
else
|
|
||||||
dialog->setTitle(tr("Are you sure to empty %1 items ?").arg(itemCount));
|
|
||||||
|
|
||||||
connect(dialog, &DDialog::buttonClicked, [&] (const int index) {
|
QDir dir(TrashDir + "/files");//QDir::homePath() + "/.local/share/Trash/files");
|
||||||
accept = index;
|
uint count = dir.entryList(ItemsShouldCount).count();
|
||||||
});
|
int execCode = -1;
|
||||||
dialog->exec();
|
|
||||||
dialog->deleteLater();
|
|
||||||
|
|
||||||
if (!accept)
|
if (count > 0) {
|
||||||
|
// blumia: Workaround. There is a bug with DDialog which will let DDialog always use the smallest
|
||||||
|
// avaliable size of the given icon. So we create a m_dialogTrashFullIcon and leave a minimum
|
||||||
|
// 64*64 pixmap size icon here.
|
||||||
|
QIcon m_dialogTrashFullIcon;
|
||||||
|
QIcon trash_full_icon = QIcon::fromTheme("user-trash-full-opened");
|
||||||
|
m_dialogTrashFullIcon.addPixmap(trash_full_icon.pixmap(64));
|
||||||
|
m_dialogTrashFullIcon.addPixmap(trash_full_icon.pixmap(128));
|
||||||
|
|
||||||
|
d.setTitle(ClearTrashMutliple.arg(count));
|
||||||
|
d.setMessage(qApp->translate("DialogManager", "This action cannot be restored"));
|
||||||
|
d.setIcon(m_dialogTrashFullIcon);
|
||||||
|
d.addButton(buttonTexts[0], true, DDialog::ButtonNormal);
|
||||||
|
d.addButton(buttonTexts[1], false, DDialog::ButtonWarning);
|
||||||
|
d.setDefaultButton(1);
|
||||||
|
d.getButton(1)->setFocus();
|
||||||
|
d.moveToCenter();
|
||||||
|
execCode = d.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (execCode != QDialog::Accepted) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QProcess::startDetached("gvfs-trash", QStringList() << "-f" << "--empty");
|
if (DTrashManager::instance()->cleanTrash()) {
|
||||||
|
DDesktopServices::playSystemSoundEffect(DDesktopServices::SSE_EmptyTrash);
|
||||||
// play sound effects
|
} else {
|
||||||
SoundEffectInter sei("com.deepin.daemon.SoundEffect", "/com/deepin/daemon/SoundEffect", QDBusConnection::sessionBus());
|
qWarning() << "Clear trash failed";
|
||||||
sei.PlaySystemSound("trash-empty");
|
}
|
||||||
|
// DFMGlobal::instance()->clearTrash();
|
||||||
// for (auto item : QDir(TrashDir).entryInfoList())
|
|
||||||
// {
|
|
||||||
// if (item.fileName() == "." || item.fileName() == "..")
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
// if (item.isFile())
|
|
||||||
// QFile(item.fileName()).remove();
|
|
||||||
// else if (item.isDir())
|
|
||||||
// QDir(item.absoluteFilePath()).removeRecursively();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PopupControlWidget::trashItemCount() const
|
int PopupControlWidget::trashItemCount() const
|
||||||
@ -135,20 +144,23 @@ void PopupControlWidget::trashStatusChanged()
|
|||||||
|
|
||||||
// add monitor paths
|
// add monitor paths
|
||||||
m_fsWatcher->addPath(TrashDir);
|
m_fsWatcher->addPath(TrashDir);
|
||||||
if (files)
|
if (files) {
|
||||||
m_fsWatcher->addPath(TrashDir + "/files");
|
m_fsWatcher->addPath(TrashDir + "/files");
|
||||||
|
}
|
||||||
// if (info)
|
// if (info)
|
||||||
// m_fsWatcher->addPath(TrashDir + "/info");
|
// m_fsWatcher->addPath(TrashDir + "/info");
|
||||||
|
|
||||||
// check empty
|
// check empty
|
||||||
if (!files)
|
if (!files) {
|
||||||
m_trashItemsCount = 0;
|
m_trashItemsCount = 0;
|
||||||
else
|
} else {
|
||||||
m_trashItemsCount = QDir(TrashDir + "/files").entryList().count() - 2;
|
m_trashItemsCount = QDir(TrashDir + "/files").entryList(ItemsShouldCount).count();
|
||||||
|
}
|
||||||
|
|
||||||
const bool empty = m_trashItemsCount == 0;
|
const bool empty = m_trashItemsCount == 0;
|
||||||
if (m_empty == empty)
|
if (m_empty == empty) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// m_clearBtn->setVisible(!empty);
|
// m_clearBtn->setVisible(!empty);
|
||||||
m_empty = empty;
|
m_empty = empty;
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -21,10 +26,15 @@
|
|||||||
|
|
||||||
#include "trashplugin.h"
|
#include "trashplugin.h"
|
||||||
|
|
||||||
|
#include <DApplication>
|
||||||
|
|
||||||
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
TrashPlugin::TrashPlugin(QObject *parent)
|
TrashPlugin::TrashPlugin(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_trashWidget(new TrashWidget),
|
m_trashWidget(new TrashWidget),
|
||||||
m_tipsLabel(new QLabel)
|
m_tipsLabel(new QLabel),
|
||||||
|
m_settings("deepin", "dde-dock-trash")
|
||||||
{
|
{
|
||||||
m_tipsLabel->setObjectName("trash");
|
m_tipsLabel->setObjectName("trash");
|
||||||
m_tipsLabel->setStyleSheet("color:white;"
|
m_tipsLabel->setStyleSheet("color:white;"
|
||||||
@ -40,8 +50,14 @@ const QString TrashPlugin::pluginName() const
|
|||||||
|
|
||||||
void TrashPlugin::init(PluginProxyInterface *proxyInter)
|
void TrashPlugin::init(PluginProxyInterface *proxyInter)
|
||||||
{
|
{
|
||||||
m_proxyInter = proxyInter;
|
// blumia: we are using i10n translation from DFM so...
|
||||||
|
QString applicationName = qApp->applicationName();
|
||||||
|
qApp->setApplicationName("dde-file-manager");
|
||||||
|
qDebug() << qApp->loadTranslator();
|
||||||
|
qApp->setApplicationName(applicationName);
|
||||||
|
|
||||||
|
m_proxyInter = proxyInter;
|
||||||
|
// DFMGlobal::instance()->installTranslator();
|
||||||
displayModeChanged(displayMode());
|
displayModeChanged(displayMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +94,7 @@ const QString TrashPlugin::itemCommand(const QString &itemKey)
|
|||||||
Q_UNUSED(itemKey);
|
Q_UNUSED(itemKey);
|
||||||
|
|
||||||
// return QString();
|
// return QString();
|
||||||
return "gvfs-open trash:///";
|
return "gio open trash:///";
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString TrashPlugin::itemContextMenu(const QString &itemKey)
|
const QString TrashPlugin::itemContextMenu(const QString &itemKey)
|
||||||
@ -104,10 +120,14 @@ void TrashPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
|
|||||||
|
|
||||||
int TrashPlugin::itemSortKey(const QString &itemKey)
|
int TrashPlugin::itemSortKey(const QString &itemKey)
|
||||||
{
|
{
|
||||||
Q_UNUSED(itemKey);
|
const QString &key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||||
|
return m_settings.value(key, -1).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
// always place at last
|
void TrashPlugin::setSortKey(const QString &itemKey, const int order)
|
||||||
return -1;
|
{
|
||||||
|
const QString &key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||||
|
m_settings.setValue(key, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
void TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,6 +31,7 @@
|
|||||||
#include "trashwidget.h"
|
#include "trashwidget.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
class TrashPlugin : public QObject, PluginsItemInterface
|
class TrashPlugin : public QObject, PluginsItemInterface
|
||||||
{
|
{
|
||||||
@ -47,7 +53,8 @@ public:
|
|||||||
void refershIcon(const QString &itemKey);
|
void refershIcon(const QString &itemKey);
|
||||||
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked);
|
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked);
|
||||||
|
|
||||||
int itemSortKey(const QString &itemKey);
|
int itemSortKey(const QString &itemKey) override;
|
||||||
|
void setSortKey(const QString &itemKey, const int order) override;
|
||||||
void displayModeChanged(const Dock::DisplayMode displayMode);
|
void displayModeChanged(const Dock::DisplayMode displayMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -56,6 +63,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
TrashWidget *m_trashWidget;
|
TrashWidget *m_trashWidget;
|
||||||
QLabel *m_tipsLabel;
|
QLabel *m_tipsLabel;
|
||||||
|
QSettings m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRASHPLUGIN_H
|
#endif // TRASHPLUGIN_H
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,6 +32,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
@ -100,11 +106,43 @@ void TrashWidget::invokeMenuItem(const QString &menuId, const bool checked)
|
|||||||
|
|
||||||
void TrashWidget::dragEnterEvent(QDragEnterEvent *e)
|
void TrashWidget::dragEnterEvent(QDragEnterEvent *e)
|
||||||
{
|
{
|
||||||
if (e->mimeData()->hasFormat("RequestDock"))
|
if (e->mimeData()->hasFormat("RequestDock")) {
|
||||||
return e->accept();
|
// accept prevent the event from being propgated to the dock main panel
|
||||||
|
// which also takes drag event;
|
||||||
|
e->accept();
|
||||||
|
|
||||||
if (e->mimeData()->hasFormat("text/uri-list"))
|
if (!e->mimeData()->hasFormat("Removable")) {
|
||||||
return e->accept();
|
// show the forbit dropping cursor.
|
||||||
|
e->setDropAction(Qt::IgnoreAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!e->mimeData()->hasUrls())
|
||||||
|
e->ignore();
|
||||||
|
|
||||||
|
e->setDropAction(Qt::MoveAction);
|
||||||
|
|
||||||
|
if (e->dropAction() != Qt::MoveAction) {
|
||||||
|
e->ignore();
|
||||||
|
} else {
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrashWidget::dragMoveEvent(QDragMoveEvent *e)
|
||||||
|
{
|
||||||
|
if (!e->mimeData()->hasUrls())
|
||||||
|
return;
|
||||||
|
|
||||||
|
e->setDropAction(Qt::MoveAction);
|
||||||
|
|
||||||
|
if (e->dropAction() != Qt::MoveAction) {
|
||||||
|
e->ignore();
|
||||||
|
} else {
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrashWidget::dropEvent(QDropEvent *e)
|
void TrashWidget::dropEvent(QDropEvent *e)
|
||||||
@ -112,12 +150,19 @@ void TrashWidget::dropEvent(QDropEvent *e)
|
|||||||
if (e->mimeData()->hasFormat("RequestDock"))
|
if (e->mimeData()->hasFormat("RequestDock"))
|
||||||
return removeApp(e->mimeData()->data("AppKey"));
|
return removeApp(e->mimeData()->data("AppKey"));
|
||||||
|
|
||||||
if (e->mimeData()->hasFormat("text/uri-list"))
|
if (!e->mimeData()->hasUrls()) {
|
||||||
{
|
return e->ignore();
|
||||||
const QMimeData *mime = e->mimeData();
|
|
||||||
for (auto url : mime->urls())
|
|
||||||
moveToTrash(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e->setDropAction(Qt::MoveAction);
|
||||||
|
|
||||||
|
if (e->dropAction() != Qt::MoveAction) {
|
||||||
|
return e->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QMimeData *mime = e->mimeData();
|
||||||
|
for (auto url : mime->urls())
|
||||||
|
moveToTrash(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrashWidget::paintEvent(QPaintEvent *e)
|
void TrashWidget::paintEvent(QPaintEvent *e)
|
||||||
@ -125,7 +170,7 @@ void TrashWidget::paintEvent(QPaintEvent *e)
|
|||||||
QWidget::paintEvent(e);
|
QWidget::paintEvent(e);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon);
|
painter.drawPixmap(rect().center() - m_icon.rect().center() / qApp->devicePixelRatio(), m_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrashWidget::resizeEvent(QResizeEvent *e)
|
void TrashWidget::resizeEvent(QResizeEvent *e)
|
||||||
@ -156,8 +201,8 @@ void TrashWidget::updateIcon()
|
|||||||
|
|
||||||
const int size = displayMode == Dock::Fashion ? std::min(width(), height()) * 0.8 : 16;
|
const int size = displayMode == Dock::Fashion ? std::min(width(), height()) * 0.8 : 16;
|
||||||
QIcon icon = QIcon::fromTheme(iconString);
|
QIcon icon = QIcon::fromTheme(iconString);
|
||||||
m_icon = icon.pixmap(size, size);
|
m_icon = icon.pixmap(size * qApp->devicePixelRatio(), size * qApp->devicePixelRatio());
|
||||||
|
m_icon.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,11 +221,5 @@ void TrashWidget::moveToTrash(const QUrl &url)
|
|||||||
{
|
{
|
||||||
const QFileInfo info = url.toLocalFile();
|
const QFileInfo info = url.toLocalFile();
|
||||||
|
|
||||||
QProcess::startDetached("gvfs-trash", QStringList() << "-f" << info.absoluteFilePath());
|
QProcess::startDetached("gio", QStringList() << "trash" << "-f" << info.absoluteFilePath());
|
||||||
|
|
||||||
// QDir trashDir(m_popupApplet->trashDir() + "/files");
|
|
||||||
// if (!trashDir.exists())
|
|
||||||
// trashDir.mkpath(".");
|
|
||||||
|
|
||||||
// QDir().rename(info.absoluteFilePath(), trashDir.absoluteFilePath(info.fileName()));
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||||
|
* 2016 ~ 2018 dragondjf
|
||||||
*
|
*
|
||||||
* Author: sbw <sbw@sbw.so>
|
* Author: sbw <sbw@sbw.so>
|
||||||
|
* dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
|
* Tangtong<tangtong@deepin.com>
|
||||||
*
|
*
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
* Maintainer: dragondjf<dingjiangfeng@deepin.com>
|
||||||
|
* zccrs<zhangjide@deepin.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -48,8 +53,9 @@ signals:
|
|||||||
void requestContextMenu() const;
|
void requestContextMenu() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QDragEnterEvent *e);
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||||
void dropEvent(QDropEvent *e);
|
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||||
|
void dropEvent(QDropEvent *e) override;
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user