File indexing completed on 2024-05-19 04:56:31

0001 /**
0002  * \file oggflacmetadataplugin.cpp
0003  * Ogg/Vorbis & FLAC metadata plugin.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 27 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 "oggflacmetadataplugin.h"
0028 #include "oggfile.hpp"
0029 #include "flacfile.hpp"
0030 #include "tagconfig.h"
0031 
0032 namespace {
0033 
0034 #ifdef HAVE_VORBIS
0035 const QLatin1String OGG_KEY("OggMetadata");
0036 #endif
0037 #ifdef HAVE_FLAC
0038 const QLatin1String FLAC_KEY("FlacMetadata");
0039 #endif
0040 
0041 }
0042 
0043 /*!
0044  * Constructor.
0045  * @param parent parent object
0046  */
0047 OggFlacMetadataPlugin::OggFlacMetadataPlugin(QObject* parent) : QObject(parent)
0048 {
0049   setObjectName(QLatin1String("OggFlacMetadata"));
0050 }
0051 
0052 /**
0053  * Get name of factory, the same as the QObject::objectName() of the plugin.
0054  * @return factory name.
0055  */
0056 QString OggFlacMetadataPlugin::name() const
0057 {
0058   return objectName();
0059 }
0060 
0061 /**
0062  * Get keys of available tagged file formats.
0063  * @return list of keys.
0064  */
0065 QStringList OggFlacMetadataPlugin::taggedFileKeys() const
0066 {
0067   return {
0068 #ifdef HAVE_VORBIS
0069       OGG_KEY,
0070 #endif
0071 #ifdef HAVE_FLAC
0072       FLAC_KEY,
0073 #endif
0074   };
0075 }
0076 
0077 /**
0078  * Get features supported.
0079  * @param key tagged file key
0080  * @return bit mask with TaggedFile::Feature flags set.
0081  */
0082 int OggFlacMetadataPlugin::taggedFileFeatures(const QString& key) const
0083 {
0084 #ifdef HAVE_VORBIS
0085   if (key == OGG_KEY) {
0086     return TaggedFile::TF_OggPictures;
0087   }
0088 #else
0089   Q_UNUSED(key)
0090 #endif
0091   return 0;
0092 }
0093 
0094 /**
0095  * Initialize tagged file factory.
0096  *
0097  * @param key tagged file key
0098  */
0099 void OggFlacMetadataPlugin::initialize(const QString& key)
0100 {
0101   Q_UNUSED(key)
0102 }
0103 
0104 /**
0105  * Create a tagged file.
0106  *
0107  * @param key tagged file key
0108  * @param fileName filename
0109  * @param idx model index
0110  * @param features optional tagged file features (TaggedFile::Feature flags)
0111  * to activate at creation
0112  *
0113  * @return tagged file, 0 if type not supported.
0114  */
0115 TaggedFile* OggFlacMetadataPlugin::createTaggedFile(
0116     const QString& key,
0117     const QString& fileName,
0118     const QPersistentModelIndex& idx,
0119     int features)
0120 {
0121   Q_UNUSED(features)
0122 #ifdef HAVE_VORBIS
0123   if (key == OGG_KEY) {
0124     if (QString ext = fileName.right(4).toLower();
0125         ext == QLatin1String(".oga") || ext == QLatin1String(".ogg"))
0126       return new OggFile(idx);
0127   }
0128 #endif
0129 #ifdef HAVE_FLAC
0130   if (key == FLAC_KEY) {
0131     if (fileName.right(5).toLower() == QLatin1String(".flac"))
0132       return new FlacFile(idx);
0133   }
0134 #endif
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 OggFlacMetadataPlugin::supportedFileExtensions(const QString& key) const
0147 {
0148 #ifdef HAVE_VORBIS
0149   if (key == OGG_KEY) {
0150     return {QLatin1String(".oga"), QLatin1String(".ogg")};
0151   }
0152 #endif
0153 #ifdef HAVE_FLAC
0154   if (key == FLAC_KEY) {
0155     return {QLatin1String(".flac")};
0156   }
0157 #endif
0158   return QStringList();
0159 }
0160 
0161 /**
0162  * Notify about configuration change.
0163  * This method shall be called when the configuration changes.
0164  *
0165  * @param key tagged file key
0166  */
0167 void OggFlacMetadataPlugin::notifyConfigurationChange(const QString& key)
0168 {
0169   Q_UNUSED(key)
0170 }