1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUIT_FileValidator.cxx
12 #include "SUIT_FileValidator.h"
13 #include "SUIT_MessageBox.h"
14 #include "SUIT_Session.h"
17 #include <qfileinfo.h>
20 SUIT_FileValidator::SUIT_FileValidator(QWidget* parent) :
25 /* returns false if can't open file */
26 bool SUIT_FileValidator::canOpen( const QString& file )
28 if ( !QFile::exists( file ) ) {
29 SUIT_MessageBox::error1( myParent,
30 QObject::tr( "ERR_ERROR" ),
31 QObject::tr( "ERR_FILE_NOT_EXIST" ).arg( file ),
32 QObject::tr( "BUT_OK" ) );
35 if ( !QFileInfo( file ).isReadable() ) {
36 SUIT_MessageBox::error1( myParent,
37 QObject::tr( "ERR_ERROR" ),
38 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
39 QObject::tr( "BUT_OK" ) );
45 /* returns false if can't save file */
46 bool SUIT_FileValidator::canSave( const QString& file )
48 if ( QFile::exists( file ) ) {
49 // if file exists - raise warning...
50 if ( SUIT_MessageBox::warn2( myParent,
51 QObject::tr( "WRN_WARNING" ),
52 QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
53 QObject::tr( "BUT_YES" ),
54 QObject::tr( "BUT_NO" ),
57 SUIT_NO ) == SUIT_NO ) {
60 // ... and if user wants to overwrite file, check it for writeability
61 if ( !QFileInfo( file ).isWritable() ) {
62 SUIT_MessageBox::error1( myParent,
63 QObject::tr( "ERR_ERROR" ),
64 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
65 QObject::tr( "BUT_OK" ) );
70 // if file doesn't exist - try to create it
72 if ( !qf.open( IO_WriteOnly ) ) {
73 SUIT_MessageBox::error1( myParent,
74 QObject::tr( "ERR_ERROR" ),
75 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
76 QObject::tr( "BUT_OK" ) );
80 // remove just created file