]> cloud.milkyroute.net Git - dolphin.git/blob - src/terminalsidebarpage.cpp
Simplify DolphinController: don't remember the show-preview state in the controller...
[dolphin.git] / src / terminalsidebarpage.cpp
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 ***************************************************************************/
19
20 #include "terminalsidebarpage.h"
21
22 #include <klibloader.h>
23 #include <kde_terminal_interface.h>
24 #include <kparts/part.h>
25 #include <kshell.h>
26
27 #include <QBoxLayout>
28 #include <QShowEvent>
29
30 TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) :
31 SidebarPage(parent),
32 m_layout(0),
33 m_terminal(0)
34 {
35 m_layout = new QVBoxLayout(this);
36 m_layout->setMargin(0);
37 }
38
39 TerminalSidebarPage::~TerminalSidebarPage()
40 {
41 }
42
43 QSize TerminalSidebarPage::sizeHint() const
44 {
45 QSize size = SidebarPage::sizeHint();
46 size.setHeight(200);
47 return size;
48 }
49
50 void TerminalSidebarPage::setUrl(const KUrl& url)
51 {
52 if (!SidebarPage::url().equals(url, KUrl::CompareWithoutTrailingSlash)) {
53 SidebarPage::setUrl(url);
54 if ((m_terminal != 0) && isVisible()) {
55 m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n');
56 }
57 }
58 }
59
60 void TerminalSidebarPage::showEvent(QShowEvent* event)
61 {
62 if (event->spontaneous()) {
63 SidebarPage::showEvent(event);
64 return;
65 }
66
67 if (m_terminal == 0) {
68 KPluginFactory* factory = KPluginLoader("libkonsolepart").factory();
69 KParts::ReadOnlyPart* part = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : 0;
70 if (part != 0) {
71 m_layout->addWidget(part->widget());
72 m_terminal = qobject_cast<TerminalInterface *>(part);
73 }
74 }
75 if (m_terminal != 0) {
76 m_terminal->showShellInDir(url().path());
77 m_terminal->sendInput("clear\n");
78 }
79
80 SidebarPage::showEvent(event);
81 }
82
83 #include "terminalsidebarpage.moc"