From 38beff1a4b291b479a067e556ad7a4dd3e52cf8e Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 4 Jun 2008 11:51:54 +0000 Subject: [PATCH] Continue cleaning up the menus of "konqueror as a webbrowser" : moved "Tools / Open Terminal" action to DolphinPart. Thanks to Kevin for reminding me of this one. svn path=/trunk/KDE/kdebase/apps/; revision=816632 --- src/dolphinpart.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++-- src/dolphinpart.h | 5 +++++ src/dolphinpart.rc | 3 ++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 766a8f0dd..686dde5b8 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #include #include @@ -164,6 +167,16 @@ void DolphinPart::createActions() createGoAction("go_autostart", "", i18nc("@action:inmenu Go", "Autostart"), KGlobalSettings::autostartPath(), goActionGroup); + + // Tools menu + if (KAuthorized::authorizeKAction("shell_access")) { + KAction* action = actionCollection()->addAction("open_terminal"); + action->setIcon(KIcon("utilities-terminal")); + action->setText(i18nc("@action:inmenu Tools", "Open &Terminal")); + connect(action, SIGNAL(triggered()), SLOT(slotOpenTerminal())); + action->setShortcut(Qt::Key_F4); + } + } void DolphinPart::createGoAction(const char* name, const char* iconName, @@ -208,7 +221,7 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection) KonqFileItemCapabilities capabilities(selection); const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); - + renameAction->setEnabled(capabilities.supportsMoving()); moveToTrashAction->setEnabled(enableMoveToTrash); deleteAction->setEnabled(capabilities.supportsDeleting()); @@ -336,7 +349,7 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&) sDeleting = false; sMoving = false; } - + if ( sMoving ) editActions.append(actionCollection()->action("rename")); @@ -458,4 +471,35 @@ void DolphinPart::setNameFilter(const QString& nameFilter) // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3? } +void DolphinPart::slotOpenTerminal() +{ + KConfigGroup confGroup(KGlobal::config(), "General"); // set by componentchooser kcm + const QString preferredTerminal = confGroup.readPathEntry("TerminalApplication", "konsole"); + + QString dir(QDir::homePath()); + + KUrl u(url()); + + // If the given directory is not local, it can still be the URL of an + // ioslave using UDS_LOCAL_PATH which to be converted first. + u = KIO::NetAccess::mostLocalUrl(u, widget()); + + //If the URL is local after the above conversion, set the directory. + if (u.isLocalFile()) { + dir = u.path(); + } + + // Compensate for terminal having arguments. + QStringList args = KShell::splitArgs(preferredTerminal); + if (args.isEmpty()) { + return; + } + const QString prog = args.takeFirst(); + if (prog == "konsole") { + args << "--workdir"; + args << dir; + } + QProcess::startDetached(prog, args); +} + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 612c22aa7..ac32c5f43 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -172,6 +172,11 @@ private Q_SLOTS: */ void slotProperties(); + /** + * Open a terminal window, starting with the current directory. + */ + void slotOpenTerminal(); + private: void createActions(); void createGoAction(const char* name, const char* iconName, diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc index 2e3f63e5c..6efc50ba9 100644 --- a/src/dolphinpart.rc +++ b/src/dolphinpart.rc @@ -1,5 +1,5 @@ - + @@ -50,6 +50,7 @@ + -- 2.47.3