Salome HOME
Updated copyright comment
[modules/gui.git] / src / CAM / CAM_Application.cxx
index 8dab93d7152bd622e51fb53848467e8e76e35bf4..e6b0d5f3a8f2f501356ae44df237e9ad52d26902 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -38,6 +38,7 @@
 #include <QApplication>
 #include <QDir>
 #include <QFileInfo>
+#include <QLockFile>
 #include <QMutex>
 #include <QMutexLocker>
 #include <QRegExp>
@@ -467,7 +468,10 @@ bool CAM_Application::activateModule( CAM_Module* mod )
   {
     if ( myModule->deactivateModule( activeStudy() ) )
     {
-      logUserEvent( tr( "MODULE_DEACTIVATED" ).arg( myModule->moduleName() ) );
+      logStructuredUserEvent( myModule->moduleName(),
+                              "",
+                              "",
+                              "deactivated" );
     }
     moduleDeactivated( myModule );
   }
@@ -479,7 +483,10 @@ bool CAM_Application::activateModule( CAM_Module* mod )
     myModule->connectToStudy( dynamic_cast<CAM_Study*>( activeStudy() ) );
     if ( myModule->activateModule( activeStudy() ) )
     {
-      logUserEvent( tr( "MODULE_ACTIVATED" ).arg( myModule->moduleName() ) );
+      logStructuredUserEvent( myModule->moduleName(),
+                              "",
+                              "",
+                              "activated" );
     }
     else
     {
@@ -507,7 +514,8 @@ bool CAM_Application::activateModule( CAM_Module* mod )
   \param actionId is a numerical unique operation identifier
   \return \c true in case of success and \c false otherwise
 */
-bool CAM_Application::activateOperation( const QString& modName, int actionId )
+bool CAM_Application::activateOperation( const QString& modName,
+                                         const int actionId )
 {
   CAM_Module* mod = loadModule(modName, false);
   if (mod) {
@@ -524,7 +532,8 @@ bool CAM_Application::activateOperation( const QString& modName, int actionId )
   \param actionId is a string unique operation identifier
   \return \c true in case of success and \c false otherwise
 */
-bool CAM_Application::activateOperation( const QString& modName, const QString& actionId )
+bool CAM_Application::activateOperation( const QString& modName,
+                                         const QString& actionId )
 {
   CAM_Module* mod = loadModule(modName, false);
   if (mod) {
@@ -1030,14 +1039,39 @@ void CAM_Application::logUserEvent( const QString& eventDescription )
     QFile file ( guiLogFile );
     if ( file.open( QFile::Append ) ) // append to log file
     {
+      // lock for multiple processes, if more than one salome instance
+      // is running on the same computer.
+      QString lockFilename = file.fileName() + ".lock";
+      QLockFile fLock( lockFilename );
+      fLock.lock();
+
       QDateTime current = QDateTime::currentDateTime();
       QTextStream stream( &file );
-      stream << current.toString("yyyyMMdd-hhmmss") << ": " << eventDescription << endl;
+      stream << current.toString("yyyyMMdd-hhmmss")
+             << "," << eventDescription
+             << endl;
+
+      fLock.unlock();
       file.close();
     }
   }
 }
 
+void CAM_Application::logStructuredUserEvent( const QString& module,
+                                              const QString& section,
+                                              const QString& action,
+                                              const QString& event,
+                                              const QString& message )
+{
+  const QStringList mes = (QStringList() << module
+                           << section
+                           << action
+                           << event
+                           << message);
+
+  logUserEvent( mes.join( "," ) );
+}
+
 /*!
   \brief Log given action.
   \param action GUI action being logged.
@@ -1050,21 +1084,24 @@ void CAM_Application::logAction( QAction* action, const QString& moduleName )
     text = action->text();
   if ( text.isEmpty() )
     text = action->iconText();
+
   if ( !text.isEmpty() )
   {
-    QStringList message;
-    if ( !moduleName.isEmpty() )
-      message << moduleName;
     if ( action->isCheckable() )
     {
-      message << tr( "ACTION_TOGGLED" );
-      message << ( action->isChecked() ? tr( "ACTION_ON" ) : tr( "ACTION_OFF" ) );
+      logStructuredUserEvent ( moduleName,
+                               "",
+                               "toggled",
+                               action->isChecked() ? "on" : "off",
+                               text );
     }
     else
     {
-      message << tr( "ACTION_TRIGGERED" );
+      logStructuredUserEvent ( moduleName,
+                               "",
+                               "triggered",
+                               "",
+                               text );
     }
-    message << text;
-    logUserEvent( message.join( ": " ) );
   }
 }