File indexing completed on 2024-05-19 04:49:32
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Téo Mrnjavac <teo@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef TRANSCODING_CONFIGURATION_H 0018 #define TRANSCODING_CONFIGURATION_H 0019 0020 #include "core/amarokcore_export.h" 0021 #include "core/meta/Meta.h" // needed for default parameter constructor 0022 #include "core/transcoding/TranscodingDefines.h" 0023 #include "core/transcoding/TranscodingProperty.h" 0024 0025 #include <KConfigGroup> 0026 0027 #include <QMap> 0028 #include <QVariant> 0029 0030 namespace Transcoding 0031 { 0032 0033 /** 0034 * This class defines the values of a set of properties as described by an instance of 0035 * Transcoding::PropertyList. It contains all the data needed to start a Transcoding::Job. 0036 * @author Téo Mrnjavac <teo@kde.org> 0037 */ 0038 class AMAROKCORE_EXPORT Configuration 0039 { 0040 public: 0041 0042 //Normally we don't specify the numbers, but must specify enumeration values in 0043 //this case, as the values will get written to a config file, so we need to preserve 0044 //the numbers across versions and specify them explicitly 0045 enum TrackSelection { 0046 /** 0047 * Transcode all tracks 0048 */ 0049 TranscodeAll = 0, 0050 /** 0051 * Transcode unless the target format is the same as source format 0052 */ 0053 TranscodeUnlessSameType = 1, 0054 /** 0055 * Transcode tracks only if needed for playability in the destination collection 0056 */ 0057 TranscodeOnlyIfNeeded = 2, 0058 /** 0059 * Transcode unless: 0060 * 1. the target format is the same as source format, AND 0061 * 2. the target bitrate is higher than source bitrate (with 10% tolerance to prevent re-encodings) 0062 */ 0063 //TranscodeUnlessUpgradesBitrate = 3 //to be implemented. 0064 }; 0065 0066 explicit Configuration( Transcoding::Encoder encoder, 0067 TrackSelection trackSelection = TranscodeAll ); 0068 0069 Encoder encoder() const { return m_encoder; } 0070 0071 /** 0072 * Return true if this transcoding configuration is valid. JUST_COPY encoder is 0073 * treated as valid. 0074 */ 0075 bool isValid() const { return m_encoder != INVALID; } 0076 0077 /** 0078 * Return true if this configuration represents plain copying of files. Both INVALID 0079 * and JUST_COPY encoders are considered plain copying. Also returns true if an encoder is 0080 * selected, but the passed track does not satisfy the selected m_trackSelection value. 0081 */ 0082 bool isJustCopy( const Meta::TrackPtr &srcTrack = Meta::TrackPtr(), 0083 const QStringList &playableFileTypes = QStringList() ) const; 0084 0085 QVariant property( const QByteArray &name ) const; 0086 void addProperty(const QByteArray &name, const QVariant &value ); 0087 0088 /** 0089 * Re-create transcoding configuration from serialized form stored in a KConfigGroup. 0090 * Return invalid configuration if parsing failed or was incomplete. 0091 */ 0092 static Configuration fromConfigGroup( const KConfigGroup &serialized ); 0093 0094 /** 0095 * Serialize this transcoding configuration to a KConfigGroup. All existing keys in 0096 * the group are erased or replaced. 0097 */ 0098 void saveToConfigGroup( KConfigGroup &group ) const; 0099 0100 /** 0101 * Return user-presentable representation of this configuration's codec and its 0102 * parameters. 0103 */ 0104 QString prettyName() const; 0105 0106 TrackSelection trackSelection() const { return m_trackSelection; } 0107 void setTrackSelection( TrackSelection trackSelection ); 0108 0109 bool operator!=( const Configuration &other ) const; 0110 0111 private: 0112 /** 0113 * Map an Encoder to its identifier 0114 */ 0115 static const QMap<Encoder, QString> &encoderNames(); 0116 0117 /** 0118 * Return a user representable description of the format and the TrackSelection 0119 */ 0120 QString formatPrettyPrefix() const; 0121 0122 static QMap<Encoder, QString> s_encoderNames; 0123 Encoder m_encoder; 0124 QMap<QByteArray, QVariant> m_values; 0125 TrackSelection m_trackSelection; //the transcoding configuration 0126 }; 0127 0128 } 0129 0130 #endif //TRANSCODING_CONFIGURATION_H