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