X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2e588733c759cccd2d86e34a3a394b9a8ab0c800..f0d201dcf1fb46e172e950c6f1767c5e8e6b9495:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 5a36ad103..d16aa3b09 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,13 @@ #include #include +#include + +#include +#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) +#include +#endif + #include #include #include @@ -111,7 +117,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : m_model = new KFileItemModel(this); m_view = new DolphinItemListView(); - m_view->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle()); + m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting); m_view->setVisibleRoles({"text"}); applyModeToView(); @@ -155,6 +161,10 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : auto *centeringLayout = new QVBoxLayout(m_container); centeringLayout->addWidget(m_placeholderLabel); centeringLayout->setAlignment(m_placeholderLabel, Qt::AlignCenter); + m_placeholderLabel->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_placeholderLabel, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos){ + slotViewContextMenuRequested(m_placeholderLabel->mapToGlobal(pos)); + }); controller->setSelectionBehavior(KItemListController::MultiSelection); connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); @@ -189,6 +199,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); + connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved); connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel); @@ -235,6 +246,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : DolphinView::~DolphinView() { + disconnect(m_container->controller(), &KItemListController::modelChanged, this, &DolphinView::slotModelChanged); } QUrl DolphinView::url() const @@ -289,9 +301,11 @@ void DolphinView::setSelectionModeEnabled(const bool enabled) m_proxyStyle = std::make_unique(); setStyle(m_proxyStyle.get()); m_view->setStyle(m_proxyStyle.get()); + m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False); } else { setStyle(QApplication::style()); m_view->setStyle(QApplication::style()); + m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting); } m_container->controller()->setSelectionModeEnabled(enabled); } @@ -749,6 +763,13 @@ void DolphinView::renameSelectedItems() 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); + trashJob->start(); +#else KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(window()); if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { @@ -758,12 +779,19 @@ void DolphinView::trashSelectedItems() 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); + trashJob->start(); +#else KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(window()); if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { @@ -772,6 +800,7 @@ void DolphinView::deleteSelectedItems() connect(job, &KIO::Job::result, this, &DolphinView::slotDeleteFileFinished); } +#endif } void DolphinView::cutSelectedItemsToClipboard() @@ -1015,11 +1044,19 @@ 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(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 return; } } @@ -1365,7 +1402,7 @@ void DolphinView::slotItemCreated(const QUrl& url) void DolphinView::slotJobResult(KJob *job) { - if (job->error()) { + if (job->error() && job->error() != KIO::ERR_USER_CANCELED) { Q_EMIT errorMessage(job->errorString()); } if (!m_selectedUrls.isEmpty()) { @@ -1488,6 +1525,16 @@ bool DolphinView::itemsExpandable() const return m_mode == DetailsView; } +bool DolphinView::isExpanded(const KFileItem& item) const +{ + Q_ASSERT(item.isDir()); + Q_ASSERT(items().contains(item)); + if (!itemsExpandable()) { + return false; + } + return m_model->isExpanded(m_model->index(item)); +} + void DolphinView::restoreState(QDataStream& stream) { // Read the version number of the view state and check if the version is supported. @@ -1864,10 +1911,13 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con #ifndef Q_OS_WIN //Confirm hiding file/directory by renaming inline if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { - KGuiItem yesGuiItem(KStandardGuiItem::yes()); - yesGuiItem.setText(i18nc("@action:button", "Rename and Hide")); + 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" @@ -1878,7 +1928,11 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con QStringLiteral("ConfirmHide") ); +#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) + if (code == KMessageBox::SecondaryAction) { +#else if (code == KMessageBox::No) { +#endif return; } } @@ -2214,6 +2268,8 @@ void DolphinView::updatePlaceholderLabel() m_placeholderLabel->setText(i18n("No relevant network resources found")); } else if (m_url.scheme() == QLatin1String("mtp") && m_url.path() == QLatin1String("/")) { m_placeholderLabel->setText(i18n("No MTP-compatible devices found")); + } else if (m_url.scheme() == QLatin1String("afc") && m_url.path() == QLatin1String("/")) { + m_placeholderLabel->setText(i18n("No Apple devices found")); } else if (m_url.scheme() == QLatin1String("bluetooth")) { m_placeholderLabel->setText(i18n("No Bluetooth devices found")); } else {