# kparts Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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()
    00075 {
    00076   delete d;
    00077 }
    00078
    00079 void MainWindow::createGUI( Part * part )
    00080 {
    00081   kdDebug(1000) << "MainWindow::createGUI, part=" << part << " " << ( part ? part->className() : "" )
    00082                 << " " << ( part ? part->name() : "" )
    00083                 << endl;
    00084
    00085   KXMLGUIFactory *factory = guiFactory();
    00086
    00087   assert( factory );
    00088
    00089   setUpdatesEnabled( false );
    00090
    00091   QPtrList<Plugin> plugins;
    00092
    00093   if ( d->m_activePart )
    00094   {
    00095     kdDebug(1000) << "deactivating GUI for " << d->m_activePart << " " << d->m_activePart->className()
    00096                   << " " << d->m_activePart->name() << endl;
    00097
    00098     GUIActivateEvent ev( false );
    00099     QApplication::sendEvent( d->m_activePart, &ev );
    00100
    00101     factory->removeClient( d->m_activePart );
    00102
    00103     disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
    00104              this, SLOT( setCaption( const QString & ) ) );
    00105     disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
    00106              this, SLOT( slotSetStatusBarText( const QString & ) ) );
    00107   }
    00108
    00109   if ( !d->m_bShellGUIActivated )
    00110   {
    00111     loadPlugins( this, this, KGlobal::instance() );
    00112     createShellGUI();
    00113     d->m_bShellGUIActivated = true;
    00114   }
    00115
    00116   if ( part )
    00117   {
    00118     // do this before sending the activate event
    00119     connect( part, SIGNAL( setWindowCaption( const QString & ) ),
    00120              this, SLOT( setCaption( const QString & ) ) );
    00121     connect( part, SIGNAL( setStatusBarText( const QString & ) ),
    00122              this, SLOT( slotSetStatusBarText( const QString & ) ) );
    00123
    00124     factory->addClient( part );
    00125
    00126     GUIActivateEvent ev( true );
    00127     QApplication::sendEvent( part, &ev );
    00128   }
    00129
    00130   setUpdatesEnabled( true );
    00131
    00132   d->m_activePart = part;
    00133 }
    00134
    00135 void MainWindow::slotSetStatusBarText( const QString & text )
    00136 {
    00137   statusBar()->message( text );
    00138 }
    00139
    00140 void MainWindow::createShellGUI( bool create )
    00141 {
    00142     bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
    00143     assert( d->m_bShellGUIActivated != create );
    00144     d->m_bShellGUIActivated = create;
    00145     if ( create )
    00146     {
    00147         if ( isHelpMenuEnabled() && !d->m_helpMenu )
    00148             d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
    00149
    00150         QString f = xmlFile();
    00151         setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
    00152         if ( !f.isEmpty() )
    00153             setXMLFile( f, true );
    00154         else
    00155         {
    00156             QString auto_file( instance()->instanceName() + "ui.rc" );
    00157             setXMLFile( auto_file, true );
    00158         }
    00159
    00160         GUIActivateEvent ev( true );
    00161         QApplication::sendEvent( this, &ev );
    00162
    00163         guiFactory()->addClient( this );
    00164     }
    00165     else
    00166     {
    00167         GUIActivateEvent ev( false );
    00168         QApplication::sendEvent( this, &ev );
    00169
    00170         guiFactory()->removeClient( this );
    00171     }
    00172     accel()->setAutoUpdate( bAccelAutoUpdate );
    00173 }
    00174
    00175 #include "mainwindow.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:26:50 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001