1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2007 by David Faure <faure@kde.org> *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphindropcontroller.h"
24 #include <QApplication>
27 #include <konq_operations.h>
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.
33 DolphinDropController::DolphinDropController(QWidget
* parentWidget
)
34 : QObject(parentWidget
), m_parentWidget(parentWidget
)
38 DolphinDropController::~DolphinDropController()
42 void DolphinDropController::dropUrls(const KUrl::List
& urls
,
43 const KUrl
& destination
)
45 kDebug() << "Source" << urls
;
46 kDebug() << "Destination:" << destination
;
48 if (destination
.protocol() == "trash") {
49 KonqOperations::del(m_parentWidget
, KonqOperations::TRASH
, urls
);
53 Qt::DropAction action
= Qt::CopyAction
;
55 Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
56 const bool shiftPressed
= modifier
& Qt::ShiftModifier
;
57 const bool controlPressed
= modifier
& Qt::ControlModifier
;
58 const bool altPressed
= modifier
& Qt::AltModifier
;
59 if ((shiftPressed
&& controlPressed
) || altPressed
) {
60 action
= Qt::LinkAction
;
61 } else if (controlPressed
) {
62 action
= Qt::CopyAction
;
63 } else if (shiftPressed
) {
64 action
= Qt::MoveAction
;
66 // open a context menu which offers the following actions:
72 KMenu
popup(m_parentWidget
);
74 QString seq
= QKeySequence(Qt::ShiftModifier
).toString();
75 seq
.chop(1); // chop superfluous '+'
76 QAction
* moveAction
= popup
.addAction(KIcon("go-jump"),
77 i18nc("@action:inmenu",
78 "&Move Here\t<shortcut>%1</shortcut>", seq
));
80 seq
= QKeySequence(Qt::ControlModifier
).toString();
82 QAction
* copyAction
= popup
.addAction(KIcon("edit-copy"),
83 i18nc("@action:inmenu",
84 "&Copy Here\t<shortcut>%1</shortcut>", seq
));
86 seq
= QKeySequence(Qt::ControlModifier
+ Qt::ShiftModifier
).toString();
88 QAction
* linkAction
= popup
.addAction(KIcon("edit-create-symbolic-link"),
89 i18nc("@action:inmenu",
90 "&Link Here\t<shortcut>%1</shortcut>", seq
));
93 popup
.addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel"));
95 QAction
* activatedAction
= popup
.exec(QCursor::pos());
96 if (activatedAction
== moveAction
) {
97 action
= Qt::MoveAction
;
98 } else if (activatedAction
== copyAction
) {
99 action
= Qt::CopyAction
;
100 } else if (activatedAction
== linkAction
) {
101 action
= Qt::LinkAction
;
109 KonqOperations::copy(m_parentWidget
, KonqOperations::MOVE
, urls
, destination
);
110 emit
doingOperation(KonqFileUndoManager::MOVE
);
114 KonqOperations::copy(m_parentWidget
, KonqOperations::COPY
, urls
, destination
);
115 emit
doingOperation(KonqFileUndoManager::COPY
);
119 KonqOperations::copy(m_parentWidget
, KonqOperations::LINK
, urls
, destination
);
120 emit
doingOperation(KonqFileUndoManager::LINK
);
128 #include "dolphindropcontroller.moc"