File indexing completed on 2025-01-05 03:56:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-02-08
0007  * Description : item properties side bar used by import tool.
0008  *
0009  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2013      by Michael G. Hansen <mike at mghansen dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "importitempropertiessidebar.h"
0017 
0018 // Qt includes
0019 
0020 #include <QSplitter>
0021 #include <QIcon>
0022 
0023 // KDE includes
0024 
0025 #include <klocalizedstring.h>
0026 #include <kconfiggroup.h>
0027 
0028 // Local includes
0029 
0030 #include "digikam_config.h"
0031 #include "dmetadata.h"
0032 #include "camiteminfo.h"
0033 #include "importitempropertiestab.h"
0034 #include "itempropertiesmetadatatab.h"
0035 
0036 #ifdef HAVE_GEOLOCATION
0037 #   include "itempropertiesgpstab.h"
0038 #endif // HAVE_GEOLOCATION
0039 
0040 namespace Digikam
0041 {
0042 
0043 class Q_DECL_HIDDEN ImportItemPropertiesSideBarImport::Private
0044 {
0045 public:
0046 
0047     explicit Private()
0048       : dirtyMetadataTab    (false),
0049         dirtyCameraItemTab  (false),
0050         dirtyGpsTab         (false),
0051         metaData            (nullptr),
0052 
0053 #ifdef HAVE_GEOLOCATION
0054 
0055         gpsTab              (nullptr),
0056 
0057 #endif // HAVE_GEOLOCATION
0058 
0059         metadataTab         (nullptr),
0060         cameraItemTab       (nullptr)
0061     {
0062     }
0063 
0064     bool                       dirtyMetadataTab;
0065     bool                       dirtyCameraItemTab;
0066     bool                       dirtyGpsTab;
0067 
0068     DMetadata*                 metaData;
0069 
0070     CamItemInfo                itemInfo;
0071 
0072 #ifdef HAVE_GEOLOCATION
0073 
0074     ItemPropertiesGPSTab*      gpsTab;
0075 
0076 #endif // HAVE_GEOLOCATION
0077 
0078     ItemPropertiesMetadataTab* metadataTab;
0079     ImportItemPropertiesTab*   cameraItemTab;
0080 };
0081 
0082 ImportItemPropertiesSideBarImport::ImportItemPropertiesSideBarImport(QWidget* const parent,
0083                                                          SidebarSplitter* const splitter,
0084                                                          Qt::Edge side,
0085                                                          bool mimimizedDefault)
0086     : Sidebar(parent, splitter, side, mimimizedDefault),
0087       d      (new Private)
0088 {
0089     d->cameraItemTab = new ImportItemPropertiesTab(parent);
0090     d->metadataTab   = new ItemPropertiesMetadataTab(parent);
0091 
0092     appendTab(d->cameraItemTab, QIcon::fromTheme(QLatin1String("configure")),             i18n("Properties"));
0093     appendTab(d->metadataTab,   QIcon::fromTheme(QLatin1String("format-text-code")),              i18n("Metadata")); // krazy:exclude=iconnames
0094 
0095 #ifdef HAVE_GEOLOCATION
0096 
0097     d->gpsTab        = new ItemPropertiesGPSTab(parent);
0098     appendTab(d->gpsTab,        QIcon::fromTheme(QLatin1String("globe")), i18n("Geolocation"));
0099 
0100 #endif // HAVE_GEOLOCATION
0101 
0102     // --- NOTE: use dynamic binding as slotChangedTab() is a virtual method which can be re-implemented in derived classes.
0103 
0104     connect(this, &ImportItemPropertiesSideBarImport::signalChangedTab,
0105             this, &ImportItemPropertiesSideBarImport::slotChangedTab);
0106 }
0107 
0108 ImportItemPropertiesSideBarImport::~ImportItemPropertiesSideBarImport()
0109 {
0110     delete d;
0111 }
0112 
0113 void ImportItemPropertiesSideBarImport::applySettings()
0114 {
0115     /// @todo Still needed?
0116 
0117     /// @todo Are load/saveState called by the creator?
0118 }
0119 
0120 QUrl ImportItemPropertiesSideBarImport::url() const
0121 {
0122     return d->itemInfo.url();
0123 }
0124 
0125 void ImportItemPropertiesSideBarImport::itemChanged(const CamItemInfo& itemInfo, const DMetadata& meta)
0126 {
0127     if (itemInfo.isNull())
0128     {
0129         return;
0130     }
0131 
0132     if (d->metaData)
0133     {
0134         delete d->metaData;
0135     }
0136 
0137     d->metaData           = new DMetadata(meta.data());
0138     d->itemInfo           = itemInfo;
0139     d->dirtyMetadataTab   = false;
0140     d->dirtyCameraItemTab = false;
0141     d->dirtyGpsTab        = false;
0142 
0143     slotChangedTab(getActiveTab());
0144 }
0145 
0146 void ImportItemPropertiesSideBarImport::slotNoCurrentItem()
0147 {
0148     d->itemInfo           = CamItemInfo();
0149 
0150     if (d->metaData)
0151     {
0152         delete d->metaData;
0153         d->metaData = nullptr;
0154     }
0155 
0156     d->dirtyMetadataTab   = false;
0157     d->dirtyCameraItemTab = false;
0158     d->dirtyGpsTab        = false;
0159 
0160     d->cameraItemTab->setCurrentItem();
0161     d->metadataTab->setCurrentURL();
0162 
0163 #ifdef HAVE_GEOLOCATION
0164 
0165     d->gpsTab->setCurrentURL();
0166 
0167 #endif // HAVE_GEOLOCATION
0168 
0169 }
0170 
0171 void ImportItemPropertiesSideBarImport::slotChangedTab(QWidget* tab)
0172 {
0173     if (d->itemInfo.isNull())
0174     {
0175         return;
0176     }
0177 
0178     setCursor(Qt::WaitCursor);
0179 
0180     if      ((tab == d->cameraItemTab) && !d->dirtyCameraItemTab)
0181     {
0182         d->cameraItemTab->setCurrentItem(d->itemInfo, d->metaData);
0183 
0184         d->dirtyCameraItemTab = true;
0185     }
0186     else if ((tab == d->metadataTab) && !d->dirtyMetadataTab)
0187     {
0188         d->metadataTab->setCurrentData(d->metaData, d->itemInfo.url());
0189         d->dirtyMetadataTab = true;
0190     }
0191 
0192 #ifdef HAVE_GEOLOCATION
0193 
0194     else if ((tab == d->gpsTab) && !d->dirtyGpsTab)
0195     {
0196         d->gpsTab->setMetadata(d->metaData, d->itemInfo.url());
0197         d->dirtyGpsTab = true;
0198     }
0199 
0200     d->gpsTab->setActive(tab == d->gpsTab);
0201 
0202 #endif // HAVE_GEOLOCATION
0203 
0204     unsetCursor();
0205 }
0206 
0207 void ImportItemPropertiesSideBarImport::doLoadState()
0208 {
0209     /// @todo This code is taken from ItemPropertiesSideBar::doLoadState()
0210     ///       Ideally ImportItemPropertiesSideBarImport should be a subclass of
0211     ///       ItemPropertiesSideBar
0212 
0213     Sidebar::doLoadState();
0214 
0215     KConfigGroup group                  = getConfigGroup();
0216 
0217     KConfigGroup groupCameraItemTab     = KConfigGroup(&group, entryName(QLatin1String("Camera Item Properties Tab")));
0218     d->cameraItemTab->readSettings(groupCameraItemTab);
0219 
0220 #ifdef HAVE_GEOLOCATION
0221 
0222     KConfigGroup groupGPSTab            = KConfigGroup(&group, entryName(QLatin1String("GPS Properties Tab")));
0223     d->gpsTab->readSettings(groupGPSTab);
0224 
0225 #endif // HAVE_GEOLOCATION
0226 
0227     const KConfigGroup groupMetadataTab = KConfigGroup(&group, entryName(QLatin1String("Metadata Properties Tab")));
0228     d->metadataTab->readSettings(groupMetadataTab);
0229 }
0230 
0231 void ImportItemPropertiesSideBarImport::doSaveState()
0232 {
0233     /// @todo This code is taken from ItemPropertiesSideBar::doSaveState()
0234     ///       Ideally ImportItemPropertiesSideBarImport should be a subclass of
0235     ///       ItemPropertiesSideBar
0236 
0237     Sidebar::doSaveState();
0238 
0239     KConfigGroup group              = getConfigGroup();
0240 
0241     KConfigGroup groupCameraItemTab = KConfigGroup(&group, entryName(QLatin1String("Camera Item Properties Tab")));
0242     d->cameraItemTab->writeSettings(groupCameraItemTab);
0243 
0244 #ifdef HAVE_GEOLOCATION
0245 
0246     KConfigGroup groupGPSTab        = KConfigGroup(&group, entryName(QLatin1String("GPS Properties Tab")));
0247     d->gpsTab->writeSettings(groupGPSTab);
0248 
0249 #endif // HAVE_GEOLOCATION
0250 
0251     KConfigGroup groupMetadataTab   = KConfigGroup(&group, entryName(QLatin1String("Metadata Properties Tab")));
0252     d->metadataTab->writeSettings(groupMetadataTab);
0253 }
0254 
0255 } // namespace Digikam
0256 
0257 #include "moc_importitempropertiessidebar.cpp"