X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/040e2afcfafaa8edd365d959760d4d0e7f3e48d3..a59d9f85fa770a00d10e66025e102c736e18fa70:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 66b6c23a8..0a1d70bf1 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -49,10 +49,8 @@ #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) #include -#endif +#include #include #include @@ -92,6 +90,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) , m_currentItemUrl() , m_scrollToCurrentItem(false) , m_restoredContentsPosition() + , m_controlWheelAccumulatedDelta(0) , m_selectedUrls() , m_clearSelectionBeforeSelectingNewItems(false) , m_markFirstNewlySelectedItemAsCurrent(false) @@ -130,6 +129,9 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); +#ifndef QT_NO_ACCESSIBILITY + m_view->setAccessibleParentsObject(m_container); +#endif setFocusProxy(m_container); connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); @@ -204,7 +206,6 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved); connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel); - connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updateSelectionState); m_view->installEventFilter(this); connect(m_view, &DolphinItemListView::sortOrderChanged, this, &DolphinView::slotSortOrderChangedByHeader); @@ -269,7 +270,6 @@ void DolphinView::setActive(bool active) if (active) { m_container->setFocus(); Q_EMIT activated(); - Q_EMIT writeStateChanged(m_isFolderWritable); } } @@ -281,6 +281,10 @@ bool DolphinView::isActive() const void DolphinView::setViewMode(Mode mode) { if (mode != m_mode) { + // Reset scrollbars before changing the view mode. + m_container->horizontalScrollBar()->setValue(0); + m_container->verticalScrollBar()->setValue(0); + ViewProperties props(viewPropertiesUrl()); props.setViewMode(mode); @@ -758,43 +762,22 @@ void DolphinView::trashSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Trash, Iface::DefaultConfirmation, this); connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished); m_selectNextItem = true; trashJob->start(); -#else - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::trash(list); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotTrashFileFinished); - } -#endif } void DolphinView::deleteSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) using Iface = KIO::AskUserActionInterface; auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Delete, Iface::DefaultConfirmation, this); connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished); m_selectNextItem = true; trashJob->start(); -#else - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::del(list); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotDeleteFileFinished); - } -#endif } void DolphinView::cutSelectedItemsToClipboard() @@ -814,6 +797,14 @@ void DolphinView::copySelectedItemsToClipboard() void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl) { + if (selection.isEmpty() || !destinationUrl.isValid()) { + return; + } + + m_clearSelectionBeforeSelectingNewItems = true; + m_markFirstNewlySelectedItemAsCurrent = true; + m_selectJobCreatedItems = true; + KIO::CopyJob *job = KIO::copy(selection.urlList(), destinationUrl, KIO::DefaultFlags); KJobWidgets::setWindow(job, this); @@ -825,6 +816,14 @@ void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl & void DolphinView::moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl) { + if (selection.isEmpty() || !destinationUrl.isValid()) { + return; + } + + m_clearSelectionBeforeSelectingNewItems = true; + m_markFirstNewlySelectedItemAsCurrent = true; + m_selectJobCreatedItems = true; + KIO::CopyJob *job = KIO::move(selection.urlList(), destinationUrl, KIO::DefaultFlags); KJobWidgets::setWindow(job, this); @@ -1065,24 +1064,14 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes) if (indexes.count() > 5) { QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) - const int answer = KMessageBox::warningTwoActions( + const int answer = KMessageBox::warningContinueCancel( this, question, {}, -#else - const int answer = - KMessageBox::warningYesNo(this, - question, - {}, -#endif KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()), QStringLiteral("document-open")), - KStandardGuiItem::cancel()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) - if (answer != KMessageBox::PrimaryAction) { -#else - if (answer != KMessageBox::Yes) { -#endif + KStandardGuiItem::cancel(), + QStringLiteral("ConfirmOpenManyFolders")); + if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) { return; } } @@ -1120,6 +1109,7 @@ void DolphinView::slotItemMiddleClicked(int index) const KFileItem &item = m_model->fileItem(index); const QUrl &url = openItemAsFolderUrl(item); const auto modifiers = QGuiApplication::keyboardModifiers(); + const QString &archiveProtocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype()); if (!url.isEmpty()) { // keep in sync with KUrlNavigator::slotNavigatorButtonClicked if (modifiers & Qt::ShiftModifier) { @@ -1127,13 +1117,15 @@ void DolphinView::slotItemMiddleClicked(int index) } else { Q_EMIT tabRequested(url); } - } else if (isTabsForFilesEnabled()) { + } else if (!archiveProtocol.isEmpty() && isTabsForFilesEnabled()) { // keep in sync with KUrlNavigator::slotNavigatorButtonClicked if (modifiers & Qt::ShiftModifier) { Q_EMIT activeTabRequested(item.url()); } else { Q_EMIT tabRequested(item.url()); } + } else { + Q_EMIT fileMiddleClickActivated(item); } } @@ -1433,6 +1425,14 @@ void DolphinView::slotItemCreated(const QUrl &url) } } +void DolphinView::onDirectoryLoadingCompleted() +{ + // the model should now contain all the items created by the job + updateSelectionState(); + m_selectJobCreatedItems = false; + m_selectedUrls.clear(); +} + void DolphinView::slotJobResult(KJob *job) { if (job->error() && job->error() != KIO::ERR_USER_CANCELED) { @@ -1448,21 +1448,7 @@ void DolphinView::slotJobResult(KJob *job) updateSelectionState(); if (!m_selectedUrls.isEmpty()) { // not all urls were found, the model may not be up to date - // TODO KF6 replace with Qt::singleShotConnection - QMetaObject::Connection *const connection = new QMetaObject::Connection; - *connection = connect( - m_model, - &KFileItemModel::directoryLoadingCompleted, - this, - [this, connection]() { - // the model should now contain all the items created by the job - updateSelectionState(); - m_selectJobCreatedItems = false; - m_selectedUrls.clear(); - QObject::disconnect(*connection); - delete connection; - }, - Qt::UniqueConnection); + connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::onDirectoryLoadingCompleted, Qt::UniqueConnection); } else { m_selectJobCreatedItems = false; m_selectedUrls.clear(); @@ -1775,7 +1761,7 @@ void DolphinView::updateViewState() // scroll to current item and reset the state if (m_scrollToCurrentItem) { - m_view->scrollToItem(currentIndex); + m_view->scrollToItem(currentIndex, KItemListView::ViewItemPosition::Middle); m_scrollToCurrentItem = false; } m_currentItemUrl = QUrl(); @@ -1812,6 +1798,11 @@ void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) } } +bool DolphinView::handleSpaceAsNormalKey() const +{ + return !m_container->hasFocus() || m_container->controller()->isSearchAsYouTypeActive(); +} + void DolphinView::slotTwoClicksRenamingTimerTimeout() { const KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); @@ -2000,13 +1991,8 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { KGuiItem yesGuiItem(i18nc("@action:button", "Rename and Hide"), QStringLiteral("view-hidden")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const auto code = KMessageBox::questionTwoActions(this, -#else - const auto code = - KMessageBox::questionYesNo(this, -#endif oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" "Do you still want to rename it?") : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" @@ -2016,11 +2002,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con KStandardGuiItem::cancel(), QStringLiteral("ConfirmHide")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (code == KMessageBox::SecondaryAction) { -#else - if (code == KMessageBox::No) { -#endif return; } } @@ -2043,9 +2025,9 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->uiDelegate()->setAutoErrorHandlingEnabled(true); - forceUrlsSelection(newUrl, {newUrl}); - if (!newNameExistsAlready) { + forceUrlsSelection(newUrl, {newUrl}); + // Only connect the result signal if there is no item with the new name // in the model yet, see bug 328262. connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); @@ -2263,6 +2245,11 @@ void DolphinView::updateWritableState() } } +bool DolphinView::isFolderWritable() const +{ + return m_isFolderWritable; +} + QUrl DolphinView::viewPropertiesUrl() const { if (m_viewPropertiesContext.isEmpty()) { @@ -2303,7 +2290,7 @@ void DolphinView::copyPathToClipboard() if (clipboard == nullptr) { return; } - clipboard->setText(path); + clipboard->setText(QDir::toNativeSeparators(path)); } void DolphinView::slotIncreaseZoom() @@ -2323,7 +2310,7 @@ void DolphinView::slotSwipeUp() void DolphinView::showLoadingPlaceholder() { - m_placeholderLabel->setText(i18n("Loading...")); + m_placeholderLabel->setText(i18n("Loading…")); m_placeholderLabel->setVisible(true); } @@ -2398,3 +2385,5 @@ bool DolphinView::tryShowNameToolTip(QHelpEvent *event) } return false; } + +#include "moc_dolphinview.cpp"