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 bool showHelpMenu:1;
00079
00080 KDEPrivate::ToolBarHandler *toolBarHandler;
00081 KToggleAction *showStatusBarAction;
00082 QPointer<KEditToolBar> toolBarEditor;
00083 KXMLGUIFactory *factory;
00084 };
00085
00086 KXmlGuiWindow::KXmlGuiWindow( QWidget* parent, Qt::WFlags f )
00087 : KMainWindow(*new KXmlGuiWindowPrivate, parent, f), KXMLGUIBuilder( this )
00088 {
00089 K_D(KXmlGuiWindow);
00090 d->showHelpMenu = true;
00091 d->toolBarHandler = 0;
00092 d->showStatusBarAction = 0;
00093 d->factory = 0;
00094 new KMainWindowInterface(this);
00095 }
00096
00097
00098 QAction *KXmlGuiWindow::toolBarMenuAction()
00099 {
00100 K_D(KXmlGuiWindow);
00101 if ( !d->toolBarHandler )
00102 return 0;
00103
00104 return d->toolBarHandler->toolBarMenuAction();
00105 }
00106
00107
00108 void KXmlGuiWindow::setupToolbarMenuActions()
00109 {
00110 K_D(KXmlGuiWindow);
00111 if ( d->toolBarHandler )
00112 d->toolBarHandler->setupActions();
00113 }
00114
00115
00116 KXmlGuiWindow::~KXmlGuiWindow()
00117 {
00118 }
00119
00120 bool KXmlGuiWindow::event( QEvent* ev )
00121 {
00122 bool ret = KMainWindow::event(ev);
00123 if (ev->type()==QEvent::Polish) {
00124 QDBusConnection::sessionBus().registerObject(dbusName() + "/actions", actionCollection(),
00125 QDBusConnection::ExportScriptableSlots |
00126 QDBusConnection::ExportScriptableProperties |
00127 QDBusConnection::ExportNonScriptableSlots |
00128 QDBusConnection::ExportNonScriptableProperties |
00129 QDBusConnection::ExportChildObjects);
00130 }
00131 return ret;
00132 }
00133
00134 void KXmlGuiWindow::setHelpMenuEnabled(bool showHelpMenu)
00135 {
00136 K_D(KXmlGuiWindow);
00137 d->showHelpMenu = showHelpMenu;
00138 }
00139
00140 bool KXmlGuiWindow::isHelpMenuEnabled() const
00141 {
00142 K_D(const KXmlGuiWindow);
00143 return d->showHelpMenu;
00144 }
00145
00146 KXMLGUIFactory *KXmlGuiWindow::guiFactory()
00147 {
00148 K_D(KXmlGuiWindow);
00149 if (!d->factory)
00150 d->factory = new KXMLGUIFactory( this, this );
00151 return d->factory;
00152 }
00153
00154 void KXmlGuiWindow::configureToolbars()
00155 {
00156 K_D(KXmlGuiWindow);
00157 KConfigGroup cg(KGlobal::config(), QString());
00158 saveMainWindowSettings(cg);
00159 if (!d->toolBarEditor) {
00160 d->toolBarEditor = new KEditToolBar(guiFactory(), this);
00161 d->toolBarEditor->setAttribute(Qt::WA_DeleteOnClose);
00162 connect(d->toolBarEditor, SIGNAL(newToolBarConfig()), SLOT(saveNewToolbarConfig()));
00163 }
00164 d->toolBarEditor->show();
00165 }
00166
00167 void KXmlGuiWindow::saveNewToolbarConfig()
00168 {
00169
00170
00171 guiFactory()->removeClient(this);
00172 guiFactory()->addClient(this);
00173
00174 KConfigGroup cg(KGlobal::config(), QString());
00175 applyMainWindowSettings(cg);
00176 }
00177
00178 void KXmlGuiWindow::setupGUI( StandardWindowOptions options, const QString & xmlfile ) {
00179 setupGUI(QSize(), options, xmlfile);
00180 }
00181
00182 void KXmlGuiWindow::setupGUI( const QSize & defaultSize, StandardWindowOptions options, const QString & xmlfile ) {
00183 if( options & Keys ){
00184 KStandardAction::keyBindings(guiFactory(),
00185 SLOT(configureShortcuts()), actionCollection());
00186 }
00187
00188 if( (options & StatusBar) && statusBar() ){
00189 createStandardStatusBarAction();
00190 }
00191
00192 if( options & ToolBar ){
00193 setStandardToolBarMenuEnabled( true );
00194 KStandardAction::configureToolbars(this,
00195 SLOT(configureToolbars() ), actionCollection());
00196 }
00197
00198 if( options & Create ){
00199 createGUI(xmlfile);
00200 }
00201
00202 if( options & Save ){
00203
00204
00205
00206
00207 if(initialGeometrySet())
00208 {
00209
00210 }
00211 else if(defaultSize.isValid())
00212 {
00213 resize(defaultSize);
00214 }
00215 else if(isHidden())
00216 {
00217 adjustSize();
00218 }
00219 setAutoSaveSettings();
00220 }
00221
00222 }
00223
00224 void KXmlGuiWindow::createGUI( const QString &xmlfile )
00225 {
00226 K_D(KXmlGuiWindow);
00227
00228
00229
00230
00231 guiFactory()->removeClient( this );
00232
00233
00234 QMenuBar* mb = menuBar();
00235 if ( mb )
00236 mb->clear();
00237
00238 qDeleteAll( toolBars() );
00239
00240
00241 if (d->showHelpMenu) {
00242 delete d->helpMenu;
00243
00244 d->helpMenu = new KHelpMenu(this, componentData().aboutData(), true, actionCollection());
00245 }
00246
00247
00248 setXMLFile(KStandardDirs::locate("config", "ui/ui_standards.rc", componentData()));
00249
00250
00251
00252 if ( !xmlfile.isNull() ) {
00253 setXMLFile( xmlfile, true );
00254 } else {
00255 QString auto_file(componentData().componentName() + "ui.rc");
00256 setXMLFile( auto_file, true );
00257 }
00258
00259
00260 setXMLGUIBuildDocument( QDomDocument() );
00261
00262
00263 guiFactory()->addClient( this );
00264
00265
00266 updateGeometry();
00267 }
00268
00269 void KXmlGuiWindow::slotStateChanged(const QString &newstate)
00270 {
00271 stateChanged(newstate, KXMLGUIClient::StateNoReverse);
00272 }
00273
00274 void KXmlGuiWindow::slotStateChanged(const QString &newstate,
00275 bool reverse)
00276 {
00277 stateChanged(newstate,
00278 reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse);
00279 }
00280
00281 void KXmlGuiWindow::setStandardToolBarMenuEnabled( bool enable )
00282 {
00283 K_D(KXmlGuiWindow);
00284 if ( enable ) {
00285 if ( d->toolBarHandler )
00286 return;
00287
00288 d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
00289
00290 if ( factory() )
00291 factory()->addClient( d->toolBarHandler );
00292 } else {
00293 if ( !d->toolBarHandler )
00294 return;
00295
00296 if ( factory() )
00297 factory()->removeClient( d->toolBarHandler );
00298
00299 delete d->toolBarHandler;
00300 d->toolBarHandler = 0;
00301 }
00302 }
00303
00304 bool KXmlGuiWindow::isStandardToolBarMenuEnabled() const
00305 {
00306 K_D(const KXmlGuiWindow);
00307 return ( d->toolBarHandler );
00308 }
00309
00310 void KXmlGuiWindow::createStandardStatusBarAction(){
00311 K_D(KXmlGuiWindow);
00312 if(!d->showStatusBarAction){
00313 d->showStatusBarAction = KStandardAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
00314 KStatusBar *sb = statusBar();
00315 connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
00316 d->showStatusBarAction->setChecked(sb->isHidden());
00317 } else {
00318
00319 KAction *tmpStatusBar = KStandardAction::showStatusbar(NULL, NULL, NULL);
00320 d->showStatusBarAction->setText(tmpStatusBar->text());
00321 d->showStatusBarAction->setWhatsThis(tmpStatusBar->whatsThis());
00322 delete tmpStatusBar;
00323 }
00324 }
00325
00326 void KXmlGuiWindow::finalizeGUI( bool )
00327 {
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 }
00343
00344 void KXmlGuiWindow::applyMainWindowSettings(const KConfigGroup &config, bool force)
00345 {
00346 K_D(KXmlGuiWindow);
00347 KMainWindow::applyMainWindowSettings(config, force);
00348 KStatusBar *sb = qFindChild<KStatusBar *>(this);
00349 if (sb && d->showStatusBarAction)
00350 d->showStatusBarAction->setChecked(!sb->isHidden());
00351 }
00352
00353
00354
00355 void KXmlGuiWindow::finalizeGUI( KXMLGUIClient *client )
00356 { KXMLGUIBuilder::finalizeGUI( client ); }
00357
00358 #include "kxmlguiwindow.moc"
00359