mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add trash-files and uninstall-app ConfirmDialog
Change-Id: I9f328a9a2ac7bed98795bfeb274d7274d19385f9
This commit is contained in:
parent
0c9e70f95e
commit
930ed1fadc
Notes:
Deepin Code Review
2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: <mr.asianwang@gmail.com> Submitted-by: <mr.asianwang@gmail.com> Submitted-at: Tue, 01 Sep 2015 10:47:05 +0800 Reviewed-on: https://cr.deepin.io/6659 Project: dde/dde-dock Branch: refs/heads/master
Binary file not shown.
After Width: | Height: | Size: 214 B |
Binary file not shown.
After Width: | Height: | Size: 178 B |
Binary file not shown.
After Width: | Height: | Size: 214 B |
54
dde-dock-trash-plugin/Resource/dark/qss/trash.qss
Normal file
54
dde-dock-trash-plugin/Resource/dark/qss/trash.qss
Normal file
@ -0,0 +1,54 @@
|
||||
QFrame#ContentFrame{
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
QPushButton#CloseButton{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_normal.png")
|
||||
}
|
||||
|
||||
QPushButton#CloseButton:hover{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_hover.png")
|
||||
}
|
||||
|
||||
|
||||
QPushButton#CloseButton:pressed{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_press.png")
|
||||
}
|
||||
|
||||
QPushButton#ActionButton{
|
||||
background-color: transparent;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-right: none;
|
||||
border-left: none;
|
||||
border-bottom: none;
|
||||
color: white;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
QPushButton#ActionButton:hover{
|
||||
background-color: transparent;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
QPushButton#ActionButton:pressed{
|
||||
background-color: transparent;
|
||||
color: #01bdff;
|
||||
}
|
||||
|
||||
QLabel#VLine{
|
||||
background-color:rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
QLabel#MessageLabel{
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
QLabel#TipMessageLabel{
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
color: #ffa530;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 214 B |
Binary file not shown.
After Width: | Height: | Size: 178 B |
Binary file not shown.
After Width: | Height: | Size: 214 B |
54
dde-dock-trash-plugin/Resource/light/qss/trash.qss
Normal file
54
dde-dock-trash-plugin/Resource/light/qss/trash.qss
Normal file
@ -0,0 +1,54 @@
|
||||
QFrame#ContentFrame{
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
QPushButton#CloseButton{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_normal.png")
|
||||
}
|
||||
|
||||
QPushButton#CloseButton:hover{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_hover.png")
|
||||
}
|
||||
|
||||
|
||||
QPushButton#CloseButton:pressed{
|
||||
border-image: url(":/images/Resource/dark/images/dark_close_small_press.png")
|
||||
}
|
||||
|
||||
QPushButton#ActionButton{
|
||||
background-color: transparent;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
border-right: none;
|
||||
border-left: none;
|
||||
border-bottom: none;
|
||||
color: white;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
QPushButton#ActionButton:hover{
|
||||
background-color: transparent;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
QPushButton#ActionButton:pressed{
|
||||
background-color: transparent;
|
||||
color: #01bdff;
|
||||
}
|
||||
|
||||
QLabel#VLine{
|
||||
background-color:rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
QLabel#MessageLabel{
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
QLabel#TipMessageLabel{
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
color: #ffa530;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
QLabel {
|
||||
color:white;
|
||||
font-size:10px;
|
||||
}
|
||||
|
||||
QLabel#DiskTitle {
|
||||
font-size:12px;
|
||||
}
|
||||
|
||||
QLabel#SplitLine {
|
||||
background: rgba(255,255,255,0.3);
|
||||
}
|
||||
|
||||
QProgressBar {
|
||||
background: rgba(255,255,255,0.1);
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
QProgressBar::chunk {
|
||||
background-color: rgba(255,255,255,0.8);
|
||||
}
|
10
dde-dock-trash-plugin/dark.qrc
Normal file
10
dde-dock-trash-plugin/dark.qrc
Normal file
@ -0,0 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="/images">
|
||||
<file>Resource/dark/images/dark_close_small_hover.png</file>
|
||||
<file>Resource/dark/images/dark_close_small_normal.png</file>
|
||||
<file>Resource/dark/images/dark_close_small_press.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qss">
|
||||
<file>Resource/dark/qss/trash.qss</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -4,13 +4,15 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui widgets dbus
|
||||
QT += core gui widgets dbus svg
|
||||
|
||||
TARGET = dde-dock-trash-plugin
|
||||
TEMPLATE = lib
|
||||
CONFIG += plugin c++11
|
||||
CONFIG += plugin c++11 link_pkgconfig
|
||||
PKGCONFIG += gtk+-2.0
|
||||
|
||||
INCLUDEPATH += ../dde-dock/src
|
||||
include(./dialogs/dialogs.pri)
|
||||
|
||||
SOURCES += \
|
||||
mainitem.cpp \
|
||||
@ -37,4 +39,6 @@ unix {
|
||||
INSTALLS += target
|
||||
}
|
||||
|
||||
RESOURCES +=
|
||||
RESOURCES += \
|
||||
light.qrc \
|
||||
dark.qrc
|
||||
|
29
dde-dock-trash-plugin/dialogs/cleartrashdialog.cpp
Normal file
29
dde-dock-trash-plugin/dialogs/cleartrashdialog.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "cleartrashdialog.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QButtonGroup>
|
||||
#include <QPushButton>
|
||||
|
||||
ClearTrashDialog::ClearTrashDialog(QWidget *parent):
|
||||
DBaseDialog(parent)
|
||||
{
|
||||
|
||||
QString icon = ":/images/skin/dialogs/images/user-trash-full.png";
|
||||
QString message = tr("Are you sure to clear items in trash?");
|
||||
QString tipMessage = tr("This action cannot be restored");
|
||||
QStringList buttons;
|
||||
buttons << "Cancel" << "Clear";
|
||||
initUI(icon, message, tipMessage, buttons, buttons);
|
||||
moveCenter();
|
||||
getButtonsGroup()->button(1)->setFocus();
|
||||
}
|
||||
|
||||
void ClearTrashDialog::handleKeyEnter(){
|
||||
handleButtonsClicked(1);
|
||||
}
|
||||
|
||||
ClearTrashDialog::~ClearTrashDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
19
dde-dock-trash-plugin/dialogs/cleartrashdialog.h
Normal file
19
dde-dock-trash-plugin/dialogs/cleartrashdialog.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef CLEARTRASHDIALOG_H
|
||||
#define CLEARTRASHDIALOG_H
|
||||
|
||||
#include "dbasedialog.h"
|
||||
|
||||
class ClearTrashDialog : public DBaseDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClearTrashDialog(QWidget *parent = 0);
|
||||
~ClearTrashDialog();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void handleKeyEnter();
|
||||
};
|
||||
|
||||
#endif // CLEARTRASHDIALOG_H
|
26
dde-dock-trash-plugin/dialogs/confirmuninstalldialog.cpp
Normal file
26
dde-dock-trash-plugin/dialogs/confirmuninstalldialog.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "confirmuninstalldialog.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QButtonGroup>
|
||||
#include <QPushButton>
|
||||
|
||||
ConfirmUninstallDialog::ConfirmUninstallDialog(QWidget *parent) : DBaseDialog(parent)
|
||||
{
|
||||
QString icon = ":/images/skin/dialogs/images/user-trash-full.png";
|
||||
QString message = tr("Are you sure to uninstall this application?");
|
||||
QString tipMessage = tr("This action cannot be restored");
|
||||
QStringList buttons;
|
||||
buttons << "Cancel" << "Ok";
|
||||
initUI(icon, message, tipMessage, buttons, buttons);
|
||||
moveCenter();
|
||||
getButtonsGroup()->button(1)->setFocus();
|
||||
}
|
||||
|
||||
void ConfirmUninstallDialog::handleKeyEnter(){
|
||||
handleButtonsClicked(1);
|
||||
}
|
||||
|
||||
ConfirmUninstallDialog::~ConfirmUninstallDialog()
|
||||
{
|
||||
|
||||
}
|
19
dde-dock-trash-plugin/dialogs/confirmuninstalldialog.h
Normal file
19
dde-dock-trash-plugin/dialogs/confirmuninstalldialog.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef CONFIRMUNINSTALLDIALOG_H
|
||||
#define CONFIRMUNINSTALLDIALOG_H
|
||||
|
||||
#include "dbasedialog.h"
|
||||
|
||||
class ConfirmUninstallDialog : public DBaseDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConfirmUninstallDialog(QWidget *parent = 0);
|
||||
~ConfirmUninstallDialog();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void handleKeyEnter();
|
||||
};
|
||||
|
||||
#endif // CONFIRMUNINSTALLDIALOG_H
|
221
dde-dock-trash-plugin/dialogs/dbasedialog.cpp
Normal file
221
dde-dock-trash-plugin/dialogs/dbasedialog.cpp
Normal file
@ -0,0 +1,221 @@
|
||||
#include "dbasedialog.h"
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QButtonGroup>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QCloseEvent>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
|
||||
DBaseDialog::DBaseDialog(QWidget *parent):DMovabelDialog(parent)
|
||||
{
|
||||
m_messageLabelMaxWidth = qApp->desktop()->availableGeometry().width() / 2 -
|
||||
100 - 2 * getCloseButton()->width();
|
||||
}
|
||||
|
||||
void DBaseDialog::initUI(const QString &icon,
|
||||
const QString &message,
|
||||
const QString &tipMessage,
|
||||
const QStringList &buttonKeys,
|
||||
const QStringList &buttonTexts){
|
||||
m_icon = icon;
|
||||
m_message = message;
|
||||
m_tipMessage = tipMessage;
|
||||
m_buttonKeys = buttonKeys;
|
||||
m_buttonTexts = buttonTexts;
|
||||
|
||||
QFrame* contentFrame = new QFrame;
|
||||
contentFrame->setObjectName("ContentFrame");
|
||||
|
||||
m_iconLabel = new QLabel;
|
||||
m_iconLabel->setFixedSize(48, 48);
|
||||
setIcon(m_icon);
|
||||
|
||||
m_messageLabel = new QLabel;
|
||||
m_messageLabel->setObjectName("MessageLabel");
|
||||
setMessage(m_message);
|
||||
|
||||
m_tipMessageLabel = new QLabel;
|
||||
m_tipMessageLabel->setObjectName("TipMessageLabel");
|
||||
setTipMessage(m_tipMessage);
|
||||
|
||||
m_buttonGroup = new QButtonGroup;
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout;
|
||||
foreach (QString label, m_buttonKeys) {
|
||||
int index = m_buttonKeys.indexOf(label);
|
||||
QPushButton* button = new QPushButton(label);
|
||||
button->setObjectName("ActionButton");
|
||||
button->setAttribute(Qt::WA_NoMousePropagation);
|
||||
button->setFixedHeight(28);
|
||||
m_buttonGroup->addButton(button, index);
|
||||
buttonLayout->addWidget(button);
|
||||
if (index < m_buttonKeys.length() - 1){
|
||||
QLabel* label = new QLabel;
|
||||
label->setObjectName("VLine");
|
||||
label->setFixedWidth(1);
|
||||
buttonLayout->addWidget(label);
|
||||
}
|
||||
}
|
||||
|
||||
setButtonTexts(m_buttonTexts);
|
||||
buttonLayout->setSpacing(0);
|
||||
buttonLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QVBoxLayout* iconLayout = new QVBoxLayout;
|
||||
iconLayout->addWidget(m_iconLabel, Qt::AlignCenter);
|
||||
iconLayout->setContentsMargins(26, 22, 26, 22);
|
||||
|
||||
m_messageLayout = new QVBoxLayout;
|
||||
m_messageLayout->addWidget(m_messageLabel);
|
||||
m_messageLayout->addWidget(m_tipMessageLabel);
|
||||
m_messageLayout->addStretch();
|
||||
m_messageLayout->setContentsMargins(5, getCloseButton()->height(), getCloseButton()->width(), 0);
|
||||
|
||||
QHBoxLayout* topLayout = new QHBoxLayout;
|
||||
topLayout->addLayout(iconLayout);
|
||||
topLayout->addLayout(m_messageLayout);
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(topLayout);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
contentFrame->setLayout(mainLayout);
|
||||
|
||||
QHBoxLayout* contentlayout = new QHBoxLayout;
|
||||
contentlayout->addWidget(contentFrame);
|
||||
contentlayout->setContentsMargins(5, 5, 5, 5);
|
||||
setLayout(contentlayout);
|
||||
|
||||
resize(m_defaultWidth, m_defaultHeight);
|
||||
setStyleSheet(getQssFromFile(":/qss/Resource/dark/qss/trash.qss"));
|
||||
initConnect();
|
||||
}
|
||||
|
||||
|
||||
void DBaseDialog::initConnect(){
|
||||
connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(handleButtonsClicked(int)));
|
||||
}
|
||||
|
||||
QButtonGroup* DBaseDialog::getButtonsGroup(){
|
||||
return m_buttonGroup;
|
||||
}
|
||||
|
||||
QVBoxLayout* DBaseDialog::getMessageLayout(){
|
||||
return m_messageLayout;
|
||||
}
|
||||
|
||||
QString DBaseDialog::getIcon(){
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void DBaseDialog::setIcon(const QString &icon){
|
||||
m_icon = icon;
|
||||
m_iconLabel->setPixmap(QPixmap(m_icon).scaled(m_iconLabel->size()));
|
||||
}
|
||||
|
||||
QString DBaseDialog::getMessage(){
|
||||
return m_message;
|
||||
}
|
||||
|
||||
void DBaseDialog::setMessage(const QString &message){
|
||||
m_message = message;
|
||||
|
||||
QFontMetrics fm = fontMetrics();
|
||||
if (fm.width(m_message) > m_messageLabelMaxWidth){
|
||||
QString text = fm.elidedText(m_message, Qt::ElideRight, m_messageLabelMaxWidth);
|
||||
m_messageLabel->setText(text);
|
||||
}else{
|
||||
m_messageLabel->setText(m_message);
|
||||
}
|
||||
m_messageLabel->resize(fm.width(m_messageLabel->text()), height());
|
||||
}
|
||||
|
||||
QString DBaseDialog::getTipMessage(){
|
||||
return m_tipMessage;
|
||||
}
|
||||
|
||||
void DBaseDialog::setTipMessage(const QString &tipMessage){
|
||||
m_tipMessage = tipMessage;
|
||||
|
||||
QFontMetrics fm = fontMetrics();
|
||||
if (fm.width(m_tipMessage) > m_messageLabelMaxWidth){
|
||||
QString text = fm.elidedText(m_tipMessage, Qt::ElideRight, m_messageLabelMaxWidth);
|
||||
m_tipMessageLabel->setText(text);
|
||||
}else{
|
||||
m_tipMessageLabel->setText(m_tipMessage);
|
||||
}
|
||||
m_tipMessageLabel->resize(fm.width(m_messageLabel->text()), height());
|
||||
}
|
||||
|
||||
QStringList DBaseDialog::getButtons(){
|
||||
return m_buttonKeys;
|
||||
}
|
||||
|
||||
void DBaseDialog::setButtons(const QStringList &buttons){
|
||||
m_buttonKeys = buttons;
|
||||
}
|
||||
|
||||
QStringList DBaseDialog::getButtonTexts(){
|
||||
return m_buttonTexts;
|
||||
}
|
||||
|
||||
void DBaseDialog::setButtonTexts(const QStringList& buttonTexts){
|
||||
if (buttonTexts.length() != m_buttonKeys.length()){
|
||||
return;
|
||||
}
|
||||
m_buttonTexts = buttonTexts;
|
||||
for (int i = 0; i < m_buttonGroup->buttons().length(); i++) {
|
||||
QPushButton* button = reinterpret_cast<QPushButton*>(m_buttonGroup->buttons().at(i));
|
||||
button->setText(m_buttonTexts.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void DBaseDialog::handleButtonsClicked(int id){
|
||||
close();
|
||||
int index = m_buttonGroup->buttons().indexOf(m_buttonGroup->button(id));
|
||||
if (m_buttonKeys.length() > index){
|
||||
emit buttonClicked(index);
|
||||
}
|
||||
}
|
||||
|
||||
void DBaseDialog::handleKeyEnter(){
|
||||
|
||||
}
|
||||
|
||||
void DBaseDialog::closeEvent(QCloseEvent *event){
|
||||
emit aboutToClose();
|
||||
DMovabelDialog::closeEvent(event);
|
||||
emit closed();
|
||||
}
|
||||
|
||||
|
||||
void DBaseDialog::resizeEvent(QResizeEvent *event){
|
||||
DMovabelDialog::resizeEvent(event);
|
||||
}
|
||||
|
||||
QString DBaseDialog::getQssFromFile(const QString &name)
|
||||
{
|
||||
QFile file(name);
|
||||
QString styleSheet = "";
|
||||
if (file.open(QFile::ReadOnly))
|
||||
{
|
||||
styleSheet = QString(file.readAll());
|
||||
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
qWarning() << "[Error:] Open style file errr!";
|
||||
|
||||
return styleSheet;
|
||||
}
|
||||
|
||||
DBaseDialog::~DBaseDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
71
dde-dock-trash-plugin/dialogs/dbasedialog.h
Normal file
71
dde-dock-trash-plugin/dialogs/dbasedialog.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef DBASEDIALOG_H
|
||||
#define DBASEDIALOG_H
|
||||
|
||||
#include "dmovabledialog.h"
|
||||
|
||||
class QPushButton;
|
||||
class QButtonGroup;
|
||||
class QLabel;
|
||||
class QCloseEvent;
|
||||
class QVBoxLayout;
|
||||
|
||||
class DBaseDialog : public DMovabelDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBaseDialog(QWidget *parent = 0);
|
||||
~DBaseDialog();
|
||||
void initUI(const QString& icon,
|
||||
const QString& message,
|
||||
const QString& tipMessage,
|
||||
const QStringList& buttonKeys,
|
||||
const QStringList& buttonTexts);
|
||||
void initConnect();
|
||||
|
||||
QString getIcon();
|
||||
QString getMessage();
|
||||
QString getTipMessage();
|
||||
QStringList getButtons();
|
||||
QStringList getButtonTexts();
|
||||
QButtonGroup* getButtonsGroup();
|
||||
|
||||
signals:
|
||||
void aboutToClose();
|
||||
void closed();
|
||||
void buttonClicked(int index);
|
||||
|
||||
public slots:
|
||||
void setIcon(const QString& icon);
|
||||
void setMessage(const QString& message);
|
||||
void setTipMessage(const QString& tipMessage);
|
||||
void setButtons(const QStringList& buttons);
|
||||
void setButtonTexts(const QStringList& buttonTexts);
|
||||
void handleButtonsClicked(int id);
|
||||
void handleKeyEnter();
|
||||
QVBoxLayout* getMessageLayout();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
private:
|
||||
QString getQssFromFile(const QString &name);
|
||||
|
||||
QString m_icon;
|
||||
QString m_message;
|
||||
QString m_tipMessage;
|
||||
QStringList m_buttonKeys;
|
||||
QStringList m_buttonTexts;
|
||||
int m_defaultWidth = 380;
|
||||
int m_defaultHeight = 120;
|
||||
|
||||
QLabel* m_iconLabel;
|
||||
QLabel* m_messageLabel;
|
||||
QLabel* m_tipMessageLabel;
|
||||
QButtonGroup* m_buttonGroup;
|
||||
|
||||
QVBoxLayout* m_messageLayout;
|
||||
int m_messageLabelMaxWidth;
|
||||
};
|
||||
|
||||
#endif // DBASEDIALOG_H
|
11
dde-dock-trash-plugin/dialogs/dialogs.pri
Normal file
11
dde-dock-trash-plugin/dialogs/dialogs.pri
Normal file
@ -0,0 +1,11 @@
|
||||
HEADERS += \
|
||||
$$PWD/dbasedialog.h \
|
||||
$$PWD/cleartrashdialog.h \
|
||||
$$PWD/confirmuninstalldialog.h \
|
||||
$$PWD/dmovabledialog.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/dbasedialog.cpp \
|
||||
$$PWD/cleartrashdialog.cpp \
|
||||
$$PWD/confirmuninstalldialog.cpp \
|
||||
$$PWD/dmovabledialog.cpp
|
67
dde-dock-trash-plugin/dialogs/dmovabledialog.cpp
Normal file
67
dde-dock-trash-plugin/dialogs/dmovabledialog.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "dmovabledialog.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
|
||||
|
||||
DMovabelDialog::DMovabelDialog(QWidget *parent):QDialog(parent)
|
||||
{
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
m_closeButton = new QPushButton(this);
|
||||
m_closeButton->setObjectName("CloseButton");
|
||||
m_closeButton->setFixedSize(25, 25);
|
||||
m_closeButton->setAttribute(Qt::WA_NoMousePropagation);
|
||||
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
}
|
||||
|
||||
void DMovabelDialog::setMovableHeight(int height){
|
||||
m_movableHeight = height;
|
||||
}
|
||||
|
||||
|
||||
QPushButton* DMovabelDialog::getCloseButton(){
|
||||
return m_closeButton;
|
||||
}
|
||||
|
||||
void DMovabelDialog::moveCenter(){
|
||||
QRect qr = frameGeometry();
|
||||
QPoint cp = qApp->desktop()->availableGeometry().center();
|
||||
qr.moveCenter(cp);
|
||||
move(qr.topLeft());
|
||||
}
|
||||
|
||||
void DMovabelDialog::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() & Qt::LeftButton)
|
||||
{
|
||||
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
|
||||
}
|
||||
QDialog::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void DMovabelDialog::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
QDialog::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void DMovabelDialog::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
move(event->globalPos() - m_dragPosition);
|
||||
QDialog::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void DMovabelDialog::resizeEvent(QResizeEvent *event){
|
||||
m_closeButton->move(width() - m_closeButton->width() - 4, 4);
|
||||
m_closeButton->raise();
|
||||
moveCenter();
|
||||
QDialog::resizeEvent(event);
|
||||
}
|
||||
|
||||
DMovabelDialog::~DMovabelDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
35
dde-dock-trash-plugin/dialogs/dmovabledialog.h
Normal file
35
dde-dock-trash-plugin/dialogs/dmovabledialog.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef DMOVABLEDIALOG_H
|
||||
#define DMOVABLEDIALOG_H
|
||||
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPoint>
|
||||
class QMouseEvent;
|
||||
class QPushButton;
|
||||
class QResizeEvent;
|
||||
|
||||
class DMovabelDialog:public QDialog
|
||||
{
|
||||
public:
|
||||
DMovabelDialog(QWidget *parent = 0);
|
||||
~DMovabelDialog();
|
||||
|
||||
QPushButton* getCloseButton();
|
||||
|
||||
public slots:
|
||||
void setMovableHeight(int height);
|
||||
void moveCenter();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
private:
|
||||
QPoint m_dragPosition;
|
||||
int m_movableHeight = 30;
|
||||
QPushButton* m_closeButton;
|
||||
};
|
||||
|
||||
#endif // DMOVABLEDIALOG_H
|
7
dde-dock-trash-plugin/images.qrc
Normal file
7
dde-dock-trash-plugin/images.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>Resource/images/dark_close_small_hover.png</file>
|
||||
<file>Resource/images/dark_close_small_normal.png</file>
|
||||
<file>Resource/images/dark_close_small_press.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
10
dde-dock-trash-plugin/light.qrc
Normal file
10
dde-dock-trash-plugin/light.qrc
Normal file
@ -0,0 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="/images">
|
||||
<file>Resource/light/images/dark_close_small_hover.png</file>
|
||||
<file>Resource/light/images/dark_close_small_normal.png</file>
|
||||
<file>Resource/light/images/dark_close_small_press.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qss">
|
||||
<file>Resource/light/qss/trash.qss</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -1,5 +1,11 @@
|
||||
#include <QSvgRenderer>
|
||||
#include "mainitem.h"
|
||||
|
||||
#undef signals
|
||||
extern "C" {
|
||||
#include <gtk/gtk.h>
|
||||
}
|
||||
#define signals public
|
||||
MainItem::MainItem(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
@ -15,17 +21,25 @@ MainItem::~MainItem()
|
||||
|
||||
void MainItem::emptyTrash()
|
||||
{
|
||||
QDBusPendingReply<QString, QDBusObjectPath, QString> tmpReply = m_dfo->NewEmptyTrashJob(false, "", "", "");
|
||||
QDBusObjectPath op = tmpReply.argumentAt(1).value<QDBusObjectPath>();
|
||||
DBusEmptyTrashJob * detj = new DBusEmptyTrashJob(op.path(), this);
|
||||
connect(detj, &DBusEmptyTrashJob::Done, detj, &DBusEmptyTrashJob::deleteLater);
|
||||
connect(detj, &DBusEmptyTrashJob::Done, [=](){
|
||||
updateIcon(false);
|
||||
ClearTrashDialog *dialog = new ClearTrashDialog;
|
||||
dialog->setIcon(getThemeIconPath("user-trash-full"));
|
||||
connect(dialog, &ClearTrashDialog::buttonClicked, [=](int key){
|
||||
dialog->deleteLater();
|
||||
if (key == 1){
|
||||
qWarning() << "Clear trash...";
|
||||
QDBusPendingReply<QString, QDBusObjectPath, QString> tmpReply = m_dfo->NewEmptyTrashJob(false, "", "", "");
|
||||
QDBusObjectPath op = tmpReply.argumentAt(1).value<QDBusObjectPath>();
|
||||
DBusEmptyTrashJob * detj = new DBusEmptyTrashJob(op.path(), this);
|
||||
connect(detj, &DBusEmptyTrashJob::Done, detj, &DBusEmptyTrashJob::deleteLater);
|
||||
connect(detj, &DBusEmptyTrashJob::Done, [=](){
|
||||
updateIcon(false);
|
||||
});
|
||||
|
||||
if (detj->isValid())
|
||||
detj->Execute();
|
||||
}
|
||||
});
|
||||
|
||||
if (detj->isValid())
|
||||
detj->Execute();
|
||||
|
||||
dialog->exec();
|
||||
}
|
||||
|
||||
void MainItem::mousePressEvent(QMouseEvent *event)
|
||||
@ -74,8 +88,18 @@ void MainItem::dropEvent(QDropEvent *event)
|
||||
if (dataObj.isEmpty())
|
||||
return;
|
||||
|
||||
qWarning() << "Uninstall application:" << dataObj.value("id").toString();
|
||||
m_launcher->RequestUninstall(dataObj.value("id").toString(), true);
|
||||
ConfirmUninstallDialog *dialog = new ConfirmUninstallDialog;
|
||||
QString message = tr("Are you sure to uninstall \"%1\"").arg(dataObj.value("name").toString());
|
||||
dialog->setMessage(message);
|
||||
dialog->setIcon(getThemeIconPath(dataObj.value("icon").toString()));
|
||||
connect(dialog, &ConfirmUninstallDialog::buttonClicked, [=](int key){
|
||||
dialog->deleteLater();
|
||||
if (key == 1){
|
||||
qWarning() << "Uninstall application:" << dataObj.value("id").toString();
|
||||
m_launcher->RequestUninstall(dataObj.value("id").toString(), true);
|
||||
}
|
||||
});
|
||||
dialog->exec();
|
||||
}
|
||||
else//File or Dirctory
|
||||
{
|
||||
@ -119,3 +143,26 @@ void MainItem::updateIcon(bool isOpen)
|
||||
QPixmap pixmap = QIcon::fromTheme(iconName).pixmap(Dock::APPLET_FASHION_ICON_SIZE,Dock::APPLET_FASHION_ICON_SIZE);
|
||||
setPixmap(pixmap);
|
||||
}
|
||||
|
||||
// iconName should be a icon name constraints to the freeedesktop standard.
|
||||
QString MainItem::getThemeIconPath(QString iconName)
|
||||
{
|
||||
QByteArray bytes = iconName.toUtf8();
|
||||
const char *name = bytes.constData();
|
||||
|
||||
GtkIconTheme* theme = gtk_icon_theme_get_default();
|
||||
|
||||
GtkIconInfo* info = gtk_icon_theme_lookup_icon(theme, name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
|
||||
|
||||
if (info) {
|
||||
char* path = g_strdup(gtk_icon_info_get_filename(info));
|
||||
#if GTK_MAJOR_VERSION >= 3
|
||||
g_object_unref(info);
|
||||
#elif GTK_MAJOR_VERSION == 2
|
||||
gtk_icon_info_free(info);
|
||||
#endif
|
||||
return QString(path);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
#include <QDragEnterEvent>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dialogs/confirmuninstalldialog.h"
|
||||
#include "dialogs/cleartrashdialog.h"
|
||||
#include "dockconstants.h"
|
||||
#include "dbus/dbusfiletrashmonitor.h"
|
||||
#include "dbus/dbusfileoperations.h"
|
||||
@ -31,6 +34,7 @@ protected:
|
||||
void dropEvent(QDropEvent * event);
|
||||
|
||||
private:
|
||||
QString getThemeIconPath(QString iconName);
|
||||
void updateIcon(bool isOpen);
|
||||
|
||||
DBusFileOperations * m_dfo = new DBusFileOperations(this);
|
||||
|
5
dde-dock-trash-plugin/qss.qrc
Normal file
5
dde-dock-trash-plugin/qss.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>Resource/qss/trash.qss</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -5,6 +5,9 @@
|
||||
TrashPlugin::TrashPlugin()
|
||||
{
|
||||
QIcon::setThemeName("Deepin");
|
||||
|
||||
m_item = new MainItem();
|
||||
connect(this, &TrashPlugin::menuItemInvoked, m_item, &MainItem::emptyTrash);
|
||||
}
|
||||
|
||||
void TrashPlugin::init(DockPluginProxyInterface *proxy)
|
||||
@ -56,12 +59,7 @@ void TrashPlugin::setDisabled(QString, bool)
|
||||
|
||||
QWidget * TrashPlugin::getItem(QString)
|
||||
{
|
||||
MainItem * item = new MainItem();
|
||||
connect(this, &TrashPlugin::menuItemInvoked, item, &MainItem::emptyTrash);
|
||||
|
||||
m_itemList.append(item);
|
||||
|
||||
return item;
|
||||
return m_item;
|
||||
}
|
||||
|
||||
QWidget * TrashPlugin::getApplet(QString)
|
||||
|
@ -49,6 +49,7 @@ private:
|
||||
QList<MainItem *> m_itemList;
|
||||
QString m_id = "trash_plugin";
|
||||
DockPluginProxyInterface * m_proxy;
|
||||
MainItem * m_item = NULL;
|
||||
|
||||
Dock::DockMode m_mode = Dock::EfficientMode;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user