From 2b7743b0044a39476dec9d3b0784606adc650eda Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 29 Jan 2008 09:36:11 +0000 Subject: [PATCH] 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. --- src/SalomeApp/Makefile.am | 12 ++- src/SalomeApp/SalomeApp_Application.cxx | 94 ++++++++++++++++++ src/SalomeApp/SalomeApp_Application.h | 11 +++ src/SalomeApp/SalomeApp_ExitDlg.cxx | 104 ++++++++++++++++++++ src/SalomeApp/SalomeApp_ExitDlg.h | 48 +++++++++ src/SalomeApp/resources/SalomeApp_msg_en.po | 21 ++++ src/Session/SALOME_Session_Server.cxx | 4 +- 7 files changed, 288 insertions(+), 6 deletions(-) create mode 100644 src/SalomeApp/SalomeApp_ExitDlg.cxx create mode 100644 src/SalomeApp/SalomeApp_ExitDlg.h diff --git a/src/SalomeApp/Makefile.am b/src/SalomeApp/Makefile.am index 53bbe36b7..7ced4827f 100755 --- a/src/SalomeApp/Makefile.am +++ b/src/SalomeApp/Makefile.am @@ -46,7 +46,8 @@ salomeinclude_HEADERS= \ SalomeApp_TypeFilter.h \ SalomeApp_StudyPropertiesDlg.h \ SalomeApp_CheckFileDlg.h \ - SalomeApp_VisualState.h + SalomeApp_VisualState.h \ + SalomeApp_ExitDlg.h dist_libSalomeApp_la_SOURCES= \ SalomeApp_Module.cxx \ @@ -64,7 +65,8 @@ dist_libSalomeApp_la_SOURCES= \ SalomeApp_StudyPropertiesDlg.cxx \ SalomeApp_ListView.cxx \ SalomeApp_CheckFileDlg.cxx \ - SalomeApp_VisualState.cxx + SalomeApp_VisualState.cxx \ + SalomeApp_ExitDlg.cxx MOC_FILES= \ SalomeApp_Application_moc.cxx \ @@ -73,7 +75,9 @@ MOC_FILES= \ SalomeApp_Study_moc.cxx \ SalomeApp_StudyPropertiesDlg_moc.cxx \ SalomeApp_ListView_moc.cxx \ - SalomeApp_CheckFileDlg_moc.cxx + SalomeApp_CheckFileDlg_moc.cxx \ + SalomeApp_ExitDlg_moc.cxx + nodist_libSalomeApp_la_SOURCES= $(MOC_FILES) dist_salomeres_DATA= \ @@ -103,4 +107,4 @@ libSalomeApp_la_LIBADD= $(KERNEL_LDFLAGS) -lOpUtil -lSALOMELocalTrace -lSalomeDS ../PythonConsole/libPythonConsole.la ../LogWindow/libLogWindow.la \ ../LightApp/libLightApp.la ../TOOLSGUI/libToolsGUI.la ../CASCatch/libCASCatch.la $(CAS_KERNEL) -EXTRA_DIST+=SalomeApp_PyInterp.h \ No newline at end of file +EXTRA_DIST+=SalomeApp_PyInterp.h diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 3e019b7f6..771c0d7de 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -30,6 +30,7 @@ #include "SalomeApp_DataObject.h" #include "SalomeApp_EventFilter.h" #include "SalomeApp_VisualState.h" +#include "SalomeApp_ExitDlg.h" #include "SalomeApp_StudyPropertiesDlg.h" @@ -43,6 +44,7 @@ #include #include +#include #include @@ -68,6 +70,7 @@ #include #include #include +#include #include "SALOMEDSClient_ClientFactory.hxx" #include "SALOMEDSClient_IParameters.hxx" @@ -429,6 +432,23 @@ void SalomeApp_Application::onLoadDoc() } } +/*! + \brief Close application. +*/ +void SalomeApp_Application::onExit() +{ + bool killServers = false; + bool result = true; + + if ( exitConfirmation() ) { + SalomeApp_ExitDlg dlg( desktop() ); + result = dlg.exec() == QDialog::Accepted; + killServers = dlg.isServersShutdown(); + } + + if ( result ) + SUIT_Session::session()->closeSession( SUIT_Session::ASK, killServers ); +} /*!SLOT. Load document with \a aName.*/ bool SalomeApp_Application::onLoadDoc( const QString& aName ) @@ -849,6 +869,80 @@ void SalomeApp_Application::updateDesktopTitle() { desktop()->setCaption( aTitle ); } +/*! + \brief Show dialog box to propose possible user actions when study is closed. + \param docName study name + \return chosen action ID + \sa closeAction() +*/ +int SalomeApp_Application::closeChoice( const QString& docName ) +{ + SUIT_MsgDlg dlg( desktop(), tr( "APPCLOSE_CAPTION" ), tr ( "APPCLOSE_DESCRIPTION" ), + QMessageBox::standardIcon( QMessageBox::Information ) ); + dlg.addButton( tr ( "APPCLOSE_SAVE" ), CloseSave ); + dlg.addButton( tr ( "APPCLOSE_CLOSE" ), CloseDiscard ); + dlg.addButton( tr ( "APPCLOSE_UNLOAD" ), CloseUnload ); + + return dlg.exec(); +} + +/*! + \brief Process user actions selected from the dialog box when study is closed. + \param choice chosen action ID + \param closePermanently "forced study closing" flag + \return operation status + \sa closeChoice() +*/ +bool SalomeApp_Application::closeAction( const int choice, bool& closePermanently ) +{ + bool res = true; + switch( choice ) + { + case CloseSave: + if ( activeStudy()->isSaved() ) + onSaveDoc(); + else if ( !onSaveAsDoc() ) + res = false; + break; + case CloseDiscard: + break; + case CloseUnload: + closePermanently = false; + break; + case CloseCancel: + default: + res = false; + } + return res; +} + +/*! + \brief Get module activation actions + \return map where + - action_id is unique non-zero action identifier + - action_name is action title + \sa moduleActionSelected() +*/ +QMap SalomeApp_Application::activateModuleActions() const +{ + QMap opmap = LightApp_Application::activateModuleActions(); + opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) ); + return opmap; +} + +/*! + \brief Process module activation action. + \param id action identifier + \sa activateModuleActions() +*/ +void SalomeApp_Application::moduleActionSelected( const int id ) +{ + if ( id == LoadStudyId ) + onLoadDoc(); + else + LightApp_Application::moduleActionSelected( id ); +} + /*!Gets CORBA::ORB_var*/ CORBA::ORB_var SalomeApp_Application::orb() { diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 09ece677d..373e13b1d 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -71,6 +71,10 @@ public: enum { DumpStudyId = LightApp_Application::UserID, LoadScriptId, PropertiesId, CatalogGenId, RegDisplayId, SaveGUIStateId, FileLoadId, UserID }; +protected: + enum { CloseUnload = CloseDiscard + 1 }; + enum { LoadStudyId = OpenStudyId + 1 }; + public: SalomeApp_Application(); virtual ~SalomeApp_Application(); @@ -98,6 +102,7 @@ public slots: virtual bool onOpenDoc( const QString& ); virtual void onLoadDoc(); virtual bool onLoadDoc( const QString& ); + virtual void onExit(); virtual void onCopy(); virtual void onPaste(); void onSaveGUIState();// called from VISU @@ -119,6 +124,12 @@ protected: virtual void createPreferences( LightApp_Preferences* ); virtual void updateDesktopTitle(); + virtual bool closeAction( const int, bool& ); + virtual int closeChoice( const QString& ); + + virtual QMap activateModuleActions() const; + virtual void moduleActionSelected( const int ); + private slots: void onDeleteInvalidReferences(); void onDblClick( QListViewItem* ); diff --git a/src/SalomeApp/SalomeApp_ExitDlg.cxx b/src/SalomeApp/SalomeApp_ExitDlg.cxx new file mode 100644 index 000000000..f01d581c9 --- /dev/null +++ b/src/SalomeApp/SalomeApp_ExitDlg.cxx @@ -0,0 +1,104 @@ +// 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: SalomeApp_ExitDlg.cxx +// Author: Margarita KARPUNINA, Open CASCADE S.A.S. +// + +#include "SalomeApp_ExitDlg.h" + +#include +#include +#include +#include +#include + +/*! + * \brief creates a Exit dialog box + * \param parent a parent widget + * \param modal bool argument, if true the dialog box is a modal dialog box + * \param f style flags + */ +SalomeApp_ExitDlg::SalomeApp_ExitDlg( QWidget* parent ) + : QDialog( parent, "SalomeApp_ExitDlg", true ) +{ + setSizeGripEnabled( true ); + setCaption( tr( "INF_DESK_EXIT" ) ); + + QVBoxLayout* m_vbL = new QVBoxLayout( this ); + m_vbL->setMargin( 11 ); + m_vbL->setSpacing( 6 ); + + QLabel* m_lIcon = new QLabel( this, "m_lDescr" ); + QPixmap pm = QMessageBox::standardIcon( QMessageBox::Question ); + m_lIcon->setPixmap( pm ); + m_lIcon->setScaledContents( false ); + m_lIcon->setAlignment( Qt::AlignCenter ); + + QLabel* m_lDescr = new QLabel (this, "m_lDescr"); + m_lDescr->setText ( tr ("QUE_DESK_EXIT") ); + m_lDescr->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + + myServersShutdown = new QCheckBox( tr("SHUTDOWN_SERVERS"), this ); + myServersShutdown->setChecked(true); + + QVBoxLayout* m_vl1 = new QVBoxLayout(); + m_vl1->setMargin( 10 ); m_vl1->setSpacing( 16 ); + m_vl1->addWidget( m_lDescr ); + m_vl1->addWidget( myServersShutdown ); + + QHBoxLayout* m_hl1 = new QHBoxLayout(); + m_hl1->setMargin( 0 ); m_hl1->setSpacing( 6 ); + m_hl1->addWidget( m_lIcon ); + m_hl1->addStretch(); + m_hl1->addLayout( m_vl1 ); + m_hl1->addStretch(); + + QPushButton* m_pbOk = new QPushButton( tr( "BUT_OK" ), this ); + QPushButton* m_pbCancel = new QPushButton( tr( "BUT_CANCEL" ), this ); + + QGridLayout* m_hl2 = new QGridLayout(); + m_hl2->setMargin( 0 ); m_hl2->setSpacing( 6 ); + m_hl2->addWidget( m_pbOk, 0, 0 ); + m_hl2->setColStretch( 1, 5 ); + m_hl2->addWidget( m_pbCancel, 0, 2 ); + + m_vbL->addStretch(); + m_vbL->addLayout( m_hl1 ); + m_vbL->addStretch(); + m_vbL->addLayout( m_hl2 ); + + connect( m_pbOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( m_pbCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/*! + * \brief Destructor + */ +SalomeApp_ExitDlg::~SalomeApp_ExitDlg() +{ +} + +/*! + * \brief get the check box status + */ +bool SalomeApp_ExitDlg::isServersShutdown() +{ + return myServersShutdown->isChecked(); +} + diff --git a/src/SalomeApp/SalomeApp_ExitDlg.h b/src/SalomeApp/SalomeApp_ExitDlg.h new file mode 100644 index 000000000..e046291e1 --- /dev/null +++ b/src/SalomeApp/SalomeApp_ExitDlg.h @@ -0,0 +1,48 @@ +// 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: SalomeApp_ExitDlg.h +// Author: Margarita KARPUNINA, Open CASCADE S.A.S. +// + +#ifndef SALOMEAPP_EXITDLG_H +#define SALOMEAPP_EXITDLG_H + +#include + +class QCheckBox; + +/*!\class SalomeApp_ExitDlg + * \brief Describes a dialog box shown on question about quit application + */ +class SalomeApp_ExitDlg: public QDialog +{ + Q_OBJECT + +public: + SalomeApp_ExitDlg( QWidget* ) ; + ~SalomeApp_ExitDlg(); + + bool isServersShutdown(); + +private: + QCheckBox* myServersShutdown; +}; + +#endif // SALOMEAPP_EXITDLG_H + diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.po b/src/SalomeApp/resources/SalomeApp_msg_en.po index f6db22171..40f7e95f1 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.po +++ b/src/SalomeApp/resources/SalomeApp_msg_en.po @@ -246,3 +246,24 @@ msgstr "Rename" msgid "SalomeApp_Application::MEN_DELETE_VS" msgstr "Delete" + +msgid "SalomeApp_Application::APPCLOSE_CAPTION" +msgstr "Close study" + +msgid "SalomeApp_Application::APPCLOSE_DESCRIPTION" +msgstr "Do you want to save or unload study before closing?" + +msgid "SalomeApp_Application::APPCLOSE_CLOSE" +msgstr "&Close w/o saving" + +msgid "SalomeApp_Application::APPCLOSE_SAVE" +msgstr "&Save && Close" + +msgid "SalomeApp_Application::APPCLOSE_UNLOAD" +msgstr "&Unload" + +msgid "SalomeApp_ExitDlg::SHUTDOWN_SERVERS" +msgstr "Shutdown standalone servers" + +msgid "SalomeApp_Application::ACTIVATE_MODULE_OP_LOAD" +msgstr "&Load..." diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index b1cde1c20..635c5724f 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -644,8 +644,8 @@ int main( int argc, char **argv ) delete splash; splash = 0; - if ( result == SUIT_Session::FROM_GUI ) { // desktop is closed by user from GUI - if ( aGUISession->isServersShutdown() ) + if ( result == SUIT_Session::NORMAL ) { // desktop is closed by user from GUI + if ( aGUISession->exitFlags() ) shutdownServers( _NS ); break; } -- 2.39.2