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