File indexing completed on 2025-01-19 03:59:45
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2003-08-03 0007 * Description : setup Metadata tab. 0008 * 0009 * SPDX-FileCopyrightText: 2003-2004 by Ralf Holzer <ralf at well dot com> 0010 * SPDX-FileCopyrightText: 2003-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0012 * SPDX-FileCopyrightText: 2017 by Simon Frei <freisim93 at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "setupmetadata_p.h" 0019 0020 namespace Digikam 0021 { 0022 0023 SetupMetadata::SetupMetadata(QWidget* const parent) 0024 : QScrollArea(parent), 0025 d (new Private) 0026 { 0027 d->tab = new QTabWidget(viewport()); 0028 setWidget(d->tab); 0029 setWidgetResizable(true); 0030 0031 // -------------------------------------------------------- 0032 0033 appendBehaviorTab(); 0034 0035 // -------------------------------------------------------- 0036 0037 appendSidecarsTab(); 0038 0039 // -------------------------------------------------------- 0040 0041 appendRotationTab(); 0042 0043 // -------------------------------------------------------- 0044 0045 appendDisplayTab(); 0046 0047 // -------------------------------------------------------- 0048 0049 d->exifToolView = new ExifToolConfPanel(d->tab); 0050 d->tab->insertTab(ExifTool, d->exifToolView, i18nc("@title:tab", "ExifTool")); 0051 0052 // -------------------------------------------------------- 0053 0054 appendBalooTab(); 0055 0056 //--------------Advanced Metadata Configuration -------------- 0057 0058 d->advTab = new AdvancedMetadataTab(this); 0059 d->tab->insertTab(AdvancedConfig, d->advTab, i18nc("@title:tab advanced metadata config view", "Advanced")); 0060 0061 // -------------------------------------------------------- 0062 0063 connect(d->exifRotateBox, SIGNAL(toggled(bool)), 0064 this, SLOT(slotExifAutoRotateToggled(bool))); 0065 0066 connect(d->writeWithExifToolBox, SIGNAL(toggled(bool)), 0067 this, SLOT(slotWriteWithExifToolToggled(bool))); 0068 0069 connect(d->exifToolView, SIGNAL(signalExifToolSettingsChanged(bool)), 0070 this, SLOT(slotExifToolSettingsChanged(bool))); 0071 0072 // -------------------------------------------------------- 0073 0074 0075 d->readSettings(); 0076 slotSidecarReadWriteToggled(); 0077 slotWriteWithExifToolToggled(d->writeWithExifToolBox->isChecked()); 0078 0079 // -------------------------------------------------------- 0080 0081 // Connect this slot later read settings. 0082 0083 connect(d->writeRawFilesBox, SIGNAL(toggled(bool)), 0084 this, SLOT(slotWriteRawFilesToggled(bool))); 0085 0086 connect(d->sidecarFileNameBox, SIGNAL(toggled(bool)), 0087 this, SLOT(slotSidecarFileNameToggled(bool))); 0088 0089 connect(d->readXMPSidecarBox, SIGNAL(toggled(bool)), 0090 this, SLOT(slotSidecarReadWriteToggled())); 0091 0092 connect(d->writeXMPSidecarBox, SIGNAL(toggled(bool)), 0093 this, SLOT(slotSidecarReadWriteToggled())); 0094 0095 // -------------------------------------------------------- 0096 0097 QTimer::singleShot(0, d->exifToolView, SLOT(slotStartFoundExifTool())); 0098 } 0099 0100 SetupMetadata::~SetupMetadata() 0101 { 0102 delete d; 0103 } 0104 0105 void SetupMetadata::setActiveTab(MetadataTab tab) 0106 { 0107 d->tab->setCurrentIndex(tab); 0108 } 0109 0110 void SetupMetadata::setActiveSubTab(MetadataSubTab tab) 0111 { 0112 d->displaySubTab->setCurrentIndex(tab); 0113 } 0114 0115 SetupMetadata::MetadataTab SetupMetadata::activeTab() const 0116 { 0117 return (MetadataTab)d->tab->currentIndex(); 0118 } 0119 0120 SetupMetadata::MetadataSubTab SetupMetadata::activeSubTab() const 0121 { 0122 return (MetadataSubTab)d->displaySubTab->currentIndex(); 0123 } 0124 0125 void SetupMetadata::applySettings() 0126 { 0127 MetaEngineSettings* const mSettings = MetaEngineSettings::instance(); 0128 0129 if (!mSettings) 0130 { 0131 return; 0132 } 0133 0134 MetaEngineSettingsContainer set; 0135 0136 set.rotationBehavior = MetaEngineSettingsContainer::RotateByInternalFlag; 0137 0138 if (d->allowRotateByMetadata->isChecked()) 0139 { 0140 set.rotationBehavior |= MetaEngineSettingsContainer::RotateByMetadataFlag; 0141 } 0142 0143 if (d->rotateByContents->isChecked()) 0144 { 0145 set.rotationBehavior |= MetaEngineSettingsContainer::RotateByLosslessRotation; 0146 0147 if (d->allowLossyRotate->isChecked()) 0148 { 0149 set.rotationBehavior |= MetaEngineSettingsContainer::RotateByLossyRotation; 0150 } 0151 } 0152 0153 set.exifRotate = d->exifRotateBox->isChecked(); 0154 set.exifSetOrientation = d->exifSetOrientationBox->isChecked(); 0155 0156 set.saveComments = d->saveCommentsBox->isChecked(); 0157 set.saveDateTime = d->saveDateTimeBox->isChecked(); 0158 set.savePickLabel = d->savePickLabelBox->isChecked(); 0159 set.saveColorLabel = d->saveColorLabelBox->isChecked(); 0160 set.saveRating = d->saveRatingBox->isChecked(); 0161 set.saveTags = d->saveTagsBox->isChecked(); 0162 set.saveTemplate = d->saveTemplateBox->isChecked(); 0163 set.saveFaceTags = d->saveFaceTags->isChecked(); 0164 set.savePosition = d->savePosition->isChecked(); 0165 0166 set.useLazySync = d->useLazySync->isChecked(); 0167 set.writeWithExifTool = d->writeWithExifToolBox->isChecked(); 0168 set.writeDngFiles = d->writeDngFilesBox->isChecked(); 0169 set.writeRawFiles = d->writeRawFilesBox->isChecked(); 0170 set.useXMPSidecar4Reading = d->readXMPSidecarBox->isChecked(); 0171 set.useCompatibleFileName = d->sidecarFileNameBox->isChecked(); 0172 0173 if (d->writeXMPSidecarBox->isChecked()) 0174 { 0175 set.metadataWritingMode = (MetaEngine::MetadataWritingMode) 0176 d->writingModeCombo->itemData(d->writingModeCombo->currentIndex()).toInt(); 0177 } 0178 else 0179 { 0180 set.metadataWritingMode = MetaEngine::WRITE_TO_FILE_ONLY; 0181 } 0182 0183 set.updateFileTimeStamp = d->updateFileTimeStampBox->isChecked(); 0184 set.rescanImageIfModified = d->rescanImageIfModifiedBox->isChecked(); 0185 0186 set.sidecarExtensions = cleanUserFilterString(d->extensionsEdit->text(), true); 0187 0188 // Check sidecar extensions for forbidden RAW extensions 0189 0190 if (!set.sidecarExtensions.isEmpty()) 0191 { 0192 QList<QString> rawList = s_rawFileExtensionsdWithDesc().keys(); 0193 rawList << QLatin1String("xmp"); 0194 QStringList::iterator it = set.sidecarExtensions.begin(); 0195 0196 for ( ; it != set.sidecarExtensions.end() ; ) 0197 { 0198 if (rawList.contains((*it).toLower())) 0199 { 0200 it = set.sidecarExtensions.erase(it); 0201 } 0202 else 0203 { 0204 ++it; 0205 } 0206 } 0207 0208 set.sidecarExtensions.removeDuplicates(); 0209 } 0210 0211 set.exifToolPath = d->exifToolView->exifToolDirectory(); 0212 0213 mSettings->setSettings(set); 0214 0215 #ifdef HAVE_KFILEMETADATA 0216 0217 ApplicationSettings* const aSettings = ApplicationSettings::instance(); 0218 0219 if (!aSettings) 0220 { 0221 return; 0222 } 0223 0224 aSettings->setSyncDigikamToBaloo(d->saveToBalooBox->isChecked()); 0225 aSettings->setSyncBalooToDigikam(d->readFromBalooBox->isChecked()); 0226 0227 aSettings->saveSettings(); 0228 0229 #endif // HAVE_KFILEMETADATA 0230 0231 d->tagsCfgPanel->applySettings(); 0232 0233 d->advTab->applySettings(); 0234 } 0235 0236 bool SetupMetadata::exifAutoRotateHasChanged() const 0237 { 0238 return (d->exifAutoRotateOriginal != d->exifRotateBox->isChecked()); 0239 } 0240 0241 void SetupMetadata::slotSidecarReadWriteToggled() 0242 { 0243 bool writeEnabled = d->writeXMPSidecarBox->isChecked(); 0244 0245 if (writeEnabled) 0246 { 0247 d->readXMPSidecarBox->setChecked(true); 0248 } 0249 0250 bool fileBoxOn = (writeEnabled || 0251 d->readXMPSidecarBox->isChecked()); 0252 0253 d->readXMPSidecarBox->setEnabled(!writeEnabled); 0254 d->writingModeCombo->setEnabled(writeEnabled); 0255 d->sidecarFileNameBox->setEnabled(fileBoxOn); 0256 } 0257 0258 void SetupMetadata::slotSidecarFileNameToggled(bool b) 0259 { 0260 // Show info if sidcar file name for commercial programs was switched on, and only once. 0261 0262 if (b && !d->sidecarFileNameShowedInfo) 0263 { 0264 d->sidecarFileNameShowedInfo = true; 0265 QMessageBox::information(this, qApp->applicationName(), 0266 i18nc("@info", 0267 "You should only activate this option if you are exchanging " 0268 "image metadata with programs that use the sidecar format " 0269 "BASENAME.xmp. If you have images with the same base name " 0270 "(e.g. Image.CR2 and Image.JPG) then the sidecar can no " 0271 "longer be uniquely assigned and will be used for both " 0272 "images, which can lead to metadata problems.")); 0273 } 0274 } 0275 0276 void SetupMetadata::slotExifAutoRotateToggled(bool b) 0277 { 0278 // Show info if rotation was switched off, and only once. 0279 0280 if (!b && !d->exifAutoRotateShowedInfo && exifAutoRotateHasChanged()) 0281 { 0282 d->exifAutoRotateShowedInfo = true; 0283 QMessageBox::information(this, qApp->applicationName(), 0284 i18nc("@info", 0285 "Switching off exif auto rotation will most probably show " 0286 "your images in a wrong orientation, so only change this " 0287 "option if you explicitly require this.")); 0288 } 0289 } 0290 0291 void SetupMetadata::slotWriteWithExifToolToggled(bool b) 0292 { 0293 d->writeDngFilesBox->setEnabled(b); 0294 d->writeRawFilesBox->setEnabled(b); 0295 } 0296 0297 void SetupMetadata::slotWriteRawFilesToggled(bool b) 0298 { 0299 // Show info if write metadata to raw files was switched on 0300 0301 if (b) 0302 { 0303 QApplication::beep(); 0304 0305 QPointer<QMessageBox> msgBox1 = new QMessageBox(QMessageBox::Warning, 0306 qApp->applicationName(), 0307 i18nc("@info", 0308 "Do you really want to enable metadata writing to RAW files? " 0309 "digiKam delegates this task to the ExifTool backend.\n" 0310 "With different RAW formats, problems are known which can " 0311 "lead to the corrupt of RAW files.\n" 0312 "If you decide to do so, make a backup of your RAW files. " 0313 "We strongly recommend not to enable this option."), 0314 QMessageBox::Yes | QMessageBox::No, this); 0315 0316 msgBox1->button(QMessageBox::Yes)->setText(i18nc("@action:button", "Yes I Understand")); 0317 msgBox1->setDefaultButton(QMessageBox::No); 0318 0319 int result1 = msgBox1->exec(); 0320 delete msgBox1; 0321 0322 if (result1 == QMessageBox::Yes) 0323 { 0324 QPointer<QMessageBox> msgBox2 = new QMessageBox(QMessageBox::Warning, 0325 qApp->applicationName(), 0326 i18nc("@info", "You would rather disable writing metadata to RAW files?"), 0327 QMessageBox::Yes | QMessageBox::No, this); 0328 0329 int result2 = msgBox2->exec(); 0330 delete msgBox2; 0331 0332 if (result2 == QMessageBox::No) 0333 { 0334 return; 0335 } 0336 } 0337 0338 d->writeRawFilesBox->setChecked(false); 0339 } 0340 } 0341 0342 } // namespace Digikam 0343 0344 #include "moc_setupmetadata.cpp"