From 35ee348c45b3400bb7d6842189855b4033f6636b Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 6 May 2007 21:50:24 +0000 Subject: [PATCH] Initial step for showing the terminal embedded inside Dolphin instead of opening a separate window. This allows to synchronize the current directory of the terminal with the shown directory in Dolphin. svn path=/trunk/KDE/kdebase/apps/; revision=661890 --- src/CMakeLists.txt | 1 + src/dolphinmainwindow.cpp | 39 ++++++++++++------------ src/dolphinmainwindow.h | 7 ++--- src/dolphinui.rc | 2 +- src/terminalsidebarpage.cpp | 60 +++++++++++++++++++++++++++++++++++++ src/terminalsidebarpage.h | 52 ++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 25 deletions(-) create mode 100644 src/terminalsidebarpage.cpp create mode 100644 src/terminalsidebarpage.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 123eed3ac9..54e59583d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,7 @@ set(dolphin_SRCS sidebarpage.cpp statusbarspaceinfo.cpp statusbarmessagelabel.cpp + terminalsidebarpage.cpp treeviewcontextmenu.cpp treeviewsidebarpage.cpp sidebartreeview.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ee4830785d..00eadbda90 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -30,6 +30,7 @@ #include "infosidebarpage.h" #include "metadatawidget.h" #include "mainwindowadaptor.h" +#include "terminalsidebarpage.h" #include "treeviewsidebarpage.h" #include "kurlnavigator.h" #include "viewpropertiesdialog.h" @@ -813,7 +814,7 @@ void DolphinMainWindow::toggleShowHiddenFiles() m_activeView->setShowHiddenFiles(show); } -void DolphinMainWindow::showFilterBar() +void DolphinMainWindow::toggleFilterBarVisibility() { const KToggleAction* showFilterBarAction = static_cast(actionCollection()->action("show_filter_bar")); @@ -879,15 +880,6 @@ void DolphinMainWindow::goHome() m_activeView->goHome(); } -void DolphinMainWindow::openTerminal() -{ - QString command("konsole --workdir \""); - command.append(m_activeView->url().path()); - command.append('\"'); - - KRun::runCommand(command, "Konsole", "konsole"); -} - void DolphinMainWindow::findFile() { KRun::run("kfind", m_activeView->url()); @@ -1237,12 +1229,6 @@ void DolphinMainWindow::setupActions() KStandardAction::home(this, SLOT(goHome()), actionCollection()); // setup 'Tools' menu - QAction* openTerminal = actionCollection()->addAction("open_terminal"); - openTerminal->setText(i18n("Open Terminal")); - openTerminal->setShortcut(Qt::Key_F4); - openTerminal->setIcon(KIcon("konsole")); - connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); - QAction* findFile = actionCollection()->addAction("find_file"); findFile->setText(i18n("Find File...")); findFile->setShortcut(Qt::CTRL | Qt::Key_F); @@ -1252,7 +1238,7 @@ void DolphinMainWindow::setupActions() KToggleAction* showFilterBar = actionCollection()->add("show_filter_bar"); showFilterBar->setText(i18n("Show Filter Bar")); showFilterBar->setShortcut(Qt::Key_Slash); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar())); + connect(showFilterBar, SIGNAL(triggered()), this, SLOT(toggleFilterBarVisibility())); QAction* compareFiles = actionCollection()->addAction("compare_files"); compareFiles->setText(i18n("Compare Files")); @@ -1273,7 +1259,7 @@ void DolphinMainWindow::setupDockWidgets() SidebarPage* infoWidget = new InfoSidebarPage(infoDock); infoDock->setWidget(infoWidget); - infoDock->toggleViewAction()->setText(i18n("Show Information Panel")); + infoDock->toggleViewAction()->setText(i18n("Information")); actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, infoDock); @@ -1289,7 +1275,7 @@ void DolphinMainWindow::setupDockWidgets() TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock); treeViewDock->setWidget(treeWidget); - treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel")); + treeViewDock->toggleViewAction()->setText(i18n("Folders")); actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, treeViewDock); @@ -1302,10 +1288,25 @@ void DolphinMainWindow::setupDockWidgets() connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)), this, SLOT(dropUrls(KUrl::List, KUrl))); + // setup "Terminal" + QDockWidget* terminalDock = new QDockWidget(i18n("Terminal")); + terminalDock->setObjectName("terminalDock"); + terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); + SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock); + terminalDock->setWidget(terminalWidget); + + terminalDock->toggleViewAction()->setText(i18n("Terminal")); + actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction()); + + addDockWidget(Qt::RightDockWidgetArea, terminalDock); + connect(this, SIGNAL(urlChanged(KUrl)), + terminalWidget, SLOT(setUrl(KUrl))); + const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun(); if (firstRun) { infoDock->hide(); treeViewDock->hide(); + terminalDock->hide(); } QDockWidget *placesDock = new QDockWidget(i18n("Places")); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index e1de7f808e..297408cc60 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -309,10 +309,10 @@ private slots: void toggleShowHiddenFiles(); /** - * Switches between showing and hiding of the filter bar dependent + * Toggles between showing and hiding of the filter bar dependent * from the current state of the 'Show Filter Bar' menu toggle action. */ - void showFilterBar(); + void toggleFilterBarVisibility(); /** Increases the size of the current set view mode. */ void zoomIn(); @@ -349,9 +349,6 @@ private slots: /** Goes to the home URL. */ void goHome(); - /** Opens a terminal for the current shown directory. */ - void openTerminal(); - /** Opens KFind for the current shown directory. */ void findFile(); diff --git a/src/dolphinui.rc b/src/dolphinui.rc index f7207b2f87..54c60e15d1 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -54,6 +54,7 @@ + Navigation Bar @@ -64,7 +65,6 @@ - diff --git a/src/terminalsidebarpage.cpp b/src/terminalsidebarpage.cpp new file mode 100644 index 0000000000..8c8dcedeff --- /dev/null +++ b/src/terminalsidebarpage.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "terminalsidebarpage.h" + +#include +#include +#include + +#include + +TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) : + SidebarPage(parent), + m_layout(0), + m_terminal(0) +{ + m_layout = new QVBoxLayout(this); + m_layout->setMargin(0); +} + +TerminalSidebarPage::~TerminalSidebarPage() +{ +} + +void TerminalSidebarPage::setUrl(const KUrl& url) +{ + SidebarPage::setUrl(url); + // TODO: synchronize terminal +} + +void TerminalSidebarPage::showEvent(QShowEvent* event) +{ + if (m_terminal == 0) { + KLibFactory* factory = KLibLoader::self()->factory("libkonsolepart"); + KParts::Part* part = static_cast(factory->create(this, "KParts::ReadOnlyPart")); + if (part != 0) { + m_terminal = part->widget(); + m_layout->addWidget(m_terminal); + } + } + SidebarPage::showEvent(event); +} + +#include "terminalsidebarpage.moc" diff --git a/src/terminalsidebarpage.h b/src/terminalsidebarpage.h new file mode 100644 index 0000000000..ddefad9e56 --- /dev/null +++ b/src/terminalsidebarpage.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef TERMINALSIDEBARPAGE_H +#define TERMINALSIDEBARPAGE_H + +#include + +class QVBoxLayout; + +/** + * @brief Shows the terminal which is synchronized with the URL of the + * active view. + */ +class TerminalSidebarPage : public SidebarPage +{ + Q_OBJECT + +public: + TerminalSidebarPage(QWidget* parent = 0); + virtual ~TerminalSidebarPage(); + +public slots: + /** @see SidebarPage::setUrl(). */ + virtual void setUrl(const KUrl& url); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + +private: + QVBoxLayout* m_layout; + QWidget* m_terminal; +}; + +#endif // TERMINALSIDEBARPAGE_H