]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/terminal/terminalpanel.cpp
BUG: 164489
[dolphin.git] / src / panels / terminal / terminalpanel.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 "terminalpanel.h"
21
22 #include <klibloader.h>
23 #include <kde_terminal_interface_v2.h>
24 #include <kparts/part.h>
25 #include <kshell.h>
26
27 #include <QBoxLayout>
28 #include <QShowEvent>
29
30 #include <kdebug.h>
31
32 TerminalPanel::TerminalPanel(QWidget* parent) :
33 Panel(parent),
34 m_layout(0),
35 m_terminal(0),
36 m_terminalWidget(0)
37 {
38 m_layout = new QVBoxLayout(this);
39 m_layout->setMargin(0);
40 }
41
42 TerminalPanel::~TerminalPanel()
43 {
44 }
45
46 QSize TerminalPanel::sizeHint() const
47 {
48 QSize size = Panel::sizeHint();
49 size.setHeight(200);
50 return size;
51 }
52
53 void TerminalPanel::setUrl(const KUrl& url)
54 {
55 if (!url.isValid() || (url == Panel::url())) {
56 return;
57 }
58
59 Panel::setUrl(url);
60 const bool sendInput = (m_terminal != 0)
61 && (m_terminal->foregroundProcessId() == -1)
62 && isVisible()
63 && url.isLocalFile();
64 if (sendInput) {
65 m_terminal->sendInput("cd " + KShell::quoteArg(url.toLocalFile()) + '\n');
66 }
67
68 }
69
70 void TerminalPanel::terminalExited()
71 {
72 emit hideTerminalPanel();
73 m_terminal = 0;
74 }
75
76 void TerminalPanel::showEvent(QShowEvent* event)
77 {
78 if (event->spontaneous()) {
79 Panel::showEvent(event);
80 return;
81 }
82
83 if (m_terminal == 0) {
84 KPluginFactory* factory = KPluginLoader("libkonsolepart").factory();
85 KParts::ReadOnlyPart* part = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : 0;
86 if (part != 0) {
87 connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited()));
88 m_terminalWidget = part->widget();
89 m_layout->addWidget(m_terminalWidget);
90 m_terminal = qobject_cast<TerminalInterfaceV2 *>(part);
91 m_terminal->showShellInDir(url().path());
92
93 }
94 }
95 if (m_terminal != 0) {
96 m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
97 m_terminal->sendInput("clear\n");
98 m_terminalWidget->setFocus();
99 }
100
101 Panel::showEvent(event);
102 }
103
104 #include "terminalpanel.moc"