Salome HOME
f5ff8534c8eddc13ad23e5f6f8cda44870750fbf
[modules/visu.git] / src / VISUGUI / VisuGUI_FileDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : VisuGUI_FileDlg.cxx
24 //  Author : 
25 //  Module : SALOME
26 //  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx
27 //
28 #include <QApplication>
29 #include <QPushButton>
30 #include <QCheckBox>
31 #include <QString>
32 #include <QLabel>
33
34 #include "VISUConfig.hh"
35 #include "VisuGUI_FileDlg.h"
36 #include "SUIT_ResourceMgr.h"
37
38 using namespace std;
39
40 bool VisuGUI_FileDlg::IsBuild = false; 
41
42 /*!
43 Constructor
44 */
45 VisuGUI_FileDlg::VisuGUI_FileDlg (QWidget* parent, 
46                                   bool open, 
47                                   bool showQuickDir, 
48                                   bool modal) :
49   SUIT_FileDlg(parent, open, showQuickDir, modal)
50
51   myCBuildAll = new QCheckBox (tr("FULL_LOAD"), this);
52
53   QLabel* label = new QLabel("", this);
54   label->setMaximumWidth(0);
55   QPushButton* pb = new QPushButton(this);               
56   pb->setMaximumWidth(0);
57   addWidgets( label, myCBuildAll, pb );
58   
59   bool toBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
60   if (toBuildAll) myCBuildAll->setChecked(true);
61 }
62
63 /*!
64   Destructor
65 */
66 VisuGUI_FileDlg::~VisuGUI_FileDlg() 
67 {
68 }
69
70 /*!
71   Processes selection : tries to set given path or filename as selection
72 */
73 bool VisuGUI_FileDlg::processPath( const QString& path )
74 {
75   if ( !path.isNull() ) {
76     QFileInfo fi( path );
77     if ( fi.exists() ) {
78       if ( fi.isFile() )
79       {
80         setDirectory( fi.absoluteDir().absolutePath() );
81         selectFile( fi.fileName() );
82       }
83       else if ( fi.isDir() )
84         setDirectory( path );
85       return true;
86     }
87     else {
88       if ( QFileInfo( fi.absoluteDir().absolutePath() ).exists() ) {
89         setDirectory( fi.absoluteDir().absolutePath() );
90         return true;
91       }
92     }
93   }
94   return false;
95 }
96
97 /*!
98   Returns the file name for Open/Save [ static ]
99 */
100 QString VisuGUI_FileDlg::getFileName( QWidget*           parent, 
101                                       const QString&     initial, 
102                                       const QStringList& filters, 
103                                       const QString&     caption,
104                                       bool               open,
105                                       bool               showQuickDir,
106                                       SUIT_FileValidator* validator )
107 {            
108   VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true );    
109   if ( !caption.isEmpty() )
110     fd->setWindowTitle( caption );
111   if ( !initial.isEmpty() ) { 
112     fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug
113   }
114   fd->setFilters( filters );        
115   if ( validator )
116     fd->setValidator( validator );
117   fd->exec();
118   QString filename = fd->selectedFile();
119   
120   VisuGUI_FileDlg::IsBuild = fd->IsChecked();
121   
122   delete fd;
123   qApp->processEvents();
124   
125   return filename;
126 }
127
128 bool VisuGUI_FileDlg::IsChecked() 
129 {
130   return myCBuildAll->isChecked();
131 }