Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_FileDlg.cxx
1 //  SALOME SALOMEGUI : GUI of VISU module
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_FileDlg.cxx
8 //  Author : 
9 //  Module : SALOME
10 //  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx
11
12
13 #include <qapplication.h>
14 #include <qpushbutton.h>
15 #include <qcheckbox.h>
16 #include <qstring.h>
17 #include <qlabel.h>
18
19 #include "VISUConfig.hh"
20 #include "VisuGUI_FileDlg.h"
21 #include "SUIT_ResourceMgr.h"
22
23 using namespace std;
24
25 bool VisuGUI_FileDlg::IsBuild = false; 
26
27 /*!
28 Constructor
29 */
30 VisuGUI_FileDlg::VisuGUI_FileDlg (QWidget* parent, 
31                                   bool open, 
32                                   bool showQuickDir, 
33                                   bool modal) :
34   SUIT_FileDlg(parent, open, showQuickDir, modal)
35
36   myCBuildAll = new QCheckBox (tr("FULL_LOAD"), this);
37   QLabel* label = new QLabel("", this);
38   label->setMaximumWidth(0);
39   QPushButton* pb = new QPushButton(this);               
40   pb->setMaximumWidth(0);
41   addWidgets( label, myCBuildAll, pb );
42   bool toBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
43   if (toBuildAll) myCBuildAll->setChecked(true);
44 }
45
46 /*!
47   Destructor
48 */
49 VisuGUI_FileDlg::~VisuGUI_FileDlg() 
50 {
51 }
52
53 /*!
54   Processes selection : tries to set given path or filename as selection
55 */
56 bool VisuGUI_FileDlg::processPath( const QString& path )
57 {
58   if ( !path.isNull() ) {
59     QFileInfo fi( path );
60     if ( fi.exists() ) {
61       if ( fi.isFile() )
62         setSelection( path );
63       else if ( fi.isDir() )
64         setDir( path );
65       return true;
66     }
67     else {
68       if ( QFileInfo( fi.dirPath() ).exists() ) {
69         setDir( fi.dirPath() );
70         return true;
71       }
72     }
73   }
74   return false;
75 }
76
77 /*!
78   Returns the file name for Open/Save [ static ]
79 */
80 QString VisuGUI_FileDlg::getFileName( QWidget*           parent, 
81                                       const QString&     initial, 
82                                       const QStringList& filters, 
83                                       const QString&     caption,
84                                       bool               open,
85                                       bool               showQuickDir,
86                                       SUIT_FileValidator* validator )
87 {            
88   VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true );    
89   if ( !caption.isEmpty() )
90     fd->setCaption( caption );
91   if ( !initial.isEmpty() ) { 
92     fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug
93   }
94   fd->setFilters( filters );        
95   if ( validator )
96     fd->setValidator( validator );
97   fd->exec();
98   QString filename = fd->selectedFile();
99   
100   VisuGUI_FileDlg::IsBuild = fd->IsChecked();
101   
102   delete fd;
103   qApp->processEvents();
104   
105   return filename;
106 }
107
108 bool VisuGUI_FileDlg::IsChecked() 
109 {
110   return myCBuildAll->isChecked();
111 }