• Skip to content
  • Skip to link menu
KDE 4.1 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     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     // 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->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     // disabling the updates prevents unnecessary redraws
00225     //setUpdatesEnabled( false );
00226 
00227     // just in case we are rebuilding, let's remove our old client
00228     guiFactory()->removeClient( this );
00229 
00230     // make sure to have an empty GUI
00231     QMenuBar* mb = menuBar();
00232     if ( mb )
00233         mb->clear();
00234 
00235     qDeleteAll( toolBars() ); // delete all toolbars
00236 
00237     // don't build a help menu unless the user ask for it
00238     if (d->showHelpMenu) {
00239         delete d->helpMenu;
00240         // we always want a help menu
00241         d->helpMenu = new KHelpMenu(this, componentData().aboutData(), true, actionCollection());
00242     }
00243 
00244     // we always want to load in our global standards file
00245     setXMLFile(KStandardDirs::locate("config", "ui/ui_standards.rc", componentData()));
00246 
00247     // now, merge in our local xml file.  if this is null, then that
00248     // means that we will be only using the global file
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     // make sure we don't have any state saved already
00257     setXMLGUIBuildDocument( QDomDocument() );
00258 
00259     // do the actual GUI building
00260     guiFactory()->addClient( this );
00261 
00262     //  setUpdatesEnabled( true );
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(); // Creates statusbar if it doesn't exist already.
00311         connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
00312         d->showStatusBarAction->setChecked(sb->isHidden());
00313     } else {
00314         // If the language has changed, we'll need to grab the new text and whatsThis
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 /*force*/ )
00323 {
00324     K_D(KXmlGuiWindow);
00325 
00326     if (d->saveFlag) {
00327         if (initialGeometrySet()) {
00328           // Do nothing...
00329         }
00330         else if (d->defaultSize.isValid()) {
00331           resize(d->defaultSize);
00332         }
00333         else if (isHidden()) {
00334           adjustSize();
00335         }
00336         setAutoSaveSettings();
00337         // We only pretend to call this one time. If setupGUI(... | Save | ...) is called this will
00338         // be set again to true.
00339         d->saveFlag = false;
00340         return; // no need to call to applyMainWindowSettings, since setAutoSaveSettings already
00341                 // does it
00342     }
00343 
00344     // FIXME: this really needs to be removed with a code more like the one we had on KDE3.
00345     //        what we need to do here is to position correctly toolbars so they don't overlap.
00346     //        Also, take in count plugins could provide their own toolbars and those also need to
00347     //        be restored.
00348     if (autoSaveSettings() && autoSaveConfigGroup().isValid()) {
00349         applyMainWindowSettings(autoSaveConfigGroup());
00350     }
00351     // END OF FIXME
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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.6
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