1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
21 // File : SUIT_FileValidator.cxx
25 #include "SUIT_FileValidator.h"
26 #include "SUIT_MessageBox.h"
27 #include "SUIT_Session.h"
30 #include <qfileinfo.h>
33 SUIT_FileValidator::SUIT_FileValidator(QWidget* parent) :
38 /*! returns false if can't open file */
39 bool SUIT_FileValidator::canOpen( const QString& file )
41 if ( !QFile::exists( file ) ) {
42 SUIT_MessageBox::error1( myParent,
43 QObject::tr( "ERR_ERROR" ),
44 QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( file ),
45 QObject::tr( "BUT_OK" ) );
48 if ( !QFileInfo( file ).isReadable() ) {
49 SUIT_MessageBox::error1( myParent,
50 QObject::tr( "ERR_ERROR" ),
51 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
52 QObject::tr( "BUT_OK" ) );
58 /*! returns false if can't save file */
59 bool SUIT_FileValidator::canSave( const QString& file )
61 if ( QFile::exists( file ) ) {
62 // if file exists - raise warning...
63 if ( SUIT_MessageBox::warn2( myParent,
64 QObject::tr( "WRN_WARNING" ),
65 QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
66 QObject::tr( "BUT_YES" ),
67 QObject::tr( "BUT_NO" ),
70 SUIT_NO ) == SUIT_NO ) {
73 // ... and if user wants to overwrite file, check it for writeability
74 if ( !QFileInfo( file ).isWritable() ) {
75 SUIT_MessageBox::error1( myParent,
76 QObject::tr( "ERR_ERROR" ),
77 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
78 QObject::tr( "BUT_OK" ) );
83 // if file doesn't exist - try to create it
85 if ( !qf.open( IO_WriteOnly ) ) {
86 SUIT_MessageBox::error1( myParent,
87 QObject::tr( "ERR_ERROR" ),
88 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
89 QObject::tr( "BUT_OK" ) );
93 // remove just created file