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
|
#include "formatinfoloader.h"
#include <tqfile.h>
#include <klocale.h>
#include <kglobal.h>
FormatInfo::FormatInfo()
{}
FormatInfo::~FormatInfo()
{}
FormatInfoLoader::FormatInfoLoader()
{}
FormatInfoLoader::~FormatInfoLoader()
{}
bool FormatInfoLoader::verifyFile( TQString fileName )
{
TQFile opmlFile( fileName );
if( !opmlFile.open( IO_ReadOnly ) ) {
return false;
}
if( !domTree.setContent( &opmlFile ) ) {
return false;
}
opmlFile.close();
TQDomElement root = domTree.documentElement();
if( root.attribute("type") == "format_info" ) return true;
return false;
}
FormatInfo* FormatInfoLoader::loadFile( TQString fileName )
{
int t_int;
float t_float;
TQString t_str;
FormatInfo* plugin = new FormatInfo();
plugin->mime_types = "application/octet-stream"; // if something goes wrong, we can see that by looking at plugin->mimetype
TQFile opmlFile( fileName );
if( !opmlFile.open( IO_ReadOnly ) ) {
return plugin;
}
if( !domTree.setContent( &opmlFile ) ) {
return plugin;
}
opmlFile.close();
TQString language = KGlobal::locale()->languagesTwoAlpha().first();
TQDomElement root = domTree.documentElement();
if( root.attribute("type") != "format_info" ) return plugin;
TQDomNode node;
node = root.firstChild();
while( !node.isNull() ) {
if( node.isElement() && node.nodeName() == "data" ) {
plugin->mime_types = TQStringList::split( ',',node.toElement().attribute("mime_types","application/octet-stream") );
plugin->extensions = TQStringList::split( ',',node.toElement().attribute("extensions") );
plugin->description = node.toElement().attribute("description_"+language);
if( plugin->description.isEmpty() ) plugin->description = node.toElement().attribute("description");
plugin->urls = TQStringList::split( ',',node.toElement().attribute("urls_"+language) );
if( plugin->urls.isEmpty() ) plugin->urls = TQStringList::split( ',',node.toElement().attribute("urls") );
TQStringList compressionTypeList = TQStringList::split( ',',node.toElement().attribute("compression_type") );
plugin->compressionType = (FormatInfo::CompressionType)0x0000;
for( TQStringList::Iterator it = compressionTypeList.begin(); it != compressionTypeList.end(); ++it ) {
if( *it == "lossy" ) plugin->compressionType = FormatInfo::CompressionType( plugin->compressionType | FormatInfo::lossy );
else if( *it == "lossless" ) plugin->compressionType = FormatInfo::CompressionType( plugin->compressionType | FormatInfo::lossless );
else if( *it == "hybrid" ) plugin->compressionType = FormatInfo::CompressionType( plugin->compressionType | FormatInfo::hybrid );
}
plugin->size = node.toElement().attribute("size","15000").toInt();
}
node = node.nextSibling();
}
return plugin;
}
|