Commit 3c175c74 authored by Michael Pyne's avatar Michael Pyne
Browse files

Remove TagLib support code that wasn't even necessary by KDE 3.5, let alone KDE 4.4.

Also restructure the code to call KMimeType::findByPath much less frequently (and when
we do, to actually look at file contents).

svn path=/trunk/KDE/kdemultimedia/juk/; revision=1027890
parent ef29c7a3
......@@ -17,7 +17,6 @@ else(TUNEPIMP_FOUND)
set(HAVE_TUNEPIMP 0)
endif(TUNEPIMP_FOUND)
MESSAGE(STATUS "${TAGLIB_INCLUDES} ==========")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
configure_file (config-juk.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-juk.h )
......
......@@ -21,24 +21,32 @@
#include <kurl.h>
#include <kio/netaccess.h>
#include <QWidget>
#include <QtGui/QWidget>
#include <QtCore/QFile>
#include <taglib.h>
#include <taglib_config.h>
#include <tag.h>
#if (TAGLIB_MAJOR_VERSION > 1) || \
((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 2))
#define TAGLIB_1_2
#include <mpegfile.h>
#include <vorbisfile.h>
#include <flacfile.h>
#include <xiphcomment.h>
#include <oggflacfile.h>
#include <mpcfile.h>
#ifdef TAGLIB_WITH_ASF
#include <asffile.h>
#endif
#if (TAGLIB_MAJOR_VERSION > 1) || \
((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 3))
#define TAGLIB_1_3
#ifdef TAGLIB_WITH_MP4
#include <mp4file.h>
#endif
namespace MediaFiles {
QStringList mimeTypes();
static QStringList savedMimeTypes;
static const char mp3Type[] = "audio/mpeg";
static const char oggType[] = "application/ogg";
static const char flacType[] = "audio/x-flac";
......@@ -48,9 +56,29 @@ namespace MediaFiles {
static const char vorbisType[] = "audio/x-vorbis+ogg";
static const char oggflacType[] = "audio/x-flac+ogg";
#ifdef TAGLIB_WITH_ASF
static const char asfType[] = "video/x-ms-asf";
#endif
#ifdef TAGLIB_WITH_MP4
static const char mp4Type[] = "video/mp4";
#endif
static const char *mediaTypes[] = {
mp3Type, oggType, flacType, mpcType, vorbisType, oggflacType
#ifdef TAGLIB_WITH_ASF
,asfType
#endif
#ifdef TAGLIB_WITH_MP4
,mp4Type
#endif
};
static const char playlistExtension[] = ".m3u";
}
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
QStringList MediaFiles::openDialog(QWidget *parent)
{
KFileDialog *dialog = new KFileDialog(KUrl(), QString(), parent);
......@@ -84,62 +112,126 @@ QString MediaFiles::savePlaylistDialog(const QString &playlistName, QWidget *par
return fileName;
}
TagLib::File *MediaFiles::fileFactoryByType(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName);
if(!result->isValid())
return 0;
TagLib::File *file(0);
QByteArray encodedFileName(QFile::encodeName(fileName));
if(result->is(mp3Type))
file = new TagLib::MPEG::File(encodedFileName.constData());
else if(result->is(flacType))
file = new TagLib::FLAC::File(encodedFileName.constData());
else if(result->is(vorbisType))
file = new TagLib::Vorbis::File(encodedFileName.constData());
else if(result->is(mpcType))
file = new TagLib::MPC::File(encodedFileName.constData());
else if(result->is(oggflacType))
file = new TagLib::Ogg::FLAC::File(encodedFileName.constData());
#ifdef TAGLIB_WITH_ASF
else if(result->is(asfType))
file = new TagLib::ASF::File(encodedFileName.constData());
#endif
#ifdef TAGLIB_WITH_MP4
else if(result->is(mp4Type))
file = new TagLib::MP4::File(encodedFileName.constData());
#endif
return file;
}
bool MediaFiles::isMediaFile(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
if(!result->isValid())
return false;
// Search through our table of media types for a match
for(unsigned i = 0; i < ARRAY_SIZE(mediaTypes); ++i) {
if(result->is(mediaTypes[i]))
return true;
}
return result->is(mp3Type) || result->is(oggType) || result->is(flacType) || result->is(mpcType);
return false;
}
bool MediaFiles::isPlaylistFile(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(m3uType);
}
bool MediaFiles::isMP3(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(mp3Type);
}
bool MediaFiles::isOgg(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(oggType);
}
bool MediaFiles::isFLAC(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(flacType);
}
bool MediaFiles::isMPC(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(mpcType);
}
bool MediaFiles::isVorbis(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, false);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(vorbisType);
}
#ifdef TAGLIB_WITH_ASF
bool MediaFiles::isASF(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(asfType);
}
#endif
#ifdef TAGLIB_WITH_MP4
bool MediaFiles::isMP4(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(mp4Type);
}
#endif
bool MediaFiles::isOggFLAC(const QString &fileName)
{
KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, false);
KMimeType::Ptr result = KMimeType::findByPath(fileName);
return result->is(oggflacType);
}
QStringList MediaFiles::mimeTypes()
{
QStringList l;
if(!savedMimeTypes.isEmpty())
return savedMimeTypes;
l << mp3Type << oggType << flacType << m3uType << vorbisType << oggflacType << mpcType;
savedMimeTypes << mp3Type << oggflacType << flacType << m3uType << vorbisType
<< oggType << mpcType
#ifdef TAGLIB_WITH_ASF
<< asfType
#endif
#ifdef TAGLIB_WITH_MP4
<< mp4Type
#endif
;
return l;
return savedMimeTypes;
}
QStringList MediaFiles::convertURLsToLocal(const KUrl::List &urlList, QWidget *w)
......
......@@ -20,7 +20,12 @@ class QWidget;
class QString;
class QStringList;
namespace TagLib {
class File;
}
#include <kurl.h>
#include <taglib_config.h>
/**
* A namespace for file JuK's file related functions. The goal is to hide
......@@ -39,6 +44,13 @@ namespace MediaFiles
*/
QString savePlaylistDialog(const QString &playlistName, QWidget *parent = 0);
/**
* Returns a pointer to a new appropriate subclass of TagLib::File, or
* a null pointer if there is no appropriate subclass for the given
* file.
*/
TagLib::File *fileFactoryByType(const QString &fileName);
/**
* Returns true if fileName is a supported media file.
*/
......@@ -74,6 +86,20 @@ namespace MediaFiles
*/
bool isVorbis(const QString &fileName);
#ifdef TAGLIB_WITH_ASF
/**
* Returns true if fileName is an ASF file.
*/
bool isASF(const QString &fileName);
#endif
#ifdef TAGLIB_WITH_MP4
/**
* Returns true if fileName is a MP4 file.
*/
bool isMP4(const QString &fileName);
#endif
/**
* Returns true if fileName is an Ogg/FLAC file.
*/
......
......@@ -17,26 +17,13 @@
#include <kdebug.h>
#include <QFile>
#include <QtCore/QFile>
#include <taglib/tag.h>
#include <mpegfile.h>
#include <vorbisfile.h>
#include <flacfile.h>
#include <xiphcomment.h>
#include <tfile.h>
#include <audioproperties.h>
#include <id3v2framefactory.h>
#if (TAGLIB_MAJOR_VERSION > 1) || \
((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 2))
#include <oggflacfile.h>
#define TAGLIB_1_2
#endif
#if (TAGLIB_MAJOR_VERSION > 1) || \
((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 3))
#include <mpcfile.h>
#define TAGLIB_1_3
#endif
#include "cache.h"
#include "mediafiles.h"
#include "stringshare.h"
......@@ -54,52 +41,20 @@ Tag::Tag(const QString &fileName) :
m_bitrate(0),
m_isValid(false)
{
// using qDebug here since we want this to show up in non-debug builds as well
if(fileName.isEmpty()) {
kError() << "Trying to add empty file, backtrace follows:" << endl;
kError() << kBacktrace(10) << endl;
return;
}
qDebug("Reading tag for %s", fileName.toLocal8Bit().data());
if(MediaFiles::isMP3(fileName)) {
TagLib::MPEG::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.isValid())
setup(&file);
}
#ifdef TAGLIB_1_3
else if(MediaFiles::isMPC(fileName)) {
kDebug() << "Trying to resolve Musepack file";
TagLib::MPC::File file(QFile::encodeName(fileName).data());
if(file.isValid())
setup(&file);
TagLib::File *file = MediaFiles::fileFactoryByType(fileName);
if(file->isValid()) {
setup(file);
delete file;
}
#endif
#ifdef TAGLIB_1_2
else if(MediaFiles::isOggFLAC(fileName)) {
TagLib::Ogg::FLAC::File file(QFile::encodeName(fileName).data());
if(file.isValid())
setup(&file);
}
#endif
else if(MediaFiles::isVorbis(fileName)) {
TagLib::Vorbis::File file(QFile::encodeName(fileName).data());
if(file.isValid())
setup(&file);
}
else {
kError() << "Couldn't resolve the mime type of \"" <<
fileName << "\" -- this shouldn't happen." << endl;
kError() << kBacktrace(10) << endl;
}
}
......@@ -107,23 +62,7 @@ bool Tag::save()
{
bool result;
TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8);
TagLib::File *file = 0;
if(MediaFiles::isMP3(m_fileName))
file = new TagLib::MPEG::File(QFile::encodeName(m_fileName).data());
else if(MediaFiles::isFLAC(m_fileName))
file = new TagLib::FLAC::File(QFile::encodeName(m_fileName).data());
#ifdef TAGLIB_1_3
else if(MediaFiles::isMPC(m_fileName))
file = new TagLib::MPC::File(QFile::encodeName(m_fileName).data());
#endif
#ifdef TAGLIB_1_2
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());
TagLib::File *file = MediaFiles::fileFactoryByType(m_fileName);
if(file && file->isValid() && file->tag() && !file->readOnly()) {
file->tag()->setTitle(TagLib::String(m_title.toUtf8().data(), TagLib::String::UTF8));
......@@ -133,12 +72,7 @@ bool Tag::save()
file->tag()->setComment(TagLib::String(m_comment.toUtf8().data(), TagLib::String::UTF8));
file->tag()->setTrack(m_track);
file->tag()->setYear(m_year);
#ifdef TAGLIB_1_2
result = file->save();
#else
file->save();
result = true;
#endif
}
else {
kError() << "Couldn't save file." << endl;
......
Markdown is supported
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