KDEUI
kxmlguiwindow.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "kxmlguiwindow.h"
00027 #include "kmainwindow_p.h"
00028 #include "kactioncollection.h"
00029 #include "kmainwindowiface_p.h"
00030 #include "ktoolbarhandler.h"
00031 #include "kwhatsthismanager_p.h"
00032 #include "kxmlguifactory.h"
00033 #include "kcmdlineargs.h"
00034 #include "ktoggleaction.h"
00035 #include "ksessionmanager.h"
00036 #include "kstandardaction.h"
00037
00038 #include <config.h>
00039
00040 #include <QCloseEvent>
00041 #include <QDesktopWidget>
00042 #include <QDockWidget>
00043 #include <QtXml/QDomDocument>
00044 #include <QtGui/QLayout>
00045 #include <QtCore/QObject>
00046 #include <QtGui/QSessionManager>
00047 #include <QtGui/QStyle>
00048 #include <QtCore/QTimer>
00049 #include <QtGui/QWidget>
00050 #include <QtCore/QList>
00051 #include <kaction.h>
00052 #include <kapplication.h>
00053 #include <kauthorized.h>
00054 #include <kconfig.h>
00055 #include <kdebug.h>
00056 #include <kedittoolbar.h>
00057 #include <khelpmenu.h>
00058 #include <klocale.h>
00059 #include <kmenubar.h>
00060 #include <kstandarddirs.h>
00061 #include <kstatusbar.h>
00062 #include <ktoolbar.h>
00063 #include <kwindowsystem.h>
00064 #include <kconfiggroup.h>
00065
00066 #if defined Q_WS_X11
00067 #include <qx11info_x11.h>
00068 #include <netwm.h>
00069 #include <kstartupinfo.h>
00070 #endif
00071
00072 #include <stdlib.h>
00073 #include <ctype.h>
00074 #include <assert.h>
00075
00076 class KXmlGuiWindowPrivate : public KMainWindowPrivate {
00077 public:
00078 void _k_slotFactoryMakingChanges(bool b)
00079 {
00080
00081
00082
00083 letDirtySettings = !b;
00084 }
00085
00086 bool showHelpMenu:1;
00087 bool saveFlag:1;
00088 QSize defaultSize;
00089
00090 KDEPrivate::ToolBarHandler *toolBarHandler;
00091 KToggleAction *showStatusBarAction;
00092 QPointer<KEditToolBar> toolBarEditor;
00093 KXMLGUIFactory *factory;
00094 };
00095
00096 KXmlGuiWindow::KXmlGuiWindow( QWidget* parent, Qt::WFlags f )
00097 : KMainWindow(*new KXmlGuiWindowPrivate, parent, f), KXMLGUIBuilder( this )
00098 {
00099 K_D(KXmlGuiWindow);
00100 d->showHelpMenu = true;
00101 d->saveFlag = false;
00102 d->toolBarHandler = 0;
00103 d->showStatusBarAction = 0;
00104 d->factory = 0;
00105 new KMainWindowInterface(this);
00106 }
00107
00108
00109 QAction *KXmlGuiWindow::toolBarMenuAction()
00110 {
00111 K_D(KXmlGuiWindow);
00112 if ( !d->toolBarHandler )
00113 return 0;
00114
00115 return d->toolBarHandler->toolBarMenuAction();
00116 }
00117
00118
00119 void KXmlGuiWindow::setupToolbarMenuActions()
00120 {
00121 K_D(KXmlGuiWindow);
00122 if ( d->toolBarHandler )
00123 d->toolBarHandler->setupActions();
00124 }
00125
00126
00127 KXmlGuiWindow::~KXmlGuiWindow()
00128 {
00129 }
00130
00131 bool KXmlGuiWindow::event( QEvent* ev )
00132 {
00133 bool ret = KMainWindow::event(ev);
00134 if (ev->type()==QEvent::Polish) {
00135 QDBusConnection::sessionBus().registerObject(dbusName() + "/actions", actionCollection(),
00136 QDBusConnection::ExportScriptableSlots |
00137 QDBusConnection::ExportScriptableProperties |
00138 QDBusConnection::ExportNonScriptableSlots |
00139 QDBusConnection::ExportNonScriptableProperties |
00140 QDBusConnection::ExportChildObjects);
00141 }
00142 return ret;
00143 }
00144
00145 void KXmlGuiWindow::setHelpMenuEnabled(bool showHelpMenu)
00146 {
00147 K_D(KXmlGuiWindow);
00148 d->showHelpMenu = showHelpMenu;
00149 }
00150
00151 bool KXmlGuiWindow::isHelpMenuEnabled() const
00152 {
00153 K_D(const KXmlGuiWindow);
00154 return d->showHelpMenu;
00155 }
00156
00157 KXMLGUIFactory *KXmlGuiWindow::guiFactory()
00158 {
00159 K_D(KXmlGuiWindow);
00160 if (!d->factory) {
00161 d->factory = new KXMLGUIFactory( this, this );
00162 connect(d->factory, SIGNAL(makingChanges(bool)),
00163 this, SLOT(_k_slotFactoryMakingChanges(bool)));
00164 }
00165 return d->factory;
00166 }
00167
00168 void KXmlGuiWindow::configureToolbars()
00169 {
00170 K_D(KXmlGuiWindow);
00171 KConfigGroup cg(KGlobal::config(), QString());
00172 saveMainWindowSettings(cg);
00173 if (!d->toolBarEditor) {
00174 d->toolBarEditor = new KEditToolBar(guiFactory(), this);
00175 d->toolBarEditor->setAttribute(Qt::WA_DeleteOnClose);
00176 connect(d->toolBarEditor, SIGNAL(newToolBarConfig()), SLOT(saveNewToolbarConfig()));
00177 }
00178 d->toolBarEditor->show();
00179 }
00180
00181 void KXmlGuiWindow::saveNewToolbarConfig()
00182 {
00183
00184
00185 guiFactory()->removeClient(this);
00186 guiFactory()->addClient(this);
00187
00188 KConfigGroup cg(KGlobal::config(), QString());
00189 applyMainWindowSettings(cg);
00190 }
00191
00192 void KXmlGuiWindow::setupGUI( StandardWindowOptions options, const QString & xmlfile ) {
00193 setupGUI(QSize(), options, xmlfile);
00194 }
00195
00196 void KXmlGuiWindow::setupGUI( const QSize & defaultSize, StandardWindowOptions options, const QString & xmlfile ) {
00197 K_D(KXmlGuiWindow);
00198
00199 if( options & Keys ){
00200 KStandardAction::keyBindings(guiFactory(),
00201 SLOT(configureShortcuts()), actionCollection());
00202 }
00203
00204 if( (options & StatusBar) && statusBar() ){
00205 createStandardStatusBarAction();
00206 }
00207
00208 if( options & ToolBar ){
00209 setStandardToolBarMenuEnabled( true );
00210 KStandardAction::configureToolbars(this,
00211 SLOT(configureToolbars() ), actionCollection());
00212 }
00213
00214 d->saveFlag = bool(options & Save);
00215 d->defaultSize = defaultSize;
00216
00217 if( options & Create ){
00218 createGUI(xmlfile);
00219 }
00220 }
00221 void KXmlGuiWindow::createGUI( const QString &xmlfile )
00222 {
00223 K_D(KXmlGuiWindow);
00224
00225
00226
00227
00228 guiFactory()->removeClient( this );
00229
00230
00231 QMenuBar* mb = menuBar();
00232 if ( mb )
00233 mb->clear();
00234
00235 qDeleteAll( toolBars() );
00236
00237
00238 if (d->showHelpMenu) {
00239 delete d->helpMenu;
00240
00241 d->helpMenu = new KHelpMenu(this, componentData().aboutData(), true, actionCollection());
00242 }
00243
00244
00245 setXMLFile(KStandardDirs::locate("config", "ui/ui_standards.rc", componentData()));
00246
00247
00248
00249 if ( !xmlfile.isNull() ) {
00250 setXMLFile( xmlfile, true );
00251 } else {
00252 QString auto_file(componentData().componentName() + "ui.rc");
00253 setXMLFile( auto_file, true );
00254 }
00255
00256
00257 setXMLGUIBuildDocument( QDomDocument() );
00258
00259
00260 guiFactory()->addClient( this );
00261
00262
00263 }
00264
00265 void KXmlGuiWindow::slotStateChanged(const QString &newstate)
00266 {
00267 stateChanged(newstate, KXMLGUIClient::StateNoReverse);
00268 }
00269
00270 void KXmlGuiWindow::slotStateChanged(const QString &newstate,
00271 bool reverse)
00272 {
00273 stateChanged(newstate,
00274 reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse);
00275 }
00276
00277 void KXmlGuiWindow::setStandardToolBarMenuEnabled( bool enable )
00278 {
00279 K_D(KXmlGuiWindow);
00280 if ( enable ) {
00281 if ( d->toolBarHandler )
00282 return;
00283
00284 d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
00285
00286 if ( factory() )
00287 factory()->addClient( d->toolBarHandler );
00288 } else {
00289 if ( !d->toolBarHandler )
00290 return;
00291
00292 if ( factory() )
00293 factory()->removeClient( d->toolBarHandler );
00294
00295 delete d->toolBarHandler;
00296 d->toolBarHandler = 0;
00297 }
00298 }
00299
00300 bool KXmlGuiWindow::isStandardToolBarMenuEnabled() const
00301 {
00302 K_D(const KXmlGuiWindow);
00303 return ( d->toolBarHandler );
00304 }
00305
00306 void KXmlGuiWindow::createStandardStatusBarAction(){
00307 K_D(KXmlGuiWindow);
00308 if(!d->showStatusBarAction){
00309 d->showStatusBarAction = KStandardAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
00310 KStatusBar *sb = statusBar();
00311 connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
00312 d->showStatusBarAction->setChecked(sb->isHidden());
00313 } else {
00314
00315 KAction *tmpStatusBar = KStandardAction::showStatusbar(NULL, NULL, NULL);
00316 d->showStatusBarAction->setText(tmpStatusBar->text());
00317 d->showStatusBarAction->setWhatsThis(tmpStatusBar->whatsThis());
00318 delete tmpStatusBar;
00319 }
00320 }
00321
00322 void KXmlGuiWindow::finalizeGUI( bool )
00323 {
00324 K_D(KXmlGuiWindow);
00325
00326 if (d->saveFlag) {
00327 if (initialGeometrySet()) {
00328
00329 }
00330 else if (d->defaultSize.isValid()) {
00331 resize(d->defaultSize);
00332 }
00333 else if (isHidden()) {
00334 adjustSize();
00335 }
00336 setAutoSaveSettings();
00337
00338
00339 d->saveFlag = false;
00340 return;
00341
00342 }
00343
00344
00345
00346
00347
00348 if (autoSaveSettings() && autoSaveConfigGroup().isValid()) {
00349 applyMainWindowSettings(autoSaveConfigGroup());
00350 }
00351
00352 }
00353
00354 void KXmlGuiWindow::applyMainWindowSettings(const KConfigGroup &config, bool force)
00355 {
00356 K_D(KXmlGuiWindow);
00357 KMainWindow::applyMainWindowSettings(config, force);
00358 KStatusBar *sb = qFindChild<KStatusBar *>(this);
00359 if (sb && d->showStatusBarAction)
00360 d->showStatusBarAction->setChecked(!sb->isHidden());
00361 }
00362
00363
00364
00365 void KXmlGuiWindow::finalizeGUI( KXMLGUIClient *client )
00366 { KXMLGUIBuilder::finalizeGUI( client ); }
00367
00368 #include "kxmlguiwindow.moc"
00369