blob: c353949c00a16a8bceb414fcba834e78ae66c44f (
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/***************************************************************************
scriptobject.cpp - Widget for holding scripts
-------------------
copyright : (C) 2002 by Marc Britton
email : consume@optusnet.com.au
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* QT INCLUDES */
#include <tqstringlist.h>
#include <tqwidget.h>
/* KDE INCLUDES */
#include <tdeglobal.h>
#include <kiconloader.h>
#include <tdelocale.h>
/* OTHER INCLUDES */
#include <kommanderwidget.h>
#include "scriptobject.h"
#include <myprocess.h>
#include <specials.h>
ScriptObject::ScriptObject(TQWidget *a_parent, const char *a_name)
: TQLabel(a_parent, a_name), KommanderWidget(TQT_TQOBJECT(this))
{
TQStringList states;
states << "default";
setStates(states);
setDisplayStates(states);
if (KommanderWidget::inEditor)
{
setPixmap(TDEGlobal::iconLoader()->loadIcon("shellscript", TDEIcon::NoGroup, TDEIcon::SizeMedium));
setFrameStyle(TQFrame::Box | TQFrame::Plain);
setLineWidth(1);
setFixedSize(pixmap()->size());
}
else
setHidden(true);
}
ScriptObject::~ScriptObject()
{
}
TQString ScriptObject::currentState() const
{
return TQString("default");
}
bool ScriptObject::isKommanderWidget() const
{
return true;
}
TQStringList ScriptObject::associatedText() const
{
return KommanderWidget::associatedText();
}
void ScriptObject::setAssociatedText(const TQStringList& a_at)
{
KommanderWidget::setAssociatedText(a_at);
}
void ScriptObject::setWidgetText(const TQString& a_text)
{
KommanderWidget::setAssociatedText(a_text);
}
void ScriptObject::setPopulationText(const TQString& a_text)
{
KommanderWidget::setPopulationText(a_text);
}
TQString ScriptObject::populationText() const
{
return KommanderWidget::populationText();
}
void ScriptObject::populate()
{
setAssociatedText(KommanderWidget::evalAssociatedText(populationText()));
}
TQString ScriptObject::executeProcess(bool blocking)
{
int index = ( states().findIndex( currentState()) );
if (index == -1)
{
printError(i18n("Invalid state for associated text."));
return TQString();
}
TQString evalText = m_associatedText[index];
if ((KommanderWidget::useInternalParser && !evalText.startsWith("#!")) || evalText.startsWith("#!kommander"))
{
evalAssociatedText(evalText);
return global(widgetName() + "_RESULT");
} else
{
MyProcess process(this);
process.setBlocking(blocking);
return process.run(evalAssociatedText(evalText));
}
}
void ScriptObject::execute()
{
m_params.clear();
executeProcess(true);
}
void ScriptObject::execute(const TQString& s)
{
m_params.clear();
m_params.append(s);
executeProcess(true);
}
void ScriptObject::execute(const TQString& s1, const TQString& s2)
{
m_params.clear();
m_params.append(s1);
m_params.append(s2);
executeProcess(true);
}
void ScriptObject::execute(int i)
{
m_params.clear();
m_params.append(TQString::number(i));
executeProcess(true);
}
void ScriptObject::execute(int i, int j)
{
m_params.clear();
m_params.append(TQString::number(i));
m_params.append(TQString::number(j));
executeProcess(true);
}
void ScriptObject::execute(bool i)
{
m_params.clear();
m_params.append(TQString::number(i));
executeProcess(true);
}
bool ScriptObject::isFunctionSupported(int f)
{
return f == DCOP::setText || f == DCOP::clear || f == DCOP::execute || f == DCOP::item
|| f == DCOP::count;
}
TQString ScriptObject::handleDCOP(int function, const TQStringList& args)
{
switch (function) {
case DCOP::setText:
setAssociatedText(args[0]);
break;
case DCOP::clear:
setAssociatedText(TQString());
break;
case DCOP::execute:
m_params = args;
return executeProcess(true);
break;
case DCOP::item:
{
uint index = args[0].toInt();
return index < m_params.count() ? m_params[index] : TQString();
}
case DCOP::count:
return TQString::number(m_params.count());
default:
return KommanderWidget::handleDCOP(function, args);
}
return TQString();
}
#include "scriptobject.moc"
|