File indexing completed on 2025-01-19 03:53:47
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-05-17 0007 * Description : low level files management interface - Finder classes 0008 * 0009 * SPDX-FileCopyrightText: 2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2012-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0012 * SPDX-FileCopyrightText: 2018 by Maik Qualmann <metzpinguin at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "diofinders.h" 0019 0020 // Qt includes 0021 0022 #include <QFileInfo> 0023 #include <QSet> 0024 0025 // Local includes 0026 0027 #include "digikam_debug.h" 0028 #include "iteminfo.h" 0029 #include "metaenginesettings.h" 0030 0031 namespace Digikam 0032 { 0033 0034 SidecarFinder::SidecarFinder(const QList<QUrl>& files) 0035 { 0036 // First, the sidecar urls will be added so that they are first copied or renamed. 0037 0038 QStringList sidecarExtensions; 0039 sidecarExtensions << QLatin1String("xmp"); 0040 sidecarExtensions << MetaEngineSettings::instance()->settings().sidecarExtensions; 0041 0042 Q_FOREACH (const QUrl& url, files) 0043 { 0044 QFileInfo info(url.toLocalFile()); 0045 0046 Q_FOREACH (const QString& ext, sidecarExtensions) 0047 { 0048 QString suffix(QLatin1Char('.') + ext); 0049 0050 if (info.filePath().endsWith(suffix)) 0051 { 0052 continue; 0053 } 0054 0055 QFileInfo extInfo(info.filePath() + suffix); 0056 QFileInfo basInfo(info.path() + 0057 QLatin1Char('/') + 0058 info.completeBaseName() + suffix); 0059 0060 if (extInfo.exists() && !localFiles.contains(QUrl::fromLocalFile(extInfo.filePath()))) 0061 { 0062 localFiles << QUrl::fromLocalFile(extInfo.filePath()); 0063 localFileModes << true; 0064 localFileSuffixes << suffix; 0065 qCDebug(DIGIKAM_DATABASE_LOG) << "Detected a sidecar" << localFiles.last(); 0066 } 0067 0068 if (basInfo.exists() && !localFiles.contains(QUrl::fromLocalFile(basInfo.filePath()))) 0069 { 0070 localFiles << QUrl::fromLocalFile(basInfo.filePath()); 0071 localFileModes << false; 0072 localFileSuffixes << suffix; 0073 qCDebug(DIGIKAM_DATABASE_LOG) << "Detected a sidecar" << localFiles.last(); 0074 } 0075 } 0076 } 0077 0078 // Now the files, if the user has selected sidecars, these are ignored. 0079 0080 Q_FOREACH (const QUrl& url, files) 0081 { 0082 if (!localFiles.contains(url)) 0083 { 0084 localFiles << url; 0085 localFileModes << true; 0086 localFileSuffixes << QString(); 0087 } 0088 } 0089 } 0090 0091 // ------------------------------------------------------------------------------------------------ 0092 0093 /** 0094 * TODO: Groups should not be resolved in dio, it should be handled in views. 0095 * This is already done for most things except for drag&drop, which is hard :) 0096 */ 0097 GroupedImagesFinder::GroupedImagesFinder(const QList<ItemInfo>& source) 0098 { 0099 QSet<qlonglong> ids; 0100 0101 Q_FOREACH (const ItemInfo& info, source) 0102 { 0103 ids << info.id(); 0104 } 0105 0106 infos.reserve(source.size()); 0107 0108 Q_FOREACH (const ItemInfo& info, source) 0109 { 0110 infos << info; 0111 0112 if (info.hasGroupedImages()) 0113 { 0114 Q_FOREACH (const ItemInfo& groupedImage, info.groupedImages()) 0115 { 0116 if (ids.contains(groupedImage.id())) 0117 { 0118 continue; 0119 } 0120 0121 infos << groupedImage; 0122 ids << groupedImage.id(); 0123 } 0124 } 0125 } 0126 } 0127 0128 } // namespace Digikam