File indexing completed on 2025-01-19 03:50:38
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-02-15 0007 * Description : contextmenu helper class - Tools methods. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "contextmenuhelper_p.h" 0017 0018 namespace Digikam 0019 { 0020 0021 void ContextMenuHelper::addOpenAndNavigateActions(const imageIds& ids, bool lightTable) 0022 { 0023 if (lightTable) 0024 { 0025 setSelectedIds(ids); 0026 QAction* const openImageFile = new QAction(QIcon::fromTheme(QLatin1String("quickopen-file")), 0027 i18nc("@action: file open dialog", "Open..."), this); 0028 addAction(openImageFile); 0029 0030 connect(openImageFile, SIGNAL(triggered()), 0031 this, SLOT(slotOpenImageFile())); 0032 } 0033 else 0034 { 0035 addAction(QLatin1String("image_edit")); 0036 addAction(QLatin1String("move_selection_to_album")); 0037 addAction(QLatin1String("copy_selection_to")); 0038 } 0039 0040 addServicesMenu(ItemInfoList(ids).toImageUrlList()); 0041 0042 // addServicesMenu() has stored d->selectedItems 0043 0044 if (!d->selectedItems.isEmpty()) 0045 { 0046 QAction* const openFileMngr = new QAction(QIcon::fromTheme(QLatin1String("folder-open")), 0047 i18nc("@action: context menu", "Open in File Manager"), this); 0048 addAction(openFileMngr); 0049 0050 connect(openFileMngr, SIGNAL(triggered()), 0051 this, SLOT(slotOpenInFileManager())); 0052 } 0053 0054 if (!lightTable) 0055 { 0056 addGotoMenu(ids); 0057 } 0058 } 0059 0060 void ContextMenuHelper::slotOpenImageFile() 0061 { 0062 if (d->selectedIds.isEmpty()) 0063 { 0064 return; 0065 } 0066 0067 ItemInfoList infos = ItemInfoList(d->selectedIds); 0068 ItemViewUtilities(d->parent).openInfos(infos.first(), infos, nullptr); 0069 } 0070 0071 void ContextMenuHelper::addImportMenu() 0072 { 0073 QMenu* const menuImport = new QMenu(i18nc("@action: context menu", "Import"), d->parent); 0074 KXMLGUIClient* const client = const_cast<KXMLGUIClient*>(d->stdActionCollection->parentGUIClient()); 0075 QList<DPluginAction*> actions = DPluginLoader::instance()->pluginsActions(DPluginAction::GenericImport, 0076 dynamic_cast<KXmlGuiWindow*>(client)); 0077 0078 if (!actions.isEmpty()) 0079 { 0080 Q_FOREACH (DPluginAction* const ac, actions) 0081 { 0082 menuImport->addActions(QList<QAction*>() << ac); 0083 } 0084 } 0085 else 0086 { 0087 QAction* const notools = new QAction(i18nc("@action: context menu", "No import tool available"), this); 0088 notools->setEnabled(false); 0089 menuImport->addAction(notools); 0090 } 0091 0092 d->parent->addMenu(menuImport); 0093 } 0094 0095 void ContextMenuHelper::addExportMenu() 0096 { 0097 QMenu* const menuExport = new QMenu(i18nc("@action: context menu", "Export"), d->parent); 0098 const QList<DPluginAction*>& actions = d->exportPluginActions(); 0099 0100 #if 0 0101 0102 QAction* selectAllAction = nullptr; 0103 selectAllAction = d->stdActionCollection->action("selectAll"); 0104 0105 #endif 0106 0107 if (!actions.isEmpty()) 0108 { 0109 Q_FOREACH (DPluginAction* const ac, actions) 0110 { 0111 ac->setData((int)DPluginAction::AlbumData); 0112 menuExport->addActions(QList<QAction*>() << ac); 0113 } 0114 } 0115 else 0116 { 0117 QAction* const notools = new QAction(i18nc("@action: context menu", "No export tool available"), this); 0118 notools->setEnabled(false); 0119 menuExport->addAction(notools); 0120 } 0121 0122 d->parent->addMenu(menuExport); 0123 } 0124 0125 void ContextMenuHelper::addQueueManagerMenu() 0126 { 0127 QMenu* const bqmMenu = new QMenu(i18nc("@action: context menu", "Batch Queue Manager"), d->parent); 0128 bqmMenu->menuAction()->setIcon(QIcon::fromTheme(QLatin1String("run-build"))); 0129 bqmMenu->addAction(d->stdActionCollection->action(QLatin1String("image_add_to_current_queue"))); 0130 bqmMenu->addAction(d->stdActionCollection->action(QLatin1String("image_add_to_new_queue"))); 0131 0132 // if queue list is empty, do not display the queue submenu 0133 0134 if (QueueMgrWindow::queueManagerWindowCreated() && 0135 !QueueMgrWindow::queueManagerWindow()->queuesMap().isEmpty()) 0136 { 0137 QueueMgrWindow* const qmw = QueueMgrWindow::queueManagerWindow(); 0138 QMenu* const queueMenu = new QMenu(i18nc("@action: context menu", "Add to Existing Queue"), bqmMenu); 0139 0140 // queueActions is used by the exec() method to Q_EMIT an appropriate signal. 0141 // Reset the map before filling in the actions. 0142 0143 if (!d->queueActions.isEmpty()) 0144 { 0145 d->queueActions.clear(); 0146 } 0147 0148 QList<QAction*> queueList; 0149 0150 // get queue list from BQM window, do not access it directly, it might crash 0151 // when the list is changed 0152 0153 QMap<int, QString> qmwMap = qmw->queuesMap(); 0154 0155 for (QMap<int, QString>::const_iterator it = qmwMap.constBegin() ; 0156 it != qmwMap.constEnd() ; ++it) 0157 { 0158 QAction* const action = new QAction(it.value(), this); 0159 queueList << action; 0160 d->queueActions[it.key()] = action; 0161 } 0162 0163 queueMenu->addActions(queueList); 0164 bqmMenu->addMenu(queueMenu); 0165 } 0166 0167 d->parent->addMenu(bqmMenu); 0168 0169 // NOTE: see bug #252130 : we need to disable new items to add on BQM is this one is running. 0170 0171 bqmMenu->setDisabled(QueueMgrWindow::queueManagerWindow()->isBusy()); 0172 } 0173 0174 } // namespace Digikam