Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / apps / dolphin / src / terminalsidebarpage.cpp
blob4749e7714c49fbf9eb634d533c4628a3ba2d2ced
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "terminalsidebarpage.h"
22 #include <klibloader.h>
23 #include <kde_terminal_interface.h>
24 #include <kparts/part.h>
25 #include <kshell.h>
27 #include <QBoxLayout>
28 #include <QShowEvent>
30 TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) :
31 SidebarPage(parent),
32 m_layout(0),
33 m_terminal(0),
34 m_terminalWidget(0)
36 m_layout = new QVBoxLayout(this);
37 m_layout->setMargin(0);
40 TerminalSidebarPage::~TerminalSidebarPage()
44 QSize TerminalSidebarPage::sizeHint() const
46 QSize size = SidebarPage::sizeHint();
47 size.setHeight(200);
48 return size;
51 void TerminalSidebarPage::setUrl(const KUrl& url)
53 if (!url.isValid() || (url == SidebarPage::url())) {
54 return;
57 SidebarPage::setUrl(url);
58 if ((m_terminal != 0) && isVisible() && url.isLocalFile()) {
59 m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n');
63 void TerminalSidebarPage::terminalExited()
65 emit hideTerminalSidebarPage();
67 m_terminal = 0;
70 void TerminalSidebarPage::showEvent(QShowEvent* event)
72 if (event->spontaneous()) {
73 SidebarPage::showEvent(event);
74 return;
77 if (m_terminal == 0) {
78 KPluginFactory* factory = KPluginLoader("libkonsolepart").factory();
79 KParts::ReadOnlyPart* part = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : 0;
80 if (part != 0) {
81 connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited()));
82 m_terminalWidget = part->widget();
83 m_layout->addWidget(m_terminalWidget);
84 m_terminal = qobject_cast<TerminalInterface *>(part);
85 m_terminal->showShellInDir(url().path());
88 if (m_terminal != 0) {
89 m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
90 m_terminal->sendInput("clear\n");
91 m_terminalWidget->setFocus();
94 SidebarPage::showEvent(event);
97 #include "terminalsidebarpage.moc"