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