Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / SUIT / SUIT_FileValidator.cxx
index d2afda00ed9c4f00d25d96294bfa3d0698eb7726..cbe7250cd527a233bdb1d93ed89f77a3dbc5493c 100755 (executable)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
+// 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 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.
+// 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
+// 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 : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // File   : SUIT_FileValidator.cxx
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 //
@@ -60,13 +61,13 @@ bool SUIT_FileValidator::canOpen( const QString& fileName, bool checkPermission
   if ( !QFile::exists( fileName ) ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( fileName ) );
+                                 QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( fileName ) );
     return false;
   }
   if ( checkPermission && !QFileInfo( fileName ).isReadable() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_PERMISSION_DENIED" ).arg( fileName ) );
+                                 QObject::tr( "ERR_OPEN_PERMISSION_DENIED" ).arg( fileName ) );
     return false; 
   }
   return true;
@@ -91,24 +92,29 @@ bool SUIT_FileValidator::canSave( const QString& fileName, bool checkPermission
   if ( QFile::exists( fileName ) ) {
     if ( parent() )
       if ( SUIT_MessageBox::question( parent(), QObject::tr( "WRN_WARNING" ),
-                                     QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( fileName ),
-                                     SUIT_MessageBox::Yes | SUIT_MessageBox::No,
-                                     SUIT_MessageBox::No ) != SUIT_MessageBox::Yes )
-       return false;
+                                      QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( fileName ),
+                                      SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+                                      SUIT_MessageBox::No ) != SUIT_MessageBox::Yes )
+        return false;
     
     if ( checkPermission && !QFileInfo( fileName ).isWritable() ) {
       if ( parent() ) 
-       SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
-                                  QObject::tr( "ERR_PERMISSION_DENIED" ).arg( fileName ) );
+        SUIT_MessageBox::critical( myParent, QObject::tr( "ERR_ERROR" ),
+                                   QObject::tr( "ERR_PERMISSION_DENIED" ).arg( fileName ) );
       return false; 
     }
   }
   else {
     QString dirName = SUIT_Tools::dir( fileName );
+    if ( !QFile::exists( dirName ) ) {
+      SUIT_MessageBox::critical( parent(), QObject::tr( "WRN_WARNING" ),
+                                 QObject::tr( "ERR_DIR_NOT_EXIST" ).arg( dirName ) );
+      return false;
+    }
     if ( checkPermission && !QFileInfo( dirName ).isWritable() ) {
       if ( parent() )
-       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                  QObject::tr( "ERR_PERMISSION_DENIED" ).arg( fileName ) );
+        SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
+                                   QObject::tr( "ERR_PERMISSION_DENIED" ).arg( fileName ) );
       return false;
     }
   }
@@ -132,19 +138,19 @@ bool SUIT_FileValidator::canReadDir( const QString& dirName, bool checkPermissio
   if ( !info.exists() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_DIR_NOT_EXIST" ).arg( dirName ) );
+                                 QObject::tr( "ERR_DIR_NOT_EXIST" ).arg( dirName ) );
     return false;
   }
   if ( !info.isDir() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_FILE_NOT_DIR" ).arg( dirName ) );
+                                 QObject::tr( "ERR_FILE_NOT_DIR" ).arg( dirName ) );
     return false;
   }
   if ( checkPermission && !info.isReadable() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_PERMISSION_DENIED" ).arg( dirName ) );
+                                 QObject::tr( "ERR_DIR_READ_PERMISSION_DENIED" ).arg( dirName ) );
     return false; 
   }
   return true;
@@ -167,19 +173,19 @@ bool SUIT_FileValidator::canWriteDir( const QString& dirName, bool checkPermissi
   if ( !info.exists() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_DIR_NOT_EXIST" ).arg( dirName ) );
+                                 QObject::tr( "ERR_DIR_NOT_EXIST" ).arg( dirName ) );
     return false;
   }
   if ( !info.isDir() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_FILE_NOT_DIR" ).arg( dirName ) );
+                                 QObject::tr( "ERR_FILE_NOT_DIR" ).arg( dirName ) );
     return false;
   }
   if ( checkPermission && !info.isWritable() ) {
     if ( parent() )
       SUIT_MessageBox::critical( parent(), QObject::tr( "ERR_ERROR" ),
-                                QObject::tr( "ERR_PERMISSION_DENIED" ).arg( dirName ) );
+                                 QObject::tr( "ERR_DIR_WRITE_PERMISSION_DENIED" ).arg( dirName ) );
     return false; 
   }
   return true;