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

0001 /**
0002  * \file mp4v2metadataplugin.cpp
0003  * Mp4v2 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 "mp4v2metadataplugin.h"
0028 #include "m4afile.h"
0029 
0030 namespace {
0031 
0032 const QLatin1String TAGGEDFILE_KEY("Mp4v2Metadata");
0033 
0034 }
0035 
0036 /*!
0037  * Constructor.
0038  * @param parent parent object
0039  */
0040 Mp4v2MetadataPlugin::Mp4v2MetadataPlugin(QObject* parent) : QObject(parent)
0041 {
0042   setObjectName(QLatin1String("Mp4v2Metadata"));
0043 }
0044 
0045 /**
0046  * Get name of factory, the same as the QObject::objectName() of the plugin.
0047  * @return factory name.
0048  */
0049 QString Mp4v2MetadataPlugin::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 Mp4v2MetadataPlugin::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 Features flags set.
0067  */
0068 int Mp4v2MetadataPlugin::taggedFileFeatures(const QString& key) const
0069 {
0070   Q_UNUSED(key)
0071   return 0;
0072 }
0073 
0074 /**
0075  * Initialize tagged file factory.
0076  *
0077  * @param key tagged file key
0078  */
0079 void Mp4v2MetadataPlugin::initialize(const QString& key)
0080 {
0081   Q_UNUSED(key)
0082 }
0083 
0084 /**
0085  * Create a tagged file.
0086  *
0087  * @param key tagged file key
0088  * @param fileName filename
0089  * @param idx model index
0090  * @param features optional tagged file features (TaggedFile::Feature flags)
0091  * to activate at creation
0092  *
0093  * @return tagged file, 0 if type not supported.
0094  */
0095 TaggedFile* Mp4v2MetadataPlugin::createTaggedFile(
0096     const QString& key,
0097     const QString& fileName,
0098     const QPersistentModelIndex& idx,
0099     int features)
0100 {
0101   Q_UNUSED(features)
0102   if (key == TAGGEDFILE_KEY) {
0103     QString ext = fileName.right(4).toLower();
0104     if (ext == QLatin1String(".m4a") || ext == QLatin1String(".m4b") ||
0105         ext == QLatin1String(".m4p") || ext == QLatin1String(".m4r") ||
0106         ext == QLatin1String(".mp4") || ext == QLatin1String(".m4v") ||
0107         ext == QLatin1String("mp4v"))
0108       return new M4aFile(idx);
0109   }
0110   return nullptr;
0111 }
0112 
0113 /**
0114  * Get a list with all extensions (e.g. ".mp3") supported by TaggedFile subclass.
0115  *
0116  * @param key tagged file key
0117  *
0118  * @return list of file extensions.
0119  */
0120 QStringList
0121 Mp4v2MetadataPlugin::supportedFileExtensions(const QString& key) const
0122 {
0123   if (key == TAGGEDFILE_KEY) {
0124     return {
0125       QLatin1String(".m4a"), QLatin1String(".m4b"), QLatin1String(".m4p"),
0126       QLatin1String(".m4r"), QLatin1String(".mp4"), QLatin1String(".m4v"),
0127       QLatin1String(".mp4v")
0128     };
0129   }
0130   return QStringList();
0131 }
0132 
0133 /**
0134  * Notify about configuration change.
0135  * This method shall be called when the configuration changes.
0136  *
0137  * @param key tagged file key
0138  */
0139 void Mp4v2MetadataPlugin::notifyConfigurationChange(const QString& key)
0140 {
0141   Q_UNUSED(key)
0142 }