#include "treeviewcontextmenu.h"
+#include <kfileitem.h>
#include <kiconloader.h>
+#include <kio/deletejob.h>
#include <kmenu.h>
#include <konqmimedata.h>
#include <konq_operations.h>
#include <klocale.h>
#include <kpropertiesdialog.h>
-#include <QApplication>
-#include <QClipboard>
+#include "renamedialog.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QClipboard>
TreeViewContextMenu::TreeViewContextMenu(QWidget* parent,
- KFileItem* fileInfo) :
+ const KFileItem& fileInfo) :
m_parent(parent),
m_fileInfo(fileInfo)
{
void TreeViewContextMenu::open()
{
- Q_ASSERT(m_fileInfo != 0);
+ Q_ASSERT(!m_fileInfo.isNull());
KMenu* popup = new KMenu(m_parent);
// insert 'Cut', 'Copy' and 'Paste'
- QAction* cutAction = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
+ QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
- QAction* copyAction = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
+ QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
- QAction* pasteAction = new QAction(KIcon("edit-paste"), i18n("Paste"), this);
+ QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
pasteAction->setEnabled(!pasteData.isEmpty());
popup->addSeparator();
// insert 'Rename'
- QAction* renameAction = new QAction(i18n("Rename"), this);
+ QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this);
connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
popup->addAction(renameAction);
// insert 'Move to Trash' and (optionally) 'Delete'
- const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
- const KConfigGroup kdeConfig(globalConfig, "KDE");
+ KConfigGroup kdeConfig(KGlobal::config(), "KDE");
bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
- const KUrl& url = m_fileInfo->url();
+ const KUrl& url = m_fileInfo.url();
if (url.isLocalFile()) {
- QAction* moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
+ QAction* moveToTrashAction = new QAction(KIcon("user-trash"),
+ i18nc("@action:inmenu", "Move To Trash"), this);
connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
popup->addAction(moveToTrashAction);
- }
- else {
+ } else {
showDeleteCommand = true;
}
if (showDeleteCommand) {
- QAction* deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
+ QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
popup->addAction(deleteAction);
}
popup->addSeparator();
- // insert 'Properties...' entry
- QAction* propertiesAction = new QAction(i18n("Properties..."), this);
- connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
+ // insert 'Properties' entry
+ QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this);
+ connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties()));
popup->addAction(propertiesAction);
popup->exec(QCursor::pos());
{
QMimeData* mimeData = new QMimeData();
KUrl::List kdeUrls;
- kdeUrls.append(m_fileInfo->url());
+ kdeUrls.append(m_fileInfo.url());
KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true);
QApplication::clipboard()->setMimeData(mimeData);
}
{
QMimeData* mimeData = new QMimeData();
KUrl::List kdeUrls;
- kdeUrls.append(m_fileInfo->url());
+ kdeUrls.append(m_fileInfo.url());
KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), false);
QApplication::clipboard()->setMimeData(mimeData);
}
const QMimeData* mimeData = clipboard->mimeData();
const KUrl::List source = KUrl::List::fromMimeData(mimeData);
- const KUrl& dest = m_fileInfo->url();
+ const KUrl& dest = m_fileInfo.url();
if (KonqMimeData::decodeIsCutSelection(mimeData)) {
KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest);
clipboard->clear();
- }
- else {
+ } else {
KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest);
}
}
void TreeViewContextMenu::rename()
{
- // TODO
+ KFileItemList item;
+ item.append(m_fileInfo);
+ RenameDialog dialog(m_parent, item);
+ if (dialog.exec() == QDialog::Accepted) {
+ const QString& newName = dialog.newName();
+ if (!newName.isEmpty()) {
+ KUrl newUrl = m_fileInfo.url();
+ newUrl.setFileName(newName);
+ KonqOperations::rename(m_parent, m_fileInfo.url(), newUrl);
+ }
+ }
}
void TreeViewContextMenu::moveToTrash()
{
- // TODO
+ KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileInfo.url());
}
void TreeViewContextMenu::deleteItem()
{
- // TODO
+ KonqOperations::del(m_parent, KonqOperations::DEL, m_fileInfo.url());
}
void TreeViewContextMenu::showProperties()
{
- new KPropertiesDialog(m_fileInfo->url());
+ KPropertiesDialog dialog(m_fileInfo.url(), m_parent);
+ dialog.exec();
}
#include "treeviewcontextmenu.moc"