]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
Qt4: firstRun dialog is now separated
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_interface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Ilkka Ollakka <ileoo@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "qt4.hpp"
31
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
35
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
38
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
43 #include "dialogs/firstrun.hpp"
44
45 #include "menus.hpp"
46 #include "recents.hpp"
47
48 #include <QCloseEvent>
49 #include <QKeyEvent>
50
51 #include <QUrl>
52 #include <QSize>
53 #include <QDate>
54
55 #include <QMenu>
56 #include <QMenuBar>
57 #include <QStatusBar>
58 #include <QLabel>
59 #include <QGroupBox>
60 #include <QPushButton>
61 #include <QStackedWidget>
62
63 #ifdef WIN32
64  #include <vlc_windows_interfaces.h>
65  #include <QBitmap>
66 #endif
67
68 #include <assert.h>
69
70 #include <vlc_keys.h> /* Wheel event */
71 #include <vlc_vout_window.h>
72 #include <vlc_vout.h>
73
74 /* Callback prototypes */
75 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
76                         vlc_value_t old_val, vlc_value_t new_val, void *param );
77 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
78                        vlc_value_t old_val, vlc_value_t new_val, void *param );
79
80 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
81 {
82     /* Variables initialisation */
83     // need_components_update = false;
84     bgWidget             = NULL;
85     videoWidget          = NULL;
86     playlistWidget       = NULL;
87 #ifndef HAVE_MAEMO
88     sysTray              = NULL;
89 #endif
90     fullscreenControls   = NULL;
91     cryptedLabel         = NULL;
92     controls             = NULL;
93     inputC               = NULL;
94
95     b_hideAfterCreation  = false;
96     playlistVisible      = false; // FIXME remove
97     input_name           = "";
98
99     stackCentralOldState = HIDDEN_TAB;
100     i_bg_height          = 0;
101
102     /* Ask for Privacy */
103     new FirstRun( this, p_intf );
104
105     /**
106      *  Configuration and settings
107      *  Pre-building of interface
108      **/
109     /* Main settings */
110     setFocusPolicy( Qt::StrongFocus );
111     setAcceptDrops( true );
112     setWindowRole( "vlc-main" );
113     setWindowIcon( QApplication::windowIcon() );
114     setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115
116     /* Set The Video In emebedded Mode or not */
117     videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
118
119     /* Does the interface resize to video size or the opposite */
120     b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
121
122     /* Are we in the enhanced always-video mode or not ? */
123     i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
124
125         /* Do we want anoying popups or not */
126     notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
127
128     /* Set the other interface settings */
129     settings = getSettings();
130     settings->beginGroup( "MainWindow" );
131
132     /**
133      * Retrieve saved sizes for main window
134      *   mainBasedSize = based window size for normal mode
135      *                  (no video, no background)
136      *   mainVideoSize = window size with video (all modes)
137      **/
138     mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
139     mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
140
141     /**************
142      * Status Bar *
143      **************/
144     createStatusBar();
145
146     /**************************
147      *  UI and Widgets design
148      **************************/
149     setVLCWindowsTitle();
150     createMainWidget( settings );
151
152     /************
153      * Menu Bar *
154      ************/
155     QVLCMenu::createMenuBar( this, p_intf );
156     CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
157              this, destroyPopupMenu() );
158
159 #if 0
160     /* Create a Dock to get the playlist */
161     dockPL = new QDockWidget( qtr( "Playlist" ), this );
162     dockPL->setSizePolicy( QSizePolicy::Preferred,
163                            QSizePolicy::Expanding );
164     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
165     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
166                            | Qt::RightDockWidgetArea
167                            | Qt::BottomDockWidgetArea );
168     dockPL->hide();
169 #endif
170
171     /*********************************
172      * Create the Systray Management *
173      *********************************/
174     initSystray();
175
176     /********************
177      * Input Manager    *
178      ********************/
179     MainInputManager::getInstance( p_intf );
180
181     /************************************************************
182      * Connect the input manager to the GUI elements it manages *
183      ************************************************************/
184     /**
185      * Connects on nameChanged()
186      * Those connects are different because options can impeach them to trigger.
187      **/
188     /* Main Interface statusbar */
189     CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
190              this, setName( const QString& ) );
191     /* and systray */
192 #ifndef HAVE_MAEMO
193     if( sysTray )
194     {
195         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
196                  this, updateSystrayTooltipName( const QString& ) );
197     }
198 #endif
199     /* and title of the Main Interface*/
200     if( config_GetInt( p_intf, "qt-name-in-title" ) )
201     {
202         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
203                  this, setVLCWindowsTitle( const QString& ) );
204     }
205
206     /**
207      * CONNECTS on PLAY_STATUS
208      **/
209     /* Status on the systray */
210 #ifndef HAVE_MAEMO
211     if( sysTray )
212     {
213         CONNECT( THEMIM->getIM(), statusChanged( int ),
214                  this, updateSystrayTooltipStatus( int ) );
215     }
216 #endif
217
218     /* END CONNECTS ON IM */
219
220     /************
221      * Callbacks
222      ************/
223     var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
224
225     /* Register callback for the intf-popupmenu variable */
226     var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
227
228
229     /* VideoWidget connects for asynchronous calls */
230     connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
231              this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
232              Qt::BlockingQueuedConnection );
233     connect( this, SIGNAL(askReleaseVideo( void )),
234              this, SLOT(releaseVideoSlot( void )),
235              Qt::BlockingQueuedConnection );
236
237     if( videoWidget )
238     {
239         CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
240                  videoWidget, SetSizing( unsigned int, unsigned int ) );
241         CONNECT( this, askVideoSetFullScreen( bool ),
242                  videoWidget, SetFullScreen( bool ) );
243         CONNECT( videoWidget, keyPressed( QKeyEvent * ),
244                  this, handleKeyPress( QKeyEvent * ) );
245     }
246
247     CONNECT( this, askUpdate(), this, doComponentsUpdate() );
248     CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
249
250     /* Size and placement of interface */
251     settings->beginGroup( "MainWindow" );
252     QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
253
254     /* resize to previously saved main window size if appicable */
255     if( b_keep_size )
256     {
257        if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
258            i_visualmode == QT_MINIMAL_MODE )
259        {
260            resize( mainVideoSize );
261        }
262        else
263        {
264            resize( mainBasedSize );
265        }
266     }
267
268     bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
269     settings->endGroup();
270
271     /* Playlist */
272     if( b_pl_visible ) togglePlaylist();
273
274     /* Enable the popup menu in the MI */
275     setContextMenuPolicy( Qt::CustomContextMenu );
276     CONNECT( this, customContextMenuRequested( const QPoint& ),
277              this, popupMenu( const QPoint& ) );
278
279     debug();
280
281     /* Final sizing and showing */
282     setVisible( !b_hideAfterCreation );
283     //setMinimumSize( QSize( 0, 0 ) );
284 //    setMinimumWidth( __MAX( controls->sizeHint().width(),
285   //                          menuBar()->sizeHint().width() ) );
286
287     debug();
288     /* And switch to minimal view if needed
289        Must be called after the show() */
290     if( i_visualmode == QT_MINIMAL_MODE )
291         toggleMinimalView( true );
292
293     /* Update the geometry : It is useful if you switch between
294        qt-display-modes */
295     updateGeometry();
296     resize( sizeHint() );
297
298 #ifdef WIN32
299     createTaskBarButtons();
300 #endif
301 }
302
303 MainInterface::~MainInterface()
304 {
305     msg_Dbg( p_intf, "Destroying the main interface" );
306
307     /* Unsure we hide the videoWidget before destroying it */
308     if( stackCentralOldState == VIDEO_TAB )
309         showBg();
310
311     /* Save playlist state */
312     if( playlistWidget )
313     {
314         if( !isDocked() )
315             QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
316
317         delete playlistWidget;
318     }
319
320 #ifdef WIN32
321     if( himl )
322         ImageList_Destroy( himl );
323     if(p_taskbl)
324         p_taskbl->vt->Release(p_taskbl);
325     CoUninitialize();
326 #endif
327
328     /* Be sure to kill the actionsManager... FIXME */
329     ActionsManager::killInstance();
330
331     /* Delete the FSC controller */
332     delete fullscreenControls;
333
334     /* Save states */
335     settings->beginGroup( "MainWindow" );
336     settings->setValue( "pl-dock-status", (int)i_pl_dock );
337     settings->setValue( "playlist-visible", (int)playlistVisible );
338     settings->setValue( "adv-controls",
339                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
340
341     settings->setValue( "mainBasedSize", mainBasedSize );
342     settings->setValue( "mainVideoSize", mainVideoSize );
343
344     if( bgWidget )
345         settings->setValue( "backgroundSize", bgWidget->size() );
346
347     /* Save this size */
348     QVLCTools::saveWidgetPosition(settings, this);
349     settings->endGroup();
350
351     /* Unregister callbacks */
352     var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
353     var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
354
355     p_intf->p_sys->p_mi = NULL;
356 }
357
358 /*****************************
359  *   Main UI handling        *
360  *****************************/
361 void MainInterface::recreateToolbars()
362 {
363     msg_Dbg( p_intf, "Recreating the toolbars" );
364     settings->beginGroup( "MainWindow" );
365     delete controls;
366     delete inputC;
367     controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
368     CONNECT( controls, advancedControlsToggled( bool ),
369              this, doComponentsUpdate() );
370     CONNECT( controls, sizeChanged(),
371              this, doComponentsUpdate() );
372     inputC = new InputControlsWidget( p_intf, this );
373
374     mainLayout->insertWidget( 2, inputC );
375     mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
376                               controls );
377     settings->endGroup();
378 }
379
380 void MainInterface::createMainWidget( QSettings *settings )
381 {
382     /* Create the main Widget and the mainLayout */
383     QWidget *main = new QWidget;
384     setCentralWidget( main );
385     mainLayout = new QVBoxLayout( main );
386
387     /* Margins, spacing */
388     main->setContentsMargins( 0, 0, 0, 0 );
389     mainLayout->setSpacing( 0 );
390     mainLayout->setMargin( 0 );
391
392     /* */
393     stackCentralW = new QStackedWidget( main );
394
395     /* Bg Cone */
396     bgWidget = new BackgroundWidget( p_intf );
397     bgWidget->resize(
398             settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
399     bgWidget->updateGeometry();
400     stackCentralW->insertWidget( BACKG_TAB, bgWidget );
401
402     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
403         i_visualmode != QT_MINIMAL_MODE )
404     {
405         stackCentralW->hide();
406     }
407
408     /* And video Outputs */
409     if( videoEmbeddedFlag )
410     {
411         videoWidget = new VideoWidget( p_intf );
412         stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
413     }
414     mainLayout->insertWidget( 1, stackCentralW, 100 );
415     /* Create the CONTROLS Widget */
416     controls = new ControlsWidget( p_intf,
417                    settings->value( "adv-controls", false ).toBool(), this );
418     CONNECT( controls, advancedControlsToggled( bool ),
419              this, doComponentsUpdate() );
420     CONNECT( controls, sizeChanged(),
421              this, doComponentsUpdate() );
422     inputC = new InputControlsWidget( p_intf, this );
423
424     //mainLayout->setRowStretch( 1, 10 );
425     mainLayout->insertWidget( 2, inputC );
426     mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
427                               controls );
428
429     /* Visualisation */
430     /* Disabled for now, they SUCK */
431     #if 0
432     visualSelector = new VisualSelector( p_intf );
433     mainLayout->insertWidget( 0, visualSelector );
434     visualSelector->hide();
435     #endif
436
437     /* Finish the sizing */
438     main->updateGeometry();
439
440     getSettings()->endGroup();
441 #ifdef WIN32
442     if ( depth() > 8 )
443 #endif
444     /* Create the FULLSCREEN CONTROLS Widget */
445     if( config_GetInt( p_intf, "qt-fs-controller" ) )
446     {
447         fullscreenControls = new FullscreenControllerWidget( p_intf, this );
448         CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
449                  this, handleKeyPress( QKeyEvent * ) );
450     }
451 }
452
453 inline void MainInterface::createStatusBar()
454 {
455     /****************
456      *  Status Bar  *
457      ****************/
458     /* Widgets Creation*/
459     QStatusBar *statusBarr = statusBar();
460
461     TimeLabel *timeLabel = new TimeLabel( p_intf );
462     nameLabel = new QLabel( this );
463     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
464                                       | Qt::TextSelectableByKeyboard );
465     SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
466
467     /* Styling those labels */
468     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
469     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
470     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
471
472     /* and adding those */
473     statusBarr->addWidget( nameLabel, 8 );
474     statusBarr->addPermanentWidget( speedLabel, 0 );
475     statusBarr->addPermanentWidget( timeLabel, 0 );
476
477     /* timeLabel behaviour:
478        - double clicking opens the goto time dialog
479        - right-clicking and clicking just toggle between remaining and
480          elapsed time.*/
481     CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
482
483     CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
484              this, showCryptedLabel( bool ) );
485 }
486
487 #ifdef WIN32
488 void MainInterface::createTaskBarButtons()
489 {
490     /*Here is the code for the taskbar thumb buttons
491     FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
492     FIXME:the play button's picture doesn't changed to pause when clicked
493     */
494     OSVERSIONINFO winVer;
495     winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
496     if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
497     {
498         if(himl = ImageList_Create( 15, //cx
499                                     18, //cy
500                                     ILC_COLOR,//flags
501                                     4,//initial nb of images
502                                     0//nb of images that can be added
503                                     ))
504         {
505             QPixmap img   = QPixmap(":/toolbar/previous_b");
506             QPixmap img2  = QPixmap(":/toolbar/pause_b");
507             QPixmap img3  = QPixmap(":/toolbar/play_b");
508             QPixmap img4  = QPixmap(":/toolbar/next_b");
509             QBitmap mask  = img.createMaskFromColor(Qt::transparent);
510             QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
511             QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
512             QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
513
514             if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
515                 msg_Err( p_intf, "ImageList_Add failed" );
516             if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
517                 msg_Err( p_intf, "ImageList_Add failed" );
518             if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
519                 msg_Err( p_intf, "ImageList_Add failed" );
520             if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
521                 msg_Err( p_intf, "ImageList_Add failed" );
522         }
523
524         CoInitialize( 0 );
525
526         if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
527                     NULL, CLSCTX_INPROC_SERVER,
528                     &IID_ITaskbarList3,
529                     (void **)&p_taskbl) )
530         {
531             p_taskbl->vt->HrInit(p_taskbl);
532
533             int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
534             //msg_Info( p_intf, "msg value: %04x", msg_value );
535
536             // Define an array of two buttons. These buttons provide images through an
537             // image list and also provide tooltips.
538             DWORD dwMask = THB_BITMAP | THB_FLAGS;
539
540             THUMBBUTTON thbButtons[2];
541             thbButtons[0].dwMask = dwMask;
542             thbButtons[0].iId = 0;
543             thbButtons[0].iBitmap = 0;
544             thbButtons[0].dwFlags = THBF_HIDDEN;
545
546             thbButtons[1].dwMask = dwMask;
547             thbButtons[1].iId = 1;
548             thbButtons[1].iBitmap = 2;
549             thbButtons[1].dwFlags = THBF_HIDDEN;
550
551             thbButtons[2].dwMask = dwMask;
552             thbButtons[2].iId = 2;
553             thbButtons[2].iBitmap = 3;
554             thbButtons[2].dwFlags = THBF_HIDDEN;
555
556             HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
557             if(S_OK != hr)
558                 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
559             if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
560                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
561
562             CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
563         }
564     }
565     else
566     {
567         himl = NULL;
568         p_taskbl = NULL;
569     }
570 }
571 #endif
572
573
574 inline void MainInterface::initSystray()
575 {
576 #ifndef HAVE_MAEMO
577     bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
578     bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
579
580     if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
581     {
582         if( b_systrayAvailable )
583         {
584             b_systrayWanted = true;
585             b_hideAfterCreation = true;
586         }
587         else
588             msg_Err( p_intf, "cannot start minimized without system tray bar" );
589     }
590
591     if( b_systrayAvailable && b_systrayWanted )
592             createSystray();
593 #endif
594 }
595
596
597 /**********************************************************************
598  * Handling of sizing of the components
599  **********************************************************************/
600
601 /* This function is probably wrong, but we don't have many many choices...
602    Since we can't know from the playlist Widget if we are inside a dock or not,
603    because the playlist Widget can be called by THEDP, as a separate windows for
604    the skins.
605    Maybe the other solution is to redefine the sizeHint() of the playlist and
606    ask _parent->isFloating()...
607    If you think this would be better, please FIXME it...
608 */
609
610 QSize MainInterface::sizeHint() const
611 {
612 #if 0
613     if( b_keep_size )
614     {
615         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
616             i_visualmode == QT_MINIMAL_MODE )
617         {
618                 return mainVideoSize;
619         }
620         else
621         {
622             if( VISIBLE( bgWidget) ||
623                 ( videoIsActive && videoWidget->isVisible() )
624               )
625                 return mainVideoSize;
626             else
627                 return mainBasedSize;
628         }
629     }
630 #endif
631
632     int nwidth  = __MAX( controls->sizeHint().width(),
633                          menuBar()->sizeHint().width() );
634
635     int nheight = controls->isVisible() ?
636                   controls->size().height()
637                   + inputC->size().height()
638                   + menuBar()->size().height()
639                   + statusBar()->size().height()
640                   : 0 ;
641
642     if( stackCentralW->isVisible() )
643         nheight += stackCentralW->height();
644         nwidth  = __MAX( nwidth, stackCentralW->width() );
645
646 /*    if( VISIBLE( bgWidget ) )
647     {
648         msg_Warn( p_intf, "Hello here" );
649         if( i_bg_height )
650             nheight += i_bg_height;
651         else
652             nheight += bgWidget->size().height();
653         nwidth  = __MAX( nwidth, bgWidget->size().width() );
654     }
655     else if( videoIsActive && videoWidget->isVisible() )
656     {
657         msg_Warn( p_intf, "Hello there" );
658         nheight += videoWidget->sizeHint().height();
659         nwidth  = __MAX( nwidth, videoWidget->sizeHint().width() );
660     }*/
661 #if 0
662     if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget()  )
663     {
664         nheight += dockPL->size().height();
665         nwidth = __MAX( nwidth, dockPL->size().width() );
666         msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
667     }
668 #endif
669     return QSize( nwidth, nheight );
670 }
671
672
673 /* Video widget cannot do this synchronously as it runs in another thread */
674 /* Well, could it, actually ? Probably dangerous ... */
675
676 /* This function is called:
677    - toggling of minimal View
678    - through askUpdate() by Vout thread request video and resize video (zoom)
679    - Advanced buttons toggled
680  */
681 void MainInterface::doComponentsUpdate()
682 {
683     if( isFullScreen() || isMaximized() ) return;
684
685     msg_Warn( p_intf, "Updating the geometry" );
686     /* Here we resize to sizeHint() and not adjustsize because we want
687        the videoWidget to be exactly the correctSize */
688
689 #ifndef NDEBUG
690     debug();
691 #endif
692     /* This is WRONG, but I believe there is a Qt bug here */
693     setMinimumSize( 0, 0 );
694     resize( sizeHint() );
695
696     //adjustSize() ; /* This is not needed, but might help in the future */
697 }
698
699 void MainInterface::debug()
700 {
701 #ifndef NDEBUG
702     msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
703     msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
704
705     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
706     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
707     //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
708
709     msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
710     msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
711     msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
712     msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
713     msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
714     msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
715     msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
716
717     /*if( videoWidget && videoWidget->isVisible() )
718     {
719         msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
720         msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
721     }*/
722 #endif
723 }
724
725 void MainInterface::destroyPopupMenu()
726 {
727     QVLCMenu::PopupMenu( p_intf, false );
728 }
729
730 void MainInterface::toggleFSC()
731 {
732    if( !fullscreenControls ) return;
733
734    IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
735    QApplication::postEvent( fullscreenControls, eShow );
736 }
737
738 void MainInterface::popupMenu( const QPoint &p )
739 {
740     /* Ow, that's ugly: don't show the popup menu if cursor over
741      * the main menu bar or the status bar */
742     if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
743                         && ( childAt( p )->parentWidget() != statusBar() ) ) )
744         QVLCMenu::PopupMenu( p_intf, true );
745 }
746
747 /****************************************************************************
748  * Video Handling
749  ****************************************************************************/
750
751 /* This event is used to deal with the fullscreen and always on top
752    issue conflict (bug in wx) */
753 class SetVideoOnTopQtEvent : public QEvent
754 {
755 public:
756     SetVideoOnTopQtEvent( bool _onTop ) :
757       QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
758     {}
759
760     bool OnTop() const { return onTop; }
761
762 private:
763     bool onTop;
764 };
765
766 /**
767  * NOTE:
768  * You must note change the state of this object or other Qt4 UI objects,
769  * from the video output thread - only from the Qt4 UI main loop thread.
770  * All window provider queries must be handled through signals or events.
771  * That's why we have all those emit statements...
772  */
773 WId MainInterface::getVideo( int *pi_x, int *pi_y,
774                              unsigned int *pi_width, unsigned int *pi_height )
775 {
776     if( !videoWidget )
777         return 0;
778
779     /* This is a blocking call signal. Results are returned through pointers.
780      * Beware of deadlocks! */
781     WId id;
782     emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
783     return id;
784 }
785
786 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
787                                   unsigned *pi_width, unsigned *pi_height )
788 {
789     /* Request the videoWidget */
790     WId ret = videoWidget->request( pi_x, pi_y,
791                                     pi_width, pi_height, b_keep_size );
792     *p_id = ret;
793     if( ret ) /* The videoWidget is available */
794     {
795         /* ask videoWidget to show */
796         videoWidget->SetSizing( *pi_width, *pi_height );
797
798         /* Consider the video active now */
799         showVideo();
800
801         stackCentralW->resize( *pi_width, *pi_height );
802
803         emit askUpdate();
804     }
805 }
806
807 inline void MainInterface::showTab( int i_tab )
808 {
809     stackCentralOldState = stackCentralW->currentIndex();
810
811     stackCentralW->setCurrentIndex( i_tab );
812     if( stackCentralW->isHidden() ) stackCentralW->show();
813 }
814
815 /* Asynchronous call from the WindowClose function */
816 void MainInterface::releaseVideo( void )
817 {
818     emit askReleaseVideo( );
819 }
820
821 /* Function that is CONNECTED to the previous emit */
822 void MainInterface::releaseVideoSlot( void )
823 {
824     videoWidget->release( );
825
826     /* Restore the previous State */
827     if( stackCentralOldState == BACKG_TAB )
828     {
829         showBg();
830     }
831     else
832     {
833         stackCentralW->hide();
834         stackCentralOldState == -1;
835     }
836
837     /* Try to resize, except when you are in Fullscreen mode */
838     doComponentsUpdate();
839 }
840
841 /* Asynchronous call from WindowControl function */
842 int MainInterface::controlVideo( int i_query, va_list args )
843 {
844     /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
845     msg_Warn( p_intf, "Control Video: %i", i_query );
846     switch( i_query )
847     {
848     case VOUT_WINDOW_SET_SIZE:
849     {
850         unsigned int i_width  = va_arg( args, unsigned int );
851         unsigned int i_height = va_arg( args, unsigned int );
852         emit askVideoToResize( i_width, i_height );
853         emit askUpdate();
854         return VLC_SUCCESS;
855     }
856     case VOUT_WINDOW_SET_ON_TOP:
857     {
858         int i_arg = va_arg( args, int );
859         QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
860         return VLC_SUCCESS;
861     }
862     case VOUT_WINDOW_SET_FULLSCREEN:
863     {
864         bool b_fs = va_arg( args, int );
865         emit askVideoSetFullScreen( b_fs );
866         return VLC_SUCCESS;
867     }
868     default:
869         msg_Warn( p_intf, "unsupported control query" );
870         return VLC_EGENERIC;
871     }
872 }
873
874 /*****************************************************************************
875  * Playlist, Visualisation and Menus handling
876  *****************************************************************************/
877 /**
878  * Toggle the playlist widget or dialog
879  **/
880 void MainInterface::togglePlaylist()
881 {
882     /* CREATION
883     If no playlist exist, then create one and attach it to the DockPL*/
884     if( !playlistWidget )
885     {
886         playlistWidget = new PlaylistWidget( p_intf );
887
888         i_pl_dock = PL_BOTTOM;
889         /*i_pl_dock = (pl_dock_e)getSettings()
890                          ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
891
892         if( i_pl_dock == PL_UNDOCKED )
893         {
894             playlistWidget->setWindowFlags( Qt::Window );
895
896             /* This will restore the geometry but will not work for position,
897                because of parenting */
898             QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
899                     playlistWidget, QSize( 600, 300 ) );
900         }
901         else
902         {
903             stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
904             stackCentralW->setCurrentWidget( playlistWidget );
905             stackCentralW->show();
906         }
907         playlistVisible = true;
908
909         playlistWidget->show();
910     }
911     else
912     {
913     /* toggle the visibility of the playlist */
914         if( stackCentralW->currentIndex() != PLAYL_TAB )
915         {
916             stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
917             stackCentralW->setCurrentWidget( playlistWidget );
918             stackCentralW->show();
919         }
920         else
921             stackCentralW->setCurrentIndex( VIDEO_TAB );
922        playlistVisible = !playlistVisible;
923        //doComponentsUpdate(); //resize( sizeHint() );
924     }
925 }
926
927 /* Function called from the menu to undock the playlist */
928 void MainInterface::undockPlaylist()
929 {
930 //    dockPL->setFloating( true );
931 //    adjustSize();
932 }
933
934 void MainInterface::dockPlaylist( pl_dock_e i_pos )
935 {
936 }
937
938 void MainInterface::toggleMinimalView( bool b_switch )
939 {
940     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
941         i_visualmode != QT_MINIMAL_MODE )
942     { /* NORMAL MODE then */
943         stackCentralW->show();
944         if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
945         {
946             showBg();
947         }
948         else
949         {
950             /* If video is visible, then toggle the status of bgWidget */
951             //bgWasVisible = !bgWasVisible;
952             if( stackCentralOldState == BACKG_TAB )
953                 stackCentralOldState = HIDDEN_TAB;
954             else
955                 stackCentralOldState = BACKG_TAB;
956         }
957     }
958
959     i_bg_height = stackCentralW->height();
960
961     menuBar()->setVisible( !b_switch );
962     controls->setVisible( !b_switch );
963     statusBar()->setVisible( !b_switch );
964     inputC->setVisible( !b_switch );
965
966     doComponentsUpdate();
967
968     emit minimalViewToggled( b_switch );
969 }
970
971 /* toggling advanced controls buttons */
972 void MainInterface::toggleAdvanced()
973 {
974     controls->toggleAdvanced();
975 //    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
976 }
977
978 /* Get the visibility status of the controls (hidden or not, advanced or not) */
979 int MainInterface::getControlsVisibilityStatus()
980 {
981     return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
982                 + CONTROLS_ADVANCED * controls->b_advancedVisible );
983 }
984
985 #if 0
986 void MainInterface::visual()
987 {
988     if( !VISIBLE( visualSelector) )
989     {
990         visualSelector->show();
991         if( !THEMIM->getIM()->hasVideo() )
992         {
993             /* Show the background widget */
994         }
995         visualSelectorEnabled = true;
996     }
997     else
998     {
999         /* Stop any currently running visualization */
1000         visualSelector->hide();
1001         visualSelectorEnabled = false;
1002     }
1003     doComponentsUpdate();
1004 }
1005 #endif
1006
1007 /************************************************************************
1008  * Other stuff
1009  ************************************************************************/
1010 void MainInterface::setName( const QString& name )
1011 {
1012     input_name = name; /* store it for the QSystray use */
1013     /* Display it in the status bar, but also as a Tooltip in case it doesn't
1014        fit in the label */
1015     nameLabel->setText( " " + name + " " );
1016     nameLabel->setToolTip( " " + name +" " );
1017 }
1018
1019 /**
1020  * Give the decorations of the Main Window a correct Name.
1021  * If nothing is given, set it to VLC...
1022  **/
1023 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1024 {
1025     if( aTitle.isEmpty() )
1026     {
1027         setWindowTitle( qtr( "VLC media player" ) );
1028     }
1029     else
1030     {
1031         setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1032     }
1033 }
1034
1035 void MainInterface::showCryptedLabel( bool b_show )
1036 {
1037     if( cryptedLabel == NULL )
1038     {
1039         cryptedLabel = new QLabel;
1040         // The lock icon is not the right one for DRM protection/scrambled.
1041         //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1042         cryptedLabel->setText( "DRM" );
1043         statusBar()->addWidget( cryptedLabel );
1044     }
1045
1046     cryptedLabel->setVisible( b_show );
1047 }
1048
1049 /*****************************************************************************
1050  * Systray Icon and Systray Menu
1051  *****************************************************************************/
1052 #ifndef HAVE_MAEMO
1053 /**
1054  * Create a SystemTray icon and a menu that would go with it.
1055  * Connects to a click handler on the icon.
1056  **/
1057 void MainInterface::createSystray()
1058 {
1059     QIcon iconVLC;
1060     if( QDate::currentDate().dayOfYear() >= 354 )
1061         iconVLC =  QIcon( ":/logo/vlc128-christmas.png" );
1062     else
1063         iconVLC =  QIcon( ":/logo/vlc128.png" );
1064     sysTray = new QSystemTrayIcon( iconVLC, this );
1065     sysTray->setToolTip( qtr( "VLC media player" ));
1066
1067     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1068     systrayMenu->setIcon( iconVLC );
1069
1070     QVLCMenu::updateSystrayMenu( this, p_intf, true );
1071     sysTray->show();
1072
1073     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1074             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1075 }
1076
1077 /**
1078  * Updates the Systray Icon's menu and toggle the main interface
1079  */
1080 void MainInterface::toggleUpdateSystrayMenu()
1081 {
1082     /* If hidden, show it */
1083     if( isHidden() )
1084     {
1085         show();
1086         activateWindow();
1087     }
1088     else if( isMinimized() )
1089     {
1090         /* Minimized */
1091         showNormal();
1092         activateWindow();
1093     }
1094     else
1095     {
1096         /* Visible (possibly under other windows) */
1097 #ifdef WIN32
1098         /* check if any visible window is above vlc in the z-order,
1099          * but ignore the ones always on top
1100          * and the ones which can't be activated */
1101         WINDOWINFO wi;
1102         HWND hwnd;
1103         wi.cbSize = sizeof( WINDOWINFO );
1104         for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1105                 hwnd && ( !IsWindowVisible( hwnd ) ||
1106                     ( GetWindowInfo( hwnd, &wi ) &&
1107                       (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1108                 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1109             if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1110                 (wi.dwExStyle&WS_EX_TOPMOST) )
1111             {
1112                 hide();
1113             }
1114             else
1115             {
1116                 activateWindow();
1117             }
1118 #else
1119         hide();
1120 #endif
1121     }
1122     QVLCMenu::updateSystrayMenu( this, p_intf );
1123 }
1124
1125 void MainInterface::handleSystrayClick(
1126                                     QSystemTrayIcon::ActivationReason reason )
1127 {
1128     switch( reason )
1129     {
1130         case QSystemTrayIcon::Trigger:
1131         case QSystemTrayIcon::DoubleClick:
1132             toggleUpdateSystrayMenu();
1133             break;
1134         case QSystemTrayIcon::MiddleClick:
1135             sysTray->showMessage( qtr( "VLC media player" ),
1136                     qtr( "Control menu for the player" ),
1137                     QSystemTrayIcon::Information, 3000 );
1138             break;
1139         default:
1140             break;
1141     }
1142 }
1143
1144 /**
1145  * Updates the name of the systray Icon tooltip.
1146  * Doesn't check if the systray exists, check before you call it.
1147  **/
1148 void MainInterface::updateSystrayTooltipName( const QString& name )
1149 {
1150     if( name.isEmpty() )
1151     {
1152         sysTray->setToolTip( qtr( "VLC media player" ) );
1153     }
1154     else
1155     {
1156         sysTray->setToolTip( name );
1157         if( notificationEnabled && ( isHidden() || isMinimized() ) )
1158         {
1159             sysTray->showMessage( qtr( "VLC media player" ), name,
1160                     QSystemTrayIcon::NoIcon, 3000 );
1161         }
1162     }
1163
1164     QVLCMenu::updateSystrayMenu( this, p_intf );
1165 }
1166
1167 /**
1168  * Updates the status of the systray Icon tooltip.
1169  * Doesn't check if the systray exists, check before you call it.
1170  **/
1171 void MainInterface::updateSystrayTooltipStatus( int i_status )
1172 {
1173     switch( i_status )
1174     {
1175         case  0:
1176         case  END_S:
1177             {
1178                 sysTray->setToolTip( qtr( "VLC media player" ) );
1179                 break;
1180             }
1181         case PLAYING_S:
1182             {
1183                 sysTray->setToolTip( input_name );
1184                 break;
1185             }
1186         case PAUSE_S:
1187             {
1188                 sysTray->setToolTip( input_name + " - "
1189                         + qtr( "Paused") );
1190                 break;
1191             }
1192     }
1193     QVLCMenu::updateSystrayMenu( this, p_intf );
1194 }
1195 #endif
1196
1197 /************************************************************************
1198  * D&D Events
1199  ************************************************************************/
1200 void MainInterface::dropEvent(QDropEvent *event)
1201 {
1202     dropEventPlay( event, true );
1203 }
1204
1205 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1206 {
1207     event->setDropAction( Qt::CopyAction );
1208     if( !event->possibleActions() & Qt::CopyAction )
1209         return;
1210
1211     const QMimeData *mimeData = event->mimeData();
1212
1213     /* D&D of a subtitles file, add it on the fly */
1214     if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1215     {
1216         if( !input_AddSubtitle( THEMIM->getInput(),
1217                  qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1218                  true ) )
1219         {
1220             event->accept();
1221             return;
1222         }
1223     }
1224
1225     bool first = b_play;
1226     foreach( const QUrl &url, mimeData->urls() )
1227     {
1228         QString s = toNativeSeparators( url.toLocalFile() );
1229
1230         if( s.length() > 0 ) {
1231             char* psz_uri = make_URI( qtu(s) );
1232             playlist_Add( THEPL, psz_uri, NULL,
1233                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1234                           PLAYLIST_END, true, pl_Unlocked );
1235             free( psz_uri );
1236             first = false;
1237             RecentsMRL::getInstance( p_intf )->addRecent( s );
1238         }
1239     }
1240     event->accept();
1241 }
1242 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1243 {
1244      event->acceptProposedAction();
1245 }
1246 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1247 {
1248      event->acceptProposedAction();
1249 }
1250 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1251 {
1252      event->accept();
1253 }
1254
1255 /************************************************************************
1256  * Events stuff
1257  ************************************************************************/
1258 void MainInterface::customEvent( QEvent *event )
1259 {
1260 #if 0
1261     if( event->type() == PLDockEvent_Type )
1262     {
1263         PlaylistDialog::killInstance();
1264         playlistEmbeddedFlag = true;
1265         menuBar()->clear();
1266         QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1267         togglePlaylist();
1268     }
1269 #endif
1270     /*else */
1271     if ( event->type() == (int)SetVideoOnTopEvent_Type )
1272     {
1273         SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1274         if( p_event->OnTop() )
1275             setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1276         else
1277             setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1278         show(); /* necessary to apply window flags */
1279     }
1280 }
1281
1282 void MainInterface::keyPressEvent( QKeyEvent *e )
1283 {
1284     handleKeyPress( e );
1285 }
1286
1287 void MainInterface::handleKeyPress( QKeyEvent *e )
1288 {
1289     if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1290           && !menuBar()->isVisible() )
1291     {
1292         toggleMinimalView( false );
1293         e->accept();
1294     }
1295
1296     int i_vlck = qtEventToVLCKey( e );
1297     if( i_vlck > 0 )
1298     {
1299         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1300         e->accept();
1301     }
1302     else
1303         e->ignore();
1304 }
1305
1306 void MainInterface::resizeEvent( QResizeEvent * event )
1307 {
1308 #if 0
1309     if( b_keep_size )
1310     {
1311         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1312             i_visualmode == QT_MINIMAL_MODE )
1313         {
1314                 mainVideoSize = size();
1315         }
1316         else
1317         {
1318             if( VISIBLE( bgWidget) ||
1319                 ( videoIsActive && videoWidget->isVisible() )
1320               )
1321                 mainVideoSize = size();
1322             else
1323                 mainBasedSize = size();
1324         }
1325     }
1326 #endif
1327     QVLCMW::resizeEvent( event );
1328     msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1329 }
1330
1331 void MainInterface::wheelEvent( QWheelEvent *e )
1332 {
1333     int i_vlckey = qtWheelEventToVLCKey( e );
1334     var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1335     e->accept();
1336 }
1337
1338 void MainInterface::closeEvent( QCloseEvent *e )
1339 {
1340     e->accept();
1341     hide();
1342     THEDP->quit();
1343 }
1344
1345 void MainInterface::toggleFullScreen( void )
1346 {
1347     if( isFullScreen() )
1348     {
1349         showNormal();
1350         emit askUpdate(); // Needed if video was launched after the F11
1351         emit fullscreenInterfaceToggled( false );
1352     }
1353     else
1354     {
1355         showFullScreen();
1356         emit fullscreenInterfaceToggled( true );
1357     }
1358
1359 }
1360
1361 //moc doesn't know about #ifdef, so we have to build this method for every platform
1362 void MainInterface::changeThumbbarButtons( int i_status)
1363 {
1364 #ifdef WIN32
1365     // Define an array of two buttons. These buttons provide images through an
1366     // image list and also provide tooltips.
1367     DWORD dwMask = THB_BITMAP | THB_FLAGS;
1368
1369     THUMBBUTTON thbButtons[3];
1370     //prev
1371     thbButtons[0].dwMask = dwMask;
1372     thbButtons[0].iId = 0;
1373     thbButtons[0].iBitmap = 0;
1374
1375     //play/pause
1376     thbButtons[1].dwMask = dwMask;
1377     thbButtons[1].iId = 1;
1378
1379     //next
1380     thbButtons[2].dwMask = dwMask;
1381     thbButtons[2].iId = 2;
1382     thbButtons[2].iBitmap = 3;
1383
1384     switch( i_status )
1385     {
1386         case  0:
1387         case  END_S:
1388             {
1389                 thbButtons[0].dwFlags = THBF_HIDDEN;
1390                 thbButtons[1].dwFlags = THBF_HIDDEN;
1391                 thbButtons[2].dwFlags = THBF_HIDDEN;
1392                 break;
1393             }
1394         case PLAYING_S:
1395             {
1396                 thbButtons[0].dwFlags = THBF_ENABLED;
1397                 thbButtons[1].dwFlags = THBF_ENABLED;
1398                 thbButtons[2].dwFlags = THBF_ENABLED;
1399                 thbButtons[1].iBitmap = 1;
1400                 break;
1401             }
1402         case PAUSE_S:
1403             {
1404                 //thbButtons[0].dwFlags = THBF_ENABLED;
1405                 //thbButtons[1].dwFlags = THBF_ENABLED;
1406                 //thbButtons[2].dwFlags = THBF_ENABLED;
1407                 thbButtons[1].iBitmap = 2;
1408                 break;
1409             }
1410     }
1411
1412     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1413     if(S_OK != hr)
1414         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1415 #else
1416     ;
1417 #endif
1418 }
1419
1420 /*****************************************************************************
1421  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1422  *  We don't show the menu directly here because we don't want the
1423  *  caller to block for a too long time.
1424  *****************************************************************************/
1425 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1426                         vlc_value_t old_val, vlc_value_t new_val, void *param )
1427 {
1428     intf_thread_t *p_intf = (intf_thread_t *)param;
1429
1430     if( p_intf->pf_show_dialog )
1431     {
1432         p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1433                                 new_val.b_bool, NULL );
1434     }
1435
1436     return VLC_SUCCESS;
1437 }
1438
1439 /*****************************************************************************
1440  * IntfShowCB: callback triggered by the intf-show libvlc variable.
1441  *****************************************************************************/
1442 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1443                        vlc_value_t old_val, vlc_value_t new_val, void *param )
1444 {
1445     intf_thread_t *p_intf = (intf_thread_t *)param;
1446     p_intf->p_sys->p_mi->toggleFSC();
1447
1448     /* Show event */
1449      return VLC_SUCCESS;
1450 }