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