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 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
135 myUrls.insert(0,QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation)));
136 myUrls.insert(0,QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
138 myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)));
139 myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)));
141 setSidebarUrls(myUrls);
143 // add quick directories widgets
144 if ( showQuickDir ) {
145 myQuickLab = new QLabel( tr( "LAB_QUICK_PATH" ), this );
146 myQuickCombo = new QComboBox( this );
147 myQuickButton = new QPushButton( tr( "BUT_ADD_PATH" ), this );
149 if ( addWidgets( myQuickLab, myQuickCombo, myQuickButton ) ) {
150 connect( myQuickCombo, SIGNAL( activated( const QString& ) ), this, SLOT( quickDir( const QString& ) ) );
151 connect( myQuickButton, SIGNAL( clicked() ), this, SLOT( addQuickDir() ) );
153 // retrieve directories list from the resources
157 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
159 if ( dirList.isEmpty() )
160 dirList << QDir::homePath();
163 for ( int i = 0; i < dirList.count(); i++ ) {
164 myQuickCombo->addItem( dirList[i] );
165 myUrls.append(QUrl::fromLocalFile(dirList[i]));
169 setSidebarUrls(myUrls);
173 delete myQuickLab; myQuickLab = 0;
174 delete myQuickCombo; myQuickCombo = 0;
175 delete myQuickButton; myQuickButton = 0;
179 setAcceptMode( open ? AcceptOpen: AcceptSave );
180 setWindowTitle( open ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) );
182 bool showCurrentDirInitial = resMgr ? resMgr->booleanValue( "FileDlg", "ShowCurDirInitial", false ) : false;
184 // If last visited path doesn't exist -> switch to the first preferred path
185 if ( !myLastVisitedPath.isEmpty() ) {
186 if ( !processPath( myLastVisitedPath ) && showQuickDir )
187 processPath( myQuickCombo->itemText( 0 ) );
189 else if ( showCurrentDirInitial ) {
190 processPath( QDir::currentPath() );
192 else if ( showQuickDir ) {
193 processPath( myQuickCombo->itemText( 0 ) );
196 // set default file validator
197 myValidator = new SUIT_FileValidator( this );
203 SUIT_FileDlg::~SUIT_FileDlg()
210 \brief Check if the dialog box is used for opening or saving the file.
211 \return \c true if dialog is used for file opening and \c false otherwise
213 bool SUIT_FileDlg::isOpenDlg() const
215 return acceptMode() == AcceptOpen;
219 \brief Get 'check file permissions' flag.
221 \sa setCheckPermissions()
223 bool SUIT_FileDlg::checkPermissions() const
225 return myCheckPermissions;
229 \brief Set 'check file permissions' flag.
231 If this flag is set and file validator is not null,
232 the validator will check the file permissions also.
234 \param checkPerm new flag value
235 \sa checkPermissions()
237 void SUIT_FileDlg::setCheckPermissions( const bool checkPerm )
239 myCheckPermissions = checkPerm;
243 \brief Get file validator.
244 \return current file validator
247 SUIT_FileValidator* SUIT_FileDlg::validator() const
253 \brief Set file validator.
255 Destroys previous validator if the dialog owns it.
257 \param v new file validator
260 void SUIT_FileDlg::setValidator( SUIT_FileValidator* v )
262 if ( myValidator && myValidator->parent() == this )
268 \brief Adds the specified widgets to the bottom of the file dialog.
270 The first widget (usually label) \a l is placed underneath the "file name"
271 and the "file types" labels.
272 The widget \a w is placed underneath the file types combobox.
273 The last widget (usually button) \a b is placed underneath the Cancel push button.
275 In general, the widgets can be arbitrary. This method is added to support
276 the functionality provided by the Qt series 3.x.
278 If you don't want to have one of the widgets added, pass 0 in that widget's position.
279 Every time this function is called, a new row of widgets is added to the bottom of the
282 \param l first widget (e.g. text label)
283 \param w second widget (e.g. combo box)
284 \param b third widget (e.g. push button)
285 \return \c true if widgets have been added successfully
287 bool SUIT_FileDlg::addWidgets( QWidget* l, QWidget* w, QWidget* b )
289 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
291 int row = grid->rowCount();
292 int columns = grid->columnCount();
294 grid->addWidget( l, row, 0 );
296 grid->addWidget( w, row, 1, 1, columns-2 );
298 grid->addWidget( b, row, columns-1 );
305 \brief Get list of selected files.
306 \return selected file names
308 QStringList SUIT_FileDlg::selectedFiles() const
310 QStringList files = QFileDialog::selectedFiles();
311 if ( fileMode() != DirectoryOnly && fileMode() != Directory ) {
312 QMutableListIterator<QString> it( files );
313 while ( it.hasNext() ) {
314 QString f = it.next();
315 QFileInfo finfo( f );
316 if ( !finfo.isDir() )
317 it.setValue( addExtension( f ) );
324 \brief Get selected file.
325 \return selected file name or null string if file is not selected
327 QString SUIT_FileDlg::selectedFile() const
329 QStringList files = selectedFiles();
330 return files.count() > 0 ? files[0] : QString();
334 \brief Get last visited directory.
336 Note, that last visited path is memorized only if the
337 dialog box is accepted.
339 \return last visited directory
341 QString SUIT_FileDlg::getLastVisitedDirectory()
343 return myLastVisitedPath;
347 \brief Customize events processing.
349 \return \c true if the event e was recognized and processed
351 bool SUIT_FileDlg::event( QEvent* e )
353 bool res = QFileDialog::event( e );
355 if ( e->type() == QEvent::Polish )
362 \brief Get line edit which is used to enter file name.
363 \return line edit widget or0 if it could not be found
365 QLineEdit* SUIT_FileDlg::lineEdit() const
368 QList<QLineEdit*> editBoxes = findChildren<QLineEdit*>();
369 QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );
372 for ( int i = 0; i < editBoxes.count(); i++ ) {
373 int widx = grid->indexOf( editBoxes[ i ] );
375 idx = qMin( idx, widx );
377 if ( grid->itemAt( idx ) )
378 ebox = qobject_cast<QLineEdit*>( grid->itemAt( idx )->widget() );
384 \brief Validate user selection.
386 The validation is done by calling the corresponding methods
387 of the validator. If the validator is not set, this method
388 always returns \c true.
390 This method can be re-implemented in the subclasses to customize
391 the file dialog behavior.
392 Another solution could be implementing own file validator class.
394 \return \c true if user selection (file(s) or directory) is valid
395 \sa SUIT_FileValidator class, validator(), setValidator()
397 bool SUIT_FileDlg::acceptData()
399 QStringList files = selectedFiles();
400 if ( files.isEmpty() )
403 // special case for ".."
405 QString txt = lineEdit()->text();
407 QDir dir = directory();
410 bool block = lineEdit()->blockSignals( true );
411 lineEdit()->setText( ".." );
412 lineEdit()->selectAll();
413 lineEdit()->setFocus( Qt::OtherFocusReason );
414 lineEdit()->blockSignals( block );
418 else if ( fileMode() != DirectoryOnly ) {
419 QStringList fs = txt.split( " ", QString::SkipEmptyParts );
420 for ( int i = 0; i < fs.count(); i++ ) {
421 QString wc = fs.at( i );
422 if ( wc.startsWith( "\"" ) && wc.endsWith( "\"" ) )
423 wc = wc.mid( 1, wc.length()-2 );
424 if ( hasWildCards( wc ) ) {
433 // special case for wildcards
434 for ( int i = 0; i < files.count(); ++i ) {
439 switch ( fileMode() ) {
443 QString fn = files.first();
445 bOk = isOpenDlg() ? validator()->canReadDir( fn, checkPermissions() ) :
446 validator()->canWriteDir( fn, checkPermissions() );
452 QString fn = files.first();
453 QFileInfo info( fn );
454 if ( info.isDir() ) {
455 setDirectory( info.absoluteFilePath() );
457 lineEdit()->selectAll();
458 lineEdit()->setFocus( Qt::OtherFocusReason );
462 // validation is not required
464 bOk = isOpenDlg() ? validator()->canOpen( fn, checkPermissions() ) :
465 validator()->canSave( fn, checkPermissions() );
472 for ( int i = 0; i < files.count(); ++i ) {
473 QFileInfo info( files.at( i ) );
474 if ( info.isDir() ) {
475 setDirectory( info.absoluteFilePath() );
477 lineEdit()->selectAll();
478 lineEdit()->setFocus( Qt::OtherFocusReason );
483 bOk = isOpenDlg() ? validator()->canOpen( files.at( i ), checkPermissions() ) :
484 validator()->canSave( files.at( i ), checkPermissions() );
494 emit filesSelected( files );
500 \brief Add an extension to the specified file name.
502 The extension is extracted from the active filter.
504 \param fileName file name to be processed
505 \return fileName with the extension added
507 QString SUIT_FileDlg::addExtension( const QString& fileName ) const
509 QString fname = fileName.trimmed();
511 // check if file name entered is empty
512 if ( fname.isEmpty() )
515 // current file extension
516 QString anExt = "." + SUIT_Tools::extension( fname ).trimmed();
518 // If the file already has extension and it does not match the filter there are two choices:
519 // - to leave it 'as is'
521 // The behavior is defined by IGNORE_NON_MATCHING_EXTENSION constant
522 if ( anExt != "." && !IGNORE_NON_MATCHING_EXTENSION )
525 QRegExp r( QString::fromLatin1("\\(?[a-zA-Z0-9.*? +;#|]*\\)?$") );
526 int index = r.indexIn( selectedNameFilter().trimmed() );
528 if ( QFileInfo( fileName ).exists() )
529 return fileName; // if file exists return as is
532 // Create wildcard regular expression basing on selected filter
533 // in order to validate a file extension.
534 // Due to transformations from the filter list (*.txt *.*xx *.c++ SUIT*.* ) we
535 // will have the pattern (\.txt|\..*xx|\.c\+\+|\..*) (as we validate extension only,
536 // we remove everything except extension mask from the pattern
537 QString wildcard = selectedNameFilter().mid( index, r.matchedLength() ).trimmed();
538 // replace '|' and ';' separators by space symbol and also brackets if there are some
539 wildcard.replace( QRegExp( "[\\|;|(|)]" )," " );
541 QString aPattern = wildcard.replace( QRegExp( "(^| )(\\s*)[0-9a-zA-Z*_?]*\\."), " \\." ).trimmed().
542 replace( QRegExp( "\\s+" ), "|" ).replace( QRegExp( "[?]" ),".?" ).
543 replace( QRegExp( "[*]" ),".*" ).replace( QRegExp( "[+]" ),"\\+" );
545 // now we get the list of all extension masks and remove all which does not contain wildcard symbols
546 QStringList extList = aPattern.split( "|", QString::SkipEmptyParts );
547 for ( int i = extList.count() - 1; i >= 0; i-- ) {
548 if ( !extList[i].contains( "." ) )
549 extList.removeAt( i );
551 aPattern = extList.join( "|" );
554 QRegExp anExtRExp( "^("+ aPattern + ")$" );
556 // Check if the current file extension matches the pattern
557 if ( !anExtRExp.exactMatch( anExt ) ) {
558 // find first appropriate extension in the selected filter
559 // (it should be without wildcard symbols)
560 for ( int i = 0; i < extList.count(); i++ ) {
561 QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" );
562 int res = newExt.lastIndexOf( '.' );
564 newExt = newExt.mid( res + 1 );
565 if ( newExt.indexOf( QRegExp("[*|?]" ) ) < 0 ) {
566 fname += fname.endsWith( "." ) ? newExt : QString( "." ) + newExt;
576 \brief Processes selection : tries to set specified sirectory or filename
577 as current file dialog selection.
578 \param path file or directory path
579 \return \c true if \a path is processed correctly and \c false otherwise
581 bool SUIT_FileDlg::processPath( const QString& path )
583 if ( !path.isNull() ) {
584 QFileInfo fi( path );
588 else if ( fi.isDir() )
589 setDirectory( path );
592 QString dirPath = SUIT_Tools::dir( path, false );
593 if ( !dirPath.isEmpty() && QFileInfo( dirPath ).exists() )
594 setDirectory( dirPath );
595 selectFile( SUIT_Tools::file( path ) );
602 \brief Add file filter and activates it.
603 \param filter new file filter
605 void SUIT_FileDlg::addFilter( const QString& filter )
607 QStringList flist = nameFilters();
608 if ( !flist.contains( filter ) ) {
610 setNameFilters( flist );
612 selectNameFilter( filter );
616 \brief Check if the string contains wildcard symbols.
617 \param s string to be checked (for example, file name)
618 \return \c true if string contains "*" or "?" symbols
620 bool SUIT_FileDlg::hasWildCards( const QString& s )
622 return s.contains( QRegExp("[*|?]") );
626 \brief Called when the user presses "Open"or "Save" button.
628 Verifies the user choice and closes dialog box, setting the return code to QDialog::Accepted
632 void SUIT_FileDlg::accept()
634 if ( acceptData() ) {
635 myLastVisitedPath = directory().path();
641 \brief Called when user selects directory from the "Quick Dir" combo box.
643 Browses the file dialog to the specified directory (if it is valid).
645 \param dirPath selected directory
647 void SUIT_FileDlg::quickDir( const QString& dirPath )
649 if ( !QDir( dirPath ).exists() )
650 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "ERR_DIR_NOT_EXIST" ).arg( dirPath ) );
652 processPath( dirPath );
656 \brief Called when user presses "Quick Dir Add" button.
658 Adds current directory to the quick directories list and to the preferences.
660 void SUIT_FileDlg::addQuickDir()
662 QString dp = directory().path();
663 if ( !dp.isEmpty() ) {
668 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
670 dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
673 bool emptyAndHome = false;
674 if ( dirList.count() > 0 ) {
675 for ( int i = 0; i < dirList.count() && !found; i++ ) {
676 QDir aDir( dirList[i] );
677 if ( ( aDir.canonicalPath().isNull() && dirList[i] == dir.absolutePath() ) ||
678 ( !aDir.canonicalPath().isNull() && aDir.exists() &&
679 aDir.canonicalPath() == dir.canonicalPath() ) ) {
685 emptyAndHome = dir.canonicalPath() == QDir( QDir::homePath() ).canonicalPath();
689 dirList.append( dp );
690 resMgr->setValue( "FileDlg", "QuickDirList", dirList.join( ";" ) );
692 if ( !emptyAndHome ) {
693 myQuickCombo->addItem( dp );
694 myUrls.append(QUrl::fromLocalFile( dp ));
695 setSidebarUrls(myUrls);
702 \brief Polish the dialog box.
704 void SUIT_FileDlg::polish()
706 QList<QPushButton*> buttons = findChildren<QPushButton*>();
710 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
711 it != buttons.end(); ++it )
712 maxBtnWidth = qMax( maxBtnWidth, (*it)->sizeHint().width() );
714 for ( QList<QPushButton*>::const_iterator it = buttons.begin();
715 it != buttons.end(); ++it ) {
716 (*it)->setDefault( false );
717 (*it)->setAutoDefault( false );
718 (*it)->setFixedWidth( maxBtnWidth );
721 QList<QListView*> views = findChildren<QListView*>();
722 for ( QList<QListView*>::const_iterator it = views.begin();
723 it != views.end(); ++it ) {
724 (*it)->setViewMode( QListView::ListMode );
729 \brief Show dialog box for the file opening/saving.
731 This method can be used to select the file for opening
732 or saving. The behavior is defined by the \a open parameter.
733 Note, that selection validation depends on the dialog mode used.
735 If \a initial parameter is not null string it is used as starting directory
736 or file at which dialog box is opened.
738 The parameter \a filters defines file filters (wildcards) to be used.
739 If filters list is empty, "All files (*)" is used by default.
741 The parameter \a caption is used as dialog box title. If it is
742 is empty, the default title is used.
744 The parameter \a showQuickDir specifies if it is necessary to
745 show additional quick directories list controls in the bottom part
748 The validation of the user selection is done with help of the file
749 validator (SUIT_FileValidator class). The last parameter \a validator
750 can be used to pass the custom file validator to the dialog box.
752 \param parent parent widget
753 \param initial initial file (or directory) dialog box to be opened on
754 \param filters file filters list
755 \param caption dialog box title
756 \param open if \c true dialog box is used for file opening, otherwise - for saving
757 \param showQuickDir if \c true the quick directory list widgets will be shown
758 \param validator custom file validator
759 \return selected file name or null string if dialog box is cancelled
760 \sa getOpenFileNames(), getExistingDirectory()
762 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
763 const QStringList& filters, const QString& caption,
764 const bool open, const bool showQuickDir,
765 SUIT_FileValidator* validator )
767 SUIT_FileDlg fd( parent, open, showQuickDir, true );
769 fd.setFileMode( open ? ExistingFile : AnyFile );
771 QString tmpfilename = initial;
772 tmpfilename = tmpfilename.simplified();
773 tmpfilename = tmpfilename.replace(QRegExp("\\*"), "" ).replace(QRegExp("\\?"), "" );
775 if ( filters.isEmpty() )
776 fd.setNameFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
778 fd.setNameFilters( filters );
780 if ( !caption.isEmpty() )
781 fd.setWindowTitle( caption );
783 if ( !tmpfilename.isEmpty() )
784 fd.processPath( tmpfilename );
787 fd.setValidator( validator );
791 if ( fd.exec() == QDialog::Accepted )
792 filename = fd.selectedFile();
794 QApplication::processEvents();
800 \brief Show dialog box for the file opening/saving.
803 This method can be used to select the file for opening
804 or saving. The behavior is defined by the \a open parameter.
805 Note, that selection validation depends on the dialog mode used.
807 If \a initial parameter is not null string it is used as starting directory
808 or file at which dialog box is opened.
810 The parameter \a filters defines file filters (wildcards) to be used.
811 This is the list of wildcards, separated by the ";;" symbols.
812 If filters list is empty, "All files (*)" is used by default.
814 The parameter \a caption is used as dialog box title. If it is
815 is empty, the default title is used.
817 The parameter \a showQuickDir specifies if it is necessary to
818 show additional quick directories list controls in the bottom part
821 The validation of the user selection is done with help of the file
822 validator (SUIT_FileValidator class). The last parameter \a validator
823 can be used to pass the custom file validator to the dialog box.
825 \param parent parent widget
826 \param initial initial file (or directory) dialog box to be opened on
827 \param filters file filters separated by ";;"
828 \param caption dialog box title
829 \param open if \c true dialog box is used for file opening, otherwise - for saving
830 \param showQuickDir if \c true the quick directory list widgets will be shown
831 \param validator custom file validator
832 \return selected file name or null string if dialog box is cancelled
833 \sa getOpenFileNames(), getExistingDirectory()
835 QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial,
836 const QString& filters, const QString& caption,
837 const bool open, const bool showQuickDir,
838 SUIT_FileValidator* validator )
840 return getFileName( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
841 caption, open, showQuickDir, validator );
845 \brief Show dialog box for the multiple files selection.
847 If \a initial parameter is not null string it is used as starting directory
848 or file at which dialog box is opened.
850 The parameter \a filters defines file filters (wildcards) to be used.
851 If filters list is empty, "All files (*)" is used by default.
853 The parameter \a caption is used as dialog box title. If it is
854 is empty, the default title is used.
856 The parameter \a showQuickDir specifies if it is necessary to
857 show additional quick directories list controls in the bottom part
860 The validation of the user selection is done with help of the file
861 validator (SUIT_FileValidator class). The last parameter \a validator
862 can be used to pass the custom file validator to the dialog box.
864 \param parent parent widget
865 \param initial initial file (or directory) dialog box to be opened on
866 \param filters file filters list
867 \param caption dialog box title
868 \param showQuickDir if \c true the quick directory list widgets will be shown
869 \param validator custom file validator
870 \return selected file names or empty list if dialog box is cancelled
871 \sa getFileName(), getExistingDirectory()
873 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
874 const QStringList& filters, const QString& caption,
875 const bool showQuickDir,
876 SUIT_FileValidator* validator )
878 SUIT_FileDlg fd( parent, true, showQuickDir, true );
880 fd.setFileMode( ExistingFiles );
882 if ( filters.isEmpty() )
883 fd.setNameFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*)
885 fd.setNameFilters( filters );
887 if ( !caption.isEmpty() )
888 fd.setWindowTitle( caption );
890 if ( !initial.isEmpty() )
891 fd.processPath( initial );
894 fd.setValidator( validator );
896 QStringList filenames;
898 if ( fd.exec() == QDialog::Accepted )
899 filenames = fd.selectedFiles();
901 QApplication::processEvents();
907 \brief Show dialog box for the multiple file opening.
910 If \a initial parameter is not null string it is used as starting directory
911 or file at which dialog box is opened.
913 The parameter \a filters defines file filters (wildcards) to be used.
914 This is the list of wildcards, separated by the ";;" symbols.
915 If filters list is empty, "All files (*)" is used by default.
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 file (or directory) dialog box to be opened on
930 \param filters file filters separated by ";;"
931 \param caption dialog box title
932 \param showQuickDir if \c true the quick directory list widgets will be shown
933 \param validator custom file validator
934 \return selected file names or empty list if dialog box is cancelled
935 \sa getFileName(), getExistingDirectory()
937 QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial,
938 const QString& filters, const QString& caption,
939 const bool showQuickDir,
940 SUIT_FileValidator* validator )
942 return getOpenFileNames( parent, initial, filters.split( ";;", QString::SkipEmptyParts ),
943 caption, showQuickDir, validator );
947 \brief Show dialog box for the existing directory selection.
949 If \a initial parameter is not null string it is used as starting directory
950 at which dialog box is opened.
952 The parameter \a caption is used as dialog box title. If it is
953 is empty, the default title is used.
955 The parameter \a showQuickDir specifies if it is necessary to
956 show additional quick directories list controls in the bottom part
959 The validation of the user selection is done with help of the file
960 validator (SUIT_FileValidator class). The last parameter \a validator
961 can be used to pass the custom file validator to the dialog box.
963 \param parent parent widget
964 \param initial initial directory dialog box to be opened on
965 \param caption dialog box title
966 \param showQuickDir if \c true the quick directory list widgets will be shown
967 \param validator custom file validator
968 \return selected directory name or null string if dialog box is cancelled
969 \sa getFileName(), getOpenFileNames()
971 QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, const QString& initial,
972 const QString& caption, const bool showQuickDir,
973 SUIT_FileValidator* validator )
975 SUIT_FileDlg fd( parent, true, showQuickDir, true );
977 fd.setFileMode( DirectoryOnly );
979 if ( !caption.isEmpty() )
980 fd.setWindowTitle( caption );
982 if ( !initial.isEmpty() )
983 fd.processPath( initial );
986 fd.setValidator( validator );
990 if ( fd.exec() == QDialog::Accepted )
991 dirname = fd.selectedFile();
993 QApplication::processEvents();
999 \brief Get last visited path
1000 \return last visited path
1002 QString SUIT_FileDlg::getLastVisitedPath()
1004 return myLastVisitedPath;
1008 \brief Selects current file
1010 This version of selectFile() methods works similar to Qt version 3.x:
1011 it selects the given file as current and it changes the current file dialog's directory
1012 to the directory of the file
1014 \param f - new current file name
1016 void SUIT_FileDlg::selectFile( const QString& f )
1018 QFileDialog::selectFile( QFileInfo( f ).baseName() );
1019 if ( !Qtx::dir( f, false ).isEmpty() )
1020 setDirectory( QFileInfo( f ).absolutePath() );