<commit_before>// Copyright (C) 2007-2013  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, <NAME>
//
// 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 : <EMAIL>
//

//#if defined WIN32
//#ifdef SUIT_ENABLE_PYTHON
//#undef SUIT_ENABLE_PYTHON
//#endif
//#else //#if defined WIN32
//#ifndef SUIT_ENABLE_PYTHON
// NOTE: DO NOT DELETE THIS DEFINITION ON LINUX
// or make sure Python is initialized in main() in any case
// Otherwise, application based on light SALOME and using Python 
// are unlikely to work properly.
//#define SUIT_ENABLE_PYTHON
//#include <Python.h>
//#endif
//
#ifdef SUIT_ENABLE_PYTHON
#include "SUITApp_init_python.hxx"
#endif

//#endif //#if defined WIN32

#include "GUI_version.h"
#include "SUITApp_Application.h"
#include "SUIT_Desktop.h"
#include "SUIT_LicenseDlg.h"
#include "SUIT_ResourceMgr.h"
#include "SUIT_Session.h"
#include "Style_Salome.h"
#include "QtxSplash.h"

#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QString>
#include <QStringList>

#include <stdlib.h>

#ifdef WIN32
#include <UserEnv.h>
#endif

static QString salomeVersion()
{
  return GUI_VERSION_STR;
}

static QString getAppName( const QString& libName )
{
  QString appName = QFileInfo( libName ).baseName();
  if ( appName.startsWith( "lib" ) ) appName = appName.mid( 3 );
  return appName;
}

// static void MessageOutput( QtMsgType type, const char* msg )
// {
//   switch ( type )
//   {
//   case QtDebugMsg:
// #ifdef _DEBUG_
//     printf( "Debug: %s\n", msg );
// #endif
//     break;
//   case QtWarningMsg:
// #ifdef _DEBUG_
//     printf( "Warning: %s\n", msg );
// #endif
//     break;
//   case QtFatalMsg:
// #ifdef _DEBUG_
//     printf( "Fatal: %s\n", msg );
// #endif
//     break;
//   default:
//     break;
//   }
// }

/* XPM */
static const char* pixmap_not_found_xpm[] = {
"16 16 3 1",
"       c None",
".      c #000000",
"+      c #A80000",
"                ",
"                ",
"    .     .     ",
"   .+.   .+.    ",
"  .+++. .+++.   ",
"   .+++.+++.    ",
"    .+++++.     ",
"     .+++.      ",
"    .+++++.     ",
"   .+++.+++.    ",
"  .+++. .+++.   ",
"   .+.   .+.    ",
"    .     .     ",
"                ",
"                ",
"                "};

class SUITApp_Session: public SUIT_Session
{
public:
  SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
  virtual ~SUITApp_Session() {}

  virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
  {
    SUIT_ResourceMgr* resMgr = 0;
    if ( myIniFormat )
    {
      resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
      resMgr->setCurrentFormat( "ini" );
    }
    else
    {
      resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
      resMgr->setVersion( salomeVersion() );
      resMgr->setCurrentFormat( "xml" );
    }

    if ( resMgr )
    {
      static QPixmap defaultPixmap( pixmap_not_found_xpm );
      resMgr->setDefaultPixmap( defaultPixmap );
      resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
    }
    return resMgr;
  }

private:
  bool  myIniFormat;
};

int main( int argc, char* argv[] )
{
  //#ifdef SUIT_ENABLE_PYTHON
  //  // First of all initialize Python, as in complex multi-component applications
  //  // someone else might initialize it some way unsuitable for light SALOME!
  //  Py_SetProgramName( argv[0] );
  //  Py_Initialize(); // Initialize the interpreter
  //  PySys_SetArgv( argc,  argv );
  //  PyEval_InitThreads(); // Create (and acquire) the interpreter lock
  //  PyEval_ReleaseLock(); // Let the others use Python API until we need it again
  //#endif

  //qInstallMsgHandler( MessageOutput );

  QStringList argList;
  bool noExceptHandling = false;
  bool iniFormat        = false;
  bool noSplash         = false;
  bool useLicense       = false;
  for ( int i = 1; i < argc; i++ )
  {
    if ( !strcmp( argv[i], "--noexcepthandling" ) )
      noExceptHandling = true;
    else if ( !strcmp( argv[i], "--format=ini") )
      iniFormat = true;
    else if ( !strcmp( argv[i], "--nosplash") )
      noSplash = true;
    else if ( !strcmp( argv[i], "--uselicense" ) )
      useLicense = true;
    else
      argList.append( QString( argv[i] ) );
  }

  // add $QTDIR/plugins to the pluins search path for image plugins
  QString qtdir( ::getenv( "QTDIR" ) );
  if ( !qtdir.isEmpty() )
    QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
  
  SUITApp_Application app( argc, argv );
  QString cfgAppName = getAppName( argList.isEmpty() ? QString() : argList.first() );
  // hard-coding for LightApp :( no other way to this for the moment
  if ( cfgAppName == "LightApp" ) {
    app.setOrganizationName( "salome" );
    app.setApplicationName( "salome" );
    app.setApplicationVersion( salomeVersion() );
  }

  int result = -1;

  if ( useLicense ) {
    QString env;

#ifdef WIN32
    DWORD aLen=1024;
    char aStr[1024];
    HANDLE aToken=0;
    HANDLE hProcess = GetCurrentProcess();
    OpenProcessToken(hProcess,TOKEN_QUERY,&aToken);
    if( GetUserProfileDirectory( aToken, aStr, &aLen ) )
      env = aStr;

#else
    if ( ::getenv( "HOME" ) )
      env = ::getenv( "HOME" );<commit_msg>Fix problem with slow rendering of the qt widgets on the remote host.<commit_after>// Copyright (C) 2007-2013  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
// 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 : <EMAIL>
//

//#if defined WIN32
//#ifdef SUIT_ENABLE_PYTHON
//#undef SUIT_ENABLE_PYTHON
//#endif
//#else //#if defined WIN32
//#ifndef SUIT_ENABLE_PYTHON
// NOTE: DO NOT DELETE THIS DEFINITION ON LINUX
// or make sure Python is initialized in main() in any case
// Otherwise, application based on light SALOME and using Python 
// are unlikely to work properly.
//#define SUIT_ENABLE_PYTHON
//#include <Python.h>
//#endif
//
#ifdef SUIT_ENABLE_PYTHON
#include "SUITApp_init_python.hxx"
#endif

//#endif //#if defined WIN32

#include "GUI_version.h"
#include "SUITApp_Application.h"
#include "SUIT_Desktop.h"
#include "SUIT_LicenseDlg.h"
#include "SUIT_ResourceMgr.h"
#include "SUIT_Session.h"
#include "Style_Salome.h"
#include "QtxSplash.h"

#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QString>
#include <QStringList>

#include <stdlib.h>

#ifdef WIN32
#include <UserEnv.h>
#endif

static QString salomeVersion()
{
  return GUI_VERSION_STR;
}

static QString getAppName( const QString& libName )
{
  QString appName = QFileInfo( libName ).baseName();
  if ( appName.startsWith( "lib" ) ) appName = appName.mid( 3 );
  return appName;
}

// static void MessageOutput( QtMsgType type, const char* msg )
// {
//   switch ( type )
//   {
//   case QtDebugMsg:
// #ifdef _DEBUG_
//     printf( "Debug: %s\n", msg );
// #endif
//     break;
//   case QtWarningMsg:
// #ifdef _DEBUG_
//     printf( "Warning: %s\n", msg );
// #endif
//     break;
//   case QtFatalMsg:
// #ifdef _DEBUG_
//     printf( "Fatal: %s\n", msg );
// #endif
//     break;
//   default:
//     break;
//   }
// }

/* XPM */
static const char* pixmap_not_found_xpm[] = {
"16 16 3 1",
"       c None",
".      c #000000",
"+      c #A80000",
"                ",
"                ",
"    .     .     ",
"   .+.   .+.    ",
"  .+++. .+++.   ",
"   .+++.+++.    ",
"    .+++++.     ",
"     .+++.      ",
"    .+++++.     ",
"   .+++.+++.    ",
"  .+++. .+++.   ",
"   .+.   .+.    ",
"    .     .     ",
"                ",
"                ",
"                "};

class SUITApp_Session: public SUIT_Session
{
public:
  SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
  virtual ~SUITApp_Session() {}

  virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
  {
    SUIT_ResourceMgr* resMgr = 0;
    if ( myIniFormat )
    {
      resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
      resMgr->setCurrentFormat( "ini" );
    }
    else
    {
      resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
      resMgr->setVersion( salomeVersion() );
      resMgr->setCurrentFormat( "xml" );
    }

    if ( resMgr )
    {
      static QPixmap defaultPixmap( pixmap_not_found_xpm );
      resMgr->setDefaultPixmap( defaultPixmap );
      resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
    }
    return resMgr;
  }

private:
  bool  myIniFormat;
};

int main( int argc, char* argv[] )
{
  //#ifdef SUIT_ENABLE_PYTHON
  //  // First of all initialize Python, as in complex multi-component applications
  //  // someone else might initialize it some way unsuitable for light SALOME!
  //  Py_SetProgramName( argv[0] );
  //  Py_Initialize(); // Initialize the interpreter
  //  PySys_SetArgv( argc,  argv );
  //  PyEval_InitThreads(); // Create (and acquire) the interpreter lock
  //  PyEval_ReleaseLock(); // Let the others use Python API until we need it again
  //#endif

  //qInstallMsgHandler( MessageOutput );

  QStringList argList;
  bool noExceptHandling = false;
  bool iniFormat        = false;
  bool noSplash         = false;
  bool useLicense       = false;
  for ( int i = 1; i < argc; i++ )
  {
    if ( !strcmp( argv[i], "--noexcepthandling" ) )
      noExceptHandling = true;
    else if ( !strcmp( argv[i], "--format=ini") )
      iniFormat = true;
    else if ( !strcmp( argv[i], "--nosplash") )
      noSplash = true;
    else if ( !strcmp( argv[i], "--uselicense" ) )
      useLicense = true;
    else
      argList.append( QString( argv[i] ) );
  }

  // add $QTDIR/plugins to the pluins search path for image plugins
  QString qtdir( ::getenv( "QTDIR" ) );
  if ( !qtdir.isEmpty() )
    QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );

  //Set a "native" graphic system in case if application runs on the remote host
  QString remote(::getenv("REMOTEHOST"));
  QString client(::getenv("SSH_CLIENT"));
  if(remote.length() > 0 || client.length() > 0 ) {
    QApplication::setGraphicsSystem(QLatin1String("native"));
  }
  
  SUITApp_Application app( argc, argv );
  QString cfgAppName = getAppName( argList.isEmpty() ? QString() : argList.first() );
  // hard-coding for LightApp :( no other way to this for the moment
  if ( cfgAppName == "LightApp" ) {
    app.setOrganizationName( "salome" );
    app.setApplicationName( "salome" );
    app.setApplicationVersion( salomeVersion() );
  }

  int result = -1;

  if ( useLicense ) {
    QString env;

#ifdef WIN32
    DWORD aLen=1024;
    char aStr[1024];
    HANDLE aToken=0;
    HANDLE hProcess = GetCurrentProcess();
    OpenProcessToken(hProcess,TOKEN_QUERY,&aToken);
    if( GetUserProfileDirectory( aToken, aStr, &aLen ) )
      env = aStr;

#else
    if ( ::getenv( "HOME" ) )
      env = ::getenv( "HOME" );
{'fraction_non_alphanumeric': 0.14621494569622306, 'fraction_numerical': 0.01256281407035176, 'mean_word_length': 2.7584526347852574, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5796343', 'n_tokens_mistral': 4425, 'n_tokens_neox': 4234, 'n_words': 1176}