File indexing completed on 2024-05-12 04:55:48
0001 /** 0002 * \file taglibmetadataplugin.cpp 0003 * TagLib metadata plugin. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 27 Jul 2013 0008 * 0009 * Copyright (C) 2013-2018 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 "taglibmetadataplugin.h" 0028 #include "taglibfile.h" 0029 0030 namespace { 0031 0032 const QLatin1String TAGGEDFILE_KEY("TaglibMetadata"); 0033 0034 } 0035 0036 /*! 0037 * Constructor. 0038 * @param parent parent object 0039 */ 0040 TaglibMetadataPlugin::TaglibMetadataPlugin(QObject* parent) : QObject(parent) 0041 { 0042 setObjectName(QLatin1String("TaglibMetadata")); 0043 } 0044 0045 /** 0046 * Get name of factory, the same as the QObject::objectName() of the plugin. 0047 * @return factory name. 0048 */ 0049 QString TaglibMetadataPlugin::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 TaglibMetadataPlugin::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 TaglibMetadataPlugin::taggedFileFeatures(const QString& key) const 0069 { 0070 if (key == TAGGEDFILE_KEY) { 0071 return TaggedFile::TF_ID3v11 | TaggedFile::TF_ID3v22 | 0072 TaggedFile::TF_OggFlac | 0073 TaggedFile::TF_OggPictures | 0074 TaggedFile::TF_ID3v23 | 0075 TaggedFile::TF_ID3v24; 0076 } 0077 return 0; 0078 } 0079 0080 /** 0081 * Initialize tagged file factory. 0082 * 0083 * @param key tagged file key 0084 */ 0085 void TaglibMetadataPlugin::initialize(const QString& key) 0086 { 0087 if (key == TAGGEDFILE_KEY) { 0088 TagLibFile::staticInit(); 0089 } 0090 } 0091 0092 /** 0093 * Create a tagged file. 0094 * 0095 * @param key tagged file key 0096 * @param fileName filename 0097 * @param idx model index 0098 * @param features optional tagged file features (TaggedFile::Feature flags) 0099 * to activate at creation 0100 * 0101 * @return tagged file, 0 if type not supported. 0102 */ 0103 TaggedFile* TaglibMetadataPlugin::createTaggedFile( 0104 const QString& key, 0105 const QString& fileName, 0106 const QPersistentModelIndex& idx, 0107 int features) 0108 { 0109 Q_UNUSED(features) 0110 if (key == TAGGEDFILE_KEY) { 0111 QString ext = fileName.right(4).toLower(); 0112 QString ext2 = ext.right(3); 0113 if ( ext == QLatin1String(".mp3") || ext == QLatin1String(".mp2") 0114 || ext == QLatin1String(".aac") 0115 || ext == QLatin1String(".mpc") || ext == QLatin1String(".oga") 0116 || ext == QLatin1String(".ogg") || ext == QLatin1String("flac") 0117 || ext == QLatin1String(".spx") || ext == QLatin1String(".tta") 0118 || ext == QLatin1String(".m4a") || ext == QLatin1String(".m4b") 0119 || ext == QLatin1String(".m4p") || ext == QLatin1String(".m4r") 0120 || ext == QLatin1String(".mp4") || ext == QLatin1String(".m4v") 0121 || ext == QLatin1String("mp4v") 0122 || ext == QLatin1String(".wma") || ext == QLatin1String(".asf") 0123 || ext == QLatin1String(".wmv") 0124 || ext == QLatin1String(".aif") || ext == QLatin1String("aiff") 0125 || ext == QLatin1String(".wav") || ext == QLatin1String(".ape") 0126 || ext == QLatin1String(".mod") || ext == QLatin1String(".s3m") 0127 || ext2 == QLatin1String(".it") 0128 || ext2 == QLatin1String(".xm") 0129 || ext == QLatin1String("opus") 0130 || ext == QLatin1String(".dsf") 0131 || ext == QLatin1String(".dff") 0132 || ext2 == QLatin1String(".wv")) 0133 return new TagLibFile(idx); 0134 } 0135 return nullptr; 0136 } 0137 0138 /** 0139 * Get a list with all extensions (e.g. ".mp3") supported by TaggedFile subclass. 0140 * 0141 * @param key tagged file key 0142 * 0143 * @return list of file extensions. 0144 */ 0145 QStringList 0146 TaglibMetadataPlugin::supportedFileExtensions(const QString& key) const 0147 { 0148 if (key == TAGGEDFILE_KEY) { 0149 return { 0150 QLatin1String(".flac"), QLatin1String(".mp3"), QLatin1String(".mpc"), 0151 QLatin1String(".oga"), QLatin1String(".ogg"), QLatin1String(".spx"), 0152 QLatin1String(".tta"), QLatin1String(".aac"), QLatin1String(".mp2"), 0153 QLatin1String(".m4a"), QLatin1String(".m4b"), QLatin1String(".m4p"), 0154 QLatin1String(".m4r"), QLatin1String(".mp4"), QLatin1String(".m4v"), 0155 QLatin1String(".mp4v"), 0156 QLatin1String(".wma"), QLatin1String(".asf"), QLatin1String(".wmv"), 0157 QLatin1String(".aif"), QLatin1String(".aiff"), QLatin1String(".wav"), 0158 QLatin1String(".ape"), 0159 QLatin1String(".mod"), QLatin1String(".s3m"), QLatin1String(".it"), 0160 QLatin1String(".xm"), 0161 QLatin1String(".opus"), 0162 QLatin1String(".dsf"), 0163 QLatin1String(".dff"), 0164 QLatin1String(".wv") 0165 }; 0166 } 0167 return QStringList(); 0168 } 0169 0170 /** 0171 * Notify about configuration change. 0172 * This method shall be called when the configuration changes. 0173 * 0174 * @param key tagged file key 0175 */ 0176 void TaglibMetadataPlugin::notifyConfigurationChange(const QString& key) 0177 { 0178 if (key == TAGGEDFILE_KEY) { 0179 TagLibFile::notifyConfigurationChange(); 0180 } 0181 }