2 // File : QAD_FileValidator.cxx
3 // Created : UI team, 17.09.02
4 // Descr : File validator for QFileDlg class
6 // Modified : Tue Sep 17 10:47:01 2002
10 // Copyright : Open CASCADE 2001
13 #include "QAD_FileValidator.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "QAD_MessageBox.h"
19 #include <qfileinfo.h>
22 QAD_FileValidator::QAD_FileValidator(QWidget* parent) :
26 myParent = QAD_Application::getDesktop();
30 /* returns false if can't open file */
31 bool QAD_FileValidator::canOpen( const QString& file )
33 MESSAGE ( "QAD_FileValidator::canOpen" )
34 if ( !QFile::exists( file ) ) {
35 QAD_MessageBox::error1( myParent,
36 QObject::tr( "ERR_ERROR" ),
37 QObject::tr( "ERR_DOC_FILENOTEXIST" ).arg( file ),
38 QObject::tr( "BUT_OK" ) );
41 if ( !QFileInfo( file ).isReadable() ) {
42 QAD_MessageBox::error1( myParent,
43 QObject::tr( "ERR_ERROR" ),
44 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
45 QObject::tr( "BUT_OK" ) );
51 /* returns false if can't save file */
52 bool QAD_FileValidator::canSave( const QString& file )
54 MESSAGE ( "QAD_FileValidator::canSave" )
55 if ( QFile::exists( file ) ) {
56 // if file exists - raise warning...
57 if ( QAD_MessageBox::warn2( myParent,
58 QObject::tr( "WRN_WARNING" ),
59 QObject::tr( "QUE_DOC_FILEEXISTS" ).arg( file ),
60 QObject::tr( "BUT_YES" ),
61 QObject::tr( "BUT_NO" ),
64 QAD_NO ) == QAD_NO ) {
67 // ... and if user wants to overwrite file, check it for writeability
68 if ( !QFileInfo( file ).isWritable() ) {
69 QAD_MessageBox::error1( myParent,
70 QObject::tr( "ERR_ERROR" ),
71 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
72 QObject::tr( "BUT_OK" ) );
77 // if file doesn't exist - try to create it
79 if ( !qf.open( IO_WriteOnly ) ) {
80 QAD_MessageBox::error1( myParent,
81 QObject::tr( "ERR_ERROR" ),
82 QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ),
83 QObject::tr( "BUT_OK" ) );
87 // remove just created file