1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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>
30 TerminalSidebarPage::TerminalSidebarPage(QWidget
* parent
) :
36 m_layout
= new QVBoxLayout(this);
37 m_layout
->setMargin(0);
40 TerminalSidebarPage::~TerminalSidebarPage()
44 QSize
TerminalSidebarPage::sizeHint() const
46 QSize size
= SidebarPage::sizeHint();
51 void TerminalSidebarPage::setUrl(const KUrl
& url
)
53 if (!SidebarPage::url().equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
54 SidebarPage::setUrl(url
);
55 if ((m_terminal
!= 0) && isVisible()) {
56 m_terminal
->sendInput("cd " + KShell::quoteArg(url
.path()) + '\n');
61 void TerminalSidebarPage::terminalExited()
63 emit
hideTerminalSidebarPage();
65 KPluginFactory
* factory
= KPluginLoader("libkonsolepart").factory();
66 KParts::ReadOnlyPart
* part
= factory
? (factory
->create
<KParts::ReadOnlyPart
>(this)) : 0;
68 connect(part
, SIGNAL(destroyed(QObject
*)), this, SLOT(terminalExited()));
69 m_terminalWidget
= part
->widget();
70 m_layout
->addWidget(m_terminalWidget
);
71 m_terminal
= qobject_cast
<TerminalInterface
*>(part
);
72 m_terminal
->showShellInDir(url().path());
74 if (m_terminal
!= 0) {
75 m_terminal
->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
76 m_terminal
->sendInput("clear\n");
77 m_terminalWidget
->setFocus();
81 void TerminalSidebarPage::showEvent(QShowEvent
* event
)
83 if (event
->spontaneous()) {
84 SidebarPage::showEvent(event
);
88 if (m_terminal
== 0) {
89 KPluginFactory
* factory
= KPluginLoader("libkonsolepart").factory();
90 KParts::ReadOnlyPart
* part
= factory
? (factory
->create
<KParts::ReadOnlyPart
>(this)) : 0;
92 connect(part
, SIGNAL(destroyed(QObject
*)), this, SLOT(terminalExited()));
93 m_terminalWidget
= part
->widget();
94 m_layout
->addWidget(m_terminalWidget
);
95 m_terminal
= qobject_cast
<TerminalInterface
*>(part
);
96 m_terminal
->showShellInDir(url().path());
99 if (m_terminal
!= 0) {
100 m_terminal
->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
101 m_terminal
->sendInput("clear\n");
102 m_terminalWidget
->setFocus();
105 SidebarPage::showEvent(event
);
108 #include "terminalsidebarpage.moc"