• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KParts

mainwindow.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, 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     if ( autoSaveSettings() )
00137         applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00138   }
00139 
00140   setUpdatesEnabled( true );
00141 
00142   d->m_activePart = part;
00143 }
00144 
00145 void MainWindow::slotSetStatusBarText( const QString & text )
00146 {
00147   statusBar()->message( text );
00148 }
00149 
00150 void MainWindow::createShellGUI( bool create )
00151 {
00152     bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
00153     assert( d->m_bShellGUIActivated != create );
00154     d->m_bShellGUIActivated = create;
00155     if ( create )
00156     {
00157         if ( isHelpMenuEnabled() && !d->m_helpMenu )
00158             d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
00159 
00160         QString f = xmlFile();
00161         setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
00162         if ( !f.isEmpty() )
00163             setXMLFile( f, true );
00164         else
00165         {
00166             QString auto_file( instance()->instanceName() + "ui.rc" );
00167             setXMLFile( auto_file, true );
00168         }
00169 
00170         GUIActivateEvent ev( true );
00171         QApplication::sendEvent( this, &ev );
00172 
00173         guiFactory()->addClient( this );
00174     }
00175     else
00176     {
00177         GUIActivateEvent ev( false );
00178         QApplication::sendEvent( this, &ev );
00179 
00180         guiFactory()->removeClient( this );
00181     }
00182     accel()->setAutoUpdate( bAccelAutoUpdate );
00183 }
00184 
00185 void KParts::MainWindow::saveNewToolbarConfig()
00186 {
00187     createGUI( d->m_activePart );
00188     applyMainWindowSettings( KGlobal::config() );
00189 }
00190 
00191 #include "mainwindow.moc"

KParts

Skip menu "KParts"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal