some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / kparts / mainwindow.cpp
blob4642270c04cd24bb226348042003f7225aa39f0b
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>
34 #include <kdebug.h>
36 #include <assert.h>
38 using namespace KParts;
40 namespace KParts
42 class MainWindowPrivate
44 public:
45 MainWindowPrivate()
46 : m_activePart(0),
47 m_bShellGUIActivated(false),
48 m_helpMenu(0)
51 ~MainWindowPrivate()
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()
76 delete d;
79 void MainWindow::createGUI( Part * part )
81 #if 0
82 kDebug(1000) << "part=" << part
83 << ( part ? part->metaObject()->className() : "" )
84 << ( part ? part->objectName() : "" );
85 #endif
86 KXMLGUIFactory *factory = guiFactory();
88 assert( factory );
90 if ( d->m_activePart )
92 #if 0
93 kDebug(1000) << "deactivating GUI for" << d->m_activePart
94 << d->m_activePart->metaObject()->className()
95 << d->m_activePart->objectName();
96 #endif
98 GUIActivateEvent ev( false );
99 QApplication::sendEvent( d->m_activePart, &ev );
101 factory->removeClient( d->m_activePart );
103 disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
104 this, SLOT( setCaption( const QString & ) ) );
105 disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
106 this, SLOT( slotSetStatusBarText( const QString & ) ) );
109 if ( !d->m_bShellGUIActivated )
111 loadPlugins( this, this, KGlobal::mainComponent() );
112 createShellGUI();
113 d->m_bShellGUIActivated = true;
116 if ( part )
118 // do this before sending the activate event
119 connect( part, SIGNAL( setWindowCaption( const QString & ) ),
120 this, SLOT( setCaption( const QString & ) ) );
121 connect( part, SIGNAL( setStatusBarText( const QString & ) ),
122 this, SLOT( slotSetStatusBarText( const QString & ) ) );
124 factory->addClient( part );
126 GUIActivateEvent ev( true );
127 QApplication::sendEvent( part, &ev );
130 d->m_activePart = part;
133 void MainWindow::slotSetStatusBarText( const QString & text )
135 statusBar()->showMessage( text );
138 void MainWindow::createShellGUI( bool create )
140 assert( d->m_bShellGUIActivated != create );
141 d->m_bShellGUIActivated = create;
142 if ( create )
144 if ( isHelpMenuEnabled() && !d->m_helpMenu )
145 d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
147 QString f = xmlFile();
148 setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
149 if ( !f.isEmpty() )
150 setXMLFile( f, true );
151 else
153 QString auto_file( componentData().componentName() + "ui.rc" );
154 setXMLFile( auto_file, true );
157 GUIActivateEvent ev( true );
158 QApplication::sendEvent( this, &ev );
160 guiFactory()->addClient( this );
162 else
164 GUIActivateEvent ev( false );
165 QApplication::sendEvent( this, &ev );
167 guiFactory()->removeClient( this );
171 void KParts::MainWindow::saveNewToolbarConfig()
173 createGUI(d->m_activePart);
174 KConfigGroup cg(KGlobal::config(), QString());
175 applyMainWindowSettings(cg);
178 void KParts::MainWindow::configureToolbars()
180 // No difference with base class anymore.
181 KXmlGuiWindow::configureToolbars();
184 #include "mainwindow.moc"