Salome HOME
Issue 0020514: EDF 1110 SMESH : Export many meshes in one Med File
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FileValidator.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_FileValidator.cxx
24 // Author : Oleg UVAROV
25 // SMESH includes
26 //
27 #include "SMESHGUI_FileValidator.h"
28
29 // SALOME GUI includes
30 #include <SUIT_MessageBox.h>
31 #include <SUIT_Tools.h>
32
33 // Qt includes
34 #include <QFileInfo>
35
36 //=======================================================================
37 //function : SMESHGUI_FileValidator
38 //purpose  : 
39 //=======================================================================
40 SMESHGUI_FileValidator::SMESHGUI_FileValidator( QWidget* parent )
41 : SUIT_FileValidator( parent ),
42   myIsOverwrite( true )
43 {
44 }
45   
46 //=======================================================================
47 //function : canSave
48 //purpose  : 
49 //=======================================================================
50 bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermission ) 
51 {
52   if ( QFile::exists( fileName ) ) {
53     if ( parent() ) {
54       int anAnswer = SUIT_MessageBox::question( parent(), QObject::tr( "SMESH_WRN_WARNING" ),
55                                                 QObject::tr( "SMESH_FILE_EXISTS" ).arg( fileName ),
56                                                 QObject::tr( "SMESH_BUT_OVERWRITE" ),
57                                                 QObject::tr( "SMESH_BUT_ADD" ),
58                                                 QObject::tr( "SMESH_BUT_CANCEL" ), 0, 2 );
59       if( anAnswer == 2 )
60         return false;
61       myIsOverwrite = anAnswer == 0;
62     }
63
64     // copied from SUIT_FileValidator
65     if ( checkPermission && !QFileInfo( fileName ).isWritable() ) {
66       if ( parent() ) 
67         SUIT_MessageBox::critical( parent(), QObject::tr( "SMESH_ERROR" ),
68                                    QObject::tr( "NO_PERMISSION" ).arg( fileName ) );
69       return false; 
70     }
71   }
72   else {
73     return SUIT_FileValidator::canSave( fileName, checkPermission );
74   }
75   return true;
76 }