1 /* This file is part of the KDE project
2 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 (C) 1999 David Faure <faure@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "mainwindow.h"
22 #include <kedittoolbar.h>
23 #include <kparts/event.h>
24 #include <kparts/part.h>
25 #include <kparts/plugin.h>
26 #include <kcomponentdata.h>
27 #include <kstatusbar.h>
28 #include <khelpmenu.h>
29 #include <kstandarddirs.h>
30 #include <QtGui/QApplication>
31 #include <kxmlguifactory.h>
32 #include <kconfiggroup.h>
38 using namespace KParts
;
42 class MainWindowPrivate
47 m_bShellGUIActivated(false),
55 QPointer
<Part
> m_activePart
;
56 bool m_bShellGUIActivated
;
57 KHelpMenu
*m_helpMenu
;
61 MainWindow::MainWindow( QWidget
* parent
, Qt::WindowFlags f
)
62 : KXmlGuiWindow( parent
, f
), d(new MainWindowPrivate())
64 PartBase::setPartObject( this );
67 MainWindow::MainWindow( QWidget
* parent
, const char *name
, Qt::WindowFlags f
)
68 : KXmlGuiWindow( parent
, f
),d(new MainWindowPrivate())
70 setObjectName( name
);
71 PartBase::setPartObject( this );
74 MainWindow::~MainWindow()
79 void MainWindow::createGUI( Part
* part
)
81 kDebug(1000) << "MainWindow::createGUI, part=" << part
<< " "
82 << ( part
? part
->metaObject()->className() : "" )
83 << " " << ( part
? part
->objectName() : "" )
86 KXMLGUIFactory
*factory
= guiFactory();
90 if ( d
->m_activePart
)
92 kDebug(1000) << "deactivating GUI for " << d
->m_activePart
<< " "
93 << d
->m_activePart
->metaObject()->className()
94 << " " << d
->m_activePart
->objectName() << endl
;
96 GUIActivateEvent
ev( false );
97 QApplication::sendEvent( d
->m_activePart
, &ev
);
99 factory
->removeClient( d
->m_activePart
);
101 disconnect( d
->m_activePart
, SIGNAL( setWindowCaption( const QString
& ) ),
102 this, SLOT( setCaption( const QString
& ) ) );
103 disconnect( d
->m_activePart
, SIGNAL( setStatusBarText( const QString
& ) ),
104 this, SLOT( slotSetStatusBarText( const QString
& ) ) );
107 if ( !d
->m_bShellGUIActivated
)
109 loadPlugins( this, this, KGlobal::mainComponent() );
111 d
->m_bShellGUIActivated
= true;
116 // do this before sending the activate event
117 connect( part
, SIGNAL( setWindowCaption( const QString
& ) ),
118 this, SLOT( setCaption( const QString
& ) ) );
119 connect( part
, SIGNAL( setStatusBarText( const QString
& ) ),
120 this, SLOT( slotSetStatusBarText( const QString
& ) ) );
122 factory
->addClient( part
);
124 GUIActivateEvent
ev( true );
125 QApplication::sendEvent( part
, &ev
);
128 d
->m_activePart
= part
;
131 void MainWindow::slotSetStatusBarText( const QString
& text
)
133 statusBar()->showMessage( text
);
136 void MainWindow::createShellGUI( bool create
)
138 assert( d
->m_bShellGUIActivated
!= create
);
139 d
->m_bShellGUIActivated
= create
;
142 if ( isHelpMenuEnabled() && !d
->m_helpMenu
)
143 d
->m_helpMenu
= new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
145 QString f
= xmlFile();
146 setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
148 setXMLFile( f
, true );
151 QString
auto_file( componentData().componentName() + "ui.rc" );
152 setXMLFile( auto_file
, true );
155 GUIActivateEvent
ev( true );
156 QApplication::sendEvent( this, &ev
);
158 guiFactory()->addClient( this );
162 GUIActivateEvent
ev( false );
163 QApplication::sendEvent( this, &ev
);
165 guiFactory()->removeClient( this );
169 void KParts::MainWindow::saveNewToolbarConfig()
171 createGUI(d
->m_activePart
);
172 KConfigGroup
cg(KGlobal::config(), QString());
173 applyMainWindowSettings(cg
);
176 void KParts::MainWindow::configureToolbars()
178 // No difference with base class anymore.
179 KXmlGuiWindow::configureToolbars();
182 #include "mainwindow.moc"