Changeset View
Changeset View
Standalone View
Standalone View
src/dolphincontextmenu.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | #include <KToolBar> | 49 | #include <KToolBar> | ||
50 | 50 | | |||
51 | #include <QApplication> | 51 | #include <QApplication> | ||
52 | #include <QClipboard> | 52 | #include <QClipboard> | ||
53 | #include <QKeyEvent> | 53 | #include <QKeyEvent> | ||
54 | #include <QMenu> | 54 | #include <QMenu> | ||
55 | #include <QMenuBar> | 55 | #include <QMenuBar> | ||
56 | #include <QMimeDatabase> | 56 | #include <QMimeDatabase> | ||
57 | #include <PurposeWidgets/Menu> | ||||
58 | #include <Purpose/AlternativesModel> | ||||
59 | #include <QJsonArray> | ||||
60 | #include <QJsonValue> | ||||
57 | 61 | | |||
58 | DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, | 62 | DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, | ||
59 | const QPoint& pos, | 63 | const QPoint& pos, | ||
60 | const KFileItem& fileInfo, | 64 | const KFileItem& fileInfo, | ||
61 | const QUrl& baseUrl) : | 65 | const QUrl& baseUrl) : | ||
62 | QMenu(parent), | 66 | QMenu(parent), | ||
63 | m_pos(pos), | 67 | m_pos(pos), | ||
64 | m_mainWindow(parent), | 68 | m_mainWindow(parent), | ||
65 | m_fileInfo(fileInfo), | 69 | m_fileInfo(fileInfo), | ||
66 | m_baseUrl(baseUrl), | 70 | m_baseUrl(baseUrl), | ||
67 | m_baseFileItem(nullptr), | 71 | m_baseFileItem(nullptr), | ||
68 | m_selectedItems(), | 72 | m_selectedItems(), | ||
69 | m_selectedItemsProperties(nullptr), | 73 | m_selectedItemsProperties(nullptr), | ||
70 | m_context(NoContext), | 74 | m_context(NoContext), | ||
71 | m_copyToMenu(parent), | 75 | m_copyToMenu(parent), | ||
72 | m_customActions(), | 76 | m_customActions(), | ||
73 | m_command(None), | 77 | m_command(None), | ||
74 | m_removeAction(nullptr) | 78 | m_removeAction(nullptr), | ||
79 | m_shareMenu(new Purpose::Menu()) | ||||
75 | { | 80 | { | ||
76 | // The context menu either accesses the URLs of the selected items | 81 | // The context menu either accesses the URLs of the selected items | ||
77 | // or the items itself. To increase the performance both lists are cached. | 82 | // or the items itself. To increase the performance both lists are cached. | ||
78 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | 83 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | ||
79 | m_selectedItems = view->selectedItems(); | 84 | m_selectedItems = view->selectedItems(); | ||
85 | | ||||
86 | m_shareMenu->setTitle(i18n("Share")); | ||||
87 | m_shareMenu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); | ||||
88 | m_shareMenu->model()->setPluginType(QStringLiteral("Export")); | ||||
80 | } | 89 | } | ||
81 | 90 | | |||
82 | DolphinContextMenu::~DolphinContextMenu() | 91 | DolphinContextMenu::~DolphinContextMenu() | ||
83 | { | 92 | { | ||
84 | delete m_selectedItemsProperties; | 93 | delete m_selectedItemsProperties; | ||
85 | m_selectedItemsProperties = nullptr; | 94 | m_selectedItemsProperties = nullptr; | ||
86 | } | 95 | } | ||
87 | 96 | | |||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 195 | { | |||
299 | // insert 'Copy To' and 'Move To' sub menus | 308 | // insert 'Copy To' and 'Move To' sub menus | ||
300 | if (GeneralSettings::showCopyMoveMenu()) { | 309 | if (GeneralSettings::showCopyMoveMenu()) { | ||
301 | m_copyToMenu.setUrls(m_selectedItems.urlList()); | 310 | m_copyToMenu.setUrls(m_selectedItems.urlList()); | ||
302 | m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); | 311 | m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); | ||
303 | m_copyToMenu.setAutoErrorHandlingEnabled(true); | 312 | m_copyToMenu.setAutoErrorHandlingEnabled(true); | ||
304 | m_copyToMenu.addActionsTo(this); | 313 | m_copyToMenu.addActionsTo(this); | ||
305 | } | 314 | } | ||
306 | 315 | | |||
316 | QJsonArray urlsJson; | ||||
317 | | ||||
318 | for (QUrl url : m_selectedItems.targetUrlList()) { | ||||
apol: const QUrl &? | |||||
319 | urlsJson.append(url.toString()); | ||||
320 | } | ||||
321 | | ||||
322 | m_shareMenu->model()->setInputData(QJsonObject{ | ||||
323 | { QStringLiteral("mimeType"), QJsonValue{QStringLiteral("*/*")} }, | ||||
324 | { QStringLiteral("urls"), urlsJson } | ||||
325 | }); | ||||
326 | m_shareMenu->reload(); | ||||
327 | addMenu(m_shareMenu); | ||||
328 | | ||||
307 | // insert 'Properties...' entry | 329 | // insert 'Properties...' entry | ||
308 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | 330 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | ||
309 | addAction(propertiesAction); | 331 | addAction(propertiesAction); | ||
310 | 332 | | |||
311 | QAction* activatedAction = exec(m_pos); | 333 | QAction* activatedAction = exec(m_pos); | ||
312 | if (activatedAction) { | 334 | if (activatedAction) { | ||
313 | if (activatedAction == addToPlacesAction) { | 335 | if (activatedAction == addToPlacesAction) { | ||
314 | const QUrl selectedUrl(m_fileInfo.url()); | 336 | const QUrl selectedUrl(m_fileInfo.url()); | ||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |
const QUrl &?