X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6e752f507a1dd82a40d4bd140457203842fc0c80..refs/heads/master:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index abaed9c7c..5c961b47b 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -12,6 +12,9 @@ #include "dolphinitemlistview.h" #include "dolphinnewfilemenuobserver.h" #include "draganddrophelper.h" +#ifndef QT_NO_ACCESSIBILITY +#include "kitemviews/accessibility/kitemlistviewaccessible.h" +#endif #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" #include "kitemviews/kitemlistcontainer.h" @@ -41,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +54,9 @@ #include #include +#ifndef QT_NO_ACCESSIBILITY +#include +#endif #include #include #include @@ -117,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 @@ -131,10 +137,10 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) m_view->setAccessibleParentsObject(m_container); #endif setFocusProxy(m_container); - connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { + connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [this] { hideToolTip(); }); - connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { + connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [this] { hideToolTip(); }); @@ -199,8 +205,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection); connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError); connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged); - // #473377: Use a QueuedConnection to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns. - connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved, Qt::QueuedConnection); + connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved); connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel); @@ -315,6 +320,12 @@ void DolphinView::setSelectionModeEnabled(const bool enabled) m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting); } m_container->controller()->setSelectionModeEnabled(enabled); +#ifndef QT_NO_ACCESSIBILITY + if (QAccessible::isActive()) { + auto accessibleViewInterface = static_cast(QAccessible::queryAccessibleInterface(m_view)); + accessibleViewInterface->announceSelectionModeEnabled(enabled); + } +#endif } bool DolphinView::selectionMode() const @@ -376,9 +387,8 @@ void DolphinView::setGroupedSorting(bool grouped) ViewProperties props(viewPropertiesUrl()); props.setGroupedSorting(grouped); - props.save(); - m_container->controller()->model()->setGroupedSorting(grouped); + m_model->setGroupedSorting(grouped); Q_EMIT groupedSortingChanged(grouped); } @@ -604,8 +614,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) { @@ -794,7 +803,23 @@ void DolphinView::renameSelectedItems() } else { KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(items, this); - connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished); + connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, [this, items](const QList &urls) { + // The model may have already been updated, so it's possible that we don't find the old items. + for (int i = 0; i < items.count(); ++i) { + const int index = m_model->index(items[i]); + if (index >= 0) { + QHash data; + data.insert("text", urls[i].fileName()); + m_model->setData(index, data); + } + } + + forceUrlsSelection(urls.first(), urls); + updateSelectionState(); + }); + connect(dialog, &KIO::RenameFileDialog::error, this, [this](KJob *job) { + KMessageBox::error(this, job->errorString()); + }); dialog->open(); } @@ -822,7 +847,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(); } @@ -855,9 +880,12 @@ void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl & KIO::CopyJob *job = KIO::copy(selection.urlList(), destinationUrl, KIO::DefaultFlags); KJobWidgets::setWindow(job, this); - connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult); + 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); } @@ -874,9 +902,12 @@ void DolphinView::moveSelectedItems(const KFileItemList &selection, const QUrl & KIO::CopyJob *job = KIO::move(selection.urlList(), destinationUrl, KIO::DefaultFlags); KJobWidgets::setWindow(job, this); - connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult); + 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); } @@ -938,6 +969,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); } } @@ -1184,6 +1218,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()); @@ -1249,7 +1286,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos) QAction *toggleSidePaddingAction = menu->addAction(i18nc("@action:inmenu", "Side Padding")); toggleSidePaddingAction->setCheckable(true); - toggleSidePaddingAction->setChecked(view->header()->sidePadding() > 0); + toggleSidePaddingAction->setChecked(layoutDirection() == Qt::LeftToRight ? view->header()->leftPadding() > 0 : view->header()->rightPadding() > 0); QAction *autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths")); autoAdjustWidthsAction->setCheckable(true); @@ -1282,7 +1319,11 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos) props.setHeaderColumnWidths(columnWidths); header->setAutomaticColumnResizing(false); } else if (action == toggleSidePaddingAction) { - header->setSidePadding(toggleSidePaddingAction->isChecked() ? 20 : 0); + if (toggleSidePaddingAction->isChecked()) { + header->setSidePadding(20, 20); + } else { + header->setSidePadding(0, 0); + } } else { // Show or hide the selected role const QByteArray selectedRole = action->data().toByteArray(); @@ -1335,10 +1376,11 @@ void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray &role, qr props.setHeaderColumnWidths(columnWidths); } -void DolphinView::slotSidePaddingWidthChanged(qreal width) +void DolphinView::slotSidePaddingWidthChanged(qreal leftPaddingWidth, qreal rightPaddingWidth) { ViewProperties props(viewPropertiesUrl()); - DetailsModeSettings::setSidePadding(int(width)); + DetailsModeSettings::setLeftPadding(int(leftPaddingWidth)); + DetailsModeSettings::setRightPadding(int(rightPaddingWidth)); m_view->writeSettings(); } @@ -1405,6 +1447,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) @@ -1778,7 +1823,6 @@ void DolphinView::updateSelectionState() if (!selectedItems.isEmpty()) { selectionManager->beginAnchoredSelection(selectionManager->currentItem()); selectionManager->setSelectedItems(selectedItems); - selectionManager->endAnchoredSelection(); if (shouldScrollToCurrentItem) { m_view->scrollToItem(selectedItems.first()); } @@ -1886,7 +1930,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; @@ -1897,6 +1941,7 @@ void DolphinView::selectNextItem() } if (nextItem >= 0) { selectionManager->setSelected(nextItem, 1); + selectionManager->beginAnchoredSelection(nextItem); } m_selectNextItem = false; } @@ -1904,15 +1949,18 @@ void DolphinView::selectNextItem() void DolphinView::slotRenamingResult(KJob *job) { - if (job->error()) { + // Change model data after renaming has succeeded. On failure we do nothing. + // If there is already an item with the newUrl, the copyjob will open a dialog for it, and + // KFileItemModel will update the data when the dir lister signals that the file name has changed. + if (!job->error()) { KIO::CopyJob *copyJob = qobject_cast(job); Q_ASSERT(copyJob); const QUrl newUrl = copyJob->destUrl(); + const QUrl oldUrl = copyJob->srcUrls().at(0); const int index = m_model->index(newUrl); - if (index >= 0) { + if (m_model->index(oldUrl) == index) { QHash data; - const QUrl oldUrl = copyJob->srcUrls().at(0); - data.insert("text", oldUrl.fileName()); + data.insert("text", newUrl.fileName()); m_model->setData(index, data); } } @@ -1946,6 +1994,7 @@ void DolphinView::slotDirectoryLoadingCompleted() Q_EMIT directoryLoadingCompleted(); + applyDynamicView(); updatePlaceholderLabel(); updateWritableState(); } @@ -2047,25 +2096,14 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con } #endif - const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); - if (!newNameExistsAlready && m_model->index(oldUrl) == index) { - // Only change the data in the model if no item with the new name - // is in the model yet. If there is an item with the new name - // already, calling KIO::CopyJob will open a dialog - // asking for a new name, and KFileItemModel will update the - // data when the dir lister signals that the file name has changed. - QHash data; - data.insert(role, retVal.newName); - m_model->setData(index, data); - } - KIO::Job *job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->uiDelegate()->setAutoErrorHandlingEnabled(true); - if (!newNameExistsAlready) { + if (m_model->index(newUrl) < 0) { forceUrlsSelection(newUrl, {newUrl}); + updateSelectionState(); // Only connect the result signal if there is no item with the new name // in the model yet, see bug 328262. @@ -2213,7 +2251,7 @@ void DolphinView::applyViewProperties(const ViewProperties &props) } else { header->setAutomaticColumnResizing(true); } - header->setSidePadding(DetailsModeSettings::sidePadding()); + header->setSidePadding(DetailsModeSettings::leftPadding(), DetailsModeSettings::rightPadding()); } m_view->endTransaction(); @@ -2237,6 +2275,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); @@ -2248,6 +2331,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) @@ -2309,6 +2395,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()) { @@ -2321,11 +2423,6 @@ QUrl DolphinView::viewPropertiesUrl() const return url; } -void DolphinView::slotRenameDialogRenamingFinished(const QList &urls) -{ - forceUrlsSelection(urls.first(), urls); -} - void DolphinView::forceUrlsSelection(const QUrl ¤t, const QList &selected) { clearSelection(); @@ -2371,12 +2468,22 @@ void DolphinView::showLoadingPlaceholder() { m_placeholderLabel->setText(i18n("Loading…")); m_placeholderLabel->setVisible(true); +#ifndef QT_NO_ACCESSIBILITY + if (QAccessible::isActive()) { + static_cast(QAccessible::queryAccessibleInterface(m_view))->announceNewlyLoadedLocation(m_placeholderLabel->text()); + } +#endif } void DolphinView::updatePlaceholderLabel() { m_showLoadingPlaceholderTimer->stop(); if (itemsCount() > 0) { +#ifndef QT_NO_ACCESSIBILITY + if (QAccessible::isActive()) { + static_cast(QAccessible::queryAccessibleInterface(m_view))->announceNewlyLoadedLocation(QString()); + } +#endif m_placeholderLabel->setVisible(false); return; } @@ -2420,6 +2527,11 @@ void DolphinView::updatePlaceholderLabel() } m_placeholderLabel->setVisible(true); +#ifndef QT_NO_ACCESSIBILITY + if (QAccessible::isActive()) { + static_cast(QAccessible::queryAccessibleInterface(m_view))->announceNewlyLoadedLocation(m_placeholderLabel->text()); + } +#endif } bool DolphinView::tryShowNameToolTip(QHelpEvent *event) @@ -2438,7 +2550,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; } }