1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SUIT_FileDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 \brief An extension of the Qt Open/Save file dialog box.
29 The class SUIT_FileDlg provides a set of static methods which canbe used
30 for file or directories selection:
31 - getFileName() for single file opening or saving
32 - getOpenFileNames() for mulktiple files opening
33 - getExistingDirectory() for existing directory selection
37 // select file to dump contents of the view
39 filters << "Image files (*.bmp *.gif *.jpg )" << "All files (*)";
40 QString fileName = SUIT_FileDlg::getFileName( desktop(),
45 if ( !fileName.isEmpty() ) {
46 ... writing image to the file
49 // select list of files to open in the editor windows
51 filters << "*.cpp | *.cxx | *.c++" << "*.h | *.hpp | *.hxx";
52 QStringList fileNames = SUIT_FileDlg::getOpenFileName( desktop(),
56 if ( !fileNames.isEmpty() ) {
61 The class SUIT_FileDlg can be subclassed to implement custom file
62 dialog boxes. The class provides a set of methods which can be used
64 - setCheckPermissions() - to enable/disable check of files/directories
66 - setValidator() - to use custom file validator
67 - addWidgets() - to add custom widgets to the lower part of the
69 - getLastVisitedDirectory() - to get last visited directory
70 - acceptData() - can be used ti customize user selection validation
72 \sa SUIT_FileValidator class.
75 #include "SUIT_FileDlg.h"
77 #include "SUIT_Tools.h"
78 #include "SUIT_Session.h"
79 #include "SUIT_MessageBox.h"
80 #include "SUIT_ResourceMgr.h"
81 #include "SUIT_FileValidator.h"
88 #include <QPushButton>
89 #include <QGridLayout>
90 #include <QApplication>
95 \brief Defines extension behavior.
97 If the selected file name has extension which does not match the selected filter
98 and this variable is set to \c true, the file extension is ignored and new one
99 (from current file filter will be added.
102 const bool IGNORE_NON_MATCHING_EXTENSION = true;
104 QString SUIT_FileDlg::myLastVisitedPath;
108 \param parent parent widget
109 \param open if \c true dialog box is used for file opening, otherwise - for saving
110 \param showQuickDir if \c true the quick directory list widgets will be shown
111 \param modal if \c true the dialog box will be modal
113 SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal )
114 : QFileDialog( parent ),
119 myCheckPermissions( true )
122 setSizeGripEnabled( true );
124 setWindowIcon( parent->windowIcon() );
126 // add quick directories widgets
127 if ( showQuickDir ) {
128 myQuickLab = new QLabel( tr( "LAB_QUICK_PATH" ), this );
129 myQuickCombo = new QComboBox( this );
130 myQuickButton = new QPushButton( tr( "BUT_ADD_PATH" ), this );
132 if ( addWidgets( myQuickLab, myQuickCombo, myQuickButton ) ) {
133 connect( myQuickCombo, SIGNAL( activated( const QString& ) ), this, SLOT( quickDir( const QString& ) ) );
134 connect( myQuickButton, SIGNAL( clicked() ), this, SLOT( addQuickDir() ) );
136 // retrieve directories list from the resources
139 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
141 dirList = resMgr->stringValue( "FileDlg", QString( "QuickDirList" ) ).split( ';', QString::SkipEmptyParts );
143 if ( dirList.isEmpty() )
144 dirList << QDir::homePath();
146 for ( int i = 0; i < dirList.count(); i++ )
147 myQuickCombo->addItem( dirList[i] );
150 delete myQuickLab; myQuickLab = 0;
151 delete myQuickCombo; myQuickCombo = 0;
152 delete myQuickButton; myQuickButton = 0;
156 setAcceptMode( open ? AcceptOpen: AcceptSave );
157 setWindowTitle( open ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) );
159 // If last visited path doesn't exist -> switch to the first preferred path
160 if ( !myLastVisitedPath.isEmpty() ) {
161 if ( !processPath( myLastVisitedPath ) && showQuickDir )
162 processPath( myQuickCombo->itemText( 0 ) );
164 else if ( showQuickDir ) {
165 processPath( myQuickCombo->itemText( 0 ) );
168 // set default file validator
169 myValidator = new SUIT_FileValidator( this );
175 SUIT_FileDlg::~SUIT_FileDlg()
182 \brief Check if the dialog box is used for opening or saving the file.
183 \return \c true if dialog is used for file opening and \c false otherwise
185 bool SUIT_FileDlg::isOpenDlg() const
187 return acceptMode() == AcceptOpen;
191 \brief Get 'check file permissions' flag.
193 \sa setCheckPermissions()
195 bool SUIT_FileDlg::checkPermissions() const
197 return myCheckPermissions;
201 \brief Set 'check file permissions' flag.
203 If this flag is set and file validator is not null,
204 the validator will check the file permissions also.
206 \param checkPerm new flag value
207 \sa checkPermissions()
209 void SUIT_FileDlg::setCheckPermissions( const bool checkPerm )
211 myCheckPermissions = checkPerm;
215 \brief Get file validator.
216 \return current file validator
219 SUIT_FileValidator* SUIT_FileDlg::validator() const
225 \brief Set file validator.
227 Destroys previous validator if the dialog owns it.
229 \param v new file validator
232 void SUIT_FileDlg::setValidator( SUIT_FileValidator* v )
234 if ( myValidator && myValidator->parent() == this )
240 \brief Adds the specified widgets to the bottom of the file dialog.
242 The first widget (usually label) \a l is placed underneath the "file name"
243 and the "file types" labels.
244 The widget \a w is placed underneath the file types combobox.
245 The last widget (usually button) \a b is placed underneath the Cancel push button.
247 In general, the widgets can be arbitrary. This method is added to support
248 the functionality provided by the Qt series 3.x.
250 If you don't want to have one of the widgets added, pass 0 in that widget's position.
251 Every time this function is called, a new row of widgets is added to the bottom of the
254 \param l first widget (e.g. text label)
255 \param w second widget (e.g. combo box)
256 \param b third widget (e.g. push button)
257 \return \c true if widgets have been added successfully
259 bool SUIT_FileDlg::addWidgets( QWidget* l, QWidget* w, QWidget* b )
261 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
263 int row = grid->rowCount();
264 int columns = grid->columnCount();
266 grid->addWidget( l, row, 0 );
268 grid->addWidget( w, row, 1, 1, columns-2 );
270 grid->addWidget( b, row, columns-1 );
277 \brief Get list of selected files.
278 \return selected file names
280 QStringList SUIT_FileDlg::selectedFiles() const
282 QStringList files = QFileDialog::selectedFiles();
283 if ( fileMode() != DirectoryOnly && fileMode() != Directory ) {
284 QMutableListIterator<QString> it( files );
285 while ( it.hasNext() ) {
286 QString f = it.next();
287 QFileInfo finfo( f );
288 if ( !finfo.isDir() )
289 it.setValue( addExtension( f ) );
296 \brief Get selected file.
297 \return selected file name or null string if file is not selected
299 QString SUIT_FileDlg::selectedFile() const
301 QStringList files = selectedFiles();
302 return files.count() > 0 ? files[0] : QString();
306 \brief Get last visited directory.
308 Note, that last visited path is memorized only if the
309 dialog box is accepted.
311 \return last visited directory
313 QString SUIT_FileDlg::getLastVisitedDirectory()
315 return myLastVisitedPath;
319 \brief Customize events processing.
321 \return \c true if the event e was recognized and processed
323 bool SUIT_FileDlg::event( QEvent* e )
325 bool res = QFileDialog::event( e );
327 if ( e->type() == QEvent::Polish )
334 \brief Get line edit which is used to enter file name.
335 \return line edit widget or0 if it could not be found
337 QLineEdit* SUIT_FileDlg::lineEdit() const
340 QList<QLineEdit*> editBoxes = findChildren<QLineEdit*>();
341 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
344 for ( int i = 0; i < editBoxes.count(); i++ ) {
345 int widx = grid->indexOf( editBoxes[ i ] );
347 idx = qMin( idx, widx );
349 if ( grid->itemAt( idx ) )
350 ebox = qobject_cast<QLineEdit*>( grid->itemAt( idx )->widget() );
356 \brief Validate user selection.
358 The validation is done by calling the corresponding methods
359 of the validator. If the validator is not set, this method
360 always returns \c true.
362 This method can be re-implemented in the subclasses to customize
363 the file dialog behavior.
364 Another solution could be implementing own file validator class.
366 \return \c true if user selection (file(s) or directory) is valid
367 \sa SUIT_FileValidator class, validator(), setValidator()
369 bool SUIT_FileDlg::acceptData()
371 QStringList files = selectedFiles();
372 if ( files.isEmpty() )
375 // special case for ".."
377 QString txt = lineEdit()->text();
379 QDir dir = directory();
382 bool block = lineEdit()->blockSignals( true );
383 lineEdit()->setText( ".." );
384 lineEdit()->selectAll();
385 lineEdit()->setFocus( Qt::OtherFocusReason );
386 lineEdit()->blockSignals( block );
390 else if ( fileMode() != DirectoryOnly ) {
391 QStringList fs = txt.split( " ", QString::SkipEmptyParts );
392 for ( int i = 0; i < fs.count(); i++ ) {
393 QString wc = fs.at( i );
394 if ( wc.startsWith( "\"" ) && wc.endsWith( "\"" ) )
395 wc = wc.mid( 1, wc.length()-2 );
396 if ( hasWildCards( wc ) ) {
405 // special case for wildcards
406 for ( int i = 0; i < files.count(); ++i ) {
411 switch ( fileMode() ) {
415 QString fn = files.first();
417 bOk = isOpenDlg() ? validator()->canReadDir( fn, checkPermissions() ) :
418 validator()->canWriteDir( fn, checkPermissions() );
424 QString fn = files.first();
425 QFileInfo info( fn );
426 if ( info.isDir() ) {
427 setDirectory( info.absoluteFilePath() );
429 lineEdit()->selectAll();
430 lineEdit()->setFocus( Qt::OtherFocusReason );
434 // validation is not required
436 bOk = isOpenDlg() ? validator()->canOpen( fn, checkPermissions() ) :
437 validator()->canSave( fn, checkPermissions() );
444 for ( int i = 0; i < files.count(); ++i ) {
445 QFileInfo info( files.at( i ) );
446 if ( info.isDir() ) {
447 setDirectory( info.absoluteFilePath() );
449 lineEdit()->selectAll();
450 lineEdit()->setFocus( Qt::OtherFocusReason );
455 bOk = isOpenDlg() ? validator()->canOpen( files.at( i ), checkPermissions() ) :
456 validator()->canSave( files.at( i ), checkPermissions() );
466 emit filesSelected( files );
472 \brief Add an extension to the specified file name.
474 The extension is extracted from the active filter.
476 \param fileName file name to be processed
477 \return fileName with the extension added
479 QString SUIT_FileDlg::addExtension( const QString& fileName ) const
481 QString fname = fileName.trimmed();
483 // check if file name entered is empty
484 if ( fname.isEmpty() )
487 // current file extension
488 QString anExt = "." + SUIT_Tools::extension( fname ).trimmed();
490 // If the file already has extension and it does not match the filter there are two choices:
491 // - to leave it 'as is'
493 // The behavior is defined by IGNORE_NON_MATCHING_EXTENSION constant
494 if ( anExt != "." && !IGNORE_NON_MATCHING_EXTENSION )
497 QRegExp r( QString::fromLatin1("\\(?[a-zA-Z0-9.*? +;#|]*\\)?$") );
498 int index = r.indexIn( selectedFilter().trimmed() );
501 // Create wildcard regular expression basing on selected filter
502 // in order to validate a file extension.
503 // Due to transformations from the filter list (*.txt *.*xx *.c++ SUIT*.* ) we
504 // will have the pattern (\.txt|\..*xx|\.c\+\+|\..*) (as we validate extension only,
505 // we remove everything except extension mask from the pattern
506 QString wildcard = selectedFilter().mid( index, r.matchedLength() ).trimmed();
507 // replace '|' and ';' separators by space symbol and also brackets if there are some
508 wildcard.replace( QRegExp( "[\\|;|(|)]" )," " );
510 QString aPattern = wildcard.replace( QRegExp( "(^| )(\\s*)[0-9a-zA-Z*_?]*\\."), " \\." ).trimmed().
511 replace( QRegExp( "\\s+" ), "|" ).replace( QRegExp( "[?]" ),".?" ).
512 replace( QRegExp( "[*]" ),".*" ).replace( QRegExp( "[+]" ),"\\+" );
514 // now we get the list of all extension masks and remove all which does not contain wildcard symbols
515 QStringList extList = aPattern.split( "|", QString::SkipEmptyParts );
516 for ( int i = extList.count() - 1; i >= 0; i-- ) {
517 if ( !extList[i].contains( "." ) )
518 extList.removeAt( i );
520 aPattern = extList.join( "|" );
523 QRegExp anExtRExp( "^("+ aPattern + ")$" );
525 // Check if the current file extension matches the pattern
526 if ( !anExtRExp.exactMatch( anExt ) ) {
527 // find first appropriate extension in the selected filter
528 // (it should be without wildcard symbols)
529 for ( int i = 0; i < extList.count(); i++ ) {
530 QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" );
531 int res = newExt.lastIndexOf( '.' );
533 newExt = newExt.mid( res + 1 );
534 if ( newExt.indexOf( QRegExp("[*|?]" ) ) < 0 ) {
535 fname += fname.endsWith( "." ) ? newExt : QString( "." ) + newExt;
545 \brief Processes selection : tries to set specified sirectory or filename
546 as current file dialog selection.
547 \param path file or directory path
548 \return \c true if \a path is processed correctly and \c false otherwise
550 bool SUIT_FileDlg::processPath( const QString& path )
552 if ( !path.isNull() ) {
553 QFileInfo fi( path );
557 else if ( fi.isDir() )
558 setDirectory( path );
561 else if ( QFileInfo( SUIT_Tools::dir( path ) ).exists() ) {
562 setDirectory( SUIT_Tools::dir( path ) );
571 \brief Add file filter and activates it.
572 \param filter new file filter
574 void SUIT_FileDlg::addFilter( const QString& filter )
576 QStringList flist = filters();
577 if ( !flist.contains( filter ) ) {
581 selectFilter( filter );
585 \brief Check if the string contains wildcard symbols.
586 \param s string to be checked (for example, file name)
587 \return \c true if string contains "*" or "?" symbols
589 bool SUIT_FileDlg::hasWildCards( const QString& s )
591 return s.contains( QRegExp("[*|?]") );
595 \brief Called when the user presses "Open"or "Save" button.
597 Verifies the user choice and closes dialog box, setting the return code to QDialog::Accepted
601 void SUIT_FileDlg::accept()
603 if ( acceptData() ) {
604 myLastVisitedPath = directory().path();
610 \brief Called when user selects directory from the "Quick Dir" combo box.
612 Browses the file dialog to the specified directory (if it is valid).
614 \param dirPath selected directory
616 void SUIT_FileDlg::quickDir( const QString& dirPath )
618 if ( !QDir( dirPath ).exists() )
619 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "ERR_DIR_NOT_EXIST" ).arg( dirPath ) );
621 processPath( dirPath );
625 \brief Called when user presses "Quick Dir Add" button.
627 Adds current directory to the quick directories list and to the preferences.
629 void SUIT_FileDlg::addQuickDir()
631 QString dp = directory().path();
632 if ( !dp.isEmpty() ) {
637 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
639 dirList = resMgr->stringValue( "FileDlg", QString( "QuickDirList" ) ).split( ';', QString::SkipEmptyParts );
642 bool emptyAndHome = false;
643 if ( dirList.count() > 0 ) {
644 for ( int i = 0; i < dirList.count() && !found; i++ ) {
645 QDir aDir( dirList[i] );
646 if ( aDir.canonicalPath().isNull() && dirList[i] == dir.absolutePath() ||
647 !aDir.canonicalPath().isNull() && aDir.exists() &&
648 aDir.canonicalPath() == dir.canonicalPath() ) {
654 emptyAndHome = dir.canonicalPath() == QDir( QDir::homePath() ).canonicalPath();
658 dirList.append( dp );
659 resMgr->setValue( "FileDlg", QString( "QuickDirList" ), dirList.join( ";" ) );
661 myQuickCombo->addItem( dp );
667 \brief Polish the dialog box.
669 void SUIT_FileDlg::polish()
671 QList<QPushButton*> buttons = findChildren<QPushButton*>();
675 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
676 it != buttons.end(); ++it )
677 maxBtnWidth = qMax( maxBtnWidth, (*it)->sizeHint().width() );
679 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
680 it != buttons.end(); ++it ) {
681 (*it)->setDefault( false );
682 (*it)->setAutoDefault( false );
683 (*it)->setFixedWidth( maxBtnWidth );
686 QList<QListView*> views = findChildren<QListView*>();
687 for ( QList<QListView*>::const_iterator it = views.begin();
688 it != views.end(); ++it ) {
689 (*it)->setViewMode( QListView::ListMode );
694 \brief Show dialog box for the file opening/saving.
696 This method can be used to select the file for opening
697 or saving. The behavior is defined by the \a open parameter.
698 Note, that selection validation depends on the dialog mode used.
700 If \a initial parameter is not null string it is used as starting directory
701 or file at which dialog box is opened.
703 The parameter \a filters defines file filters (wildcards) to be used.
704 If filters list is empty, "All files (*)" is used by default.
706 The parameter \a caption is used as dialog box title. If it is
707 is empty, the default title is used.
709 The parameter \a showQuickDir specifies if it is necessary to
710 show additional quick directories list controls in the bottom part
713 The validation of the user selection is done with help of the file
714 validator (SUIT_FileValidator class). The last parameter \a validator
715 can be used to pass the custom file validator to the dialog box.
717 \param parent parent widget
718 \param initial initial file (or directory) dialog box to be opened on
719 \param filters file filters list
720 \param caption dialog box title
721 \param open if \c true dialog box is used for file opening, otherwise - for saving
722 \param showQuickDir if \c true the quick directory list widgets will be shown
723 \param validator custom file validator
724 \return selected file name or null string if dialog box is cancelled
725 \sa getOpenFileNames(), getExistingDirectory()
727 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
728 const QStringList& filters, const QString& caption,
729 const bool open, const bool showQuickDir,
730 SUIT_FileValidator* validator )
732 SUIT_FileDlg fd( parent, open, showQuickDir, true );
734 fd.setFileMode( open ? ExistingFile : AnyFile );
736 QString tmpfilename = initial;
737 tmpfilename = tmpfilename.simplified();
738 tmpfilename = tmpfilename.replace(QRegExp("\\*"), "" ).replace(QRegExp("\\?"), "" );
740 if ( filters.isEmpty() )
741 fd.setFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
743 fd.setFilters( filters );
745 if ( !caption.isEmpty() )
746 fd.setWindowTitle( caption );
748 if ( !tmpfilename.isEmpty() )
749 fd.processPath( tmpfilename );
752 fd.setValidator( validator );
756 if ( fd.exec() == QDialog::Accepted )
757 filename = fd.selectedFile();
759 QApplication::processEvents();
765 \brief Show dialog box for the file opening/saving.
768 This method can be used to select the file for opening
769 or saving. The behavior is defined by the \a open parameter.
770 Note, that selection validation depends on the dialog mode used.
772 If \a initial parameter is not null string it is used as starting directory
773 or file at which dialog box is opened.
775 The parameter \a filters defines file filters (wildcards) to be used.
776 This is the list of wildcards, separated by the ";;" symbols.
777 If filters list is empty, "All files (*)" is used by default.
779 The parameter \a caption is used as dialog box title. If it is
780 is empty, the default title is used.
782 The parameter \a showQuickDir specifies if it is necessary to
783 show additional quick directories list controls in the bottom part
786 The validation of the user selection is done with help of the file
787 validator (SUIT_FileValidator class). The last parameter \a validator
788 can be used to pass the custom file validator to the dialog box.
790 \param parent parent widget
791 \param initial initial file (or directory) dialog box to be opened on
792 \param filters file filters separated by ";;"
793 \param caption dialog box title
794 \param open if \c true dialog box is used for file opening, otherwise - for saving
795 \param showQuickDir if \c true the quick directory list widgets will be shown
796 \param validator custom file validator
797 \return selected file name or null string if dialog box is cancelled
798 \sa getOpenFileNames(), getExistingDirectory()
800 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
801 const QString& filters, const QString& caption,
802 const bool open, const bool showQuickDir,
803 SUIT_FileValidator* validator )
805 return getFileName( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
806 caption, open, showQuickDir, validator );
810 \brief Show dialog box for the multiple files selection.
812 If \a initial parameter is not null string it is used as starting directory
813 or file at which dialog box is opened.
815 The parameter \a filters defines file filters (wildcards) to be used.
816 If filters list is empty, "All files (*)" is used by default.
818 The parameter \a caption is used as dialog box title. If it is
819 is empty, the default title is used.
821 The parameter \a showQuickDir specifies if it is necessary to
822 show additional quick directories list controls in the bottom part
825 The validation of the user selection is done with help of the file
826 validator (SUIT_FileValidator class). The last parameter \a validator
827 can be used to pass the custom file validator to the dialog box.
829 \param parent parent widget
830 \param initial initial file (or directory) dialog box to be opened on
831 \param filters file filters list
832 \param caption dialog box title
833 \param showQuickDir if \c true the quick directory list widgets will be shown
834 \param validator custom file validator
835 \return selected file names or empty list if dialog box is cancelled
836 \sa getFileName(), getExistingDirectory()
838 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
839 const QStringList& filters, const QString& caption,
840 const bool showQuickDir,
841 SUIT_FileValidator* validator )
843 SUIT_FileDlg fd( parent, true, showQuickDir, true );
845 fd.setFileMode( ExistingFiles );
847 if ( filters.isEmpty() )
848 fd.setFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
850 fd.setFilters( filters );
852 if ( !caption.isEmpty() )
853 fd.setWindowTitle( caption );
855 if ( !initial.isEmpty() )
856 fd.processPath( initial );
859 fd.setValidator( validator );
861 QStringList filenames;
863 if ( fd.exec() == QDialog::Accepted )
864 filenames = fd.selectedFiles();
866 QApplication::processEvents();
872 \brief Show dialog box for the multiple file opening.
875 If \a initial parameter is not null string it is used as starting directory
876 or file at which dialog box is opened.
878 The parameter \a filters defines file filters (wildcards) to be used.
879 This is the list of wildcards, separated by the ";;" symbols.
880 If filters list is empty, "All files (*)" is used by default.
882 The parameter \a caption is used as dialog box title. If it is
883 is empty, the default title is used.
885 The parameter \a showQuickDir specifies if it is necessary to
886 show additional quick directories list controls in the bottom part
889 The validation of the user selection is done with help of the file
890 validator (SUIT_FileValidator class). The last parameter \a validator
891 can be used to pass the custom file validator to the dialog box.
893 \param parent parent widget
894 \param initial initial file (or directory) dialog box to be opened on
895 \param filters file filters separated by ";;"
896 \param caption dialog box title
897 \param showQuickDir if \c true the quick directory list widgets will be shown
898 \param validator custom file validator
899 \return selected file names or empty list if dialog box is cancelled
900 \sa getFileName(), getExistingDirectory()
902 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
903 const QString& filters, const QString& caption,
904 const bool showQuickDir,
905 SUIT_FileValidator* validator )
907 return getOpenFileNames( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
908 caption, showQuickDir, validator );
912 \brief Show dialog box for the existing directory selection.
914 If \a initial parameter is not null string it is used as starting directory
915 at which dialog box is opened.
917 The parameter \a caption is used as dialog box title. If it is
918 is empty, the default title is used.
920 The parameter \a showQuickDir specifies if it is necessary to
921 show additional quick directories list controls in the bottom part
924 The validation of the user selection is done with help of the file
925 validator (SUIT_FileValidator class). The last parameter \a validator
926 can be used to pass the custom file validator to the dialog box.
928 \param parent parent widget
929 \param initial initial directory dialog box to be opened on
930 \param caption dialog box title
931 \param showQuickDir if \c true the quick directory list widgets will be shown
932 \param validator custom file validator
933 \return selected directory name or null string if dialog box is cancelled
934 \sa getFileName(), getOpenFileNames()
936 QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, const QString& initial,
937 const QString& caption, const bool showQuickDir,
938 SUIT_FileValidator* validator )
940 SUIT_FileDlg fd( parent, true, showQuickDir, true );
942 fd.setFileMode( DirectoryOnly );
944 if ( !caption.isEmpty() )
945 fd.setWindowTitle( caption );
947 if ( !initial.isEmpty() )
948 fd.processPath( initial );
951 fd.setValidator( validator );
955 if ( fd.exec() == QDialog::Accepted )
956 dirname = fd.selectedFile();
958 QApplication::processEvents();
964 \brief Get last visited path
965 \return last visited path
967 QString SUIT_FileDlg::getLastVisitedPath()
969 return myLastVisitedPath;
973 \brief Selects current file
975 This version of selectFile() methods works similar to Qt version 3.x:
976 it selects the given file as current and it changes the current file dialog's directory
977 to the directory of the file
979 \param f - new current file name
981 void SUIT_FileDlg::selectFile( const QString& f )
983 QFileDialog::selectFile( QFileInfo( f ).baseName() );
984 setDirectory( QFileInfo( f ).absoluteDir() );