class KDirOperator

A widget for displaying files and browsing directories. More...

Definition#include <kdiroperator.h>
InheritsQWidget (qt) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Public Slots

Signals

Protected Methods

Protected Slots


Detailed Description

This widget works as a network transparent filebrowser. You specify a URL to display and this url will be loaded via KDirLister. The user can browse through directories, highlight and select files, delete or rename files.

It supports different views, e.g. a detailed view (see @KFileDetailView), a simple icon view (see @KFileIconView), a combination of two views, separating directories and files (@see KCombiView).

Additionally, a preview view is available (see @KFilePreview), which can show either a simple or detailed view and additionally a preview widget (see setPreviewWidget()). KImageFilePreview is one implementation of a preview widget, that displays previews for all supported filetypes utilizing KIO::PreviewJob.

Currently, those classes don't support Drag&Drop out of the box -- there you have to use your own view-classes. You can use some DnD-aware views from Björn Sahlström until they will be integrated into this library. See http://master.kde.org/~pfeiffer/DnD-classes.tar.gz

This widget is the one used in the KFileDialog.

Basic usage is like this:


   KDirOperator *op = new KDirOperator( KURL( "file:/home/gis" ), this );
   // some signals you might be interested in
   connect(op, SIGNAL(updateInformation(int, int)),
           SLOT(updateStatusLine(int, int)));
   connect(op, SIGNAL(urlEntered(const KURL&)),
           SLOT(urlEntered(const KURL&)));
   connect(op, SIGNAL(fileHighlighted(const KFileViewItem *)),
           SLOT(fileHighlighted(const KFileViewItem *)));
   connect(op, SIGNAL(fileSelected(const KFileViewItem *)),
           SLOT(fileSelected(const KFileViewItem *)));
   connect(op, SIGNAL(finishedLoading()),
           SLOT(slotLoadingFinished()));

   op->readConfig( KGlobal::config(), "Your KDiroperator ConfigGroup" );
   op->setView(KFile::Default);

This will create a childwidget of 'this' showing the directory contents of /home/gis in the default-view. The view is determined by the readConfig() call, which will read the KDirOperator settings, the user left your program with (and which you saved with op->saveConfig()).

 KDirOperator (const KURL& urlName = KURL(), QWidget *parent = 0, const char* name = 0)

KDirOperator

Constructs the KDirOperator with no initial view. As the views are configurable, call readConfig() to load the user's configuration and then setView to explicitly set a view.

This constructor doesn't start loading the url, setView will do it.

 ~KDirOperator ()

~KDirOperator

[virtual]

Destroys the KDirOperator.

void  setShowHiddenFiles ( bool s )

setShowHiddenFiles

Enable/disable showing hidden files.

bool  showHiddenFiles ()

showHiddenFiles

[const]

Returns: true when hidden files are shown or false otherwise.

void  close ()

close

Stops loading immediately. You don't need to call this, usually.

Reimplemented from QWidget.

void  setNameFilter (const QString& filter)

setNameFilter

Set a filter like "*.cpp *.h *.o". Only files matching that filter will be shown. Call rereadDir() to apply it.

See also: setNameFilter, nameFilter

const QString&  nameFilter ()

nameFilter

[const]

Returns: the current namefilter.

See also: setNameFilter

void  setMimeFilter ( const QStringList& mimetypes )

setMimeFilter

Sets a list of mimetypes as filter. Only files of those mimetypes will be shown.

Example:


 QStringList filter;
 filter << "text/html" << "image/png" << "inode/directory";
 dirOperator->setMimefilter( filter );

Node: Without the mimetype inode/directory, only files would be shown.

See also: setMimeFilter, mimeFilter

QStringList  mimeFilter ()

mimeFilter

[const]

void  clearFilter ()

clearFilter

Clears both the namefilter and mimetype filter, so that all files and directories will be shown.

See also: setMimeFilter, setNameFilter

KURL  url ()

url

[const]

Returns: the current url

void  setURL (const KURL& url, bool clearforward)

setURL

Sets a new url to list.

Parameters:
clearforwardspecifies whether the "forward" history should be cleared.

void  setCurrentItem ( const QString& filename )

setCurrentItem

Clears the current selection and attempts to set filename the current file. filename is just the name, no path or url.

void  setView (KFileView *view)

setView

Sets a new KFileView to be used for showing and browsing files. Note: this will read the current url() to fill the view.

See also: KFileView, KFileIconView, KFileDetailView, view, view

const KFileView *  view ()

view

[const]

Returns: the currently used view.

See also: setView

QWidget *  viewWidget ()

viewWidget

[const]

Returns the widget of the current view. 0L if there is no view/widget. (KFileView itself is not a widget.)

void  setView (KFile::FileView view)

setView

Sets one of the predefine fileviews

See also: FileView

void  setSorting ( QDir::SortSpec )

setSorting

Sets the way to sort files and directories.

QDir::SortSpec  sorting ()

sorting

[const]

Returns: the current way of sorting files and directories

bool  isRoot ()

isRoot

[const]

Returns: true if we are displaying the root directory of the current url

KFileReaderfileReader ()

fileReader

[const]

Returns: the object listing the directory (KFileReader inherits KDirLister).

KProgress *  progressBar ()

progressBar

[const]

Returns: the progress widget, that is shown during directory listing. You can for example reparent() it to put it into a statusbar.

void  setMode ( KFile::Mode m )

setMode

Sets the listing/selection mode for the views, an OR'ed combination of

You cannot mix File and Files of course, as the former means single-selection mode, the latter multi-selection.

KFile::Mode  mode ()

mode

[const]

void  setPreviewWidget (const QWidget *w)

setPreviewWidget

Sets a preview-widget to be shown next to the file-view. The ownership of w is transferred to KDirOperator, so don't delete it yourself!

const KFileViewItemList *  selectedItems ()

selectedItems

[const]

Returns: a list of all currently selected items. If there is no view, then 0L is returned.

inline bool  isSelected ( const KFileViewItem *item )

isSelected

[const]

Returns: true if item is currently selected, or false otherwise.

int  numDirs ()

numDirs

[const]

Returns: the number of directories in the currently listed url. Returns 0 if there is no view.

int  numFiles ()

numFiles

[const]

Returns: the number of files in the currently listed url. Returns 0 if there is no view.

KCompletion *  completionObject ()

completionObject

[const]

Returns: a KCompletion object, containing all filenames and directories of the current directory/URL. You can use it to insert it into a KLineEdit or KComboBox Note: it will only contain files, after prepareCompletionObjects() has been called. It will be implicitly called from makeCompletion() or makeDirCompletion()

KCompletiondirCompletionObject ()

dirCompletionObject

[const]

Returns: a KCompletion object, containing only all directories of the current directory/URL. You can use it to insert it into a KLineEdit or KComboBox Note: it will only contain directories, after prepareCompletionObjects() has been called. It will be implicitly called from makeCompletion() or makeDirCompletion()

KActionCollection *  actionCollection ()

actionCollection

[const]

an accessor to a collection of all available Actions. The actions are static, they will be there all the time (no need to connect to the signals KActionCollection::inserted() or removed().

There are the following actions:

The short and detailed view are in an exclusive group. The sort-by actions are in an exclusive group as well. Also the "separate dirs", "preview" and "single" actions are in an exclusive group.

You can e.g. use

actionCollection()->action( "up" )->plug( someToolBar );
to add a button into a toolbar, which makes the dirOperator change to its parent directory. @returns all available Actions

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

readConfig

[virtual]

Reads the default settings for a view, i.e. the default KFile::FileView. Also reads the sorting and whether hidden files should be shown. Note: the default view will not be set - you have to call

@ref setView( KFile::Default )
to apply it. @see #saveConfig

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

saveConfig

[virtual]

Saves the current settings like sorting, simple or detailed view.

See also: readConfig

void  setOnlyDoubleClickSelectsFiles ( bool enable )

setOnlyDoubleClickSelectsFiles

This is a KFileDialog specific hack: we want to select directories with single click, but not files. But as a generic class, we have to be able to select files on single click as well.

This gives us the opportunity to do both.

The default is false, set it to true if you don't want files selected with single click.

bool  onlyDoubleClickSelectsFiles ()

onlyDoubleClickSelectsFiles

[const]

Returns: whether files (not directories) should only be select()ed by double-clicks.

See also: setOnlyDoubleClickSelectsFiles

bool  mkdir ( const QString& directory, bool enterDirectory = true )

mkdir

Creates the given directory/url. If it is a relative path, it will be completed with the current directory. If enterDirectory is true, the directory will be entered after a successful operation. If unsuccessful, a messagebox will be presented to the user.

Returns: true if the directory could be created.

KIO::DeleteJob *  del ( const KFileViewItemList& items, bool ask = true, bool showProgress = true )

del

Starts and returns a KIO::DeleteJob to delete the given items.

Parameters:
askspecifies whether a confirmation dialog should be shown
showProgresspassed to the DeleteJob to show a progress dialog

void  clearHistory ()

clearHistory

Clears the forward and backward history.

void  setEnableDirHighlighting ( bool enable )

setEnableDirHighlighting

When going up in the directory hierarchy, KDirOperator can highlight the directory that was just left.

I.e. when you go from /home/gis/src to /home/gis, the item "src" will be made the current item.

Default is off.

bool  dirHighlighting ()

dirHighlighting

[const]

Default is false.

Returns: whether the last directory will be made the current item when going up in the directory hierarchy.

bool  dirOnlyMode ()

dirOnlyMode

[const]

Returns: true if we are in directory-only mode, that is, no files are shown.

void  setFileReader ( KFileReader *reader )

setFileReader

[protected]

Sets a custom KFileReader to list directories.

void  resizeEvent ( QResizeEvent * )

resizeEvent

[protected]

Reimplemented from QWidget for internal purposes..

void  setupActions ()

setupActions

[protected]

Sets up all the actions. Called from the constructor, you usually better not call this.

void  updateSortActions ()

updateSortActions

[protected]

Updates the sorting-related actions to comply with the current sorting

See also: sorting

void  updateViewActions ()

updateViewActions

[protected]

Updates the view-related actions to comply with the current KFile::FileView

void  setupMenu ()

setupMenu

[protected]

Sets up the context-menu with all the necessary actions. Called from the constructor, you usually don't need to call this.

void  prepareCompletionObjects ()

prepareCompletionObjects

[protected]

Synchronizes the completion objects with the entries of the currently listed url.

Automatically called from makeCompletion() and makeDirCompletion()

bool  checkPreviewSupport ()

checkPreviewSupport

[protected]

Checks if there support from KIO::PreviewJob for the currently shown files, taking mimeFilter() and nameFilter() into account Enables/disables the preview-action accordingly.

void  back ()

back

[slot]

Goes one step back in the history and opens that url.

void  forward ()

forward

[slot]

Goes one step forward in the history and opens that url.

void  home ()

home

[slot]

Enters the home directory.

void  cdUp ()

cdUp

[slot]

Goes one directory up from the current url.

void  rereadDir ()

rereadDir

[slot]

Re-reads the current url.

void  mkdir ()

mkdir

[slot]

Opens a dialog to create a new directory.

void  deleteSelected ()

deleteSelected

[slot]

Deletes the currently selected files/directories.

void  updateSelectionDependentActions ()

updateSelectionDependentActions

[slot]

Enables/disables actions that are selection dependent. Call this e.g. when you are about to show a popup menu using some of KDirOperators actions.

QString  makeCompletion (const QString&)

makeCompletion

[slot]

Tries to complete the given string (only completes files).

QString  makeDirCompletion (const QString&)

makeDirCompletion

[slot]

Tries to complete the given string (only completes directores).

void  resetCursor ()

resetCursor

[protected slots slot]

Restores the normal cursor after showing the busy-cursor. Also hides the progressbar.

void  readNextMimeType ()

readNextMimeType

[protected slots slot]

void  pathChanged ()

pathChanged

[protected slots slot]

Called after setURL() to load the directory, update the history, etc.

void  filterChanged ()

filterChanged

[protected slots slot]

void  insertNewFiles (const KFileItemList &newone)

insertNewFiles

[protected slots slot]

Adds a new list of KFileItems to the view (coming from KFileReader/KDirLister)

void  itemDeleted (KFileItem *)

itemDeleted

[protected slots slot]

Removes the given KFileItem item from the view (usually called from KFileReader/KDirLister).

void  selectDir (const KFileViewItem *item )

selectDir

[protected slots slot]

Enters the directory specified by the given item.

void  selectFile (const KFileViewItem *item)

selectFile

[protected slots slot]

Emits fileSelected( item )

void  highlightFile (const KFileViewItem* i)

highlightFile

[protected slots slot]

Emits fileHighlighted( i )

void  activatedMenu ( const KFileViewItem * )

activatedMenu

[protected slots virtual slot]

Called upon right-click to activate the popupmenu.

void  sortByName ()

sortByName

[protected slots slot]

Changes sorting to sort by name

void  sortBySize ()

sortBySize

[protected slots slot]

Changes sorting to sort by size

void  sortByDate ()

sortByDate

[protected slots slot]

Changes sorting to sort by date

void  sortReversed ()

sortReversed

[protected slots slot]

Changes sorting to reverse sorting

void  toggleDirsFirst ()

toggleDirsFirst

[protected slots slot]

Toggles showing directories first / having them sorted like files.

void  toggleIgnoreCase ()

toggleIgnoreCase

[protected slots slot]

Toggles case sensitive / case insensitive sorting

void  deleteOldView ()

deleteOldView

[protected slots slot]

internal

void  slotCompletionMatch (const QString& match)

slotCompletionMatch

[protected slots slot]

Tries to make the given match as current item in the view and emits completion( match )

void  urlEntered (const KURL& )

urlEntered

[signal]

void  updateInformation (int files, int dirs)

updateInformation

[signal]

void  completion (const QString&)

completion

[signal]

void  finishedLoading ()

finishedLoading

[signal]

void  viewChanged ( KFileView * newView )

viewChanged

[signal]

Emitted whenever the current fileview is changed, either by an explicit call to setView() or by the user selecting a different view thru the GUI.

void  fileHighlighted (const KFileViewItem*)

fileHighlighted

[signal]

void  dirActivated (const KFileViewItem*)

dirActivated

[signal]

void  fileSelected (const KFileViewItem*)

fileSelected

[signal]