]>
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 "dolphin_folderspanelsettings.h"
25 #include <kfileitem.h>
26 #include <kiconloader.h>
27 #include <kio/deletejob.h>
29 #include <konqmimedata.h>
30 #include <konq_fileitemcapabilities.h>
31 #include <konq_operations.h>
33 #include <kpropertiesdialog.h>
35 #include "treeviewsidebarpage.h"
37 #include <QtGui/QApplication>
38 #include <QtGui/QClipboard>
40 TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage
* parent
,
41 const KFileItem
& fileInfo
) :
48 TreeViewContextMenu::~TreeViewContextMenu()
52 void TreeViewContextMenu::open()
54 KMenu
* popup
= new KMenu(m_parent
);
56 if (!m_fileInfo
.isNull()) {
57 KonqFileItemCapabilities
capabilities(KFileItemList() << m_fileInfo
);
59 // insert 'Cut', 'Copy' and 'Paste'
60 QAction
* cutAction
= new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
61 cutAction
->setEnabled(capabilities
.supportsMoving());
62 connect(cutAction
, SIGNAL(triggered()), this, SLOT(cut()));
64 QAction
* copyAction
= new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
65 connect(copyAction
, SIGNAL(triggered()), this, SLOT(copy()));
67 QAction
* pasteAction
= new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
68 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
69 const KUrl::List pasteData
= KUrl::List::fromMimeData(mimeData
);
70 connect(pasteAction
, SIGNAL(triggered()), this, SLOT(paste()));
71 pasteAction
->setEnabled(!pasteData
.isEmpty() && capabilities
.supportsWriting());
73 popup
->addAction(cutAction
);
74 popup
->addAction(copyAction
);
75 popup
->addAction(pasteAction
);
76 popup
->addSeparator();
79 QAction
* renameAction
= new QAction(i18nc("@action:inmenu", "Rename..."), this);
80 renameAction
->setEnabled(capabilities
.supportsMoving());
81 connect(renameAction
, SIGNAL(triggered()), this, SLOT(rename()));
82 popup
->addAction(renameAction
);
84 // insert 'Move to Trash' and (optionally) 'Delete'
85 KConfigGroup
kdeConfig(KGlobal::config(), "KDE");
86 bool showDeleteCommand
= kdeConfig
.readEntry("ShowDeleteCommand", false);
87 const KUrl
& url
= m_fileInfo
.url();
88 if (url
.isLocalFile()) {
89 QAction
* moveToTrashAction
= new QAction(KIcon("user-trash"),
90 i18nc("@action:inmenu", "Move To Trash"), this);
91 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
92 moveToTrashAction
->setEnabled(enableMoveToTrash
);
93 connect(moveToTrashAction
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
94 popup
->addAction(moveToTrashAction
);
96 showDeleteCommand
= true;
99 if (showDeleteCommand
) {
100 QAction
* deleteAction
= new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
101 deleteAction
->setEnabled(capabilities
.supportsDeleting());
102 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItem()));
103 popup
->addAction(deleteAction
);
106 popup
->addSeparator();
108 // insert 'Properties' entry
109 QAction
* propertiesAction
= new QAction(i18nc("@action:inmenu", "Properties"), this);
110 connect(propertiesAction
, SIGNAL(triggered()), this, SLOT(showProperties()));
111 popup
->addAction(propertiesAction
);
113 popup
->addSeparator();
116 QAction
* showHiddenFilesAction
= new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
117 showHiddenFilesAction
->setCheckable(true);
118 showHiddenFilesAction
->setChecked(FoldersPanelSettings::showHiddenFiles());
119 popup
->addAction(showHiddenFilesAction
);
121 connect(showHiddenFilesAction
, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
123 popup
->exec(QCursor::pos());
124 popup
->deleteLater();
127 void TreeViewContextMenu::cut()
129 QMimeData
* mimeData
= new QMimeData();
131 kdeUrls
.append(m_fileInfo
.url());
132 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), true);
133 QApplication::clipboard()->setMimeData(mimeData
);
136 void TreeViewContextMenu::copy()
138 QMimeData
* mimeData
= new QMimeData();
140 kdeUrls
.append(m_fileInfo
.url());
141 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), false);
142 QApplication::clipboard()->setMimeData(mimeData
);
145 void TreeViewContextMenu::paste()
147 QClipboard
* clipboard
= QApplication::clipboard();
148 const QMimeData
* mimeData
= clipboard
->mimeData();
150 const KUrl::List source
= KUrl::List::fromMimeData(mimeData
);
151 const KUrl
& dest
= m_fileInfo
.url();
152 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
153 KonqOperations::copy(m_parent
, KonqOperations::MOVE
, source
, dest
);
156 KonqOperations::copy(m_parent
, KonqOperations::COPY
, source
, dest
);
160 void TreeViewContextMenu::rename()
162 m_parent
->rename(m_fileInfo
);
165 void TreeViewContextMenu::moveToTrash()
167 KonqOperations::del(m_parent
, KonqOperations::TRASH
, m_fileInfo
.url());
170 void TreeViewContextMenu::deleteItem()
172 KonqOperations::del(m_parent
, KonqOperations::DEL
, m_fileInfo
.url());
175 void TreeViewContextMenu::showProperties()
177 KPropertiesDialog
dialog(m_fileInfo
.url(), m_parent
);
181 void TreeViewContextMenu::setShowHiddenFiles(bool show
)
183 m_parent
->setShowHiddenFiles(show
);
186 #include "treeviewcontextmenu.moc"