File indexing completed on 2025-01-19 03:51:17

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2018-07-30
0007  * Description : a plugin to acquire images with a digital scanner.
0008  *
0009  * SPDX-FileCopyrightText: 2018-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 "dscannerplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 #include <QMessageBox>
0021 #include <QString>
0022 #include <QApplication>
0023 
0024 // KDE includes
0025 
0026 #include <klocalizedstring.h>
0027 
0028 // Local includes
0029 
0030 #include "digikam_debug.h"
0031 #include "scandialog.h"
0032 
0033 namespace DigikamGenericDScannerPlugin
0034 {
0035 
0036 DigitalScannerPlugin::DigitalScannerPlugin(QObject* const parent)
0037     : DPluginGeneric(parent)
0038 {
0039 }
0040 
0041 DigitalScannerPlugin::~DigitalScannerPlugin()
0042 {
0043 }
0044 
0045 void DigitalScannerPlugin::cleanUp()
0046 {
0047     if (m_saneWidget)
0048     {
0049         delete m_saneWidget;
0050     }
0051 }
0052 
0053 QString DigitalScannerPlugin::name() const
0054 {
0055     return i18n("Digital Scanner");
0056 }
0057 
0058 QString DigitalScannerPlugin::iid() const
0059 {
0060     return QLatin1String(DPLUGIN_IID);
0061 }
0062 
0063 QIcon DigitalScannerPlugin::icon() const
0064 {
0065     return QIcon::fromTheme(QLatin1String("scanner"));
0066 }
0067 
0068 QString DigitalScannerPlugin::description() const
0069 {
0070     return i18n("A tool to acquire images with a digital scanner");
0071 }
0072 
0073 QString DigitalScannerPlugin::details() const
0074 {
0075     return i18n("<p>This tool allows users to acquire new images from a digital scanner.</p>"
0076                 "<p>Plenty of scanner devices are supported through the Sane library.</p>"
0077                 "<p>Target image can be post processed as crop and rotate.</p>");
0078 }
0079 
0080 QString DigitalScannerPlugin::handbookSection() const
0081 {
0082     return QLatin1String("import_tools");
0083 }
0084 
0085 QString DigitalScannerPlugin::handbookChapter() const
0086 {
0087     return QLatin1String("scanner_import");
0088 }
0089 
0090 QList<DPluginAuthor> DigitalScannerPlugin::authors() const
0091 {
0092     return QList<DPluginAuthor>()
0093             << DPluginAuthor(QString::fromUtf8("Kare Sars"),
0094                              QString::fromUtf8("kare dot sars at kolumbus dot fi"),
0095                              QString::fromUtf8("(C) 2003-2005"))
0096             << DPluginAuthor(QString::fromUtf8("Angelo Naselli"),
0097                              QString::fromUtf8("anaselli at linux dot it"),
0098                              QString::fromUtf8("(C) 2006-2007"))
0099             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0100                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0101                              QString::fromUtf8("(C) 2003-2022"))
0102             ;
0103 }
0104 
0105 void DigitalScannerPlugin::setup(QObject* const parent)
0106 {
0107     DPluginAction* const ac = new DPluginAction(parent);
0108     ac->setIcon(icon());
0109     ac->setText(i18nc("@action", "Import from Scanner..."));
0110     ac->setObjectName(QLatin1String("import_scan"));
0111     ac->setActionCategory(DPluginAction::GenericImport);
0112 
0113     connect(ac, &DPluginAction::triggered,
0114             this, &DigitalScannerPlugin::slotDigitalScanner);
0115 
0116     addAction(ac);
0117 }
0118 
0119 void DigitalScannerPlugin::slotDigitalScanner()
0120 {
0121     if (!m_saneWidget)
0122     {
0123         m_saneWidget = new KSaneIface::KSaneWidget(nullptr);
0124     }
0125 
0126     if (m_saneWidget)
0127     {
0128         QString dev = m_saneWidget->selectDevice(nullptr);
0129 
0130         if (dev.isEmpty())
0131         {
0132             QMessageBox::warning(nullptr, qApp->applicationName(), i18n("There is no scanner device available.\n"
0133                                                                         "Please check your configuration"));
0134             return;
0135         }
0136 
0137         if (!m_saneWidget->openDevice(dev))
0138         {
0139             // could not open a scanner
0140 
0141             QMessageBox::warning(nullptr, qApp->applicationName(), i18n("Cannot open scanner device \"%1\".\n"
0142                                                                         "Please check your configuration", dev));
0143             return;
0144         }
0145 
0146         DInfoInterface* const iface = infoIface(sender());
0147         ScanDialog* const dlg       = new ScanDialog(m_saneWidget);
0148 
0149         connect(dlg, &ScanDialog::signalImportedImage,
0150                 iface, &DInfoInterface::signalImportedImage);
0151 
0152         dlg->setTargetDir(iface->defaultUploadUrl().toLocalFile());
0153         dlg->setPlugin(this);
0154         dlg->show();
0155     }
0156 }
0157 
0158 } // namespace DigikamGenericDScannerPlugin
0159 
0160 #include "moc_dscannerplugin.cpp"