TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mainwindow.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* This file is part of the KDE project
  2. Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
  3. (C) 1999 David Faure <faure@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tdeparts/mainwindow.h>
  18. #include <tdeparts/event.h>
  19. #include <tdeparts/part.h>
  20. #include <tdeparts/plugin.h>
  21. #include <kinstance.h>
  22. #include <kstatusbar.h>
  23. #include <khelpmenu.h>
  24. #include <kstandarddirs.h>
  25. #include <tqapplication.h>
  26. #include <kxmlguifactory.h>
  27. #include <tdeaccel.h>
  28. #include <kdebug.h>
  29. #include <assert.h>
  30. using namespace KParts;
  31. namespace KParts
  32. {
  33. class MainWindowPrivate
  34. {
  35. public:
  36. MainWindowPrivate()
  37. {
  38. m_activePart = 0;
  39. m_bShellGUIActivated = false;
  40. m_helpMenu = 0;
  41. }
  42. ~MainWindowPrivate()
  43. {
  44. }
  45. TQGuardedPtr<Part> m_activePart;
  46. bool m_bShellGUIActivated;
  47. KHelpMenu *m_helpMenu;
  48. };
  49. }
  50. MainWindow::MainWindow( TQWidget* parent, const char *name, WFlags f )
  51. : TDEMainWindow( parent, name, f )
  52. {
  53. d = new MainWindowPrivate();
  54. PartBase::setPartObject( TQT_TQOBJECT(this) );
  55. }
  56. MainWindow::MainWindow( const char *name, WFlags f )
  57. : TDEMainWindow( 0L, name, f )
  58. {
  59. d = new MainWindowPrivate();
  60. PartBase::setPartObject( TQT_TQOBJECT(this) );
  61. }
  62. MainWindow::MainWindow( int cflags, TQWidget* parent, const char *name, WFlags f )
  63. : TDEMainWindow( cflags, parent, name, f )
  64. {
  65. d = new MainWindowPrivate();
  66. PartBase::setPartObject( TQT_TQOBJECT(this) );
  67. }
  68. MainWindow::~MainWindow()
  69. {
  70. delete d;
  71. }
  72. void MainWindow::createGUI( Part * part )
  73. {
  74. kdDebug(1000) << "MainWindow::createGUI, part=" << part << " " << ( part ? part->className() : "" )
  75. << " " << ( part ? part->name() : "" )
  76. << endl;
  77. KXMLGUIFactory *factory = guiFactory();
  78. assert( factory );
  79. setUpdatesEnabled( false );
  80. TQPtrList<Plugin> plugins;
  81. if ( d->m_activePart )
  82. {
  83. kdDebug(1000) << "deactivating GUI for " << d->m_activePart << " " << d->m_activePart->className()
  84. << " " << d->m_activePart->name() << endl;
  85. GUIActivateEvent ev( false );
  86. TQApplication::sendEvent( d->m_activePart, &ev );
  87. factory->removeClient( d->m_activePart );
  88. disconnect( d->m_activePart, TQT_SIGNAL( setWindowCaption( const TQString & ) ),
  89. this, TQT_SLOT( setCaption( const TQString & ) ) );
  90. disconnect( d->m_activePart, TQT_SIGNAL( setStatusBarText( const TQString & ) ),
  91. this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) );
  92. }
  93. if ( !d->m_bShellGUIActivated )
  94. {
  95. loadPlugins( TQT_TQOBJECT(this), this, TDEGlobal::instance() );
  96. createShellGUI();
  97. d->m_bShellGUIActivated = true;
  98. }
  99. if ( part )
  100. {
  101. // do this before sending the activate event
  102. connect( part, TQT_SIGNAL( setWindowCaption( const TQString & ) ),
  103. this, TQT_SLOT( setCaption( const TQString & ) ) );
  104. connect( part, TQT_SIGNAL( setStatusBarText( const TQString & ) ),
  105. this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) );
  106. factory->addClient( part );
  107. GUIActivateEvent ev( true );
  108. TQApplication::sendEvent( part, &ev );
  109. if ( autoSaveSettings() )
  110. applyMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
  111. }
  112. setUpdatesEnabled( true );
  113. d->m_activePart = part;
  114. }
  115. void MainWindow::slotSetStatusBarText( const TQString & text )
  116. {
  117. statusBar()->message( text );
  118. }
  119. void MainWindow::createShellGUI( bool create )
  120. {
  121. bool bAccelAutoUpdate = accel()->setAutoUpdate( false );
  122. assert( d->m_bShellGUIActivated != create );
  123. d->m_bShellGUIActivated = create;
  124. if ( create )
  125. {
  126. if ( isHelpMenuEnabled() && !d->m_helpMenu )
  127. d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() );
  128. TQString f = xmlFile();
  129. setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
  130. if ( !f.isEmpty() )
  131. setXMLFile( f, true );
  132. else
  133. {
  134. TQString auto_file( instance()->instanceName() + "ui.rc" );
  135. setXMLFile( auto_file, true );
  136. }
  137. GUIActivateEvent ev( true );
  138. TQApplication::sendEvent( this, &ev );
  139. guiFactory()->addClient( this );
  140. }
  141. else
  142. {
  143. GUIActivateEvent ev( false );
  144. TQApplication::sendEvent( this, &ev );
  145. guiFactory()->removeClient( this );
  146. }
  147. accel()->setAutoUpdate( bAccelAutoUpdate );
  148. }
  149. void KParts::MainWindow::saveNewToolbarConfig()
  150. {
  151. createGUI( d->m_activePart );
  152. applyMainWindowSettings( TDEGlobal::config() );
  153. }
  154. #include "mainwindow.moc"