• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kxmlguiwindow.cpp

Go to the documentation of this file.
00001  /* This file is part of the KDE libraries
00002      Copyright
00003      (C) 2000 Reginald Stadlbauer (reggie@kde.org)
00004      (C) 1997 Stephan Kulow (coolo@kde.org)
00005      (C) 1997-2000 Sven Radej (radej@kde.org)
00006      (C) 1997-2000 Matthias Ettrich (ettrich@kde.org)
00007      (C) 1999 Chris Schlaeger (cs@kde.org)
00008      (C) 2002 Joseph Wenninger (jowenn@kde.org)
00009      (C) 2005-2006 Hamish Rodda (rodda@kde.org)
00010 
00011      This library is free software; you can redistribute it and/or
00012      modify it under the terms of the GNU Library General Public
00013      License version 2 as published by the Free Software Foundation.
00014 
00015      This library is distributed in the hope that it will be useful,
00016      but WITHOUT ANY WARRANTY; without even the implied warranty of
00017      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018      Library General Public License for more details.
00019 
00020      You should have received a copy of the GNU Library General Public License
00021      along with this library; see the file COPYING.LIB.  If not, write to
00022      the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023      Boston, MA 02110-1301, USA.
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         // While the GUI factory is adding/removing clients,
00081         // don't let KMainWindow think those are changes made by the user
00082         // #105525
00083         letDirtySettings = !b;
00084     }
00085 
00086     bool showHelpMenu:1;
00087     QSize defaultSize;
00088 
00089     KDEPrivate::ToolBarHandler *toolBarHandler;
00090     KToggleAction *showStatusBarAction;
00091     QPointer<KEditToolBar> toolBarEditor;
00092     KXMLGUIFactory *factory;
00093 };
00094 
00095 KXmlGuiWindow::KXmlGuiWindow( QWidget* parent, Qt::WFlags f )
00096     : KMainWindow(*new KXmlGuiWindowPrivate, parent, f), KXMLGUIBuilder( this )
00097 {
00098     K_D(KXmlGuiWindow);
00099     d->showHelpMenu = true;
00100     d->toolBarHandler = 0;
00101     d->showStatusBarAction = 0;
00102     d->factory = 0;
00103     new KMainWindowInterface(this);
00104 }
00105 
00106 
00107 QAction *KXmlGuiWindow::toolBarMenuAction()
00108 {
00109     K_D(KXmlGuiWindow);
00110     if ( !d->toolBarHandler )
00111     return 0;
00112 
00113     return d->toolBarHandler->toolBarMenuAction();
00114 }
00115 
00116 
00117 void KXmlGuiWindow::setupToolbarMenuActions()
00118 {
00119     K_D(KXmlGuiWindow);
00120     if ( d->toolBarHandler )
00121         d->toolBarHandler->setupActions();
00122 }
00123 
00124 
00125 KXmlGuiWindow::~KXmlGuiWindow()
00126 {
00127     K_D(KXmlGuiWindow);
00128     delete d->factory;
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     // createGUI(xmlFile()); // this loses any plugged-in guiclients, so we use remove+add instead.
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->defaultSize = defaultSize;
00215 
00216     if( options & Create ){
00217         createGUI(xmlfile);
00218     }
00219 
00220     if (initialGeometrySet()) {
00221         // Do nothing...
00222     }
00223     else if (d->defaultSize.isValid()) {
00224         resize(d->defaultSize);
00225     }
00226     else if (isHidden()) {
00227         adjustSize();
00228     }
00229 
00230     if( options & Save ){
00231         const KConfigGroup cg(autoSaveConfigGroup());
00232         if (cg.isValid()) {
00233             setAutoSaveSettings(cg);
00234         } else {
00235             setAutoSaveSettings();
00236         }
00237     }
00238 }
00239 void KXmlGuiWindow::createGUI( const QString &xmlfile )
00240 {
00241     K_D(KXmlGuiWindow);
00242     // disabling the updates prevents unnecessary redraws
00243     //setUpdatesEnabled( false );
00244 
00245     // just in case we are rebuilding, let's remove our old client
00246     guiFactory()->removeClient( this );
00247 
00248     // make sure to have an empty GUI
00249     QMenuBar* mb = menuBar();
00250     if ( mb )
00251         mb->clear();
00252 
00253     qDeleteAll( toolBars() ); // delete all toolbars
00254 
00255     // don't build a help menu unless the user ask for it
00256     if (d->showHelpMenu) {
00257         delete d->helpMenu;
00258         // we always want a help menu
00259         d->helpMenu = new KHelpMenu(this, componentData().aboutData(), true, actionCollection());
00260     }
00261 
00262     const QString windowXmlFile = xmlfile.isNull() ? componentData().componentName() + "ui.rc" : xmlfile;
00263 
00264     // Help beginners who call setXMLFile and then setupGUI...
00265     if (!xmlFile().isEmpty() && xmlFile() != windowXmlFile) {
00266         kWarning() << "You called setXMLFile(" << xmlFile() << ") and then createGUI or setupGUI,"
00267                    << "which also calls setXMLFile and will overwrite the file you have previously set.\n"
00268                    << "You should call createGUI("<<xmlFile()<<") or setupGUI(<options>,"<<xmlFile()<<") instead.";
00269     }
00270 
00271     // we always want to load in our global standards file
00272     setXMLFile(KStandardDirs::locate("config", "ui/ui_standards.rc", componentData()));
00273 
00274     // now, merge in our local xml file.
00275     setXMLFile(windowXmlFile, true);
00276 
00277     // make sure we don't have any state saved already
00278     setXMLGUIBuildDocument( QDomDocument() );
00279 
00280     // do the actual GUI building
00281     guiFactory()->addClient( this );
00282 
00283     //  setUpdatesEnabled( true );
00284 }
00285 
00286 void KXmlGuiWindow::slotStateChanged(const QString &newstate)
00287 {
00288   stateChanged(newstate, KXMLGUIClient::StateNoReverse);
00289 }
00290 
00291 void KXmlGuiWindow::slotStateChanged(const QString &newstate,
00292                                    bool reverse)
00293 {
00294   stateChanged(newstate,
00295                reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse);
00296 }
00297 
00298 void KXmlGuiWindow::setStandardToolBarMenuEnabled( bool enable )
00299 {
00300     K_D(KXmlGuiWindow);
00301     if ( enable ) {
00302         if ( d->toolBarHandler )
00303             return;
00304 
00305         d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
00306 
00307         if ( factory() )
00308             factory()->addClient( d->toolBarHandler );
00309     } else {
00310         if ( !d->toolBarHandler )
00311             return;
00312 
00313         if ( factory() )
00314             factory()->removeClient( d->toolBarHandler );
00315 
00316         delete d->toolBarHandler;
00317         d->toolBarHandler = 0;
00318     }
00319 }
00320 
00321 bool KXmlGuiWindow::isStandardToolBarMenuEnabled() const
00322 {
00323     K_D(const KXmlGuiWindow);
00324     return ( d->toolBarHandler );
00325 }
00326 
00327 void KXmlGuiWindow::createStandardStatusBarAction(){
00328     K_D(KXmlGuiWindow);
00329     if(!d->showStatusBarAction){
00330         d->showStatusBarAction = KStandardAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
00331         KStatusBar *sb = statusBar(); // Creates statusbar if it doesn't exist already.
00332         connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
00333         d->showStatusBarAction->setChecked(sb->isHidden());
00334     } else {
00335         // If the language has changed, we'll need to grab the new text and whatsThis
00336     KAction *tmpStatusBar = KStandardAction::showStatusbar(NULL, NULL, NULL);
00337         d->showStatusBarAction->setText(tmpStatusBar->text());
00338         d->showStatusBarAction->setWhatsThis(tmpStatusBar->whatsThis());
00339     delete tmpStatusBar;
00340     }
00341 }
00342 
00343 void KXmlGuiWindow::finalizeGUI( bool /*force*/ )
00344 {
00345     // FIXME: this really needs to be removed with a code more like the one we had on KDE3.
00346     //        what we need to do here is to position correctly toolbars so they don't overlap.
00347     //        Also, take in count plugins could provide their own toolbars and those also need to
00348     //        be restored.
00349     if (autoSaveSettings() && autoSaveConfigGroup().isValid()) {
00350         applyMainWindowSettings(autoSaveConfigGroup());
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 // KDE5 TODO: change it to "using KXMLGUIBuilder::finalizeGUI;" in the header
00364 // and remove the reimplementation
00365 void KXmlGuiWindow::finalizeGUI( KXMLGUIClient *client )
00366 { KXMLGUIBuilder::finalizeGUI( client ); }
00367 
00368 #include "kxmlguiwindow.moc"
00369 

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal