File indexing completed on 2025-01-19 03:50:42

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 - Extra tools
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::setupSelectToolsAction()
0021 {
0022     // Create action model
0023 
0024     ActionItemModel* const actionModel = new ActionItemModel(this);
0025     actionModel->setMode(ActionItemModel::ToplevelMenuCategory | ActionItemModel::SortCategoriesByInsertionOrder);
0026 
0027     // Builtin actions
0028 
0029     QString mainCategory   = i18nc("@title Main Tools",            "Main Tools");
0030     actionModel->addAction(d->ieAction,                   mainCategory);
0031     actionModel->addAction(d->openTagMngrAction,          mainCategory);
0032     actionModel->addAction(d->bqmAction,                  mainCategory);
0033     actionModel->addAction(d->maintenanceAction,          mainCategory);
0034     actionModel->addAction(d->scanNewItemsAction,         mainCategory);
0035     actionModel->addAction(d->ltAction,                   mainCategory);
0036     actionModel->addAction(d->advSearchAction,            mainCategory);
0037 
0038     QString postCategory   = i18nc("@title Post Processing Tools", "Post-Processing");
0039 
0040     Q_FOREACH (DPluginAction* const ac, DPluginLoader::instance()->pluginsActions(DPluginAction::GenericTool, this))
0041     {
0042         actionModel->addAction(ac, postCategory);
0043     }
0044 
0045     Q_FOREACH (DPluginAction* const ac, DPluginLoader::instance()->pluginsActions(DPluginAction::GenericMetadata, this))
0046     {
0047         actionModel->addAction(ac, postCategory);
0048     }
0049 
0050     QString exportCategory = i18nc("@title Export Tools",          "Export");
0051 
0052     Q_FOREACH (DPluginAction* const ac, DPluginLoader::instance()->pluginsActions(DPluginAction::GenericExport, this))
0053     {
0054         actionModel->addAction(ac, exportCategory);
0055     }
0056 
0057     QString importCategory = i18nc("@title Import Tools",          "Import");
0058 
0059     Q_FOREACH (DPluginAction* const ac, DPluginLoader::instance()->pluginsActions(DPluginAction::GenericImport, this))
0060     {
0061         actionModel->addAction(ac, importCategory);
0062     }
0063 
0064     // setup categorized view
0065 
0066     DCategorizedSortFilterProxyModel* const filterModel = actionModel->createFilterModel();
0067 
0068     ActionCategorizedView* const selectToolsActionView  = new ActionCategorizedView;
0069     selectToolsActionView->setIconSize(QSize(22, 22));
0070     selectToolsActionView->setModel(filterModel);
0071     selectToolsActionView->setupIconMode();
0072     selectToolsActionView->adjustGridSize();
0073 
0074     connect(selectToolsActionView, SIGNAL(clicked(QModelIndex)),
0075             actionModel, SLOT(trigger(QModelIndex)));
0076 
0077     d->view->setToolsIconView(selectToolsActionView);
0078 }
0079 
0080 void DigikamApp::slotMaintenance()
0081 {
0082     QPointer<MaintenanceDlg> dlg = new MaintenanceDlg(this);
0083 
0084     if (dlg->exec() == QDialog::Accepted)
0085     {
0086         d->maintenanceAction->setEnabled(false);
0087         d->scanNewItemsAction->setEnabled(false);
0088 
0089         MaintenanceMngr* const mngr = new MaintenanceMngr(this);
0090 
0091         connect(mngr, SIGNAL(signalComplete()),
0092                 this, SLOT(slotMaintenanceDone()));
0093 
0094         connect(mngr, SIGNAL(signalComplete()),
0095                 mngr, SLOT(deleteLater()));
0096 
0097         mngr->setSettings(dlg->settings());
0098     }
0099 
0100     delete dlg;
0101 }
0102 
0103 void DigikamApp::slotScanNewItems()
0104 {
0105     d->maintenanceAction->setEnabled(false);
0106     d->scanNewItemsAction->setEnabled(false);
0107 
0108     NewItemsFinder* const tool = new NewItemsFinder(NewItemsFinder::ScanDeferredFiles);
0109 
0110     connect(tool, SIGNAL(signalComplete()),
0111             this, SLOT(slotMaintenanceDone()));
0112 
0113     connect(tool, SIGNAL(signalCanceled()),
0114             this, SLOT(slotMaintenanceDone()));
0115 
0116     if (ApplicationSettings::instance()->getDetectFacesInNewImages())
0117     {
0118         connect(tool, SIGNAL(signalComplete()),
0119                 this, SLOT(slotDetectFaces()));
0120     }
0121 
0122     tool->start();
0123 }
0124 
0125 void DigikamApp::slotMaintenanceDone()
0126 {
0127     d->maintenanceAction->setEnabled(true);
0128     d->scanNewItemsAction->setEnabled(true);
0129 
0130     d->view->refreshView();
0131 
0132     if (LightTableWindow::lightTableWindowCreated())
0133     {
0134         LightTableWindow::lightTableWindow()->refreshView();
0135     }
0136 
0137     if (QueueMgrWindow::queueManagerWindowCreated())
0138     {
0139         QueueMgrWindow::queueManagerWindow()->refreshView();
0140     }
0141 }
0142 
0143 void DigikamApp::slotDetectFaces()
0144 {
0145     ItemInfoList newImages(ScanController::instance()->getNewIdsList());
0146 
0147     if (newImages.isEmpty())
0148     {
0149         return;
0150     }
0151 
0152     FaceScanSettings settings;
0153 
0154     settings.accuracy               = ApplicationSettings::instance()->getFaceDetectionAccuracy();
0155     settings.useYoloV3              = ApplicationSettings::instance()->getFaceDetectionYoloV3();
0156     settings.task                   = FaceScanSettings::DetectAndRecognize;
0157     settings.alreadyScannedHandling = FaceScanSettings::Skip;
0158     settings.infos                  = newImages;
0159 
0160     FacesDetector* const tool       = new FacesDetector(settings);
0161     tool->start();
0162 }
0163 
0164 void DigikamApp::slotDatabaseMigration()
0165 {
0166     DatabaseMigrationDialog dlg(this);
0167     (void)dlg.exec();
0168 }
0169 
0170 } // namespace Digikam