-// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// 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
+// 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/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include "SUIT_Session.h"
+#include "SUIT_Study.h"
#include "SUIT_Tools.h"
-#include "SUIT_Desktop.h"
#include "SUIT_MessageBox.h"
-#include "SUIT_ViewWindow.h"
-#include "SUIT_ViewManager.h"
#include "SUIT_ExceptionHandler.h"
+#include "SUIT_ResourceMgr.h"
-#include <qtextcodec.h>
-#include <qmessagebox.h>
-#include <qapplication.h>
+#include <QApplication>
#ifdef WIN32
#include <windows.h>
SUIT_Session::SUIT_Session()
: QObject(),
-myResMgr( 0 ),
-myHandler( 0 ),
-myActiveApp( 0 ),
-myExitStatus( FROM_GUI )
+ myResMgr( 0 ),
+ myActiveApp( 0 ),
+ myHandler( 0 ),
+ myExitStatus( NORMAL ),
+ myExitFlags ( 0 )
{
SUIT_ASSERT( !mySession )
mySession = this;
+}
- myAppList.setAutoDelete( true );
+SUIT_Session::SUIT_Session( int argc, char** argv )
+: QObject(),
+ myResMgr( 0 ),
+ myActiveApp( 0 ),
+ myHandler( 0 ),
+ myExitStatus( NORMAL ),
+ myExitFlags ( 0 )
+{
+ SUIT_ASSERT( !mySession )
+
+ mySession = this;
+
+ for ( int i = 0; i < argc; i++ )
+ myArguments << QString( argv[i] );
}
/*!destructor. Clear applications list and set mySession to zero.*/
SUIT_Session::~SUIT_Session()
{
+ for ( AppList::iterator it = myAppList.begin(); it != myAppList.end(); ++it )
+ delete *it;
+
myAppList.clear();
+ if ( myResMgr )
+ {
+ delete myResMgr;
+ myResMgr = 0;
+ }
mySession = 0;
}
+/*!
+ Get arguments of the current session
+ */
+QStringList SUIT_Session::arguments()
+{
+ QStringList r;
+ if ( !myArguments.isEmpty() ) r = myArguments;
+ else if ( QApplication::instance() ) r = QApplication::arguments();
+ return r;
+}
+
/*! \retval return mySession */
SUIT_Session* SUIT_Session::session()
{
Starts new application using "createApplication" function of loaded DLL.
*/
-SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, char** argv )
+SUIT_Application* SUIT_Session::startApplication( const QString& name, int /*args*/, char** /*argv*/ )
{
AppLib libHandle = 0;
if ( !libHandle )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ),
+ tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ) );
return 0;
}
APP_CREATE_FUNC crtInst = 0;
#ifdef WIN32
- crtInst = (APP_CREATE_FUNC)::GetProcAddress( libHandle, APP_CREATE_NAME );
+ crtInst = (APP_CREATE_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_CREATE_NAME );
#else
crtInst = (APP_CREATE_FUNC)dlsym( libHandle, APP_CREATE_NAME );
#endif
if ( !crtInst )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ),
+ tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ) );
return 0;
}
SUIT_Application* anApp = crtInst();
if ( !anApp )
{
- SUIT_MessageBox::warn1( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warning( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ) );
return 0;
}
- anApp->setName( appName );
+ anApp->setObjectName( appName );
- connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ),
- this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
- connect( anApp, SIGNAL( activated( SUIT_Application* ) ),
- this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
-
- myAppList.append( anApp );
+ insertApplication( anApp );
if ( !myHandler )
{
APP_GET_HANDLER_FUNC crtHndlr = 0;
#ifdef WIN32
- crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( libHandle, APP_GET_HANDLER_NAME );
+ crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_GET_HANDLER_NAME );
#else
crtHndlr = (APP_GET_HANDLER_FUNC)dlsym( libHandle, APP_GET_HANDLER_NAME );
#endif
/*!
Gets the list of all applications
*/
-QPtrList<SUIT_Application> SUIT_Session::applications() const
+QList<SUIT_Application*> SUIT_Session::applications() const
+{
+ return myAppList;
+}
+
+void SUIT_Session::insertApplication( SUIT_Application* app )
{
- QPtrList<SUIT_Application> apps;
- apps.setAutoDelete( false );
+ if ( !app || myAppList.contains( app ) )
+ return;
- for ( AppListIterator it( myAppList ); it.current(); ++it )
- apps.append( it.current() );
+ myAppList.append( app );
- return apps;
+ connect( app, SIGNAL( applicationClosed( SUIT_Application* ) ),
+ this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
+ connect( app, SIGNAL( activated( SUIT_Application* ) ),
+ this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
}
/*!
{
emit applicationClosed( theApp );
- myAppList.remove( theApp );
+ myAppList.removeAll( theApp );
+ delete theApp;
+
if ( theApp == myActiveApp )
myActiveApp = 0;
if ( myAppList.isEmpty() )
{
- printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus );
- qApp->exit( myExitStatus );
+ //printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus );
+ QApplication::instance()->exit( myExitStatus );
}
}
/*!
Destroys session by closing all applications.
*/
-void SUIT_Session::closeSession( int mode )
+void SUIT_Session::closeSession( int mode, int flags )
{
- while ( !myAppList.isEmpty() )
+ AppList apps = myAppList;
+ for ( AppList::const_iterator it = apps.begin(); it != apps.end(); ++it )
{
- SUIT_Application* app = myAppList.getFirst();
- if ( mode == ASK && !app->isPossibleToClose() )
+ SUIT_Application* app = *it;
+ bool closePermanently;
+ if ( mode == ASK && !app->isPossibleToClose( closePermanently ) )
return;
else if ( mode == SAVE )
{
SUIT_Study* study = app->activeStudy();
if ( study->isModified() && study->isSaved() )
- study->saveDocument();
+ study->saveDocument();
}
else if ( mode == DONT_SAVE )
{
- myExitStatus = FROM_CORBA_SESSION;
- //....
+ myExitStatus = FORCED;
}
app->closeApplication();
}
+
+ myExitFlags = flags;
+}
+
+/*!
+ Get session exit flags.
+
+ 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
+*/
+int SUIT_Session::exitFlags() const
+{
+ return myExitFlags;
}
/*! \retval return myHandler*/
QString SUIT_Session::lastError() const
{
QString str;
-#ifdef WNT
+#ifdef WIN32
LPVOID lpMsgBuf;
::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 );
- str = QString( (LPTSTR)lpMsgBuf );
+ LPTSTR msg = (LPTSTR)lpMsgBuf;
+ str = QString( SUIT_Tools::toQString( msg ) );
LocalFree( lpMsgBuf );
#else
str = QString( dlerror() );
return 0;
AppLib lib = 0;
+ QByteArray bid = libFile.toLatin1();
#ifdef WIN32
- lib = ::LoadLibrary( (char*)libFile.latin1() );
+#ifdef UNICODE
+ LPTSTR str = (LPTSTR)libFile.utf16();
+#else
+ LPTSTR str = (LPTSTR)(const char*)bid;
+#endif
+ lib = ::LoadLibrary( str );
#else
- lib = dlopen( (char*)libFile.latin1(), RTLD_LAZY /*| RTLD_GLOBAL */ );
+ lib = dlopen( (const char*)libFile.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
#endif
return lib;
}
*/
SUIT_ResourceMgr* SUIT_Session::createResourceMgr( const QString& appName ) const
{
- return new SUIT_ResourceMgr( appName );
+ return new SUIT_ResourceMgr( applicationName( appName ) );
}
/*!