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