summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/wav
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/wav
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/wav')
-rw-r--r--kfile-plugins/wav/Makefile.am22
-rw-r--r--kfile-plugins/wav/kfile_wav.cpp173
-rw-r--r--kfile-plugins/wav/kfile_wav.desktop67
-rw-r--r--kfile-plugins/wav/kfile_wav.h37
4 files changed, 299 insertions, 0 deletions
diff --git a/kfile-plugins/wav/Makefile.am b/kfile-plugins/wav/Makefile.am
new file mode 100644
index 00000000..0a533384
--- /dev/null
+++ b/kfile-plugins/wav/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for wav file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_wav.h
+
+kde_module_LTLIBRARIES = kfile_wav.la
+
+kfile_wav_la_SOURCES = kfile_wav.cpp
+kfile_wav_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_wav_la_LIBADD = $(LIB_KIO)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) kfile_wav.cpp -o $(podir)/kfile_wav.pot
+
+services_DATA = kfile_wav.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kfile-plugins/wav/kfile_wav.cpp b/kfile-plugins/wav/kfile_wav.cpp
new file mode 100644
index 00000000..4eda7bce
--- /dev/null
+++ b/kfile-plugins/wav/kfile_wav.cpp
@@ -0,0 +1,173 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Ryan Cumming <bodnar42@phalynx.dhs.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_wav.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>
+
+#if !defined(__osf__)
+#include <inttypes.h>
+#else
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#endif
+
+typedef KGenericFactory<KWavPlugin> WavFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_wav, WavFactory( "kfile_wav" ))
+
+KWavPlugin::KWavPlugin(QObject *parent, const char *name,
+ const QStringList &args)
+
+ : KFilePlugin(parent, name, args)
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo( "audio/x-wav" );
+
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+
+ // "the" group
+ group = addGroupInfo(info, "Technical", i18n("Technical Details"));
+
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ item = addItemInfo(group, "Sample Size", i18n("Sample Size"), QVariant::Int);
+ setSuffix(item, i18n(" bits"));
+
+ 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, "Length", i18n("Length"), QVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Cummulative);
+ setUnit(item, KFileMimeTypeInfo::Seconds);
+}
+
+bool KWavPlugin::readInfo( KFileMetaInfo& info, uint /*what*/)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ QFile file(info.path());
+
+ uint32_t format_size;
+ uint16_t format_tag;
+ uint16_t channel_count;
+ uint32_t sample_rate;
+ uint32_t bytes_per_second;
+ uint16_t bytes_per_sample;
+ uint16_t sample_size;
+ uint32_t data_size;
+ uint32_t unknown_chunk_size;
+ uint16_t unknown_chunk16;
+ bool have_fmt = false;
+ bool have_data = false;
+ QIODevice::Offset file_length;
+
+ const char *riff_signature = "RIFF";
+ const char *wav_signature = "WAVE";
+ const char *fmt_signature = "fmt ";
+ const char *data_signature = "data";
+ char signature_buffer[4];
+
+ if (!file.open(IO_ReadOnly))
+ {
+ kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl;
+ return false;
+ }
+
+ file_length = file.size() - 100; // a bit of insurance
+ QDataStream dstream(&file);
+
+ // WAV files are little-endian
+ dstream.setByteOrder(QDataStream::LittleEndian);
+
+ // Read and verify the RIFF signature
+ dstream.readRawBytes(signature_buffer, 4);
+ if (memcmp(signature_buffer, riff_signature, 4))
+ return false;
+
+ // Skip the next bit (total file size, pretty useless)
+ file.at(8);
+
+ // Read and verify the WAVE signature
+ dstream.readRawBytes(signature_buffer, 4);
+ if (memcmp(signature_buffer, wav_signature, 4))
+ return false;
+
+ // pretty dumb scanner, but better than what we had!
+ do
+ {
+ dstream.readRawBytes(signature_buffer, 4);
+ if (!memcmp(signature_buffer, fmt_signature, 4)) {
+ dstream >> format_size;
+ dstream >> format_tag;
+ dstream >> channel_count;
+ dstream >> sample_rate;
+ dstream >> bytes_per_second;
+ dstream >> bytes_per_sample;
+ dstream >> sample_size;
+ have_fmt = true;
+ if ( format_size > 16 ) {
+ for (unsigned int i = 0; i < (format_size-16+1)/2; i++)
+ dstream >> unknown_chunk16;
+ }
+ } else if (!memcmp(signature_buffer, data_signature, 4)) {
+ dstream >> data_size;
+ have_data = true;
+ } else {
+ dstream >> unknown_chunk_size;
+ for (unsigned int i = 0; i < (unknown_chunk_size+1)/2; i++)
+ dstream >> unknown_chunk16;
+ }
+ if (have_data && have_fmt)
+ break;
+ } while (file.at() < file_length);
+
+ if ( (!have_data) || (!have_fmt) )
+ return false;
+
+ // These values are downright illegal
+ if ((!channel_count) || (!bytes_per_second))
+ return false;
+
+ KFileMetaInfoGroup group = appendGroup(info, "Technical");
+
+
+ appendItem(group, "Sample Size", int(sample_size));
+ appendItem(group, "Sample Rate", int(sample_rate));
+ appendItem(group, "Channels", int(channel_count));
+ unsigned int wav_seconds = data_size / bytes_per_second;
+ appendItem(group, "Length", int(wav_seconds));
+
+ return true;
+}
+
+#include "kfile_wav.moc"
diff --git a/kfile-plugins/wav/kfile_wav.desktop b/kfile-plugins/wav/kfile_wav.desktop
new file mode 100644
index 00000000..c25e8b8f
--- /dev/null
+++ b/kfile-plugins/wav/kfile_wav.desktop
@@ -0,0 +1,67 @@
+[Desktop Entry]
+Type=Service
+Name=WAV Info
+Name[af]=Wav Inligting
+Name[ar]=معلومات WAV
+Name[bg]=Информация за WAV
+Name[br]=Titouroù WAV
+Name[bs]=WAV informacije
+Name[ca]=Informació WAV
+Name[cs]=WAV info
+Name[cy]=Gwybodaeth WAV
+Name[da]=WAV-info
+Name[de]=WAV-Info
+Name[el]=Πληροφορίες WAV
+Name[eo]=WAV-informo
+Name[es]=Info WAV
+Name[et]=WAV info
+Name[eu]=WAV informazioa
+Name[fa]=اطلاعات WAV
+Name[fi]=WAV-tiedot
+Name[fr]=Informations Wave
+Name[gl]=Información WAV
+Name[he]=מידע WAV
+Name[hi]=WAV जानकारी
+Name[hr]=Informacije o WAV datoteci
+Name[hu]=WAV-jellemzők
+Name[is]=WAV upplýsingar
+Name[it]=Informazioni WAV
+Name[ja]=WAV 情報
+Name[kk]=WAV мәліметі
+Name[km]=ព័ត៌មាន WAV
+Name[ko]=WAV 정보
+Name[lt]=WAV informacija
+Name[mk]=WAV информации
+Name[nb]=WAV informasjon
+Name[nds]=WAV-Info
+Name[ne]=वाभ सूचना
+Name[nl]=WAV-informatie
+Name[nn]=WAV-info
+Name[pa]=WAV ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o pliku WAV
+Name[pt]=Informação do WAV
+Name[pt_BR]=Informação sobre WAV
+Name[ro]=Informaţii WAV
+Name[ru]=Сведения о WAV
+Name[se]=WAV-dieđut
+Name[sl]=Podatki o WAV
+Name[sr]=Информације о WAV-у
+Name[sr@Latn]=Informacije o WAV-u
+Name[sv]=Wav-information
+Name[ta]=WAV தகவல்
+Name[tg]=WAV Ахборот
+Name[th]=ข้อมูล WAV
+Name[tr]=WAV Bilgisi
+Name[uk]=Інформація по WAV
+Name[uz]=WAV haqida maʼlumot
+Name[uz@cyrillic]=WAV ҳақида маълумот
+Name[xh]=MAV Ulwazi
+Name[zh_CN]=WAV 信息
+Name[zh_HK]=WAV 資訊
+Name[zh_TW]=WAV 資訊
+Name[zu]=Ulwazi lwe WAV
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_wav
+MimeType=audio/x-wav
+PreferredGrous=Technical
+PreferredItems=Length,Sample Rate,Sample Size,Channels
diff --git a/kfile-plugins/wav/kfile_wav.h b/kfile-plugins/wav/kfile_wav.h
new file mode 100644
index 00000000..318ee2f5
--- /dev/null
+++ b/kfile-plugins/wav/kfile_wav.h
@@ -0,0 +1,37 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Ryan Cumming <bodnar42@phalynx.dhs.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_WAV_H__
+#define __KFILE_WAV_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+
+class KWavPlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ KWavPlugin( QObject *parent, const char *name, const QStringList& args );
+
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+};
+
+#endif