Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "SMESHGUI_FileValidator.h"
00026
00027
00028 #include <SUIT_MessageBox.h>
00029 #include <SUIT_Tools.h>
00030
00031
00032 #include <QFileInfo>
00033
00034
00035
00036
00037
00038 SMESHGUI_FileValidator::SMESHGUI_FileValidator( QWidget* parent )
00039 : SUIT_FileValidator( parent ),
00040 myIsOverwrite( true )
00041 {
00042 }
00043
00044
00045
00046
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
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 }