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

#include "iractions.h"
#include "iraction.h"

void IRActions::loadFromConfig(KConfig &theConfig)
{
	clear();
	int numBindings = theConfig.readNumEntry("Bindings");
	for(int i = 0; i < numBindings; i++)
		addAction(IRAction().loadFromConfig(theConfig, i));
}

void IRActions::purgeAllBindings(KConfig &theConfig)
{
	int numBindings = theConfig.readNumEntry("Bindings");
	for(int i = 0; i < numBindings; i++)
	{	TQString Binding = "Binding" + TQString().setNum(i);
		int numArguments = theConfig.readNumEntry(Binding + "Arguments");
		for(int j = 0; j < numArguments; j++)
		{	theConfig.deleteEntry(Binding + "Argument" + TQString().setNum(j));
			theConfig.deleteEntry(Binding + "ArgumentType" + TQString().setNum(j));
		}
		theConfig.deleteEntry(Binding + "Arguments"); theConfig.deleteEntry(Binding + "Program");
		theConfig.deleteEntry(Binding + "Object"); theConfig.deleteEntry(Binding + "Method");
		theConfig.deleteEntry(Binding + "Remote"); theConfig.deleteEntry(Binding + "Button");
		theConfig.deleteEntry(Binding + "Repeat"); theConfig.deleteEntry(Binding + "Mode");
	}
}

void IRActions::saveToConfig(KConfig &theConfig)
{
	int index = 0;
	purgeAllBindings(theConfig);
	for(iterator i = begin(); i != end(); ++i,index++)
		(*i).saveToConfig(theConfig, index);
	theConfig.writeEntry("Bindings", index);
}

IRAIt IRActions::addAction(const IRAction &theAction)
{
	return append(theAction);
}

IRAItList IRActions::findByButton(const TQString &remote, const TQString &button)
{
	IRAItList ret;
	for(iterator i = begin(); i != end(); ++i)
		if((*i).remote() == remote && (*i).button() == button)
			ret += i;
	return ret;
}

void IRActions::renameMode(const Mode &mode, const TQString &to)
{
	for(iterator i = begin(); i != end(); ++i)
	{	if((*i).remote() == mode.remote() && (*i).mode() == mode.name()) (*i).setMode(to);
		if((*i).isModeChange() && (*i).modeChange() == mode.name()) (*i).setModeChange(to);
	}
}

IRAItList IRActions::findByMode(const Mode &mode)
{
	IRAItList ret;
	for(iterator i = begin(); i != end(); ++i)
		if((*i).remote() == mode.remote() && (*i).mode() == mode.name()) ret += i;
	return ret;
}

IRAItList IRActions::findByModeButton(const Mode &mode, const TQString &button)
{
	IRAItList ret;
	for(iterator i = begin(); i != end(); ++i)
		if((*i).remote() == mode.remote() && (*i).mode() == mode.name() && (*i).button() == button)
			ret += i;
	return ret;
}