kparts Library API Documentation

mainwindow.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
00003              (C) 1999 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <kparts/mainwindow.h>
00022 #include <kparts/event.h>
00023 #include <kparts/part.h>
00024 #include <kparts/plugin.h>
00025 #include <kinstance.h>
00026 #include <kstatusbar.h>
00027 #include <khelpmenu.h>
00028 #include <kstandarddirs.h>
00029 #include <qapplication.h>
00030 #include <kxmlguifactory.h>
00031 
00032 #include <kaccel.h>
00033 #include <kdebug.h>
00034 
00035 #include <assert.h>
00036 
00037 using namespace KParts;
00038 
00039 namespace KParts
00040 {
00041 class MainWindowPrivate
00042 {
00043 public:
00044   MainWindowPrivate()
00045   {
00046     m_activePart = 0;
00047     m_bShellGUIActivated = false;
00048     m_helpMenu = 0;
00049   }
00050   ~MainWindowPrivate()
00051   {
00052   }
00053 
00054   QGuardedPtr<Part> m_activePart;
00055   bool m_bShellGUIActivated;
00056   KHelpMenu *m_helpMenu;
00057 };
00058 }
00059 
00060 MainWindow::MainWindow( QWidget* parent,  const char *name, WFlags f )
00061     : KMainWindow( parent, name, f )
00062 {
00063   d = new MainWindowPrivate();
00064   PartBase::setPartObject( this );
00065 }
00066 
00067 MainWindow::MainWindow( const char *name, WFlags f )
00068   : KMainWindow( 0L, name, f )
00069 {
00070   d = new MainWindowPrivate();
00071   PartBase::setPartObject( this );
00072 }
00073 
00074 MainWindow::MainWindow( int cflags, QWidget* parent,  const char *name, WFlags f )
00075     : KMainWindow( cflags, parent, name, f )
00076 {
00077   d = new MainWindowPrivate();
00078   PartBase::setPartObject( this );
00079 }
00080 
00081 MainWindow::~MainWindow()
00082 {
00083   delete d;
00084 }
00085 
00086 void MainWindow::createGUI( Part * part )
00087 {
00088   kdDebug(1000) << "MainWindow::createGUI, part=" << part << " " << ( part ? part->className() : "" )
00089                 << " " << ( part ? part->name() : "" )
00090                 << endl;
00091 
00092   KXMLGUIFactory *factory = guiFactory();
00093 
00094   assert( factory );
00095 
00096   setUpdatesEnabled( false );
00097 
00098   QPtrList<Plugin> plugins;
00099 
00100   if ( d->m_activePart )
00101   {
00102     kdDebug(1000) << "deactivating GUI for " << d->m_activePart << " " << d->m_activePart->className()
00103                   << " " << d->m_activePart->name() << endl;
00104 
00105     GUIActivateEvent ev( false );
00106     QApplication::sendEvent( d->m_activePart, &ev );
00107 
00108     factory->removeClient( d->m_activePart );
00109 
00110     disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
00111              this, SLOT( setCaption( const QString & ) ) );
00112     disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
00113              this, SLOT( slotSetStatusBarText( const QString & ) ) );
00114   }
00115 
00116   if ( !d->m_bShellGUIActivated )
00117   {
00118     loadPlugins( this, this, KGlobal::instance() );
00119     createShellGUI();
00120     d->m_bShellGUIActivated = true;
00121   }
00122 
00123   if ( part )
00124   {
00125     // do this before sending the activate event
00126     connect( part, SIGNAL( setWindowCaption( const QString & ) ),
00127              this, SLOT( setCaption( const QString & ) ) );
00128     connect( part, SIGNAL( setStatusBarText( const QString & ) ),
00129              this, SLOT( slotSetStatusBarText( const QString & ) ) );
00130 
00131     factory->addClient( part );
00132 
00133     GUIActivateEvent ev( true );
00134     QApplication::sendEvent( part, &ev );
00135   }
00136 
00137   setUpdatesEnabled( true );
00138 
00139   d->m_activePart = part;
00140 }
00141 
00142 void MainWindow::slotSetStatusBarText( const QString & text )
00143 {
00144   statusBar()->message( text );
00145 }
00146 
00147 void MainWindow::createShellGUI( bool create )
00148 {
00149     bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
00150     assert( d->m_bShellGUIActivated != create );
00151     d->m_bShellGUIActivated = create;
00152     if ( create )
00153     {
00154         if ( isHelpMenuEnabled() && !d->m_helpMenu )
00155             d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
00156 
00157         QString f = xmlFile();
00158         setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
00159         if ( !f.isEmpty() )
00160             setXMLFile( f, true );
00161         else
00162         {
00163             QString auto_file( instance()->instanceName() + "ui.rc" );
00164             setXMLFile( auto_file, true );
00165         }
00166 
00167         GUIActivateEvent ev( true );
00168         QApplication::sendEvent( this, &ev );
00169 
00170         guiFactory()->addClient( this );
00171     }
00172     else
00173     {
00174         GUIActivateEvent ev( false );
00175         QApplication::sendEvent( this, &ev );
00176 
00177         guiFactory()->removeClient( this );
00178     }
00179     accel()->setAutoUpdate( bAccelAutoUpdate );
00180 }
00181 
00182 #include "mainwindow.moc"
KDE Logo
This file is part of the documentation for kparts Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 4 22:44:46 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003