# class KFileDialog | A file selection dialog. More...
Definition | `#include <kfiledialog.h>`
Inherits | KDialogBase (kdeui) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- KFileDialog (const QString& startDir, const QString& filter, QWidget *parent, const char *name, bool modal)
- ~KFileDialog ()
- KURL selectedURL () const
- KURL::List selectedURLs () const
- KURL baseURL () const
- QString selectedFile () const
- QStringList selectedFiles () const
- void setURL (const KURL &url, bool clearforward = true)
- void setSelection (const QString& name)
- void setKeepLocation ( bool keep )
- bool keepsLocation () const
- void setFilter (const QString& filter)
- QString currentFilter () const
- void setFilterMimeType (const QString &label, const KMimeType::List &types, const KMimeType::Ptr &defaultType)
- KMimeType::Ptr currentFilterMimeType ()
- void setPreviewWidget (const QWidget *w)
- void setMode ( KFile::Mode m )
- KFile::Mode mode () const
- void setLocationLabel (const QString& text)
- KToolBar * toolBar () const
- QPushButton * okButton () const
- QPushButton * cancelButton () const

#### Signals

- void fileSelected (const QString&)
- void fileHighlighted (const QString&)
- void selectionChanged ()
- void filterChanged ( const QString& filter )

#### Public Static Methods

- static QString getOpenFileName (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null)
- static QStringList getOpenFileNames (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent = 0, const QString& caption= QString::null)
- static KURL getOpenURL (const QString& startDir = QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null)
- static KURL::List getOpenURLs (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent = 0, const QString& caption= QString::null)
- static QString getSaveFileName (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null)
- static KURL getSaveURL (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null)
- static QString getExistingDirectory (const QString & startDir = QString::null, QWidget * parent = 0, const QString& caption= QString::null)

#### Protected Methods

- void addDirEntry (KFileViewItem *entry, bool disableUpdating)
- virtual void initGUI ()
- void multiSelectionChanged ()
- virtual void readConfig ( KConfig *, const QString& group = QString::null )
- virtual void saveConfig ( KConfig *, const QString& group = QString::null )
- virtual void readRecentFiles ( KConfig * )
- virtual void saveRecentFiles ( KConfig * )
- KURL::List tokenize (const QString& line) const
- KURL::List& parseSelectedURLs () const

#### Protected Slots

- void urlEntered ( const KURL& )
- void pathComboActivated ( const KURL& url )
- void pathComboReturnPressed ( const QString& url )
- void locationActivated ( const QString& url )
- void toolbarCallback (int)
- void toolbarPressedCallback (int)
- void slotFilterChanged ()
- void pathComboChanged ( const QString& )
- void fileHighlighted (const KFileViewItem *i)
- void fileSelected (const KFileViewItem *i)
- void slotStatResult (KIO::Job* job)
- void slotLoadingFinished ()
- void dirCompletion ( const QString& )
- void fileCompletion ( const QString& )
- virtual void updateStatusLine (int dirs, int files)
- virtual void slotOk ()
- virtual void accept ()
- virtual void slotCancel ()
- void addToBookmarks ()
- void bookmarksChanged ()
- void fillBookmarkMenu ( KFileBookmark *parent, QPopupMenu *menu, int &id )

#### Protected Members

- KToolBar *toolbar
- static KURL *lastDirectory
- QPopupMenu *bookmarksMenu
- KURLComboBox *locationEdit
- KFileFilter *filterWidget
- KFileBookmarkManager *bookmarks
- QStringList history
- KFileDialogPrivate *d
- KDirOperator *ops
- bool autoDirectoryFollowing

## Detailed Description

Provide a user (and developer) friendly way to select files and directories.

The widget can be used as a drop in replacement for the QFileDialog widget, but has greater functionality and a nicer GUI.

You will usually want to use one of the static methods getOpenFileName(), getSaveFileName(), getOpenURL() or for multiple files getOpenFileNames() or getOpenURLs().

The dialog has been designed to allow applications to customise it by subclassing. It uses geometry management to ensure that subclasses can easily add children that will be incorporated into the layout.

KFileDialog (const QString& startDir, const QString& filter, QWidget *parent, const char *name, bool modal) | ### KFileDialog

Construct a file dialog.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | A shell glob that specifies which files to display. See setFilter() for details on how to use this argument.
acceptURLs | If set to `false`, KFileDialog will just accept files on the local filesystem.

~KFileDialog () | ### ~KFileDialog

Destruct the file dialog.

KURL selectedURL () | ### selectedURL

[const]

Returns: The selected fully qualified filename.

KURL::List selectedURLs () | ### selectedURLs

[const]

Returns: The list of selected URLs.

KURL baseURL () | ### baseURL

[const]

Returns: the currently shown directory.

QString selectedFile () | ### selectedFile

[const]

Retrieve the full path of the selected file in the local filesystem. (Local files only)

QStringList selectedFiles () | ### selectedFiles

[const]

Retrieve a list of all selected local files.

void setURL (const KURL &url, bool clearforward = true) | ### setURL

Set the directory to view.

Parameters:

url | URL to show.
clearforward | Indicates whether the forward queue should be cleared.

void setSelection (const QString& name) | ### setSelection

Set the file name to preselect to `name`

This takes absolute URLs and relative file names.

void setKeepLocation ( bool keep ) | ### setKeepLocation

Sets whether the filename/url should be kept when changing directories. This is for example useful when having a predefined filename where the full path for that file is searched.

getSaveFileName() and getSaveURL() set this to true by default, so that you can type in the filename and change the directory without having to type the name again.

bool keepsLocation () | ### keepsLocation

[const]

Returns: whether the contents of the location edit are kept when changing directories.

void setFilter (const QString& filter) | ### setFilter

Set the filter to be used to `filter`.

You can set more filters for the user to select seperated by '\n'. Every filter entry is defined through namefilter|text to diplay. If no | is found in the expression, just the namefilter is shown. Examples:

     kfile->setFilter("*.cpp|C++ Source Files\n*.h|Header files");
     kfile->setFilter("*.cpp");
     kfile->setFilter("*.cpp|Sources (*.cpp)");
     kfile->setFilter("*.cpp *.cc *.C|C++ Source Files\n*.h *.H|Header files");

Note: The text to display is not parsed in any way. So, if you want to show the suffix to select by a specific filter, you must repeat it.

See also: filterChanged()

QString currentFilter () | ### currentFilter

[const]

Retrieve the current filter as entered by the user or one of the predefined set via setFilter().

Parameters:

filter | Contains the new filter (only the extension part, not the explanation), for example, "*.cpp" or "*.cpp *.cc".

See also: setFilter(), filterChanged()

void setFilterMimeType (const QString &label, const KMimeType::List &types, const KMimeType::Ptr &defaultType) | ### setFilterMimeType

Set the filter up to specify the output type.

Do not use in conjunction with setFilter()

Parameters:

label | the label to use instead of "Filter:"
types | a list of mimetypes that can be used as output format
defaultType | the default mimetype to use as output format.

KMimeType::Ptr currentFilterMimeType () | ### currentFilterMimeType

The mimetype for the desired output format.

This is only valid if setFilterMimeType() has been called previously.

See also: setFilterMimeType()

void setPreviewWidget (const QWidget *w) | ### setPreviewWidget

Add a preview widget and enter the preview mode.

In this mode the dialog is split and the right part contains your widget. This widget has to inherit QWidget and it has to implement a slot showPreview(const KURL &); which is called every time the file changes. You may want to look at koffice/lib/kofficecore/koFilterManager.cc for some hints :)

QString getOpenFileName (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null) | ### getOpenFileName

[static]

Create a modal file dialog and return the selected filename or an empty string if none was chosen.

Note that with this method the user must select an existing filename.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

QStringList getOpenFileNames (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent = 0, const QString& caption= QString::null) | ### getOpenFileNames

[static]

Create a modal file dialog and return the selected filenames or an empty list if none was chosen.

Note that with this method the user must select an existing filename.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

KURL getOpenURL (const QString& startDir = QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null) | ### getOpenURL

[static]

Create a modal file dialog and return the selected URL or an empty string if none was chosen.

Note that with this method the user must select an existing URL.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

KURL::List getOpenURLs (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent = 0, const QString& caption= QString::null) | ### getOpenURLs

[static]

Create a modal file dialog and return the selected URLs or an empty list if none was chosen.

Note that with this method the user must select an existing filename.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

QString getSaveFileName (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null) | ### getSaveFileName

[static]

Create a modal file dialog and return the selected filename or an empty string if none was chosen.

Note that with this method the user need not select an existing filename.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

KURL getSaveURL (const QString& startDir= QString::null, const QString& filter= QString::null, QWidget *parent= 0, const QString& caption = QString::null) | ### getSaveURL

[static]

Create a modal file dialog and returns the selected filename or an empty string if none was chosen.

Note that with this method the user need not select an existing filename.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
filter | This is a space seperated list of shell globs.
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

QString getExistingDirectory (const QString & startDir = QString::null, QWidget * parent = 0, const QString& caption= QString::null) | ### getExistingDirectory

[static]

Create a modal file dialog and returns the selected directory or an empty string if none was chosen.

Note that with this method the user need not select an existing directory.

- The URL of the directory to start in.
- QString::null to start in the current working directory, or the last directory where a file has been selected.
- ':<keyword>' to start in the directory last used by a filedialog in the same application that specified the same keyword.
- '::<keyword' to start in the direcotry last used by a filedialog in any application that specified the same keyword.

Parameters:

startDir | This can either be
parent | The widget the dialog will be centered on initially.
caption | The name of the dialog widget.

void show () | ### show

[virtual]

void setMode ( KFile::Mode m ) | ### setMode

Set the mode of the dialog.

The mode is defined as (in kfile.h):

        enum Mode {
                          File         = 1,
                          Directory    = 2,
                          Files        = 4,
                          ExistingOnly = 8,
                          LocalOnly    = 16
                        };

You can OR the values, e.g.

     KFile::Mode mode = static_cast<KFile::Mode>( KFile::Files |
                                                  KFile::ExistingOnly |
                                                  KFile::LocalOnly );
     setMode( mode );

You need an explicit cast, which looks a little ugly, but is unavoidable without using (even uglier) #defines.

KFile::Mode mode () | ### mode

[const]

Retrieve the mode of the filedialog.

See also: setMode()

void setLocationLabel (const QString& text) | ### setLocationLabel

Set the text to be displayed in front of the selection.

The default is "Location". Most useful if you want to make clear what the location is used for.

KToolBar * toolBar () | ### toolBar

[const]

Retrieve a pointer to the toolbar.

You can use this to insert custom items into it, e.g.:

          yourAction = new KAction( i18n("Your Action"), 0,
                                    this, SLOT( yourSlot() ),
                                    this, "action name" );
          yourAction->plug( kfileDialog->toolBar() );

QPushButton * okButton () | ### okButton

[const]

Returns: a pointer to the OK-Button in the filedialog. You may use it e.g. to set a custom text to it.

QPushButton * cancelButton () | ### cancelButton

[const]

Returns: a pointer to the Cancel-Button in the filedialog. You may use it e.g. to set a custom text to it.

void fileSelected (const QString&) | ### fileSelected

[signal]

Emitted when the user selects a file. It is only emitted in single- selection mode. The best way to get notified about selected file(s) is to connect to the okClicked() signal inherited from KDialogBase and call selectedFile(), selectedFiles(), selectedURL() or selectedURLs().

void fileHighlighted (const QString&) | ### fileHighlighted

[signal]

Emitted when the user highlights a file.

void selectionChanged () | ### selectionChanged

[signal]

Emitted when the user hilights one or more files in multiselection mode.

Note: fileHighlighted() or fileSelected() are not emitted in multiselection mode. You may use selectedItems() to ask for the current highlighted items.

See also: fileSelected

void filterChanged ( const QString& filter ) | ### filterChanged

[signal]

Emitted when the filter changed, i.e. the user entered an own filter or chose one of the predefined set via setFilter().

Parameters:

filter | contains the new filter (only the extension part, not the explanation), i.e. "*.cpp" or "*.cpp *.cc".

See also: setFilter(), currentFilter()

KToolBar * toolbar | ### toolbar

[protected]

static KURL * lastDirectory | ### lastDirectory

[protected]

QPopupMenu * bookmarksMenu | ### bookmarksMenu

[protected]

KURLComboBox * locationEdit | ### locationEdit

[protected]

KFileFilter * filterWidget | ### filterWidget

[protected]

KFileBookmarkManager * bookmarks | ### bookmarks

[protected]

QStringList history | ### history

[protected]

void addDirEntry (KFileViewItem *entry, bool disableUpdating) | ### addDirEntry

[protected]

adds a entry of the current directory. If disableUpdating is set to true, it will care about clever updating

void initGUI () | ### initGUI

[protected virtual]

rebuild geometry managment.

void multiSelectionChanged () | ### multiSelectionChanged

[protected]

called when an item is highlighted/selected in multiselection mode. handles setting the locationEdit.

void readConfig ( KConfig *, const QString& group = QString::null ) | ### readConfig

[protected virtual]

Reads configuration and applies it (size, recent directories, ...)

void saveConfig ( KConfig *, const QString& group = QString::null ) | ### saveConfig

[protected virtual]

Saves the current configuration

void readRecentFiles ( KConfig * ) | ### readRecentFiles

[protected virtual]

Reads the recent used files and inserts them into the location combobox

void saveRecentFiles ( KConfig * ) | ### saveRecentFiles

[protected virtual]

Saves the entries from the location combobox.

KURL::List tokenize (const QString& line) | ### tokenize

[protected const]

Parses the string "line" for files. If line doesn't contain any ", the whole line will be interpreted as one file. If the number of " is odd, an empty list will be returned. Otherwise, all items enclosed in " " will be returned as correct urls.

void urlEntered ( const KURL& ) | ### urlEntered

[protected slots slot]

void pathComboActivated ( const KURL& url ) | ### pathComboActivated

[protected slots slot]

void pathComboReturnPressed ( const QString& url ) | ### pathComboReturnPressed

[protected slots slot]

void locationActivated ( const QString& url ) | ### locationActivated

[protected slots slot]

void toolbarCallback (int) | ### toolbarCallback

[protected slots slot]

void toolbarPressedCallback (int) | ### toolbarPressedCallback

[protected slots slot]

void slotFilterChanged () | ### slotFilterChanged

[protected slots slot]

void pathComboChanged ( const QString& ) | ### pathComboChanged

[protected slots slot]

void fileHighlighted (const KFileViewItem *i) | ### fileHighlighted

[protected slots slot]

void fileSelected (const KFileViewItem *i) | ### fileSelected

[protected slots slot]

void slotStatResult (KIO::Job* job) | ### slotStatResult

[protected slots slot]

void slotLoadingFinished () | ### slotLoadingFinished

[protected slots slot]

void dirCompletion ( const QString& ) | ### dirCompletion

[protected slots slot]

void fileCompletion ( const QString& ) | ### fileCompletion

[protected slots slot]

void updateStatusLine (int dirs, int files) | ### updateStatusLine

[protected slots virtual slot]

void slotOk () | ### slotOk

[protected slots virtual slot]

Reimplemented from KDialogBase.

void accept () | ### accept

[protected slots virtual slot]

void slotCancel () | ### slotCancel

[protected slots virtual slot]

Reimplemented from KDialogBase.

void addToBookmarks () | ### addToBookmarks

[protected slots slot]

Add the current location to the global bookmarks list

void bookmarksChanged () | ### bookmarksChanged

[protected slots slot]

void fillBookmarkMenu ( KFileBookmark *parent, QPopupMenu *menu, int &id ) | ### fillBookmarkMenu

[protected slots slot]

KFileDialogPrivate * d | ### d

[protected]

KDirOperator * ops | ### ops

[protected]

bool autoDirectoryFollowing | ### autoDirectoryFollowing

[protected]

KURL::List& parseSelectedURLs () | ### parseSelectedURLs

[protected const]

- Author: Richard J. Moore <rich@kde.org>, Carsten Pfeiffer <pfeiffer@kde.org>
- Generated: root@sparc.ports.openbsd.org on Wed May 2 09:42:26 2001, using kdoc 2.0a53.