File indexing completed on 2025-01-19 03:59:32
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2013-08-09 0007 * Description : Thread actions task for metadata synchronizer. 0008 * 0009 * SPDX-FileCopyrightText: 2013-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 "metadatasynctask.h" 0016 0017 // Local includes 0018 0019 #include "collectionscanner.h" 0020 #include "scancontroller.h" 0021 #include "metadatahub.h" 0022 #include "digikam_debug.h" 0023 #include "maintenancedata.h" 0024 0025 namespace Digikam 0026 { 0027 0028 class Q_DECL_HIDDEN MetadataSyncTask::Private 0029 { 0030 public: 0031 0032 explicit Private() 0033 : tagsOnly (false), 0034 direction (MetadataSynchronizer::WriteFromDatabaseToFile), 0035 data (nullptr) 0036 { 0037 } 0038 0039 bool tagsOnly; 0040 0041 MetadataSynchronizer::SyncDirection direction; 0042 0043 MaintenanceData* data; 0044 }; 0045 0046 // ------------------------------------------------------- 0047 0048 MetadataSyncTask::MetadataSyncTask() 0049 : ActionJob(), 0050 d (new Private) 0051 { 0052 } 0053 0054 MetadataSyncTask::~MetadataSyncTask() 0055 { 0056 cancel(); 0057 delete d; 0058 } 0059 0060 void MetadataSyncTask::setTagsOnly(bool value) 0061 { 0062 d->tagsOnly = value; 0063 } 0064 0065 void MetadataSyncTask::setDirection(MetadataSynchronizer::SyncDirection dir) 0066 { 0067 d->direction = dir; 0068 } 0069 0070 void MetadataSyncTask::setMaintenanceData(MaintenanceData* const data) 0071 { 0072 d->data = data; 0073 } 0074 0075 void MetadataSyncTask::run() 0076 { 0077 // While we have data (using this as check for non-null) 0078 0079 while (d->data) 0080 { 0081 if (m_cancel) 0082 { 0083 return; 0084 } 0085 0086 ItemInfo item = d->data->getItemInfo(); 0087 0088 // If the item is null, we are done. 0089 0090 if (item.isNull()) 0091 { 0092 break; 0093 } 0094 0095 if (d->direction == MetadataSynchronizer::WriteFromDatabaseToFile) 0096 { 0097 MetadataHub hub; 0098 0099 // read in from database 0100 0101 hub.load(item); 0102 0103 // write out to file DMetadata 0104 0105 if (d->tagsOnly) 0106 { 0107 ScanController::FileMetadataWrite writeScope(item); 0108 writeScope.changed(hub.writeToMetadata(item, MetadataHub::WRITE_TAGS, true)); 0109 } 0110 else 0111 { 0112 ScanController::FileMetadataWrite writeScope(item); 0113 writeScope.changed(hub.writeToMetadata(item, MetadataHub::WRITE_ALL, true)); 0114 } 0115 } 0116 else // MetadataSynchronizer::ReadFromFileToDatabase 0117 { 0118 CollectionScanner scanner; 0119 scanner.scanFile(item, CollectionScanner::CleanScan); 0120 } 0121 0122 Q_EMIT signalFinished(QImage()); 0123 } 0124 0125 Q_EMIT signalDone(); 0126 } 0127 0128 } // namespace Digikam 0129 0130 #include "moc_metadatasynctask.cpp"