]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
2a3694dc71cadbb806077013ba1057add5721170
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_interface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 
22  *****************************************************************************/
23
24 #include "qt4.hpp"
25 #include "main_interface.hpp"
26 #include "input_manager.hpp"
27 #include "util/input_slider.hpp"
28 #include "util/qvlcframe.hpp"
29 #include "util/customwidgets.hpp"
30 #include "dialogs_provider.hpp"
31 #include "components/interface_widgets.hpp"
32 #include "dialogs/playlist.hpp"
33 #include "menus.hpp"
34
35 #include <QMenuBar>
36 #include <QCloseEvent>
37 #include <QPushButton>
38 #include <QStatusBar>
39 #include <QKeyEvent>
40 #include <QUrl>
41 #include <QSystemTrayIcon>
42
43 #include <assert.h>
44 #include <vlc_keys.h>
45 #include <vlc_vout.h>
46
47 #ifdef WIN32
48     #define PREF_W 410
49     #define PREF_H 121
50 #else
51     #define PREF_W 450
52     #define PREF_H 125
53 #endif
54
55 #define VISIBLE(i) (i && i->isVisible())
56
57 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
58 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
59 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
60
61 #define DS(i) i.width(),i.height()
62
63 /* Callback prototypes */
64 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
65                         vlc_value_t old_val, vlc_value_t new_val, void *param );
66 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
67                        vlc_value_t old_val, vlc_value_t new_val, void *param );
68 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
69                              vlc_value_t, void *);
70 /* Video handling */
71 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
72                         int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
73 {
74     return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
75 }
76 static void DoRelease( intf_thread_t *p_intf, void *p_win )
77 {
78     return p_intf->p_sys->p_mi->releaseVideo( p_win );
79 }
80 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
81 {
82     return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
83 }
84
85 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
86 {
87     /* Configuration */
88     settings = new QSettings( "VideoLAN", "VLC" );
89     settings->beginGroup( "MainWindow" );
90
91     setWindowIcon( QApplication::windowIcon() );
92
93     need_components_update = false;
94     bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
95     embeddedPlaylistWasActive = videoIsActive = false;
96
97     videoEmbeddedFlag = false;
98     if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
99
100     alwaysVideoFlag = false;
101     if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ))
102         alwaysVideoFlag = true;
103
104     playlistEmbeddedFlag = settings->value("playlist-embedded", true).toBool();
105     advControlsEnabled= settings->value( "adv-controls", false ).toBool();
106     visualSelectorEnabled= settings->value( "visual-selector", false ).toBool();
107
108     /* UI */
109     setVLCWindowsTitle();
110     handleMainUi( settings );
111     QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag,
112                              advControlsEnabled, visualSelectorEnabled );
113     timeLabel = new QLabel( 0 );
114     nameLabel = new QLabel( 0 );
115     statusBar()->addWidget( nameLabel, 4 );
116     statusBar()->addPermanentWidget( timeLabel, 1 );
117
118     setFocusPolicy( Qt::StrongFocus );
119     setAcceptDrops(true);
120
121     /* Init input manager */
122     MainInputManager::getInstance( p_intf );
123     ON_TIMEOUT( updateOnTimer() );
124
125     /* Volume control */
126     CONNECT( ui.volumeSlider, valueChanged(int), this, updateVolume(int) );
127     /* Connect the input manager to the GUI elements it manages */
128     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
129              slider, setPosition( float,int, int ) );
130     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
131              this, setDisplay( float, int, int ) );
132     CONNECT( THEMIM->getIM(), nameChanged( QString ), this,setName( QString ) );
133     CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
134     CONNECT( THEMIM->getIM(), statusChanged( int ), this,
135              updateSystrayMenu( int ) );
136     CONNECT( THEMIM->getIM(), navigationChanged( int ), 
137              this, setNavigation(int) );
138     CONNECT( slider, sliderDragged( float ),
139              THEMIM->getIM(), sliderUpdate( float ) );
140
141     CONNECT( ui.prevSectionButton, clicked(), THEMIM->getIM(),
142              sectionPrev() );
143     CONNECT( ui.nextSectionButton, clicked(), THEMIM->getIM(),
144              sectionNext() );
145     CONNECT( ui.menuButton, clicked(), THEMIM->getIM(),
146              sectionMenu() );
147
148     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
149     var_AddCallback( p_intf, "interaction", InteractCallback, this );
150     p_intf->b_interaction = VLC_TRUE;
151
152     /* Register callback for the intf-popupmenu variable */
153     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
154                                         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
155     if( p_playlist != NULL )
156     {
157         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
158         var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
159         vlc_object_release( p_playlist );
160     }
161     if( QSystemTrayIcon::isSystemTrayAvailable() &&
162                               ( config_GetInt( p_intf, "qt-system-tray") == 1))
163             createSystrayMenu();
164 }
165
166 MainInterface::~MainInterface()
167 {
168     /* Unregister callback for the intf-popupmenu variable */
169     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
170                                         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
171     if( p_playlist != NULL )
172     {
173         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
174         var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
175         vlc_object_release( p_playlist );
176     }
177
178     settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
179     settings->setValue( "adv-controls", advControlsEnabled );
180     settings->setValue( "pos", pos() );
181     settings->endGroup();
182     delete settings;
183     p_intf->b_interaction = VLC_FALSE;
184     var_DelCallback( p_intf, "interaction", InteractCallback, this );
185
186     p_intf->pf_request_window = NULL;
187     p_intf->pf_release_window = NULL;
188     p_intf->pf_control_window = NULL;
189 }
190
191 void MainInterface::setVLCWindowsTitle( QString aTitle )
192 {
193     if( aTitle.isEmpty() )
194     {
195         this->setWindowTitle( qtr( "VLC media player" ) );
196     }
197     else
198     {
199         this->setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
200     }
201 }
202
203 void MainInterface::handleMainUi( QSettings *settings )
204 {
205     QWidget *main = new QWidget( this );
206     setCentralWidget( main );
207     ui.setupUi( centralWidget() );
208
209     slider = new InputSlider( Qt::Horizontal, NULL );
210     ui.vboxLayout->insertWidget( 0, slider );
211     ui.discFrame->hide();
212     BUTTON_SET_IMG( ui.prevSectionButton, "", previous.png, "" );
213     BUTTON_SET_IMG( ui.nextSectionButton, "", next.png, "" );
214     BUTTON_SET_IMG( ui.menuButton, "", previous.png, "" );
215
216     BUTTON_SET_ACT_I( ui.prevButton, "" , previous.png,
217                       qtr("Previous"), prev() );
218     BUTTON_SET_ACT_I( ui.nextButton, "", next.png, qtr("Next"), next() );
219     BUTTON_SET_ACT_I( ui.playButton, "", play.png, qtr("Play"), play() );
220     BUTTON_SET_ACT_I( ui.stopButton, "", stop.png, qtr("Stop"), stop() );
221
222     /* Volume */
223     ui.volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
224     ui.volumeSlider->setMaximum( 100 );
225     ui.volMuteLabel->setToolTip( qtr( "Mute" ) );
226     VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
227     ui.volMuteLabel->installEventFilter(h);
228     ui.volumeSlider->setFocusPolicy( Qt::NoFocus );
229
230     BUTTON_SET_IMG( ui.playlistButton, "" , playlist_icon.png,
231                         playlistEmbeddedFlag ?  qtr( "Show playlist" ) :
232                                                 qtr( "Open playlist" ) );
233     BUTTONACT( ui.playlistButton, playlist() );
234
235     /* Set initial size */
236     resize ( PREF_W, PREF_H );
237
238     addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
239
240     advControls = new ControlsWidget( p_intf );
241     ui.vboxLayout->insertWidget( 0, advControls );
242     advControls->updateGeometry();
243     if( !advControlsEnabled ) advControls->hide();
244     need_components_update = true;
245
246     visualSelector = new VisualSelector( p_intf );
247     ui.vboxLayout->insertWidget( 0, visualSelector );
248     visualSelector->hide();
249
250     if( alwaysVideoFlag )
251     {
252         bgWidget = new BackgroundWidget( p_intf );
253         bgWidget->widgetSize = settings->value( "backgroundSize",
254                                                 QSize( 200, 200 ) ).toSize();
255         bgWidget->resize( bgWidget->widgetSize );
256         bgWidget->updateGeometry();
257         ui.vboxLayout->insertWidget( 0, bgWidget );
258     }
259
260     if( videoEmbeddedFlag )
261     {
262         videoWidget = new VideoWidget( p_intf );
263         videoWidget->widgetSize = QSize( 1, 1 );
264         videoWidget->resize( videoWidget->widgetSize );
265         ui.vboxLayout->insertWidget( 0, videoWidget );
266
267         p_intf->pf_request_window  = ::DoRequest;
268         p_intf->pf_release_window  = ::DoRelease;
269         p_intf->pf_control_window  = ::DoControl;
270     }
271     setMinimumSize( PREF_W, addSize.height() );
272 }
273
274 void MainInterface::createSystrayMenu()
275 {
276     sysTray = new QSystemTrayIcon( QIcon( QPixmap( ":/vlc128.png" ) ) );
277     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
278     QVLCMenu::updateSystrayMenu( this, p_intf );
279     sysTray->show();
280 }
281
282 void MainInterface::updateSystrayMenu( int status )
283 {
284     QVLCMenu::updateSystrayMenu( this, p_intf ) ;
285 }
286
287 /**********************************************************************
288  * Handling of the components
289  **********************************************************************/
290 void MainInterface::calculateInterfaceSize()
291 {
292     int width = 0, height = 0;
293     if( VISIBLE( bgWidget ) )
294     {
295         width = bgWidget->widgetSize.width();
296         height = bgWidget->widgetSize.height();
297         assert( !(playlistWidget && playlistWidget->isVisible() ) );
298     }
299     else if( VISIBLE( playlistWidget ) )
300     {
301         width = playlistWidget->widgetSize.width();
302         height = playlistWidget->widgetSize.height();
303     }
304     else if( videoIsActive )
305     {
306         width =  videoWidget->widgetSize.width() ;
307         height = videoWidget->widgetSize.height();
308     }
309     else
310     {
311         width = PREF_W - addSize.width();
312         height = PREF_H - addSize.height();
313     }
314     if( VISIBLE( visualSelector ) )
315         height += visualSelector->height();
316     if( VISIBLE( advControls) )
317     {
318         height += advControls->sizeHint().height();
319     }
320     mainSize = QSize( width + addSize.width(), height + addSize.height() );
321 }
322
323 void MainInterface::resizeEvent( QResizeEvent *e )
324 {
325     videoWidget->widgetSize.setWidth(  e->size().width() - addSize.width() );
326     if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
327     {
328         SET_WH( videoWidget, e->size().width() - addSize.width(),
329                              e->size().height()  - addSize.height() );
330         videoWidget->updateGeometry();
331     }
332     if( VISIBLE( playlistWidget ) )
333     {
334         SET_WH( playlistWidget , e->size().width() - addSize.width(),
335                                  e->size().height() - addSize.height() );
336         playlistWidget->updateGeometry();
337     }
338 }
339
340 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
341                                    int *pi_y, unsigned int *pi_width,
342                                    unsigned int *pi_height )
343 {
344     void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
345     if( ret )
346     {
347         videoIsActive = true;
348         if( VISIBLE( playlistWidget ) )
349         {
350             embeddedPlaylistWasActive = true;
351 //            playlistWidget->hide();
352         }
353         bool bgWasVisible = false;
354         if( VISIBLE( bgWidget) )
355         {
356             bgWasVisible = true;
357 //            bgWidget->hide();
358         }
359         if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
360         {
361             videoWidget->widgetSize = QSize( *pi_width, *pi_height );
362         }
363         else /* Background widget available, use its size */
364         {
365             /* Ok, our visualizations are bad, so don't do this for the moment
366              * use the requested size anyway */
367             // videoWidget->widgetSize = bgWidget->widgeTSize;
368             videoWidget->widgetSize = QSize( *pi_width, *pi_height );
369         }
370 //        videoWidget->updateGeometry(); /// FIXME: Needed ?
371         need_components_update = true;
372     }
373     return ret;
374 }
375
376 void MainInterface::releaseVideo( void *p_win )
377 {
378     videoWidget->release( p_win );
379     videoWidget->widgetSize = QSize( 0, 0 );
380     videoWidget->resize( videoWidget->widgetSize );
381
382     if( embeddedPlaylistWasActive )
383         ;//playlistWidget->show();
384     else if( bgWidget )
385         ;//bgWidget->show();
386
387     videoIsActive = false;
388     need_components_update = true;
389 }
390
391 class SetVideoOnTopQtEvent : public QEvent
392 {
393 public:
394     SetVideoOnTopQtEvent( bool _onTop ) :
395       QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
396     {
397     }
398
399     bool OnTop() const
400     {
401         return onTop;
402     }
403
404 private:
405     bool onTop;
406 };
407
408 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
409 {
410     int i_ret = VLC_EGENERIC;
411     switch( i_query )
412     {
413         case VOUT_GET_SIZE:
414         {
415             unsigned int *pi_width  = va_arg( args, unsigned int * );
416             unsigned int *pi_height = va_arg( args, unsigned int * );
417             *pi_width = videoWidget->widgetSize.width();
418             *pi_height = videoWidget->widgetSize.height();
419             i_ret = VLC_SUCCESS;
420             break;
421         }
422         case VOUT_SET_SIZE:
423         {
424             unsigned int i_width  = va_arg( args, unsigned int );
425             unsigned int i_height = va_arg( args, unsigned int );
426             videoWidget->widgetSize = QSize( i_width, i_height );
427             // videoWidget->updateGeometry();
428             need_components_update = true;
429             i_ret = VLC_SUCCESS;
430             break;
431         }
432         case VOUT_SET_STAY_ON_TOP:
433         {
434             int i_arg = va_arg( args, int );
435             QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
436             i_ret = VLC_SUCCESS;
437             break;
438         }
439         default:
440             msg_Warn( p_intf, "unsupported control query" );
441             break;
442     }
443     return i_ret;
444 }
445
446 void MainInterface::advanced()
447 {
448     if( !VISIBLE( advControls ) )
449     {
450         advControls->show();
451         advControlsEnabled = true;
452     }
453     else
454     {
455         advControls->hide();
456         advControlsEnabled = false;
457     }
458     doComponentsUpdate();
459 }
460
461 void MainInterface::visual()
462 {
463     if( !VISIBLE( visualSelector) )
464     {
465         visualSelector->show();
466         if( !THEMIM->getIM()->hasVideo() )
467         {
468             /* Show the background widget */
469         }
470         visualSelectorEnabled = true;
471     }
472     else
473     {
474         /* Stop any currently running visualization */
475         visualSelector->hide();
476         visualSelectorEnabled = false;
477     }
478     doComponentsUpdate();
479 }
480
481 void MainInterface::playlist()
482 {
483     // Toggle the playlist dialog
484     if( !playlistEmbeddedFlag )
485     {
486         if( playlistWidget )
487         {
488             /// \todo Destroy it
489         }
490         THEDP->playlistDialog();
491         return;
492     }
493
494     if( !playlistWidget )
495     {
496         PlaylistDialog::killInstance();
497         playlistWidget = new PlaylistWidget( p_intf );
498         ui.vboxLayout->insertWidget( 0, playlistWidget );
499         playlistWidget->widgetSize = settings->value( "playlistSize",
500                                                QSize( 650, 310 ) ).toSize();
501         playlistWidget->hide();
502     }
503     if( VISIBLE( playlistWidget ) )
504     {
505         playlistWidget->hide();
506         if( videoIsActive )
507         {
508             videoWidget->widgetSize = savedVideoSize;
509             videoWidget->resize( videoWidget->widgetSize );
510             videoWidget->updateGeometry();
511         }
512     }
513     else
514     {
515         playlistWidget->show();
516         if( videoIsActive )
517         {
518             savedVideoSize = videoWidget->widgetSize;
519             videoWidget->widgetSize.setHeight( 0 );
520             videoWidget->resize( videoWidget->widgetSize );
521             videoWidget->updateGeometry();
522         }
523         if( VISIBLE( bgWidget ) ) bgWidget->hide();
524     }
525     doComponentsUpdate();
526 }
527
528 /* Video widget cannot do this synchronously as it runs in another thread */
529 /* Well, could it, actually ? Probably dangerous ... */
530 void MainInterface::doComponentsUpdate()
531 {
532     calculateInterfaceSize();
533     resize( mainSize );
534 }
535
536 void MainInterface::undockPlaylist()
537 {
538     if( playlistWidget )
539     {
540         playlistWidget->hide();
541         playlistWidget->deleteLater();
542         ui.vboxLayout->removeWidget( playlistWidget );
543         playlistWidget = NULL;
544         playlistEmbeddedFlag = false;
545
546         menuBar()->clear();
547         QVLCMenu::createMenuBar( this, p_intf, false, advControlsEnabled,
548                                  visualSelectorEnabled);
549
550         if( videoIsActive )
551         {
552             videoWidget->widgetSize = savedVideoSize;
553             videoWidget->resize( videoWidget->widgetSize );
554             videoWidget->updateGeometry();
555         }
556
557         doComponentsUpdate();
558         THEDP->playlistDialog();
559     }
560 }
561
562 void MainInterface::customEvent( QEvent *event )
563 {
564     if( event->type() == PLDockEvent_Type )
565     {
566         PlaylistDialog::killInstance();
567         playlistEmbeddedFlag = true;
568         menuBar()->clear();
569         QVLCMenu::createMenuBar(this, p_intf, true, advControlsEnabled,
570                                 visualSelectorEnabled);
571         playlist();
572     }
573     else if ( event->type() == SetVideoOnTopEvent_Type )
574     {
575         SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
576         if( p_event->OnTop() )
577             setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
578         else
579             setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
580         show(); /* necessary to apply window flags?? */
581     }
582 }
583
584
585 /************************************************************************
586  * D&D
587  ************************************************************************/
588 void MainInterface::dropEvent(QDropEvent *event)
589 {
590      const QMimeData *mimeData = event->mimeData();
591
592      /* D&D of a subtitles file, add it on the fly */
593      if( mimeData->urls().size() == 1 )
594      {
595         if( THEMIM->getIM()->hasInput() )
596         {
597             if( input_AddSubtitles( THEMIM->getInput(),
598                                     qtu( mimeData->urls()[0].toString() ),
599                                     VLC_TRUE ) )
600             {
601                 event->acceptProposedAction();
602                 return;
603             }
604         }
605      }
606      bool first = true;
607      foreach( QUrl url, mimeData->urls() ) {
608         QString s = url.toString();
609         if( s.length() > 0 ) {
610             playlist_Add( THEPL, qtu(s), NULL,
611                           PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
612                           PLAYLIST_END, VLC_TRUE, VLC_FALSE );
613             first = false;
614         }
615      }
616      event->acceptProposedAction();
617 }
618 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
619 {
620      event->acceptProposedAction();
621 }
622 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
623 {
624      event->acceptProposedAction();
625 }
626 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
627 {
628      event->accept();
629 }
630
631 /************************************************************************
632  * Other stuff
633  ************************************************************************/
634 void MainInterface::keyPressEvent( QKeyEvent *e )
635 {
636     int i_vlck = qtEventToVLCKey( e );
637     if( i_vlck >= 0 )
638     {
639         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
640         e->accept();
641     }
642     else
643         e->ignore();
644 }
645
646 void MainInterface::wheelEvent( QWheelEvent *e )
647 {
648     int i_vlckey = qtWheelEventToVLCKey( e );
649     var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
650     e->accept();
651 }
652
653 void MainInterface::stop()
654 {
655     THEMIM->stop();
656 }
657
658 void MainInterface::play()
659 {
660     if( playlist_IsEmpty(THEPL) )
661     {
662         /* The playlist is empty, open a file requester */
663         THEDP->openFileDialog();
664         setStatus( 0 );
665         return;
666     }
667     THEMIM->togglePlayPause();
668 }
669
670 void MainInterface::prev()
671 {
672     THEMIM->prev();
673 }
674
675 void MainInterface::next()
676 {
677     THEMIM->next();
678 }
679
680 void MainInterface::setDisplay( float pos, int time, int length )
681 {
682     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
683     secstotimestr( psz_length, length );
684     secstotimestr( psz_time, time );
685     QString title;
686     title.sprintf( "%s/%s", psz_time, psz_length );
687     timeLabel->setText( " "+title+" " );
688 }
689
690 void MainInterface::setName( QString name )
691 {
692     nameLabel->setText( " " + name+" " );
693     setVLCWindowsTitle( name );
694 }
695
696 void MainInterface::setStatus( int status )
697 {
698     if( status == 1 ) // Playing
699         ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
700     else
701         ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
702 }
703
704 #define HELP_MENU N_("Menu")
705 #define HELP_PCH N_("Previous chapter")
706 #define HELP_NCH N_("Next chapter")
707 #define HELP_PTR N_("Previous track")
708 #define HELP_NTR N_("Next track")
709
710 void MainInterface::setNavigation( int navigation )
711 {
712     // 1 = chapter, 2 = title, 0 = no
713     if( navigation == 0 )
714     {
715         ui.discFrame->hide();
716     } else if( navigation == 1 ) {
717         ui.prevSectionButton->show();
718         ui.prevSectionButton->setToolTip( qfu(HELP_PCH) );
719         ui.nextSectionButton->show();
720         ui.nextSectionButton->setToolTip( qfu(HELP_NCH) );
721         ui.menuButton->show();
722         ui.discFrame->show();
723     } else {
724         ui.prevSectionButton->show();
725         ui.prevSectionButton->setToolTip( qfu(HELP_PCH) );
726         ui.nextSectionButton->show();
727         ui.nextSectionButton->setToolTip( qfu(HELP_NCH) );
728         ui.menuButton->hide();
729         ui.discFrame->show();
730     }
731 }
732
733 static bool b_my_volume;
734
735 void MainInterface::updateOnTimer()
736 {
737     /* \todo Make this event-driven */
738     advControls->enableInput( THEMIM->getIM()->hasInput() );
739     advControls->enableVideo( THEMIM->getIM()->hasVideo() );
740
741     if( intf_ShouldDie( p_intf ) )
742     {
743         QApplication::closeAllWindows();
744         QApplication::quit();
745     }
746     if( need_components_update )
747     {
748         doComponentsUpdate();
749         need_components_update = false;
750     }
751
752     audio_volume_t i_volume;
753     aout_VolumeGet( p_intf, &i_volume );
754     i_volume = (i_volume *  200 )/ AOUT_VOLUME_MAX ;
755     int i_gauge = ui.volumeSlider->value();
756     b_my_volume = false;
757     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
758     {
759         b_my_volume = true;
760         ui.volumeSlider->setValue( i_volume );
761         b_my_volume = false;
762     }
763 }
764
765 void MainInterface::closeEvent( QCloseEvent *e )
766 {
767     hide();
768     p_intf->b_die = VLC_TRUE;
769 }
770
771 void MainInterface::updateVolume( int sliderVolume )
772 {
773     if( !b_my_volume )
774     {
775         int i_res = sliderVolume * AOUT_VOLUME_MAX /
776                             (2*ui.volumeSlider->maximum() );
777         aout_VolumeSet( p_intf, i_res );
778     }
779 }
780
781 static int InteractCallback( vlc_object_t *p_this,
782                              const char *psz_var, vlc_value_t old_val,
783                              vlc_value_t new_val, void *param )
784 {
785     intf_dialog_args_t *p_arg = new intf_dialog_args_t;
786     p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
787     DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
788     QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
789     return VLC_SUCCESS;
790 }
791
792 /*****************************************************************************
793  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
794  *  We don't show the menu directly here because we don't want the
795  *  caller to block for a too long time.
796  *****************************************************************************/
797 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
798                         vlc_value_t old_val, vlc_value_t new_val, void *param )
799 {
800     intf_thread_t *p_intf = (intf_thread_t *)param;
801
802     if( p_intf->pf_show_dialog )
803     {
804         p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
805                                 new_val.b_bool, 0 );
806     }
807
808     return VLC_SUCCESS;
809 }
810
811 /*****************************************************************************
812  * IntfShowCB: callback triggered by the intf-show playlist variable.
813  *****************************************************************************/
814 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
815                        vlc_value_t old_val, vlc_value_t new_val, void *param )
816 {
817     intf_thread_t *p_intf = (intf_thread_t *)param;
818     //p_intf->p_sys->b_intf_show = VLC_TRUE;
819
820     return VLC_SUCCESS;
821 }