]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_FileValidator.cxx
Salome HOME
Clean up Python features
[modules/gui.git] / src / LightApp / LightApp_FileValidator.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 // File   : LightApp_FileValidator.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21
22 #include "LightApp_FileValidator.h"
23 #include "SUIT_MessageBox.h"
24
25 #include <QFileInfo>
26
27 /*!
28   \class LightApp_PyFileValidator
29   \brief Validator for Python scripts file names. 
30 */
31
32 /*!
33   \brief Constructor
34   \param parent parent widget
35 */
36 LightApp_PyFileValidator::LightApp_PyFileValidator( QWidget* parent )
37   : SUIT_FileValidator ( parent )
38 {
39 }
40
41 /*!
42   \brief Check if the specified file can be written.
43
44   Checks if file name is valid for Python script.
45
46   \param fileName file path
47   \param checkPermission if \c true (default) check also file permissions
48   \return \c false if file exists and user rejects file overwriting
49   or if file does not have write permissions (if \a checkPermission is \c true)
50   \sa SUIT_FileValidator
51 */
52 bool LightApp_PyFileValidator::canSave( const QString& fileName, bool checkPermission )
53 {
54   QFileInfo fi( fileName );
55   if ( !QRegExp( "[A-Za-z_][A-Za-z0-9_]*" ).exactMatch( fi.completeBaseName() ) ) {
56     SUIT_MessageBox::critical( parent(),
57                                QObject::tr( "WRN_WARNING" ),
58                                QObject::tr( "WRN_PYTHON_FILE_NAME_BAD" ) );
59     return false;
60   }
61   return SUIT_FileValidator::canSave( fileName, checkPermission );
62 }