From: vsr Date: Tue, 29 Jan 2008 09:13:20 +0000 (+0000) Subject: Improve study/session closing and module activation mechanism: for light modules... X-Git-Tag: for_M2008_07022008~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca144711d326d0f575464d284be75fbb8ca073c2;p=modules%2Fgui.git Improve study/session closing and module activation mechanism: for light modules no actions like "Load study", "Unload study" and "Shutdown standalone servers" should be proposed. --- diff --git a/src/SUIT/Makefile.am b/src/SUIT/Makefile.am index a87d39fae..84543711b 100755 --- a/src/SUIT/Makefile.am +++ b/src/SUIT/Makefile.am @@ -39,6 +39,7 @@ salomeinclude_HEADERS= \ SUIT_FileDlg.h \ SUIT_FileValidator.h \ SUIT_MessageBox.h \ + SUIT_MsgDlg.h \ SUIT_Operation.h \ SUIT_OverrideCursor.h \ SUIT_ParserSettings.h \ @@ -70,6 +71,7 @@ dist_libsuit_la_SOURCES= \ SUIT_FileDlg.cxx \ SUIT_FileValidator.cxx \ SUIT_MessageBox.cxx \ + SUIT_MsgDlg.cxx \ SUIT_Operation.cxx \ SUIT_OverrideCursor.cxx \ SUIT_ParserSettings.cxx \ @@ -93,6 +95,7 @@ MOC_FILES= \ SUIT_DataObject_moc.cxx \ SUIT_Desktop_moc.cxx \ SUIT_FileDlg_moc.cxx \ + SUIT_MsgDlg_moc.cxx \ SUIT_Operation_moc.cxx \ SUIT_PopupClient_moc.cxx \ SUIT_Session_moc.cxx \ diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index 3281323e0..e6400595c 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -65,7 +65,7 @@ SUIT_Desktop* SUIT_Application::desktop() \return FALSE if application can not be closed (because of non saved data for example). This method called by SUIT_Session whin closing of application was requested. */ -bool SUIT_Application::isPossibleToClose() +bool SUIT_Application::isPossibleToClose( bool& ) { return true; } diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 151877d67..14d4854ab 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -63,7 +63,7 @@ public: /*! Returns FALSE if application can not be closed (because of non saved data for example). This method called by SUIT_Session whin closing of application was requested. */ - virtual bool isPossibleToClose(); + virtual bool isPossibleToClose( bool& ); /*! Performs some finalization of life cycle of this application. For instance, the application can force its documents(s) to close. */ diff --git a/src/SUIT/SUIT_MsgDlg.cxx b/src/SUIT/SUIT_MsgDlg.cxx new file mode 100644 index 000000000..b19372cb8 --- /dev/null +++ b/src/SUIT/SUIT_MsgDlg.cxx @@ -0,0 +1,224 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SUIT_MsgDlg.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "SUIT_MsgDlg.h" + +#include +#include +#include + +/*! + \class SUIT_MsgDlg + \brief Information message dialog box with custom number of buttons. + + The class provides a functionality to display message box with the custom number + of buttons. Each button is identified by the unique non-zero number which can + be tested after dialog box finishes its execution. Pressing each button except + causes dialog box to finish execution with return status equal to the button + identifier. In addition, pressing "Cancel" button finishes dialog box execution + wih return status 0. + + It is also possible to display custom pixmap or icon at the left side of the + dialog box. Pass the required pixmap to the constructor or use method setPixmap(). + + The typical usage of the dialog box: + \code + SUIT_MsgDlg dlg( this, tr( "Warning!" ), + tr( "File %s exists. Overwrite?" ).arg( files[i] ), + QMessageBox::standardIcon( QMessageBox::Warning ) ); + dlg.addButton( "Yes", YesId ); + dlg.addButton( "No", NoId ); + dlg.addButton( "Yes to all", YesAllId ); + dlg.addButton( "No to all", NoAllId ); + int ret = dlg.exec(); + switch( ret ) { + case YesId: + // process one file + processOneFile(); + break; + case NoId: + // skip current file processing and proceed to the next file + break; + case YesAllId: + // process all files + processAllFiles(); + stopped = true; + break; + case NoAllId: + // skip all process all files + processAllFiles(); + break; + default: + // operation is cancelled + break; + } + \endcode + + \sa addButton(), setPixmap() +*/ + +/*! + \brief Constructor. + \param parent parent widget + \param title dialog box caption + \param msg dialog box message + \param icon dialog box icon +*/ +SUIT_MsgDlg::SUIT_MsgDlg( QWidget* parent, + const QString& title, + const QString& msg, + const QPixmap& icon ) +: QDialog ( parent, "SUIT_MsgDlg", true ) +{ + // title + setCaption( title ); + + // icon + myIconLab = new QLabel( this ); + myIconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + myIconLab->setScaledContents( false ); + myIconLab->setAlignment( Qt::AlignCenter ); + + if ( !icon.isNull() ) + myIconLab->setPixmap( icon ); + + // info message + myMsgLab = new QLabel( msg, this ); + myMsgLab->setTextFormat( Qt::RichText ); + myMsgLab->setAlignment( Qt::AlignCenter ); + + // Buttons + myButtonLayout = new QHBoxLayout(); + myButtonLayout->setMargin( 0 ); + myButtonLayout->setSpacing( 6 ); + + // + QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this ); + myButtonLayout->addSpacing( 20 ); + myButtonLayout->addStretch(); + myButtonLayout->addWidget( cancelBtn ); + + QGridLayout* layout = new QGridLayout( this ); + layout->setMargin( 11 ); + layout->setSpacing( 6 ); + + layout->addWidget( myIconLab, 0, 0 ); + layout->addWidget( myMsgLab, 0, 1 ); + layout->addMultiCellLayout( myButtonLayout, 1, 1, 0, 1 ); + + // signals and slots connections + connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/*! + \brief Destructor. +*/ +SUIT_MsgDlg::~SUIT_MsgDlg() +{ +} + +/*! + \brief Add operation button to the dialog box. + + If the parameter \a id is equal to -1, then the + button identifier is generated automatically. + + \param btext button text + \param id button identifier + \return button identifier +*/ +int SUIT_MsgDlg::addButton( const QString& btext, const int id ) +{ + static int lastId = 0; + int bid = id == -1 ? --lastId : id; + + QPushButton* b = button( bid ); + if ( b ) { + myButtons.remove( b ); + delete b; + } + + QPushButton* newButton = new QPushButton( btext, this ); + + myButtonLayout->insertWidget( myButtons.count(), newButton ); + myButtons.insert( newButton, bid ); + connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + + return bid; +} + +/*! + \brief Set icon to the dialog box + \param icon pixmap +*/ +void SUIT_MsgDlg::setPixmap( const QPixmap& icon ) +{ + myIconLab->setPixmap( icon ); +} + + +/*! + \brief Called when any dialog button (except \c Cancel) + is clicked. + + Closes the dialog and sets its result code to the identifier + of the button clicked by the user. +*/ +void SUIT_MsgDlg::accept() +{ + QPushButton* btn = ( QPushButton* )sender(); + done( myButtons[ btn ] ); +} + +/*! + \brief Search button with the specified identifier. + \param id button identifier + \return button or 0 if \a id is invalid +*/ +QPushButton* SUIT_MsgDlg::button( const int id ) const +{ + QPushButton* btn = 0; + for ( ButtonMap::ConstIterator it = myButtons.begin(); + it != myButtons.end() && !btn; ++it ) { + if ( it.data() == id ) + btn = it.key(); + } + return btn; +} + +/*! + \brief Get information icon label. + \return information icon label +*/ +QLabel* SUIT_MsgDlg::iconLabel() const +{ + return myIconLab; +} + +/*! + \brief Get information message label. + \return information message label +*/ +QLabel* SUIT_MsgDlg::messageLabel() const +{ + return myMsgLab; +} diff --git a/src/SUIT/SUIT_MsgDlg.h b/src/SUIT/SUIT_MsgDlg.h new file mode 100644 index 000000000..e7f0e816c --- /dev/null +++ b/src/SUIT/SUIT_MsgDlg.h @@ -0,0 +1,66 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SUIT_MsgDlg.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef SUIT_MSGDLG_H +#define SUIT_MSGDLG_H + +#include "SUIT.h" + +#include +#include +#include + +class QLabel; +class QPushButton; +class QHBoxLayout; + +class SUIT_EXPORT SUIT_MsgDlg : public QDialog +{ + Q_OBJECT + +public: + SUIT_MsgDlg( QWidget*, const QString&, const QString&, const QPixmap& = QPixmap() ) ; + ~SUIT_MsgDlg(); + + int addButton( const QString&, const int = -1); + void setPixmap( const QPixmap& ); + +public slots: + void accept(); + +protected: + QPushButton* button( const int ) const; + QLabel* iconLabel() const; + QLabel* messageLabel() const; + +private: + typedef QMap ButtonMap; + +private: + ButtonMap myButtons; + QHBoxLayout* myButtonLayout; + QLabel* myIconLab; + QLabel* myMsgLab; +}; + +#endif // SUIT_MSGDLG_H + diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index 31b38b3a4..6ea095648 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -47,8 +47,8 @@ SUIT_Session::SUIT_Session() myResMgr( 0 ), myHandler( 0 ), myActiveApp( 0 ), -myExitStatus( FROM_GUI ), -myServersShutdown ( true ) +myExitStatus( NORMAL ), +myExitFlags ( 0 ) { SUIT_ASSERT( !mySession ) @@ -238,12 +238,13 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) /*! Destroys session by closing all applications. */ -void SUIT_Session::closeSession( int mode ) +void SUIT_Session::closeSession( int mode, int flags ) { while ( !myAppList.isEmpty() ) { SUIT_Application* app = myAppList.getFirst(); - if ( mode == ASK && !app->isPossibleToClose() ) + bool closePermanently; + if ( mode == ASK && !app->isPossibleToClose( closePermanently ) ) return; else if ( mode == SAVE ) { @@ -253,29 +254,26 @@ void SUIT_Session::closeSession( int mode ) } else if ( mode == DONT_SAVE ) { - myExitStatus = FROM_CORBA_SESSION; - //.... + myExitStatus = FORCED; } app->closeApplication(); } + myExitFlags = flags; } /*! - Set a flag to shutdown or not standalone servers at exit of application. -*/ -void SUIT_Session::serversShutdown( bool theVal ) -{ - myServersShutdown = theVal; -} + Get session exit flags. -/*! - \retval Return TRUE, if standalone servers will be shutdown at exit of application, - FALSE otherwise. + By default, exit flags are set to 0. You can use pass any flags to the + closeSession() method if you need to process them later on application + quiting. + + \return exit flags */ -bool SUIT_Session::isServersShutdown() const +int SUIT_Session::exitFlags() const { - return myServersShutdown; + return myExitFlags; } /*! \retval return myHandler*/ diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index 1565fc40e..7b16ea183 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -55,7 +55,7 @@ public: typedef LIB_HANDLE AppLib; enum { ASK = 0, SAVE, DONT_SAVE } CloseMode; - enum { FROM_GUI = 0, FROM_CORBA_SESSION } ExitStatus; + enum { NORMAL = 0, FORCED } ExitStatus; public: SUIT_Session(); @@ -70,9 +70,8 @@ public: SUIT_ResourceMgr* resourceMgr() const; - void closeSession( int mode = ASK ); - void serversShutdown( bool theVal ); - bool isServersShutdown() const; + void closeSession( int mode = ASK, int flags = 0 ); + int exitFlags() const; SUIT_ExceptionHandler* handler() const; @@ -110,7 +109,7 @@ private: static SUIT_Session* mySession; int myExitStatus; - bool myServersShutdown; + int myExitFlags; }; #endif