From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kfile-plugins/mpc/Makefile.am | 22 ++++ kfile-plugins/mpc/configure.in.in | 1 + kfile-plugins/mpc/kfile_mpc.cpp | 253 ++++++++++++++++++++++++++++++++++++ kfile-plugins/mpc/kfile_mpc.desktop | 56 ++++++++ kfile-plugins/mpc/kfile_mpc.h | 48 +++++++ 5 files changed, 380 insertions(+) create mode 100644 kfile-plugins/mpc/Makefile.am create mode 100644 kfile-plugins/mpc/configure.in.in create mode 100644 kfile-plugins/mpc/kfile_mpc.cpp create mode 100644 kfile-plugins/mpc/kfile_mpc.desktop create mode 100644 kfile-plugins/mpc/kfile_mpc.h (limited to 'kfile-plugins/mpc') diff --git a/kfile-plugins/mpc/Makefile.am b/kfile-plugins/mpc/Makefile.am new file mode 100644 index 00000000..a2fa88d6 --- /dev/null +++ b/kfile-plugins/mpc/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for MPC file meta info plugin + +# set the include path for X, qt, KDE and TagLib +INCLUDES = $(all_includes) $(taglib_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_mpc.h + +kde_module_LTLIBRARIES = kfile_mpc.la + +kfile_mpc_la_SOURCES = kfile_mpc.cpp +kfile_mpc_la_LDFLAGS = $(all_libraries) $(taglib_libs) -module $(KDE_PLUGIN) +kfile_mpc_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) kfile_mpc.cpp -o $(podir)/kfile_mpc.pot + +services_DATA = kfile_mpc.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/mpc/configure.in.in b/kfile-plugins/mpc/configure.in.in new file mode 100644 index 00000000..6590e6c5 --- /dev/null +++ b/kfile-plugins/mpc/configure.in.in @@ -0,0 +1 @@ +AM_CONDITIONAL(include_mpc_SUBDIR, test "x$have_taglib_mpc" = xyes) diff --git a/kfile-plugins/mpc/kfile_mpc.cpp b/kfile-plugins/mpc/kfile_mpc.cpp new file mode 100644 index 00000000..dae3e232 --- /dev/null +++ b/kfile-plugins/mpc/kfile_mpc.cpp @@ -0,0 +1,253 @@ +/* This file is part of the KDE project + * Copyright (C) 2003-2004 Allan Sandfeld Jensen + * + * Originally based upon the kfile_ogg plugin: + * Copyright (C) 2001, 2002 Rolf Magnus + * Interfacing to TagLib is copied from kfile_mp3 plugin: + * Copyright (C) 2003 Scott Wheeler + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "kfile_mpc.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +K_EXPORT_COMPONENT_FACTORY(kfile_mpc, KGenericFactory("kfile_mpc")) + +KMpcPlugin::KMpcPlugin( QObject *parent, const char *name, + const QStringList &args ) + : KFilePlugin( parent, name, args ) +{ + kdDebug(7034) << "mpc plugin\n"; + + KFileMimeTypeInfo* info = addMimeTypeInfo( "audio/x-musepack" ); + + KFileMimeTypeInfo::GroupInfo* group = 0; + + // comment group + group = addGroupInfo(info, "Comment", i18n("Comment")); + setAttributes(group, KFileMimeTypeInfo::Addable | + KFileMimeTypeInfo::Removable); + + KFileMimeTypeInfo::ItemInfo* item = 0; + + item = addItemInfo(group, "Artist", i18n("Artist"), QVariant::String); + setHint(item, KFileMimeTypeInfo::Author); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Title", i18n("Title"), QVariant::String); + setHint(item, KFileMimeTypeInfo::Name); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Album", i18n("Album"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Genre", i18n("Genre"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Tracknumber", i18n("Track Number"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Date", i18n("Date"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Description", i18n("Description"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Organization", i18n("Organization"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Location", i18n("Location"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Copyright", i18n("Copyright"), QVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + + addVariableInfo(group, QVariant::String, KFileMimeTypeInfo::Addable | + KFileMimeTypeInfo::Removable | + KFileMimeTypeInfo::Modifiable); + + // technical group + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + setAttributes(group, 0); + + addItemInfo(group, "Channels", i18n("Channels"), QVariant::Int); + + addItemInfo(group, "Version", i18n("Version"), QVariant::Int); + + item = addItemInfo(group, "Sample Rate", i18n("Sample Rate"), QVariant::Int); + setSuffix(item, i18n(" Hz")); + + item = addItemInfo(group, "Bitrate", i18n("Average Bitrate"), + QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + setHint(item, KFileMimeTypeInfo::Bitrate); + setSuffix(item, i18n( " kbps")); + + item = addItemInfo(group, "Length", i18n("Length"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Cummulative); + setHint(item, KFileMimeTypeInfo::Length); + setUnit(item, KFileMimeTypeInfo::Seconds); +} + +bool KMpcPlugin::readInfo( KFileMetaInfo& info, uint what ) +{ + + bool readComment = false; + bool readTech = false; + if (what & (KFileMetaInfo::Fastest | + KFileMetaInfo::DontCare | + KFileMetaInfo::ContentInfo)) readComment = true; + + if (what & (KFileMetaInfo::Fastest | + KFileMetaInfo::DontCare | + KFileMetaInfo::TechnicalInfo)) readTech = true; + + if ( info.path().isEmpty() ) // remote file + return false; + + TagLib::File *file = new TagLib::MPC::File(QFile::encodeName(info.path()).data(), readTech); + + if (!file->isOpen()) + { + kdDebug(7034) << "Couldn't open " << file->name() << endl; + delete file; + return false; + } + + if(readComment) + { + KFileMetaInfoGroup commentgroup = appendGroup(info, "Comment"); + + QString date = file->tag()->year() > 0 ? QString::number(file->tag()->year()) : QString::null; + QString track = file->tag()->track() > 0 ? QString::number(file->tag()->track()) : QString::null; + + appendItem(commentgroup, "Title", TStringToQString(file->tag()->title()).stripWhiteSpace()); + appendItem(commentgroup, "Artist", TStringToQString(file->tag()->artist()).stripWhiteSpace()); + appendItem(commentgroup, "Album", TStringToQString(file->tag()->album()).stripWhiteSpace()); + appendItem(commentgroup, "Date", date); + appendItem(commentgroup, "Comment", TStringToQString(file->tag()->comment()).stripWhiteSpace()); + appendItem(commentgroup, "Tracknumber", track); + appendItem(commentgroup, "Genre", TStringToQString(file->tag()->genre()).stripWhiteSpace()); + } + + if (readTech) + { + KFileMetaInfoGroup techgroup = appendGroup(info, "Technical"); + TagLib::MPC::Properties *properties = + (TagLib::MPC::Properties*)(file->audioProperties()); + + appendItem(techgroup, "Bitrate", properties->bitrate()); + appendItem(techgroup, "Sample Rate", properties->sampleRate()); + appendItem(techgroup, "Channels", properties->channels()); + appendItem(techgroup, "Length", properties->length()); + appendItem(techgroup, "Version", properties->mpcVersion()); + } + + delete file; + return true; + +} + +/** + * Do translation between KFileMetaInfo items and TagLib::String in a tidy way. + */ + +class Translator +{ +public: + Translator(const KFileMetaInfo &info) : m_info(info) {} + TagLib::String operator[](const char *key) const + { + return QStringToTString(m_info["Comment"][key].value().toString()); + } + int toInt(const char *key) const + { + return m_info["Comment"][key].value().toInt(); + } +private: + const KFileMetaInfo &m_info; +}; + +bool KMpcPlugin::writeInfo(const KFileMetaInfo& info) const +{ + TagLib::File *file; + + if (!TagLib::File::isWritable(QFile::encodeName(info.path()).data())) { + kdDebug(7034) << "can't write to " << info.path() << endl; + return false; + } + + file = new TagLib::MPC::File(QFile::encodeName(info.path()).data(), false); + + if(!file->isOpen()) + { + kdDebug(7034) << "couldn't open " << info.path() << endl; + delete file; + return false; + } + + Translator t(info); + + file->tag()->setTitle(t["Title"]); + file->tag()->setArtist(t["Artist"]); + file->tag()->setAlbum(t["Album"]); + file->tag()->setYear(t.toInt("Date")); + file->tag()->setComment(t["Comment"]); + file->tag()->setTrack(t.toInt("Tracknumber")); + file->tag()->setGenre(t["Genre"]); + + file->save(); + + delete file; + return true; +} + +QValidator* KMpcPlugin::createValidator( const QString&, + const QString &group, const QString &key, + QObject* parent, const char* name) const +{ + if(key == "Tracknumber" || key == "Date") + { + return new QIntValidator(0, 9999, parent, name); + } + else + return new QRegExpValidator(QRegExp(".*"), parent, name); +} + +#include "kfile_mpc.moc" diff --git a/kfile-plugins/mpc/kfile_mpc.desktop b/kfile-plugins/mpc/kfile_mpc.desktop new file mode 100644 index 00000000..c35f1bde --- /dev/null +++ b/kfile-plugins/mpc/kfile_mpc.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +Type=Service +Name=Musepack Info +Name[bg]=Информация за Musepack +Name[br]=Titouroù Musepack +Name[bs]=Musepack informacije +Name[ca]=Informació Musepack +Name[cs]=Musepack info +Name[de]=Musepack-Info +Name[el]=Πληροφορίες Musepack +Name[eo]=epack-informo +Name[es]=Info Musepack +Name[et]=Musepacki info +Name[eu]=Musepack informazioa +Name[fa]=اطلاعات Musepack +Name[fi]=Musepack-tiedot +Name[fr]=Informations Musepack +Name[ga]=Eolas faoi Musepack +Name[gl]=Información Musepack +Name[he]=מידע Musepack +Name[hu]=Musepack-jellemzők +Name[is]=Musepack upplýsingar +Name[it]=Informazioni Musepack +Name[ja]=Musepack 情報 +Name[kk]=Musepack мәліметі +Name[km]=ព័ត៌មាន Musepack +Name[ko]=Musepack 정보 +Name[lt]=Musepack informacija +Name[mk]=Musepack информации +Name[nb]=Musepack-info +Name[nds]=Musepack-Info +Name[ne]=म्युजप्याक सूचना +Name[nl]=Musepack-informatie +Name[nn]=Musepack-info +Name[pa]=Musepack ਜਾਣਕਾਰੀ +Name[pl]=Informacja Musepack +Name[pt]=Informação do Musepack +Name[pt_BR]=Informações sobre Musepack +Name[ro]=Informaţii Musepack +Name[ru]=Сведения о Musepack +Name[sl]=Podatki o Musepack +Name[sr]=Информације о Musepack-у +Name[sr@Latn]=Informacije o Musepack-u +Name[sv]=Musepack-information +Name[ta]=MP3 தகவல் +Name[th]=ข้อมูล Musepack +Name[tr]=MusePack Bilgisi +Name[uk]=Інформація по Musepack +Name[zh_CN]=Musepack 信息 +Name[zh_HK]=Musepack 資訊 +Name[zh_TW]=Musepack 資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_mpc +MimeType=audio/x-musepack +PreferredGroups=Comment,Technical +PreferredItems=Title,Artist,Album,Tracknumber,Genre,Bitrate,Length,Channels, Date,Description,Organization,Location,Copyright diff --git a/kfile-plugins/mpc/kfile_mpc.h b/kfile-plugins/mpc/kfile_mpc.h new file mode 100644 index 00000000..88aabbb4 --- /dev/null +++ b/kfile-plugins/mpc/kfile_mpc.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + * Copyright (C) 2004 Allan Sandfeld Jensen + * + * Originally based upon the kfile_ogg plugin: + * Copyright (C) 2001, 2002 Rolf Magnus + * Interfacing to TagLib is copied from kfile_mp3 plugin: + * Copyright (C) 2003 Scott Wheeler + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __KFILE_MPC_H__ +#define __KFILE_MPC_H__ + +#include + +class QString; +class QStringList; + +class KMpcPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KMpcPlugin( QObject *parent, const char *name, const QStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); + virtual bool writeInfo( const KFileMetaInfo& info ) const; + virtual QValidator* createValidator( const QString& mimetype, + const QString &group, + const QString &key, + QObject* parent, const char* name) const; +}; + + +#endif -- cgit v1.2.1