• Skip to content
  • Skip to link menu
KDE 4.2 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 }
00128 
00129 bool KXmlGuiWindow::event( QEvent* ev )
00130 {
00131     bool ret = KMainWindow::event(ev);
00132     if (ev->type()==QEvent::Polish) {
00133         QDBusConnection::sessionBus().registerObject(dbusName() + "/actions", actionCollection(),
00134                                                      QDBusConnection::ExportScriptableSlots |
00135                                                      QDBusConnection::ExportScriptableProperties |
00136                                                      QDBusConnection::ExportNonScriptableSlots |
00137                                                      QDBusConnection::ExportNonScriptableProperties |
00138                                                      QDBusConnection::ExportChildObjects);
00139     }
00140     return ret;
00141 }
00142 
00143 void KXmlGuiWindow::setHelpMenuEnabled(bool showHelpMenu)
00144 {
00145     K_D(KXmlGuiWindow);
00146     d->showHelpMenu = showHelpMenu;
00147 }
00148 
00149 bool KXmlGuiWindow::isHelpMenuEnabled() const
00150 {
00151     K_D(const KXmlGuiWindow);
00152     return d->showHelpMenu;
00153 }
00154 
00155 KXMLGUIFactory *KXmlGuiWindow::guiFactory()
00156 {
00157     K_D(KXmlGuiWindow);
00158     if (!d->factory) {
00159         d->factory = new KXMLGUIFactory( this, this );
00160         connect(d->factory, SIGNAL(makingChanges(bool)),
00161                 this, SLOT(_k_slotFactoryMakingChanges(bool)));
00162     }
00163     return d->factory;
00164 }
00165 
00166 void KXmlGuiWindow::configureToolbars()
00167 {
00168     K_D(KXmlGuiWindow);
00169     KConfigGroup cg(KGlobal::config(), QString());
00170     saveMainWindowSettings(cg);
00171     if (!d->toolBarEditor) {
00172       d->toolBarEditor = new KEditToolBar(guiFactory(), this);
00173       d->toolBarEditor->setAttribute(Qt::WA_DeleteOnClose);
00174       connect(d->toolBarEditor, SIGNAL(newToolBarConfig()), SLOT(saveNewToolbarConfig()));
00175     }
00176     d->toolBarEditor->show();
00177 }
00178 
00179 void KXmlGuiWindow::saveNewToolbarConfig()
00180 {
00181     // createGUI(xmlFile()); // this loses any plugged-in guiclients, so we use remove+add instead.
00182 
00183     guiFactory()->removeClient(this);
00184     guiFactory()->addClient(this);
00185 
00186     KConfigGroup cg(KGlobal::config(), QString());
00187     applyMainWindowSettings(cg);
00188 }
00189 
00190 void KXmlGuiWindow::setupGUI( StandardWindowOptions options, const QString & xmlfile ) {
00191     setupGUI(QSize(), options, xmlfile);
00192 }
00193 
00194 void KXmlGuiWindow::setupGUI( const QSize & defaultSize, StandardWindowOptions options, const QString & xmlfile ) {
00195     K_D(KXmlGuiWindow);
00196 
00197     if( options & Keys ){
00198         KStandardAction::keyBindings(guiFactory(),
00199                     SLOT(configureShortcuts()), actionCollection());
00200     }
00201 
00202     if( (options & StatusBar) && statusBar() ){
00203         createStandardStatusBarAction();
00204     }
00205 
00206     if( options & ToolBar ){
00207         setStandardToolBarMenuEnabled( true );
00208         KStandardAction::configureToolbars(this,
00209                       SLOT(configureToolbars() ), actionCollection());
00210     }
00211 
00212     d->defaultSize = defaultSize;
00213 
00214     if( options & Create ){
00215         createGUI(xmlfile);
00216     }
00217 
00218     if (initialGeometrySet()) {
00219         // Do nothing...
00220     }
00221     else if (d->defaultSize.isValid()) {
00222         resize(d->defaultSize);
00223     }
00224     else if (isHidden()) {
00225         adjustSize();
00226     }
00227 
00228     if( options & Save ){
00229         const KConfigGroup cg(autoSaveConfigGroup());
00230         if (cg.isValid()) {
00231             setAutoSaveSettings(cg);
00232         } else {
00233             setAutoSaveSettings();
00234         }
00235     }
00236 }
00237 void KXmlGuiWindow::createGUI( const QString &xmlfile )
00238 {
00239     K_D(KXmlGuiWindow);
00240     // disabling the updates prevents unnecessary redraws
00241     //setUpdatesEnabled( false );
00242 
00243     // just in case we are rebuilding, let's remove our old client
00244     guiFactory()->removeClient( this );
00245 
00246     // make sure to have an empty GUI
00247     QMenuBar* mb = menuBar();
00248     if ( mb )
00249         mb->clear();
00250 
00251     qDeleteAll( toolBars() ); // delete all toolbars
00252 
00253     // don't build a help menu unless the user ask for it
00254     if (d->showHelpMenu) {
00255         delete d->helpMenu;
00256         // we always want a help menu
00257         d->helpMenu = new KHelpMenu(this, componentData().aboutData(), true, actionCollection());
00258     }
00259 
00260     const QString windowXmlFile = xmlfile.isNull() ? componentData().componentName() + "ui.rc" : xmlfile;
00261 
00262     // Help beginners who call setXMLFile and then setupGUI...
00263     if (!xmlFile().isEmpty() && xmlFile() != windowXmlFile) {
00264         kWarning() << "You called setXMLFile(" << xmlFile() << ") and then createGUI or setupGUI,"
00265                    << "which also calls setXMLFile and will overwrite the file you have previously set.\n"
00266                    << "You should call createGUI("<<xmlFile()<<") or setupGUI(<options>,"<<xmlFile()<<") instead.";
00267     }
00268 
00269     // we always want to load in our global standards file
00270     setXMLFile(KStandardDirs::locate("config", "ui/ui_standards.rc", componentData()));
00271 
00272     // now, merge in our local xml file.
00273     setXMLFile(windowXmlFile, true);
00274 
00275     // make sure we don't have any state saved already
00276     setXMLGUIBuildDocument( QDomDocument() );
00277 
00278     // do the actual GUI building
00279     guiFactory()->addClient( this );
00280 
00281     //  setUpdatesEnabled( true );
00282 }
00283 
00284 void KXmlGuiWindow::slotStateChanged(const QString &newstate)
00285 {
00286   stateChanged(newstate, KXMLGUIClient::StateNoReverse);
00287 }
00288 
00289 void KXmlGuiWindow::slotStateChanged(const QString &newstate,
00290                                    bool reverse)
00291 {
00292   stateChanged(newstate,
00293                reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse);
00294 }
00295 
00296 void KXmlGuiWindow::setStandardToolBarMenuEnabled( bool enable )
00297 {
00298     K_D(KXmlGuiWindow);
00299     if ( enable ) {
00300         if ( d->toolBarHandler )
00301             return;
00302 
00303         d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
00304 
00305         if ( factory() )
00306             factory()->addClient( d->toolBarHandler );
00307     } else {
00308         if ( !d->toolBarHandler )
00309             return;
00310 
00311         if ( factory() )
00312             factory()->removeClient( d->toolBarHandler );
00313 
00314         delete d->toolBarHandler;
00315         d->toolBarHandler = 0;
00316     }
00317 }
00318 
00319 bool KXmlGuiWindow::isStandardToolBarMenuEnabled() const
00320 {
00321     K_D(const KXmlGuiWindow);
00322     return ( d->toolBarHandler );
00323 }
00324 
00325 void KXmlGuiWindow::createStandardStatusBarAction(){
00326     K_D(KXmlGuiWindow);
00327     if(!d->showStatusBarAction){
00328         d->showStatusBarAction = KStandardAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
00329         KStatusBar *sb = statusBar(); // Creates statusbar if it doesn't exist already.
00330         connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
00331         d->showStatusBarAction->setChecked(sb->isHidden());
00332     } else {
00333         // If the language has changed, we'll need to grab the new text and whatsThis
00334     KAction *tmpStatusBar = KStandardAction::showStatusbar(NULL, NULL, NULL);
00335         d->showStatusBarAction->setText(tmpStatusBar->text());
00336         d->showStatusBarAction->setWhatsThis(tmpStatusBar->whatsThis());
00337     delete tmpStatusBar;
00338     }
00339 }
00340 
00341 void KXmlGuiWindow::finalizeGUI( bool /*force*/ )
00342 {
00343     // FIXME: this really needs to be removed with a code more like the one we had on KDE3.
00344     //        what we need to do here is to position correctly toolbars so they don't overlap.
00345     //        Also, take in count plugins could provide their own toolbars and those also need to
00346     //        be restored.
00347     if (autoSaveSettings() && autoSaveConfigGroup().isValid()) {
00348         applyMainWindowSettings(autoSaveConfigGroup());
00349     }
00350 }
00351 
00352 void KXmlGuiWindow::applyMainWindowSettings(const KConfigGroup &config, bool force)
00353 {
00354     K_D(KXmlGuiWindow);
00355     KMainWindow::applyMainWindowSettings(config, force);
00356     KStatusBar *sb = qFindChild<KStatusBar *>(this);
00357     if (sb && d->showStatusBarAction)
00358         d->showStatusBarAction->setChecked(!sb->isHidden());
00359 }
00360 
00361 // KDE5 TODO: change it to "using KXMLGUIBuilder::finalizeGUI;" in the header
00362 // and remove the reimplementation
00363 void KXmlGuiWindow::finalizeGUI( KXMLGUIClient *client )
00364 { KXMLGUIBuilder::finalizeGUI( client ); }
00365 
00366 #include "kxmlguiwindow.moc"
00367 

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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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