[1f6d2f]: libkwave / CodecBase.cpp Maximize Restore History

Download this file

CodecBase.cpp    147 lines (124 with data), 5.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*************************************************************************
CodecBase.cpp - base class for Encoder and Decoder
-------------------
begin : Mon Mar 11 2002
copyright : (C) 2002 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include <QString>
#include <QStringList>
#include <QtGlobal>
#include <kmimetype.h>
#include <kfile.h>
#include <kurl.h>
#include "CodecBase.h"
/***************************************************************************/
Kwave::CodecBase::CodecBase()
:m_supported_mime_types(), m_supported_compression_types()
{
}
/***************************************************************************/
Kwave::CodecBase::~CodecBase()
{
m_supported_mime_types.clear();
m_supported_compression_types.clear();
}
/***************************************************************************/
void Kwave::CodecBase::addMimeType(const QString &name,
const QString &description,
const QString &patterns)
{
// check for duplicates
if (supports(name)) return;
Kwave::CodecBase::MimeType type;
KMimeType::Ptr t = KMimeType::mimeType(name);
if (!t || (t && t->isDefault())) {
// qWarning("mime type '%s' not registered, using built-in!",
// name.toLocal8Bit().data());
type.name = name;
type.description = description;
type.patterns = patterns.split("; ", QString::SkipEmptyParts);
} else {
type.description = t->comment();
type.patterns = t->patterns();
if (t->name() != name) {
// type has been translated (maybe un-alias'ed)
// manually add the original name
type.name = name;
m_supported_mime_types.append(type);
}
if (!supports(t->name())) {
// new type or new alias
type.name = t->name();
}
}
m_supported_mime_types.append(type);
}
/***************************************************************************/
void Kwave::CodecBase::addCompression(int compression)
{
if (m_supported_compression_types.contains(compression)) return;
m_supported_compression_types.append(compression);
qSort(m_supported_compression_types);
}
/***************************************************************************/
bool Kwave::CodecBase::supports(const KMimeType &mimetype)
{
return supports(mimetype.name());
}
/***************************************************************************/
bool Kwave::CodecBase::supports(const QString &mimetype_name)
{
foreach (const Kwave::CodecBase::MimeType &mime, m_supported_mime_types) {
if (mime.name == mimetype_name) return true;
}
return false;
}
/***************************************************************************/
QStringList Kwave::CodecBase::extensions(const QString &mimetype_name) const
{
foreach (const Kwave::CodecBase::MimeType &mime, m_supported_mime_types) {
if (mime.name == mimetype_name) {
return mime.patterns;
}
}
return QStringList();
}
/***************************************************************************/
const QList<Kwave::CodecBase::MimeType> Kwave::CodecBase::mimeTypes()
{
return m_supported_mime_types;
}
/***************************************************************************/
const QList<int> Kwave::CodecBase::compressionTypes()
{
return m_supported_compression_types;
}
/***************************************************************************/
QString Kwave::CodecBase::whatContains(const KUrl &url)
{
// get the extension of the file
QFileInfo file(url.fileName());
QString suffix = file.suffix();
if (!suffix.length()) return KMimeType::defaultMimeType();
suffix = "*."+suffix;
// try to find in the list of supported mime types
QListIterator<Kwave::CodecBase::MimeType> it(m_supported_mime_types);
while (it.hasNext()) {
Kwave::CodecBase::MimeType mime_type = it.next();
if (mime_type.patterns.contains(suffix))
return mime_type.name;
}
return KMimeType::defaultMimeType();
}
/***************************************************************************/
/***************************************************************************/