Warning, file /utilities/krename/src/taglibplugin.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 taglibplugin.cpp - description 0003 ------------------- 0004 begin : Tue Jul 1st 2008 0005 copyright : (C) 2008 by Dominik Seichter 0006 email : domseichter@web.de 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "taglibplugin.h" 0019 0020 // taglib includes 0021 #include <taglib.h> 0022 #include <fileref.h> 0023 #include <tfile.h> 0024 #include <tstring.h> 0025 #include <tag.h> 0026 0027 #include <KLocalizedString> 0028 0029 #include "batchrenamer.h" 0030 0031 TagLibPlugin::TagLibPlugin(PluginLoader *loader) 0032 : FilePlugin(loader) 0033 { 0034 this->addSupportedToken("tagTitle"); 0035 this->addSupportedToken("tagArtist"); 0036 this->addSupportedToken("tagAlbum"); 0037 this->addSupportedToken("tagComment"); 0038 this->addSupportedToken("tagGenre"); 0039 this->addSupportedToken("tagYear"); 0040 this->addSupportedToken("tagTrack"); 0041 0042 m_help.append("[tagTitle];;" + i18n("Insert the title of a track")); 0043 m_help.append("[tagArtist];;" + i18n("Insert the artist of a track")); 0044 m_help.append("[tagAlbum];;" + i18n("Insert the album of a track")); 0045 m_help.append("[tagComment];;" + i18n("Insert the comment of a track")); 0046 m_help.append("[tagGenre];;" + i18n("Insert the genre of a track")); 0047 m_help.append("[tagYear];;" + i18n("Insert the year of a track")); 0048 m_help.append("[tagTrack];;" + i18n("Insert the number of a track")); 0049 m_help.append("[##tagTrack];;" + i18n("Insert the number of a track formatted with a leading 0")); 0050 0051 m_name = i18n("TagLib (MP3/Ogg) Plugin"); 0052 m_comment = i18n("<qt>This plugin supports reading tags for " 0053 "MP3, Ogg Vorbis, FLAC, MPC, Speex WavPack " 0054 "and TrueAudio files.</qt>"); 0055 m_icon = "audio-x-generic"; 0056 } 0057 0058 QString TagLibPlugin::processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType) 0059 { 0060 QString token(filenameOrToken.toLower()); 0061 QString filename = (*b->files())[index].srcUrl().path(); 0062 0063 TagLib::FileRef g(TagLib::FileName(filename.toUtf8().data())); 0064 TagLib::String result; 0065 0066 if (g.isNull()) { 0067 return QString(""); 0068 } 0069 0070 if (token == "tagtitle") { 0071 result = g.tag()->title(); 0072 } else if (token == "tagartist") { 0073 result = g.tag()->artist(); 0074 } else if (token == "tagalbum") { 0075 result = g.tag()->album(); 0076 } else if (token == "tagcomment") { 0077 result = g.tag()->comment(); 0078 } else if (token == "taggenre") { 0079 result = g.tag()->genre(); 0080 } else if (token == "tagyear") { 0081 unsigned int year = g.tag()->year(); 0082 return QString::number(year); 0083 } else if (token == "tagtrack") { 0084 unsigned int track = g.tag()->track(); 0085 return QString::number(track); 0086 } 0087 0088 return TStringToQString(result); 0089 }