1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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
23 // File : SUIT_FileDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
28 \brief An extension of the Qt Open/Save file dialog box.
30 The class SUIT_FileDlg provides a set of static methods which canbe used
31 for file or directories selection:
32 - getFileName() for single file opening or saving
33 - getOpenFileNames() for mulktiple files opening
34 - getExistingDirectory() for existing directory selection
38 // select file to dump contents of the view
40 filters << "Image files (*.bmp *.gif *.jpg )" << "All files (*)";
41 QString fileName = SUIT_FileDlg::getFileName( desktop(),
46 if ( !fileName.isEmpty() ) {
47 ... writing image to the file
50 // select list of files to open in the editor windows
52 filters << "*.cpp | *.cxx | *.c++" << "*.h | *.hpp | *.hxx";
53 QStringList fileNames = SUIT_FileDlg::getOpenFileName( desktop(),
57 if ( !fileNames.isEmpty() ) {
62 The class SUIT_FileDlg can be subclassed to implement custom file
63 dialog boxes. The class provides a set of methods which can be used
65 - setCheckPermissions() - to enable/disable check of files/directories
67 - setValidator() - to use custom file validator
68 - addWidgets() - to add custom widgets to the lower part of the
70 - getLastVisitedDirectory() - to get last visited directory
71 - acceptData() - can be used ti customize user selection validation
73 \sa SUIT_FileValidator class.
76 #include "SUIT_FileDlg.h"
78 #include "SUIT_Tools.h"
79 #include "SUIT_Session.h"
80 #include "SUIT_MessageBox.h"
81 #include "SUIT_ResourceMgr.h"
82 #include "SUIT_FileValidator.h"
90 #include <QPushButton>
91 #include <QGridLayout>
92 #include <QApplication>
97 #include <QDesktopServices>
100 \brief Defines extension behavior.
102 If the selected file name has extension which does not match the selected filter
103 and this variable is set to \c true, the file extension is ignored and new one
104 (from current file filter will be added.
107 const bool IGNORE_NON_MATCHING_EXTENSION = true;
109 QString SUIT_FileDlg::myLastVisitedPath;
113 \param parent parent widget
114 \param open if \c true dialog box is used for file opening, otherwise - for saving
115 \param showQuickDir if \c true the quick directory list widgets will be shown
116 \param modal if \c true the dialog box will be modal
118 SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal )
119 : QFileDialog( parent ),
124 myCheckPermissions( true )
126 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
127 setOption(QFileDialog::DontUseNativeDialog, true);
129 setSizeGripEnabled( true );
131 setWindowIcon( parent->windowIcon() );
134 myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)));
135 myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)));
137 setSidebarUrls(myUrls);
139 // add quick directories widgets
140 if ( showQuickDir ) {
141 myQuickLab = new QLabel( tr( "LAB_QUICK_PATH" ), this );
142 myQuickCombo = new QComboBox( this );
143 myQuickButton = new QPushButton( tr( "BUT_ADD_PATH" ), this );
145 if ( addWidgets( myQuickLab, myQuickCombo, myQuickButton ) ) {
146 connect( myQuickCombo, SIGNAL( activated( const QString& ) ), this, SLOT( quickDir( const QString& ) ) );
147 connect( myQuickButton, SIGNAL( clicked() ), this, SLOT( addQuickDir() ) );
149 // retrieve directories list from the resources
153 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
155 if ( dirList.isEmpty() )
156 dirList << QDir::homePath();
159 for ( int i = 0; i < dirList.count(); i++ ) {
160 myQuickCombo->addItem( dirList[i] );
161 myUrls.append(QUrl::fromLocalFile(dirList[i]));
165 setSidebarUrls(myUrls);
169 delete myQuickLab; myQuickLab = 0;
170 delete myQuickCombo; myQuickCombo = 0;
171 delete myQuickButton; myQuickButton = 0;
175 setAcceptMode( open ? AcceptOpen: AcceptSave );
176 setWindowTitle( open ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) );
178 bool showCurrentDirInitial = resMgr ? resMgr->booleanValue( "FileDlg", "ShowCurDirInitial", false ) : false;
180 // If last visited path doesn't exist -> switch to the first preferred path
181 if ( !myLastVisitedPath.isEmpty() ) {
182 if ( !processPath( myLastVisitedPath ) && showQuickDir )
183 processPath( myQuickCombo->itemText( 0 ) );
185 else if ( showCurrentDirInitial ) {
186 processPath( QDir::currentPath() );
188 else if ( showQuickDir ) {
189 processPath( myQuickCombo->itemText( 0 ) );
192 // set default file validator
193 myValidator = new SUIT_FileValidator( this );
199 SUIT_FileDlg::~SUIT_FileDlg()
206 \brief Check if the dialog box is used for opening or saving the file.
207 \return \c true if dialog is used for file opening and \c false otherwise
209 bool SUIT_FileDlg::isOpenDlg() const
211 return acceptMode() == AcceptOpen;
215 \brief Get 'check file permissions' flag.
217 \sa setCheckPermissions()
219 bool SUIT_FileDlg::checkPermissions() const
221 return myCheckPermissions;
225 \brief Set 'check file permissions' flag.
227 If this flag is set and file validator is not null,
228 the validator will check the file permissions also.
230 \param checkPerm new flag value
231 \sa checkPermissions()
233 void SUIT_FileDlg::setCheckPermissions( const bool checkPerm )
235 myCheckPermissions = checkPerm;
239 \brief Get file validator.
240 \return current file validator
243 SUIT_FileValidator* SUIT_FileDlg::validator() const
249 \brief Set file validator.
251 Destroys previous validator if the dialog owns it.
253 \param v new file validator
256 void SUIT_FileDlg::setValidator( SUIT_FileValidator* v )
258 if ( myValidator && myValidator->parent() == this )
264 \brief Adds the specified widgets to the bottom of the file dialog.
266 The first widget (usually label) \a l is placed underneath the "file name"
267 and the "file types" labels.
268 The widget \a w is placed underneath the file types combobox.
269 The last widget (usually button) \a b is placed underneath the Cancel push button.
271 In general, the widgets can be arbitrary. This method is added to support
272 the functionality provided by the Qt series 3.x.
274 If you don't want to have one of the widgets added, pass 0 in that widget's position.
275 Every time this function is called, a new row of widgets is added to the bottom of the
278 \param l first widget (e.g. text label)
279 \param w second widget (e.g. combo box)
280 \param b third widget (e.g. push button)
281 \return \c true if widgets have been added successfully
283 bool SUIT_FileDlg::addWidgets( QWidget* l, QWidget* w, QWidget* b )
285 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
287 int row = grid->rowCount();
288 int columns = grid->columnCount();
290 grid->addWidget( l, row, 0 );
292 grid->addWidget( w, row, 1, 1, columns-2 );
294 grid->addWidget( b, row, columns-1 );
301 \brief Get list of selected files.
302 \return selected file names
304 QStringList SUIT_FileDlg::selectedFiles() const
306 QStringList files = QFileDialog::selectedFiles();
307 if ( fileMode() != DirectoryOnly && fileMode() != Directory ) {
308 QMutableListIterator<QString> it( files );
309 while ( it.hasNext() ) {
310 QString f = it.next();
311 QFileInfo finfo( f );
312 if ( !finfo.isDir() )
313 it.setValue( addExtension( f ) );
320 \brief Get selected file.
321 \return selected file name or null string if file is not selected
323 QString SUIT_FileDlg::selectedFile() const
325 QStringList files = selectedFiles();
326 return files.count() > 0 ? files[0] : QString();
330 \brief Get last visited directory.
332 Note, that last visited path is memorized only if the
333 dialog box is accepted.
335 \return last visited directory
337 QString SUIT_FileDlg::getLastVisitedDirectory()
339 return myLastVisitedPath;
343 \brief Customize events processing.
345 \return \c true if the event e was recognized and processed
347 bool SUIT_FileDlg::event( QEvent* e )
349 bool res = QFileDialog::event( e );
351 if ( e->type() == QEvent::Polish )
358 \brief Get line edit which is used to enter file name.
359 \return line edit widget or0 if it could not be found
361 QLineEdit* SUIT_FileDlg::lineEdit() const
364 QList<QLineEdit*> editBoxes = findChildren<QLineEdit*>();
365 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
368 for ( int i = 0; i < editBoxes.count(); i++ ) {
369 int widx = grid->indexOf( editBoxes[ i ] );
371 idx = qMin( idx, widx );
373 if ( grid->itemAt( idx ) )
374 ebox = qobject_cast<QLineEdit*>( grid->itemAt( idx )->widget() );
380 \brief Validate user selection.
382 The validation is done by calling the corresponding methods
383 of the validator. If the validator is not set, this method
384 always returns \c true.
386 This method can be re-implemented in the subclasses to customize
387 the file dialog behavior.
388 Another solution could be implementing own file validator class.
390 \return \c true if user selection (file(s) or directory) is valid
391 \sa SUIT_FileValidator class, validator(), setValidator()
393 bool SUIT_FileDlg::acceptData()
395 QStringList files = selectedFiles();
396 if ( files.isEmpty() )
399 // special case for ".."
401 QString txt = lineEdit()->text();
403 QDir dir = directory();
406 bool block = lineEdit()->blockSignals( true );
407 lineEdit()->setText( ".." );
408 lineEdit()->selectAll();
409 lineEdit()->setFocus( Qt::OtherFocusReason );
410 lineEdit()->blockSignals( block );
414 else if ( fileMode() != DirectoryOnly ) {
415 QStringList fs = txt.split( " ", QString::SkipEmptyParts );
416 for ( int i = 0; i < fs.count(); i++ ) {
417 QString wc = fs.at( i );
418 if ( wc.startsWith( "\"" ) && wc.endsWith( "\"" ) )
419 wc = wc.mid( 1, wc.length()-2 );
420 if ( hasWildCards( wc ) ) {
429 // special case for wildcards
430 for ( int i = 0; i < files.count(); ++i ) {
435 switch ( fileMode() ) {
439 QString fn = files.first();
441 bOk = isOpenDlg() ? validator()->canReadDir( fn, checkPermissions() ) :
442 validator()->canWriteDir( fn, checkPermissions() );
448 QString fn = files.first();
449 QFileInfo info( fn );
450 if ( info.isDir() ) {
451 setDirectory( info.absoluteFilePath() );
453 lineEdit()->selectAll();
454 lineEdit()->setFocus( Qt::OtherFocusReason );
458 // validation is not required
460 bOk = isOpenDlg() ? validator()->canOpen( fn, checkPermissions() ) :
461 validator()->canSave( fn, checkPermissions() );
468 for ( int i = 0; i < files.count(); ++i ) {
469 QFileInfo info( files.at( i ) );
470 if ( info.isDir() ) {
471 setDirectory( info.absoluteFilePath() );
473 lineEdit()->selectAll();
474 lineEdit()->setFocus( Qt::OtherFocusReason );
479 bOk = isOpenDlg() ? validator()->canOpen( files.at( i ), checkPermissions() ) :
480 validator()->canSave( files.at( i ), checkPermissions() );
490 emit filesSelected( files );
496 \brief Add an extension to the specified file name.
498 The extension is extracted from the active filter.
500 \param fileName file name to be processed
501 \return fileName with the extension added
503 QString SUIT_FileDlg::addExtension( const QString& fileName ) const
505 QString fname = fileName.trimmed();
507 // check if file name entered is empty
508 if ( fname.isEmpty() )
511 // current file extension
512 QString anExt = "." + SUIT_Tools::extension( fname ).trimmed();
514 // If the file already has extension and it does not match the filter there are two choices:
515 // - to leave it 'as is'
517 // The behavior is defined by IGNORE_NON_MATCHING_EXTENSION constant
518 if ( anExt != "." && !IGNORE_NON_MATCHING_EXTENSION )
521 QRegExp r( QString::fromLatin1("\\(?[a-zA-Z0-9.*? +;#|]*\\)?$") );
522 int index = r.indexIn( selectedNameFilter().trimmed() );
524 if ( QFileInfo( fileName ).exists() )
525 return fileName; // if file exists return as is
528 // Create wildcard regular expression basing on selected filter
529 // in order to validate a file extension.
530 // Due to transformations from the filter list (*.txt *.*xx *.c++ SUIT*.* ) we
531 // will have the pattern (\.txt|\..*xx|\.c\+\+|\..*) (as we validate extension only,
532 // we remove everything except extension mask from the pattern
533 QString wildcard = selectedNameFilter().mid( index, r.matchedLength() ).trimmed();
534 // replace '|' and ';' separators by space symbol and also brackets if there are some
535 wildcard.replace( QRegExp( "[\\|;|(|)]" )," " );
537 QString aPattern = wildcard.replace( QRegExp( "(^| )(\\s*)[0-9a-zA-Z*_?]*\\."), " \\." ).trimmed().
538 replace( QRegExp( "\\s+" ), "|" ).replace( QRegExp( "[?]" ),".?" ).
539 replace( QRegExp( "[*]" ),".*" ).replace( QRegExp( "[+]" ),"\\+" );
541 // now we get the list of all extension masks and remove all which does not contain wildcard symbols
542 QStringList extList = aPattern.split( "|", QString::SkipEmptyParts );
543 for ( int i = extList.count() - 1; i >= 0; i-- ) {
544 if ( !extList[i].contains( "." ) )
545 extList.removeAt( i );
547 aPattern = extList.join( "|" );
550 QRegExp anExtRExp( "^("+ aPattern + ")$" );
552 // Check if the current file extension matches the pattern
553 if ( !anExtRExp.exactMatch( anExt ) ) {
554 // find first appropriate extension in the selected filter
555 // (it should be without wildcard symbols)
556 for ( int i = 0; i < extList.count(); i++ ) {
557 QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" );
558 int res = newExt.lastIndexOf( '.' );
560 newExt = newExt.mid( res + 1 );
561 if ( newExt.indexOf( QRegExp("[*|?]" ) ) < 0 ) {
562 fname += fname.endsWith( "." ) ? newExt : QString( "." ) + newExt;
572 \brief Processes selection : tries to set specified sirectory or filename
573 as current file dialog selection.
574 \param path file or directory path
575 \return \c true if \a path is processed correctly and \c false otherwise
577 bool SUIT_FileDlg::processPath( const QString& path )
579 if ( !path.isNull() ) {
580 QFileInfo fi( path );
584 else if ( fi.isDir() )
585 setDirectory( path );
588 QString dirPath = SUIT_Tools::dir( path, false );
589 if ( !dirPath.isEmpty() && QFileInfo( dirPath ).exists() )
590 setDirectory( dirPath );
591 selectFile( SUIT_Tools::file( path ) );
598 \brief Add file filter and activates it.
599 \param filter new file filter
601 void SUIT_FileDlg::addFilter( const QString& filter )
603 QStringList flist = nameFilters();
604 if ( !flist.contains( filter ) ) {
606 setNameFilters( flist );
608 selectNameFilter( filter );
612 \brief Check if the string contains wildcard symbols.
613 \param s string to be checked (for example, file name)
614 \return \c true if string contains "*" or "?" symbols
616 bool SUIT_FileDlg::hasWildCards( const QString& s )
618 return s.contains( QRegExp("[*|?]") );
622 \brief Called when the user presses "Open"or "Save" button.
624 Verifies the user choice and closes dialog box, setting the return code to QDialog::Accepted
628 void SUIT_FileDlg::accept()
630 if ( acceptData() ) {
631 myLastVisitedPath = directory().path();
637 \brief Called when user selects directory from the "Quick Dir" combo box.
639 Browses the file dialog to the specified directory (if it is valid).
641 \param dirPath selected directory
643 void SUIT_FileDlg::quickDir( const QString& dirPath )
645 if ( !QDir( dirPath ).exists() )
646 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "ERR_DIR_NOT_EXIST" ).arg( dirPath ) );
648 processPath( dirPath );
652 \brief Called when user presses "Quick Dir Add" button.
654 Adds current directory to the quick directories list and to the preferences.
656 void SUIT_FileDlg::addQuickDir()
658 QString dp = directory().path();
659 if ( !dp.isEmpty() ) {
664 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
666 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
669 bool emptyAndHome = false;
670 if ( dirList.count() > 0 ) {
671 for ( int i = 0; i < dirList.count() && !found; i++ ) {
672 QDir aDir( dirList[i] );
673 if ( ( aDir.canonicalPath().isNull() && dirList[i] == dir.absolutePath() ) ||
674 ( !aDir.canonicalPath().isNull() && aDir.exists() &&
675 aDir.canonicalPath() == dir.canonicalPath() ) ) {
681 emptyAndHome = dir.canonicalPath() == QDir( QDir::homePath() ).canonicalPath();
685 dirList.append( dp );
686 resMgr->setValue( "FileDlg", "QuickDirList", dirList.join( ";" ) );
688 if ( !emptyAndHome ) {
689 myQuickCombo->addItem( dp );
690 myUrls.append(QUrl::fromLocalFile( dp ));
691 setSidebarUrls(myUrls);
698 \brief Polish the dialog box.
700 void SUIT_FileDlg::polish()
702 QList<QPushButton*> buttons = findChildren<QPushButton*>();
706 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
707 it != buttons.end(); ++it )
708 maxBtnWidth = qMax( maxBtnWidth, (*it)->sizeHint().width() );
710 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
711 it != buttons.end(); ++it ) {
712 (*it)->setDefault( false );
713 (*it)->setAutoDefault( false );
714 (*it)->setFixedWidth( maxBtnWidth );
717 QList<QListView*> views = findChildren<QListView*>();
718 for ( QList<QListView*>::const_iterator it = views.begin();
719 it != views.end(); ++it ) {
720 (*it)->setViewMode( QListView::ListMode );
725 \brief Show dialog box for the file opening/saving.
727 This method can be used to select the file for opening
728 or saving. The behavior is defined by the \a open parameter.
729 Note, that selection validation depends on the dialog mode used.
731 If \a initial parameter is not null string it is used as starting directory
732 or file at which dialog box is opened.
734 The parameter \a filters defines file filters (wildcards) to be used.
735 If filters list is empty, "All files (*)" is used by default.
737 The parameter \a caption is used as dialog box title. If it is
738 is empty, the default title is used.
740 The parameter \a showQuickDir specifies if it is necessary to
741 show additional quick directories list controls in the bottom part
744 The validation of the user selection is done with help of the file
745 validator (SUIT_FileValidator class). The last parameter \a validator
746 can be used to pass the custom file validator to the dialog box.
748 \param parent parent widget
749 \param initial initial file (or directory) dialog box to be opened on
750 \param filters file filters list
751 \param caption dialog box title
752 \param open if \c true dialog box is used for file opening, otherwise - for saving
753 \param showQuickDir if \c true the quick directory list widgets will be shown
754 \param validator custom file validator
755 \return selected file name or null string if dialog box is cancelled
756 \sa getOpenFileNames(), getExistingDirectory()
758 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
759 const QStringList& filters, const QString& caption,
760 const bool open, const bool showQuickDir,
761 SUIT_FileValidator* validator )
763 SUIT_FileDlg fd( parent, open, showQuickDir, true );
765 fd.setFileMode( open ? ExistingFile : AnyFile );
767 QString tmpfilename = initial;
768 tmpfilename = tmpfilename.simplified();
769 tmpfilename = tmpfilename.replace(QRegExp("\\*"), "" ).replace(QRegExp("\\?"), "" );
771 if ( filters.isEmpty() )
772 fd.setNameFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
774 fd.setNameFilters( filters );
776 if ( !caption.isEmpty() )
777 fd.setWindowTitle( caption );
779 if ( !tmpfilename.isEmpty() )
780 fd.processPath( tmpfilename );
783 fd.setValidator( validator );
787 if ( fd.exec() == QDialog::Accepted )
788 filename = fd.selectedFile();
790 QApplication::processEvents();
796 \brief Show dialog box for the file opening/saving.
799 This method can be used to select the file for opening
800 or saving. The behavior is defined by the \a open parameter.
801 Note, that selection validation depends on the dialog mode used.
803 If \a initial parameter is not null string it is used as starting directory
804 or file at which dialog box is opened.
806 The parameter \a filters defines file filters (wildcards) to be used.
807 This is the list of wildcards, separated by the ";;" symbols.
808 If filters list is empty, "All files (*)" is used by default.
810 The parameter \a caption is used as dialog box title. If it is
811 is empty, the default title is used.
813 The parameter \a showQuickDir specifies if it is necessary to
814 show additional quick directories list controls in the bottom part
817 The validation of the user selection is done with help of the file
818 validator (SUIT_FileValidator class). The last parameter \a validator
819 can be used to pass the custom file validator to the dialog box.
821 \param parent parent widget
822 \param initial initial file (or directory) dialog box to be opened on
823 \param filters file filters separated by ";;"
824 \param caption dialog box title
825 \param open if \c true dialog box is used for file opening, otherwise - for saving
826 \param showQuickDir if \c true the quick directory list widgets will be shown
827 \param validator custom file validator
828 \return selected file name or null string if dialog box is cancelled
829 \sa getOpenFileNames(), getExistingDirectory()
831 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
832 const QString& filters, const QString& caption,
833 const bool open, const bool showQuickDir,
834 SUIT_FileValidator* validator )
836 return getFileName( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
837 caption, open, showQuickDir, validator );
841 \brief Show dialog box for the multiple files selection.
843 If \a initial parameter is not null string it is used as starting directory
844 or file at which dialog box is opened.
846 The parameter \a filters defines file filters (wildcards) to be used.
847 If filters list is empty, "All files (*)" is used by default.
849 The parameter \a caption is used as dialog box title. If it is
850 is empty, the default title is used.
852 The parameter \a showQuickDir specifies if it is necessary to
853 show additional quick directories list controls in the bottom part
856 The validation of the user selection is done with help of the file
857 validator (SUIT_FileValidator class). The last parameter \a validator
858 can be used to pass the custom file validator to the dialog box.
860 \param parent parent widget
861 \param initial initial file (or directory) dialog box to be opened on
862 \param filters file filters list
863 \param caption dialog box title
864 \param showQuickDir if \c true the quick directory list widgets will be shown
865 \param validator custom file validator
866 \return selected file names or empty list if dialog box is cancelled
867 \sa getFileName(), getExistingDirectory()
869 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
870 const QStringList& filters, const QString& caption,
871 const bool showQuickDir,
872 SUIT_FileValidator* validator )
874 SUIT_FileDlg fd( parent, true, showQuickDir, true );
876 fd.setFileMode( ExistingFiles );
878 if ( filters.isEmpty() )
879 fd.setNameFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
881 fd.setNameFilters( filters );
883 if ( !caption.isEmpty() )
884 fd.setWindowTitle( caption );
886 if ( !initial.isEmpty() )
887 fd.processPath( initial );
890 fd.setValidator( validator );
892 QStringList filenames;
894 if ( fd.exec() == QDialog::Accepted )
895 filenames = fd.selectedFiles();
897 QApplication::processEvents();
903 \brief Show dialog box for the multiple file opening.
906 If \a initial parameter is not null string it is used as starting directory
907 or file at which dialog box is opened.
909 The parameter \a filters defines file filters (wildcards) to be used.
910 This is the list of wildcards, separated by the ";;" symbols.
911 If filters list is empty, "All files (*)" is used by default.
913 The parameter \a caption is used as dialog box title. If it is
914 is empty, the default title is used.
916 The parameter \a showQuickDir specifies if it is necessary to
917 show additional quick directories list controls in the bottom part
920 The validation of the user selection is done with help of the file
921 validator (SUIT_FileValidator class). The last parameter \a validator
922 can be used to pass the custom file validator to the dialog box.
924 \param parent parent widget
925 \param initial initial file (or directory) dialog box to be opened on
926 \param filters file filters separated by ";;"
927 \param caption dialog box title
928 \param showQuickDir if \c true the quick directory list widgets will be shown
929 \param validator custom file validator
930 \return selected file names or empty list if dialog box is cancelled
931 \sa getFileName(), getExistingDirectory()
933 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
934 const QString& filters, const QString& caption,
935 const bool showQuickDir,
936 SUIT_FileValidator* validator )
938 return getOpenFileNames( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
939 caption, showQuickDir, validator );
943 \brief Show dialog box for the existing directory selection.
945 If \a initial parameter is not null string it is used as starting directory
946 at which dialog box is opened.
948 The parameter \a caption is used as dialog box title. If it is
949 is empty, the default title is used.
951 The parameter \a showQuickDir specifies if it is necessary to
952 show additional quick directories list controls in the bottom part
955 The validation of the user selection is done with help of the file
956 validator (SUIT_FileValidator class). The last parameter \a validator
957 can be used to pass the custom file validator to the dialog box.
959 \param parent parent widget
960 \param initial initial directory dialog box to be opened on
961 \param caption dialog box title
962 \param showQuickDir if \c true the quick directory list widgets will be shown
963 \param validator custom file validator
964 \return selected directory name or null string if dialog box is cancelled
965 \sa getFileName(), getOpenFileNames()
967 QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, const QString& initial,
968 const QString& caption, const bool showQuickDir,
969 SUIT_FileValidator* validator )
971 SUIT_FileDlg fd( parent, true, showQuickDir, true );
973 fd.setFileMode( DirectoryOnly );
975 if ( !caption.isEmpty() )
976 fd.setWindowTitle( caption );
978 if ( !initial.isEmpty() )
979 fd.processPath( initial );
982 fd.setValidator( validator );
986 if ( fd.exec() == QDialog::Accepted )
987 dirname = fd.selectedFile();
989 QApplication::processEvents();
995 \brief Get last visited path
996 \return last visited path
998 QString SUIT_FileDlg::getLastVisitedPath()
1000 return myLastVisitedPath;
1004 \brief Selects current file
1006 This version of selectFile() methods works similar to Qt version 3.x:
1007 it selects the given file as current and it changes the current file dialog's directory
1008 to the directory of the file
1010 \param f - new current file name
1012 void SUIT_FileDlg::selectFile( const QString& f )
1014 QFileDialog::selectFile( QFileInfo( f ).baseName() );
1015 if ( !Qtx::dir( f, false ).isEmpty() )
1016 setDirectory( QFileInfo( f ).absolutePath() );