summaryrefslogtreecommitdiffstats
path: root/src/pluginloader/replaygainpluginloader.cpp
blob: dcc7578707baeb0196ae534cf4138a84ae6ac8ea (plain)
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

#include "replaygainpluginloader.h"

#include <tqfile.h>

#include <tdelocale.h>


ReplayGainPlugin::ReplayGainPlugin()
{}

ReplayGainPlugin::~ReplayGainPlugin()
{}


ReplayGainPluginLoader::ReplayGainPluginLoader()
{}

ReplayGainPluginLoader::~ReplayGainPluginLoader()
{}

int ReplayGainPluginLoader::verifyFile( TQString fileName )
{
    TQFile opmlFile( fileName );
    if( !opmlFile.open( IO_ReadOnly ) ) {
        return -1;
    }
    if( !domTree.setContent( &opmlFile ) ) {
        return -1;
    }
    opmlFile.close();

    TQDomElement root = domTree.documentElement();
    if( root.attribute("type") != "replaygain" ) return -1;
    int version;
    TQDomNode node;
    node = root.firstChild();
    while( !node.isNull() ) {
        if( node.isElement() && node.nodeName() == "info" ) {
            version = node.toElement().attribute("version","0").toInt();
            break;
        }
    }

    return version;
}

ReplayGainPlugin* ReplayGainPluginLoader::loadFile( TQString fileName )
{
    //int t_int;
    //float t_float;
    //TQString t_str;

    ReplayGainPlugin* plugin = new ReplayGainPlugin();
    plugin->info.version = -1; // if something goes wrong, we can see that by looking at plugin->info.version
    plugin->filePathName = fileName;

    TQFile opmlFile( fileName );
    if( !opmlFile.open( IO_ReadOnly ) ) {
        return plugin;
    }
    if( !domTree.setContent( &opmlFile ) ) {
        return plugin;
    }
    opmlFile.close();

    TQDomElement root = domTree.documentElement();
    if( root.attribute("type") != "replaygain" ) return plugin;
    TQDomNode node;//, sub1Node;
    node = root.firstChild();

    while( !node.isNull() ) {
        if( node.isElement() && node.nodeName() == "info" ) {

            plugin->info.name = node.toElement().attribute("name",i18n("Unknown Name"));
            plugin->info.about = node.toElement().attribute("about",i18n("Sorry, no information available!"));
            plugin->info.author = node.toElement().attribute("author",i18n("Unknown Author"));
            plugin->info.version = node.toElement().attribute("version","0").toInt();

        }
        else if( node.isElement() && node.nodeName() == "replaygain" ) {

            plugin->replaygain.rank = node.toElement().attribute("rank","10").toInt();
            plugin->replaygain.bin = node.toElement().attribute( "bin" );
            plugin->replaygain.param = node.toElement().attribute("param");
            plugin->replaygain.silent_param = node.toElement().attribute("silent_param");
            plugin->replaygain.in_files = node.toElement().attribute("in_files");
            plugin->replaygain.output_single = node.toElement().attribute("output_single");
            plugin->replaygain.output_multiple = node.toElement().attribute("output_multiple");
            plugin->replaygain.mime_types = TQStringList::split( ',', node.toElement().attribute("mime_types","application/octet-stream") );
            plugin->replaygain.force = node.toElement().attribute("force");
            plugin->replaygain.skip = node.toElement().attribute("skip");
            plugin->replaygain.track = node.toElement().attribute("track");
            plugin->replaygain.album = node.toElement().attribute("album");
            plugin->replaygain.remove = node.toElement().attribute("remove");

            /*sub1Node = node.toElement().firstChild(); // obsolete
            while( !sub1Node.isNull() ) {
                if( sub1Node.isElement() && sub1Node.nodeName() == "test" ) {

                    if( sub1Node.toElement().attribute("enabled") == "true" ) plugin->replaygain.test.enabled = true;
                    else plugin->replaygain.test.enabled = false;
                    plugin->replaygain.test.param = sub1Node.toElement().attribute("param");
                    plugin->replaygain.test.output_track = sub1Node.toElement().attribute("output_track");
                    plugin->replaygain.test.output_album = sub1Node.toElement().attribute("output_album");

                }
                sub1Node = sub1Node.nextSibling();
            }*/
        }
        node = node.nextSibling();
    }

    return plugin;
}