]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/folders/treeviewcontextmenu.cpp
1 /***************************************************************************
2 * Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by 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 <kfileitem.h>
24 #include <kiconloader.h>
25 #include <kio/deletejob.h>
27 #include <konqmimedata.h>
28 #include <kfileitemlistproperties.h>
29 #include <konq_operations.h>
31 #include <kpropertiesdialog.h>
33 #include "folderspanel.h"
35 #include <QApplication>
39 TreeViewContextMenu::TreeViewContextMenu(FoldersPanel
* parent
,
40 const KFileItem
& fileInfo
) :
47 TreeViewContextMenu::~TreeViewContextMenu()
51 void TreeViewContextMenu::open()
53 KMenu
* popup
= new KMenu(m_parent
);
55 if (!m_fileInfo
.isNull()) {
56 KFileItemListProperties
capabilities(KFileItemList() << m_fileInfo
);
58 // insert 'Cut', 'Copy' and 'Paste'
59 QAction
* cutAction
= new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
60 cutAction
->setEnabled(capabilities
.supportsMoving());
61 connect(cutAction
, SIGNAL(triggered()), this, SLOT(cut()));
63 QAction
* copyAction
= new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
64 connect(copyAction
, SIGNAL(triggered()), this, SLOT(copy()));
66 QAction
* pasteAction
= new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
67 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
68 const KUrl::List pasteData
= KUrl::List::fromMimeData(mimeData
);
69 connect(pasteAction
, SIGNAL(triggered()), this, SLOT(paste()));
70 pasteAction
->setEnabled(!pasteData
.isEmpty() && capabilities
.supportsWriting());
72 popup
->addAction(cutAction
);
73 popup
->addAction(copyAction
);
74 popup
->addAction(pasteAction
);
75 popup
->addSeparator();
78 QAction
* renameAction
= new QAction(i18nc("@action:inmenu", "Rename..."), this);
79 renameAction
->setEnabled(capabilities
.supportsMoving());
80 connect(renameAction
, SIGNAL(triggered()), this, SLOT(rename()));
81 popup
->addAction(renameAction
);
83 // insert 'Move to Trash' and (optionally) 'Delete'
84 KSharedConfig::Ptr globalConfig
= KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals
);
85 KConfigGroup
configGroup(globalConfig
, "KDE");
86 bool showDeleteCommand
= configGroup
.readEntry("ShowDeleteCommand", false);
88 const KUrl url
= m_fileInfo
.url();
89 if (url
.isLocalFile()) {
90 QAction
* moveToTrashAction
= new QAction(KIcon("user-trash"),
91 i18nc("@action:inmenu", "Move to Trash"), this);
92 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
93 moveToTrashAction
->setEnabled(enableMoveToTrash
);
94 connect(moveToTrashAction
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
95 popup
->addAction(moveToTrashAction
);
97 showDeleteCommand
= true;
100 if (showDeleteCommand
) {
101 QAction
* deleteAction
= new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
102 deleteAction
->setEnabled(capabilities
.supportsDeleting());
103 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItem()));
104 popup
->addAction(deleteAction
);
107 popup
->addSeparator();
109 // insert 'Properties' entry
110 QAction
* propertiesAction
= new QAction(i18nc("@action:inmenu", "Properties"), this);
111 connect(propertiesAction
, SIGNAL(triggered()), this, SLOT(showProperties()));
112 popup
->addAction(propertiesAction
);
114 popup
->addSeparator();
117 QAction
* showHiddenFilesAction
= new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
118 showHiddenFilesAction
->setCheckable(true);
119 showHiddenFilesAction
->setChecked(m_parent
->showHiddenFiles());
120 popup
->addAction(showHiddenFilesAction
);
121 connect(showHiddenFilesAction
, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
123 QAction
* autoScrollingAction
= new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
124 autoScrollingAction
->setCheckable(true);
125 autoScrollingAction
->setChecked(m_parent
->autoScrolling());
126 popup
->addAction(autoScrollingAction
);
127 connect(autoScrollingAction
, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool)));
130 popup
->exec(QCursor::pos());
131 popup
->deleteLater();
134 void TreeViewContextMenu::populateMimeData(QMimeData
* mimeData
, bool cut
)
137 kdeUrls
.append(m_fileInfo
.url());
138 KUrl::List mostLocalUrls
;
140 mostLocalUrls
.append(m_fileInfo
.mostLocalUrl(dummy
));
141 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, mostLocalUrls
, cut
);
144 void TreeViewContextMenu::cut()
146 QMimeData
* mimeData
= new QMimeData();
147 populateMimeData(mimeData
, true);
148 QApplication::clipboard()->setMimeData(mimeData
);
151 void TreeViewContextMenu::copy()
153 QMimeData
* mimeData
= new QMimeData();
154 populateMimeData(mimeData
, false);
155 QApplication::clipboard()->setMimeData(mimeData
);
158 void TreeViewContextMenu::paste()
160 QClipboard
* clipboard
= QApplication::clipboard();
161 const QMimeData
* mimeData
= clipboard
->mimeData();
163 const KUrl::List source
= KUrl::List::fromMimeData(mimeData
);
164 const KUrl
& dest
= m_fileInfo
.url();
165 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
166 KonqOperations::copy(m_parent
, KonqOperations::MOVE
, source
, dest
);
169 KonqOperations::copy(m_parent
, KonqOperations::COPY
, source
, dest
);
173 void TreeViewContextMenu::rename()
175 m_parent
->rename(m_fileInfo
);
178 void TreeViewContextMenu::moveToTrash()
180 KonqOperations::del(m_parent
, KonqOperations::TRASH
, m_fileInfo
.url());
183 void TreeViewContextMenu::deleteItem()
185 KonqOperations::del(m_parent
, KonqOperations::DEL
, m_fileInfo
.url());
188 void TreeViewContextMenu::showProperties()
190 QPointer
<KPropertiesDialog
> dialog
= new KPropertiesDialog(m_fileInfo
.url(), m_parent
);
195 void TreeViewContextMenu::setShowHiddenFiles(bool show
)
197 m_parent
->setShowHiddenFiles(show
);
200 void TreeViewContextMenu::setAutoScrolling(bool enable
)
202 m_parent
->setAutoScrolling(enable
);
205 #include "treeviewcontextmenu.moc"