Salome HOME
Fix of the following issues:
[modules/visu.git] / src / VISUGUI / VisuGUI_FileDlg.cxx
1 //  Copyright (C) 2007-2008  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 //  File   : VisuGUI_FileDlg.cxx
23 //  Author : 
24 //  Module : SALOME
25 //  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx
26 //
27 #include <QApplication>
28 #include <QPushButton>
29 #include <QCheckBox>
30 #include <QString>
31 #include <QLabel>
32
33 #include "VISUConfig.hh"
34 #include "VisuGUI_FileDlg.h"
35 #include "SUIT_ResourceMgr.h"
36
37 using namespace std;
38
39 bool VisuGUI_FileDlg::IsBuild = false; 
40
41 /*!
42 Constructor
43 */
44 VisuGUI_FileDlg::VisuGUI_FileDlg (QWidget* parent, 
45                                   bool open, 
46                                   bool showQuickDir, 
47                                   bool modal) :
48   SUIT_FileDlg(parent, open, showQuickDir, modal)
49
50   myCBuildAll = new QCheckBox (tr("FULL_LOAD"), this);
51
52   QLabel* label = new QLabel("", this);
53   label->setMaximumWidth(0);
54   QPushButton* pb = new QPushButton(this);               
55   pb->setMaximumWidth(0);
56   addWidgets( label, myCBuildAll, pb );
57   
58   bool toBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
59   if (toBuildAll) myCBuildAll->setChecked(true);
60 }
61
62 /*!
63   Destructor
64 */
65 VisuGUI_FileDlg::~VisuGUI_FileDlg() 
66 {
67 }
68
69 /*!
70   Processes selection : tries to set given path or filename as selection
71 */
72 bool VisuGUI_FileDlg::processPath( const QString& path )
73 {
74   if ( !path.isNull() ) {
75     QFileInfo fi( path );
76     if ( fi.exists() ) {
77       if ( fi.isFile() )
78       {
79         setDirectory( fi.absoluteDir().absolutePath() );
80         selectFile( fi.fileName() );
81       }
82       else if ( fi.isDir() )
83         setDirectory( path );
84       return true;
85     }
86     else {
87       if ( QFileInfo( fi.absoluteDir().absolutePath() ).exists() ) {
88         setDirectory( fi.absoluteDir().absolutePath() );
89         return true;
90       }
91     }
92   }
93   return false;
94 }
95
96 /*!
97   Returns the file name for Open/Save [ static ]
98 */
99 QString VisuGUI_FileDlg::getFileName( QWidget*           parent, 
100                                       const QString&     initial, 
101                                       const QStringList& filters, 
102                                       const QString&     caption,
103                                       bool               open,
104                                       bool               showQuickDir,
105                                       SUIT_FileValidator* validator )
106 {            
107   VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true );    
108   if ( !caption.isEmpty() )
109     fd->setWindowTitle( caption );
110   if ( !initial.isEmpty() ) { 
111     fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug
112   }
113   fd->setFilters( filters );        
114   if ( validator )
115     fd->setValidator( validator );
116   fd->exec();
117   QString filename = fd->selectedFile();
118   
119   VisuGUI_FileDlg::IsBuild = fd->IsChecked();
120   
121   delete fd;
122   qApp->processEvents();
123   
124   return filename;
125 }
126
127 bool VisuGUI_FileDlg::IsChecked() 
128 {
129   return myCBuildAll->isChecked();
130 }