]>
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_operations.h>
32 #include <kpropertiesdialog.h>
34 #include "renamedialog.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 // insert 'Cut', 'Copy' and 'Paste'
58 QAction
* cutAction
= new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
59 connect(cutAction
, SIGNAL(triggered()), this, SLOT(cut()));
61 QAction
* copyAction
= new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
62 connect(copyAction
, SIGNAL(triggered()), this, SLOT(copy()));
64 QAction
* pasteAction
= new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
65 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
66 const KUrl::List pasteData
= KUrl::List::fromMimeData(mimeData
);
67 pasteAction
->setEnabled(!pasteData
.isEmpty());
68 connect(pasteAction
, SIGNAL(triggered()), this, SLOT(paste()));
70 popup
->addAction(cutAction
);
71 popup
->addAction(copyAction
);
72 popup
->addAction(pasteAction
);
73 popup
->addSeparator();
76 QAction
* renameAction
= new QAction(i18nc("@action:inmenu", "Rename..."), this);
77 connect(renameAction
, SIGNAL(triggered()), this, SLOT(rename()));
78 popup
->addAction(renameAction
);
80 // insert 'Move to Trash' and (optionally) 'Delete'
81 KConfigGroup
kdeConfig(KGlobal::config(), "KDE");
82 bool showDeleteCommand
= kdeConfig
.readEntry("ShowDeleteCommand", false);
83 const KUrl
& url
= m_fileInfo
.url();
84 if (url
.isLocalFile()) {
85 QAction
* moveToTrashAction
= new QAction(KIcon("user-trash"),
86 i18nc("@action:inmenu", "Move To Trash"), this);
87 connect(moveToTrashAction
, SIGNAL(triggered()), this, SLOT(moveToTrash()));
88 popup
->addAction(moveToTrashAction
);
90 showDeleteCommand
= true;
93 if (showDeleteCommand
) {
94 QAction
* deleteAction
= new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
95 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(deleteItem()));
96 popup
->addAction(deleteAction
);
99 popup
->addSeparator();
101 // insert 'Properties' entry
102 QAction
* propertiesAction
= new QAction(i18nc("@action:inmenu", "Properties"), this);
103 connect(propertiesAction
, SIGNAL(triggered()), this, SLOT(showProperties()));
104 popup
->addAction(propertiesAction
);
106 popup
->addSeparator();
109 QAction
* showHiddenFilesAction
= new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
110 showHiddenFilesAction
->setCheckable(true);
111 showHiddenFilesAction
->setChecked(FoldersPanelSettings::showHiddenFiles());
112 popup
->addAction(showHiddenFilesAction
);
114 connect(showHiddenFilesAction
, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
116 popup
->exec(QCursor::pos());
117 popup
->deleteLater();
120 void TreeViewContextMenu::cut()
122 QMimeData
* mimeData
= new QMimeData();
124 kdeUrls
.append(m_fileInfo
.url());
125 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), true);
126 QApplication::clipboard()->setMimeData(mimeData
);
129 void TreeViewContextMenu::copy()
131 QMimeData
* mimeData
= new QMimeData();
133 kdeUrls
.append(m_fileInfo
.url());
134 KonqMimeData::populateMimeData(mimeData
, kdeUrls
, KUrl::List(), false);
135 QApplication::clipboard()->setMimeData(mimeData
);
138 void TreeViewContextMenu::paste()
140 QClipboard
* clipboard
= QApplication::clipboard();
141 const QMimeData
* mimeData
= clipboard
->mimeData();
143 const KUrl::List source
= KUrl::List::fromMimeData(mimeData
);
144 const KUrl
& dest
= m_fileInfo
.url();
145 if (KonqMimeData::decodeIsCutSelection(mimeData
)) {
146 KonqOperations::copy(m_parent
, KonqOperations::MOVE
, source
, dest
);
149 KonqOperations::copy(m_parent
, KonqOperations::COPY
, source
, dest
);
153 void TreeViewContextMenu::rename()
156 item
.append(m_fileInfo
);
157 RenameDialog
dialog(m_parent
, item
);
158 if (dialog
.exec() == QDialog::Accepted
) {
159 const QString
& newName
= dialog
.newName();
160 if (!newName
.isEmpty()) {
161 KUrl newUrl
= m_fileInfo
.url();
162 newUrl
.setFileName(newName
);
163 KonqOperations::rename(m_parent
, m_fileInfo
.url(), newUrl
);
168 void TreeViewContextMenu::moveToTrash()
170 KonqOperations::del(m_parent
, KonqOperations::TRASH
, m_fileInfo
.url());
173 void TreeViewContextMenu::deleteItem()
175 KonqOperations::del(m_parent
, KonqOperations::DEL
, m_fileInfo
.url());
178 void TreeViewContextMenu::showProperties()
180 KPropertiesDialog
dialog(m_fileInfo
.url(), m_parent
);
184 void TreeViewContextMenu::setShowHiddenFiles(bool show
)
186 m_parent
->setShowHiddenFiles(show
);
189 #include "treeviewcontextmenu.moc"