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