2 #include <QApplication>
12 QObject(parent), _path(path), initialized(false), process(0)
17 QObject(parent), _info(base._info), _path(base._path), initialized(false), process(0)
31 return QDir(QApplication::applicationDirPath() +
"/../Resources").absoluteFilePath(
"ckb-animations");
33 return QDir(
"/usr/lib").absoluteFilePath(
"ckb-animations");
42 foreach(QString file, dir.entryList(QDir::Files | QDir::Executable)){
53 QMap<QString, const AnimScript*> result;
56 if(result.contains(name)){
60 script->
_info.
name +=
" " + script->
guid().toString().toUpper();
62 result[script->
name()] = script;
64 return result.values();
72 return QUrl::fromPercentEncoding(param.trimmed().toLatin1()).trimmed();
75 const static double ONE_DAY = 24. * 60. * 60.;
80 infoProcess.start(
_path, QStringList(
"--ckb-info"));
81 qDebug() <<
"Scanning " <<
_path;
82 infoProcess.waitForFinished(1000);
83 if(infoProcess.state() == QProcess::Running){
94 while((line = infoProcess.readLine()) !=
""){
95 line = line.trimmed();
96 QStringList components = line.split(
" ");
97 int count = components.count();
100 QString
param = components[0].trimmed();
103 else if(param ==
"name")
105 else if(param ==
"version")
107 else if(param ==
"year")
109 else if(param ==
"author")
111 else if(param ==
"license")
113 else if(param ==
"description")
115 else if(param ==
"kpmode")
117 else if(param ==
"time")
118 _info.absoluteTime = (components[1] ==
"absolute");
119 else if(param ==
"repeat")
120 _info.repeat = (components[1] ==
"on");
121 else if(param ==
"preempt")
122 _info.preempt = (components[1] ==
"on");
123 else if(param ==
"parammode")
124 _info.liveParams = (components[1] ==
"live");
125 else if(param ==
"param"){
129 while(components.count() < 8)
130 components.append(
"");
132 QString sType = components[1].toLower();
135 else if(sType ==
"double")
137 else if(sType ==
"bool")
139 else if(sType ==
"rgb")
141 else if(sType ==
"argb")
143 else if(sType ==
"gradient")
145 else if(sType ==
"agradient")
147 else if(sType ==
"angle")
149 else if(sType ==
"string")
151 else if(sType ==
"label")
156 QString
name = components[2].toLower();
160 QString prefix =
urlParam(components[3]), postfix =
urlParam(components[4]);
163 if(name ==
"trigger" || name ==
"kptrigger" || name ==
"kpmode" || name ==
"duration" || name ==
"delay" || name ==
"kpdelay" || name ==
"repeat" || name ==
"kprepeat" || name ==
"stop" || name ==
"kpstop" || name ==
"kpmodestop" || name ==
"kprelease")
165 Param param = { type,
name, prefix, postfix, def, minimum, maximum };
166 _info.params.append(param);
167 }
else if(param ==
"preset"){
170 QMap<QString, QVariant>
preset;
171 for(
int i = 2; i <
count; i++){
173 QString setting = components.at(i);
174 QStringList sComponents = setting.split(
"=");
175 if(sComponents.count() != 2)
177 QString param = sComponents.first().trimmed();
178 QString value =
urlParam(sComponents.last());
179 preset[
param] = value;
182 if(preset.contains(
"duration")){
183 QVariant duration = preset.value(
"duration");
184 preset[
"repeat"] = duration;
185 preset[
"kprepeat"] = duration;
195 double defaultDuration = -1.;
196 if(!
_info.absoluteTime){
197 defaultDuration = 1.;
199 _info.params.append(duration);
202 _info.params.append(trigger);
204 _info.params.append(kptrigger);
206 _info.preempt =
false;
210 _info.params.append(kpmode);
213 _info.params.append(delay);
214 _info.params.append(kpdelay);
217 _info.params.append(kpmodestop);
218 _info.params.append(kprelease);
225 _info.params.append(repeat);
226 _info.params.append(kprepeat);
227 _info.params.append(stop);
228 _info.params.append(kpstop);
233 _info.params.append(stop);
234 _info.params.append(kpstop);
254 if(
_info.absoluteTime){
274 process->write(
"begin params\n");
279 process->write(i.key().toLatin1());
281 process->write(QUrl::toPercentEncoding(i.value().toString()));
284 process->write(
"end params\n");
293 QStringList keysCopy =
_keys;
296 foreach(
const QString&
key, keysCopy){
299 keysCopy.removeAll(key);
307 if(keysCopy.isEmpty()){
315 qDebug() <<
"Starting " <<
_path;
317 process->write(
"begin keymap\n");
318 process->write(QString(
"keycount %1\n").arg(keysCopy.count()).toLatin1());
319 foreach(
const QString& key, keysCopy){
321 process->write(QString(
"key %1 %2,%3\n").arg(key).arg(pos.
x -
minX).arg(pos.
y -
minY).toLatin1());
323 process->write(
"end keymap\n");
359 int kpMode =
_info.kpMode;
368 else if(
_paramValues.value(
"kprelease",
false).toBool())
374 process->write((
"key " + key + (pressed ?
" down\n" :
" up\n")).toLatin1());
382 process->write((
"key " + QString(
"%1,%2").arg(kp.
x -
minX).arg(kp.
y -
minY) + (pressed ?
" down\n" :
" up\n")).toLatin1());
391 connect(
process, SIGNAL(finished(
int)),
process, SLOT(deleteLater()));
399 QByteArray line =
process->readLine().trimmed();
402 if(line ==
"begin frame")
404 else if(line ==
"end run"){
410 if(line.startsWith(
"argb ")){
414 if(sscanf(line,
"argb %30s %x", keyName, &keyColor) != 2)
421 if(line ==
"end frame"){
450 if(!
_info.absoluteTime){
457 process->write(QString(
"time %1\n").arg(delta).toLatin1());
QString urlParam(const QString ¶m)
Param param(const QString &name) const
void init(const KeyMap &map)
void advance(quint64 timestamp)
static QList< const AnimScript * > list()
void retrigger(quint64 timestamp, bool allowPreempt=false)
void frame(quint64 timestamp)
const PresetValue & preset(int index) const
Key key(const QString &name) const
AnimScript(QObject *parent, const QString &path)
QRgb * colorForName(const char *name)
bool hasParam(const QString &name) const
static QHash< QUuid, AnimScript * > scripts
struct AnimScript::@0 _info
static const int KP_POSITION
QList< PresetValue > _presetValues
void init(const KeyMap &map, const QStringList &keys, const QMap< QString, QVariant > ¶mValues)
void keypress(const QString &key, bool pressed, quint64 timestamp)
const QString & name() const
static AnimScript * copy(QObject *parent, const QUuid &id)
static const double ONE_DAY
const QUuid & guid() const
void parameters(const QMap< QString, QVariant > ¶mValues)
void begin(quint64 timestamp)
void stop(quint64 timestamp)