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