1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : QAD_FileValidator.cxx
12 #include "QAD_FileValidator.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_MessageBox.h"
17 #include "utilities.h"
20 #include <qfileinfo.h>
25 QAD_FileValidator::QAD_FileValidator(QWidget* parent) :
29 myParent = QAD_Application::getDesktop();
33 /* returns false if can't open file */
34 bool QAD_FileValidator::canOpen( const QString& file )
36 MESSAGE ( "QAD_FileValidator::canOpen" )
37 if ( !QFile::exists( file ) ) {
38 QAD_MessageBox::error1( myParent,
39 QObject::tr( "ERR_ERROR" ),
40 QObject::tr( "ERR_DOC_FILENOTEXIST" ).arg( file ),
41 QObject::tr( "BUT_OK" ) );
44 if ( !QFileInfo( file ).isReadable() ) {
45 QAD_MessageBox::error1( myParent,
46 QObject::tr( "ERR_ERROR" ),
47 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
48 QObject::tr( "BUT_OK" ) );
54 /* returns false if can't save file */
55 bool QAD_FileValidator::canSave( const QString& file )
57 MESSAGE ( "QAD_FileValidator::canSave" )
58 if ( QFile::exists( file ) ) {
59 // if file exists - raise warning...
60 if ( QAD_MessageBox::warn2( myParent,
61 QObject::tr( "WRN_WARNING" ),
62 QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
63 QObject::tr( "BUT_YES" ),
64 QObject::tr( "BUT_NO" ),
67 QAD_NO ) == QAD_NO ) {
70 // ... and if user wants to overwrite file, check it for writeability
71 if ( !QFileInfo( file ).isWritable() ) {
72 QAD_MessageBox::error1( myParent,
73 QObject::tr( "ERR_ERROR" ),
74 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
75 QObject::tr( "BUT_OK" ) );
80 // if file doesn't exist - try to create it
82 if ( !qf.open( IO_WriteOnly ) ) {
83 QAD_MessageBox::error1( myParent,
84 QObject::tr( "ERR_ERROR" ),
85 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
86 QObject::tr( "BUT_OK" ) );
90 // remove just created file