]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/terminal/terminalpanel.cpp
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 "terminalpanel.h"
22 #include <klibloader.h>
23 #include <kde_terminal_interface_v2.h>
24 #include <kparts/part.h>
27 #include <KIO/JobUiDelegate>
34 TerminalPanel::TerminalPanel(QWidget
* parent
) :
40 m_layout
= new QVBoxLayout(this);
41 m_layout
->setMargin(0);
44 TerminalPanel::~TerminalPanel()
48 QSize
TerminalPanel::sizeHint() const
50 QSize size
= Panel::sizeHint();
55 void TerminalPanel::setUrl(const KUrl
& url
)
57 if (!url
.isValid() || (url
== Panel::url())) {
63 const bool sendInput
= (m_terminal
!= 0)
64 && (m_terminal
->foregroundProcessId() == -1)
71 void TerminalPanel::terminalExited()
73 emit
hideTerminalPanel();
77 void TerminalPanel::showEvent(QShowEvent
* event
)
79 if (event
->spontaneous()) {
80 Panel::showEvent(event
);
84 if (m_terminal
== 0) {
85 KPluginFactory
* factory
= KPluginLoader("libkonsolepart").factory();
86 KParts::ReadOnlyPart
* part
= factory
? (factory
->create
<KParts::ReadOnlyPart
>(this)) : 0;
88 connect(part
, SIGNAL(destroyed(QObject
*)), this, SLOT(terminalExited()));
89 m_terminalWidget
= part
->widget();
90 m_layout
->addWidget(m_terminalWidget
);
91 m_terminal
= qobject_cast
<TerminalInterfaceV2
*>(part
);
94 if (m_terminal
!= 0) {
95 m_terminal
->showShellInDir(url().toLocalFile());
97 m_terminal
->sendInput("clear\n"); // TODO do clear after slotMostLocalUrlResult is called, for remote dirs?
98 m_terminalWidget
->setFocus();
101 Panel::showEvent(event
);
104 void TerminalPanel::cdUrl(const KUrl
& url
)
106 if (url
.isLocalFile()) {
107 cdDirectory(url
.toLocalFile());
109 KIO::StatJob
* job
= KIO::mostLocalUrl(url
, KIO::HideProgressInfo
);
110 job
->ui()->setWindow(this);
111 connect(job
, SIGNAL(result(KJob
*)), this, SLOT(slotMostLocalUrlResult(KJob
*)));
115 void TerminalPanel::cdDirectory(const QString
& dir
)
117 m_terminal
->sendInput("cd " + KShell::quoteArg(dir
) + '\n');
120 void TerminalPanel::slotMostLocalUrlResult(KJob
* job
)
122 KIO::StatJob
* statJob
= static_cast<KIO::StatJob
*>(job
);
123 const KUrl url
= statJob
->mostLocalUrl();
124 if (url
.isLocalFile()) {
125 cdDirectory(url
.toLocalFile());
129 #include "terminalpanel.moc"