]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinremoveaction.cpp
Remove unused #include
[dolphin.git] / src / dolphinremoveaction.cpp
1 /***************************************************************************
2 * Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org> *
3 * Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphinremoveaction.h"
22
23 #include <QApplication>
24
25 DolphinRemoveAction::DolphinRemoveAction(QObject* parent, KActionCollection* collection) :
26 QAction(parent),
27 m_collection(collection)
28 {
29 update();
30 connect(this, &DolphinRemoveAction::triggered, this, &DolphinRemoveAction::slotRemoveActionTriggered);
31 }
32
33 void DolphinRemoveAction::slotRemoveActionTriggered()
34 {
35 if (m_action) {
36 m_action->trigger();
37 }
38 }
39
40 void DolphinRemoveAction::update(ShiftState shiftState)
41 {
42 if (!m_collection) {
43 m_action = nullptr;
44 return;
45 }
46
47 if (shiftState == ShiftState::Unknown) {
48 shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released;
49 }
50
51 switch (shiftState) {
52 case ShiftState::Pressed: {
53 m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile));
54 // Make sure we show Shift+Del in the context menu.
55 auto deleteShortcuts = m_action->shortcuts();
56 deleteShortcuts.removeAll(Qt::SHIFT | Qt::Key_Delete);
57 deleteShortcuts.prepend(Qt::SHIFT | Qt::Key_Delete);
58 m_collection->setDefaultShortcuts(this, deleteShortcuts);
59 break;
60 }
61 case ShiftState::Released: {
62 m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash));
63 // Make sure we show Del in the context menu.
64 auto trashShortcuts = m_action->shortcuts();
65 trashShortcuts.removeAll(QKeySequence::Delete);
66 trashShortcuts.prepend(QKeySequence::Delete);
67 m_collection->setDefaultShortcuts(this, trashShortcuts);
68 break;
69 }
70 case ShiftState::Unknown:
71 Q_UNREACHABLE();
72 break;
73 }
74
75 if (m_action) {
76 setText(m_action->text());
77 setIcon(m_action->icon());
78 setEnabled(m_action->isEnabled());
79 }
80 }