From: mkr Date: Thu, 26 Jan 2006 14:28:08 +0000 (+0000) Subject: Fix for bug PAL8557 : "Export to Library" doesn't create ".salome" directory in home... X-Git-Tag: mergeto_trunk_07Feb06~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dc5522c1bfff6ec3d90c714abd0c030b369d8e4b;p=modules%2Fsuperv.git Fix for bug PAL8557 : "Export to Library" doesn't create ".salome" directory in home if it isn't exist. --- diff --git a/src/SUPERVGUI/SUPERVGUI_Library.cxx b/src/SUPERVGUI/SUPERVGUI_Library.cxx index 4af1b37..044f5de 100644 --- a/src/SUPERVGUI/SUPERVGUI_Library.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Library.cxx @@ -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 diff --git a/src/SUPERVGUI/SUPERV_msg_en.po b/src/SUPERVGUI/SUPERV_msg_en.po index 706508f..95ee79d 100644 --- a/src/SUPERVGUI/SUPERV_msg_en.po +++ b/src/SUPERVGUI/SUPERV_msg_en.po @@ -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"