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