4
#include <qsizepolicy.h>
16
#define KA_ERROR_NONE 0
17
#define KA_ERROR_FILENAME 1
18
#define KA_ERROR_INFO 2
19
#define KA_ERROR_UNSUPPORTED 3
20
#define KA_ERROR_ACTIVE 4
21
#define KA_ERROR_EXECUTABLE 5
23
KXAnim::KXAnim(QWidget *parent, const char *name) : QWidget( parent, name)
25
/* default autoresize */
28
/* default loop state */
31
/* Get the base window ID */
32
window = this->winId();
34
/* Get the X11 display */
35
dpy = this->x11Display();
36
window_atom = XInternAtom(dpy, "XANIM_PROPERTY", 0);
40
connect(&proc, SIGNAL( receivedStdout(KProcess *, char *, int)),
41
this, SLOT( getOutput( KProcess *, char *, int)) );
43
connect(&proc, SIGNAL( receivedStderr(KProcess *, char *, int)),
44
this, SLOT( getOutput( KProcess *, char *, int)) );
45
/* KProcess terminated */
46
connect(&proc, SIGNAL( processExited(KProcess *)),
47
this, SLOT( emitStopped( KProcess *)) );
52
void KXAnim::resetXAnimDefaults()
54
/* =========== SOUND ============ */
57
audioInitialVolume=40;
58
/* =========== COLOR ============ */
61
/* =========== GAMMA ============ */
63
/* =========== SCALING ============ */
79
/* =========== OTHERS ============ */
85
x11VisualClass="default";
91
void KXAnim::setDefaults()
93
/* we aren't playing anything! */
95
/* we don't have a file yet! */
97
/* x-anim is not active */
99
/* set the default sizes */
102
/* set the default framerate */
104
/* we have no frames! */
106
/* empty the outpu buffer */
108
/* we have no video, so: */
111
errorCode=KA_ERROR_NONE;
115
void KXAnim::changeProperty( const char *c )
117
/* send the char(s)... */
119
XChangeProperty(dpy, window, window_atom, XA_STRING, 8, PropModeReplace, (unsigned char *)c, strlen(c));
122
void KXAnim::updateSize()
126
x=int(videoWidth * scaleFactor);
127
y=int(videoHeight * scaleFactor);
128
if (scaleHFactor!=1.0)
129
x=int(videoWidth * scaleHFactor);
133
if (scaleVFactor!=1.0)
134
y=int(videoWidth * scaleVFactor);
140
// reinterpret_cast<QWidget *>(parent())->updateGeometry();
141
// if (x!=width() || y!=height()) setFixedSize(x,y);
148
if (!fileName.isEmpty())
151
/* Activate x-anim */
154
proc.clearArguments();
157
s.sprintf("+W%d",winId());
161
/* resize the widget properly */
165
proc.start(KProcess::NotifyOnExit,KProcess::Stdout);
187
void KXAnim::stepForward()
193
void KXAnim::stepBack()
199
void KXAnim::stepForwardWA()
205
void KXAnim::stepBackWA()
211
void KXAnim::toggleSound()
216
void KXAnim::volumeIncrement()
221
void KXAnim::volumeDecrement()
226
void KXAnim::setVolume(int v)
234
void KXAnim::faster()
239
void KXAnim::slower()
244
void KXAnim::resetSpeed()
249
void KXAnim::setFile(QString file)
251
errorCode=KA_ERROR_NONE;
253
if (!file.isEmpty() && QFile::exists(file) && !QDir(file).exists())
256
/* Activate x-anim */
260
proc.clearArguments();
262
proc << "+Zv" << "+v" << "+f" << "-Ae";
264
/* just to get the file information */
265
disconnect(&proc, SIGNAL( processExited(KProcess *)),
266
this, SLOT( emitStopped( KProcess *)) );
267
connect(&proc, SIGNAL( processExited(KProcess *)),
268
this, SLOT( checkOutput( KProcess *)) );
269
if (proc.start(KProcess::NotifyOnExit,KProcess::AllOutput)==false)
271
/* can't finde the xanim executable! */
272
errorCode = KA_ERROR_EXECUTABLE;
273
setErrorString( errorCode, fileName );
279
errorCode = KA_ERROR_ACTIVE;
280
setErrorString( errorCode, file );
286
errorCode = KA_ERROR_FILENAME;
287
setErrorString( errorCode, file );
292
void KXAnim::checkOutput( KProcess *)
295
the xanim has stopped. Check the output and emit the stopped signal
297
disconnect(&proc, SIGNAL( processExited(KProcess *)),
298
this, SLOT( checkOutput( KProcess *)) );
299
connect(&proc, SIGNAL( processExited(KProcess *)),
300
this, SLOT( emitStopped( KProcess *)) );
304
errorCode=getVideoInfo();
307
/* resize the widget properly */
309
setErrorString( errorCode, fileName );
313
int KXAnim::getVideoInfo()
318
/*** check the output of xanim to see if the executable is valid ***/
319
if ( (pos=outBuff.find("XAnim Rev",0,false)) == -1)
320
return KA_ERROR_EXECUTABLE;
322
/*** check the output of xanim to get the file info ***/
323
if ( (pos=outBuff.find("Video Codec:",0,false)) != -1)
325
/* check the video codec */
326
if ( (pos2=outBuff.find("unsupported by this executable",pos+12,false)) == -1)
328
if ( (pos3=outBuff.find("depth=",pos+13,false)) != -1)
330
videoCodec=outBuff.mid(pos+13,pos3-(pos+13));
332
else return KA_ERROR_INFO;
334
else return KA_ERROR_UNSUPPORTED;
335
} else videoCodec="";
337
// if ( (pos=outBuff.find("Frame Stats:",0,false)) != -1)
340
pos2=outBuff.find("Size",0,false);
343
pos2=outBuff.findRev("MPG",-1,false);
344
if (pos2!=-1) pos2--;
348
if ( (pos3=outBuff.find("x",pos2+5,false)) != -1)
350
s=outBuff.mid(pos2+5,pos3-(pos2+5));
351
videoWidth=s.toInt();
352
if ( (pos2=outBuff.find(" ",pos3,false)) != -1)
354
s=outBuff.mid(pos3+1,pos2-(pos3+1));
355
videoHeight=s.toInt();
357
else return KA_ERROR_INFO;
359
else return KA_ERROR_INFO;
361
else return KA_ERROR_INFO;
363
/* check the number of frames */
364
if ( (pos2=outBuff.find("frames",0,false)) != -1)
366
if ( (pos3=outBuff.find(" ",pos2+8,false)) != -1)
368
s=outBuff.mid(pos2+7,pos3-(pos2+7));
369
videoFrames=s.toInt();
371
else return KA_ERROR_INFO;
375
/* check the video speed */
376
if ( (pos2=outBuff.find("fps=",0,false)) != -1)
378
if ( (pos3=outBuff.find("\n",pos2+4,false)) != -1)
380
s=outBuff.mid(pos2+4,pos3-(pos2+4));
381
videoSpeed=s.toFloat();
383
else return KA_ERROR_INFO;
387
// else return KA_ERROR_INFO;
390
return KA_ERROR_NONE;
393
void KXAnim::getOutput( KProcess *, char *text, int len)
395
temp.fill(' ',len+1);
396
temp.replace(0,len,text);
398
outBuff.append(temp);
401
void KXAnim::emitStopped( KProcess *)
404
the xanim has stopped the playing of a video
405
emit the stopped signal
412
void KXAnim::setErrorString( int n, QString file )
415
errorString=QString::null;
418
case KA_ERROR_FILENAME : errorString=i18n("%1: wrong file name.").arg(file); break;
419
case KA_ERROR_INFO : errorString=i18n("Error reading file info."); break;
420
case KA_ERROR_UNSUPPORTED: errorString=i18n("Unsupported video codec."); break;
421
case KA_ERROR_ACTIVE : errorString=i18n("The video is active!"); break;
422
case KA_ERROR_EXECUTABLE : errorString=i18n("Can't find the xanim executable:\n%1").arg(executable); break;
426
void KXAnim::closeEvent( QCloseEvent *e)
438
void KXAnim::parseParameters()
446
/* =========== SOUND ============ */
447
if (audio==false) proc<<"-Ae";
448
if (audioSync==false) proc<<"-Ak";
449
if (audioInitialVolume!=40)
451
s.sprintf("+Av%d",audioInitialVolume);
454
/* =========== COLOR ============ */
455
switch (colorMapping)
458
case static332: proc<<"+C3"; break;
459
case lookupTable: proc<<"+CF4"; break;
460
case grayScale: proc<<"+Cg"; break;
462
if (colorMapping==lookupTable && colorAhead!=5)
464
s.sprintf("+Cs%d",colorAhead);
468
/* =========== GAMMA ============ */
469
if (gammaDisplay!=1.0)
471
s.sprintf("+Gd%1.5f",gammaDisplay);
475
/* =========== SCALING ============ */
476
if (resizing==true) proc<<"+Sr";
480
s.sprintf("+Sx%d", width());
482
s.sprintf("+Sy%d", height());
487
if (scaleFactor != 1.0)
489
s.sprintf("+Ss%2.5f",scaleFactor);
494
if (scaleHFactor != 1.0)
496
s.sprintf("+Sh%10.8f",scaleHFactor);
499
if (scaleVFactor != 1.0)
501
s.sprintf("+Sv%10.8f",scaleVFactor);
507
s.sprintf("+Sx%d",scaleWidth);
512
s.sprintf("+Sy%d",scaleHeight);
515
if (scaleToBuffer==true) proc<<"+Sc";
518
if (scaleFactorB != 1.0)
520
s.sprintf("+SS%10.8f",scaleFactorB);
525
if (scaleHFactorB != 1.0)
527
s.sprintf("+SH%10.8f",scaleHFactorB);
530
if (scaleVFactorB != 1.0)
532
s.sprintf("+SV%10.8f",scaleVFactorB);
538
s.sprintf("+SX%d",scaleWidthB);
543
s.sprintf("+SY%d",scaleHeightB);
546
if (scaleToDisplay==true) proc<<"+SC";
548
/* =========== OTHERS ============ */
552
case 1: proc<<"+b"; break;
553
case 2: proc<<"+f"; break;
555
if (x11Shared==true && loading!=1) proc<<"+B";
556
if (multiBuffer==false) proc<<"-D";
557
if (usePixmap==true) proc<<"+p";
558
if (x11VisualClass.contains("default",false)==0)
566
s.sprintf("+Zp%d",pauseAt);
569
extras.simplifyWhiteSpace();
570
if (!extras.isEmpty())
575
pos2=extras.find(' ',pos+1);
577
s=extras.mid(pos+1,pos2-(pos+1));
579
s=extras.mid(pos+1,extras.length()-(pos+1));
586
void KXAnim::mousePressEvent( QMouseEvent *mouse)
588
emit mouseClick(mouse);
591
QSize KXAnim::sizeHint() const
595
x=int(videoWidth * scaleFactor);
596
y=int(videoHeight * scaleFactor);
597
if (scaleHFactor!=1.0)
598
x=int(videoWidth * scaleHFactor);
603
if (scaleVFactor!=1.0)
604
y=int(videoWidth * scaleVFactor);
612
QSize KXAnim::minimumSizeHint() const
617
QSizePolicy KXAnim::sizePolicy() const
619
return QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
623
#include "kxanim.moc"