+void DolphinPart::slotMessage(const QString &msg)
+{
+ Q_EMIT setStatusBarText(msg);
+}
+
+void DolphinPart::slotErrorMessage(const QString &msg)
+{
+ qCDebug(DolphinDebug) << msg;
+ Q_EMIT canceled(msg);
+ //KMessageBox::error(m_view, msg);
+}
+
+void DolphinPart::slotRequestItemInfo(const KFileItem &item)
+{
+ Q_EMIT m_extension->mouseOverInfo(item);
+ if (item.isNull()) {
+ updateStatusBar();
+ } else {
+ const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
+ Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
+ }
+}
+
+void DolphinPart::slotItemActivated(const KFileItem &item)
+{
+ KParts::OpenUrlArguments args;
+ // Forget about the known mimetype if a target URL is used.
+ // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
+ if (item.targetUrl() == item.url()) {
+ args.setMimeType(item.mimetype());
+ }
+
+ Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args);
+}
+
+void DolphinPart::slotItemsActivated(const KFileItemList &items)
+{
+ for (const KFileItem &item : items) {
+ slotItemActivated(item);
+ }
+}
+
+void DolphinPart::createNewWindow(const QUrl &url)
+{
+ // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
+ // should be moved into DolphinPart::slotItemActivated()
+ Q_EMIT m_extension->createNewWindow(url);
+}
+
+void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
+{
+ KParts::NavigationExtension::PopupFlags popupFlags =
+ KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
+
+ KFileItem item(_item);
+
+ if (item.isNull()) { // viewport context menu
+ item = m_view->rootItem();
+ if (item.isNull())
+ item = KFileItem(url());
+ else
+ item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
+ }
+
+ KFileItemList items;
+ if (selectedItems.isEmpty()) {
+ items.append(item);
+ } else {
+ items = selectedItems;
+ }
+
+ KFileItemListProperties capabilities(items);
+
+ KParts::NavigationExtension::ActionGroupMap actionGroups;
+ QList<QAction *> editActions;
+ editActions += m_view->versionControlActions(m_view->selectedItems());
+
+ if (!_item.isNull()) { // only for context menu on one or more items
+ const bool supportsMoving = capabilities.supportsMoving();
+
+ if (capabilities.supportsDeleting()) {
+ const bool showDeleteAction =
+ (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
+ const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
+
+ if (showDeleteAction && showMoveToTrashAction) {
+ delete m_removeAction;
+ m_removeAction = nullptr;
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else if (showDeleteAction && !showMoveToTrashAction) {
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else {
+ if (!m_removeAction)
+ m_removeAction = new DolphinRemoveAction(this, actionCollection());
+ editActions.append(m_removeAction);
+ m_removeAction->update();
+ }
+ } else {
+ popupFlags |= KParts::NavigationExtension::NoDeletion;
+ }
+
+ if (supportsMoving) {
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
+ }
+
+ // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
+ // since otherwise the created file would not be visible.
+ // But in treeview mode we should allow it.
+ if (m_view->itemsExpandable())
+ popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
+ }
+
+ actionGroups.insert(QStringLiteral("editactions"), editActions);
+
+ Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
+}
+
+void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
+{
+ qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
+ if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
+ KParts::ReadOnlyPart::setUrl(newUrl);
+ const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
+ Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
+ }
+}
+
+void DolphinPart::slotEditMimeType()
+{
+ const KFileItemList items = m_view->selectedItems();
+ if (!items.isEmpty()) {
+ KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
+ }
+}
+
+void DolphinPart::slotSelectItemsMatchingPattern()
+{
+ openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
+}
+
+void DolphinPart::slotUnselectItemsMatchingPattern()
+{
+ openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);
+}
+
+void DolphinPart::openSelectionDialog(const QString &title, const QString &text, bool selectItems)
+{
+ auto *dialog = new QInputDialog(m_view);
+ dialog->setAttribute(Qt::WA_DeleteOnClose, true);
+ dialog->setInputMode(QInputDialog::TextInput);
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(text);
+
+ const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
+ dialog->setComboBoxEditable(true);
+ dialog->setComboBoxItems(group.readEntry("History", QStringList()));
+
+ dialog->setTextValue(QStringLiteral("*"));
+
+ connect(dialog, &QDialog::accepted, this, [=, this]() {
+ const QString pattern = dialog->textValue();
+ if (!pattern.isEmpty()) {
+ QStringList items = dialog->comboBoxItems();
+ items.removeAll(pattern);
+ items.prepend(pattern);
+
+ // Need to evaluate this again here, because the captured value is const
+ // (even if the const were removed from 'const KConfigGroup group =' above).
+ KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
+ // Limit the size of the saved history.
+ group.writeEntry("History", items.mid(0, 10));
+ group.sync();
+
+ const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
+ m_view->selectItems(patternRegExp, selectItems);
+ }
+ });
+
+ dialog->open();
+}
+
+void DolphinPart::setCurrentViewMode(const QString &viewModeName)
+{
+ QAction *action = actionCollection()->action(viewModeName);
+ Q_ASSERT(action);
+ action->trigger();
+}
+
+QString DolphinPart::currentViewMode() const
+{
+ return m_actionHandler->currentViewModeActionName();
+}
+
+void DolphinPart::setNameFilter(const QString &nameFilter)
+{
+ // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
+ // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
+ m_nameFilter = nameFilter;
+ // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
+}
+
+QString DolphinPart::localFilePathOrHome() const
+{
+ const QString localPath = localFilePath();
+ if (!localPath.isEmpty()) {
+ return localPath;
+ }
+ return QDir::homePath();
+}
+
+void DolphinPart::slotOpenTerminal()
+{
+ auto job = new KTerminalLauncherJob(QString());
+ job->setWorkingDirectory(localFilePathOrHome());
+ job->start();
+}
+
+void DolphinPart::slotFindFile()
+{
+ KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
+ job->setDesktopName(QStringLiteral("org.kde.kfind"));
+ job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
+ job->start();
+}
+
+void DolphinPart::updateNewMenu()
+{
+ // As requested by KNewFileMenu :
+ m_newFileMenu->checkUpToDate();
+ // And set the files that the menu apply on :
+ m_newFileMenu->setWorkingDirectory(url());
+}
+
+void DolphinPart::updateStatusBar()
+{
+ m_view->requestStatusBarText();
+}
+
+void DolphinPart::updateProgress(int percent)
+{
+ Q_EMIT m_extension->loadingProgress(percent);
+}
+
+void DolphinPart::createDirectory()
+{
+ m_newFileMenu->setWorkingDirectory(url());
+ m_newFileMenu->createDirectory();
+}
+
+void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
+{
+ if (files.isEmpty()) {
+ return;
+ }
+
+ m_view->markUrlsAsSelected(files);
+ m_view->markUrlAsCurrent(files.at(0));
+}
+
+bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
+{
+ using ShiftState = DolphinRemoveAction::ShiftState;
+ const int type = event->type();
+
+ if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
+ QMenu *menu = qobject_cast<QMenu *>(obj);
+ if (menu && menu->parent() == m_view) {
+ QKeyEvent *ev = static_cast<QKeyEvent *>(event);
+ if (ev->key() == Qt::Key_Shift) {
+ m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
+ }
+ }
+ }
+
+ return KParts::ReadOnlyPart::eventFilter(obj, event);
+}
+