]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Merge branch 'master' into kf6
[dolphin.git] / src / dolphinpart.cpp
1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "dolphinpart.h"
8
9 #include "dolphindebug.h"
10 #include "dolphinnewfilemenu.h"
11 #include "dolphinpart_ext.h"
12 #include "dolphinremoveaction.h"
13 #include "kitemviews/kfileitemmodel.h"
14 #include "views/dolphinnewfilemenuobserver.h"
15 #include "views/dolphinremoteencoding.h"
16 #include "views/dolphinview.h"
17 #include "views/dolphinviewactionhandler.h"
18
19 #include <KActionCollection>
20 #include <KAuthorized>
21 #include <KConfigGroup>
22 #include <KDialogJobUiDelegate>
23 #include <KDirLister>
24 #include <KFileItemListProperties>
25 #include <KIO/CommandLauncherJob>
26 #include <KIconLoader>
27 #include <KJobWidgets>
28 #include <KLocalizedString>
29 #include <KMessageBox>
30 #include <KMimeTypeEditor>
31 #include <KMoreToolsMenuFactory>
32 #include <KPluginFactory>
33 #include <KPluginMetaData>
34 #include <KSharedConfig>
35 #include <KTerminalLauncherJob>
36
37 #include <QActionGroup>
38 #include <QApplication>
39 #include <QClipboard>
40 #include <QDir>
41 #include <QInputDialog>
42 #include <QKeyEvent>
43 #include <QMenu>
44 #include <QRegularExpression>
45 #include <QStandardPaths>
46 #include <QTextDocument>
47
48 #include <KPluginFactory>
49
50 K_PLUGIN_CLASS_WITH_JSON(DolphinPart, "dolphinpart.json")
51
52 DolphinPart::DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
53 : KParts::ReadOnlyPart(parent, metaData)
54 , m_openTerminalAction(nullptr)
55 , m_removeAction(nullptr)
56 {
57 Q_UNUSED(args)
58
59 m_extension = new DolphinPartBrowserExtension(this);
60
61 // make sure that other apps using this part find Dolphin's view-file-columns icons
62 KIconLoader::global()->addAppDir(QStringLiteral("dolphin"));
63
64 m_view = new DolphinView(QUrl(), parentWidget);
65 m_view->setTabsForFilesEnabled(true);
66 setWidget(m_view);
67
68 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinPart::slotErrorMessage);
69
70 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &KParts::ReadOnlyPart::completed);
71 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinPart::updatePasteAction);
72 connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinPart::updateProgress);
73 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
74
75 setXMLFile(QStringLiteral("dolphinpart.rc"));
76
77 connect(m_view, &DolphinView::infoMessage, this, &DolphinPart::slotMessage);
78 connect(m_view, &DolphinView::operationCompletedMessage, this, &DolphinPart::slotMessage);
79 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
80 connect(m_view, &DolphinView::itemActivated, this, &DolphinPart::slotItemActivated);
81 connect(m_view, &DolphinView::itemsActivated, this, &DolphinPart::slotItemsActivated);
82 connect(m_view, &DolphinView::statusBarTextChanged, this, [this](const QString &text) {
83 const QString escapedText = Qt::convertFromPlainText(text);
84 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
85 });
86 connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow);
87 connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu);
88 connect(m_view, &DolphinView::selectionChanged, m_extension, &KParts::NavigationExtension::selectionInfo);
89 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::slotSelectionChanged);
90 connect(m_view, &DolphinView::requestItemInfo, this, &DolphinPart::slotRequestItemInfo);
91 connect(m_view, &DolphinView::modeChanged, this, &DolphinPart::viewModeChanged); // relay signal
92 connect(m_view, &DolphinView::redirection, this, &DolphinPart::slotDirectoryRedirection);
93
94 // Watch for changes that should result in updates to the
95 // status bar text.
96 connect(m_view, &DolphinView::itemCountChanged, this, &DolphinPart::updateStatusBar);
97 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::updateStatusBar);
98
99 m_actionHandler = new DolphinViewActionHandler(actionCollection(), nullptr, this);
100 m_actionHandler->setCurrentView(m_view);
101 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinPart::createDirectory);
102
103 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
104 connect(this, &DolphinPart::aboutToOpenURL, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
105
106 QClipboard *clipboard = QApplication::clipboard();
107 connect(clipboard, &QClipboard::dataChanged, this, &DolphinPart::updatePasteAction);
108
109 // Create file info and listing filter extensions.
110 // NOTE: Listing filter needs to be instantiated after the creation of the view.
111 new DolphinPartFileInfoExtension(this);
112
113 new DolphinPartListingFilterExtension(this);
114
115 KDirLister *lister = m_view->m_model->m_dirLister;
116 if (lister) {
117 DolphinPartListingNotificationExtension *notifyExt = new DolphinPartListingNotificationExtension(this);
118 connect(lister, &KDirLister::newItems, notifyExt, &DolphinPartListingNotificationExtension::slotNewItems);
119 connect(lister, &KDirLister::itemsDeleted, notifyExt, &DolphinPartListingNotificationExtension::slotItemsDeleted);
120 } else {
121 qCWarning(DolphinDebug) << "NULL KDirLister object! KParts::ListingNotificationExtension will NOT be supported";
122 }
123
124 createActions();
125 m_actionHandler->updateViewActions();
126 slotSelectionChanged(KFileItemList()); // initially disable selection-dependent actions
127
128 // Listen to events from the app so we can update the remove key by
129 // checking for a Shift key press.
130 qApp->installEventFilter(this);
131
132 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
133 // (sort of spacial navigation)
134 }
135
136 DolphinPart::~DolphinPart()
137 {
138 }
139
140 void DolphinPart::createActions()
141 {
142 // Edit menu
143
144 m_newFileMenu = new DolphinNewFileMenu(actionCollection()->action(QStringLiteral("create_dir")), this);
145 m_newFileMenu->setParentWidget(widget());
146 connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
147
148 QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType"));
149 editMimeTypeAction->setText(i18nc("@action:inmenu Edit", "&Edit File Type…"));
150 connect(editMimeTypeAction, &QAction::triggered, this, &DolphinPart::slotEditMimeType);
151
152 QAction *selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
153 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching…"));
154 actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL | Qt::Key_S);
155 connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
156
157 QAction *unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
158 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching…"));
159 connect(unselectItemsMatching, &QAction::triggered, this, &DolphinPart::slotUnselectItemsMatchingPattern);
160
161 KStandardAction::selectAll(m_view, &DolphinView::selectAll, actionCollection());
162
163 QAction *unselectAll = actionCollection()->addAction(QStringLiteral("unselect_all"));
164 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
165 connect(unselectAll, &QAction::triggered, m_view, &DolphinView::clearSelection);
166
167 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
168 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
169 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
170 connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
171
172 // View menu: all done by DolphinViewActionHandler
173
174 // Go menu
175
176 QActionGroup *goActionGroup = new QActionGroup(this);
177 connect(goActionGroup, &QActionGroup::triggered, this, &DolphinPart::slotGoTriggered);
178
179 createGoAction("go_applications", "start-here-kde", i18nc("@action:inmenu Go", "App&lications"), QStringLiteral("programs:/"), goActionGroup);
180 createGoAction("go_network_folders", "folder-remote", i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"), goActionGroup);
181 createGoAction("go_trash", "user-trash", i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"), goActionGroup);
182 createGoAction("go_autostart",
183 "",
184 i18nc("@action:inmenu Go", "Autostart"),
185 QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart",
186 goActionGroup);
187
188 // Tools menu
189 m_findFileAction = KStandardAction::find(this, &DolphinPart::slotFindFile, actionCollection());
190 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File…"));
191
192 #ifndef Q_OS_WIN
193 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
194 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
195 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
196 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
197 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
198 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
199 }
200 #endif
201 }
202
203 void DolphinPart::createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup)
204 {
205 QAction *action = actionCollection()->addAction(name);
206 action->setIcon(QIcon::fromTheme(iconName));
207 action->setText(text);
208 action->setData(url);
209 action->setActionGroup(actionGroup);
210 }
211
212 void DolphinPart::slotGoTriggered(QAction *action)
213 {
214 const QString url = action->data().toString();
215 Q_EMIT m_extension->openUrlRequest(QUrl(url));
216 }
217
218 void DolphinPart::slotSelectionChanged(const KFileItemList &selection)
219 {
220 const bool hasSelection = !selection.isEmpty();
221
222 QAction *renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
223 QAction *moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
224 QAction *deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
225 QAction *editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
226 QAction *propertiesAction = actionCollection()->action(QStringLiteral("properties"));
227 QAction *deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
228
229 if (!hasSelection) {
230 stateChanged(QStringLiteral("has_no_selection"));
231
232 Q_EMIT m_extension->enableAction("cut", false);
233 Q_EMIT m_extension->enableAction("copy", false);
234 deleteWithTrashShortcut->setEnabled(false);
235 editMimeTypeAction->setEnabled(false);
236 } else {
237 stateChanged(QStringLiteral("has_selection"));
238
239 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
240 // in libkonq
241 KFileItemListProperties capabilities(selection);
242 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
243
244 renameAction->setEnabled(capabilities.supportsMoving());
245 moveToTrashAction->setEnabled(enableMoveToTrash);
246 deleteAction->setEnabled(capabilities.supportsDeleting());
247 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
248 editMimeTypeAction->setEnabled(true);
249 propertiesAction->setEnabled(true);
250 Q_EMIT m_extension->enableAction("cut", capabilities.supportsMoving());
251 Q_EMIT m_extension->enableAction("copy", true);
252 }
253 }
254
255 void DolphinPart::updatePasteAction()
256 {
257 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
258 Q_EMIT m_extension->enableAction("paste", pasteInfo.first);
259 Q_EMIT m_extension->setActionText("paste", pasteInfo.second);
260 }
261
262 QString DolphinPart::urlToLocalFilePath(const QUrl &url)
263 {
264 KIO::StatJob *statJob = KIO::mostLocalUrl(url);
265 KJobWidgets::setWindow(statJob, widget());
266 statJob->exec();
267 QUrl localUrl = statJob->mostLocalUrl();
268 if (localUrl.isLocalFile()) {
269 return localUrl.toLocalFile();
270 }
271 return QString();
272 }
273
274 bool DolphinPart::openUrl(const QUrl &url)
275 {
276 bool reload = arguments().reload();
277 // A bit of a workaround so that changing the namefilter works: force reload.
278 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
279 if (m_nameFilter != m_view->nameFilter())
280 reload = true;
281 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
282 return true;
283 }
284 setUrl(url); // remember url at the KParts level
285 setLocalFilePath(urlToLocalFilePath(url)); // remember local path at the KParts level
286 QUrl visibleUrl(url);
287 if (!m_nameFilter.isEmpty()) {
288 visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
289 }
290 QString prettyUrl = visibleUrl.toDisplayString(QUrl::PreferLocalFile);
291 Q_EMIT setWindowCaption(prettyUrl);
292 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
293 Q_EMIT started(nullptr); // get the wheel to spin
294 m_view->setNameFilter(m_nameFilter);
295 m_view->setUrl(url);
296 updatePasteAction();
297 Q_EMIT aboutToOpenURL();
298 if (reload)
299 m_view->reload();
300 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
301 // e.g. ftp, smb, etc. #279283
302 const bool isLocalUrl = !(localFilePath().isEmpty());
303 m_findFileAction->setEnabled(isLocalUrl);
304 if (m_openTerminalAction) {
305 m_openTerminalAction->setEnabled(isLocalUrl);
306 }
307 return true;
308 }
309
310 void DolphinPart::slotMessage(const QString &msg)
311 {
312 Q_EMIT setStatusBarText(msg);
313 }
314
315 void DolphinPart::slotErrorMessage(const QString &msg)
316 {
317 qCDebug(DolphinDebug) << msg;
318 Q_EMIT canceled(msg);
319 //KMessageBox::error(m_view, msg);
320 }
321
322 void DolphinPart::slotRequestItemInfo(const KFileItem &item)
323 {
324 Q_EMIT m_extension->mouseOverInfo(item);
325 if (item.isNull()) {
326 updateStatusBar();
327 } else {
328 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
329 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
330 }
331 }
332
333 void DolphinPart::slotItemActivated(const KFileItem &item)
334 {
335 KParts::OpenUrlArguments args;
336 // Forget about the known mimetype if a target URL is used.
337 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
338 if (item.targetUrl() == item.url()) {
339 args.setMimeType(item.mimetype());
340 }
341
342 // Ideally, konqueror should be changed to not require trustedSource for directory views,
343 // since the idea was not to need BrowserArguments for non-browser stuff...
344 KParts::BrowserArguments browserArgs;
345 browserArgs.trustedSource = true;
346 Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args, browserArgs);
347 }
348
349 void DolphinPart::slotItemsActivated(const KFileItemList &items)
350 {
351 for (const KFileItem &item : items) {
352 slotItemActivated(item);
353 }
354 }
355
356 void DolphinPart::createNewWindow(const QUrl &url)
357 {
358 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
359 // should be moved into DolphinPart::slotItemActivated()
360 Q_EMIT m_extension->createNewWindow(url);
361 }
362
363 void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
364 {
365 KParts::NavigationExtension::PopupFlags popupFlags =
366 KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
367
368 KFileItem item(_item);
369
370 if (item.isNull()) { // viewport context menu
371 item = m_view->rootItem();
372 if (item.isNull())
373 item = KFileItem(url());
374 else
375 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
376 }
377
378 KFileItemList items;
379 if (selectedItems.isEmpty()) {
380 items.append(item);
381 } else {
382 items = selectedItems;
383 }
384
385 KFileItemListProperties capabilities(items);
386
387 KParts::NavigationExtension::ActionGroupMap actionGroups;
388 QList<QAction *> editActions;
389 editActions += m_view->versionControlActions(m_view->selectedItems());
390
391 if (!_item.isNull()) { // only for context menu on one or more items
392 const bool supportsMoving = capabilities.supportsMoving();
393
394 if (capabilities.supportsDeleting()) {
395 const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
396 const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
397
398 if (showDeleteAction && showMoveToTrashAction) {
399 delete m_removeAction;
400 m_removeAction = nullptr;
401 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
402 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
403 } else if (showDeleteAction && !showMoveToTrashAction) {
404 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
405 } else {
406 if (!m_removeAction)
407 m_removeAction = new DolphinRemoveAction(this, actionCollection());
408 editActions.append(m_removeAction);
409 m_removeAction->update();
410 }
411 } else {
412 popupFlags |= KParts::NavigationExtension::NoDeletion;
413 }
414
415 if (supportsMoving) {
416 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
417 }
418
419 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
420 // since otherwise the created file would not be visible.
421 // But in treeview mode we should allow it.
422 if (m_view->itemsExpandable())
423 popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
424 }
425
426 actionGroups.insert(QStringLiteral("editactions"), editActions);
427
428 Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags, actionGroups);
429 }
430
431 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
432 {
433 qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
434 if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
435 KParts::ReadOnlyPart::setUrl(newUrl);
436 const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
437 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
438 }
439 }
440
441 void DolphinPart::slotEditMimeType()
442 {
443 const KFileItemList items = m_view->selectedItems();
444 if (!items.isEmpty()) {
445 KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
446 }
447 }
448
449 void DolphinPart::slotSelectItemsMatchingPattern()
450 {
451 openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
452 }
453
454 void DolphinPart::slotUnselectItemsMatchingPattern()
455 {
456 openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);
457 }
458
459 void DolphinPart::openSelectionDialog(const QString &title, const QString &text, bool selectItems)
460 {
461 auto *dialog = new QInputDialog(m_view);
462 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
463 dialog->setInputMode(QInputDialog::TextInput);
464 dialog->setWindowTitle(title);
465 dialog->setLabelText(text);
466
467 const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
468 dialog->setComboBoxEditable(true);
469 dialog->setComboBoxItems(group.readEntry("History", QStringList()));
470
471 dialog->setTextValue(QStringLiteral("*"));
472
473 connect(dialog, &QDialog::accepted, this, [=]() {
474 const QString pattern = dialog->textValue();
475 if (!pattern.isEmpty()) {
476 QStringList items = dialog->comboBoxItems();
477 items.removeAll(pattern);
478 items.prepend(pattern);
479
480 // Need to evaluate this again here, because the captured value is const
481 // (even if the const were removed from 'const KConfigGroup group =' above).
482 KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
483 // Limit the size of the saved history.
484 group.writeEntry("History", items.mid(0, 10));
485 group.sync();
486
487 const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
488 m_view->selectItems(patternRegExp, selectItems);
489 }
490 });
491
492 dialog->open();
493 }
494
495 void DolphinPart::setCurrentViewMode(const QString &viewModeName)
496 {
497 QAction *action = actionCollection()->action(viewModeName);
498 Q_ASSERT(action);
499 action->trigger();
500 }
501
502 QString DolphinPart::currentViewMode() const
503 {
504 return m_actionHandler->currentViewModeActionName();
505 }
506
507 void DolphinPart::setNameFilter(const QString &nameFilter)
508 {
509 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
510 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
511 m_nameFilter = nameFilter;
512 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
513 }
514
515 QString DolphinPart::localFilePathOrHome() const
516 {
517 const QString localPath = localFilePath();
518 if (!localPath.isEmpty()) {
519 return localPath;
520 }
521 return QDir::homePath();
522 }
523
524 void DolphinPart::slotOpenTerminal()
525 {
526 auto job = new KTerminalLauncherJob(QString());
527 job->setWorkingDirectory(localFilePathOrHome());
528 job->start();
529 }
530
531 void DolphinPart::slotFindFile()
532 {
533 QMenu searchTools;
534 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&searchTools, {"files-find"}, QUrl::fromLocalFile(localFilePathOrHome()));
535 QList<QAction *> actions = searchTools.actions();
536 if (!(actions.isEmpty())) {
537 actions.first()->trigger();
538 } else {
539 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
540 job->setDesktopName(QStringLiteral("org.kde.kfind"));
541 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
542 job->start();
543 }
544 }
545
546 void DolphinPart::updateNewMenu()
547 {
548 // As requested by KNewFileMenu :
549 m_newFileMenu->checkUpToDate();
550 // And set the files that the menu apply on :
551 m_newFileMenu->setWorkingDirectory(url());
552 }
553
554 void DolphinPart::updateStatusBar()
555 {
556 m_view->requestStatusBarText();
557 }
558
559 void DolphinPart::updateProgress(int percent)
560 {
561 Q_EMIT m_extension->loadingProgress(percent);
562 }
563
564 void DolphinPart::createDirectory()
565 {
566 m_newFileMenu->setWorkingDirectory(url());
567 m_newFileMenu->createDirectory();
568 }
569
570 void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
571 {
572 if (files.isEmpty()) {
573 return;
574 }
575
576 m_view->markUrlsAsSelected(files);
577 m_view->markUrlAsCurrent(files.at(0));
578 }
579
580 bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
581 {
582 using ShiftState = DolphinRemoveAction::ShiftState;
583 const int type = event->type();
584
585 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
586 QMenu *menu = qobject_cast<QMenu *>(obj);
587 if (menu && menu->parent() == m_view) {
588 QKeyEvent *ev = static_cast<QKeyEvent *>(event);
589 if (ev->key() == Qt::Key_Shift) {
590 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
591 }
592 }
593 }
594
595 return KParts::ReadOnlyPart::eventFilter(obj, event);
596 }
597
598 #include "dolphinpart.moc"
599 #include "moc_dolphinpart.cpp"