9
#include <kiconloader.h>
12
#include <kmessagebox.h>
13
#include <kfiledialog.h>
15
#include <kseparator.h>
17
#include <qtoolbutton.h>
24
#include <qdropsite.h>
25
#include <qdragobject.h>
33
#include "aktionConf.h"
37
Principal::Principal( const char *name)
38
: KMainWindow(0, name, 0)
40
setCaption("aKtion!");
42
config=KGlobal::config();
44
QWidget *mainwidget=new QWidget(this);
46
setCentralWidget(mainwidget);
50
loader = KGlobal::iconLoader();
52
timer = new QTimer(this, "timer");
54
menu = new QPopupMenu(0L, "menu");
55
menu->insertItem(i18n("Video information"),this,SLOT(click_info()) );
56
menu->insertSeparator();
57
menu->insertItem(SmallIconSet("fileopen"),
58
i18n("Open file..."),this,SLOT(click_open()) );
59
menu->insertItem(SmallIconSet("configure"),
60
i18n("Setup..."),this,SLOT(click_config()) );
61
menu->insertSeparator();
62
menu->insertItem(SmallIconSet("original"),
63
i18n("Original size"),this,SLOT(click_original()) );
64
menu->insertItem(SmallIconSet("half"),
65
i18n("Half size"),this,SLOT(click_half()) );
66
menu->insertItem(SmallIconSet("double"),
67
i18n("Double size"),this,SLOT(click_double()) );
68
menu->insertItem(SmallIconSet("ak_maximize"),
69
i18n("Maximized"),this,SLOT(maximize()) );
70
menuItemFullScreen = menu->insertItem(SmallIconSet("fullscreen"),
71
i18n("Full screen"),this,SLOT(goFullScreen()) );
74
videoMode=new aktionVm(mainwidget);
77
videoContainer=new QWidget(mainwidget);
78
videoContainer->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
79
video = new KXAnim(videoContainer, "video");
83
video->setAutoResize(false);
86
logoWidget = new QLabel( mainwidget, "logo");
87
logoWidget->setAutoResize(true);
88
logoWidget->setPixmap( QPixmap(locate("data","aktion/toolbar/aktion_logo.png")) );
90
line = new KSeparator( KSeparator::HLine, mainwidget);
92
volumeSlider = new QSlider(mainwidget);
94
volumeSlider->setOrientation(QSlider::Horizontal);
95
volumeSlider->setRange(0,100);
96
volumeSlider->setSteps(1,20);
97
volumeSlider->setTickmarks( QSlider::Right );
98
volumeSlider->setTickInterval(10);
99
volumeSlider->setTracking(true);
100
volumeSlider->setMaximumWidth(120);
102
QToolTip::add(volumeSlider,i18n("Volume"));
103
config->setGroup("audio");
104
volumeSlider->setValue(config->readNumEntry("audioInitialVolume"));
106
if (config->readBoolEntry("showVolumeSlider")==true) volumeSlider->show();
109
abrir = new QToolButton(mainwidget, "abrir");
110
abrir->setIconSet(MainBarIconSet("fileopen"));
111
QToolTip::add(abrir,i18n("Open file"));
113
tocar = new QToolButton(mainwidget, "tocar");
114
tocar->setIconSet(MainBarIconSet("1rightarrow"));
115
QToolTip::add(tocar,i18n("Play"));
117
parar = new QToolButton(mainwidget, "parar");
118
parar->setIconSet(MainBarIconSet("player_stop"));
119
QToolTip::add(parar,i18n("Stop"));
121
avanzar = new QToolButton(mainwidget, "avanzar");
122
avanzar->setIconSet(MainBarIconSet("2rightarrow"));
123
avanzar->setAutoRepeat( true );
124
QToolTip::add(avanzar,i18n("Forward"));
126
retroceder = new QToolButton(mainwidget, "retroceder");
127
retroceder->setIconSet(MainBarIconSet("2leftarrow"));
128
retroceder->setAutoRepeat( true );
129
QToolTip::add(retroceder,i18n("Backward"));
131
ayuda = new QToolButton(mainwidget, "ayuda");
132
ayuda->setIconSet(MainBarIconSet("help"));
133
QToolTip::add(ayuda,i18n("Help"));
135
configB = new QToolButton(mainwidget, "Setup");
136
configB->setIconSet(MainBarIconSet("configure"));
137
QToolTip::add(configB,i18n("Setup"));
139
connect(abrir,SIGNAL(clicked()),
140
this,SLOT(click_open()) );
141
connect(ayuda,SIGNAL(clicked()),
142
this,SLOT(click_ayuda()) );
143
connect(configB,SIGNAL(clicked()),
144
this,SLOT(click_config()) );
145
connect(tocar,SIGNAL(clicked()),
146
this,SLOT(click_play()) );
147
connect(parar,SIGNAL(clicked()),
148
this,SLOT(click_stop()));
149
connect(avanzar,SIGNAL(clicked()),
150
this,SLOT(click_forward()));
151
connect(retroceder,SIGNAL(clicked()),
152
this,SLOT(click_backward()));
153
connect(video,SIGNAL(stopped()),
154
this,SLOT(waitForKXanimExit()) );
155
connect(video,SIGNAL(mouseClick(QMouseEvent *)),
156
this,SLOT(receiveMouseClick(QMouseEvent *)) );
157
connect(volumeSlider,SIGNAL(valueChanged(int)),
158
this,SLOT(volumeSliderMoved(int)) );
159
connect(timer,SIGNAL(timeout()),
160
this,SLOT(checkStates()) );
162
config->setGroup("others");
163
lastDir=config->readEntry("initialDirectory");
164
if (!QDir(lastDir).exists())
166
KMessageBox::information(0L,
167
i18n("Invalid initial directory"),
168
i18n("aktion error!"));
172
/* switch the buttons to the 'disabled' mode */
173
toggleButtons(false);
176
parametersChanged=false;
179
externalChange=false;
183
QVBoxLayout *lv=new QVBoxLayout( mainwidget );
185
lv->addWidget(videoContainer);
186
lv->addWidget( logoWidget );
188
lv->addWidget( line );
189
QHBoxLayout *lh2=new QHBoxLayout( lv );
191
lh2->addWidget( volumeSlider );
192
QHBoxLayout *lh=new QHBoxLayout( lv );
193
lh->addWidget( abrir );
194
lh->addWidget( tocar );
195
lh->addWidget( parar );
196
lh->addWidget( retroceder );
197
lh->addWidget( avanzar );
199
lh->addWidget( configB );
200
lh->addWidget( ayuda );
204
Principal::~Principal()
208
void Principal::toggleButtons(bool state)
210
tocar->setEnabled(state);
211
parar->setEnabled(state);
212
avanzar->setEnabled(state);
213
retroceder->setEnabled(state);
216
void Principal::click_original() { changeSize(1.0); };
217
void Principal::click_half() { changeSize(0.5); };
218
void Principal::click_double() { changeSize(2.0); };
220
void Principal::changeSize(float zoom)
222
/* resize the window according to a zoom factor */
227
KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
230
zH=(float)video->getVideoHeight()*zoom;
231
zW=(float)video->getVideoWidth()*zoom;
233
resize(zW,zH+volumeSlider->height()+tocar->height()+line->height()+15);
236
void Principal::maximize()
238
/* maximizes the window */
240
// KWM is dead, I hope this works as a replacement
241
KWin::Info info = KWin::info( winId() ); // doesn't this look funny? :)
242
KWin::setState( winId(), info.state | NET::MaxVert | NET::MaxHoriz );
245
QRect with_frame, no_frame, result;
247
with_frame = KWM::geometry(winId(),true);
248
no_frame = KWM::geometry(winId(),false);
249
result = KWM::windowRegion( KWM::currentDesktop() );
251
result.setWidth( result.width() - (with_frame.width() - no_frame.width()) );
252
result.setHeight( result.height() - (with_frame.height() - no_frame.height()) );
253
setGeometry( result );
257
void Principal::changeInitialSize()
259
/* this procedure sets the window size just after a video
261
config->setGroup("scaling");
262
switch (config->readNumEntry("scale"))
264
case 0: changeSize(1.0); break;
265
case 1: changeSize(0.5); break;
266
case 2: changeSize(2.0); break;
267
case 3: maximize(); break;
268
case 4: goFullScreen(); break;
272
void Principal::waitForKXanimExit()
274
/* the kxanim's stopped signal activates this slot every time the video
275
is stopped. I use the whatToDo switch to know "what to do now that
276
kxanim is stopped". This is the most secure way to manage the things,
277
but not the cleaner, though.
279
tocar->setIconSet(MainBarIconSet("1rightarrow"));
283
case NOTHING : if (inFullScreen)
288
case CLOSE_THE_APP : kapp->quit(); break;
289
case NEW_VIDEO : click_open(); break;
290
case CONTINUE_LOADING : continueLoading(); break;
291
case CHANGE_EXECUTABLE: executableChanged(); break;
295
bool Principal::queryExit()
297
whatToDo = CLOSE_THE_APP;
298
if (video->isActive())
301
return false; // wait for signal
307
void Principal::click_open()
309
/* the idea behind this method is not very simple:
310
if fileName is empty then: get a file name!
311
if the video is active (here comes the hard part!):
312
set 'what to do' to NEW_VIDEO, stop the video and wait that the
313
waitForKXanimExit slot gets activated...
315
ok, now that the video is REALLY inactive, we can play with it...!
316
set the video file and wait until KXAnim finishes reading info...
317
(continues on continueLoading() )
321
if ( fileName.isEmpty() )
323
url=KFileDialog::getOpenURL(lastDir, i18n("*.avi *.AVI *.mov *.MOV *.mpg *.MPG *.mpeg *.MPEG *.flc *.FLC *.fli *.FLI|All video formats\n"
324
"*.avi *.AVI|AVI files (*.avi)\n"
325
"*.mov *.MOV|QuickTime files (*.mov)\n"
326
"*.mpg *.MPG *.mpeg *.MPEG|MPG Files (*.mpg)\n"
327
"*.fli *.FLI *.flc *.FLC|FLI/FLC Files (*.fli *.flc)\n"
329
,0L,i18n("Select a movie"));
330
if (url.isEmpty()) return;
334
url.setPath(fileName);
337
if( url.isLocalFile() )
339
fileName = url.path();
343
KMessageBox::sorry( 0L, i18n("Only local files are currently supported." ) );
347
if (video->isActive() && !fileName.isEmpty() )
353
if (!fileName.isEmpty())
355
/* remove the logo picture */
356
if (logoWidget != 0L)
363
whatToDo=CONTINUE_LOADING;
364
kapp->setOverrideCursor( waitCursor );
366
parametersChanged=false;
367
video->setFile(fileName);
371
void Principal::continueLoading()
377
if (video->getErrorCode()==0)
379
/* Everything seems to be fine... */
380
/* enable the buttons */
382
pos=fileName.findRev('/');
383
title=fileName.mid(pos+1,fileName.length()-(pos+1));
384
// title+=" - aKtion!";
385
// preserve the caption for future use (in fullscreen)
388
lastDir=fileName.mid(0,pos+1);
391
theCapturer.resetCounter();
392
config->setGroup("capture");
393
theCapturer.setParameters(config->readEntry("outputDir"),fileName,
394
config->readEntry("outputFormat"));
396
kapp->restoreOverrideCursor();
402
/* something is wrong... */
403
/* disable buttons */
404
toggleButtons(false);
405
kapp->restoreOverrideCursor();
406
KMessageBox::sorry(0L,video->getErrorString());
411
void Principal::dragEnterEvent( QDragEnterEvent *event )
413
event->accept( QUriDrag::canDecode(event) );
416
void Principal::dropEvent( QDropEvent *event )
418
if ( QUriDrag::canDecode(event) )
421
if ( QUriDrag::decode(event, urls) )
423
char *urlStr=urls.first();
425
fileName = url.path();
431
void Principal::click_ayuda()
436
void Principal::click_play()
438
/* maube do we need to resize the whole application? */
439
if (parametersChanged==true && video->isActive()==false)
442
parametersChanged=false;
444
/* autoplay or not */
445
config->setGroup("others");
446
if (isNewVideo==true && config->readBoolEntry("autoplay")==false)
448
video->setPauseAt(0);
450
else video->setPauseAt(-1);
453
/* set the play button pixmap */
454
if (video->isPlaying()==true)
455
tocar->setIconSet(MainBarIconSet("1rightarrow"));
457
tocar->setIconSet(MainBarIconSet("player_pause"));
459
// timer->start(100);
464
void Principal::click_forward()
466
if (video->isPlaying()==true)
467
tocar->setIconSet(MainBarIconSet("1rightarrow"));
468
video->stepForward();
471
void Principal::click_backward()
473
if (video->isPlaying()==true)
474
tocar->setIconSet(MainBarIconSet("1rightarrow"));
478
void Principal::click_stop()
483
void Principal::click_config()
485
QString oldExecutable, newExecutable;
487
config->setGroup("others");
488
oldExecutable=config->readEntry("executable");
490
Setup dialogo(0L, "setup");
491
if (dialogo.exec()==1)
493
parametersChanged=true;
495
config->setGroup("capture");
496
theCapturer.setParameters(config->readEntry("outputDir"),fileName,
497
config->readEntry("outputFormat"));
499
config->setGroup("others");
500
newExecutable=config->readEntry("executable");
502
if (oldExecutable!=newExecutable)
507
void Principal::setParameters()
509
config->setGroup("audio");
510
video->setAudio(config->readBoolEntry("enable"));
511
video->setAudioSync(config->readBoolEntry("audioSync"));
512
video->setInitialVolume(volumeSlider->value());
514
config->setGroup("color");
515
video->setColorAhead(config->readNumEntry("colorAhead"));
516
switch (config->readNumEntry("colorMapping"))
518
case 0: video->setColorMapping(KXAnim::static332); break;
519
case 1: video->setColorMapping(KXAnim::lookupTable); break;
520
case 2: video->setColorMapping(KXAnim::grayScale); break;
521
case 3: video->setColorMapping(KXAnim::none); break;
523
video->setGammaDisplay(float(config->readDoubleNumEntry("gammaDisp")));
525
config->setGroup("scaling");
526
/* I always wants "resinzing on the fly"
528
video->setResizing(true);
529
is not necessary 'cause it's true by default.
532
// video->setScaleFactor( float(config->readNumEntry("dispFactor"))/100 );
533
// video->setScaleFactorB( float(config->readNumEntry("bufFactor"))/100);
535
config->setGroup("others");
536
video->setLoading(config->readNumEntry("loading"));
537
video->setX11Shared(config->readBoolEntry("x11shared"));
538
video->setMultiBuffer(config->readBoolEntry("multiBuffer"));
539
video->setUsePixmap(config->readBoolEntry("pixmap"));
541
switch (config->readNumEntry("visualClass"))
543
case 0: video->setX11VisualClass("default"); break;
544
case 1: video->setX11VisualClass("staticgray"); break;
545
case 2: video->setX11VisualClass("grayscale"); break;
546
case 3: video->setX11VisualClass("staticcolor"); break;
547
case 4: video->setX11VisualClass("pseudocolor"); break;
548
case 5: video->setX11VisualClass("truecolor"); break;
549
case 6: video->setX11VisualClass("directcolor"); break;
552
video->setLoop(config->readBoolEntry("loop"));
553
video->setExtraParameters( config->readEntry("extras").ascii());
554
video->setExecutable( QFile::encodeName(config->readEntry("executable")) );
557
void Principal::keyPressEvent( QKeyEvent *key)
561
case Key_Space : click_play(); break;
562
case Key_Period: click_forward(); break;
563
case Key_Comma : click_backward(); break;
564
case Key_Enter : click_open(); break;
565
case Key_3 : if(volumeSlider->value() <= 99)
568
volumeSlider->setValue( volumeSlider->value() + 1);
569
externalChange=false;
570
video->volumeIncrement();
573
case Key_2 : if(volumeSlider->value() >= 1)
576
volumeSlider->setValue( volumeSlider->value() - 1);
577
externalChange=false;
578
video->volumeDecrement();
581
case Key_F1 : click_ayuda(); break;
582
case Key_Escape: this->close(); break;
583
case Key_C : theCapturer.captureWidget(video); break;
584
default : if (inFullScreen)
587
/* restore the geometry */
588
// KWM::setGeometry( winId(), oldGeometry);
589
KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
596
void Principal::receiveMouseClick( QMouseEvent *mouse)
598
if (mouse->button()==RightButton)
600
menu->move(this->x()+mouse->x(),this->y()+mouse->y());
605
if (mouse->button()==LeftButton && inFullScreen)
608
// KWM::setGeometry( winId(), oldGeometry);
609
KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
614
void Principal::loadFile( const char *name)
620
void Principal::click_info()
622
QString codec(video->getVideoCodec());
625
s = i18n("File: %1\n"
628
"%5 frames - %6 fps")
631
.arg(video->getVideoWidth())
632
.arg(video->getVideoHeight())
633
.arg(video->getVideoFrames())
634
.arg(KGlobal::locale()->formatNumber(video->getVideoSpeed(), 2));
635
KMessageBox::information(this, s, "aktion!");
638
void Principal::volumeSliderMoved(int v)
644
void Principal::resizeEvent( QResizeEvent *)
646
int w=videoContainer->width();
647
int h=videoContainer->height();
648
float video_ar, space_ar, scaled;
651
if (inFullScreen==false)
653
config->setGroup("audio");
654
if (config->readBoolEntry("showVolumeSlider")==true)
656
volumeSlider->show();
660
volumeSlider->hide();
664
/* Here comes the resizing-moving process for the video widget.
665
It'll maintain his aspect ratio. Steps are:
666
.The available space for the video is defined w and h.
667
.Resize the video widget as much as possible:
668
.Calculate video and left space aspect ratio.
669
.If video aspect ratio is smaller:
672
.If video aspect ratio is bigger
678
videoW=video->getVideoWidth();
679
if (videoW==0) videoW=1;
680
videoH=video->getVideoHeight();
681
if (videoH==0) videoH=1;
683
video_ar=(float)videoW/(float)videoH; // video aspect ratio
684
space_ar=(float)w/(float)h; // available space aspect ratio
686
if (video_ar<space_ar)
688
scaled=(float)videoW*( (float)h/(float)videoH );
689
video->resize( (int)scaled,h);
690
scaled=((float)w - scaled) /2;
691
video->move( (int)scaled, 0);
696
if (video_ar>space_ar)
698
scaled=(float)videoH*( (float)w/(float)videoW );
699
video->resize(w, (int)scaled);
700
scaled=((float)h - scaled) /2;
701
video->move(0, (int)scaled);
713
void Principal::checkStates()
715
// cout<<video->iconText()<<endl;
718
void Principal::goFullScreen()
720
int sizeW=0, sizeH=0;
722
/* change the popup menu */
723
menu->setItemEnabled(menuItemFullScreen,false);
725
/* Hide all widgets (except the video widget) */
734
volumeSlider->hide();
737
bool vmExtensionsOk=false;
740
config->setGroup("scaling");
741
if (config->readBoolEntry("usevm"))
743
if (true)//geteuid()==0)
745
sizeW=video->getVideoWidth();
746
sizeH=video->getVideoHeight();
747
vmExtensionsOk=videoMode->setVideoMode(&sizeW,&sizeH);
752
KMessageBox::sorry(0L, i18n("You must be root to use the XFree86-VidMode extensions\n"
753
"Switching to normal full-screen..."));
759
/* Make the window FULL SCREEN in the traditional way */
760
sizeW = QApplication::desktop()->width();
761
sizeH = QApplication::desktop()->height();
768
config->setGroup("scaling");
769
if (config->readBoolEntry("grabmouse"))
771
kapp->setOverrideCursor( blankCursor );
772
QCursor::setPos(0,0);
775
/* Save the window's background color and geometry */
776
saveBackground = backgroundColor();
777
videoContainer->setBackgroundColor( black );
780
this->setCaption(saveCaption);
782
setGeometry( 0, 0, sizeW, sizeH );
785
void Principal::undoFullScreen()
790
videoMode->resetVideoMode();
795
/* change the popup menu */
796
menu->setItemEnabled(menuItemFullScreen,true);
798
/* Show all widgets */
808
/* Restore background color */
809
videoContainer->setBackgroundColor( saveBackground );
811
inFullScreen = false;
813
config->setGroup("scaling");
814
if (config->readBoolEntry("grabmouse"))
815
kapp->restoreOverrideCursor();
817
// KWM::setDecoration( winId(), KWM::normalDecoration );
822
// reparent(0,0,p,true);//WStyle_Customize | WStyle_NormalBorder | WType_TopLevel, p, false);
823
// KWin::setType(winId(), NET::Normal);
824
// KWin::clearState(winId(), NET::StaysOnTop);
827
this->setCaption(saveCaption);
830
void Principal::executableChanged()
832
if (video->isActive())
834
whatToDo=CHANGE_EXECUTABLE;
840
fileName=video->getVideoFileName();
841
if (!fileName.isEmpty())
845
#include "principal.moc"