summaryrefslogtreecommitdiffstats
path: root/kverbos/kverbos/kfeedercontrol.cpp
blob: daa4b9ab6581ca5e049fcae7c906f4bb68bdb928 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
                          kfeedercontrol.cpp  -  description
                             -------------------
    begin                : Wed Apr 17 2002
    copyright            : (C) 2002 by Arnold Kraschinski
    email                : arnold.k67@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 "kfeedercontrol.h"

#include <kapplication.h>
#include <kstandarddirs.h>

KFeederControl::KFeederControl(int ID, bool splash, bool automatic)
{
	QString f = KStandardDirs::findExe("kfeeder");
	QString s;
	s.setNum(ID);
	childFeeder << f;
	if (splash)
		childFeeder << "-s" << "yes";
	else
		childFeeder << "-s" << "no";
	if (automatic)
		childFeeder << "-m" << "automatic";
	else
		childFeeder << "-m" << "triggered";
	if (!childFeeder.start())
		active = false;
	else
	{
		feederID.setNum(childFeeder.pid());
		feederID = "KFeeder-" + feederID;

		dcop = kapp->dcopClient();
		dcop->attach();
		appId = dcop->registerAs("KVerbos");	
		active = true;
	};
}

KFeederControl::~KFeederControl()
{
}

// resets the KFeeder
bool KFeederControl::reset()
{
	if (active)
	{
		QByteArray data;								// "raw support" for data
		QDataStream	arg(data, IO_WriteOnly);			// "container" provides
														// easy access to data
		int a_number = 1;
		arg << a_number;								// put information on the
														// "support" in the "container"
		lastResult = dcop->send(feederID,				// identify the recipient
										"kfeeder",		//hierarchically designate
														// the targeted object
										"reset()",		// signature of the method
														// that will handle sent data
										data);			// the data
	};
	return active && lastResult;
}

bool KFeederControl::addOne()
{
	if (active)
	{
		QByteArray data;								// "raw support" for data
		QDataStream	arg(data, IO_WriteOnly);			// "container" provides
														// easy access to data
		int a_number = 1;
		arg << a_number;								// put information on the
		// "support" in the "container"
		lastResult = dcop->send(feederID,				// identify the recipient
										"kfeeder",		//hierarchically designate
														// the targeted object
										"addOne()",		// signature of the method
														// that will handle sent data
										data);			// the data
	};
	return active && lastResult;
}

bool KFeederControl::addN(int n)
{
	if (active)
	{
		QByteArray data;								// "raw support" for data
		QDataStream	arg(data, IO_WriteOnly);			// "container" provides
														// easy access to data
		int a_number = n;
		arg << a_number;								// put information on the
		// "support" in the "container"
		lastResult = dcop->send(feederID,				// identify the recipient
										"kfeeder",		// hierarchically designate
														// the targeted object
										"addN(int)",	// signature of the method
														// that will handle sent data
										data);			// the data
	};
	return active && lastResult;
}

// sets the type of food movement. 'true' the food is moved automatically.
// 'false' it is necessary to trigger the food movement. */
bool KFeederControl::setAutomatic(bool a)
{
	if (active)
	{
		QByteArray data;								// "raw support" for data
		QDataStream	arg(data, IO_WriteOnly);			// "container" provides
														// easy access to data
		int num;
		if (a)
			num = 1;									// put information on the
		else
			num = 0;
		arg << num;
														// "support" in the "container"
		lastResult = dcop->send(feederID,				// identify the recipient
						"kfeeder",						//hierarchically designate
														// the targeted object
						"setAutomatic(int)",			// signature of the method
														// that will handle sent data
						data);							// the data
	};
	return active && lastResult;
}