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