X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/13cf4c096fc673e43a22746342d25c506bde8405..0464ea82a6850f58805bc4d6fc1df5369d83c3df:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 613f99405..0afa27d73 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" @@ -50,6 +53,9 @@ #include #include +#ifndef QT_NO_ACCESSIBILITY +#include +#endif #include #include #include @@ -119,6 +125,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) KItemListController *controller = new KItemListController(m_model, m_view, this); const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; controller->setAutoActivationDelay(delay); + connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground); // The EnlargeSmallPreviews setting can only be changed after the model // has been set in the view by KItemListController. @@ -130,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(); }); @@ -198,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); @@ -230,7 +236,9 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) m_versionControlObserver->setView(this); m_versionControlObserver->setModel(m_model); connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage); - connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage); + connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, [this](const QString &message) { + Q_EMIT errorMessage(message, KIO::ERR_UNKNOWN); + }); connect(m_versionControlObserver, &VersionControlObserver::operationCompletedMessage, this, &DolphinView::operationCompletedMessage); m_twoClicksRenamingTimer = new QTimer(this); @@ -312,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 @@ -373,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); } @@ -755,7 +768,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(); } @@ -816,7 +845,7 @@ 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); KIO::FileUndoManager::self()->recordCopyJob(job); @@ -835,7 +864,7 @@ 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); KIO::FileUndoManager::self()->recordCopyJob(job); @@ -1117,7 +1146,7 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes) void DolphinView::slotItemMiddleClicked(int index) { const KFileItem &item = m_model->fileItem(index); - const QUrl &url = openItemAsFolderUrl(item); + const QUrl &url = openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives()); const auto modifiers = QGuiApplication::keyboardModifiers(); if (!url.isEmpty()) { // keep in sync with KUrlNavigator::slotNavigatorButtonClicked @@ -1145,6 +1174,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()); @@ -1210,7 +1242,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); @@ -1243,7 +1275,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(); @@ -1296,10 +1332,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(); } @@ -1452,7 +1489,7 @@ void DolphinView::onDirectoryLoadingCompletedAfterJob() void DolphinView::slotJobResult(KJob *job) { if (job->error() && job->error() != KIO::ERR_USER_CANCELED) { - Q_EMIT errorMessage(job->errorString()); + Q_EMIT errorMessage(job->errorString(), job->error()); } if (!m_selectJobCreatedItems) { m_selectedUrls.clear(); @@ -1714,6 +1751,7 @@ void DolphinView::updateSelectionState() if (!m_selectedUrls.isEmpty()) { KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); + const bool shouldScrollToCurrentItem = m_clearSelectionBeforeSelectingNewItems; // if there is a selection already, leave it that way // unless some drop/paste job are in the process of creating items if (!selectionManager->hasSelection() || m_selectJobCreatedItems) { @@ -1738,6 +1776,9 @@ void DolphinView::updateSelectionState() if (!selectedItems.isEmpty()) { selectionManager->beginAnchoredSelection(selectionManager->currentItem()); selectionManager->setSelectedItems(selectedItems); + if (shouldScrollToCurrentItem) { + m_view->scrollToItem(selectedItems.first()); + } } } } @@ -1820,7 +1861,7 @@ void DolphinView::slotTrashFileFinished(KJob *job) selectNextItem(); // Fixes BUG: 419914 via selecting next item Q_EMIT operationCompletedMessage(i18nc("@info:status", "Trash operation completed.")); } else if (job->error() != KIO::ERR_USER_CANCELED) { - Q_EMIT errorMessage(job->errorString()); + Q_EMIT errorMessage(job->errorString(), job->error()); } } @@ -1830,7 +1871,7 @@ void DolphinView::slotDeleteFileFinished(KJob *job) selectNextItem(); // Fixes BUG: 419914 via selecting next item Q_EMIT operationCompletedMessage(i18nc("@info:status", "Delete operation completed.")); } else if (job->error() != KIO::ERR_USER_CANCELED) { - Q_EMIT errorMessage(job->errorString()); + Q_EMIT errorMessage(job->errorString(), job->error()); } } @@ -1842,7 +1883,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().constEnd()); if (lastSelectedIndex < 0) { Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed."); return; @@ -1853,6 +1894,7 @@ void DolphinView::selectNextItem() } if (nextItem >= 0) { selectionManager->setSelected(nextItem, 1); + selectionManager->beginAnchoredSelection(nextItem); } m_selectNextItem = false; } @@ -1860,15 +1902,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); } } @@ -2003,25 +2048,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. @@ -2042,9 +2076,9 @@ void DolphinView::loadDirectory(const QUrl &url, bool reload) if (!url.isValid()) { const QString location(url.toDisplayString(QUrl::PreferLocalFile)); if (location.isEmpty()) { - Q_EMIT errorMessage(i18nc("@info:status", "The location is empty.")); + Q_EMIT errorMessage(i18nc("@info:status", "The location is empty."), KIO::ERR_UNKNOWN); } else { - Q_EMIT errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location)); + Q_EMIT errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location), KIO::ERR_UNKNOWN); } return; } @@ -2157,7 +2191,7 @@ void DolphinView::applyViewProperties(const ViewProperties &props) } else { header->setAutomaticColumnResizing(true); } - header->setSidePadding(DetailsModeSettings::sidePadding()); + header->setSidePadding(DetailsModeSettings::leftPadding(), DetailsModeSettings::rightPadding()); } m_view->endTransaction(); @@ -2188,8 +2222,16 @@ void DolphinView::pasteToUrl(const QUrl &url) m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; m_selectJobCreatedItems = true; - // TODO KF6 use KIO::PasteJob::copyJobStarted to hook to earlier events copying/moving connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated); + 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::linking, this, [this](KIO::Job *job, const QString &src, const QUrl &dest) { + Q_UNUSED(job) + Q_UNUSED(src) + slotItemCreated(dest); + }); + }); connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult); } @@ -2245,6 +2287,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()) { @@ -2257,11 +2315,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(); @@ -2307,12 +2360,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; } @@ -2356,6 +2419,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) @@ -2374,7 +2442,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; } }