summaryrefslogtreecommitdiffstats
path: root/kdelirc/kdelirc/remoteserver.cpp
blob: 04fb290629075397ae55a10abb12d14fadc9c962 (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
//
//
// C++ Implementation: $MODULE$
//
// Description:
//
//
// Author: Gav Wood <gav@kde.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include <tqfile.h>
#include <tqxml.h>

#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdebug.h>

#include "remoteserver.h"

RemoteServer *RemoteServer::theInstance = 0;

RemoteServer::RemoteServer()
{
	theRemotes.setAutoDelete(true);
	loadRemotes();
}

RemoteServer::~RemoteServer()
{
}

void RemoteServer::loadRemotes()
{
	TQStringList theFiles = KGlobal::dirs()->findAllResources("data", "remotes/*.remote.xml");
	for(TQStringList::iterator i = theFiles.begin(); i != theFiles.end(); ++i)
	{	kdDebug() << "Found data file: " << *i << endl;
		Remote *p = new Remote();
		p->loadFromFile(*i);
		theRemotes.insert(p->id(), p);
	}
}

Remote::Remote()
{
	theButtons.setAutoDelete(true);
}

Remote::~Remote()
{
}

void Remote::loadFromFile(const TQString &fileName)
{
	charBuffer = "";
	curRB = 0;

	TQFile xmlFile(fileName);
	TQXmlInputSource source(TQT_TQIODEVICE(&xmlFile));
	TQXmlSimpleReader reader;
	reader.setContentHandler(this);
	reader.parse(source);
}

bool Remote::characters(const TQString &data)
{
	charBuffer += data;
	return true;
}

bool Remote::startElement(const TQString &, const TQString &, const TQString &name, const TQXmlAttributes &attributes)
{
	if(name == "remote")
		theId = theName = attributes.value("id");
	else if(name == "button")
	{
		curRB = new RemoteButton();
		curRB->setId(attributes.value("id"));
		curRB->setClass(attributes.value("id"));
		if(attributes.index("class") > -1)
			curRB->setClass(attributes.value("class"));
		curRB->setParameter(attributes.value("parameter"));
		curRB->setName(attributes.value("id"));
	}

	charBuffer = "";
	return true;
}

bool Remote::endElement(const TQString &, const TQString &, const TQString &name)
{
	if(name == "name")
		if(curRB)
			curRB->setName(charBuffer);
		else
			theName = charBuffer;
	else if(name == "author")
		theAuthor = charBuffer;
	else if(name == "button")
	{
		theButtons.insert(curRB->id(), curRB);
		curRB = 0;
	}

	charBuffer = "";
	return true;
}