File indexing completed on 2024-05-12 04:55:37
0001 /** 0002 * \file id3libmetadataplugin.cpp 0003 * id3lib metadata plugin. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 23 Jul 2013 0008 * 0009 * Copyright (C) 2013-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include "id3libmetadataplugin.h" 0028 #include "mp3file.h" 0029 0030 namespace { 0031 0032 const QLatin1String TAGGEDFILE_KEY("Id3libMetadata"); 0033 0034 } 0035 0036 /*! 0037 * Constructor. 0038 * @param parent parent object 0039 */ 0040 Id3libMetadataPlugin::Id3libMetadataPlugin(QObject* parent) : QObject(parent) 0041 { 0042 setObjectName(QLatin1String("Id3libMetadata")); 0043 } 0044 0045 /** 0046 * Get name of factory, the same as the QObject::objectName() of the plugin. 0047 * @return factory name. 0048 */ 0049 QString Id3libMetadataPlugin::name() const 0050 { 0051 return objectName(); 0052 } 0053 0054 /** 0055 * Get keys of available tagged file formats. 0056 * @return list of keys. 0057 */ 0058 QStringList Id3libMetadataPlugin::taggedFileKeys() const 0059 { 0060 return {TAGGEDFILE_KEY}; 0061 } 0062 0063 /** 0064 * Get features supported. 0065 * @param key tagged file key 0066 * @return bit mask with TaggedFile::Feature flags set. 0067 */ 0068 int Id3libMetadataPlugin::taggedFileFeatures(const QString& key) const 0069 { 0070 if (key == TAGGEDFILE_KEY) { 0071 return TaggedFile::TF_ID3v11 | TaggedFile::TF_ID3v23; 0072 } 0073 return 0; 0074 } 0075 0076 /** 0077 * Initialize tagged file factory. 0078 * 0079 * @param key tagged file key 0080 */ 0081 void Id3libMetadataPlugin::initialize(const QString& key) 0082 { 0083 Q_UNUSED(key); 0084 } 0085 0086 /** 0087 * Create a tagged file. 0088 * 0089 * @param key tagged file key 0090 * @param fileName filename 0091 * @param idx model index 0092 * @param features optional tagged file features (TaggedFile::Feature flags) 0093 * to activate at creation 0094 * 0095 * @return tagged file, 0 if type not supported. 0096 */ 0097 TaggedFile* Id3libMetadataPlugin::createTaggedFile( 0098 const QString& key, 0099 const QString& fileName, 0100 const QPersistentModelIndex& idx, 0101 int features) 0102 { 0103 if (key == TAGGEDFILE_KEY) { 0104 if (QString ext = fileName.right(4).toLower(); 0105 (ext == QLatin1String(".mp3") || ext == QLatin1String(".mp2") || 0106 ext == QLatin1String(".aac")) && 0107 (TagConfig::instance().id3v2Version() == TagConfig::ID3v2_3_0 || 0108 (features & TaggedFile::TF_ID3v23) != 0)) { 0109 return new Mp3File(idx); 0110 } 0111 } 0112 return nullptr; 0113 } 0114 0115 /** 0116 * Get a list with all extensions (e.g. ".mp3") supported by TaggedFile subclass. 0117 * 0118 * @param key tagged file key 0119 * 0120 * @return list of file extensions. 0121 */ 0122 QStringList 0123 Id3libMetadataPlugin::supportedFileExtensions(const QString& key) const 0124 { 0125 if (key == TAGGEDFILE_KEY) { 0126 return {QLatin1String(".mp3"), QLatin1String(".mp2"), QLatin1String(".aac")}; 0127 } 0128 return QStringList(); 0129 } 0130 0131 /** 0132 * Notify about configuration change. 0133 * This method shall be called when the configuration changes. 0134 * 0135 * @param key tagged file key 0136 */ 0137 void Id3libMetadataPlugin::notifyConfigurationChange(const QString& key) 0138 { 0139 if (key == TAGGEDFILE_KEY) { 0140 Mp3File::notifyConfigurationChange(); 0141 } 0142 }