KParts
dockmainwindow.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kparts/dockmainwindow.h>
00023 #include <kparts/event.h>
00024 #include <kparts/part.h>
00025 #include <kaccel.h>
00026 #include <kparts/plugin.h>
00027 #include <kstatusbar.h>
00028 #include <kinstance.h>
00029 #include <khelpmenu.h>
00030 #include <kstandarddirs.h>
00031 #include <qapplication.h>
00032
00033 #include <kdebug.h>
00034 #include <kxmlguifactory.h>
00035
00036 #include <assert.h>
00037
00038 using namespace KParts;
00039
00040 namespace KParts
00041 {
00042 class DockMainWindowPrivate
00043 {
00044 public:
00045 DockMainWindowPrivate()
00046 {
00047 m_activePart = 0;
00048 m_bShellGUIActivated = false;
00049 m_helpMenu = 0;
00050 }
00051 ~DockMainWindowPrivate()
00052 {
00053 }
00054
00055 QGuardedPtr<Part> m_activePart;
00056 bool m_bShellGUIActivated;
00057 KHelpMenu *m_helpMenu;
00058 };
00059 }
00060
00061 DockMainWindow::DockMainWindow( QWidget* parent, const char *name, WFlags f )
00062 : KDockMainWindow( parent, name, f )
00063 {
00064 d = new DockMainWindowPrivate();
00065 PartBase::setPartObject( this );
00066 }
00067
00068 DockMainWindow::~DockMainWindow()
00069 {
00070 delete d;
00071 }
00072
00073 void DockMainWindow::createGUI( Part * part )
00074 {
00075 kdDebug(1000) << QString("DockMainWindow::createGUI for %1").arg(part?part->name():"0L") << endl;
00076
00077 KXMLGUIFactory *factory = guiFactory();
00078
00079 setUpdatesEnabled( false );
00080
00081 QPtrList<Plugin> plugins;
00082
00083 if ( d->m_activePart )
00084 {
00085 kdDebug(1000) << QString("deactivating GUI for %1").arg(d->m_activePart->name()) << endl;
00086
00087 GUIActivateEvent ev( false );
00088 QApplication::sendEvent( d->m_activePart, &ev );
00089
00090 factory->removeClient( d->m_activePart );
00091
00092 disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
00093 this, SLOT( setCaption( const QString & ) ) );
00094 disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
00095 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00096 }
00097
00098 if ( !d->m_bShellGUIActivated )
00099 {
00100 loadPlugins( this, this, KGlobal::instance() );
00101 createShellGUI();
00102 d->m_bShellGUIActivated = true;
00103 }
00104
00105 if ( part )
00106 {
00107
00108 connect( part, SIGNAL( setWindowCaption( const QString & ) ),
00109 this, SLOT( setCaption( const QString & ) ) );
00110 connect( part, SIGNAL( setStatusBarText( const QString & ) ),
00111 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00112
00113 factory->addClient( part );
00114
00115 GUIActivateEvent ev( true );
00116 QApplication::sendEvent( part, &ev );
00117
00118 }
00119
00120 setUpdatesEnabled( true );
00121
00122 d->m_activePart = part;
00123 }
00124
00125 void DockMainWindow::slotSetStatusBarText( const QString & text )
00126 {
00127 statusBar()->message( text );
00128 }
00129
00130 void DockMainWindow::createShellGUI( bool create )
00131 {
00132 bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
00133 assert( d->m_bShellGUIActivated != create );
00134 d->m_bShellGUIActivated = create;
00135 if ( create )
00136 {
00137 if ( isHelpMenuEnabled() )
00138 d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
00139
00140 QString f = xmlFile();
00141 setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
00142 if ( !f.isEmpty() )
00143 setXMLFile( f, true );
00144 else
00145 {
00146 QString auto_file( instance()->instanceName() + "ui.rc" );
00147 setXMLFile( auto_file, true );
00148 }
00149
00150 GUIActivateEvent ev( true );
00151 QApplication::sendEvent( this, &ev );
00152
00153 guiFactory()->addClient( this );
00154
00155 }
00156 else
00157 {
00158 GUIActivateEvent ev( false );
00159 QApplication::sendEvent( this, &ev );
00160
00161 guiFactory()->removeClient( this );
00162 }
00163 accel()->setAutoUpdate( bAccelAutoUpdate );
00164 }
00165
00166 #include "dockmainwindow.moc"