parts/konsole/konsoleviewwidget.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2003 by KDevelop Authors * 00003 * kdevelop-devel@kde.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include <qlayout.h> 00013 #include <qframe.h> 00014 #include <qdir.h> 00015 00016 #include <kparts/part.h> 00017 #include <klibloader.h> 00018 #include <kurl.h> 00019 #include <kdebug.h> 00020 00021 #include "kdevcore.h" 00022 #include "kdevproject.h" 00023 #include "konsoleviewpart.h" 00024 #include "kdevpartcontroller.h" 00025 00026 #include "konsoleviewpart.h" 00027 #include "konsoleviewwidget.h" 00028 00029 KonsoleViewWidget::KonsoleViewWidget(KonsoleViewPart *part) 00030 : QWidget(0, "konsole widget"), part(0), owner( part ) 00031 { 00032 connect(part->partController(), SIGNAL(activePartChanged(KParts::Part*)), this, SLOT(activePartChanged(KParts::Part*))); 00033 vbox = new QVBoxLayout(this); 00034 } 00035 00036 KonsoleViewWidget::~KonsoleViewWidget() 00037 { 00038 } 00039 00040 void KonsoleViewWidget::show() 00041 { 00042 activate(); 00043 QWidget::show(); 00044 } 00045 00046 void KonsoleViewWidget::activate() 00047 { 00048 if (part) 00049 return; 00050 00051 KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart"); 00052 if (!factory) 00053 return; 00054 00055 part = (KParts::ReadOnlyPart *) factory->create(this); 00056 if (!part) 00057 return; 00058 00059 part->widget()->setFocusPolicy(QWidget::WheelFocus); 00060 setFocusProxy(part->widget()); 00061 part->widget()->setFocus(); 00062 00063 if (part->widget()->inherits("QFrame")) 00064 ((QFrame*)part->widget())->setFrameStyle(QFrame::Panel|QFrame::Sunken); 00065 00066 vbox->addWidget(part->widget()); 00067 00068 // this->activePartChanged( owner->partController()->activePart() ); 00069 part->widget()->show(); 00070 00071 connect(part, SIGNAL(destroyed()), this, SLOT(partDestroyed())); 00072 } 00073 00074 00075 void KonsoleViewWidget::activePartChanged(KParts::Part *activatedPart) 00076 { 00077 kdDebug() << "KonsoleViewWidget::activePartChanged()" << endl; 00078 KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(activatedPart); 00079 00080 if (ro_part && !ro_part->url().isLocalFile()) 00081 { 00082 kdDebug() << " ===> Hmmm ... part is null or not local ... :-/" << endl; 00083 return; 00084 } 00085 QString dir; 00086 if (ro_part) 00087 dir = ro_part->url().directory(); 00088 else if (owner->project()) 00089 dir = owner->project()->projectDirectory(); 00090 00091 kdDebug() << " ===> Changing dir to " << dir << endl; 00092 if (dir.isEmpty()) 00093 return; 00094 setDirectory( KURL(dir) ); 00095 } 00096 00097 void KonsoleViewWidget::setDirectory(const KURL &dirUrl) 00098 { 00099 kdDebug() << "KonsoleViewWidget::setDirectory()" << endl; 00100 kdDebug() << " ===> part is " << (long)part << endl; 00101 00102 if (part && dirUrl != part->url()) 00103 { 00104 kdDebug() << " ===> Changing dirUrl.path() == " << dirUrl.path() << endl; 00105 kdDebug() << " ===> Changing part->url.path() == " << part->url().path() << endl; 00106 00107 part->openURL( dirUrl ); 00108 } 00109 } 00110 00111 void KonsoleViewWidget::partDestroyed() 00112 { 00113 part = 0; 00114 activate(); 00115 } 00116 00117 00118 #include "konsoleviewwidget.moc"