File indexing completed on 2025-01-05 03:51:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2002-16-10 0007 * Description : main digiKam interface implementation - Camera management 0008 * 0009 * SPDX-FileCopyrightText: 2002-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "digikamapp_p.h" 0016 0017 namespace Digikam 0018 { 0019 0020 void DigikamApp::autoDetect() 0021 { 0022 // Called from main if command line option is set, or via DBus 0023 0024 if (d->splashScreen) 0025 { 0026 d->splashScreen->setMessage(i18n("Auto-Detecting Camera...")); 0027 } 0028 0029 QTimer::singleShot(0, this, SLOT(slotCameraAutoDetect())); 0030 } 0031 0032 void DigikamApp::downloadFrom(const QString& cameraGuiPath) 0033 { 0034 // Called from main if command line option is set, or via DBus 0035 0036 if (!cameraGuiPath.isEmpty()) 0037 { 0038 if (d->splashScreen) 0039 { 0040 d->splashScreen->setMessage(i18n("Opening Download Dialog...")); 0041 } 0042 0043 Q_EMIT queuedOpenCameraUiFromPath(cameraGuiPath); 0044 } 0045 } 0046 0047 void DigikamApp::downloadFromUdi(const QString& udi) 0048 { 0049 // Called from main if command line option is set, or via DBus 0050 0051 if (!udi.isEmpty()) 0052 { 0053 if (d->splashScreen) 0054 { 0055 d->splashScreen->setMessage(i18n("Opening Download Dialog...")); 0056 } 0057 0058 Q_EMIT queuedOpenSolidDevice(udi); 0059 } 0060 } 0061 0062 void DigikamApp::loadCameras() 0063 { 0064 KActionCollection* const ac = actionCollection(); 0065 0066 d->cameraMenu->setTitle(i18n("Cameras")); 0067 d->cameraMenu->setIcon(QIcon::fromTheme(QLatin1String("camera-photo"))); 0068 d->usbMediaMenu->setTitle(i18n("USB Storage Devices")); 0069 d->usbMediaMenu->setIcon(QIcon::fromTheme(QLatin1String("drive-removable-media"))); 0070 d->cardReaderMenu->setTitle(i18n("Card Readers")); 0071 d->cardReaderMenu->setIcon(QIcon::fromTheme(QLatin1String("media-flash-sd-mmc"))); 0072 0073 ac->addAction(QLatin1String("cameras"), d->cameraMenu->menuAction()); 0074 ac->addAction(QLatin1String("usb_media"), d->usbMediaMenu->menuAction()); 0075 ac->addAction(QLatin1String("card_reader"), d->cardReaderMenu->menuAction()); 0076 0077 // ----------------------------------------------------------------- 0078 0079 d->addImagesAction = new QAction(QIcon::fromTheme(QLatin1String("document-import")), i18n("Add Images..."), this); 0080 d->addImagesAction->setWhatsThis(i18n("Adds new items to an Album.")); 0081 connect(d->addImagesAction, SIGNAL(triggered()), this, SLOT(slotImportAddImages())); 0082 ac->addAction(QLatin1String("import_addImages"), d->addImagesAction); 0083 ac->setDefaultShortcut(d->addImagesAction, Qt::ALT | Qt::SHIFT | Qt::Key_I); 0084 0085 // ----------------------------------------------------------------- 0086 0087 d->addFoldersAction = new QAction(QIcon::fromTheme(QLatin1String("folder-new")), i18n("Add Folders..."), this); 0088 d->addFoldersAction->setWhatsThis(i18n("Adds new folders to Album library.")); 0089 connect(d->addFoldersAction, SIGNAL(triggered()), this, SLOT(slotImportAddFolders())); 0090 ac->addAction(QLatin1String("import_addFolders"), d->addFoldersAction); 0091 0092 // -- fill manually added cameras ---------------------------------- 0093 0094 d->cameraList->load(); 0095 0096 // -- scan Solid devices ------------------------------------------- 0097 0098 fillSolidMenus(); 0099 0100 connectToSolidNotifiers(); 0101 } 0102 0103 void DigikamApp::updateCameraMenu() 0104 { 0105 d->cameraMenu->clear(); 0106 0107 Q_FOREACH (QAction* const action, d->solidCameraActionGroup->actions()) 0108 { 0109 d->cameraMenu->addAction(action); 0110 } 0111 0112 d->cameraMenu->addSeparator(); 0113 0114 Q_FOREACH (QAction* const action, d->manualCameraActionGroup->actions()) 0115 { 0116 // remove duplicate entries, prefer manually added cameras 0117 0118 Q_FOREACH (QAction* const actionSolid, d->solidCameraActionGroup->actions()) 0119 { 0120 if (CameraNameHelper::sameDevices(actionSolid->iconText(), action->iconText())) 0121 { 0122 d->cameraMenu->removeAction(actionSolid); 0123 d->solidCameraActionGroup->removeAction(actionSolid); 0124 } 0125 } 0126 0127 d->cameraMenu->addAction(action); 0128 } 0129 0130 d->cameraMenu->addSeparator(); 0131 d->cameraMenu->addAction(actionCollection()->action(QLatin1String("camera_add"))); 0132 } 0133 0134 void DigikamApp::slotSetupCamera() 0135 { 0136 Setup::execSinglePage(this, Setup::CameraPage); 0137 } 0138 0139 void DigikamApp::slotOpenManualCamera(QAction* action) 0140 { 0141 CameraType* const ctype = d->cameraList->find(action->data().toString()); 0142 0143 if (ctype) 0144 { 0145 // check not to open two dialogs for the same camera 0146 0147 if (ctype->currentImportUI() && !ctype->currentImportUI()->isClosed()) 0148 { 0149 // show and raise dialog 0150 0151 ctype->currentImportUI()->unminimizeAndActivateWindow(); 0152 } 0153 else 0154 { 0155 // the ImportUI will delete itself when it has finished 0156 0157 ImportUI* const cgui = new ImportUI(ctype->title(), ctype->model(), 0158 ctype->port(), ctype->path(), ctype->startingNumber()); 0159 0160 ctype->setCurrentImportUI(cgui); 0161 0162 cgui->show(); 0163 0164 connect(cgui, SIGNAL(signalLastDestination(QUrl)), 0165 d->view, SLOT(slotSelectAlbum(QUrl))); 0166 } 0167 } 0168 } 0169 0170 void DigikamApp::slotCameraAdded(CameraType* ctype) 0171 { 0172 if (!ctype) 0173 { 0174 return; 0175 } 0176 0177 QAction* const cAction = new QAction(QIcon::fromTheme(QLatin1String("camera-photo")), 0178 ctype->title(), d->manualCameraActionGroup); 0179 cAction->setData(ctype->title()); 0180 actionCollection()->addAction(ctype->title(), cAction); 0181 0182 ctype->setAction(cAction); 0183 updateCameraMenu(); 0184 updateQuickImportAction(); 0185 } 0186 0187 void DigikamApp::slotCameraRemoved(QAction* cAction) 0188 { 0189 if (cAction) 0190 { 0191 d->manualCameraActionGroup->removeAction(cAction); 0192 } 0193 0194 updateCameraMenu(); 0195 updateQuickImportAction(); 0196 } 0197 0198 void DigikamApp::slotCameraAutoDetect() 0199 { 0200 bool retry = false; 0201 CameraType* const ctype = d->cameraList->autoDetect(retry); 0202 0203 if (!ctype && retry) 0204 { 0205 QTimer::singleShot(0, this, SLOT(slotCameraAutoDetect())); 0206 return; 0207 } 0208 0209 if (ctype && ctype->action()) 0210 { 0211 ctype->action()->activate(QAction::Trigger); 0212 } 0213 } 0214 0215 void DigikamApp::slotOpenCameraUiFromPath(const QString& path) 0216 { 0217 if (path.isEmpty()) 0218 { 0219 return; 0220 } 0221 0222 // the ImportUI will delete itself when it has finished 0223 0224 ImportUI* const cgui = new ImportUI(i18n("Images found in %1", path), 0225 QLatin1String("directory browse"), 0226 QLatin1String("Fixed"), path, 1); 0227 cgui->show(); 0228 0229 connect(cgui, SIGNAL(signalLastDestination(QUrl)), 0230 d->view, SLOT(slotSelectAlbum(QUrl))); 0231 } 0232 0233 void DigikamApp::downloadImages(const QString& folder) 0234 { 0235 if (!folder.isNull()) 0236 { 0237 // activate window when called by media menu and DCOP 0238 0239 unminimizeAndActivateWindow(); 0240 0241 Q_EMIT queuedOpenCameraUiFromPath(folder); 0242 } 0243 } 0244 0245 void DigikamApp::cameraAutoDetect() 0246 { 0247 // activate window when called by media menu and DCOP 0248 0249 unminimizeAndActivateWindow(); 0250 0251 slotCameraAutoDetect(); 0252 } 0253 0254 } // namespace Digikam