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