summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/mp3
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch)
tree9047cf9e6b5c43878d5bf82660adae77ceee097a /kfile-plugins/mp3
downloadtdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz
tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip
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
Diffstat (limited to 'kfile-plugins/mp3')
-rw-r--r--kfile-plugins/mp3/Makefile.am22
-rw-r--r--kfile-plugins/mp3/configure.in.in1
-rw-r--r--kfile-plugins/mp3/kfile_mp3.cpp307
-rw-r--r--kfile-plugins/mp3/kfile_mp3.desktop70
-rw-r--r--kfile-plugins/mp3/kfile_mp3.h41
5 files changed, 441 insertions, 0 deletions
diff --git a/kfile-plugins/mp3/Makefile.am b/kfile-plugins/mp3/Makefile.am
new file mode 100644
index 00000000..91b43e73
--- /dev/null
+++ b/kfile-plugins/mp3/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for mp3 file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes) $(taglib_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_mp3.h
+
+kde_module_LTLIBRARIES = kfile_mp3.la
+
+kfile_mp3_la_SOURCES = kfile_mp3.cpp
+kfile_mp3_la_LDFLAGS = $(all_libraries) $(taglib_libs) -module $(KDE_PLUGIN)
+kfile_mp3_la_LIBADD = $(LIB_KIO)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) kfile_mp3.cpp -o $(podir)/kfile_mp3.pot
+
+services_DATA = kfile_mp3.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kfile-plugins/mp3/configure.in.in b/kfile-plugins/mp3/configure.in.in
new file mode 100644
index 00000000..d04bc223
--- /dev/null
+++ b/kfile-plugins/mp3/configure.in.in
@@ -0,0 +1 @@
+AM_CONDITIONAL(include_mp3_SUBDIR, test "x$have_taglib" = xyes)
diff --git a/kfile-plugins/mp3/kfile_mp3.cpp b/kfile-plugins/mp3/kfile_mp3.cpp
new file mode 100644
index 00000000..343b37cd
--- /dev/null
+++ b/kfile-plugins/mp3/kfile_mp3.cpp
@@ -0,0 +1,307 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org>
+ * Copyright (C) 2002 Ryan Cumming <bodnar42@phalynx.dhs.org>
+ * Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>
+ *
+ * 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 "config.h"
+
+#include "kfile_mp3.h"
+
+#include <kprocess.h>
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <kstringvalidator.h>
+#include <kdebug.h>
+
+#include <qdict.h>
+#include <qvalidator.h>
+#include <qcstring.h>
+#include <qfile.h>
+#include <qdatetime.h>
+
+#include <tstring.h>
+#include <tag.h>
+#include <mpegfile.h>
+#include <id3v1genres.h>
+#include <id3v2framefactory.h>
+
+typedef KGenericFactory<KMp3Plugin> Mp3Factory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_mp3, Mp3Factory( "kfile_mp3" ))
+
+KMp3Plugin::KMp3Plugin(QObject *parent, const char *name, const QStringList &args)
+ : KFilePlugin(parent, name, args)
+{
+ kdDebug(7034) << "mp3 plugin\n";
+
+ KFileMimeTypeInfo *info = addMimeTypeInfo("audio/x-mp3");
+
+ // id3 group
+
+ KFileMimeTypeInfo::GroupInfo *group = addGroupInfo(info, "id3", i18n("ID3 Tag"));
+
+ setAttributes(group, KFileMimeTypeInfo::Addable |
+ KFileMimeTypeInfo::Removable);
+
+ KFileMimeTypeInfo::ItemInfo *item;
+
+ item = addItemInfo(group, "Title", i18n("Title"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+ setHint(item, KFileMimeTypeInfo::Name);
+
+ item = addItemInfo(group, "Artist", i18n("Artist"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+ setHint(item, KFileMimeTypeInfo::Author);
+
+ item = addItemInfo(group, "Album", i18n("Album"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+
+ item = addItemInfo(group, "Date", i18n("Year"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+
+ item = addItemInfo(group, "Comment", i18n("Comment"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+ setHint(item, KFileMimeTypeInfo::Description);
+
+ item = addItemInfo(group, "Tracknumber", i18n("Track"), QVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+
+ item = addItemInfo(group, "Genre", i18n("Genre"), QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+
+ // technical group
+
+ group = addGroupInfo(info, "Technical", i18n("Technical Details"));
+
+ item = addItemInfo(group, "Version", i18n("Version"), QVariant::Int);
+ setPrefix(item, i18n("MPEG "));
+
+ item = addItemInfo(group, "Layer", i18n("Layer"), QVariant::Int);
+ item = addItemInfo(group, "CRC", i18n("CRC"), QVariant::Bool);
+ item = addItemInfo(group, "Bitrate", i18n("Bitrate"), QVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Averaged);
+ setHint(item, KFileMimeTypeInfo::Bitrate);
+ setSuffix(item, i18n(" kbps"));
+
+ item = addItemInfo(group, "Sample Rate", i18n("Sample Rate"), QVariant::Int);
+ setSuffix(item, i18n("Hz"));
+
+ item = addItemInfo(group, "Channels", i18n("Channels"), QVariant::Int);
+ item = addItemInfo(group, "Copyright", i18n("Copyright"), QVariant::Bool);
+ item = addItemInfo(group, "Original", i18n("Original"), QVariant::Bool);
+ item = addItemInfo(group, "Length", i18n("Length"), QVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Cummulative);
+ setUnit(item, KFileMimeTypeInfo::Seconds);
+ item = addItemInfo(group, "Emphasis", i18n("Emphasis"), QVariant::String);
+}
+
+bool KMp3Plugin::readInfo(KFileMetaInfo &info, uint what)
+{
+ kdDebug(7034) << "mp3 plugin readInfo\n";
+
+ bool readId3 = false;
+ bool readTech = false;
+
+ typedef enum KFileMetaInfo::What What;
+
+ if(what & (KFileMetaInfo::Fastest |
+ KFileMetaInfo::DontCare |
+ KFileMetaInfo::ContentInfo))
+ {
+ readId3 = true;
+ }
+
+ if(what & (KFileMetaInfo::Fastest |
+ KFileMetaInfo::DontCare |
+ KFileMetaInfo::TechnicalInfo))
+ {
+ readTech = true;
+ }
+
+ if(!readId3 && !readTech)
+ return true;
+
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ TagLib::MPEG::File file(QFile::encodeName(info.path()).data(), readTech);
+
+ if(!file.isOpen())
+ {
+ kdDebug(7034) << "Couldn't open " << file.name() << endl;
+ return false;
+ }
+
+ if(readId3)
+ {
+ KFileMetaInfoGroup id3group = appendGroup(info, "id3");
+
+ 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;
+
+ QString title = TStringToQString(file.tag()->title()).stripWhiteSpace();
+ if (!title.isEmpty())
+ appendItem(id3group, "Title", title);
+ QString artist = TStringToQString(file.tag()->artist()).stripWhiteSpace();
+ if (!artist.isEmpty())
+ appendItem(id3group, "Artist", artist);
+ QString album = TStringToQString(file.tag()->album()).stripWhiteSpace();
+ if (!album.isEmpty())
+ appendItem(id3group, "Album", album);
+ appendItem(id3group, "Date", date);
+ QString comment = TStringToQString(file.tag()->comment()).stripWhiteSpace();
+ if (!comment.isEmpty())
+ appendItem(id3group, "Comment", comment);
+ appendItem(id3group, "Tracknumber", track);
+ QString genre = TStringToQString(file.tag()->genre()).stripWhiteSpace();
+ if (!genre.isEmpty())
+ appendItem(id3group, "Genre", genre);
+ }
+
+ if(readTech)
+ {
+ KFileMetaInfoGroup techgroup = appendGroup(info, "Technical");
+
+ QString version;
+ switch(file.audioProperties()->version())
+ {
+ case TagLib::MPEG::Header::Version1:
+ version = "1.0";
+ break;
+ case TagLib::MPEG::Header::Version2:
+ version = "2.0";
+ break;
+ case TagLib::MPEG::Header::Version2_5:
+ version = "2.5";
+ break;
+ }
+
+ static const int dummy = 0; // QVariant's bool constructor requires a dummy int value.
+
+ // CRC and Emphasis aren't yet implemented in TagLib (not that I think anyone cares)
+
+ appendItem(techgroup, "Version", version);
+ appendItem(techgroup, "Layer", file.audioProperties()->layer());
+ // appendItem(techgroup, "CRC", file.audioProperties()->crc());
+ appendItem(techgroup, "Bitrate", file.audioProperties()->bitrate());
+ appendItem(techgroup, "Sample Rate", file.audioProperties()->sampleRate());
+ appendItem(techgroup, "Channels", file.audioProperties()->channels());
+ appendItem(techgroup, "Copyright", QVariant(file.audioProperties()->isCopyrighted(), dummy));
+ appendItem(techgroup, "Original", QVariant(file.audioProperties()->isOriginal(), dummy));
+ appendItem(techgroup, "Length", file.audioProperties()->length());
+ // appendItem(techgroup, "Emphasis", file.audioProperties()->empahsis());
+ }
+
+ kdDebug(7034) << "reading finished\n";
+
+ 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["id3"][key].value().toString());
+ }
+ int toInt(const char *key) const
+ {
+ return m_info["id3"][key].value().toInt();
+ }
+private:
+ const KFileMetaInfo &m_info;
+};
+
+bool KMp3Plugin::writeInfo(const KFileMetaInfo &info) const
+{
+ TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8);
+ TagLib::MPEG::File file(QFile::encodeName(info.path()).data(), false);
+
+ if(!file.isOpen() || !TagLib::File::isWritable(file.name()))
+ {
+ kdDebug(7034) << "couldn't open " << info.path() << endl;
+ 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();
+
+ return true;
+}
+
+/**
+ * A validator that will suggest a list of strings, but allow for free form
+ * strings as well.
+ */
+
+class ComboValidator : public KStringListValidator
+{
+public:
+ ComboValidator(const QStringList &list, bool rejecting,
+ bool fixupEnabled, QObject *parent, const char *name) :
+ KStringListValidator(list, rejecting, fixupEnabled, parent, name)
+ {
+
+ }
+
+ virtual QValidator::State validate(QString &, int &) const
+ {
+ return QValidator::Acceptable;
+ }
+};
+
+QValidator *KMp3Plugin::createValidator(const QString & /* mimetype */,
+ const QString &group, const QString &key,
+ QObject *parent, const char *name) const
+{
+ kdDebug(7034) << "making a validator for " << group << "/" << key << endl;
+
+ if(key == "Tracknumber" || key == "Date")
+ {
+ return new QIntValidator(0, 9999, parent, name);
+ }
+
+ if(key == "Genre")
+ {
+ QStringList l;
+ TagLib::StringList genres = TagLib::ID3v1::genreList();
+ for(TagLib::StringList::ConstIterator it = genres.begin(); it != genres.end(); ++it)
+ {
+ l.append(TStringToQString((*it)));
+ }
+ return new ComboValidator(l, false, true, parent, name);
+ }
+
+ return 0;
+}
+
+#include "kfile_mp3.moc"
diff --git a/kfile-plugins/mp3/kfile_mp3.desktop b/kfile-plugins/mp3/kfile_mp3.desktop
new file mode 100644
index 00000000..90527766
--- /dev/null
+++ b/kfile-plugins/mp3/kfile_mp3.desktop
@@ -0,0 +1,70 @@
+[Desktop Entry]
+Type=Service
+Name=MP3 Info
+Name[af]=Mp3 Inligting
+Name[ar]=معلومات MP3
+Name[bg]=Информация за MP3
+Name[bn]=এম-পি-৩ (MP3) তথ্য
+Name[br]=Titouroù MP3
+Name[bs]=MP3 informacije
+Name[ca]=Informació MP3
+Name[cs]=MP3 info
+Name[cy]=Gwybodaeth MP3
+Name[da]=MP3-info
+Name[de]=MP3-Info
+Name[el]=Πληροφορίες MP3
+Name[eo]=MP3-informo
+Name[es]=Info MP3
+Name[et]=MP3 info
+Name[eu]=MP3 informazioa
+Name[fa]=اطلاعات MP3
+Name[fi]=MP3-tiedot
+Name[fr]=Informations Mpeg3
+Name[gl]=Información MP3
+Name[he]=מידע MP3
+Name[hi]=MP3 जानकारी
+Name[hr]=Informacije o MP3 datoteci
+Name[hu]=MP3-jellemzők
+Name[is]=MP3 upplýsingar
+Name[it]=Informazioni MP3
+Name[ja]=MP3 情報
+Name[kk]=MP3 мәліметі
+Name[km]=ព័ត៌មាន MP3
+Name[ko]=MP3 정보
+Name[lt]=MP3 informacija
+Name[mk]=MP3 информации
+Name[nb]=MP3 informasjon
+Name[nds]=MP3-Info
+Name[ne]=MP3 सूचना
+Name[nl]=MP3-informatie
+Name[nn]=MP3-info
+Name[pa]=MP3 ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o pliku MP3
+Name[pt]=Informação do MP3
+Name[pt_BR]=Informações sobre MP3
+Name[ro]=Informaţii MP3
+Name[ru]=Сведения о MP3
+Name[rw]=Amakuru MP3
+Name[se]=MP3-dieđut
+Name[sl]=Podatki o MP3
+Name[sr]=Информације о MP3-ју
+Name[sr@Latn]=Informacije o MP3-ju
+Name[sv]=MP3-information
+Name[ta]=MP3 தகவல்
+Name[tg]=MP3 Ахборот
+Name[th]=ข้อมูล MP3
+Name[tr]=MP3 Bilgisi
+Name[uk]=Інформація по MP3
+Name[uz]=MP3 haqida maʼlumot
+Name[uz@cyrillic]=MP3 ҳақида маълумот
+Name[wa]=Infôrmåcion MP3
+Name[xh]=MP3 ulwazi
+Name[zh_CN]=MP3 信息
+Name[zh_HK]=MP3 資訊
+Name[zh_TW]=MP3 資訊
+Name[zu]=Ulwazi lwe-MP3
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_mp3
+MimeType=audio/x-mp3
+PreferredGroups=id3,Technical
+PreferredItems=Title,Artist,Album,Tracknumber,Genre,Bitrate,Length,Date,Comment,Sample Rate,Channels,Version,Layer,Copyright,Original,CRC
diff --git a/kfile-plugins/mp3/kfile_mp3.h b/kfile-plugins/mp3/kfile_mp3.h
new file mode 100644
index 00000000..6479b52f
--- /dev/null
+++ b/kfile-plugins/mp3/kfile_mp3.h
@@ -0,0 +1,41 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org>
+ *
+ * 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_MP3_H__
+#define __KFILE_MP3_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+
+class KMp3Plugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ KMp3Plugin(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