Commit f1ed6a85 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen
Browse files

Detect TagLib 1.1 vs 1.2+ for correct API and features.

* Fix compile-bug with the latest official TagLib release 1.1
* Detect TagLib 1.2 for Ogg/FLAC and Musepack support
* Fix problem with Ogg/FLAC files misdetected as Ogg/Vorbis

svn path=/trunk/kdemultimedia/juk/; revision=330557
parent cf403c4c
[Desktop Entry]
ServiceTypes=application/ogg,audio/x-mp3
ServiceTypes=application/ogg,audio/vorbis,audio/x-mp3,audio/x-flac,audio/x-oggflac,audio/x-musepack
Actions=addToCollection
[Desktop Action addToCollection]
......@@ -12,10 +12,11 @@ Name[de]=Zur JuK-Kollektion hinzufügen
Name[el]=Προσθήκη στη συλλογή του JuK
Name[es]=Añadir a colección de JuK
Name[et]=Lisa JuKi kollektsiooni
Name[fi]=Lisää JuK kokoelmaan
Name[fi]=Lisää JuKin kokoelmalistaan
Name[fr]=Ajouter à la collection de JuK
Name[hi]=ज्यूक संग्रह में जोड़ें
Name[hu]=Hozzáadás egy JuK-válogatáshoz
Name[is]=Bæta við JuK safnið
Name[it]=Aggiungi alla collezione di JuK
Name[ms]=Tambah ke koleksi JuK
Name[nb]=Legg til JuK-samling
......@@ -24,12 +25,15 @@ Name[nn]=Legg til JuK-samlinga
Name[pl]=Dodaj do kolekcji JuK
Name[pt]=Adicionar à Colecção do JuK
Name[pt_BR]=Adicionar à Coleção do Juk
Name[ru]=Добавить в коллекцию Juk
Name[ro]=Adaugă în colecţia JuK
Name[ru]=Добавить в коллекцию JuK
Name[sk]=Pridať do kolekcie JuK
Name[sl]=Dodaj v zbirko JuK
Name[sr]=Додај у JuK колекцију
Name[sr@Latn]=Dodaj u JuK kolekciju
Name[sv]=Lägg till i Juk-samlingslista
Name[ta]=JuK திரட்டிக்கு சேர்
Name[tg]=Иловакунӣ ба Маҷмӯаи JuK
Name[tr]=JuK Koleksiyonu Ekle
Name[uk]=Додати до збірки JuK
Name[uz]=JuK тўпламига қўшиш
......
......@@ -16,17 +16,26 @@
#include <kfiledialog.h>
#include <klocale.h>
#include "mediafiles.h"
#include <taglib/tag.h>
#if (TAGLIB_MAJOR_VERSION>1) || \
((TAGLIB_MAJOR_VERSION==1) && (TAGLIB_MINOR_VERSION>=2))
#define TAGLIB_12
#endif
namespace MediaFiles {
QStringList mimeTypes();
static const char mp3Type[] = "audio/x-mp3";
static const char oggType[] = "application/ogg";
static const char flacType[] = "audio/x-flac";
static const char mpcType[] = "audio/x-musepack";
static const char m3uType[] = "audio/mpegurl";
static const char vorbisType[] = "audio/x-vorbis";
static const char oggflacType[] = "audio/x-oggflac";
static const char playlistExtension[] = ".m3u";
}
......@@ -61,7 +70,11 @@ bool MediaFiles::isMediaFile(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
return result->is(mp3Type) || result->is(oggType) || result->is(flacType);
return result->is(mp3Type) || result->is(oggType) || result->is(flacType)
#ifdef TAGLIB_12
|| result->is(mpcType)
#endif
;
}
bool MediaFiles::isPlaylistFile(const QString &fileName)
......@@ -88,11 +101,32 @@ bool MediaFiles::isFLAC(const QString &fileName)
return result->is(flacType);
}
bool MediaFiles::isMPC(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
return result->is(mpcType);
}
bool MediaFiles::isVorbis(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, false);
return result->is(vorbisType);
}
bool MediaFiles::isOggFLAC(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, false);
return result->is(oggflacType);
}
QStringList MediaFiles::mimeTypes()
{
QStringList l;
l << mp3Type << oggType << flacType << m3uType;
l << mp3Type << oggType << flacType << m3uType << vorbisType
#ifdef TAGLIB_12
<< oggflacType << mpcType
#endif
;
return l;
}
......@@ -45,19 +45,34 @@ namespace MediaFiles
bool isPlaylistFile(const QString &fileName);
/**
* Returns true if fileName is an mp3 file.
* Returns true if fileName is a mp3 file.
*/
bool isMP3(const QString &fileName);
/**
* Returns true if fileName is a mpc (aka musepack) file.
*/
bool isMPC(const QString &fileName);
/**
* Returns true if fileName is an Ogg file.
*/
bool isOgg(const QString &fileName);
/**
* Returns true if fileName is an FLAC file.
* Returns true if fileName is a FLAC file.
*/
bool isFLAC(const QString &fileName);
/**
* Returns true if fileName is an Ogg/Vorbis file.
*/
bool isVorbis(const QString &fileName);
/**
* Returns true if fileName is an Ogg/FLAC file.
*/
bool isOggFLAC(const QString &fileName);
}
#endif
......@@ -25,6 +25,13 @@
#include <taglib/xiphcomment.h>
#include <taglib/id3v2framefactory.h>
#if (TAGLIB_MAJOR_VERSION>1) || \
((TAGLIB_MAJOR_VERSION==1) && (TAGLIB_MINOR_VERSION>=2))
#include <taglib/mpcfile.h>
#include <taglib/oggflacfile.h>
#define TAGLIB_12
#endif
#include "cache.h"
#include "tag.h"
#include "mediafiles.h"
......@@ -49,17 +56,30 @@ Tag::Tag(const QString &fileName) :
setup(&file);
}
else if(MediaFiles::isOgg(fileName)) {
TagLib::Vorbis::File file(QFile::encodeName(fileName).data());
if(file.isValid())
setup(&file);
}
else if(MediaFiles::isFLAC(fileName)) {
TagLib::FLAC::File file(QFile::encodeName(fileName).data());
if(file.isOpen())
setup(&file);
}
#ifdef TAGLIB_12
else if(MediaFiles::isMPC(fileName)) {
kdDebug(65432) << "Trying to resolve Musepack file" << endl;
TagLib::MPC::File file(QFile::encodeName(fileName).data());
if(file.isOpen())
setup(&file);
}
else if(MediaFiles::isOggFLAC(fileName)) {
kdDebug(65432) << "Trying to resolve Ogg/FLAC file" << endl;
TagLib::Ogg::FLAC::File file(QFile::encodeName(fileName).data());
if(file.isOpen())
setup(&file);
}
#endif
else if(MediaFiles::isVorbis(fileName)) {
TagLib::Vorbis::File file(QFile::encodeName(fileName).data());
if(file.isValid())
setup(&file);
}
else {
kdError(65432) << "Couldn't resolve the mime type of \"" <<
......@@ -76,10 +96,16 @@ bool Tag::save()
if(MediaFiles::isMP3(m_fileName))
file = new TagLib::MPEG::File(QFile::encodeName(m_fileName).data());
else if(MediaFiles::isOgg(m_fileName))
file = new TagLib::Vorbis::File(QFile::encodeName(m_fileName).data());
else if(MediaFiles::isFLAC(m_fileName))
file = new TagLib::FLAC::File(QFile::encodeName(m_fileName).data());
#ifdef TAGLIB_12
else if(MediaFiles::isMPC(m_fileName))
file = new TagLib::MPC::File(QFile::encodeName(m_fileName).data());
else if(MediaFiles::isOggFLAC(m_fileName))
file = new TagLib::Ogg::FLAC::File(QFile::encodeName(m_fileName).data());
#endif
else if(MediaFiles::isVorbis(m_fileName))
file = new TagLib::Vorbis::File(QFile::encodeName(m_fileName).data());
if(file && file->isValid() && file->tag() && !file->readOnly()) {
file->tag()->setTitle(QStringToTString(m_title));
......@@ -89,8 +115,12 @@ bool Tag::save()
file->tag()->setComment(QStringToTString(m_comment));
file->tag()->setTrack(m_track);
file->tag()->setYear(m_year);
#ifdef TAGLIB_12
result = file->save();
#else
file->save();
result = true;
#endif
}
else {
kdError(65432) << "Couldn't save file." << endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment