]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/terminalsidebarpage.cpp
Use a QActionGroup and save 6 slots (and the duplication of the action names in the...
[dolphin.git] / src / terminalsidebarpage.cpp
index ff410711cb540c06d891e5255cd795acb4e3ba98..4a82599f0c64d8c527c65be9dc99c6ac4fb581e8 100644 (file)
 #include <klibloader.h>
 #include <kde_terminal_interface.h>
 #include <kparts/part.h>
-#include <Part.h>
+#include <kshell.h>
 
-#include <QVBoxLayout>
+#include <QBoxLayout>
+#include <QShowEvent>
 
 TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) :
     SidebarPage(parent),
     m_layout(0),
-    m_terminal(0)
+    m_terminal(0),
+    m_terminalWidget(0)
 {
     m_layout = new QVBoxLayout(this);
     m_layout->setMargin(0);
@@ -39,34 +41,52 @@ TerminalSidebarPage::~TerminalSidebarPage()
 {
 }
 
+QSize TerminalSidebarPage::sizeHint() const
+{
+    QSize size = SidebarPage::sizeHint();
+    size.setHeight(200);
+    return size;
+}
+
 void TerminalSidebarPage::setUrl(const KUrl& url)
 {
     if (!SidebarPage::url().equals(url, KUrl::CompareWithoutTrailingSlash)) {
         SidebarPage::setUrl(url);
         if ((m_terminal != 0) && isVisible()) {
-            m_terminal->showShellInDir(url.path());
+            m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n');
         }
     }
 }
 
+void TerminalSidebarPage::terminalExited()
+{
+    emit hideTerminalSidebarPage();
+
+    m_terminal = 0;
+}
+
 void TerminalSidebarPage::showEvent(QShowEvent* event)
 {
+    if (event->spontaneous()) {
+        SidebarPage::showEvent(event);
+        return;
+    }
+
     if (m_terminal == 0) {
-        KLibFactory* factory = KLibLoader::self()->factory("libkonsolepart");
-        KParts::Part* part = static_cast<KParts::Part*>(factory->create(this, "KParts::ReadOnlyPart"));
+        KPluginFactory* factory = KPluginLoader("libkonsolepart").factory();
+        KParts::ReadOnlyPart* part = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : 0;
         if (part != 0) {
-            m_layout->addWidget(part->widget());
-
-            // TODO: in KDE3 the following code worked:
-            //     m_terminal = static_cast<TerminalInterface*>(part->qt_cast("TerminalInterface"));
-            // which does not work anymore in Qt4. As temporary workaround <konsole_part.h> is
-            // included directly:
-            m_terminal = static_cast<TerminalInterface*>(reinterpret_cast<Konsole::Part*>(part));
+            connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited()));
+            m_terminalWidget = part->widget();
+            m_layout->addWidget(m_terminalWidget);
+            m_terminal = qobject_cast<TerminalInterface *>(part);
+            m_terminal->showShellInDir(url().path());
         }
     }
     if (m_terminal != 0) {
-        m_terminal->showShellInDir(url().path());
+        m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
         m_terminal->sendInput("clear\n");
+        m_terminalWidget->setFocus();
     }
 
     SidebarPage::showEvent(event);