blob: 859d87d07ee3d2b1e5e4f75baa4079f4d9080a40 (
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 <qstringlist.h>
#include <qwidget.h>
/* KDE INCLUDES */
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
/* OTHER INCLUDES */
#include <kommanderwidget.h>
#include "scriptobject.h"
#include <myprocess.h>
#include <specials.h>
ScriptObject::ScriptObject(QWidget *a_parent, const char *a_name)
: QLabel(a_parent, a_name), KommanderWidget(this)
{
QStringList states;
states << "default";
setStates(states);
setDisplayStates(states);
if (KommanderWidget::inEditor)
{
setPixmap(KGlobal::iconLoader()->loadIcon("shellscript", KIcon::NoGroup, KIcon::SizeMedium));
setFrameStyle(QFrame::Box | QFrame::Plain);
setLineWidth(1);
setFixedSize(pixmap()->size());
}
else
setHidden(true);
}
ScriptObject::~ScriptObject()
{
}
QString ScriptObject::currentState() const
{
return QString("default");
}
bool ScriptObject::isKommanderWidget() const
{
return true;
}
QStringList ScriptObject::associatedText() const
{
return KommanderWidget::associatedText();
}
void ScriptObject::setAssociatedText(const QStringList& a_at)
{
KommanderWidget::setAssociatedText(a_at);
}
void ScriptObject::setWidgetText(const QString& a_text)
{
KommanderWidget::setAssociatedText(a_text);
}
void ScriptObject::setPopulationText(const QString& a_text)
{
KommanderWidget::setPopulationText(a_text);
}
QString ScriptObject::populationText() const
{
return KommanderWidget::populationText();
}
void ScriptObject::populate()
{
setAssociatedText(KommanderWidget::evalAssociatedText(populationText()));
}
QString ScriptObject::executeProcess(bool blocking)
{
int index = ( states().findIndex( currentState()) );
if (index == -1)
{
printError(i18n("Invalid state for associated text."));
return QString();
}
QString 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 QString& s)
{
m_params.clear();
m_params.append(s);
executeProcess(true);
}
void ScriptObject::execute(const QString& s1, const QString& 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(QString::number(i));
executeProcess(true);
}
void ScriptObject::execute(int i, int j)
{
m_params.clear();
m_params.append(QString::number(i));
m_params.append(QString::number(j));
executeProcess(true);
}
void ScriptObject::execute(bool i)
{
m_params.clear();
m_params.append(QString::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;
}
QString ScriptObject::handleDCOP(int function, const QStringList& args)
{
switch (function) {
case DCOP::setText:
setAssociatedText(args[0]);
break;
case DCOP::clear:
setAssociatedText(QString::null);
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] : QString::null;
}
case DCOP::count:
return QString::number(m_params.count());
default:
return KommanderWidget::handleDCOP(function, args);
}
return QString();
}
#include "scriptobject.moc"
|