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> |
4 | |
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. |
9 | |
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. |
14 | |
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. |
19 | */ |
20 | |
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> |
33 | |
34 | #include <kdebug.h> |
35 | |
36 | #include <assert.h> |
37 | |
38 | using namespace KParts; |
39 | |
40 | namespace KParts |
41 | { |
42 | class MainWindowPrivate |
43 | { |
44 | public: |
45 | MainWindowPrivate() |
46 | : m_activePart(0), |
47 | m_bShellGUIActivated(false), |
48 | m_helpMenu(0) |
49 | { |
50 | } |
51 | ~MainWindowPrivate() |
52 | { |
53 | } |
54 | |
55 | QPointer<Part> m_activePart; |
56 | bool m_bShellGUIActivated; |
57 | KHelpMenu *m_helpMenu; |
58 | }; |
59 | } |
60 | |
61 | MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f ) |
62 | : KXmlGuiWindow( parent, f ), d(new MainWindowPrivate()) |
63 | { |
64 | PartBase::setPartObject( this ); |
65 | } |
66 | |
67 | #ifndef KDE_NO_DEPRECATED |
68 | MainWindow::MainWindow( QWidget* parent, const char *name, Qt::WindowFlags f ) |
69 | : KXmlGuiWindow( parent, f ),d(new MainWindowPrivate()) |
70 | { |
71 | setObjectName( name ); |
72 | PartBase::setPartObject( this ); |
73 | } |
74 | #endif |
75 | |
76 | MainWindow::~MainWindow() |
77 | { |
78 | delete d; |
79 | } |
80 | |
81 | void MainWindow::createGUI( Part * part ) |
82 | { |
83 | #if 0 |
84 | kDebug(1000) << "part=" << part |
85 | << ( part ? part->metaObject()->className() : "" ) |
86 | << ( part ? part->objectName() : "" ); |
87 | #endif |
88 | KXMLGUIFactory *factory = guiFactory(); |
89 | |
90 | assert( factory ); |
91 | |
92 | if ( d->m_activePart ) |
93 | { |
94 | #if 0 |
95 | kDebug(1000) << "deactivating GUI for" << d->m_activePart |
96 | << d->m_activePart->metaObject()->className() |
97 | << d->m_activePart->objectName(); |
98 | #endif |
99 | |
100 | GUIActivateEvent ev( false ); |
101 | QApplication::sendEvent( d->m_activePart, &ev ); |
102 | |
103 | factory->removeClient( d->m_activePart ); |
104 | |
105 | disconnect( d->m_activePart, SIGNAL(setWindowCaption(QString)), |
106 | this, SLOT(setCaption(QString)) ); |
107 | disconnect( d->m_activePart, SIGNAL(setStatusBarText(QString)), |
108 | this, SLOT(slotSetStatusBarText(QString)) ); |
109 | } |
110 | |
111 | if ( !d->m_bShellGUIActivated ) |
112 | { |
113 | loadPlugins( this, this, KGlobal::mainComponent() ); |
114 | createShellGUI(); |
115 | d->m_bShellGUIActivated = true; |
116 | } |
117 | |
118 | if ( part ) |
119 | { |
120 | // do this before sending the activate event |
121 | connect( part, SIGNAL(setWindowCaption(QString)), |
122 | this, SLOT(setCaption(QString)) ); |
123 | connect( part, SIGNAL(setStatusBarText(QString)), |
124 | this, SLOT(slotSetStatusBarText(QString)) ); |
125 | |
126 | factory->addClient( part ); |
127 | |
128 | GUIActivateEvent ev( true ); |
129 | QApplication::sendEvent( part, &ev ); |
130 | } |
131 | |
132 | d->m_activePart = part; |
133 | } |
134 | |
135 | void MainWindow::slotSetStatusBarText( const QString & text ) |
136 | { |
137 | statusBar()->showMessage( text ); |
138 | } |
139 | |
140 | void MainWindow::createShellGUI( bool create ) |
141 | { |
142 | assert( d->m_bShellGUIActivated != create ); |
143 | d->m_bShellGUIActivated = create; |
144 | if ( create ) |
145 | { |
146 | if ( isHelpMenuEnabled() && !d->m_helpMenu ) |
147 | d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() ); |
148 | |
149 | QString f = xmlFile(); |
150 | setXMLFile( KStandardDirs::locate( "config" , "ui/ui_standards.rc" , componentData() ) ); |
151 | if ( !f.isEmpty() ) |
152 | setXMLFile( f, true ); |
153 | else |
154 | { |
155 | QString auto_file( componentData().componentName() + "ui.rc" ); |
156 | setXMLFile( auto_file, true ); |
157 | } |
158 | |
159 | GUIActivateEvent ev( true ); |
160 | QApplication::sendEvent( this, &ev ); |
161 | |
162 | guiFactory()->addClient( this ); |
163 | } |
164 | else |
165 | { |
166 | GUIActivateEvent ev( false ); |
167 | QApplication::sendEvent( this, &ev ); |
168 | |
169 | guiFactory()->removeClient( this ); |
170 | } |
171 | } |
172 | |
173 | void KParts::MainWindow::saveNewToolbarConfig() |
174 | { |
175 | createGUI(d->m_activePart); |
176 | KConfigGroup cg(KGlobal::config(), QString()); |
177 | applyMainWindowSettings(cg); |
178 | } |
179 | |
180 | void KParts::MainWindow::configureToolbars() |
181 | { |
182 | // No difference with base class anymore. |
183 | KXmlGuiWindow::configureToolbars(); |
184 | } |
185 | |
186 | #include "mainwindow.moc" |
187 | |