• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

tdetoolbarhandler.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "tdetoolbarhandler.h"
00020 
00021 #include <tqpopupmenu.h>
00022 #include <tdeapplication.h>
00023 #include <tdetoolbar.h>
00024 #include <tdemainwindow.h>
00025 #include <tdelocale.h>
00026 #include <tdeaction.h>
00027 #include <assert.h>
00028 
00029 namespace
00030 {
00031     const char *actionListName = "show_menu_and_toolbar_actionlist";
00032 
00033     const char *guiDescription = ""
00034         "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
00035         "<MenuBar>"
00036         "    <Menu name=\"settings\">"
00037         "        <ActionList name=\"%1\" />"
00038         "    </Menu>"
00039         "</MenuBar>"
00040         "</kpartgui>";
00041 
00042     const char *resourceFileName = "barhandler.rc";
00043 
00044     class BarActionBuilder
00045     {
00046     public:
00047         BarActionBuilder( TDEActionCollection *actionCollection, TDEMainWindow *mainWindow, TQPtrList<TDEToolBar> &oldToolBarList )
00048             : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
00049         {
00050             TQPtrList<TQDockWindow> dockWindows = m_mainWindow->dockWindows();
00051             TQPtrListIterator<TQDockWindow> dockWindowIt( dockWindows );
00052             for ( ; dockWindowIt.current(); ++dockWindowIt ) {
00053 
00054                 TDEToolBar *toolBar = tqt_dynamic_cast<TDEToolBar *>( dockWindowIt.current() );
00055                 if ( !toolBar )
00056                     continue;
00057 
00058                 if ( oldToolBarList.findRef( toolBar ) == -1 )
00059                     m_needsRebuild = true;
00060 
00061                 m_toolBars.append( toolBar );
00062             }
00063 
00064             if ( !m_needsRebuild )
00065                 m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
00066         }
00067 
00068         bool needsRebuild() const { return m_needsRebuild; }
00069 
00070         TQPtrList<TDEAction> create()
00071         {
00072             if ( !m_needsRebuild )
00073                 return TQPtrList<TDEAction>();
00074 
00075             TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
00076             for ( ; toolBarIt.current(); ++toolBarIt )
00077                 handleToolBar( toolBarIt.current() );
00078 
00079             TQPtrList<TDEAction> actions;
00080 
00081             if ( m_toolBarActions.count() == 0 )
00082                 return actions;
00083 
00084             if ( m_toolBarActions.count() == 1 ) {
00085                 TDEToggleToolBarAction* action = static_cast<TDEToggleToolBarAction *>( m_toolBarActions.getFirst() );
00086                 action->setText( i18n( "Show Toolbar" ) );
00087                 action->setCheckedState( i18n( "Hide Toolbar" ) );
00088                 return m_toolBarActions;
00089             }
00090 
00091             TDEActionMenu *menuAction = new TDEActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" );
00092 
00093             TQPtrListIterator<TDEAction> actionIt( m_toolBarActions );
00094             for ( ; actionIt.current(); ++actionIt )
00095                 menuAction->insert( actionIt.current() );
00096 
00097             actions.append( menuAction );
00098             return actions;
00099         }
00100 
00101         const TQPtrList<TDEToolBar> &toolBars() const { return m_toolBars; }
00102 
00103     private:
00104         void handleToolBar( TDEToolBar *toolBar )
00105         {
00106             TDEToggleToolBarAction *action = new TDEToggleToolBarAction(
00107                 toolBar,
00108                 toolBar->label(),
00109                 m_actionCollection,
00110                 toolBar->name() );
00111             // ## tooltips, whatsthis?
00112             m_toolBarActions.append( action );
00113         }
00114 
00115         TDEActionCollection *m_actionCollection;
00116         TDEMainWindow *m_mainWindow;
00117 
00118         TQPtrList<TDEToolBar> m_toolBars;
00119         TQPtrList<TDEAction> m_toolBarActions;
00120 
00121         bool m_needsRebuild : 1;
00122     };
00123 }
00124 
00125 using namespace KDEPrivate;
00126 
00127 ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, const char *name )
00128     : TQObject( mainWindow, name ), KXMLGUIClient( mainWindow )
00129 {
00130     init( mainWindow );
00131 }
00132 
00133 ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name )
00134     : TQObject( parent, name ), KXMLGUIClient( mainWindow )
00135 {
00136     init( mainWindow );
00137 }
00138 
00139 ToolBarHandler::~ToolBarHandler()
00140 {
00141     m_actions.setAutoDelete( true );
00142     m_actions.clear();
00143 }
00144 
00145 TDEAction *ToolBarHandler::toolBarMenuAction()
00146 {
00147     assert( m_actions.count() == 1 );
00148     return m_actions.getFirst();
00149 }
00150 
00151 void ToolBarHandler::setupActions()
00152 {
00153     if ( !factory() || !m_mainWindow )
00154         return;
00155 
00156     BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
00157 
00158     if ( !builder.needsRebuild() )
00159         return;
00160 
00161     unplugActionList( actionListName );
00162 
00163     m_actions.setAutoDelete( true );
00164     m_actions.clear();
00165     m_actions.setAutoDelete( false );
00166 
00167     m_actions = builder.create();
00168 
00169     /*
00170     for (  TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
00171            toolBarIt.current(); ++toolBarIt )
00172         toolBarIt.current()->disconnect( this );
00173         */
00174 
00175     m_toolBars = builder.toolBars();
00176 
00177     /*
00178     for (  TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
00179            toolBarIt.current(); ++toolBarIt )
00180         connect( toolBarIt.current(), TQT_SIGNAL( destroyed() ),
00181                  this, TQT_SLOT( setupActions() ) );
00182                  */
00183 
00184     if (kapp && kapp->authorizeTDEAction("options_show_toolbar"))
00185     plugActionList( actionListName, m_actions );
00186 
00187     connectToActionContainers();
00188 }
00189 
00190 void ToolBarHandler::clientAdded( KXMLGUIClient *client )
00191 {
00192     if ( client == this )
00193         setupActions();
00194 }
00195 
00196 void ToolBarHandler::init( TDEMainWindow *mainWindow )
00197 {
00198     d = 0;
00199     m_mainWindow = mainWindow;
00200 
00201     connect( m_mainWindow->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ),
00202              this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) );
00203 
00204     /* re-use an existing resource file if it exists. can happen if the user launches the
00205      * toolbar editor */
00206     /*
00207     setXMLFile( resourceFileName );
00208     */
00209 
00210     if ( domDocument().documentElement().isNull() ) {
00211 
00212         TQString completeDescription = TQString::fromLatin1( guiDescription )
00213             .arg( actionListName );
00214 
00215         setXML( completeDescription, false /*merge*/ );
00216     }
00217 }
00218 
00219 void ToolBarHandler::connectToActionContainers()
00220 {
00221     TQPtrListIterator<TDEAction> actionIt( m_actions );
00222     for ( ; actionIt.current(); ++actionIt )
00223         connectToActionContainer( actionIt.current() );
00224 }
00225 
00226 void ToolBarHandler::connectToActionContainer( TDEAction *action )
00227 {
00228     uint containerCount = action->containerCount();
00229     for ( uint i = 0; i < containerCount; ++i )
00230         connectToActionContainer( action->container( i ) );
00231 }
00232 
00233 void ToolBarHandler::connectToActionContainer( TQWidget *container )
00234 {
00235     TQPopupMenu *popupMenu = tqt_dynamic_cast<TQPopupMenu *>( container );
00236     if ( !popupMenu )
00237         return;
00238 
00239     connect( popupMenu, TQT_SIGNAL( aboutToShow() ),
00240              this, TQT_SLOT( setupActions() ) );
00241 }
00242 
00243 #include "tdetoolbarhandler.moc"
00244 
00245 /* vim: et sw=4 ts=4
00246  */

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.6.3
This website is maintained by Timothy Pearson.