Back to index

salome-smesh  6.5.0
SMESHGUI_FileValidator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // SMESH SMESHGUI : GUI for SMESH component
00021 // File   : SMESHGUI_FileValidator.cxx
00022 // Author : Oleg UVAROV
00023 // SMESH includes
00024 //
00025 #include "SMESHGUI_FileValidator.h"
00026 
00027 // SALOME GUI includes
00028 #include <SUIT_MessageBox.h>
00029 #include <SUIT_Tools.h>
00030 
00031 // Qt includes
00032 #include <QFileInfo>
00033 
00034 //=======================================================================
00035 //function : SMESHGUI_FileValidator
00036 //purpose  : 
00037 //=======================================================================
00038 SMESHGUI_FileValidator::SMESHGUI_FileValidator( QWidget* parent )
00039 : SUIT_FileValidator( parent ),
00040   myIsOverwrite( true )
00041 {
00042 }
00043   
00044 //=======================================================================
00045 //function : canSave
00046 //purpose  : 
00047 //=======================================================================
00048 bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermission ) 
00049 {
00050   if ( QFile::exists( fileName ) ) {
00051     if ( parent() ) {
00052       int anAnswer = SUIT_MessageBox::question( parent(), QObject::tr( "SMESH_WRN_WARNING" ),
00053                                                 QObject::tr( "SMESH_FILE_EXISTS" ).arg( fileName ),
00054                                                 QObject::tr( "SMESH_BUT_OVERWRITE" ),
00055                                                 QObject::tr( "SMESH_BUT_ADD" ),
00056                                                 QObject::tr( "SMESH_BUT_CANCEL" ), 0, 2 );
00057       if( anAnswer == 2 )
00058         return false;
00059       myIsOverwrite = anAnswer == 0;
00060     }
00061 
00062     // copied from SUIT_FileValidator
00063     if ( checkPermission && !QFileInfo( fileName ).isWritable() ) {
00064       if ( parent() ) 
00065         SUIT_MessageBox::critical( parent(), QObject::tr( "SMESH_ERROR" ),
00066                                    QObject::tr( "NO_PERMISSION" ).arg( fileName ) );
00067       return false; 
00068     }
00069   }
00070   else {
00071     return SUIT_FileValidator::canSave( fileName, checkPermission );
00072   }
00073   return true;
00074 }