]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindropcontroller.cpp
As requested by Peter: upgrade version to 1.0
[dolphin.git] / src / dolphindropcontroller.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2007 by David Faure <faure@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 "dolphindropcontroller.h"
22 #include <klocale.h>
23 #include <kicon.h>
24 #include <QApplication>
25 #include <kdebug.h>
26 #include <kmenu.h>
27 #include <konq_operations.h>
28
29 // TODO replace with KonqOperations::doDrop [or move doDrop code into this class]
30 // Note that this means changing the DolphinDropController controller usage
31 // to "create with new and let it autodelete" instead of on stack, since doDrop is async.
32
33 DolphinDropController::DolphinDropController(QWidget* parentWidget)
34 : QObject(parentWidget), m_parentWidget(parentWidget)
35 {
36 }
37
38 DolphinDropController::~DolphinDropController()
39 {
40 }
41
42 void DolphinDropController::dropUrls(const KUrl::List& urls,
43 const KUrl& destination)
44 {
45 kDebug() << "Source" << urls;
46 kDebug() << "Destination:" << destination;
47
48 Qt::DropAction action = Qt::CopyAction;
49
50 Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
51 const bool shiftPressed = modifier & Qt::ShiftModifier;
52 const bool controlPressed = modifier & Qt::ControlModifier;
53 const bool altPressed = modifier & Qt::AltModifier;
54 if (shiftPressed && controlPressed) {
55 // shortcut for 'Link Here' is used
56 action = Qt::LinkAction;
57 } else if (shiftPressed) {
58 // shortcut for 'Move Here' is used
59 action = Qt::MoveAction;
60 } else if (controlPressed) {
61 // shortcut for 'Copy Here' is used
62 action = Qt::CopyAction;
63 } else if (altPressed) {
64 // shortcut for 'Link Here' is used
65 action = Qt::LinkAction;
66 } else {
67 // open a context menu which offers the following actions:
68 // - Move Here
69 // - Copy Here
70 // - Link Here
71 // - Cancel
72
73 KMenu popup(m_parentWidget);
74
75 QString seq = QKeySequence(Qt::ShiftModifier).toString();
76 seq.chop(1); // chop superfluous '+'
77 QAction* moveAction = popup.addAction(KIcon("go-jump"),
78 i18nc("@action:inmenu",
79 "&Move Here\t<shortcut>%1</shortcut>", seq));
80
81 seq = QKeySequence(Qt::ControlModifier).toString();
82 seq.chop(1);
83 QAction* copyAction = popup.addAction(KIcon("edit-copy"),
84 i18nc("@action:inmenu",
85 "&Copy Here\t<shortcut>%1</shortcut>", seq));
86
87 seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
88 seq.chop(1);
89 QAction* linkAction = popup.addAction(KIcon("insert-link"),
90 i18nc("@action:inmenu",
91 "&Link Here\t<shortcut>%1</shortcut>", seq));
92
93 popup.addSeparator();
94 popup.addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel"));
95
96 QAction* activatedAction = popup.exec(QCursor::pos());
97 if (activatedAction == moveAction) {
98 action = Qt::MoveAction;
99 } else if (activatedAction == copyAction) {
100 action = Qt::CopyAction;
101 } else if (activatedAction == linkAction) {
102 action = Qt::LinkAction;
103 } else {
104 return;
105 }
106 }
107
108 switch (action) {
109 case Qt::MoveAction:
110 KonqOperations::copy(m_parentWidget, KonqOperations::MOVE, urls, destination);
111 emit doingOperation(KonqFileUndoManager::MOVE);
112 break;
113
114 case Qt::CopyAction:
115 KonqOperations::copy(m_parentWidget, KonqOperations::COPY, urls, destination);
116 emit doingOperation(KonqFileUndoManager::COPY);
117 break;
118
119 case Qt::LinkAction:
120 KonqOperations::copy(m_parentWidget, KonqOperations::LINK, urls, destination);
121 emit doingOperation(KonqFileUndoManager::LINK);
122 break;
123
124 default:
125 break;
126 }
127 }
128
129 #include "dolphindropcontroller.moc"