File indexing completed on 2025-01-05 03:59:46

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-12-21
0007  * Description : abstract camera interface class
0008  *
0009  * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006-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 "dkcamera.h"
0017 
0018 // Local includes
0019 
0020 #include "applicationsettings.h"
0021 #include "dmetadata.h"
0022 #include "digikam_debug.h"
0023 
0024 namespace Digikam
0025 {
0026 
0027 DKCamera::DKCamera(const QString& title, const QString& model, const QString& port, const QString& path)
0028     : QObject                       (),
0029       m_thumbnailSupport            (false),
0030       m_deleteSupport               (false),
0031       m_uploadSupport               (false),
0032       m_mkDirSupport                (false),
0033       m_delDirSupport               (false),
0034       m_captureImageSupport         (false),
0035       m_captureImagePreviewSupport  (false),
0036       m_model                       (model),
0037       m_port                        (port),
0038       m_path                        (path),
0039       m_title                       (title)
0040 {
0041     ApplicationSettings* const settings = ApplicationSettings::instance();
0042     m_imageFilter                       = settings->getImageFileFilter();
0043     m_movieFilter                       = settings->getMovieFileFilter();
0044     m_audioFilter                       = settings->getAudioFileFilter();
0045     m_rawFilter                         = settings->getRawFileFilter();
0046     m_imageFilter                       = m_imageFilter.toLower();
0047     m_movieFilter                       = m_movieFilter.toLower();
0048     m_audioFilter                       = m_audioFilter.toLower();
0049     m_rawFilter                         = m_rawFilter.toLower();
0050 }
0051 
0052 DKCamera::~DKCamera()
0053 {
0054 }
0055 
0056 QString DKCamera::title() const
0057 {
0058     return m_title;
0059 }
0060 
0061 QString DKCamera::model() const
0062 {
0063     return m_model;
0064 }
0065 
0066 QString DKCamera::port() const
0067 {
0068     return m_port;
0069 }
0070 
0071 QString DKCamera::path() const
0072 {
0073     return m_path;
0074 }
0075 
0076 QString DKCamera::uuid() const
0077 {
0078     return m_uuid;
0079 }
0080 
0081 bool DKCamera::thumbnailSupport() const
0082 {
0083     return m_thumbnailSupport;
0084 }
0085 
0086 bool DKCamera::deleteSupport() const
0087 {
0088     return m_deleteSupport;
0089 }
0090 
0091 bool DKCamera::uploadSupport() const
0092 {
0093     return m_uploadSupport;
0094 }
0095 
0096 bool DKCamera::mkDirSupport() const
0097 {
0098     return m_mkDirSupport;
0099 }
0100 
0101 bool DKCamera::delDirSupport() const
0102 {
0103     return m_delDirSupport;
0104 }
0105 
0106 bool DKCamera::captureImageSupport() const
0107 {
0108     return m_captureImageSupport;
0109 }
0110 
0111 bool DKCamera::captureImagePreviewSupport() const
0112 {
0113     return m_captureImagePreviewSupport;
0114 }
0115 
0116 QString DKCamera::mimeType(const QString& fileext) const
0117 {
0118     if (fileext.isEmpty())
0119     {
0120         return QString();
0121     }
0122 
0123     QString ext = fileext;
0124     QString mime;
0125 
0126     // Massage known variations of known mimetypes
0127 
0128     if      ((ext == QLatin1String("jpg")) || (ext == QLatin1String("jpe")))
0129     {
0130         ext = QLatin1String("jpeg");
0131     }
0132     else if (ext == QLatin1String("tif"))
0133     {
0134         ext = QLatin1String("tiff");
0135     }
0136 
0137     if      (m_rawFilter.contains(ext))
0138     {
0139         mime = QLatin1String("image/x-raw");
0140     }
0141     else if (m_imageFilter.contains(ext))
0142     {
0143         mime = QLatin1String("image/") + ext;
0144     }
0145     else if (m_movieFilter.contains(ext))
0146     {
0147         mime = QLatin1String("video/") + ext;
0148     }
0149     else if (m_audioFilter.contains(ext))
0150     {
0151         mime = QLatin1String("audio/") + ext;
0152     }
0153 
0154     return mime;
0155 }
0156 
0157 void DKCamera::fillItemInfoFromMetadata(CamItemInfo& info, const DMetadata& meta) const
0158 {
0159     QSize dims     = meta.getItemDimensions();
0160     info.ctime     = meta.getItemDateTime();
0161 
0162     // NOTE: see bug #246401 to sort based on milliseconds for items taken quickly.
0163 
0164     if (!info.ctime.isNull())
0165     {
0166         info.ctime.setTime(info.ctime.time().addMSecs(meta.getMSecsInfo()));
0167     }
0168 
0169     info.width     = dims.width();
0170     info.height    = dims.height();
0171     info.photoInfo = meta.getPhotographInformation();
0172 }
0173 
0174 void DKCamera::printSupportedFeatures()
0175 {
0176     qCDebug(DIGIKAM_IMPORTUI_LOG) << "Supported features for" << title();
0177     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Thumbnails:" << thumbnailSupport();
0178     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Delete:" << deleteSupport();
0179     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Delete dir:" << delDirSupport();
0180     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Upload:" << uploadSupport();
0181     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Mkdir:" << mkDirSupport();
0182     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Image capture:" << captureImageSupport();
0183     qCDebug(DIGIKAM_IMPORTUI_LOG) << "  Image capture preview (liveview):" << captureImagePreviewSupport();
0184 }
0185 
0186 } // namespace Digikam
0187 
0188 #include "moc_dkcamera.cpp"