]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
Fix for bug PAL8557 : "Export to Library" doesn't create ".salome" directory in home...
authormkr <mkr@opencascade.com>
Thu, 26 Jan 2006 14:28:08 +0000 (14:28 +0000)
committermkr <mkr@opencascade.com>
Thu, 26 Jan 2006 14:28:08 +0000 (14:28 +0000)
src/SUPERVGUI/SUPERVGUI_Library.cxx
src/SUPERVGUI/SUPERV_msg_en.po

index 4af1b37b8e2a09ded89effeb1437cd38e240d44d..044f5de08f9d9ff0c70b4fd7cd8539c427058854 100644 (file)
@@ -101,8 +101,33 @@ bool SUPERVGUI_Library::createLibFile() const {
       return true;
     }
     else {
-      SUIT_MessageBox::error1( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()), tr( "ERROR" ), tr( "MSG_ERROR_LIB1" ), tr( "OK" ) );
-      return false; // error opening library file for writing
+      // mkr : PAL8557
+      QString aFullPath = GetLibraryFileName();
+      QString aDir = aFullPath.left( aFullPath.findRev('/')+1 );
+      const int toCreateDir = SUIT_MessageBox::warn2( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()), tr( "ERROR" ), 
+                                                     tr( "MSG_ERROR_LIB_DIR_NOT_EXIST_RECREATE" ).arg(aDir), tr( "BUT_YES" ), tr( "BUT_NO" ), 1, 0, 0 );
+      if ( toCreateDir ) { // user selected to create a new ./salome subdirectory in HOME directory
+       
+       // create directory
+       QString aCommand = QString("mkdir ") + aDir;
+       int status = system( aCommand.latin1() );
+       
+       if ( status == -1 || status == 217 ) {
+         SUIT_MessageBox::error1( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()), tr( "ERROR" ), tr( "MSG_ERROR_LIB_RECREATE_DIR" ).arg(aDir), tr( "OK" ) );
+         return false;
+       }
+       
+       // create XML file
+       libFile.open( IO_WriteOnly | IO_Truncate );
+        QDomDocument doc( DOCTYPE ); // create a simple XML stub
+        doc.appendChild( doc.createElement( ROOT_ELEMENT ) ); // IMPORTANT: do not delete this root element
+        QTextStream stream( &libFile );
+        doc.save( stream, 0 );
+        libFile.close();
+        return true;
+      }
+      else // user chose not to create a new ./salome subdirectory in HOME directory
+       return false;
     }
   }
   catch ( ... ) {
@@ -163,6 +188,11 @@ bool SUPERVGUI_Library::Export( SUPERV::INode_var theNode ) const {
                                                      tr( "MSG_ERROR_LIB_IS_RECREATE" ), tr( "BUT_YES" ), tr( "BUT_NO" ), 1, 0, 0 );
       if ( toRecreate ) { // user selected to recreate a bad XML file
        libFile.close(); // in case it was opened by doc.setContent()
+       
+       // remove old bad file
+       QString aCommand = QString("rm -f ") + libFile.name();
+       system( aCommand.latin1() );
+
        if ( !createLibFile() )
          return false; // error opening library file for writing.  MB was already displayed
        
index 706508f8034a993027880202090e18db0ea5a15c..95ee79d497184cee3063e2b526ad35f750d059b0 100644 (file)
@@ -781,13 +781,19 @@ msgid "MSG_ERROR_LIB1"
 msgstr "Error creating a library file and opening for writing."
 
 msgid "MSG_ERROR_LIB_IS_RECREATE"
-msgstr "Library file is corrupt (bad XML structure).  Remove it and create a new one?"
+msgstr "Library file is corrupt (bad XML structure) or read-protected.  Remove it and create a new one?"
+
+msgid "MSG_ERROR_LIB_DIR_NOT_EXIST_RECREATE"
+msgstr "%1 directory doesn't exist. Create it?"
+
+msgid "MSG_ERROR_LIB_RECREATE_DIR"
+msgstr "Can not create %1 directory."
 
 msgid "MSG_ERROR_LIB_IO"
 msgstr "Unknown I/O error occured creating new library file."
 
 msgid "MSG_ERROR_LIB_WRITE"
-msgstr "Error writing library file!"
+msgstr "Error writing library file: file is write-protected!"
 
 msgid "MSG_ERROR_LIB_NIL_NODE"
 msgstr "Error: the node to be exported is NULL"