File indexing completed on 2024-04-28 11:41:16

0001 // -*- c++ -*-
0002 /*
0003     This file is part of the KDE libraries
0004     SPDX-FileCopyrightText: 1999 Stephan Kulow <coolo@kde.org>
0005     SPDX-FileCopyrightText: 2000, 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 #ifndef KDIROPERATOR_H_
0010 #define KDIROPERATOR_H_
0011 
0012 #include "kiofilewidgets_export.h"
0013 #include <kfile.h>
0014 
0015 #include <QStyleOptionViewItem>
0016 #include <QUrl>
0017 #include <QWidget>
0018 
0019 class QAbstractItemView;
0020 class QMenu;
0021 class QModelIndex;
0022 class QProgressBar;
0023 
0024 class KActionCollection;
0025 class KActionMenu;
0026 class KConfigGroup;
0027 class KFileItemList;
0028 class KFilePreviewGenerator;
0029 class KPreviewWidgetBase;
0030 
0031 #include <KToggleAction> // SIC TODO KF6: Not used, remove
0032 #include <QStack> // SIC TODO KF6: Not used, remove
0033 
0034 // SIC TODO KF6: forward-declaration is enough for these three
0035 #include <KCompletion>
0036 #include <KDirLister>
0037 #include <KFileItem>
0038 
0039 namespace KIO
0040 {
0041 class CopyJob;
0042 class DeleteJob;
0043 }
0044 
0045 class KDirOperatorPrivate;
0046 
0047 /**
0048  * @class KDirOperator kdiroperator.h <KDirOperator>
0049  *
0050  * This widget works as a network transparent filebrowser. You specify a URL
0051  * to display and this url will be loaded via KDirLister. The user can
0052  * browse through directories, highlight and select files, delete or rename
0053  * files.
0054  *
0055  * It supports different views, e.g. a detailed view (see KFileDetailView),
0056  * a simple icon view (see KFileIconView), a combination of two views,
0057  * separating directories and files ( KCombiView).
0058  *
0059  * Additionally, a preview view is available (see KFilePreview), which can
0060  * show either a simple or detailed view and additionally a preview widget
0061  * (see setPreviewWidget()). KImageFilePreview is one implementation
0062  * of a preview widget, that displays previews for all supported filetypes
0063  * utilizing KIO::PreviewJob.
0064  *
0065  * Currently, those classes don't support Drag&Drop out of the box -- there
0066  * you have to use your own view-classes. You can use some DnD-aware views
0067  * from Björn Sahlström <bjorn@kbear.org> until they will be integrated
0068  * into this library. See http://devel-home.kde.org/~pfeiffer/DnD-classes.tar.gz
0069  *
0070  * This widget is the one used in the KFileWidget.
0071  *
0072  * Basic usage is like this:
0073  * \code
0074  *   KDirOperator *op = new KDirOperator(QUrl("file:///home/gis"), this);
0075  *   // some signals you might be interested in
0076  *   connect(op, &KDirOperator::urlEntered, this, [this](const QUrl &url) { slotUrlEntered(url); });
0077  *   connect(op, &KDirOperator::fileHighlighted, this, [this](const KFileItem &item) { slotFileHighlighted(item) });
0078  *   connect(op, &KDirOperator::fileSelected, this, [this](const KFileItem &item) { slotFileSelected(item) });
0079  *   connect(op, &KDirOperator::finishedLoading, this, [this]() { slotLoadingFinished(); };
0080  *
0081  *   KConfigGroup grp(KSharedConfig::openConfig(),"Your KDiroperator ConfigGroup" );
0082  *   op->readConfig( &grp);
0083  *   op->setViewMode(KFile::Default);
0084  * \endcode
0085  *
0086  * This will create a childwidget of 'this' showing the directory contents
0087  * of /home/gis in the default-view. The view is determined by the readConfig()
0088  * call, which will read the KDirOperator settings, the user left your program
0089  * with (and which you saved with op->writeConfig()).
0090  *
0091  * @short A widget for displaying files and browsing directories.
0092  * @author Stephan Kulow <coolo@kde.org>, Carsten Pfeiffer <pfeiffer@kde.org>
0093  */
0094 class KIOFILEWIDGETS_EXPORT KDirOperator : public QWidget
0095 {
0096     Q_OBJECT
0097 
0098 public:
0099     /**
0100      * The various action types. These values can be or'd together
0101      */
0102     enum ActionType {
0103         SortActions = 1,
0104         ViewActions = 2,
0105         NavActions = 4,
0106         FileActions = 8,
0107         AllActions = 15,
0108     };
0109 
0110     /**
0111      * Actions provided by KDirOperator that can be accessed from the outside using action()
0112      */
0113     enum Action {
0114         /**
0115          * An ActionMenu presenting a popupmenu with all actions
0116          */
0117         PopupMenu,
0118         /**
0119          * Changes to the parent directory
0120          */
0121         Up,
0122         /**
0123          * Goes back to the previous directory
0124          */
0125         Back,
0126         /**
0127          * Goes forward in the history
0128          */
0129         Forward,
0130         /**
0131          * Changes to the user's home directory
0132          */
0133         Home,
0134         /**
0135          * Reloads the current directory
0136          */
0137         Reload,
0138         /*
0139          * A KNewFileMenu
0140          */
0141         New,
0142         /**
0143          * Opens a dialog box to create a directory
0144          */
0145         NewFolder,
0146         Rename,
0147         Trash,
0148         /**
0149          * Deletes the selected files/directories
0150          */
0151         Delete,
0152         /**
0153          * An ActionMenu containing all sort-options
0154          */
0155         SortMenu,
0156         /**
0157          * Sorts by name
0158          */
0159         SortByName,
0160         /**
0161          * Sorts by size
0162          */
0163         SortBySize,
0164         /**
0165          * Sorts by date
0166          */
0167         SortByDate,
0168         /**
0169          * Sorts by type
0170          */
0171         SortByType,
0172         /**
0173          * Changes sort order to ascending
0174          */
0175         SortAscending,
0176         /**
0177          * Changes sort order to descending
0178          */
0179         SortDescending,
0180         /**
0181          * Sorts folders before files
0182          */
0183         SortFoldersFirst,
0184         /**
0185          * Sorts hidden files last
0186          */
0187         SortHiddenFilesLast,
0188         /**
0189          *  an ActionMenu containing all actions concerning the view
0190          */
0191         ViewModeMenu,
0192         ViewIconsView,
0193         ViewCompactView,
0194         ViewDetailsView,
0195         DecorationMenu,
0196         DecorationAtTop,
0197         DecorationAtLeft,
0198         /**
0199          * Shows a simple fileview
0200          */
0201         ShortView,
0202         /**
0203          * Shows a detailed fileview (dates, permissions ,...)
0204          */
0205         DetailedView,
0206 
0207         TreeView,
0208         DetailedTreeView,
0209         AllowExpansionInDetailsView,
0210         /**
0211          * shows hidden files
0212          */
0213         ShowHiddenFiles,
0214         /**
0215          * shows a preview next to the fileview
0216          */
0217         ShowPreviewPanel,
0218         ShowPreview,
0219         OpenContainingFolder,
0220         /**
0221          * Shows a KPropertiesDialog for the selected files
0222          */
0223         Properties,
0224     };
0225 
0226     /**
0227      * Constructs the KDirOperator with no initial view. As the views are
0228      * configurable, call readConfig() to load the user's configuration
0229      * and then setView to explicitly set a view.
0230      *
0231      * This constructor doesn't start loading the url, setView will do it.
0232      */
0233     explicit KDirOperator(const QUrl &urlName = QUrl{}, QWidget *parent = nullptr);
0234     /**
0235      * Destroys the KDirOperator.
0236      */
0237     ~KDirOperator() override;
0238 
0239     /**
0240      * Enables/disables showing hidden files.
0241      */
0242     virtual void setShowHiddenFiles(bool s);
0243 
0244     /**
0245      * @returns true when hidden files are shown or false otherwise.
0246      */
0247     bool showHiddenFiles() const;
0248 
0249     /**
0250      * Stops loading immediately. You don't need to call this, usually.
0251      */
0252     void close();
0253 
0254     /**
0255      * Sets a filter like "*.cpp *.h *.o". Only files matching that filter
0256      * will be shown.
0257      *
0258      * @see KDirLister::setNameFilter
0259      * @see nameFilter
0260      */
0261     void setNameFilter(const QString &filter);
0262 
0263     /**
0264      * @returns the current namefilter.
0265      * @see setNameFilter
0266      */
0267     QString nameFilter() const;
0268 
0269     /**
0270      * Sets a list of MIME types as filter. Only files of those MIME types
0271      * will be shown.
0272      *
0273      * Example:
0274      * \code
0275      * QStringList filter;
0276      * filter << "text/html" << "image/png" << "inode/directory";
0277      * dirOperator->setMimefilter( filter );
0278      * \endcode
0279      *
0280      * Node: Without the MIME type inode/directory, only files would be shown.
0281      * Call updateDir() to apply it.
0282      *
0283      * @see KDirLister::setMimeFilter
0284      * @see mimeFilter
0285      */
0286     void setMimeFilter(const QStringList &mimetypes);
0287 
0288     /**
0289      * @returns the current MIME type filter.
0290      */
0291     QStringList mimeFilter() const;
0292 
0293     /**
0294      * Only show the files in a given set of MIME types.
0295      * This is useful in specialized applications (while file managers, on
0296      * the other hand, want to show all MIME types). Internally uses
0297      * KNewFileMenu::setSupportedMimeTypes
0298      *
0299      * Example:
0300      * \code
0301      * QStringList mimeTypes;
0302      * mimeTypes << "text/html" << "inode/directory";
0303      * dirOperator->setNewFileMenuSupportedMimeTypes(mimeTypes);
0304      * \endcode
0305      *
0306      * Note: If the list is empty, all options will be shown. Otherwise,
0307      * without the MIME type inode/directory, only file options will be shown.
0308      *
0309      * @see KNewFileMenu::setSupportedMimeTypes
0310      * @see newFileMenuSupportedMimeTypes
0311      * @since 4.5
0312      */
0313     void setNewFileMenuSupportedMimeTypes(const QStringList &mime);
0314 
0315     /**
0316      * @returns the current Supported Mimes Types.
0317      * @since 4.5
0318      */
0319     QStringList newFileMenuSupportedMimeTypes() const;
0320 
0321     /**
0322      * Setting this to true will make a directory get selected when trying to create a new one that has the same name.
0323      *
0324      * @since 5.76
0325      */
0326     void setNewFileMenuSelectDirWhenAlreadyExist(bool selectOnDirExists);
0327 
0328     /**
0329      * Clears both the namefilter and MIME type filter, so that all files and
0330      * directories will be shown. Call updateDir() to apply it.
0331      *
0332      * @see setMimeFilter
0333      * @see setNameFilter
0334      */
0335     void clearFilter();
0336 
0337     /**
0338      * @returns the current url
0339      */
0340     QUrl url() const;
0341 
0342     /**
0343      * Sets a new url to list.
0344      * @param clearforward specifies whether the "forward" history should be cleared.
0345      * @param url the URL to set
0346      */
0347     virtual void setUrl(const QUrl &url, bool clearforward);
0348 
0349     /**
0350      * Clears the current selection and attempts to set @p url
0351      * the current url file.
0352      */
0353     void setCurrentItem(const QUrl &url);
0354 
0355     /**
0356      * Clears the current selection and attempts to set @p item
0357      * as the current item.
0358      */
0359     void setCurrentItem(const KFileItem &item);
0360 
0361     /**
0362      * Clears the current selection and attempts to set @p urls
0363      * the current url files.
0364      * @since 4.2
0365      */
0366     void setCurrentItems(const QList<QUrl> &urls);
0367 
0368     /**
0369      * Clears the current selection and attempts to set @p items
0370      * as the current items.
0371      * @since 4.2
0372      */
0373     void setCurrentItems(const KFileItemList &items);
0374 
0375     // Not _ENABLED_ because this is a virtual method
0376 #if KIOFILEWIDGETS_BUILD_DEPRECATED_SINCE(5, 100)
0377     /**
0378      * Sets a new view to be used for showing and browsing files.
0379      * Note: this will read the current url() to fill the view.
0380      *
0381      * @see KFileTreeView
0382      * @see view
0383      *
0384      * @deprecated since 5.100, no known users.
0385      */
0386     KIOFILEWIDGETS_DEPRECATED_VERSION(5, 100, "No known users.")
0387     virtual void setView(QAbstractItemView *view);
0388 #endif
0389 
0390     /**
0391      * @returns the currently used view.
0392      * @see setView
0393      */
0394     QAbstractItemView *view() const;
0395 
0396     // Not _ENABLED_ because this is a virtual method
0397 #if KIOFILEWIDGETS_BUILD_DEPRECATED_SINCE(5, 100)
0398     /**
0399      * Sets one of the predefined fileviews.
0400      * @see KFile::FileView
0401      * @deprecated Since 5.100, use setViewMode(KFile::FileView).
0402      */
0403     KIOFILEWIDGETS_DEPRECATED_VERSION_BELATED(5, 103, 5, 100, "Use setViewMode(KFile::FileView)")
0404     virtual void setView(KFile::FileView viewKind);
0405 #endif
0406 
0407     /**
0408      * Set the view mode to one of the predefined modes.
0409      * @see KFile::FileView
0410      *
0411      * @since 5.100
0412      */
0413     void setViewMode(KFile::FileView viewKind);
0414 
0415     /**
0416      * Returns the current view mode.
0417      * @returns KFile::FileView
0418      * @see KFile::FileView
0419      * @since 5.0
0420      */
0421     KFile::FileView viewMode() const;
0422 
0423     /**
0424      * Sets the way to sort files and directories.
0425      */
0426     void setSorting(QDir::SortFlags);
0427 
0428     /**
0429      * @returns the current way of sorting files and directories
0430      */
0431     QDir::SortFlags sorting() const;
0432 
0433     /**
0434      * @returns true if we are displaying the root directory of the current url
0435      */
0436     bool isRoot() const;
0437 
0438     /**
0439      * @returns the object listing the directory
0440      */
0441     KDirLister *dirLister() const;
0442 
0443     /**
0444      * @returns the progress widget, that is shown during directory listing.
0445      * You can for example reparent() it to put it into a statusbar.
0446      */
0447     QProgressBar *progressBar() const;
0448 
0449     /**
0450      * Sets the listing/selection mode for the views, an OR'ed combination of
0451      * @li File
0452      * @li Directory
0453      * @li Files
0454      * @li ExistingOnly
0455      * @li LocalOnly
0456      *
0457      * You cannot mix File and Files of course, as the former means
0458      * single-selection mode, the latter multi-selection.
0459      */
0460     virtual void setMode(KFile::Modes m);
0461     /**
0462      * @returns the listing/selection mode.
0463      */
0464     KFile::Modes mode() const;
0465 
0466     /**
0467      * Sets a preview-widget to be shown next to the file-view.
0468      * The ownership of @p w is transferred to KDirOperator, so don't
0469      * delete it yourself!
0470      */
0471     virtual void setPreviewWidget(KPreviewWidgetBase *w);
0472 
0473     /**
0474      * @returns a list of all currently selected items. If there is no view,
0475      * or there are no selected items, an empty list is returned.
0476      */
0477     KFileItemList selectedItems() const;
0478 
0479     /**
0480      * @returns true if @p item is currently selected, or false otherwise.
0481      */
0482     bool isSelected(const KFileItem &item) const;
0483 
0484     /**
0485      * @returns the number of directories in the currently listed url.
0486      * Returns 0 if there is no view.
0487      */
0488     int numDirs() const;
0489 
0490     /**
0491      * @returns the number of files in the currently listed url.
0492      * Returns 0 if there is no view.
0493      */
0494     int numFiles() const;
0495 
0496     /**
0497      * @returns a KCompletion object, containing all filenames and
0498      * directories of the current directory/URL.
0499      * You can use it to insert it into a KLineEdit or KComboBox
0500      * Note: it will only contain files, after prepareCompletionObjects()
0501      * has been called. It will be implicitly called from makeCompletion()
0502      * or makeDirCompletion()
0503      */
0504     KCompletion *completionObject() const;
0505 
0506     /**
0507      * @returns a KCompletion object, containing only all directories of the
0508      * current directory/URL.
0509      * You can use it to insert it into a KLineEdit or KComboBox
0510      * Note: it will only contain directories, after
0511      * prepareCompletionObjects() has been called. It will be implicitly
0512      * called from makeCompletion() or makeDirCompletion()
0513      */
0514     KCompletion *dirCompletionObject() const;
0515 
0516 #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(5, 100)
0517     /**
0518      * an accessor to a collection of all available Actions. The actions
0519      * are static, they will be there all the time (no need to connect to
0520      * the signals KActionCollection::inserted() or removed().
0521      *
0522      * There are the following actions:
0523      *
0524      * @li popupMenu : an ActionMenu presenting a popupmenu with all actions
0525      * @li up : changes to the parent directory
0526      * @li back : goes back to the previous directory
0527      * @li forward : goes forward in the history
0528      * @li home : changes to the user's home directory
0529      * @li reload : reloads the current directory
0530      * @li mkdir : opens a dialog box to create a directory
0531      * @li delete : deletes the selected files/directories
0532      * @li sorting menu : an ActionMenu containing all sort-options
0533      * @li by name : sorts by name
0534      * @li by size : sorts by size
0535      * @li by date : sorts by date
0536      * @li by type : sorts by type
0537      * @li descending : reverses the sort order
0538      * @li view menu : an ActionMenu containing all actions concerning the view
0539      * @li short view : shows a simple fileview
0540      * @li detailed view : shows a detailed fileview (dates, permissions ,...)
0541      * @li show hidden : shows hidden files
0542      * @li preview  : shows a preview next to the fileview
0543      * @li properties : shows a KPropertiesDialog for the selected files
0544      *
0545      * The short and detailed view are in an exclusive group. The sort-by
0546      * actions are in an exclusive group as well. Also the "separate dirs",
0547      * "preview" and "single" actions are in an exclusive group.
0548      *
0549      * You can e.g. use
0550      * \code
0551      * actionCollection()->action( "up" )->plug( someToolBar );
0552      * \endcode
0553      * to add a button into a toolbar, which makes the dirOperator change to
0554      * its parent directory.
0555      *
0556      * @returns all available Actions
0557      *
0558      * @deprecated since 5.100, use action() or allActions() instead.
0559      */
0560     KIOFILEWIDGETS_DEPRECATED_VERSION(5, 100, "Use action() or allActions() instead")
0561     KActionCollection *actionCollection() const;
0562 #endif
0563 
0564     /**
0565      * Obtain a given action from the KDirOperator's set of actions.
0566      *
0567      * You can e.g. use
0568      * \code
0569      * dirOperator->action(KDirOperator::Up)->plug(someToolBar);
0570      * \endcode
0571      * to add a button into a toolbar, which makes the dirOperator change to
0572      * its parent directory.
0573      *
0574      *  @since 5.100
0575      */
0576     QAction *action(KDirOperator::Action action) const;
0577 
0578     /**
0579      * A list of all actions for this KDirOperator.
0580      *
0581      * See action()
0582      *
0583      * @since 5.100
0584      *
0585      */
0586     QList<QAction *> allActions() const;
0587 
0588     /**
0589      * Sets the config object and the to be used group in KDirOperator. This
0590      * will be used to store the view's configuration.
0591      * If you don't set this, the views cannot save and restore their
0592      * configuration.
0593      *
0594      * Usually you call this right after KDirOperator creation so that the view
0595      * instantiation can make use of it already.
0596      *
0597      * Note that KDirOperator does NOT take ownership of that object (typically
0598      * it's KSharedConfig::openConfig() anyway.
0599      *
0600      * You must not delete the KConfig or KConfigGroup object (and master config object) before
0601      * either deleting the KDirOperator or  calling setViewConfig(0); or something like that
0602      *
0603      * @see viewConfig
0604      * @see viewConfigGroup
0605      */
0606     virtual void setViewConfig(KConfigGroup &configGroup);
0607 
0608     /**
0609      * @returns the group set by setViewConfig configuration.
0610      */
0611     KConfigGroup *viewConfigGroup() const;
0612 
0613     /**
0614      * Reads the default settings for a view, i.e.\ the default KFile::FileView.
0615      * Also reads the sorting and whether hidden files should be shown.
0616      * Note: the default view will not be set - you have to call
0617      * \code
0618      * setViewMode( KFile::Default )
0619      * \endcode
0620      * to apply it.
0621      *
0622      * @see setView
0623      * @see setViewConfig
0624      * @see writeConfig
0625      */
0626     virtual void readConfig(const KConfigGroup &configGroup);
0627 
0628     /**
0629      * Saves the current settings like sorting, simple or detailed view.
0630      *
0631      * @see readConfig
0632      * @see setViewConfig
0633      */
0634     virtual void writeConfig(KConfigGroup &configGroup);
0635 
0636     /**
0637      * This toggles between double/single click file and directory selection mode.
0638      * When argument is true, files and directories are highlighted with single click and
0639      * selected (executed) with double click.
0640      *
0641      * NOTE: this currently has no effect.
0642      *
0643      * The default follows the single/double click system setting.
0644      */
0645     void setOnlyDoubleClickSelectsFiles(bool enable);
0646 
0647     /**
0648      * @returns whether files (not directories) should only be select()ed by
0649      * double-clicks.
0650      * @see setOnlyDoubleClickSelectsFiles
0651      */
0652     bool onlyDoubleClickSelectsFiles() const;
0653 
0654     /**
0655      * Toggles whether setUrl is called on newly created directories.
0656      * @since 5.62
0657      */
0658     void setFollowNewDirectories(bool enable);
0659 
0660     /**
0661      * @returns true if setUrl is called on newly created directories, false
0662      * otherwise. Enabled by default.
0663      * @since 5.62
0664      * @see setFollowNewDirectories
0665      */
0666     bool followNewDirectories() const;
0667 
0668     /**
0669      * Toggles whether setUrl is called on selected directories when a tree view
0670      * is used.
0671      * @since 5.62
0672      */
0673     void setFollowSelectedDirectories(bool enable);
0674 
0675     /**
0676      * @returns whether setUrl is called on selected directories when a tree
0677      * view is used. Enabled by default.
0678      * @since 5.62
0679      */
0680     bool followSelectedDirectories() const;
0681 
0682 #if KIOFILEWIDGETS_BUILD_DEPRECATED_SINCE(5, 78)
0683     /**
0684      * Creates the given directory/url. If it is a relative path,
0685      * it will be completed with the current directory.
0686      * If enterDirectory is true, the directory will be entered after a
0687      * successful operation. If unsuccessful, a messagebox will be presented
0688      * to the user.
0689      * @returns true if the directory could be created.
0690      */
0691     KIOFILEWIDGETS_DEPRECATED_VERSION(5,
0692                                       78,
0693                                       "Deprecated for lack of usage; use the other"
0694                                       " KDirOperator::mkdir() method instead.")
0695     virtual bool mkdir(const QString &directory, bool enterDirectory = true);
0696 #endif
0697 
0698     /**
0699      * Starts and returns a KIO::DeleteJob to delete the given @p items.
0700      *
0701      * @param items the list of items to be deleted
0702      * @param parent the parent widget used for the confirmation dialog
0703      * @param ask specifies whether a confirmation dialog should be shown
0704      * @param showProgress passed to the DeleteJob to show a progress dialog
0705      */
0706     virtual KIO::DeleteJob *del(const KFileItemList &items, QWidget *parent = nullptr, bool ask = true, bool showProgress = true);
0707 
0708     /**
0709      * Clears the forward and backward history.
0710      */
0711     void clearHistory();
0712 
0713     /**
0714      * When using the up or back actions to navigate the directory hierarchy, KDirOperator
0715      * can highlight the directory that was just left.
0716      *
0717      * For example:
0718      *  - starting in /a/b/c/, going up to /a/b, "c" will be highlighted
0719      *  - starting in /a/b/c, going up (twice) to /a, "b" will be highlighted;
0720      *    using the back action to go to /a/b/, "c" will be highlighted
0721      *  - starting in /a, going to "b", then going to "c", using the back action
0722      *    to go to /a/b/, "c" will be highlighted; using the back action again to go
0723      *    to /a/, "b" will be highlighted
0724      *
0725      * @see dirHighlighting. The default is to highlight directories when going back/up.
0726      */
0727     virtual void setEnableDirHighlighting(bool enable);
0728 
0729     /**
0730      * @returns whether the last directory will be made the current item
0731      * (and hence highlighted) when going up or back in the directory hierarchy
0732      *
0733      * Directories are highlighted by default.
0734      */
0735     bool dirHighlighting() const;
0736 
0737     /**
0738      * @returns true if we are in directory-only mode, that is, no files are
0739      * shown.
0740      */
0741     bool dirOnlyMode() const;
0742 
0743     static bool dirOnlyMode(uint mode);
0744 
0745     /**
0746      * Sets up the action menu.
0747      * @param whichActions is an value of OR'd ActionTypes that controls which actions to show in the action menu
0748      */
0749     void setupMenu(int whichActions);
0750 
0751     /**
0752      * Reimplemented - allow dropping of files if @p b is true, defaults to true since 5.59
0753      * @param b true if the widget should allow dropping of files
0754      */
0755     virtual void setAcceptDrops(bool b);
0756 
0757     /**
0758      * Sets the options for dropping files.
0759      * CURRENTLY NOT IMPLEMENTED
0760      */
0761     virtual void setDropOptions(int options);
0762 
0763     /**
0764      * Starts and returns a KIO::CopyJob to trash the given @p items.
0765      *
0766      * @param items the list of items to be trashed
0767      * @param parent the parent widget used for the confirmation dialog
0768      * @param ask specifies whether a confirmation dialog should be shown
0769      * @param showProgress passed to the CopyJob to show a progress dialog
0770      */
0771     virtual KIO::CopyJob *trash(const KFileItemList &items, QWidget *parent, bool ask = true, bool showProgress = true);
0772 
0773     /**
0774      * Returns the preview generator for the current view.
0775      * @since 4.2
0776      */
0777     KFilePreviewGenerator *previewGenerator() const;
0778 
0779     /**
0780      * Forces the inline previews to be shown or hidden, depending on @p show.
0781      *
0782      * @param show Whether to show inline previews or not.
0783      * @since 4.2
0784      */
0785     void setInlinePreviewShown(bool show);
0786 
0787     /**
0788      * Returns the position where icons are shown relative to the labels
0789      * of file items in the icon view.
0790      * @since 4.2.3
0791      */
0792     QStyleOptionViewItem::Position decorationPosition() const;
0793 
0794     /**
0795      * Sets the position where icons shall be shown relative to the labels
0796      * of file items in the icon view.
0797      * @since 4.2.3
0798      */
0799     void setDecorationPosition(QStyleOptionViewItem::Position position);
0800 
0801     /**
0802      * Returns whether the inline previews are shown or not.
0803      * @since 4.2
0804      */
0805     bool isInlinePreviewShown() const;
0806 
0807 #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(5, 76)
0808     /**
0809      * Returns the icon zoom.
0810      * @since 4.2
0811      */
0812     KIOFILEWIDGETS_DEPRECATED_VERSION(5, 76, "Use KDirOperator::iconSize()")
0813     int iconsZoom() const;
0814 #endif
0815 
0816     /**
0817      * Returns the icon size in pixels, ranged from KIconLoader::SizeSmall (16) to
0818      * KIconLoader::SizeEnormous (128).
0819      *
0820      * @since 5.76
0821      */
0822     int iconSize() const;
0823 
0824     /**
0825      * If the system is set up to trigger items on single click, if @p isSaving
0826      * is true, we will force to double click to accept.
0827      * @note this is false by default
0828      * @since 4.2
0829      */
0830     void setIsSaving(bool isSaving);
0831 
0832     /**
0833      * Returns whether KDirOperator will force a double click to accept.
0834      * @note this is false by default
0835      * @since 4.2
0836      */
0837     bool isSaving() const;
0838 
0839     /**
0840      * Returns the URL schemes that the file widget should allow navigating to.
0841      *
0842      * If the returned list is empty, all schemes are supported.
0843      *
0844      * @sa QFileDialog::supportedSchemes
0845      * @since 5.43
0846      */
0847     QStringList supportedSchemes() const;
0848 
0849     /**
0850      * Call with @c true to add open-with actions to items in the view.
0851      * This can be useful when you're attaching an image or text file to
0852      * an email or uploading an image to some online service, and need to
0853      * check the contents before going forward.
0854      *
0855      * @since 5.87
0856      */
0857     void showOpenWithActions(bool enable);
0858 
0859 protected:
0860     /**
0861      * A view factory for creating predefined fileviews. Called internally by setView,
0862      * but you can also call it directly. Reimplement this if you depend on self defined fileviews.
0863      * @param parent   is the QWidget to be set as parent
0864      * @param viewKind is the predefined view to be set, note: this can be several ones OR:ed together
0865      * @returns the created view
0866      * @see KFile::FileView
0867      * @see setView
0868      */
0869     virtual QAbstractItemView *createView(QWidget *parent, KFile::FileView viewKind);
0870 
0871     /**
0872      * Sets a custom KDirLister to list directories.
0873      * The KDirOperator takes ownership of the given KDirLister.
0874      */
0875     virtual void setDirLister(KDirLister *lister);
0876 
0877     void resizeEvent(QResizeEvent *event) override;
0878 
0879     void keyPressEvent(QKeyEvent *event) override; // TODO KF6 REMOVE
0880 
0881     /**
0882      * Sets up all the actions. Called from the constructor, you usually
0883      * better not call this.
0884      */
0885     void setupActions();
0886 
0887     /**
0888      * Updates the sorting-related actions to comply with the current sorting
0889      * @see sorting
0890      */
0891     void updateSortActions();
0892 
0893     /**
0894      * Updates the view-related actions to comply with the current
0895      * KFile::FileView
0896      */
0897     void updateViewActions();
0898 
0899     /**
0900      * Sets up the context-menu with all the necessary actions. Called from the
0901      * constructor, you usually don't need to call this.
0902      */
0903     void setupMenu();
0904 
0905     /**
0906      * Synchronizes the completion objects with the entries of the
0907      * currently listed url.
0908      *
0909      * Automatically called from makeCompletion() and
0910      * makeDirCompletion()
0911      */
0912     void prepareCompletionObjects();
0913 
0914     /**
0915      * Checks if there support from KIO::PreviewJob for the currently
0916      * shown files, taking mimeFilter() and nameFilter() into account
0917      * Enables/disables the preview-action accordingly.
0918      */
0919     bool checkPreviewSupport();
0920 
0921     /**
0922      * Called upon right-click to activate the popupmenu.
0923      */
0924     virtual void activatedMenu(const KFileItem &item, const QPoint &pos);
0925 
0926     void changeEvent(QEvent *event) override;
0927 
0928     bool eventFilter(QObject *watched, QEvent *event) override;
0929 
0930 public Q_SLOTS:
0931     /**
0932      * Goes one step back in the history and opens that url.
0933      */
0934     virtual void back();
0935 
0936     /**
0937      * Goes one step forward in the history and opens that url.
0938      */
0939     virtual void forward();
0940 
0941     /**
0942      * Enters the home directory.
0943      */
0944     virtual void home();
0945 
0946     /**
0947      * Goes one directory up from the current url.
0948      */
0949     virtual void cdUp();
0950 
0951     /**
0952      * to update the view after changing the settings
0953      */
0954     void updateDir();
0955 
0956     /**
0957      * Re-reads the current url.
0958      */
0959     virtual void rereadDir();
0960 
0961     /**
0962      * Opens a dialog to create a new directory.
0963      */
0964     virtual void mkdir();
0965 
0966     /**
0967      * Deletes the currently selected files/directories.
0968      */
0969     virtual void deleteSelected();
0970 
0971     /**
0972      * Enables/disables actions that are selection dependent. Call this e.g.
0973      * when you are about to show a popup menu using some of KDirOperators
0974      * actions.
0975      */
0976     void updateSelectionDependentActions();
0977 
0978     /**
0979      * Tries to complete the given string (only completes files).
0980      */
0981     QString makeCompletion(const QString &);
0982 
0983     /**
0984      * Tries to complete the given string (only completes directories).
0985      */
0986     QString makeDirCompletion(const QString &);
0987 
0988     /**
0989      * Initiates a rename operation on the currently selected files/directories,
0990      * prompting the user to choose a new name(s) for the currently selected items
0991      * @see renamingFinished
0992      * @since 5.67
0993      */
0994     void renameSelected();
0995 
0996     /**
0997      * Trashes the currently selected files/directories.
0998      *
0999      * This function used to take activation reason and keyboard modifiers,
1000      * in order to call deleteSelected() if the user wanted to delete.
1001      * Instead, call deleteSelected().
1002      *
1003      * FIXME KAction Port: link deleteSelected() up correctly
1004      */
1005     virtual void trashSelected();
1006 
1007 #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(5, 76)
1008     /**
1009      * Notifies that the icons size should change. @p value is an int ranged from 0 to 100.
1010      * 100 means KIconLoader::SizeEnormous.
1011      * @since 4.2
1012      */
1013     KIOFILEWIDGETS_DEPRECATED_VERSION(5, 76, "Use KDirOperator::setIconSize(int)")
1014     void setIconsZoom(int value);
1015 #endif
1016 
1017     /**
1018      * Notifies that the icons size should change. @p value is the icon size in pixels, ranged
1019      * from KIconLoader::SizeSmall (16) to KIconLoader::SizeEnormous (128).
1020      *
1021      * @since 5.76
1022      */
1023     void setIconSize(int value);
1024 
1025     /**
1026      * Set the URL schemes that the file widget should allow navigating to.
1027      *
1028      * If the returned list is empty, all schemes are supported. Examples for
1029      * schemes are @c "file" or @c "ftp".
1030      *
1031      * @sa QFileDialog::setSupportedSchemes
1032      * @since 5.43
1033      */
1034     void setSupportedSchemes(const QStringList &schemes);
1035 
1036 protected Q_SLOTS:
1037     /**
1038      * Restores the normal cursor after showing the busy-cursor. Also hides
1039      * the progressbar.
1040      */
1041     void resetCursor();
1042 
1043     /**
1044      * Called after setUrl() to load the directory, update the history,
1045      * etc.
1046      */
1047     void pathChanged();
1048 
1049     /**
1050      * Enters the directory specified by the given @p item.
1051      */
1052     virtual void selectDir(const KFileItem &item);
1053 
1054     /**
1055      * Emits fileSelected( item )
1056      */
1057     void selectFile(const KFileItem &item);
1058 
1059     /**
1060      * Emits fileHighlighted(item)
1061      */
1062     void highlightFile(const KFileItem &item);
1063 
1064     /**
1065      * Changes sorting to sort by name
1066      */
1067     void sortByName();
1068 
1069     /**
1070      * Changes sorting to sort by size
1071      */
1072     void sortBySize();
1073 
1074     /**
1075      * Changes sorting to sort by date
1076      */
1077     void sortByDate();
1078 
1079     /**
1080      * Changes sorting to sort by date
1081      */
1082     void sortByType();
1083 
1084     /**
1085      * Changes sorting to reverse sorting
1086      */
1087     void sortReversed();
1088 
1089     /**
1090      * Toggles showing directories first / having them sorted like files.
1091      */
1092     void toggleDirsFirst();
1093 
1094     /**
1095      * Toggles case sensitive / case insensitive sorting
1096      */
1097     void toggleIgnoreCase();
1098 
1099     /**
1100      * Tries to make the given @p match as current item in the view and emits
1101      * completion( match )
1102      */
1103     void slotCompletionMatch(const QString &match);
1104 
1105 Q_SIGNALS:
1106     void urlEntered(const QUrl &);
1107     void updateInformation(int files, int dirs);
1108     void completion(const QString &);
1109     void finishedLoading();
1110 
1111     /**
1112      * Emitted whenever the current fileview is changed, either by an explicit
1113      * call to setView() or by the user selecting a different view thru
1114      * the GUI.
1115      */
1116     void viewChanged(QAbstractItemView *newView);
1117 
1118     /**
1119      * Emitted when a file is highlighted or generally the selection changes in
1120      * multiselection mode. In the latter case, @p item is a null KFileItem.
1121      * You can access the selected items with selectedItems().
1122      */
1123     void fileHighlighted(const KFileItem &item);
1124     void dirActivated(const KFileItem &item);
1125     void fileSelected(const KFileItem &item);
1126     /**
1127      * Emitted when files are dropped. Dropping files is disabled by
1128      * default. You need to enable it with setAcceptDrops()
1129      * @param item the item on which the drop occurred or 0.
1130      * @param event the drop event itself.
1131      * @param urls the urls that where dropped.
1132      */
1133     void dropped(const KFileItem &item, QDropEvent *event, const QList<QUrl> &urls);
1134 
1135     /**
1136      * Emitted just before the context menu is shown, allows users to
1137      * extend the menu with custom actions.
1138      *
1139      * @param item the file on which the context menu was invoked
1140      * @param menu the context menu, pre-populated with the file-management actions
1141      * @since 4.2
1142      */
1143     void contextMenuAboutToShow(const KFileItem &item, QMenu *menu);
1144 
1145     /**
1146      * Will notify that the icon size has changed. Since we save the icon size depending
1147      * on the view type (list view or a different kind of view), a call to setView() can
1148      * trigger this signal to be emitted.
1149      * @since 4.2
1150      */
1151     void currentIconSizeChanged(int size);
1152 
1153     /**
1154      * Triggered when the user hit Enter/Return
1155      * @since 5.57
1156      */
1157     void keyEnterReturnPressed();
1158 
1159     /**
1160      * Emitted when renaming selected files has finished.
1161      *
1162      * @param urls URL list of the renamed files
1163      * @since 5.96
1164      */
1165     void renamingFinished(const QList<QUrl> &urls);
1166 
1167 private:
1168     KIOFILEWIDGETS_NO_EXPORT void setViewInternal(QAbstractItemView *view);
1169 
1170     friend class KDirOperatorPrivate;
1171     std::unique_ptr<KDirOperatorPrivate> d;
1172 };
1173 
1174 #endif