2 * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Gregor Kališnik <gregor@podnapisi.net>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #include "dolphinview.h"
10 #include "dolphin_detailsmodesettings.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinitemlistview.h"
13 #include "dolphinnewfilemenuobserver.h"
14 #include "draganddrophelper.h"
15 #include "kitemviews/kfileitemlistview.h"
16 #include "kitemviews/kfileitemmodel.h"
17 #include "kitemviews/kitemlistcontainer.h"
18 #include "kitemviews/kitemlistcontroller.h"
19 #include "kitemviews/kitemlistheader.h"
20 #include "kitemviews/kitemlistselectionmanager.h"
21 #include "kitemviews/private/kitemlistroleeditor.h"
22 #include "versioncontrol/versioncontrolobserver.h"
23 #include "viewproperties.h"
24 #include "views/tooltips/tooltipmanager.h"
25 #include "zoomlevelinfo.h"
28 #include <Baloo/IndexerConfig>
30 #include <KColorScheme>
31 #include <KDesktopFile>
33 #include <KFileItemListProperties>
35 #include <KIO/CopyJob>
36 #include <KIO/DeleteJob>
37 #include <KIO/DropJob>
38 #include <KIO/JobUiDelegate>
40 #include <KIO/PasteJob>
41 #include <KIO/PreviewJob>
42 #include <KIO/RenameFileDialog>
43 #include <KJobWidgets>
44 #include <KLocalizedString>
45 #include <KMessageBox>
46 #include <KProtocolManager>
48 #include <QAbstractItemView>
49 #include <QActionGroup>
50 #include <QApplication>
53 #include <QGraphicsOpacityEffect>
54 #include <QGraphicsSceneDragDropEvent>
57 #include <QMimeDatabase>
58 #include <QPixmapCache>
63 #include <QVBoxLayout>
65 DolphinView::DolphinView(const QUrl
& url
, QWidget
* parent
) :
68 m_tabsForFiles(false),
69 m_assureVisibleCurrentIndex(false),
70 m_isFolderWritable(true),
74 m_viewPropertiesContext(),
75 m_mode(DolphinView::IconsView
),
81 m_toolTipManager(nullptr),
82 m_selectionChangedTimer(nullptr),
84 m_scrollToCurrentItem(false),
85 m_restoredContentsPosition(),
87 m_clearSelectionBeforeSelectingNewItems(false),
88 m_markFirstNewlySelectedItemAsCurrent(false),
89 m_versionControlObserver(nullptr),
90 m_twoClicksRenamingTimer(nullptr),
91 m_placeholderLabel(nullptr),
92 m_showLoadingPlaceholderTimer(nullptr)
94 m_topLayout
= new QVBoxLayout(this);
95 m_topLayout
->setSpacing(0);
96 m_topLayout
->setContentsMargins(0, 0, 0, 0);
98 // When a new item has been created by the "Create New..." menu, the item should
99 // get selected and it must be assured that the item will get visible. As the
100 // creation is done asynchronously, several signals must be checked:
101 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
102 this, &DolphinView::observeCreatedItem
);
104 m_selectionChangedTimer
= new QTimer(this);
105 m_selectionChangedTimer
->setSingleShot(true);
106 m_selectionChangedTimer
->setInterval(300);
107 connect(m_selectionChangedTimer
, &QTimer::timeout
,
108 this, &DolphinView::emitSelectionChangedSignal
);
110 m_model
= new KFileItemModel(this);
111 m_view
= new DolphinItemListView();
112 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
113 m_view
->setVisibleRoles({"text"});
116 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
117 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
118 controller
->setAutoActivationDelay(delay
);
120 // The EnlargeSmallPreviews setting can only be changed after the model
121 // has been set in the view by KItemListController.
122 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
124 m_container
= new KItemListContainer(controller
, this);
125 m_container
->installEventFilter(this);
126 setFocusProxy(m_container
);
127 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
128 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
130 m_showLoadingPlaceholderTimer
= new QTimer(this);
131 m_showLoadingPlaceholderTimer
->setInterval(500);
132 m_showLoadingPlaceholderTimer
->setSingleShot(true);
133 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
135 // Show some placeholder text for empty folders
136 // This is made using a heavily-modified QLabel rather than a KTitleWidget
137 // because KTitleWidget can't be told to turn off mouse-selectable text
138 m_placeholderLabel
= new QLabel(this);
139 QFont placeholderLabelFont
;
140 // To match the size of a level 2 Heading/KTitleWidget
141 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
142 m_placeholderLabel
->setFont(placeholderLabelFont
);
143 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
144 m_placeholderLabel
->setWordWrap(true);
145 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
146 // Match opacity of QML placeholder label component
147 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
148 effect
->setOpacity(0.5);
149 m_placeholderLabel
->setGraphicsEffect(effect
);
150 // Set initial text and visibility
151 updatePlaceholderLabel();
153 auto *centeringLayout
= new QVBoxLayout(m_container
);
154 centeringLayout
->addWidget(m_placeholderLabel
);
155 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
157 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
158 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
159 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
160 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
161 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
162 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
163 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
164 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
165 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
166 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
167 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
168 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
169 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
170 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
171 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
172 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
173 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
175 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
176 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
177 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
178 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
179 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
180 connect(m_model
, &KFileItemModel::itemsChanged
,
181 this, &DolphinView::slotItemsChanged
);
182 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
183 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
184 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
185 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
186 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
187 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
188 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
190 connect(this, &DolphinView::itemCountChanged
,
191 this, &DolphinView::updatePlaceholderLabel
);
193 m_view
->installEventFilter(this);
194 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
195 this, &DolphinView::slotSortOrderChangedByHeader
);
196 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
197 this, &DolphinView::slotSortRoleChangedByHeader
);
198 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
199 this, &DolphinView::slotVisibleRolesChangedByHeader
);
200 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
201 this, &DolphinView::slotRoleEditingCanceled
);
202 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
,
203 this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
205 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
206 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
207 this, &DolphinView::slotSelectionChanged
);
210 m_toolTipManager
= new ToolTipManager(this);
211 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
214 m_versionControlObserver
= new VersionControlObserver(this);
215 m_versionControlObserver
->setView(this);
216 m_versionControlObserver
->setModel(m_model
);
217 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
218 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
219 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
221 m_twoClicksRenamingTimer
= new QTimer(this);
222 m_twoClicksRenamingTimer
->setSingleShot(true);
223 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
225 applyViewProperties();
226 m_topLayout
->addWidget(m_container
);
231 DolphinView::~DolphinView()
235 QUrl
DolphinView::url() const
240 void DolphinView::setActive(bool active
)
242 if (active
== m_active
) {
251 m_container
->setFocus();
253 Q_EMIT
writeStateChanged(m_isFolderWritable
);
257 bool DolphinView::isActive() const
262 void DolphinView::setMode(Mode mode
)
264 if (mode
!= m_mode
) {
265 ViewProperties
props(viewPropertiesUrl());
266 props
.setViewMode(mode
);
268 // We pass the new ViewProperties to applyViewProperties, rather than
269 // storing them on disk and letting applyViewProperties() read them
270 // from there, to prevent that changing the view mode fails if the
271 // .directory file is not writable (see bug 318534).
272 applyViewProperties(props
);
276 DolphinView::Mode
DolphinView::mode() const
281 void DolphinView::setPreviewsShown(bool show
)
283 if (previewsShown() == show
) {
287 ViewProperties
props(viewPropertiesUrl());
288 props
.setPreviewsShown(show
);
290 const int oldZoomLevel
= m_view
->zoomLevel();
291 m_view
->setPreviewsShown(show
);
292 Q_EMIT
previewsShownChanged(show
);
294 const int newZoomLevel
= m_view
->zoomLevel();
295 if (newZoomLevel
!= oldZoomLevel
) {
296 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
300 bool DolphinView::previewsShown() const
302 return m_view
->previewsShown();
305 void DolphinView::setHiddenFilesShown(bool show
)
307 if (m_model
->showHiddenFiles() == show
) {
311 const KFileItemList itemList
= selectedItems();
312 m_selectedUrls
.clear();
313 m_selectedUrls
= itemList
.urlList();
315 ViewProperties
props(viewPropertiesUrl());
316 props
.setHiddenFilesShown(show
);
318 m_model
->setShowHiddenFiles(show
);
319 Q_EMIT
hiddenFilesShownChanged(show
);
322 bool DolphinView::hiddenFilesShown() const
324 return m_model
->showHiddenFiles();
327 void DolphinView::setGroupedSorting(bool grouped
)
329 if (grouped
== groupedSorting()) {
333 ViewProperties
props(viewPropertiesUrl());
334 props
.setGroupedSorting(grouped
);
337 m_container
->controller()->model()->setGroupedSorting(grouped
);
339 Q_EMIT
groupedSortingChanged(grouped
);
342 bool DolphinView::groupedSorting() const
344 return m_model
->groupedSorting();
347 KFileItemList
DolphinView::items() const
350 const int itemCount
= m_model
->count();
351 list
.reserve(itemCount
);
353 for (int i
= 0; i
< itemCount
; ++i
) {
354 list
.append(m_model
->fileItem(i
));
360 int DolphinView::itemsCount() const
362 return m_model
->count();
365 KFileItemList
DolphinView::selectedItems() const
367 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
369 KFileItemList selectedItems
;
370 const auto items
= selectionManager
->selectedItems();
371 selectedItems
.reserve(items
.count());
372 for (int index
: items
) {
373 selectedItems
.append(m_model
->fileItem(index
));
375 return selectedItems
;
378 int DolphinView::selectedItemsCount() const
380 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
381 return selectionManager
->selectedItems().count();
384 void DolphinView::markUrlsAsSelected(const QList
<QUrl
>& urls
)
386 m_selectedUrls
= urls
;
389 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
391 m_currentItemUrl
= url
;
392 m_scrollToCurrentItem
= true;
395 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
397 const KItemListSelectionManager::SelectionMode mode
= enabled
398 ? KItemListSelectionManager::Select
399 : KItemListSelectionManager::Deselect
;
400 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
402 for (int index
= 0; index
< m_model
->count(); index
++) {
403 const KFileItem item
= m_model
->fileItem(index
);
404 if (regexp
.match(item
.text()).hasMatch()) {
405 // An alternative approach would be to store the matching items in a KItemSet and
406 // select them in one go after the loop, but we'd need a new function
407 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
409 selectionManager
->setSelected(index
, 1, mode
);
414 void DolphinView::setZoomLevel(int level
)
416 const int oldZoomLevel
= zoomLevel();
417 m_view
->setZoomLevel(level
);
418 if (zoomLevel() != oldZoomLevel
) {
420 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
424 int DolphinView::zoomLevel() const
426 return m_view
->zoomLevel();
429 void DolphinView::setSortRole(const QByteArray
& role
)
431 if (role
!= sortRole()) {
432 updateSortRole(role
);
436 QByteArray
DolphinView::sortRole() const
438 const KItemModelBase
* model
= m_container
->controller()->model();
439 return model
->sortRole();
442 void DolphinView::setSortOrder(Qt::SortOrder order
)
444 if (sortOrder() != order
) {
445 updateSortOrder(order
);
449 Qt::SortOrder
DolphinView::sortOrder() const
451 return m_model
->sortOrder();
454 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
456 if (sortFoldersFirst() != foldersFirst
) {
457 updateSortFoldersFirst(foldersFirst
);
461 bool DolphinView::sortFoldersFirst() const
463 return m_model
->sortDirectoriesFirst();
466 void DolphinView::setSortHiddenLast(bool hiddenLast
)
468 if (sortHiddenLast() != hiddenLast
) {
469 updateSortHiddenLast(hiddenLast
);
473 bool DolphinView::sortHiddenLast() const
475 return m_model
->sortHiddenLast();
478 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
480 const QList
<QByteArray
> previousRoles
= roles
;
482 ViewProperties
props(viewPropertiesUrl());
483 props
.setVisibleRoles(roles
);
485 m_visibleRoles
= roles
;
486 m_view
->setVisibleRoles(roles
);
488 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
491 QList
<QByteArray
> DolphinView::visibleRoles() const
493 return m_visibleRoles
;
496 void DolphinView::reload()
498 QByteArray viewState
;
499 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
500 saveState(saveStream
);
503 loadDirectory(url(), true);
505 QDataStream
restoreStream(viewState
);
506 restoreState(restoreStream
);
509 void DolphinView::readSettings()
511 const int oldZoomLevel
= m_view
->zoomLevel();
513 GeneralSettings::self()->load();
514 m_view
->readSettings();
515 applyViewProperties();
517 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
518 m_container
->controller()->setAutoActivationDelay(delay
);
520 const int newZoomLevel
= m_view
->zoomLevel();
521 if (newZoomLevel
!= oldZoomLevel
) {
522 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
526 void DolphinView::writeSettings()
528 GeneralSettings::self()->save();
529 m_view
->writeSettings();
532 void DolphinView::setNameFilter(const QString
& nameFilter
)
534 m_model
->setNameFilter(nameFilter
);
537 QString
DolphinView::nameFilter() const
539 return m_model
->nameFilter();
542 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
544 return m_model
->setMimeTypeFilters(filters
);
547 QStringList
DolphinView::mimeTypeFilters() const
549 return m_model
->mimeTypeFilters();
552 void DolphinView::requestStatusBarText()
554 if (m_statJobForStatusBarText
) {
555 // Kill the pending request.
556 m_statJobForStatusBarText
->kill();
559 if (m_container
->controller()->selectionManager()->hasSelection()) {
562 KIO::filesize_t totalFileSize
= 0;
564 // Give a summary of the status of the selected files
565 const KFileItemList list
= selectedItems();
566 for (const KFileItem
& item
: list
) {
571 totalFileSize
+= item
.size();
575 if (folderCount
+ fileCount
== 1) {
576 // If only one item is selected, show info about it
577 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
579 // At least 2 items are selected
580 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
582 } else { // has no selection
583 if (!m_model
->rootItem().url().isValid()) {
587 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(),
588 KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
589 connect(m_statJobForStatusBarText
, &KJob::result
,
590 this, &DolphinView::slotStatJobResult
);
591 m_statJobForStatusBarText
->start();
595 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
,
596 KIO::filesize_t totalFileSize
, const Selection selection
)
602 if (selection
== HasSelection
) {
603 // At least 2 items are selected because the case of 1 selected item is handled in
604 // DolphinView::requestStatusBarText().
605 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
606 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
608 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
609 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
612 if (fileCount
> 0 && folderCount
> 0) {
613 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
614 foldersText
, filesText
,
615 KFormat().formatByteSize(totalFileSize
));
616 } else if (fileCount
> 0) {
617 summary
= i18nc("@info:status files (size)", "%1 (%2)",
619 KFormat().formatByteSize(totalFileSize
));
620 } else if (folderCount
> 0) {
621 summary
= foldersText
;
623 summary
= i18nc("@info:status", "0 Folders, 0 Files");
625 Q_EMIT
statusBarTextChanged(summary
);
628 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
630 QList
<QAction
*> actions
;
632 if (items
.isEmpty()) {
633 const KFileItem item
= m_model
->rootItem();
634 if (!item
.isNull()) {
635 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
638 actions
= m_versionControlObserver
->actions(items
);
644 void DolphinView::setUrl(const QUrl
& url
)
656 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
657 this, &DolphinView::slotRoleEditingFinished
);
659 // It is important to clear the items from the model before
660 // applying the view properties, otherwise expensive operations
661 // might be done on the existing items although they get cleared
662 // anyhow afterwards by loadDirectory().
664 applyViewProperties();
667 Q_EMIT
urlChanged(url
);
670 void DolphinView::selectAll()
672 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
673 selectionManager
->setSelected(0, m_model
->count());
676 void DolphinView::invertSelection()
678 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
679 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
682 void DolphinView::clearSelection()
684 m_selectedUrls
.clear();
685 m_container
->controller()->selectionManager()->clearSelection();
688 void DolphinView::renameSelectedItems()
690 const KFileItemList items
= selectedItems();
691 if (items
.isEmpty()) {
695 if (items
.count() == 1 && GeneralSettings::renameInline()) {
696 const int index
= m_model
->index(items
.first());
698 QMetaObject::Connection
* const connection
= new QMetaObject::Connection
;
699 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=](){
700 QObject::disconnect(*connection
);
703 m_view
->editRole(index
, "text");
707 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
708 this, &DolphinView::slotRoleEditingFinished
);
710 m_view
->scrollToItem(index
);
713 KIO::RenameFileDialog
* dialog
= new KIO::RenameFileDialog(items
, this);
714 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
,
715 this, &DolphinView::slotRenameDialogRenamingFinished
);
720 // Assure that the current index remains visible when KFileItemModel
721 // will notify the view about changed items (which might result in
722 // a changed sorting).
723 m_assureVisibleCurrentIndex
= true;
726 void DolphinView::trashSelectedItems()
728 const QList
<QUrl
> list
= simplifiedSelectedUrls();
729 KIO::JobUiDelegate uiDelegate
;
730 uiDelegate
.setWindow(window());
731 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
732 KIO::Job
* job
= KIO::trash(list
);
733 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
734 KJobWidgets::setWindow(job
, this);
735 connect(job
, &KIO::Job::result
,
736 this, &DolphinView::slotTrashFileFinished
);
740 void DolphinView::deleteSelectedItems()
742 const QList
<QUrl
> list
= simplifiedSelectedUrls();
744 KIO::JobUiDelegate uiDelegate
;
745 uiDelegate
.setWindow(window());
746 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
747 KIO::Job
* job
= KIO::del(list
);
748 KJobWidgets::setWindow(job
, this);
749 connect(job
, &KIO::Job::result
,
750 this, &DolphinView::slotDeleteFileFinished
);
754 void DolphinView::cutSelectedItemsToClipboard()
756 QMimeData
* mimeData
= selectionMimeData();
757 KIO::setClipboardDataCut(mimeData
, true);
758 QApplication::clipboard()->setMimeData(mimeData
);
761 void DolphinView::copySelectedItemsToClipboard()
763 QMimeData
* mimeData
= selectionMimeData();
764 QApplication::clipboard()->setMimeData(mimeData
);
767 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
769 KIO::CopyJob
* job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
770 KJobWidgets::setWindow(job
, this);
772 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
773 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
774 KIO::FileUndoManager::self()->recordCopyJob(job
);
777 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
779 KIO::CopyJob
* job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
780 KJobWidgets::setWindow(job
, this);
782 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
783 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
784 KIO::FileUndoManager::self()->recordCopyJob(job
);
788 void DolphinView::paste()
793 void DolphinView::pasteIntoFolder()
795 const KFileItemList items
= selectedItems();
796 if ((items
.count() == 1) && items
.first().isDir()) {
797 pasteToUrl(items
.first().url());
801 void DolphinView::duplicateSelectedItems()
803 const KFileItemList itemList
= selectedItems();
804 if (itemList
.isEmpty()) {
808 const QMimeDatabase db
;
810 // Duplicate all selected items and append "copy" to the end of the file name
811 // but before the filename extension, if present
812 QList
<QUrl
> newSelection
;
813 for (const auto &item
: itemList
) {
814 const QUrl originalURL
= item
.url();
815 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
816 const QString originalFileName
= item
.name();
818 QString extension
= db
.suffixForFileName(originalFileName
);
820 QUrl duplicateURL
= originalURL
;
822 // No extension; new filename is "<oldfilename> copy"
823 if (extension
.isEmpty()) {
824 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
825 // There's an extension; new filename is "<oldfilename> copy.<extension>"
827 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
828 extension
= QLatin1String(".") + extension
;
829 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
830 // Preserve file's original filename extension in case the casing differs
831 // from what QMimeDatabase::suffixForFileName() returned
832 const QString originalExtension
= originalFileName
.right(extension
.size());
833 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
836 KIO::CopyJob
* job
= KIO::copyAs(originalURL
, duplicateURL
);
837 KJobWidgets::setWindow(job
, this);
840 newSelection
<< duplicateURL
;
841 KIO::FileUndoManager::self()->recordCopyJob(job
);
845 forceUrlsSelection(newSelection
.first(), newSelection
);
848 void DolphinView::stopLoading()
850 m_model
->cancelDirectoryLoading();
853 void DolphinView::updatePalette()
855 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
860 QWidget
* viewport
= m_container
->viewport();
863 palette
.setColor(viewport
->backgroundRole(), color
);
864 viewport
->setPalette(palette
);
870 void DolphinView::abortTwoClicksRenaming()
872 m_twoClicksRenamingItemUrl
.clear();
873 m_twoClicksRenamingTimer
->stop();
876 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
878 switch (event
->type()) {
879 case QEvent::PaletteChange
:
881 QPixmapCache::clear();
884 case QEvent::WindowActivate
:
885 case QEvent::WindowDeactivate
:
889 case QEvent::KeyPress
:
890 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
891 if (GeneralSettings::useTabForSwitchingSplitView()) {
892 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
893 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
894 Q_EMIT
toggleActiveViewRequested();
899 case QEvent::FocusIn
:
900 if (watched
== m_container
) {
905 case QEvent::GraphicsSceneDragEnter
:
906 if (watched
== m_view
) {
908 abortTwoClicksRenaming();
912 case QEvent::GraphicsSceneDragLeave
:
913 if (watched
== m_view
) {
918 case QEvent::GraphicsSceneDrop
:
919 if (watched
== m_view
) {
926 return QWidget::eventFilter(watched
, event
);
929 void DolphinView::wheelEvent(QWheelEvent
* event
)
931 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
932 const QPoint numDegrees
= event
->angleDelta() / 8;
933 const QPoint numSteps
= numDegrees
/ 15;
935 setZoomLevel(zoomLevel() + numSteps
.y());
942 void DolphinView::hideEvent(QHideEvent
* event
)
945 QWidget::hideEvent(event
);
948 bool DolphinView::event(QEvent
* event
)
950 if (event
->type() == QEvent::WindowDeactivate
) {
952 * Dolphin leaves file preview tooltips open even when is not visible.
954 * Hide tool-tip when Dolphin loses focus.
957 abortTwoClicksRenaming();
960 return QWidget::event(event
);
963 void DolphinView::activate()
968 void DolphinView::slotItemActivated(int index
)
970 abortTwoClicksRenaming();
972 const KFileItem item
= m_model
->fileItem(index
);
973 if (!item
.isNull()) {
974 Q_EMIT
itemActivated(item
);
978 void DolphinView::slotItemsActivated(const KItemSet
& indexes
)
980 Q_ASSERT(indexes
.count() >= 2);
982 abortTwoClicksRenaming();
984 if (indexes
.count() > 5) {
985 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
986 const int answer
= KMessageBox::warningYesNo(this, question
);
987 if (answer
!= KMessageBox::Yes
) {
993 items
.reserve(indexes
.count());
995 for (int index
: indexes
) {
996 KFileItem item
= m_model
->fileItem(index
);
997 const QUrl
& url
= openItemAsFolderUrl(item
);
999 if (!url
.isEmpty()) { // Open folders in new tabs
1000 Q_EMIT
tabRequested(url
);
1006 if (items
.count() == 1) {
1007 Q_EMIT
itemActivated(items
.first());
1008 } else if (items
.count() > 1) {
1009 Q_EMIT
itemsActivated(items
);
1013 void DolphinView::slotItemMiddleClicked(int index
)
1015 const KFileItem
& item
= m_model
->fileItem(index
);
1016 const QUrl
& url
= openItemAsFolderUrl(item
);
1017 if (!url
.isEmpty()) {
1018 Q_EMIT
tabRequested(url
);
1019 } else if (isTabsForFilesEnabled()) {
1020 Q_EMIT
tabRequested(item
.url());
1024 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
1026 // Force emit of a selection changed signal before we request the
1027 // context menu, to update the edit-actions first. (See Bug 294013)
1028 if (m_selectionChangedTimer
->isActive()) {
1029 emitSelectionChangedSignal();
1032 const KFileItem item
= m_model
->fileItem(index
);
1033 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, url(), QList
<QAction
*>());
1036 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
1038 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), url(), QList
<QAction
*>());
1041 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
1043 ViewProperties
props(viewPropertiesUrl());
1045 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1047 KItemListView
* view
= m_container
->controller()->view();
1048 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1050 bool indexingEnabled
= false;
1052 Baloo::IndexerConfig config
;
1053 indexingEnabled
= config
.fileIndexingEnabled();
1057 QMenu
* groupMenu
= nullptr;
1059 // Add all roles to the menu that can be shown or hidden by the user
1060 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1061 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
1062 if (info
.role
== "text") {
1063 // It should not be possible to hide the "text" role
1067 const QString text
= m_model
->roleDescription(info
.role
);
1068 QAction
* action
= nullptr;
1069 if (info
.group
.isEmpty()) {
1070 action
= menu
->addAction(text
);
1072 if (!groupMenu
|| info
.group
!= groupName
) {
1073 groupName
= info
.group
;
1074 groupMenu
= menu
->addMenu(groupName
);
1077 action
= groupMenu
->addAction(text
);
1080 action
->setCheckable(true);
1081 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1082 action
->setData(info
.role
);
1084 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
1085 (info
.requiresBaloo
) ||
1086 (info
.requiresIndexer
&& indexingEnabled
);
1087 action
->setEnabled(enable
);
1090 menu
->addSeparator();
1092 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
1093 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1095 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1096 autoAdjustWidthsAction
->setCheckable(true);
1097 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1098 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1100 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1101 customWidthsAction
->setCheckable(true);
1102 customWidthsAction
->setChecked(!autoColumnWidths
);
1103 customWidthsAction
->setActionGroup(widthsGroup
);
1105 QAction
* action
= menu
->exec(pos
.toPoint());
1106 if (menu
&& action
) {
1107 KItemListHeader
* header
= view
->header();
1109 if (action
== autoAdjustWidthsAction
) {
1110 // Clear the column-widths from the viewproperties and turn on
1111 // the automatic resizing of the columns
1112 props
.setHeaderColumnWidths(QList
<int>());
1113 header
->setAutomaticColumnResizing(true);
1114 } else if (action
== customWidthsAction
) {
1115 // Apply the current column-widths as custom column-widths and turn
1116 // off the automatic resizing of the columns
1117 QList
<int> columnWidths
;
1118 const auto visibleRoles
= view
->visibleRoles();
1119 columnWidths
.reserve(visibleRoles
.count());
1120 for (const QByteArray
& role
: visibleRoles
) {
1121 columnWidths
.append(header
->columnWidth(role
));
1123 props
.setHeaderColumnWidths(columnWidths
);
1124 header
->setAutomaticColumnResizing(false);
1126 // Show or hide the selected role
1127 const QByteArray selectedRole
= action
->data().toByteArray();
1129 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1130 if (action
->isChecked()) {
1131 visibleRoles
.append(selectedRole
);
1133 visibleRoles
.removeOne(selectedRole
);
1136 view
->setVisibleRoles(visibleRoles
);
1137 props
.setVisibleRoles(visibleRoles
);
1139 QList
<int> columnWidths
;
1140 if (!header
->automaticColumnResizing()) {
1141 const auto visibleRoles
= view
->visibleRoles();
1142 columnWidths
.reserve(visibleRoles
.count());
1143 for (const QByteArray
& role
: visibleRoles
) {
1144 columnWidths
.append(header
->columnWidth(role
));
1147 props
.setHeaderColumnWidths(columnWidths
);
1154 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
& role
, qreal current
)
1156 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1158 ViewProperties
props(viewPropertiesUrl());
1159 QList
<int> columnWidths
= props
.headerColumnWidths();
1160 if (columnWidths
.count() != visibleRoles
.count()) {
1161 columnWidths
.clear();
1162 columnWidths
.reserve(visibleRoles
.count());
1163 const KItemListHeader
* header
= m_view
->header();
1164 for (const QByteArray
& role
: visibleRoles
) {
1165 const int width
= header
->columnWidth(role
);
1166 columnWidths
.append(width
);
1170 const int roleIndex
= visibleRoles
.indexOf(role
);
1171 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1172 columnWidths
[roleIndex
] = current
;
1174 props
.setHeaderColumnWidths(columnWidths
);
1177 void DolphinView::slotItemHovered(int index
)
1179 const KFileItem item
= m_model
->fileItem(index
);
1181 if (GeneralSettings::showToolTips() && !m_dragging
) {
1182 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1183 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1184 itemRect
.moveTo(pos
);
1187 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParentWidget()->windowHandle());
1191 Q_EMIT
requestItemInfo(item
);
1194 void DolphinView::slotItemUnhovered(int index
)
1198 Q_EMIT
requestItemInfo(KFileItem());
1201 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1204 KFileItem destItem
= m_model
->fileItem(index
);
1205 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1206 // Use the URL of the view as drop target if the item is no directory
1208 destItem
= m_model
->rootItem();
1211 // The item represents a directory or desktop-file
1212 destUrl
= destItem
.mostLocalUrl();
1215 QDropEvent
dropEvent(event
->pos().toPoint(),
1216 event
->possibleActions(),
1219 event
->modifiers());
1220 dropUrls(destUrl
, &dropEvent
, this);
1225 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1227 KIO::DropJob
* job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1230 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1232 if (destUrl
== url()) {
1233 // Mark the dropped urls as selected.
1234 m_clearSelectionBeforeSelectingNewItems
= true;
1235 m_markFirstNewlySelectedItemAsCurrent
= true;
1236 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1241 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1243 if (previous
!= nullptr) {
1244 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1245 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1246 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1247 m_versionControlObserver
->setModel(nullptr);
1251 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1252 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1253 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1254 m_versionControlObserver
->setModel(fileItemModel
);
1258 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1264 if (buttons
& Qt::BackButton
) {
1265 Q_EMIT
goBackRequested();
1266 } else if (buttons
& Qt::ForwardButton
) {
1267 Q_EMIT
goForwardRequested();
1271 void DolphinView::slotSelectedItemTextPressed(int index
)
1273 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1274 const KFileItem item
= m_model
->fileItem(index
);
1275 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1276 if (capabilities
.supportsMoving()) {
1277 m_twoClicksRenamingItemUrl
= item
.url();
1278 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1283 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1285 slotItemCreated(to
);
1288 void DolphinView::slotItemCreated(const QUrl
& url
)
1290 if (m_markFirstNewlySelectedItemAsCurrent
) {
1291 markUrlAsCurrent(url
);
1292 m_markFirstNewlySelectedItemAsCurrent
= false;
1294 m_selectedUrls
<< url
;
1297 void DolphinView::slotJobResult(KJob
*job
)
1300 Q_EMIT
errorMessage(job
->errorString());
1302 if (!m_selectedUrls
.isEmpty()) {
1303 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1307 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1309 const int currentCount
= current
.count();
1310 const int previousCount
= previous
.count();
1311 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1312 (currentCount
> 0 && previousCount
== 0);
1314 // If nothing has been selected before and something got selected (or if something
1315 // was selected before and now nothing is selected) the selectionChangedSignal must
1316 // be emitted asynchronously as fast as possible to update the edit-actions.
1317 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1318 m_selectionChangedTimer
->start();
1321 void DolphinView::emitSelectionChangedSignal()
1323 m_selectionChangedTimer
->stop();
1324 Q_EMIT
selectionChanged(selectedItems());
1327 void DolphinView::slotStatJobResult(KJob
*job
)
1329 int folderCount
= 0;
1331 KIO::filesize_t totalFileSize
= 0;
1332 bool countFileSize
= true;
1334 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1335 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1336 // We have a precomputed value.
1337 totalFileSize
= static_cast<KIO::filesize_t
>(
1338 entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1339 countFileSize
= false;
1342 const int itemCount
= m_model
->count();
1343 for (int i
= 0; i
< itemCount
; ++i
) {
1344 const KFileItem item
= m_model
->fileItem(i
);
1349 if (countFileSize
) {
1350 totalFileSize
+= item
.size();
1354 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1357 void DolphinView::updateSortRole(const QByteArray
& role
)
1359 ViewProperties
props(viewPropertiesUrl());
1360 props
.setSortRole(role
);
1362 KItemModelBase
* model
= m_container
->controller()->model();
1363 model
->setSortRole(role
);
1365 Q_EMIT
sortRoleChanged(role
);
1368 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1370 ViewProperties
props(viewPropertiesUrl());
1371 props
.setSortOrder(order
);
1373 m_model
->setSortOrder(order
);
1375 Q_EMIT
sortOrderChanged(order
);
1378 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1380 ViewProperties
props(viewPropertiesUrl());
1381 props
.setSortFoldersFirst(foldersFirst
);
1383 m_model
->setSortDirectoriesFirst(foldersFirst
);
1385 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1388 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1390 ViewProperties
props(viewPropertiesUrl());
1391 props
.setSortHiddenLast(hiddenLast
);
1393 m_model
->setSortHiddenLast(hiddenLast
);
1395 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1399 QPair
<bool, QString
> DolphinView::pasteInfo() const
1401 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1402 QPair
<bool, QString
> info
;
1403 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1407 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1409 m_tabsForFiles
= tabsForFiles
;
1412 bool DolphinView::isTabsForFilesEnabled() const
1414 return m_tabsForFiles
;
1417 bool DolphinView::itemsExpandable() const
1419 return m_mode
== DetailsView
;
1422 void DolphinView::restoreState(QDataStream
& stream
)
1424 // Read the version number of the view state and check if the version is supported.
1425 quint32 version
= 0;
1428 // The version of the view state isn't supported, we can't restore it.
1432 // Restore the current item that had the keyboard focus
1433 stream
>> m_currentItemUrl
;
1435 // Restore the previously selected items
1436 stream
>> m_selectedUrls
;
1438 // Restore the view position
1439 stream
>> m_restoredContentsPosition
;
1441 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1444 m_model
->restoreExpandedDirectories(urls
);
1447 void DolphinView::saveState(QDataStream
& stream
)
1449 stream
<< quint32(1); // View state version
1451 // Save the current item that has the keyboard focus
1452 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1453 if (currentIndex
!= -1) {
1454 KFileItem item
= m_model
->fileItem(currentIndex
);
1455 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1456 QUrl currentItemUrl
= item
.url();
1457 stream
<< currentItemUrl
;
1462 // Save the selected urls
1463 stream
<< selectedItems().urlList();
1465 // Save view position
1466 const qreal x
= m_container
->horizontalScrollBar()->value();
1467 const qreal y
= m_container
->verticalScrollBar()->value();
1468 stream
<< QPoint(x
, y
);
1470 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1471 stream
<< m_model
->expandedDirectories();
1474 KFileItem
DolphinView::rootItem() const
1476 return m_model
->rootItem();
1479 void DolphinView::setViewPropertiesContext(const QString
& context
)
1481 m_viewPropertiesContext
= context
;
1484 QString
DolphinView::viewPropertiesContext() const
1486 return m_viewPropertiesContext
;
1489 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1491 if (item
.isNull()) {
1495 QUrl url
= item
.targetUrl();
1501 if (item
.isMimeTypeKnown()) {
1502 const QString
& mimetype
= item
.mimetype();
1504 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1505 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1506 // zip:/<path>/ when clicking on a zip file, etc.
1507 // The .protocol file specifies the mimetype that the kioslave handles.
1508 // Note that we don't use mimetype inheritance since we don't want to
1509 // open OpenDocument files as zip folders...
1510 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1511 if (!protocol
.isEmpty()) {
1512 url
.setScheme(protocol
);
1517 if (mimetype
== QLatin1String("application/x-desktop")) {
1518 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1519 KDesktopFile
desktopFile(url
.toLocalFile());
1520 if (desktopFile
.hasLinkType()) {
1521 const QString linkUrl
= desktopFile
.readUrl();
1522 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1523 return QUrl::fromUserInput(linkUrl
);
1532 void DolphinView::resetZoomLevel()
1534 ViewModeSettings::ViewMode mode
;
1537 case IconsView
: mode
= ViewModeSettings::IconsMode
; break;
1538 case CompactView
: mode
= ViewModeSettings::CompactMode
; break;
1539 case DetailsView
: mode
= ViewModeSettings::DetailsMode
; break;
1541 const ViewModeSettings
settings(mode
);
1542 const QSize iconSize
= QSize(settings
.iconSize(), settings
.iconSize());
1543 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize
));
1546 void DolphinView::observeCreatedItem(const QUrl
& url
)
1549 forceUrlsSelection(url
, {url
});
1553 void DolphinView::slotDirectoryRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
)
1555 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1556 Q_EMIT
redirection(oldUrl
, newUrl
);
1557 m_url
= newUrl
; // #186947
1561 void DolphinView::updateViewState()
1563 if (m_currentItemUrl
!= QUrl()) {
1564 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1566 // if there is a selection already, leave it that way
1567 if (!selectionManager
->hasSelection()) {
1568 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1569 if (currentIndex
!= -1) {
1570 selectionManager
->setCurrentItem(currentIndex
);
1572 // scroll to current item and reset the state
1573 if (m_scrollToCurrentItem
) {
1574 m_view
->scrollToItem(currentIndex
);
1575 m_scrollToCurrentItem
= false;
1578 selectionManager
->setCurrentItem(0);
1582 m_currentItemUrl
= QUrl();
1585 if (!m_restoredContentsPosition
.isNull()) {
1586 const int x
= m_restoredContentsPosition
.x();
1587 const int y
= m_restoredContentsPosition
.y();
1588 m_restoredContentsPosition
= QPoint();
1590 m_container
->horizontalScrollBar()->setValue(x
);
1591 m_container
->verticalScrollBar()->setValue(y
);
1594 if (!m_selectedUrls
.isEmpty()) {
1595 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1597 // if there is a selection already, leave it that way
1598 if (!selectionManager
->hasSelection()) {
1599 if (m_clearSelectionBeforeSelectingNewItems
) {
1600 selectionManager
->clearSelection();
1601 m_clearSelectionBeforeSelectingNewItems
= false;
1604 KItemSet selectedItems
= selectionManager
->selectedItems();
1606 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1607 while (it
!= m_selectedUrls
.end()) {
1608 const int index
= m_model
->index(*it
);
1610 selectedItems
.insert(index
);
1611 it
= m_selectedUrls
.erase(it
);
1617 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1618 selectionManager
->setSelectedItems(selectedItems
);
1623 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1626 if (GeneralSettings::showToolTips()) {
1627 m_toolTipManager
->hideToolTip(behavior
);
1634 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1636 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1638 // verify that only one item is selected
1639 if (selectionManager
->selectedItems().count() == 1) {
1640 const int index
= selectionManager
->currentItem();
1641 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1643 // check if the selected item was the same item that started the twoClicksRenaming
1644 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1645 renameSelectedItems();
1650 void DolphinView::slotTrashFileFinished(KJob
* job
)
1652 if (job
->error() == 0) {
1653 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1654 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1655 Q_EMIT
errorMessage(job
->errorString());
1659 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1661 if (job
->error() == 0) {
1662 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1663 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1664 Q_EMIT
errorMessage(job
->errorString());
1668 void DolphinView::slotRenamingResult(KJob
* job
)
1671 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1673 const QUrl newUrl
= copyJob
->destUrl();
1674 const int index
= m_model
->index(newUrl
);
1676 QHash
<QByteArray
, QVariant
> data
;
1677 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1678 data
.insert("text", oldUrl
.fileName());
1679 m_model
->setData(index
, data
);
1684 void DolphinView::slotDirectoryLoadingStarted()
1687 updatePlaceholderLabel();
1689 // Disable the writestate temporary until it can be determined in a fast way
1690 // in DolphinView::slotDirectoryLoadingCompleted()
1691 if (m_isFolderWritable
) {
1692 m_isFolderWritable
= false;
1693 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1696 Q_EMIT
directoryLoadingStarted();
1699 void DolphinView::slotDirectoryLoadingCompleted()
1703 // Update the view-state. This has to be done asynchronously
1704 // because the view might not be in its final state yet.
1705 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1707 // Update the placeholder label in case we found that the folder was empty
1710 Q_EMIT
directoryLoadingCompleted();
1712 updatePlaceholderLabel();
1713 updateWritableState();
1716 void DolphinView::slotDirectoryLoadingCanceled()
1720 updatePlaceholderLabel();
1722 Q_EMIT
directoryLoadingCanceled();
1725 void DolphinView::slotItemsChanged()
1727 m_assureVisibleCurrentIndex
= false;
1730 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1733 Q_ASSERT(m_model
->sortOrder() == current
);
1735 ViewProperties
props(viewPropertiesUrl());
1736 props
.setSortOrder(current
);
1738 Q_EMIT
sortOrderChanged(current
);
1741 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1744 Q_ASSERT(m_model
->sortRole() == current
);
1746 ViewProperties
props(viewPropertiesUrl());
1747 props
.setSortRole(current
);
1749 Q_EMIT
sortRoleChanged(current
);
1752 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1753 const QList
<QByteArray
>& previous
)
1756 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1758 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1760 m_visibleRoles
= current
;
1762 ViewProperties
props(viewPropertiesUrl());
1763 props
.setVisibleRoles(m_visibleRoles
);
1765 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1768 void DolphinView::slotRoleEditingCanceled()
1770 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1771 this, &DolphinView::slotRoleEditingFinished
);
1774 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1776 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1777 this, &DolphinView::slotRoleEditingFinished
);
1779 const KFileItemList items
= selectedItems();
1780 if (items
.count() != 1) {
1784 if (role
== "text") {
1785 const KFileItem oldItem
= items
.first();
1786 const EditResult retVal
= value
.value
<EditResult
>();
1787 const QString newName
= retVal
.newName
;
1788 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1789 const QUrl oldUrl
= oldItem
.url();
1791 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1792 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1795 //Confirm hiding file/directory by renaming inline
1796 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1797 KGuiItem
yesGuiItem(KStandardGuiItem::yes());
1798 yesGuiItem
.setText(i18nc("@action:button", "Rename and Hide"));
1800 const auto code
= KMessageBox::questionYesNo(this,
1801 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1802 "Do you still want to rename it?")
1803 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1804 "Do you still want to rename it?"),
1805 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1807 KStandardGuiItem::cancel(),
1808 QStringLiteral("ConfirmHide")
1811 if (code
== KMessageBox::No
) {
1817 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1818 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1819 // Only change the data in the model if no item with the new name
1820 // is in the model yet. If there is an item with the new name
1821 // already, calling KIO::CopyJob will open a dialog
1822 // asking for a new name, and KFileItemModel will update the
1823 // data when the dir lister signals that the file name has changed.
1824 QHash
<QByteArray
, QVariant
> data
;
1825 data
.insert(role
, retVal
.newName
);
1826 m_model
->setData(index
, data
);
1829 KIO::Job
* job
= KIO::moveAs(oldUrl
, newUrl
);
1830 KJobWidgets::setWindow(job
, this);
1831 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1832 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1834 forceUrlsSelection(newUrl
, {newUrl
});
1836 if (!newNameExistsAlready
) {
1837 // Only connect the result signal if there is no item with the new name
1838 // in the model yet, see bug 328262.
1839 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1842 if (retVal
.direction
!= EditDone
) {
1843 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1844 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1845 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1,
1846 KItemListSelectionManager::Select
);
1847 renameSelectedItems();
1852 void DolphinView::loadDirectory(const QUrl
& url
, bool reload
)
1854 if (!url
.isValid()) {
1855 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1856 if (location
.isEmpty()) {
1857 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1859 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1865 m_model
->refreshDirectory(url
);
1867 m_model
->loadDirectory(url
);
1871 void DolphinView::applyViewProperties()
1873 const ViewProperties
props(viewPropertiesUrl());
1874 applyViewProperties(props
);
1877 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1879 m_view
->beginTransaction();
1881 const Mode mode
= props
.viewMode();
1882 if (m_mode
!= mode
) {
1883 const Mode previousMode
= m_mode
;
1886 // Changing the mode might result in changing
1887 // the zoom level. Remember the old zoom level so
1888 // that zoomLevelChanged() can get emitted.
1889 const int oldZoomLevel
= m_view
->zoomLevel();
1892 Q_EMIT
modeChanged(m_mode
, previousMode
);
1894 if (m_view
->zoomLevel() != oldZoomLevel
) {
1895 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1899 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1900 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1901 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1902 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
1905 const bool groupedSorting
= props
.groupedSorting();
1906 if (groupedSorting
!= m_model
->groupedSorting()) {
1907 m_model
->setGroupedSorting(groupedSorting
);
1908 Q_EMIT
groupedSortingChanged(groupedSorting
);
1911 const QByteArray sortRole
= props
.sortRole();
1912 if (sortRole
!= m_model
->sortRole()) {
1913 m_model
->setSortRole(sortRole
);
1914 Q_EMIT
sortRoleChanged(sortRole
);
1917 const Qt::SortOrder sortOrder
= props
.sortOrder();
1918 if (sortOrder
!= m_model
->sortOrder()) {
1919 m_model
->setSortOrder(sortOrder
);
1920 Q_EMIT
sortOrderChanged(sortOrder
);
1923 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1924 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1925 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1926 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
1929 const bool sortHiddenLast
= props
.sortHiddenLast();
1930 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
1931 m_model
->setSortHiddenLast(sortHiddenLast
);
1932 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
1935 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1936 if (visibleRoles
!= m_visibleRoles
) {
1937 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1938 m_visibleRoles
= visibleRoles
;
1939 m_view
->setVisibleRoles(visibleRoles
);
1940 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1943 const bool previewsShown
= props
.previewsShown();
1944 if (previewsShown
!= m_view
->previewsShown()) {
1945 const int oldZoomLevel
= zoomLevel();
1947 m_view
->setPreviewsShown(previewsShown
);
1948 Q_EMIT
previewsShownChanged(previewsShown
);
1950 // Changing the preview-state might result in a changed zoom-level
1951 if (oldZoomLevel
!= zoomLevel()) {
1952 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
1956 KItemListView
* itemListView
= m_container
->controller()->view();
1957 if (itemListView
->isHeaderVisible()) {
1958 KItemListHeader
* header
= itemListView
->header();
1959 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
1960 const int rolesCount
= m_visibleRoles
.count();
1961 if (headerColumnWidths
.count() == rolesCount
) {
1962 header
->setAutomaticColumnResizing(false);
1964 QHash
<QByteArray
, qreal
> columnWidths
;
1965 for (int i
= 0; i
< rolesCount
; ++i
) {
1966 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
1968 header
->setColumnWidths(columnWidths
);
1970 header
->setAutomaticColumnResizing(true);
1974 m_view
->endTransaction();
1977 void DolphinView::applyModeToView()
1980 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
1981 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
1982 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
1983 default: Q_ASSERT(false); break;
1987 void DolphinView::pasteToUrl(const QUrl
& url
)
1989 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
1990 KJobWidgets::setWindow(job
, this);
1991 m_clearSelectionBeforeSelectingNewItems
= true;
1992 m_markFirstNewlySelectedItemAsCurrent
= true;
1993 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1994 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
1997 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2001 const KFileItemList items
= selectedItems();
2002 urls
.reserve(items
.count());
2003 for (const KFileItem
& item
: items
) {
2004 urls
.append(item
.url());
2007 if (itemsExpandable()) {
2008 // TODO: Check if we still need KDirModel for this in KDE 5.0
2009 urls
= KDirModel::simplifiedUrlList(urls
);
2015 QMimeData
* DolphinView::selectionMimeData() const
2017 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
2018 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2020 return m_model
->createMimeData(selectedIndexes
);
2023 void DolphinView::updateWritableState()
2025 const bool wasFolderWritable
= m_isFolderWritable
;
2026 m_isFolderWritable
= false;
2028 KFileItem item
= m_model
->rootItem();
2029 if (item
.isNull()) {
2030 // Try to find out if the URL is writable even if the "root item" is
2031 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2032 item
= KFileItem(url());
2033 item
.setDelayedMimeTypes(true);
2036 KFileItemListProperties
capabilities(KFileItemList() << item
);
2037 m_isFolderWritable
= capabilities
.supportsWriting();
2039 if (m_isFolderWritable
!= wasFolderWritable
) {
2040 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2044 QUrl
DolphinView::viewPropertiesUrl() const
2046 if (m_viewPropertiesContext
.isEmpty()) {
2051 url
.setScheme(m_url
.scheme());
2052 url
.setPath(m_viewPropertiesContext
);
2056 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
>& urls
)
2058 forceUrlsSelection(urls
.first(), urls
);
2061 void DolphinView::forceUrlsSelection(const QUrl
& current
, const QList
<QUrl
>& selected
)
2064 m_clearSelectionBeforeSelectingNewItems
= true;
2065 markUrlAsCurrent(current
);
2066 markUrlsAsSelected(selected
);
2069 void DolphinView::copyPathToClipboard()
2071 const KFileItemList list
= selectedItems();
2072 if (list
.isEmpty()) {
2075 const KFileItem
& item
= list
.at(0);
2076 QString path
= item
.localPath();
2077 if (path
.isEmpty()) {
2078 path
= item
.url().toDisplayString();
2080 QClipboard
* clipboard
= QApplication::clipboard();
2081 if (clipboard
== nullptr) {
2084 clipboard
->setText(path
);
2087 void DolphinView::slotIncreaseZoom()
2089 setZoomLevel(zoomLevel() + 1);
2092 void DolphinView::slotDecreaseZoom()
2094 setZoomLevel(zoomLevel() - 1);
2097 void DolphinView::slotSwipeUp()
2099 Q_EMIT
goUpRequested();
2102 void DolphinView::showLoadingPlaceholder()
2104 m_placeholderLabel
->setText(i18n("Loading..."));
2105 m_placeholderLabel
->setVisible(true);
2108 void DolphinView::updatePlaceholderLabel()
2110 m_showLoadingPlaceholderTimer
->stop();
2111 if (itemsCount() > 0) {
2112 m_placeholderLabel
->setVisible(false);
2117 m_placeholderLabel
->setVisible(false);
2118 m_showLoadingPlaceholderTimer
->start();
2122 if (!nameFilter().isEmpty()) {
2123 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2124 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2125 m_placeholderLabel
->setText(i18n("No items matching the search"));
2126 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2127 m_placeholderLabel
->setText(i18n("Trash is empty"));
2128 } else if (m_url
.scheme() == QLatin1String("tags")) {
2129 m_placeholderLabel
->setText(i18n("No tags"));
2130 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2131 m_placeholderLabel
->setText(i18n("No recently used items"));
2132 } else if (m_url
.scheme() == QLatin1String("smb")) {
2133 m_placeholderLabel
->setText(i18n("No shared folders found"));
2134 } else if (m_url
.scheme() == QLatin1String("network")) {
2135 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2136 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2137 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2138 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2139 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2141 m_placeholderLabel
->setText(i18n("Folder is empty"));
2144 m_placeholderLabel
->setVisible(true);