]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
qt4: two more places where uri-encoded mrl are required
[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     else
366     {
367         himl = NULL;
368         p_taskbl = NULL;
369     }
370 #endif
371
372 }
373
374 MainInterface::~MainInterface()
375 {
376     msg_Dbg( p_intf, "Destroying the main interface" );
377
378     /* Unsure we hide the videoWidget before destroying it */
379     if( videoIsActive ) videoWidget->hide();
380
381     /* Save playlist state */
382     if( playlistWidget )
383     {
384         if( !isDocked() )
385             QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
386
387         delete playlistWidget;
388     }
389
390 #ifdef WIN32
391     if( himl )
392         ImageList_Destroy( himl );
393     if(p_taskbl)
394         p_taskbl->vt->Release(p_taskbl);
395     CoUninitialize();
396 #endif
397
398     /* Be sure to kill the actionsManager... FIXME */
399     ActionsManager::killInstance();
400
401     /* Delete the FSC controller */
402     delete fullscreenControls;
403
404     /* Save states */
405     settings->beginGroup( "MainWindow" );
406     settings->setValue( "pl-dock-status", (int)i_pl_dock );
407     settings->setValue( "playlist-visible", (int)playlistVisible );
408     settings->setValue( "adv-controls",
409                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
410
411     settings->setValue( "mainBasedSize", mainBasedSize );
412     settings->setValue( "mainVideoSize", mainVideoSize );
413
414     if( bgWidget )
415         settings->setValue( "backgroundSize", bgWidget->size() );
416
417     /* Save this size */
418     QVLCTools::saveWidgetPosition(settings, this);
419     settings->endGroup();
420
421
422     /* Unregister callbacks */
423     var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
424     var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
425
426     p_intf->p_sys->p_mi = NULL;
427 }
428
429 /*****************************
430  *   Main UI handling        *
431  *****************************/
432 void MainInterface::recreateToolbars()
433 {
434     msg_Dbg( p_intf, "Recreating the toolbars" );
435     settings->beginGroup( "MainWindow" );
436     delete controls;
437     delete inputC;
438     controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
439     CONNECT( controls, advancedControlsToggled( bool ),
440              this, doComponentsUpdate() );
441     CONNECT( controls, sizeChanged(),
442              this, doComponentsUpdate() );
443     inputC = new InputControlsWidget( p_intf, this );
444
445     mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
446     mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
447                               0, 1, -1, Qt::AlignBottom );
448     settings->endGroup();
449 }
450
451 void MainInterface::createMainWidget( QSettings *settings )
452 {
453     /* Create the main Widget and the mainLayout */
454     QWidget *main = new QWidget;
455     setCentralWidget( main );
456     mainLayout = new QGridLayout( main );
457
458     /* Margins, spacing */
459     main->setContentsMargins( 0, 0, 0, 0 );
460     main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
461     mainLayout->setSpacing( 0 );
462     mainLayout->setMargin( 0 );
463
464     /* Visualisation */
465     /* Disabled for now, they SUCK */
466     #if 0
467     visualSelector = new VisualSelector( p_intf );
468     mainLayout->insertWidget( 0, visualSelector );
469     visualSelector->hide();
470     #endif
471
472     /* Bg Cone */
473     bgWidget = new BackgroundWidget( p_intf );
474     bgWidget->resize(
475             settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
476     bgWidget->updateGeometry();
477
478     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
479         i_visualmode != QT_MINIMAL_MODE )
480     {
481         bgWidget->hide();
482     }
483
484     /* And video Outputs */
485     if( videoEmbeddedFlag )
486         videoWidget = new VideoWidget( p_intf );
487
488     /* Create the CONTROLS Widget */
489     controls = new ControlsWidget( p_intf,
490                    settings->value( "adv-controls", false ).toBool(), this );
491     CONNECT( controls, advancedControlsToggled( bool ),
492              this, doComponentsUpdate() );
493     CONNECT( controls, sizeChanged(),
494              this, doComponentsUpdate() );
495     inputC = new InputControlsWidget( p_intf, this );
496
497
498     /* Add the controls Widget to the main Widget */
499     if( videoWidget ){
500         mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
501         mainLayout->setRowStretch( 0, 10 );
502     }
503     mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
504     //mainLayout->setRowStretch( 1, 10 );
505     mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
506     mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
507                            0, 1, -1, Qt::AlignBottom );
508
509     /* Finish the sizing */
510     main->updateGeometry();
511
512     getSettings()->endGroup();
513 #ifdef WIN32
514     if ( depth() > 8 )
515 #endif
516     /* Create the FULLSCREEN CONTROLS Widget */
517     if( config_GetInt( p_intf, "qt-fs-controller" ) )
518     {
519         fullscreenControls = new FullscreenControllerWidget( p_intf, this );
520         CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
521                  this, handleKeyPress( QKeyEvent * ) );
522     }
523 }
524
525 inline void MainInterface::createStatusBar()
526 {
527     /****************
528      *  Status Bar  *
529      ****************/
530     /* Widgets Creation*/
531     QStatusBar *statusBarr = statusBar();
532
533     TimeLabel *timeLabel = new TimeLabel( p_intf );
534     nameLabel = new QLabel( this );
535     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
536                                       | Qt::TextSelectableByKeyboard );
537     SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
538
539     /* Styling those labels */
540     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
541     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
542     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
543
544     /* and adding those */
545     statusBarr->addWidget( nameLabel, 8 );
546     statusBarr->addPermanentWidget( speedLabel, 0 );
547     statusBarr->addPermanentWidget( timeLabel, 0 );
548
549     /* timeLabel behaviour:
550        - double clicking opens the goto time dialog
551        - right-clicking and clicking just toggle between remaining and
552          elapsed time.*/
553     CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
554
555     CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
556              this, showCryptedLabel( bool ) );
557 }
558
559 inline void MainInterface::initSystray()
560 {
561     bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
562     bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
563
564     if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
565     {
566         if( b_systrayAvailable )
567         {
568             b_systrayWanted = true;
569             b_shouldHide = true;
570         }
571         else
572             msg_Err( p_intf, "cannot start minimized without system tray bar" );
573     }
574
575     if( b_systrayAvailable && b_systrayWanted )
576             createSystray();
577 }
578
579 inline void MainInterface::askForPrivacy()
580 {
581     /**
582      * Ask for the network policy on FIRST STARTUP
583      **/
584     if( config_GetInt( p_intf, "qt-privacy-ask") )
585     {
586         QList<ConfigControl *> controls;
587         if( privacyDialog( &controls ) == QDialog::Accepted )
588         {
589             QList<ConfigControl *>::Iterator i;
590             for(  i = controls.begin() ; i != controls.end() ; i++ )
591             {
592                 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
593                 c->doApply( p_intf );
594             }
595
596             config_PutInt( p_intf,  "qt-privacy-ask" , 0 );
597             /* We have to save here because the user may not launch Prefs */
598             config_SaveConfigFile( p_intf, NULL );
599         }
600     }
601 }
602
603 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
604 {
605     QDialog *privacy = new QDialog( this );
606
607     privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
608
609     QGridLayout *gLayout = new QGridLayout( privacy );
610
611     QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
612     QGridLayout *blablaLayout = new QGridLayout( blabla );
613     QLabel *text = new QLabel( qtr(
614         "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
615         "online without authorization.</p>\n "
616         "<p><i>VLC media player</i> can retreive limited information from "
617         "the Internet in order to get CD covers or to check "
618         "for available updates.</p>\n"
619         "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
620         "information, even anonymously, about your usage.</p>\n"
621         "<p>Therefore please select from the following options, the default being "
622         "almost no access to the web.</p>\n") );
623     text->setWordWrap( true );
624     text->setTextFormat( Qt::RichText );
625
626     blablaLayout->addWidget( text, 0, 0 ) ;
627
628     QGroupBox *options = new QGroupBox;
629     QGridLayout *optionsLayout = new QGridLayout( options );
630
631     gLayout->addWidget( blabla, 0, 0, 1, 3 );
632     gLayout->addWidget( options, 1, 0, 1, 3 );
633     module_config_t *p_config;
634     ConfigControl *control;
635     int line = 0;
636
637 #define CONFIG_GENERIC( option, type )                            \
638     p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
639     if( p_config )                                                \
640     {                                                             \
641         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
642                 p_config, options, false, optionsLayout, line );  \
643         controls->append( control );                               \
644     }
645
646 #define CONFIG_GENERIC_NOBOOL( option, type )                     \
647     p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
648     if( p_config )                                                \
649     {                                                             \
650         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
651                 p_config, options, optionsLayout, line );  \
652         controls->append( control );                               \
653     }
654
655     CONFIG_GENERIC( "album-art", IntegerList ); line++;
656 #ifdef UPDATE_CHECK
657     CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
658 #endif
659
660     QPushButton *ok = new QPushButton( qtr( "OK" ) );
661
662     gLayout->addWidget( ok, 2, 2 );
663
664     CONNECT( ok, clicked(), privacy, accept() );
665     return privacy->exec();
666 }
667
668
669 /**********************************************************************
670  * Handling of sizing of the components
671  **********************************************************************/
672
673 /* This function is probably wrong, but we don't have many many choices...
674    Since we can't know from the playlist Widget if we are inside a dock or not,
675    because the playlist Widget can be called by THEDP, as a separate windows for
676    the skins.
677    Maybe the other solution is to redefine the sizeHint() of the playlist and
678    ask _parent->isFloating()...
679    If you think this would be better, please FIXME it...
680 */
681
682 QSize MainInterface::sizeHint() const
683 {
684     if( b_keep_size )
685     {
686         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
687             i_visualmode == QT_MINIMAL_MODE )
688         {
689                 return mainVideoSize;
690         }
691         else
692         {
693             if( VISIBLE( bgWidget) ||
694                 ( videoIsActive && videoWidget->isVisible() )
695               )
696                 return mainVideoSize;
697             else
698                 return mainBasedSize;
699         }
700     }
701
702     int nwidth  = controls->sizeHint().width();
703     int nheight = controls->isVisible() ?
704                   controls->size().height()
705                   + inputC->size().height()
706                   + menuBar()->size().height()
707                   + statusBar()->size().height()
708                   : 0 ;
709
710     if( VISIBLE( bgWidget ) )
711     {
712         if( i_bg_height )
713             nheight += i_bg_height;
714         else
715             nheight += bgWidget->size().height();
716         nwidth  = __MAX( nwidth, bgWidget->size().width() );
717     }
718     else if( videoIsActive && videoWidget->isVisible() )
719     {
720         nheight += videoWidget->sizeHint().height();
721         nwidth  = __MAX( nwidth, videoWidget->sizeHint().width() );
722     }
723 #if 0
724     if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget()  )
725     {
726         nheight += dockPL->size().height();
727         nwidth = __MAX( nwidth, dockPL->size().width() );
728         msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
729     }
730 #endif
731     return QSize( nwidth, nheight );
732 }
733
734 /* Video widget cannot do this synchronously as it runs in another thread */
735 /* Well, could it, actually ? Probably dangerous ... */
736
737 /* This function is called:
738    - toggling of minimal View
739    - through askUpdate() by Vout thread request video and resize video (zoom)
740    - Advanced buttons toggled
741  */
742 void MainInterface::doComponentsUpdate()
743 {
744     if( isFullScreen() || isMaximized() ) return;
745
746     msg_Dbg( p_intf, "Updating the geometry" );
747     /* Here we resize to sizeHint() and not adjustsize because we want
748        the videoWidget to be exactly the correctSize */
749     resize( sizeHint() );
750     //    adjustSize()  ;
751 #ifndef NDEBUG
752     debug();
753 #endif
754 }
755
756 void MainInterface::debug()
757 {
758 #ifndef NDEBUG
759     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
760     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
761     if( videoWidget && videoWidget->isVisible() )
762     {
763         msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
764         msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
765     }
766 #endif
767 }
768
769 void MainInterface::destroyPopupMenu()
770 {
771     QVLCMenu::PopupMenu(p_intf, false );
772 }
773
774
775 void MainInterface::toggleFSC()
776 {
777    if( !fullscreenControls ) return;
778
779    IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
780    QApplication::postEvent( fullscreenControls, eShow );
781 }
782
783 void MainInterface::popupMenu( const QPoint &p )
784 {
785     /* Ow, that's ugly: don't show the popup menu if cursor over
786      * the main menu bar or the status bar */
787     if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
788                         && ( childAt( p )->parentWidget() != statusBar() ) ) )
789         QVLCMenu::PopupMenu( p_intf, true );
790 }
791
792 /****************************************************************************
793  * Video Handling
794  ****************************************************************************/
795
796 /* This event is used to deal with the fullscreen and always on top
797    issue conflict (bug in wx) */
798 class SetVideoOnTopQtEvent : public QEvent
799 {
800 public:
801     SetVideoOnTopQtEvent( bool _onTop ) :
802       QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
803     {}
804
805     bool OnTop() const { return onTop; }
806
807 private:
808     bool onTop;
809 };
810
811 /**
812  * NOTE:
813  * You must note change the state of this object or other Qt4 UI objects,
814  * from the video output thread - only from the Qt4 UI main loop thread.
815  * All window provider queries must be handled through signals or events.
816  * That's why we have all those emit statements...
817  */
818 WId MainInterface::getVideo( int *pi_x, int *pi_y,
819                              unsigned int *pi_width, unsigned int *pi_height )
820 {
821     if( !videoWidget )
822         return 0;
823
824     /* This is a blocking call signal. Results are returned through pointers.
825      * Beware of deadlocks! */
826     WId id;
827     emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
828     return id;
829 }
830
831 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
832                                   unsigned *pi_width, unsigned *pi_height )
833 {
834     /* Request the videoWidget */
835     WId ret = videoWidget->request( pi_x, pi_y,
836                                     pi_width, pi_height, b_keep_size );
837     *p_id = ret;
838     if( ret ) /* The videoWidget is available */
839     {
840         /* Did we have a bg ? Hide it! */
841         if( VISIBLE( bgWidget) )
842         {
843             bgWasVisible = true;
844             bgWidget->toggle();
845         }
846         else
847             bgWasVisible = false;
848
849         /* ask videoWidget to show */
850         videoWidget->SetSizing( *pi_width, *pi_height );
851
852         /* Consider the video active now */
853         videoIsActive = true;
854
855         emit askUpdate();
856     }
857 }
858
859 /* Asynchronous call from the WindowClose function */
860 void MainInterface::releaseVideo( void )
861 {
862     emit askReleaseVideo( );
863 }
864
865 /* Function that is CONNECTED to the previous emit */
866 void MainInterface::releaseVideoSlot( void )
867 {
868     videoWidget->release( );
869
870     if( bgWasVisible )
871     {
872         /* Reset the bg state */
873         bgWasVisible = false;
874         bgWidget->show();
875     }
876
877     videoIsActive = false;
878
879     /* Try to resize, except when you are in Fullscreen mode */
880     doComponentsUpdate();
881 }
882
883 /* Asynchronous call from WindowControl function */
884 int MainInterface::controlVideo( int i_query, va_list args )
885 {
886     switch( i_query )
887     {
888     case VOUT_WINDOW_SET_SIZE:
889     {
890         unsigned int i_width  = va_arg( args, unsigned int );
891         unsigned int i_height = va_arg( args, unsigned int );
892         emit askVideoToResize( i_width, i_height );
893         emit askUpdate();
894         return VLC_SUCCESS;
895     }
896     case VOUT_WINDOW_SET_ON_TOP:
897     {
898         int i_arg = va_arg( args, int );
899         QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
900         return VLC_SUCCESS;
901     }
902     case VOUT_WINDOW_SET_FULLSCREEN:
903     {
904         bool b_fs = va_arg( args, int );
905         emit askVideoSetFullScreen( b_fs );
906         return VLC_SUCCESS;
907     }
908     default:
909         msg_Warn( p_intf, "unsupported control query" );
910         return VLC_EGENERIC;
911     }
912 }
913
914 /*****************************************************************************
915  * Playlist, Visualisation and Menus handling
916  *****************************************************************************/
917 /**
918  * Toggle the playlist widget or dialog
919  **/
920 void MainInterface::togglePlaylist()
921 {
922     /* CREATION
923     If no playlist exist, then create one and attach it to the DockPL*/
924     if( !playlistWidget )
925     {
926         playlistWidget = new PlaylistWidget( p_intf );
927
928         i_pl_dock = PL_UNDOCKED;
929 /*        i_pl_dock = (pl_dock_e)getSettings()
930                          ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
931
932         if( i_pl_dock == PL_UNDOCKED )
933         {
934             playlistWidget->setWindowFlags( Qt::Window );
935
936             /* This will restore the geometry but will not work for position,
937                because of parenting */
938             QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
939                     playlistWidget, QSize( 600, 300 ) );
940         }
941         else
942         {
943          //   mainLayout->insertWidget( 4, playlistWidget );
944         }
945         playlistVisible = true;
946
947         playlistWidget->show();
948     }
949     else
950     {
951     /* toggle the visibility of the playlist */
952        TOGGLEV( playlistWidget );
953        playlistVisible = !playlistVisible;
954        //doComponentsUpdate(); //resize( sizeHint() );
955     }
956 }
957
958 /* Function called from the menu to undock the playlist */
959 void MainInterface::undockPlaylist()
960 {
961 //    dockPL->setFloating( true );
962 //    adjustSize();
963 }
964
965 void MainInterface::dockPlaylist( pl_dock_e i_pos )
966 {
967 }
968
969 void MainInterface::toggleMinimalView( bool b_switch )
970 {
971     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
972         i_visualmode != QT_MINIMAL_MODE )
973     { /* NORMAL MODE then */
974         if( !videoWidget || videoWidget->isHidden() )
975         {
976             bgWidget->toggle();
977         }
978         else
979         {
980             /* If video is visible, then toggle the status of bgWidget */
981             bgWasVisible = !bgWasVisible;
982         }
983     }
984
985     i_bg_height = bgWidget->height();
986
987     menuBar()->setVisible( !b_switch );
988     controls->setVisible( !b_switch );
989     statusBar()->setVisible( !b_switch );
990     inputC->setVisible( !b_switch );
991
992     doComponentsUpdate();
993
994     emit minimalViewToggled( b_switch );
995 }
996
997 /* toggling advanced controls buttons */
998 void MainInterface::toggleAdvanced()
999 {
1000     controls->toggleAdvanced();
1001 //    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1002 }
1003
1004 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1005 int MainInterface::getControlsVisibilityStatus()
1006 {
1007     return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1008                 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1009 }
1010
1011 #if 0
1012 void MainInterface::visual()
1013 {
1014     if( !VISIBLE( visualSelector) )
1015     {
1016         visualSelector->show();
1017         if( !THEMIM->getIM()->hasVideo() )
1018         {
1019             /* Show the background widget */
1020         }
1021         visualSelectorEnabled = true;
1022     }
1023     else
1024     {
1025         /* Stop any currently running visualization */
1026         visualSelector->hide();
1027         visualSelectorEnabled = false;
1028     }
1029     doComponentsUpdate();
1030 }
1031 #endif
1032
1033 /************************************************************************
1034  * Other stuff
1035  ************************************************************************/
1036 void MainInterface::setName( const QString& name )
1037 {
1038     input_name = name; /* store it for the QSystray use */
1039     /* Display it in the status bar, but also as a Tooltip in case it doesn't
1040        fit in the label */
1041     nameLabel->setText( " " + name + " " );
1042     nameLabel->setToolTip( " " + name +" " );
1043 }
1044
1045 /**
1046  * Give the decorations of the Main Window a correct Name.
1047  * If nothing is given, set it to VLC...
1048  **/
1049 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1050 {
1051     if( aTitle.isEmpty() )
1052     {
1053         setWindowTitle( qtr( "VLC media player" ) );
1054     }
1055     else
1056     {
1057         setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1058     }
1059 }
1060
1061 void MainInterface::showCryptedLabel( bool b_show )
1062 {
1063     if( cryptedLabel == NULL )
1064     {
1065         cryptedLabel = new QLabel;
1066         // The lock icon is not the right one for DRM protection/scrambled.
1067         //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1068         cryptedLabel->setText( "DRM" );
1069         statusBar()->addWidget( cryptedLabel );
1070     }
1071
1072     cryptedLabel->setVisible( b_show );
1073 }
1074
1075 /*****************************************************************************
1076  * Systray Icon and Systray Menu
1077  *****************************************************************************/
1078
1079 /**
1080  * Create a SystemTray icon and a menu that would go with it.
1081  * Connects to a click handler on the icon.
1082  **/
1083 void MainInterface::createSystray()
1084 {
1085     QIcon iconVLC;
1086     if( QDate::currentDate().dayOfYear() >= 354 )
1087         iconVLC =  QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
1088     else
1089         iconVLC =  QIcon( QPixmap( ":/logo/vlc128.png" ) );
1090     sysTray = new QSystemTrayIcon( iconVLC, this );
1091     sysTray->setToolTip( qtr( "VLC media player" ));
1092
1093     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1094     systrayMenu->setIcon( iconVLC );
1095
1096     QVLCMenu::updateSystrayMenu( this, p_intf, true );
1097     sysTray->show();
1098
1099     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1100             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1101 }
1102
1103 /**
1104  * Updates the Systray Icon's menu and toggle the main interface
1105  */
1106 void MainInterface::toggleUpdateSystrayMenu()
1107 {
1108     /* If hidden, show it */
1109     if( isHidden() )
1110     {
1111         show();
1112         activateWindow();
1113     }
1114     else if( isMinimized() )
1115     {
1116         /* Minimized */
1117         showNormal();
1118         activateWindow();
1119     }
1120     else
1121     {
1122         /* Visible (possibly under other windows) */
1123 #ifdef WIN32
1124         /* check if any visible window is above vlc in the z-order,
1125          * but ignore the ones always on top
1126          * and the ones which can't be activated */
1127         WINDOWINFO wi;
1128         HWND hwnd;
1129         wi.cbSize = sizeof( WINDOWINFO );
1130         for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1131                 hwnd && ( !IsWindowVisible( hwnd ) ||
1132                     ( GetWindowInfo( hwnd, &wi ) &&
1133                       (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1134                 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1135             if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1136                 (wi.dwExStyle&WS_EX_TOPMOST) )
1137             {
1138                 hide();
1139             }
1140             else
1141             {
1142                 activateWindow();
1143             }
1144 #else
1145         hide();
1146 #endif
1147     }
1148     QVLCMenu::updateSystrayMenu( this, p_intf );
1149 }
1150
1151 void MainInterface::handleSystrayClick(
1152                                     QSystemTrayIcon::ActivationReason reason )
1153 {
1154     switch( reason )
1155     {
1156         case QSystemTrayIcon::Trigger:
1157         case QSystemTrayIcon::DoubleClick:
1158             toggleUpdateSystrayMenu();
1159             break;
1160         case QSystemTrayIcon::MiddleClick:
1161             sysTray->showMessage( qtr( "VLC media player" ),
1162                     qtr( "Control menu for the player" ),
1163                     QSystemTrayIcon::Information, 3000 );
1164             break;
1165         default:
1166             break;
1167     }
1168 }
1169
1170 /**
1171  * Updates the name of the systray Icon tooltip.
1172  * Doesn't check if the systray exists, check before you call it.
1173  **/
1174 void MainInterface::updateSystrayTooltipName( const QString& name )
1175 {
1176     if( name.isEmpty() )
1177     {
1178         sysTray->setToolTip( qtr( "VLC media player" ) );
1179     }
1180     else
1181     {
1182         sysTray->setToolTip( name );
1183         if( notificationEnabled && ( isHidden() || isMinimized() ) )
1184         {
1185             sysTray->showMessage( qtr( "VLC media player" ), name,
1186                     QSystemTrayIcon::NoIcon, 3000 );
1187         }
1188     }
1189
1190     QVLCMenu::updateSystrayMenu( this, p_intf );
1191 }
1192
1193 /**
1194  * Updates the status of the systray Icon tooltip.
1195  * Doesn't check if the systray exists, check before you call it.
1196  **/
1197 void MainInterface::updateSystrayTooltipStatus( int i_status )
1198 {
1199     switch( i_status )
1200     {
1201         case  0:
1202         case  END_S:
1203             {
1204                 sysTray->setToolTip( qtr( "VLC media player" ) );
1205                 break;
1206             }
1207         case PLAYING_S:
1208             {
1209                 sysTray->setToolTip( input_name );
1210                 break;
1211             }
1212         case PAUSE_S:
1213             {
1214                 sysTray->setToolTip( input_name + " - "
1215                         + qtr( "Paused") );
1216                 break;
1217             }
1218     }
1219     QVLCMenu::updateSystrayMenu( this, p_intf );
1220 }
1221
1222 /************************************************************************
1223  * D&D Events
1224  ************************************************************************/
1225 void MainInterface::dropEvent(QDropEvent *event)
1226 {
1227     dropEventPlay( event, true );
1228 }
1229
1230 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1231 {
1232      event->setDropAction( Qt::CopyAction );
1233      if( !event->possibleActions() & Qt::CopyAction )
1234          return;
1235
1236      const QMimeData *mimeData = event->mimeData();
1237
1238      /* D&D of a subtitles file, add it on the fly */
1239      if( mimeData->urls().size() == 1 )
1240      {
1241         if( THEMIM->getIM()->hasInput() )
1242         {
1243             if( !input_AddSubtitle( THEMIM->getInput(),
1244                                     qtu( toNativeSeparators(
1245                                          mimeData->urls()[0].toLocalFile() ) ),
1246                                     true ) )
1247             {
1248                 event->accept();
1249                 return;
1250             }
1251         }
1252      }
1253      bool first = b_play;
1254      foreach( const QUrl &url, mimeData->urls() )
1255      {
1256         QString s = toNativeSeparators( url.toLocalFile() );
1257
1258         if( s.length() > 0 ) {
1259             char* psz_uri = make_URI( qtu(s) );
1260             playlist_Add( THEPL, psz_uri, NULL,
1261                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1262                           PLAYLIST_END, true, pl_Unlocked );
1263             free( psz_uri );
1264             first = false;
1265             RecentsMRL::getInstance( p_intf )->addRecent( s );
1266         }
1267      }
1268      event->accept();
1269 }
1270 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1271 {
1272      event->acceptProposedAction();
1273 }
1274 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1275 {
1276      event->acceptProposedAction();
1277 }
1278 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1279 {
1280      event->accept();
1281 }
1282
1283 /************************************************************************
1284  * Events stuff
1285  ************************************************************************/
1286 void MainInterface::customEvent( QEvent *event )
1287 {
1288 #if 0
1289     if( event->type() == PLDockEvent_Type )
1290     {
1291         PlaylistDialog::killInstance();
1292         playlistEmbeddedFlag = true;
1293         menuBar()->clear();
1294         QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1295         togglePlaylist();
1296     }
1297 #endif
1298     /*else */
1299     if ( event->type() == (int)SetVideoOnTopEvent_Type )
1300     {
1301         SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1302         if( p_event->OnTop() )
1303             setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1304         else
1305             setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1306         show(); /* necessary to apply window flags */
1307     }
1308 }
1309
1310 void MainInterface::keyPressEvent( QKeyEvent *e )
1311 {
1312     handleKeyPress( e );
1313 }
1314
1315 void MainInterface::handleKeyPress( QKeyEvent *e )
1316 {
1317     if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1318           && !menuBar()->isVisible() )
1319     {
1320         toggleMinimalView( false );
1321         e->accept();
1322     }
1323
1324     int i_vlck = qtEventToVLCKey( e );
1325     if( i_vlck > 0 )
1326     {
1327         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1328         e->accept();
1329     }
1330     else
1331         e->ignore();
1332 }
1333
1334 void MainInterface::resizeEvent( QResizeEvent * event )
1335 {
1336     if( b_keep_size )
1337     {
1338         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1339             i_visualmode == QT_MINIMAL_MODE )
1340         {
1341                 mainVideoSize = size();
1342         }
1343         else
1344         {
1345             if( VISIBLE( bgWidget) ||
1346                 ( videoIsActive && videoWidget->isVisible() )
1347               )
1348                 mainVideoSize = size();
1349             else
1350                 mainBasedSize = size();
1351         }
1352     }
1353 }
1354
1355 void MainInterface::wheelEvent( QWheelEvent *e )
1356 {
1357     int i_vlckey = qtWheelEventToVLCKey( e );
1358     var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1359     e->accept();
1360 }
1361
1362 void MainInterface::closeEvent( QCloseEvent *e )
1363 {
1364     e->accept();
1365     hide();
1366     THEDP->quit();
1367 }
1368
1369 void MainInterface::toggleFullScreen( void )
1370 {
1371     if( isFullScreen() )
1372     {
1373         showNormal();
1374         emit askUpdate(); // Needed if video was launched after the F11
1375         emit fullscreenInterfaceToggled( false );
1376     }
1377     else
1378     {
1379         showFullScreen();
1380         emit fullscreenInterfaceToggled( true );
1381     }
1382
1383 }
1384
1385 //moc doesn't know about #ifdef, so we have to build this method for every platform
1386 void MainInterface::changeThumbbarButtons( int i_status)
1387 {
1388 #ifdef WIN32
1389     // Define an array of two buttons. These buttons provide images through an
1390     // image list and also provide tooltips.
1391     DWORD dwMask = THB_BITMAP | THB_FLAGS;
1392
1393     THUMBBUTTON thbButtons[3];
1394     //prev
1395     thbButtons[0].dwMask = dwMask;
1396     thbButtons[0].iId = 0;
1397     thbButtons[0].iBitmap = 0;
1398
1399     //play/pause
1400     thbButtons[1].dwMask = dwMask;
1401     thbButtons[1].iId = 1;
1402
1403     //next
1404     thbButtons[2].dwMask = dwMask;
1405     thbButtons[2].iId = 2;
1406     thbButtons[2].iBitmap = 3;
1407
1408     switch( i_status )
1409     {
1410         case  0:
1411         case  END_S:
1412             {
1413                 thbButtons[0].dwFlags = THBF_HIDDEN;
1414                 thbButtons[1].dwFlags = THBF_HIDDEN;
1415                 thbButtons[2].dwFlags = THBF_HIDDEN;
1416                 break;
1417             }
1418         case PLAYING_S:
1419             {
1420                 thbButtons[0].dwFlags = THBF_ENABLED;
1421                 thbButtons[1].dwFlags = THBF_ENABLED;
1422                 thbButtons[2].dwFlags = THBF_ENABLED;
1423                 thbButtons[1].iBitmap = 1;
1424                 break;
1425             }
1426         case PAUSE_S:
1427             {
1428                 //thbButtons[0].dwFlags = THBF_ENABLED;
1429                 //thbButtons[1].dwFlags = THBF_ENABLED;
1430                 //thbButtons[2].dwFlags = THBF_ENABLED;
1431                 thbButtons[1].iBitmap = 2;
1432                 break;
1433             }
1434     }
1435
1436     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1437     if(S_OK != hr)
1438         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1439 #else
1440     ;
1441 #endif
1442 }
1443
1444 /*****************************************************************************
1445  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1446  *  We don't show the menu directly here because we don't want the
1447  *  caller to block for a too long time.
1448  *****************************************************************************/
1449 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1450                         vlc_value_t old_val, vlc_value_t new_val, void *param )
1451 {
1452     intf_thread_t *p_intf = (intf_thread_t *)param;
1453
1454     if( p_intf->pf_show_dialog )
1455     {
1456         p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1457                                 new_val.b_bool, NULL );
1458     }
1459
1460     return VLC_SUCCESS;
1461 }
1462
1463 /*****************************************************************************
1464  * IntfShowCB: callback triggered by the intf-show libvlc variable.
1465  *****************************************************************************/
1466 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1467                        vlc_value_t old_val, vlc_value_t new_val, void *param )
1468 {
1469     intf_thread_t *p_intf = (intf_thread_t *)param;
1470     p_intf->p_sys->p_mi->toggleFSC();
1471
1472     /* Show event */
1473      return VLC_SUCCESS;
1474 }
1475