| 1 | // -*- c++ -*- |
| 2 | /* |
| 3 | This file is part of the KDE libraries |
| 4 | SPDX-FileCopyrightText: 1999 Stephan Kulow <coolo@kde.org> |
| 5 | SPDX-FileCopyrightText: 2000, 2001 Carsten Pfeiffer <pfeiffer@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 | */ |
| 9 | #ifndef KDIROPERATOR_H_ |
| 10 | #define KDIROPERATOR_H_ |
| 11 | |
| 12 | #include "kiofilewidgets_export.h" |
| 13 | #include <kfile.h> |
| 14 | |
| 15 | #include <KFileItem> |
| 16 | |
| 17 | #include <QStyleOptionViewItem> |
| 18 | #include <QUrl> |
| 19 | #include <QWidget> |
| 20 | |
| 21 | class QAbstractItemView; |
| 22 | class ; |
| 23 | class QModelIndex; |
| 24 | class QProgressBar; |
| 25 | |
| 26 | class KActionCollection; |
| 27 | class ; |
| 28 | class KCompletion; |
| 29 | class KConfigGroup; |
| 30 | class KDirLister; |
| 31 | class KFileItemList; |
| 32 | class KFilePreviewGenerator; |
| 33 | class KPreviewWidgetBase; |
| 34 | |
| 35 | namespace KIO |
| 36 | { |
| 37 | class CopyJob; |
| 38 | class DeleteJob; |
| 39 | } |
| 40 | |
| 41 | class KDirOperatorPrivate; |
| 42 | |
| 43 | /*! |
| 44 | * \class KDirOperator |
| 45 | * \inmodule KIOFileWidgets |
| 46 | * |
| 47 | * \brief A widget for displaying files and browsing directories. |
| 48 | * |
| 49 | * This widget works as a network transparent filebrowser. You specify a URL |
| 50 | * to display and this url will be loaded via KDirLister. The user can |
| 51 | * browse through directories, highlight and select files, delete or rename |
| 52 | * files. |
| 53 | * |
| 54 | * It supports different views, e.g. a detailed view (see KFileDetailView), |
| 55 | * a simple icon view (see KFileIconView), a combination of two views, |
| 56 | * separating directories and files ( KCombiView). |
| 57 | * |
| 58 | * Additionally, a preview view is available (see KFilePreview), which can |
| 59 | * show either a simple or detailed view and additionally a preview widget |
| 60 | * (see setPreviewWidget()). KImageFilePreview is one implementation |
| 61 | * of a preview widget, that displays previews for all supported filetypes |
| 62 | * utilizing KIO::PreviewJob. |
| 63 | * |
| 64 | * Currently, those classes don't support Drag&Drop out of the box -- there |
| 65 | * you have to use your own view-classes. You can use some DnD-aware views |
| 66 | * from Björn Sahlström <bjorn@kbear.org> until they will be integrated |
| 67 | * into this library. See http://devel-home.kde.org/~pfeiffer/DnD-classes.tar.gz |
| 68 | * |
| 69 | * This widget is the one used in the KFileWidget. |
| 70 | * |
| 71 | * Basic usage is like this: |
| 72 | * \code |
| 73 | * KDirOperator *op = new KDirOperator(QUrl("file:///home/gis"), this); |
| 74 | * // some signals you might be interested in |
| 75 | * connect(op, &KDirOperator::urlEntered, this, [this](const QUrl &url) { slotUrlEntered(url); }); |
| 76 | * connect(op, &KDirOperator::fileHighlighted, this, [this](const KFileItem &item) { slotFileHighlighted(item) }); |
| 77 | * connect(op, &KDirOperator::fileSelected, this, [this](const KFileItem &item) { slotFileSelected(item) }); |
| 78 | * connect(op, &KDirOperator::finishedLoading, this, [this]() { slotLoadingFinished(); }; |
| 79 | * |
| 80 | * KConfigGroup grp(KSharedConfig::openConfig(),"Your KDiroperator ConfigGroup" ); |
| 81 | * op->readConfig( &grp); |
| 82 | * op->setViewMode(KFile::Default); |
| 83 | * \endcode |
| 84 | * |
| 85 | * This will create a childwidget of 'this' showing the directory contents |
| 86 | * of /home/gis in the default-view. The view is determined by the readConfig() |
| 87 | * call, which will read the KDirOperator settings, the user left your program |
| 88 | * with (and which you saved with op->writeConfig()). |
| 89 | */ |
| 90 | class KIOFILEWIDGETS_EXPORT KDirOperator : public QWidget |
| 91 | { |
| 92 | Q_OBJECT |
| 93 | |
| 94 | public: |
| 95 | /*! |
| 96 | * The various action types. These values can be or'd together |
| 97 | * |
| 98 | * \value SortActions |
| 99 | * \value ViewActions |
| 100 | * \value NavActions |
| 101 | * \value FileActions |
| 102 | * \value AllActions |
| 103 | */ |
| 104 | enum ActionType { |
| 105 | SortActions = 1, |
| 106 | ViewActions = 2, |
| 107 | NavActions = 4, |
| 108 | FileActions = 8, |
| 109 | AllActions = 15, |
| 110 | }; |
| 111 | |
| 112 | /*! |
| 113 | * Actions provided by KDirOperator that can be accessed from the outside using action() |
| 114 | * |
| 115 | * \value PopupMenu An ActionMenu presenting a popupmenu with all actions |
| 116 | * \value Up Changes to the parent directory |
| 117 | * \value Back Goes back to the previous directory |
| 118 | * \value Forward Goes forward in the history |
| 119 | * \value Home Changes to the user's home directory |
| 120 | * \value Reload Reloads the current directory |
| 121 | * \value New A KNewFileMenu |
| 122 | * \value NewFolder Opens a dialog box to create a directory |
| 123 | * \value Rename |
| 124 | * \value Trash |
| 125 | * \value Delete Deletes the selected files/directories |
| 126 | * \value SortMenu An ActionMenu containing all sort-options |
| 127 | * \value SortByName Sorts by name |
| 128 | * \value SortBySize Sorts by size |
| 129 | * \value SortByDate Sorts by date |
| 130 | * \value SortByType Sorts by type |
| 131 | * \value SortAscending Changes sort order to ascending |
| 132 | * \value SortDescending Changes sort order to descending |
| 133 | * \value SortFoldersFirst Sorts folders before files |
| 134 | * \value SortHiddenFilesLast Sorts hidden files last |
| 135 | * \value ViewModeMenu an ActionMenu containing all actions concerning the view |
| 136 | * \value ViewIconsView |
| 137 | * \value ViewCompactView |
| 138 | * \value ViewDetailsView |
| 139 | * \value DecorationMenu |
| 140 | * \value DecorationAtTop |
| 141 | * \value DecorationAtLeft |
| 142 | * \value ShortView Shows a simple fileview |
| 143 | * \value DetailedView Shows a detailed fileview (dates, permissions ,...) |
| 144 | * \value TreeView |
| 145 | * \value DetailedTreeView |
| 146 | * \value AllowExpansionInDetailsView |
| 147 | * \value ShowHiddenFiles shows hidden files |
| 148 | * \value ShowPreviewPanel shows a preview next to the fileview |
| 149 | * \value ShowPreview |
| 150 | * \value OpenContainingFolder |
| 151 | * \value Properties Shows a KPropertiesDialog for the selected files |
| 152 | */ |
| 153 | enum Action { |
| 154 | , |
| 155 | Up, |
| 156 | Back, |
| 157 | Forward, |
| 158 | Home, |
| 159 | Reload, |
| 160 | New, |
| 161 | NewFolder, |
| 162 | Rename, |
| 163 | Trash, |
| 164 | Delete, |
| 165 | , |
| 166 | SortByName, |
| 167 | SortBySize, |
| 168 | SortByDate, |
| 169 | SortByType, |
| 170 | SortAscending, |
| 171 | SortDescending, |
| 172 | SortFoldersFirst, |
| 173 | SortHiddenFilesLast, |
| 174 | , |
| 175 | ViewIconsView, |
| 176 | ViewCompactView, |
| 177 | ViewDetailsView, |
| 178 | , |
| 179 | DecorationAtTop, |
| 180 | DecorationAtLeft, |
| 181 | ShortView, |
| 182 | DetailedView, |
| 183 | TreeView, |
| 184 | DetailedTreeView, |
| 185 | AllowExpansionInDetailsView, |
| 186 | ShowHiddenFiles, |
| 187 | ShowPreviewPanel, |
| 188 | ShowPreview, |
| 189 | OpenContainingFolder, |
| 190 | Properties, |
| 191 | }; |
| 192 | |
| 193 | /*! |
| 194 | * Constructs the KDirOperator with no initial view. As the views are |
| 195 | * configurable, call readConfig() to load the user's configuration |
| 196 | * and then setView to explicitly set a view. |
| 197 | * |
| 198 | * This constructor doesn't start loading the url, setView will do it. |
| 199 | */ |
| 200 | explicit KDirOperator(const QUrl &urlName = QUrl{}, QWidget *parent = nullptr); |
| 201 | |
| 202 | ~KDirOperator() override; |
| 203 | |
| 204 | /*! |
| 205 | * Enables/disables showing hidden files. |
| 206 | */ |
| 207 | virtual void setShowHiddenFiles(bool s); |
| 208 | |
| 209 | /*! |
| 210 | * Returns true when hidden files are shown or false otherwise. |
| 211 | */ |
| 212 | bool showHiddenFiles() const; |
| 213 | |
| 214 | /*! |
| 215 | * Stops loading immediately. You don't need to call this, usually. |
| 216 | */ |
| 217 | void close(); |
| 218 | |
| 219 | /*! |
| 220 | * Sets a filter like "*.cpp *.h *.o". Only files matching that filter |
| 221 | * will be shown. |
| 222 | * |
| 223 | * \sa KDirLister::setNameFilter |
| 224 | * \sa nameFilter |
| 225 | */ |
| 226 | void setNameFilter(const QString &filter); |
| 227 | |
| 228 | /*! |
| 229 | * Returns the current namefilter. |
| 230 | * \sa setNameFilter |
| 231 | */ |
| 232 | QString nameFilter() const; |
| 233 | |
| 234 | /*! |
| 235 | * Sets a list of MIME types as filter. Only files of those MIME types |
| 236 | * will be shown. |
| 237 | * |
| 238 | * Example: |
| 239 | * \code |
| 240 | * QStringList filter; |
| 241 | * filter << "text/html" << "image/png" << "inode/directory"; |
| 242 | * dirOperator->setMimefilter( filter ); |
| 243 | * \endcode |
| 244 | * |
| 245 | * Node: Without the MIME type inode/directory, only files would be shown. |
| 246 | * Call updateDir() to apply it. |
| 247 | * |
| 248 | * \sa KDirLister::setMimeFilter |
| 249 | * \sa mimeFilter |
| 250 | */ |
| 251 | void setMimeFilter(const QStringList &mimetypes); |
| 252 | |
| 253 | /*! |
| 254 | * Returns the current MIME type filter. |
| 255 | */ |
| 256 | QStringList mimeFilter() const; |
| 257 | |
| 258 | /*! |
| 259 | * Only show the files in a given set of MIME types. |
| 260 | * This is useful in specialized applications (while file managers, on |
| 261 | * the other hand, want to show all MIME types). Internally uses |
| 262 | * KNewFileMenu::setSupportedMimeTypes |
| 263 | * |
| 264 | * Example: |
| 265 | * \code |
| 266 | * QStringList mimeTypes; |
| 267 | * mimeTypes << "text/html" << "inode/directory"; |
| 268 | * dirOperator->setNewFileMenuSupportedMimeTypes(mimeTypes); |
| 269 | * \endcode |
| 270 | * |
| 271 | * Note: If the list is empty, all options will be shown. Otherwise, |
| 272 | * without the MIME type inode/directory, only file options will be shown. |
| 273 | * |
| 274 | * \sa KNewFileMenu::setSupportedMimeTypes |
| 275 | * \sa newFileMenuSupportedMimeTypes |
| 276 | */ |
| 277 | void (const QStringList &mime); |
| 278 | |
| 279 | /*! |
| 280 | * Returns the current Supported Mimes Types. |
| 281 | */ |
| 282 | QStringList () const; |
| 283 | |
| 284 | /*! |
| 285 | * Setting this to true will make a directory get selected when trying to create a new one that has the same name. |
| 286 | * |
| 287 | * \since 5.76 |
| 288 | */ |
| 289 | void (bool selectOnDirExists); |
| 290 | |
| 291 | /*! |
| 292 | * Clears both the namefilter and MIME type filter, so that all files and |
| 293 | * directories will be shown. Call updateDir() to apply it. |
| 294 | * |
| 295 | * \sa setMimeFilter |
| 296 | * \sa setNameFilter |
| 297 | */ |
| 298 | void clearFilter(); |
| 299 | |
| 300 | /*! |
| 301 | * Returns the current url |
| 302 | */ |
| 303 | QUrl url() const; |
| 304 | |
| 305 | /*! |
| 306 | * Sets a new url to list. |
| 307 | * |
| 308 | * \a clearforward specifies whether the "forward" history should be cleared. |
| 309 | * |
| 310 | * \a url the URL to set |
| 311 | */ |
| 312 | virtual void setUrl(const QUrl &url, bool clearforward); |
| 313 | |
| 314 | /*! |
| 315 | * Clears the current selection and attempts to set \a url |
| 316 | * the current url file. |
| 317 | */ |
| 318 | void setCurrentItem(const QUrl &url); |
| 319 | |
| 320 | /*! |
| 321 | * Clears the current selection and attempts to set \a item |
| 322 | * as the current item. |
| 323 | */ |
| 324 | void setCurrentItem(const KFileItem &item); |
| 325 | |
| 326 | /*! |
| 327 | * Clears the current selection and attempts to set \a urls |
| 328 | * the current url files. |
| 329 | */ |
| 330 | void setCurrentItems(const QList<QUrl> &urls); |
| 331 | |
| 332 | /*! |
| 333 | * Clears the current selection and attempts to set \a items |
| 334 | * as the current items. |
| 335 | */ |
| 336 | void setCurrentItems(const KFileItemList &items); |
| 337 | |
| 338 | /*! |
| 339 | * Returns the currently used view. |
| 340 | * \sa setViewMode |
| 341 | */ |
| 342 | QAbstractItemView *view() const; |
| 343 | |
| 344 | /*! |
| 345 | * Set the view mode to one of the predefined modes. |
| 346 | * \sa KFile::FileView |
| 347 | * |
| 348 | * \since 5.100 |
| 349 | */ |
| 350 | void setViewMode(KFile::FileView viewKind); |
| 351 | |
| 352 | /*! |
| 353 | * Returns the current view mode. |
| 354 | * \sa KFile::FileView |
| 355 | * \since 5.0 |
| 356 | */ |
| 357 | KFile::FileView viewMode() const; |
| 358 | |
| 359 | /*! |
| 360 | * Sets the way to sort files and directories. |
| 361 | */ |
| 362 | void setSorting(QDir::SortFlags); |
| 363 | |
| 364 | /*! |
| 365 | * Returns the current way of sorting files and directories |
| 366 | */ |
| 367 | QDir::SortFlags sorting() const; |
| 368 | |
| 369 | /*! |
| 370 | * Returns true if we are displaying the root directory of the current url |
| 371 | */ |
| 372 | bool isRoot() const; |
| 373 | |
| 374 | /*! |
| 375 | * Returns the object listing the directory |
| 376 | */ |
| 377 | KDirLister *dirLister() const; |
| 378 | |
| 379 | /*! |
| 380 | * Returns the progress widget, that is shown during directory listing. |
| 381 | * You can for example reparent() it to put it into a statusbar. |
| 382 | */ |
| 383 | QProgressBar *progressBar() const; |
| 384 | |
| 385 | /*! |
| 386 | * Sets the listing/selection mode for the views, an OR'ed combination of |
| 387 | * \list |
| 388 | * \li File |
| 389 | * \li Directory |
| 390 | * \li Files |
| 391 | * \li ExistingOnly |
| 392 | * \li LocalOnly |
| 393 | * \endlist |
| 394 | * |
| 395 | * You cannot mix File and Files of course, as the former means |
| 396 | * single-selection mode, the latter multi-selection. |
| 397 | */ |
| 398 | virtual void setMode(KFile::Modes m); |
| 399 | /*! |
| 400 | * Returns the listing/selection mode. |
| 401 | */ |
| 402 | KFile::Modes mode() const; |
| 403 | |
| 404 | /*! |
| 405 | * Sets a preview-widget to be shown next to the file-view. |
| 406 | * |
| 407 | * The ownership of \a w is transferred to KDirOperator, so don't |
| 408 | * delete it yourself! |
| 409 | */ |
| 410 | virtual void setPreviewWidget(KPreviewWidgetBase *w); |
| 411 | |
| 412 | /*! |
| 413 | * Returns a list of all currently selected items. If there is no view, |
| 414 | * or there are no selected items, an empty list is returned. |
| 415 | */ |
| 416 | KFileItemList selectedItems() const; |
| 417 | |
| 418 | /*! |
| 419 | * Returns true if \a item is currently selected, or false otherwise. |
| 420 | */ |
| 421 | bool isSelected(const KFileItem &item) const; |
| 422 | |
| 423 | /*! |
| 424 | * Returns the number of directories in the currently listed url. |
| 425 | * Returns 0 if there is no view. |
| 426 | */ |
| 427 | int numDirs() const; |
| 428 | |
| 429 | /*! |
| 430 | * Returns the number of files in the currently listed url. |
| 431 | * Returns 0 if there is no view. |
| 432 | */ |
| 433 | int numFiles() const; |
| 434 | |
| 435 | /*! |
| 436 | * Returns a KCompletion object, containing all filenames and |
| 437 | * directories of the current directory/URL. |
| 438 | * You can use it to insert it into a KLineEdit or KComboBox |
| 439 | * Note: it will only contain files, after prepareCompletionObjects() |
| 440 | * has been called. It will be implicitly called from makeCompletion() |
| 441 | * or makeDirCompletion() |
| 442 | */ |
| 443 | KCompletion *completionObject() const; |
| 444 | |
| 445 | /*! |
| 446 | * Returns a KCompletion object, containing only all directories of the |
| 447 | * current directory/URL. |
| 448 | * You can use it to insert it into a KLineEdit or KComboBox |
| 449 | * Note: it will only contain directories, after |
| 450 | * prepareCompletionObjects() has been called. It will be implicitly |
| 451 | * called from makeCompletion() or makeDirCompletion() |
| 452 | */ |
| 453 | KCompletion *dirCompletionObject() const; |
| 454 | |
| 455 | /*! |
| 456 | * Obtain a given action from the KDirOperator's set of actions. |
| 457 | * |
| 458 | * You can e.g. use |
| 459 | * \code |
| 460 | * dirOperator->action(KDirOperator::Up)->plug(someToolBar); |
| 461 | * \endcode |
| 462 | * to add a button into a toolbar, which makes the dirOperator change to |
| 463 | * its parent directory. |
| 464 | * |
| 465 | * \since 5.100 |
| 466 | */ |
| 467 | QAction *action(KDirOperator::Action action) const; |
| 468 | |
| 469 | /*! |
| 470 | * A list of all actions for this KDirOperator. |
| 471 | * |
| 472 | * See action() |
| 473 | * |
| 474 | * \since 5.100 |
| 475 | */ |
| 476 | QList<QAction *> allActions() const; |
| 477 | |
| 478 | /*! |
| 479 | * Sets the config object and the to be used group in KDirOperator. This |
| 480 | * will be used to store the view's configuration. |
| 481 | * If you don't set this, the views cannot save and restore their |
| 482 | * configuration. |
| 483 | * |
| 484 | * Usually you call this right after KDirOperator creation so that the view |
| 485 | * instantiation can make use of it already. |
| 486 | * |
| 487 | * Note that KDirOperator does NOT take ownership of that object (typically |
| 488 | * it's KSharedConfig::openConfig() anyway. |
| 489 | * |
| 490 | * You must not delete the KConfig or KConfigGroup object (and master config object) before |
| 491 | * either deleting the KDirOperator or calling setViewConfig(0); or something like that |
| 492 | * |
| 493 | * \sa viewConfigGroup |
| 494 | */ |
| 495 | virtual void setViewConfig(KConfigGroup &configGroup); |
| 496 | |
| 497 | /*! |
| 498 | * Returns the group set by setViewConfig configuration. |
| 499 | */ |
| 500 | KConfigGroup *viewConfigGroup() const; |
| 501 | |
| 502 | /*! |
| 503 | * Reads the default settings for a view, i.e.\ the default KFile::FileView. |
| 504 | * Also reads the sorting and whether hidden files should be shown. |
| 505 | * Note: the default view will not be set - you have to call |
| 506 | * \code |
| 507 | * setViewMode( KFile::Default ) |
| 508 | * \endcode |
| 509 | * to apply it. |
| 510 | * |
| 511 | * \sa setViewMode |
| 512 | * \sa setViewConfig |
| 513 | * \sa writeConfig |
| 514 | */ |
| 515 | virtual void readConfig(const KConfigGroup &configGroup); |
| 516 | |
| 517 | /*! |
| 518 | * Saves the current settings like sorting, simple or detailed view. |
| 519 | * |
| 520 | * \sa readConfig |
| 521 | * \sa setViewConfig |
| 522 | */ |
| 523 | virtual void writeConfig(KConfigGroup &configGroup); |
| 524 | |
| 525 | /*! |
| 526 | * This toggles between double/single click file and directory selection mode. |
| 527 | * When argument is true, files and directories are highlighted with single click and |
| 528 | * selected (executed) with double click. |
| 529 | * |
| 530 | * NOTE: this currently has no effect. |
| 531 | * |
| 532 | * The default follows the single/double click system setting. |
| 533 | */ |
| 534 | void setOnlyDoubleClickSelectsFiles(bool enable); |
| 535 | |
| 536 | /*! |
| 537 | * Returns whether files (not directories) should only be select()ed by |
| 538 | * double-clicks. |
| 539 | * \sa setOnlyDoubleClickSelectsFiles |
| 540 | */ |
| 541 | bool onlyDoubleClickSelectsFiles() const; |
| 542 | |
| 543 | /*! |
| 544 | * Toggles whether setUrl is called on newly created directories. |
| 545 | * \since 5.62 |
| 546 | */ |
| 547 | void setFollowNewDirectories(bool enable); |
| 548 | |
| 549 | /*! |
| 550 | * Returns true if setUrl is called on newly created directories, false |
| 551 | * otherwise. Enabled by default. |
| 552 | * \since 5.62 |
| 553 | * \sa setFollowNewDirectories |
| 554 | */ |
| 555 | bool followNewDirectories() const; |
| 556 | |
| 557 | /*! |
| 558 | * Toggles whether setUrl is called on selected directories when a tree view |
| 559 | * is used. |
| 560 | * \since 5.62 |
| 561 | */ |
| 562 | void setFollowSelectedDirectories(bool enable); |
| 563 | |
| 564 | /*! |
| 565 | * Returns whether setUrl is called on selected directories when a tree |
| 566 | * view is used. Enabled by default. |
| 567 | * \since 5.62 |
| 568 | */ |
| 569 | bool followSelectedDirectories() const; |
| 570 | |
| 571 | #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(6, 15) |
| 572 | /*! |
| 573 | * Starts and returns a KIO::DeleteJob to delete the given \a items. |
| 574 | * |
| 575 | * \a items the list of items to be deleted |
| 576 | * |
| 577 | * \a parent the parent widget used for the confirmation dialog |
| 578 | * |
| 579 | * \a ask specifies whether a confirmation dialog should be shown |
| 580 | * |
| 581 | * \a showProgress passed to the DeleteJob to show a progress dialog |
| 582 | * \deprecated[6.15] |
| 583 | */ |
| 584 | KIOFILEWIDGETS_DEPRECATED_VERSION(6, 15, "Use KIO::DeleteOrTrashJob instead" ) |
| 585 | virtual KIO::DeleteJob *del(const KFileItemList &items, QWidget *parent = nullptr, bool ask = true, bool showProgress = true); |
| 586 | #endif |
| 587 | |
| 588 | /*! |
| 589 | * Clears the forward and backward history. |
| 590 | */ |
| 591 | void clearHistory(); |
| 592 | |
| 593 | /*! |
| 594 | * When using the up or back actions to navigate the directory hierarchy, KDirOperator |
| 595 | * can highlight the directory that was just left. |
| 596 | * |
| 597 | * For example: |
| 598 | * \list |
| 599 | * \li starting in /a/b/c/, going up to /a/b, "c" will be highlighted |
| 600 | * \li starting in /a/b/c, going up (twice) to /a, "b" will be highlighted; |
| 601 | * using the back action to go to /a/b/, "c" will be highlighted |
| 602 | * \li starting in /a, going to "b", then going to "c", using the back action |
| 603 | * to go to /a/b/, "c" will be highlighted; using the back action again to go |
| 604 | * to /a/, "b" will be highlighted |
| 605 | * \endlist |
| 606 | * |
| 607 | * \sa dirHighlighting. |
| 608 | * The default is to highlight directories when going back/up. |
| 609 | */ |
| 610 | virtual void setEnableDirHighlighting(bool enable); |
| 611 | |
| 612 | /*! |
| 613 | * Returns whether the last directory will be made the current item |
| 614 | * (and hence highlighted) when going up or back in the directory hierarchy |
| 615 | * |
| 616 | * Directories are highlighted by default. |
| 617 | */ |
| 618 | bool dirHighlighting() const; |
| 619 | |
| 620 | /*! |
| 621 | * Returns true if we are in directory-only mode, that is, no files are |
| 622 | * shown. |
| 623 | */ |
| 624 | bool dirOnlyMode() const; |
| 625 | |
| 626 | static bool dirOnlyMode(uint mode); |
| 627 | |
| 628 | /*! |
| 629 | * Sets up the action menu. |
| 630 | * |
| 631 | * \a whichActions is an value of OR'd ActionTypes that controls which actions to show in the action menu |
| 632 | */ |
| 633 | void (int whichActions); |
| 634 | |
| 635 | /*! |
| 636 | * Reimplemented - allow dropping of files if \a b is true, defaults to true since 5.59 |
| 637 | * |
| 638 | * \a b true if the widget should allow dropping of files |
| 639 | */ |
| 640 | virtual void setAcceptDrops(bool b); |
| 641 | |
| 642 | /*! |
| 643 | * Sets the options for dropping files. |
| 644 | * CURRENTLY NOT IMPLEMENTED |
| 645 | */ |
| 646 | virtual void setDropOptions(int options); |
| 647 | |
| 648 | #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(6, 15) |
| 649 | /*! |
| 650 | * Starts and returns a KIO::CopyJob to trash the given \a items. |
| 651 | * |
| 652 | * \a items the list of items to be trashed |
| 653 | * \a parent the parent widget used for the confirmation dialog |
| 654 | * \a ask specifies whether a confirmation dialog should be shown |
| 655 | * \a showProgress passed to the CopyJob to show a progress dialog |
| 656 | */ |
| 657 | KIOFILEWIDGETS_DEPRECATED_VERSION(6, 15, "Use KIO::DeleteOrTrashJob instead" ) |
| 658 | virtual KIO::CopyJob *trash(const KFileItemList &items, QWidget *parent, bool ask = true, bool showProgress = true); |
| 659 | #endif |
| 660 | |
| 661 | /*! |
| 662 | * Returns the preview generator for the current view. |
| 663 | */ |
| 664 | KFilePreviewGenerator *previewGenerator() const; |
| 665 | |
| 666 | /*! |
| 667 | * Forces the inline previews to be shown or hidden, depending on \a show. |
| 668 | * |
| 669 | * \a show Whether to show inline previews or not. |
| 670 | */ |
| 671 | void setInlinePreviewShown(bool show); |
| 672 | |
| 673 | /*! |
| 674 | * Returns the position where icons are shown relative to the labels |
| 675 | * of file items in the icon view. |
| 676 | * \since 4.2.3 |
| 677 | */ |
| 678 | QStyleOptionViewItem::Position decorationPosition() const; |
| 679 | |
| 680 | /*! |
| 681 | * Sets the position where icons shall be shown relative to the labels |
| 682 | * of file items in the icon view. |
| 683 | * \since 4.2.3 |
| 684 | */ |
| 685 | void setDecorationPosition(QStyleOptionViewItem::Position position); |
| 686 | |
| 687 | /*! |
| 688 | * Returns whether the inline previews are shown or not. |
| 689 | */ |
| 690 | bool isInlinePreviewShown() const; |
| 691 | |
| 692 | /*! |
| 693 | * Returns the icon size in pixels, ranged from KIconLoader::SizeSmall (16) to |
| 694 | * KIconLoader::SizeEnormous (128). |
| 695 | * |
| 696 | * \since 5.76 |
| 697 | */ |
| 698 | int iconSize() const; |
| 699 | |
| 700 | /*! |
| 701 | * If the system is set up to trigger items on single click, if \a isSaving |
| 702 | * is true, we will force to double click to accept. |
| 703 | * \note this is false by default |
| 704 | */ |
| 705 | void setIsSaving(bool isSaving); |
| 706 | |
| 707 | /*! |
| 708 | * Returns whether KDirOperator will force a double click to accept. |
| 709 | * \note this is false by default |
| 710 | */ |
| 711 | bool isSaving() const; |
| 712 | |
| 713 | /*! |
| 714 | * Returns the URL schemes that the file widget should allow navigating to. |
| 715 | * |
| 716 | * If the returned list is empty, all schemes are supported. |
| 717 | * |
| 718 | * \sa QFileDialog::supportedSchemes |
| 719 | * \since 5.43 |
| 720 | */ |
| 721 | QStringList supportedSchemes() const; |
| 722 | |
| 723 | /*! |
| 724 | * Call with \c true to add open-with actions to items in the view. |
| 725 | * This can be useful when you're attaching an image or text file to |
| 726 | * an email or uploading an image to some online service, and need to |
| 727 | * check the contents before going forward. |
| 728 | * |
| 729 | * \since 5.87 |
| 730 | */ |
| 731 | void showOpenWithActions(bool enable); |
| 732 | |
| 733 | /*! |
| 734 | * @returns true if the user was using keys to navigate. |
| 735 | * |
| 736 | * \since 6.14 |
| 737 | */ |
| 738 | bool usingKeyNavigation(); |
| 739 | |
| 740 | protected: |
| 741 | /*! |
| 742 | * A view factory for creating predefined fileviews. Called internally by setView, |
| 743 | * but you can also call it directly. Reimplement this if you depend on self defined fileviews. |
| 744 | * |
| 745 | * \a parent is the QWidget to be set as parent |
| 746 | * |
| 747 | * \a viewKind is the predefined view to be set, note: this can be several ones OR:ed together |
| 748 | * |
| 749 | * Returns the created view |
| 750 | * |
| 751 | * \sa KFile::FileView |
| 752 | * \sa setViewMode |
| 753 | */ |
| 754 | virtual QAbstractItemView *createView(QWidget *parent, KFile::FileView viewKind); |
| 755 | |
| 756 | /*! |
| 757 | * Sets a custom KDirLister to list directories. |
| 758 | * The KDirOperator takes ownership of the given KDirLister. |
| 759 | */ |
| 760 | virtual void setDirLister(KDirLister *lister); |
| 761 | |
| 762 | void resizeEvent(QResizeEvent *event) override; |
| 763 | |
| 764 | /*! |
| 765 | * Sets up all the actions. Called from the constructor, you usually |
| 766 | * better not call this. |
| 767 | */ |
| 768 | void setupActions(); |
| 769 | |
| 770 | /*! |
| 771 | * Updates the sorting-related actions to comply with the current sorting |
| 772 | * \sa sorting |
| 773 | */ |
| 774 | void updateSortActions(); |
| 775 | |
| 776 | /*! |
| 777 | * Updates the view-related actions to comply with the current |
| 778 | * KFile::FileView |
| 779 | */ |
| 780 | void updateViewActions(); |
| 781 | |
| 782 | /*! |
| 783 | * Sets up the context-menu with all the necessary actions. Called from the |
| 784 | * constructor, you usually don't need to call this. |
| 785 | */ |
| 786 | void (); |
| 787 | |
| 788 | /*! |
| 789 | * Synchronizes the completion objects with the entries of the |
| 790 | * currently listed url. |
| 791 | * |
| 792 | * Automatically called from makeCompletion() and |
| 793 | * makeDirCompletion() |
| 794 | */ |
| 795 | void prepareCompletionObjects(); |
| 796 | |
| 797 | /*! |
| 798 | * Checks if there support from KIO::PreviewJob for the currently |
| 799 | * shown files, taking mimeFilter() and nameFilter() into account |
| 800 | * Enables/disables the preview-action accordingly. |
| 801 | */ |
| 802 | bool checkPreviewSupport(); |
| 803 | |
| 804 | /*! |
| 805 | * Called upon right-click to activate the popupmenu. |
| 806 | */ |
| 807 | virtual void (const KFileItem &item, const QPoint &pos); |
| 808 | |
| 809 | void changeEvent(QEvent *event) override; |
| 810 | |
| 811 | bool eventFilter(QObject *watched, QEvent *event) override; |
| 812 | |
| 813 | public Q_SLOTS: |
| 814 | /*! |
| 815 | * Goes one step back in the history and opens that url. |
| 816 | */ |
| 817 | virtual void back(); |
| 818 | |
| 819 | /*! |
| 820 | * Goes one step forward in the history and opens that url. |
| 821 | */ |
| 822 | virtual void forward(); |
| 823 | |
| 824 | /*! |
| 825 | * Enters the home directory. |
| 826 | */ |
| 827 | virtual void home(); |
| 828 | |
| 829 | /*! |
| 830 | * Goes one directory up from the current url. |
| 831 | */ |
| 832 | virtual void cdUp(); |
| 833 | |
| 834 | /*! |
| 835 | * to update the view after changing the settings |
| 836 | */ |
| 837 | void updateDir(); |
| 838 | |
| 839 | /*! |
| 840 | * Re-reads the current url. |
| 841 | */ |
| 842 | virtual void rereadDir(); |
| 843 | |
| 844 | /*! |
| 845 | * Opens a dialog to create a new directory. |
| 846 | */ |
| 847 | virtual void mkdir(); |
| 848 | |
| 849 | /*! |
| 850 | * Deletes the currently selected files/directories. |
| 851 | */ |
| 852 | virtual void deleteSelected(); |
| 853 | |
| 854 | /*! |
| 855 | * Enables/disables actions that are selection dependent. Call this e.g. |
| 856 | * when you are about to show a popup menu using some of KDirOperators |
| 857 | * actions. |
| 858 | */ |
| 859 | void updateSelectionDependentActions(); |
| 860 | |
| 861 | /*! |
| 862 | * Tries to complete the given string (only completes files). |
| 863 | */ |
| 864 | QString makeCompletion(const QString &); |
| 865 | |
| 866 | /*! |
| 867 | * Tries to complete the given string (only completes directories). |
| 868 | */ |
| 869 | QString makeDirCompletion(const QString &); |
| 870 | |
| 871 | /*! |
| 872 | * Initiates a rename operation on the currently selected files/directories, |
| 873 | * prompting the user to choose a new name(s) for the currently selected items |
| 874 | * \sa renamingFinished |
| 875 | * \since 5.67 |
| 876 | */ |
| 877 | void renameSelected(); |
| 878 | |
| 879 | /*! |
| 880 | * Trashes the currently selected files/directories. |
| 881 | * |
| 882 | * This function used to take activation reason and keyboard modifiers, |
| 883 | * in order to call deleteSelected() if the user wanted to delete. |
| 884 | * Instead, call deleteSelected(). |
| 885 | * |
| 886 | * FIXME KAction Port: link deleteSelected() up correctly |
| 887 | */ |
| 888 | virtual void trashSelected(); |
| 889 | |
| 890 | /*! |
| 891 | * Notifies that the icons size should change. \a value is the icon size in pixels, ranged |
| 892 | * from KIconLoader::SizeSmall (16) to KIconLoader::SizeEnormous (128). |
| 893 | * |
| 894 | * \since 5.76 |
| 895 | */ |
| 896 | void setIconSize(int value); |
| 897 | |
| 898 | /*! |
| 899 | * Set the URL schemes that the file widget should allow navigating to. |
| 900 | * |
| 901 | * If the returned list is empty, all schemes are supported. Examples for |
| 902 | * schemes are \c "file" or \c "ftp". |
| 903 | * |
| 904 | * \sa QFileDialog::setSupportedSchemes |
| 905 | * \since 5.43 |
| 906 | */ |
| 907 | void setSupportedSchemes(const QStringList &schemes); |
| 908 | |
| 909 | protected Q_SLOTS: |
| 910 | /*! |
| 911 | * Restores the normal cursor after showing the busy-cursor. Also hides |
| 912 | * the progressbar. |
| 913 | */ |
| 914 | void resetCursor(); |
| 915 | |
| 916 | /*! |
| 917 | * Called after setUrl() to load the directory, update the history, |
| 918 | * etc. |
| 919 | */ |
| 920 | void pathChanged(); |
| 921 | |
| 922 | /*! |
| 923 | * Enters the directory specified by the given \a item. |
| 924 | */ |
| 925 | virtual void selectDir(const KFileItem &item); |
| 926 | |
| 927 | /*! |
| 928 | * Emits fileSelected( item ) |
| 929 | */ |
| 930 | void selectFile(const KFileItem &item); |
| 931 | |
| 932 | /*! |
| 933 | * Emits fileHighlighted(item) |
| 934 | */ |
| 935 | void highlightFile(const KFileItem &item); |
| 936 | |
| 937 | /*! |
| 938 | * Changes sorting to sort by name |
| 939 | */ |
| 940 | void sortByName(); |
| 941 | |
| 942 | /*! |
| 943 | * Changes sorting to sort by size |
| 944 | */ |
| 945 | void sortBySize(); |
| 946 | |
| 947 | /*! |
| 948 | * Changes sorting to sort by date |
| 949 | */ |
| 950 | void sortByDate(); |
| 951 | |
| 952 | /*! |
| 953 | * Changes sorting to sort by date |
| 954 | */ |
| 955 | void sortByType(); |
| 956 | |
| 957 | /*! |
| 958 | * Changes sorting to reverse sorting |
| 959 | */ |
| 960 | void sortReversed(); |
| 961 | |
| 962 | /*! |
| 963 | * Toggles showing directories first / having them sorted like files. |
| 964 | */ |
| 965 | void toggleDirsFirst(); |
| 966 | |
| 967 | /*! |
| 968 | * Toggles case sensitive / case insensitive sorting |
| 969 | */ |
| 970 | void toggleIgnoreCase(); |
| 971 | |
| 972 | /*! |
| 973 | * Tries to make the given \a match as current item in the view and emits |
| 974 | * completion( match ) |
| 975 | */ |
| 976 | void slotCompletionMatch(const QString &match); |
| 977 | |
| 978 | Q_SIGNALS: |
| 979 | /*! |
| 980 | * |
| 981 | */ |
| 982 | void urlEntered(const QUrl &); |
| 983 | |
| 984 | /*! |
| 985 | * |
| 986 | */ |
| 987 | void updateInformation(int files, int dirs); |
| 988 | |
| 989 | /*! |
| 990 | * |
| 991 | */ |
| 992 | void completion(const QString &); |
| 993 | |
| 994 | /*! |
| 995 | * |
| 996 | */ |
| 997 | void finishedLoading(); |
| 998 | |
| 999 | /*! |
| 1000 | * Emitted whenever the current fileview is changed, either by an explicit |
| 1001 | * call to setViewMode() or by the user selecting a different view thru |
| 1002 | * the GUI. |
| 1003 | */ |
| 1004 | void viewChanged(QAbstractItemView *newView); |
| 1005 | |
| 1006 | /*! |
| 1007 | * Emitted when a file is highlighted or generally the selection changes in |
| 1008 | * multiselection mode. In the latter case, \a item is a null KFileItem. |
| 1009 | * You can access the selected items with selectedItems(). |
| 1010 | */ |
| 1011 | void fileHighlighted(const KFileItem &item); |
| 1012 | |
| 1013 | /*! |
| 1014 | * |
| 1015 | */ |
| 1016 | void dirActivated(const KFileItem &item); |
| 1017 | |
| 1018 | /*! |
| 1019 | * |
| 1020 | */ |
| 1021 | void fileSelected(const KFileItem &item); |
| 1022 | |
| 1023 | /*! |
| 1024 | * Emitted when files are dropped. Dropping files is disabled by |
| 1025 | * default. You need to enable it with setAcceptDrops() |
| 1026 | * |
| 1027 | * \a item the item on which the drop occurred or 0. |
| 1028 | * |
| 1029 | * \a event the drop event itself. |
| 1030 | * |
| 1031 | * \a urls the urls that where dropped. |
| 1032 | */ |
| 1033 | void dropped(const KFileItem &item, QDropEvent *event, const QList<QUrl> &urls); |
| 1034 | |
| 1035 | /*! |
| 1036 | * Emitted just before the context menu is shown, allows users to |
| 1037 | * extend the menu with custom actions. |
| 1038 | * |
| 1039 | * \a item the file on which the context menu was invoked |
| 1040 | * |
| 1041 | * \a menu the context menu, pre-populated with the file-management actions |
| 1042 | */ |
| 1043 | void (const KFileItem &item, QMenu *); |
| 1044 | |
| 1045 | /*! |
| 1046 | * Will notify that the icon size has changed. Since we save the icon size depending |
| 1047 | * on the view type (list view or a different kind of view), a call to setViewMode() can |
| 1048 | * trigger this signal to be emitted. |
| 1049 | */ |
| 1050 | void currentIconSizeChanged(int size); |
| 1051 | |
| 1052 | /*! |
| 1053 | * Triggered when the user hit Enter/Return |
| 1054 | * \since 5.57 |
| 1055 | */ |
| 1056 | void keyEnterReturnPressed(); |
| 1057 | |
| 1058 | /*! |
| 1059 | * Emitted when renaming selected files has finished. |
| 1060 | * |
| 1061 | * \a urls URL list of the renamed files |
| 1062 | * \since 5.96 |
| 1063 | */ |
| 1064 | void renamingFinished(const QList<QUrl> &urls); |
| 1065 | |
| 1066 | private: |
| 1067 | KIOFILEWIDGETS_NO_EXPORT void setViewInternal(QAbstractItemView *view); |
| 1068 | |
| 1069 | friend class KDirOperatorPrivate; |
| 1070 | friend class KFileWidgetTest; // For testing |
| 1071 | std::unique_ptr<KDirOperatorPrivate> d; |
| 1072 | }; |
| 1073 | |
| 1074 | #endif |
| 1075 | |