]>
cloud.milkyroute.net Git - dolphin.git/blob - src/treeviewcontextmenu.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * Cvetoslav Ludmiloff *
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 "treeviewcontextmenu.h"
23 #include <kiconloader.h>
24 #include <kio/deletejob.h>
26 #include <konqmimedata.h>
27 #include <konq_operations.h>
29 #include <kpropertiesdialog.h>
31 #include "renamedialog.h"
33 #include <QApplication>
36 TreeViewContextMenu::TreeViewContextMenu(QWidget
* parent
,
37 KFileItem
* fileInfo
) :
43 TreeViewContextMenu::~TreeViewContextMenu()
47 void TreeViewContextMenu::open()
49 Q_ASSERT(m_fileInfo
!= 0);
51 KMenu
* popup
= new KMenu(m_parent
);
53 // insert 'Cut', 'Copy' and 'Paste'
54 QAction
* cutAction
= new QAction(KIcon("edit-cut"), i18n("Cut"), this);
55 connect(cutAction
, SIGNAL(triggered()), this, SLOT(cut()));
57 QAction
* copyAction
= new QAction(KIcon("edit-copy"), i18n("Copy"), this);
58 connect(copyAction
, SIGNAL(triggered()), this, SLOT(copy()));
60 QAction
* pasteAction
= new QAction(KIcon("edit-paste"), i18n("Paste"), this);
61 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
62 const KUrl::List pasteData
= KUrl::List::fromMimeData(mimeData
);
63 pasteAction
->setEnabled(!pasteData
.isEmpty());
64 connect(pasteAction
, SIGNAL(triggered()), this, SLOT(paste()));
66 popup
->addAction(cutAction
);
67 popup
->addAction(copyAction
);
68 popup
->addAction(pasteAction
);
69 popup
->addSeparator();
72 QAction
* renameAction
= new QAction(i18n("Rename"), this);
73 connect(renameAction
, SIGNAL(triggered()), this, SLOT(rename()));
74 popup
->addAction(renameAction
);
76 // insert 'Move to Trash' and (optionally) 'Delete'
77 const KSharedConfig::Ptr globalConfig
= KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals
);
78 const KConfigGroup
kdeConfig(globalConfig
, "KDE");
79 bool showDeleteCommand
= kdeConfig
.readEntry("ShowDeleteCommand", false);
80 const KUrl
& url
= m_fileInfo
->url();
81 if (url
.isLocalFile()) {
82 QAction
* moveToTrashAction
= new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
83 connect(moveToTrashAction
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
84 popup
->addAction(moveToTrashAction
);
87 showDeleteCommand
= true;
90 if (showDeleteCommand
) {
91 QAction
* deleteAction
= new QAction(KIcon("edit-delete"), i18n("Delete"), this);
92 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItem()));
93 popup
->addAction(deleteAction
);
96 popup
->addSeparator();
98 // insert 'Properties...' entry
99 QAction
* propertiesAction
= new QAction(i18n("Properties..."), this);
100 connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
101 popup
->addAction(propertiesAction
);
103 popup
->exec(QCursor::pos());
104 popup
->deleteLater();
107 void TreeViewContextMenu::cut()
109 QMimeData
* mimeData
= new QMimeData();
111 kdeUrls
.append(m_fileInfo
->url());
112 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), true);
113 QApplication::clipboard()->setMimeData(mimeData
);
116 void TreeViewContextMenu::copy()
118 QMimeData
* mimeData
= new QMimeData();
120 kdeUrls
.append(m_fileInfo
->url());
121 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), false);
122 QApplication::clipboard()->setMimeData(mimeData
);
125 void TreeViewContextMenu::paste()
127 QClipboard
* clipboard
= QApplication::clipboard();
128 const QMimeData
* mimeData
= clipboard
->mimeData();
130 const KUrl::List source
= KUrl::List::fromMimeData(mimeData
);
131 const KUrl
& dest
= m_fileInfo
->url();
132 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
133 KonqOperations::copy(m_parent
, KonqOperations::MOVE
, source
, dest
);
137 KonqOperations::copy(m_parent
, KonqOperations::COPY
, source
, dest
);
141 void TreeViewContextMenu::rename()
143 const KUrl
& oldUrl
= m_fileInfo
->url();
144 RenameDialog
dialog(oldUrl
);
145 if (dialog
.exec() == QDialog::Accepted
) {
146 const QString
& newName
= dialog
.newName();
147 if (!newName
.isEmpty()) {
148 KUrl newUrl
= oldUrl
.upUrl();
149 newUrl
.addPath(newName
);
150 KonqOperations::rename(m_parent
, oldUrl
, newUrl
);
155 void TreeViewContextMenu::moveToTrash()
157 KonqOperations::del(m_parent
, KonqOperations::TRASH
, m_fileInfo
->url());
160 void TreeViewContextMenu::deleteItem()
162 const KUrl
& url
= m_fileInfo
->url();
163 const bool del
= KonqOperations::askDeleteConfirmation(url
,
165 KonqOperations::FORCE_CONFIRMATION
,
172 void TreeViewContextMenu::showProperties()
174 new KPropertiesDialog(m_fileInfo
->url());
177 #include "treeviewcontextmenu.moc"