X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/95542a389112491abf3a31c338e7d78f7785f48e..c4ffe88c9fafaed4b66a010a25b117427ba709f6:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index a18f53769..b702f5b13 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -123,8 +124,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) applyModeToView(); KItemListController *controller = new KItemListController(m_model, m_view, this); - const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; - controller->setAutoActivationDelay(delay); + controller->setAutoActivationEnabled(GeneralSettings::autoExpandFolders()); connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground); // The EnlargeSmallPreviews setting can only be changed after the model @@ -578,8 +578,7 @@ void DolphinView::readSettings() m_view->readSettings(); applyViewProperties(); - const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; - m_container->controller()->setAutoActivationDelay(delay); + m_container->controller()->setAutoActivationEnabled(GeneralSettings::autoExpandFolders()); const int newZoomLevel = m_view->zoomLevel(); if (newZoomLevel != oldZoomLevel) { @@ -812,7 +811,7 @@ void DolphinView::deleteSelectedItems() using Iface = KIO::AskUserActionInterface; auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Delete, Iface::DefaultConfirmation, this); - connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished); + connect(trashJob, &KJob::result, this, &DolphinView::slotDeleteFileFinished); m_selectNextItem = true; trashJob->start(); } @@ -848,6 +847,9 @@ void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl & connect(job, &KIO::CopyJob::result, this, &DolphinView::slotJobResult); connect(job, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob); connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob); + connect(job, &KIO::CopyJob::warning, this, [this](KJob *job, const QString & /* warning */) { + Q_EMIT errorMessage(job->errorString(), job->error()); + }); KIO::FileUndoManager::self()->recordCopyJob(job); } @@ -867,6 +869,9 @@ void DolphinView::moveSelectedItems(const KFileItemList &selection, const QUrl & connect(job, &KIO::CopyJob::result, this, &DolphinView::slotJobResult); connect(job, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob); connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob); + connect(job, &KIO::CopyJob::warning, this, [this](KJob *job, const QString & /*warning */) { + Q_EMIT errorMessage(job->errorString(), job->error()); + }); KIO::FileUndoManager::self()->recordCopyJob(job); } @@ -928,6 +933,9 @@ void DolphinView::duplicateSelectedItems() connect(job, &KIO::CopyJob::result, this, &DolphinView::slotJobResult); connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob); connect(job, &KIO::CopyJob::copyingLinkDone, this, &DolphinView::slotItemLinkCreatedFromJob); + connect(job, &KIO::CopyJob::warning, this, [this](KJob *job, const QString & /*warning*/) { + Q_EMIT errorMessage(job->errorString(), job->error()); + }); KIO::FileUndoManager::self()->recordCopyJob(job); } } @@ -1174,6 +1182,9 @@ void DolphinView::slotItemContextMenuRequested(int index, const QPointF &pos) if (m_selectionChangedTimer->isActive()) { emitSelectionChangedSignal(); } + if (m_twoClicksRenamingTimer->isActive()) { + abortTwoClicksRenaming(); + } const KFileItem item = m_model->fileItem(index); Q_EMIT requestContextMenu(pos.toPoint(), item, selectedItems(), url()); @@ -1400,6 +1411,9 @@ void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget * connect(job, &KIO::DropJob::copyJobStarted, this, [this](const KIO::CopyJob *copyJob) { connect(copyJob, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob); connect(copyJob, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob); + connect(copyJob, &KIO::CopyJob::warning, this, [this](KJob *job, const QString & /*warning*/) { + Q_EMIT errorMessage(job->errorString(), job->error()); + }); connect(copyJob, &KIO::CopyJob::linking, this, [this](KIO::Job *job, const QString &src, const QUrl &dest) { Q_UNUSED(job) Q_UNUSED(src) @@ -1773,7 +1787,6 @@ void DolphinView::updateSelectionState() if (!selectedItems.isEmpty()) { selectionManager->beginAnchoredSelection(selectionManager->currentItem()); selectionManager->setSelectedItems(selectedItems); - selectionManager->endAnchoredSelection(); if (shouldScrollToCurrentItem) { m_view->scrollToItem(selectedItems.first()); } @@ -1881,7 +1894,7 @@ void DolphinView::selectNextItem() Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed."); return; } - const auto lastSelectedIndex = m_model->index(selectedItems().last()); + const auto lastSelectedIndex = m_model->index(selectedItems().constLast()); if (lastSelectedIndex < 0) { Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed."); return; @@ -1945,6 +1958,7 @@ void DolphinView::slotDirectoryLoadingCompleted() Q_EMIT directoryLoadingCompleted(); + applyDynamicView(); updatePlaceholderLabel(); updateWritableState(); } @@ -2213,6 +2227,51 @@ void DolphinView::applyModeToView() } } +void DolphinView::applyDynamicView() +{ + ViewProperties props(viewPropertiesUrl()); + /* return early if: + * - dynamic view is not enabled + * - the current view mode is already Icon View + * - dynamic view has previously changed the view mode + */ + if (!GeneralSettings::dynamicView() || m_mode == IconsView || props.dynamicViewPassed()) { + return; + } + + uint imageAndVideoCount = 0; + uint checkedItems = 0; + const uint totalItems = itemsCount(); + const KFileItemList itemList = items(); + bool applyDynamicView = false; + + for (const auto &file : itemList) { + ++checkedItems; + const QString type = file.mimetype().slice(0, 5); + + if (type == "image" || type == "video") { + ++imageAndVideoCount; + // if 2/3 or more of the items are images/videos, dynamic view should be applied + applyDynamicView = imageAndVideoCount >= (totalItems * 2 / 3); + if (applyDynamicView) { + break; + } + } else if (checkedItems - imageAndVideoCount > totalItems / 3) { + // if more than a third of the checked files are not media files, return + return; + } + } + + if (!applyDynamicView) { + return; + } + + props.setAutoSaveEnabled(!GeneralSettings::globalViewProps()); + props.setDynamicViewPassed(true); + props.setViewMode(IconsView); + applyViewProperties(props); +} + void DolphinView::pasteToUrl(const QUrl &url) { KIO::PasteJob *job = KIO::paste(QApplication::clipboard()->mimeData(), url); @@ -2224,6 +2283,9 @@ void DolphinView::pasteToUrl(const QUrl &url) connect(job, &KIO::PasteJob::copyJobStarted, this, [this](const KIO::CopyJob *copyJob) { connect(copyJob, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob); connect(copyJob, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob); + connect(copyJob, &KIO::CopyJob::warning, this, [this](KJob *job, const QString & /*warning*/) { + Q_EMIT errorMessage(job->errorString(), job->error()); + }); connect(copyJob, &KIO::CopyJob::linking, this, [this](KIO::Job *job, const QString &src, const QUrl &dest) { Q_UNUSED(job) Q_UNUSED(src) @@ -2285,6 +2347,22 @@ bool DolphinView::isFolderWritable() const return m_isFolderWritable; } +int DolphinView::horizontalScrollBarHeight() const +{ + if (m_container && m_container->horizontalScrollBar() && m_container->horizontalScrollBar()->isVisible()) { + return m_container->horizontalScrollBar()->height(); + } + return 0; +} + +void DolphinView::setStatusBarOffset(int offset) +{ + KItemListView *view = m_container->controller()->view(); + if (view) { + view->setStatusBarOffset(offset); + } +} + QUrl DolphinView::viewPropertiesUrl() const { if (m_viewPropertiesContext.isEmpty()) { @@ -2424,7 +2502,7 @@ bool DolphinView::tryShowNameToolTip(QHelpEvent *event) const KFileItem item = m_model->fileItem(index.value()); const QString text = item.text(); const QPoint pos = mapToGlobal(event->pos()); - QToolTip::showText(pos, text); + QToolTip::showText(pos, text, this); return true; } }