]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
Change 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     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_Dbg( 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_Warn( 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 #ifndef NDEBUG
781     debug();
782 #endif
783     /* This is WRONG, but I believe there is a Qt bug here */
784     setMinimumSize( 0, 0 );
785     resize( sizeHint() );
786
787     //adjustSize() ; /* This is not needed, but might help in the future */
788 }
789
790 void MainInterface::debug()
791 {
792 #ifndef NDEBUG
793     msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
794     msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
795
796     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
797     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
798     //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
799
800     msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
801     msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
802     msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
803     msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
804     msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
805     msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
806     msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
807
808     /*if( videoWidget && videoWidget->isVisible() )
809     {
810         msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
811         msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
812     }*/
813 #endif
814 }
815
816 void MainInterface::destroyPopupMenu()
817 {
818     QVLCMenu::PopupMenu( p_intf, false );
819 }
820
821 void MainInterface::toggleFSC()
822 {
823    if( !fullscreenControls ) return;
824
825    IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
826    QApplication::postEvent( fullscreenControls, eShow );
827 }
828
829 void MainInterface::popupMenu( const QPoint &p )
830 {
831     /* Ow, that's ugly: don't show the popup menu if cursor over
832      * the main menu bar or the status bar */
833     if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
834                         && ( childAt( p )->parentWidget() != statusBar() ) ) )
835         QVLCMenu::PopupMenu( p_intf, true );
836 }
837
838 /****************************************************************************
839  * Video Handling
840  ****************************************************************************/
841
842 /* This event is used to deal with the fullscreen and always on top
843    issue conflict (bug in wx) */
844 class SetVideoOnTopQtEvent : public QEvent
845 {
846 public:
847     SetVideoOnTopQtEvent( bool _onTop ) :
848       QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
849     {}
850
851     bool OnTop() const { return onTop; }
852
853 private:
854     bool onTop;
855 };
856
857 /**
858  * NOTE:
859  * You must note change the state of this object or other Qt4 UI objects,
860  * from the video output thread - only from the Qt4 UI main loop thread.
861  * All window provider queries must be handled through signals or events.
862  * That's why we have all those emit statements...
863  */
864 WId MainInterface::getVideo( int *pi_x, int *pi_y,
865                              unsigned int *pi_width, unsigned int *pi_height )
866 {
867     if( !videoWidget )
868         return 0;
869
870     /* This is a blocking call signal. Results are returned through pointers.
871      * Beware of deadlocks! */
872     WId id;
873     emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
874     return id;
875 }
876
877 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
878                                   unsigned *pi_width, unsigned *pi_height )
879 {
880     /* Request the videoWidget */
881     WId ret = videoWidget->request( pi_x, pi_y,
882                                     pi_width, pi_height, b_keep_size );
883     *p_id = ret;
884     if( ret ) /* The videoWidget is available */
885     {
886         /* ask videoWidget to show */
887         videoWidget->SetSizing( *pi_width, *pi_height );
888
889         /* Consider the video active now */
890         showVideo();
891
892         stackCentralW->resize( *pi_width, *pi_height );
893
894         emit askUpdate();
895     }
896 }
897
898 inline void MainInterface::showTab( int i_tab )
899 {
900     stackCentralOldState = stackCentralW->currentIndex();
901
902     stackCentralW->setCurrentIndex( i_tab );
903     if( stackCentralW->isHidden() ) stackCentralW->show();
904 }
905
906 /* Asynchronous call from the WindowClose function */
907 void MainInterface::releaseVideo( void )
908 {
909     emit askReleaseVideo( );
910 }
911
912 /* Function that is CONNECTED to the previous emit */
913 void MainInterface::releaseVideoSlot( void )
914 {
915     videoWidget->release( );
916
917     /* Restore the previous State */
918     if( stackCentralOldState == BACKG_TAB )
919     {
920         showBg();
921     }
922     else
923     {
924         stackCentralW->hide();
925         stackCentralOldState == -1;
926     }
927
928     /* Try to resize, except when you are in Fullscreen mode */
929     doComponentsUpdate();
930 }
931
932 /* Asynchronous call from WindowControl function */
933 int MainInterface::controlVideo( int i_query, va_list args )
934 {
935     /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
936     msg_Warn( p_intf, "Control Video: %i", i_query );
937     switch( i_query )
938     {
939     case VOUT_WINDOW_SET_SIZE:
940     {
941         unsigned int i_width  = va_arg( args, unsigned int );
942         unsigned int i_height = va_arg( args, unsigned int );
943         emit askVideoToResize( i_width, i_height );
944         emit askUpdate();
945         return VLC_SUCCESS;
946     }
947     case VOUT_WINDOW_SET_ON_TOP:
948     {
949         int i_arg = va_arg( args, int );
950         QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
951         return VLC_SUCCESS;
952     }
953     case VOUT_WINDOW_SET_FULLSCREEN:
954     {
955         bool b_fs = va_arg( args, int );
956         emit askVideoSetFullScreen( b_fs );
957         return VLC_SUCCESS;
958     }
959     default:
960         msg_Warn( p_intf, "unsupported control query" );
961         return VLC_EGENERIC;
962     }
963 }
964
965 /*****************************************************************************
966  * Playlist, Visualisation and Menus handling
967  *****************************************************************************/
968 /**
969  * Toggle the playlist widget or dialog
970  **/
971 void MainInterface::togglePlaylist()
972 {
973     /* CREATION
974     If no playlist exist, then create one and attach it to the DockPL*/
975     if( !playlistWidget )
976     {
977         playlistWidget = new PlaylistWidget( p_intf );
978
979         i_pl_dock = PL_BOTTOM;
980         /*i_pl_dock = (pl_dock_e)getSettings()
981                          ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
982
983         if( i_pl_dock == PL_UNDOCKED )
984         {
985             playlistWidget->setWindowFlags( Qt::Window );
986
987             /* This will restore the geometry but will not work for position,
988                because of parenting */
989             QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
990                     playlistWidget, QSize( 600, 300 ) );
991         }
992         else
993         {
994             stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
995             stackCentralW->setCurrentWidget( playlistWidget );
996             stackCentralW->show();
997         }
998         playlistVisible = true;
999
1000         playlistWidget->show();
1001     }
1002     else
1003     {
1004     /* toggle the visibility of the playlist */
1005         if( stackCentralW->currentIndex() != PLAYL_TAB )
1006         {
1007             stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1008             stackCentralW->setCurrentWidget( playlistWidget );
1009             stackCentralW->show();
1010         }
1011         else
1012             stackCentralW->setCurrentIndex( VIDEO_TAB );
1013        playlistVisible = !playlistVisible;
1014        //doComponentsUpdate(); //resize( sizeHint() );
1015     }
1016 }
1017
1018 /* Function called from the menu to undock the playlist */
1019 void MainInterface::undockPlaylist()
1020 {
1021 //    dockPL->setFloating( true );
1022 //    adjustSize();
1023 }
1024
1025 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1026 {
1027 }
1028
1029 void MainInterface::toggleMinimalView( bool b_switch )
1030 {
1031     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1032         i_visualmode != QT_MINIMAL_MODE )
1033     { /* NORMAL MODE then */
1034         stackCentralW->show();
1035         if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1036         {
1037             showBg();
1038         }
1039         else
1040         {
1041             /* If video is visible, then toggle the status of bgWidget */
1042             //bgWasVisible = !bgWasVisible;
1043             if( stackCentralOldState == BACKG_TAB )
1044                 stackCentralOldState = HIDDEN_TAB;
1045             else
1046                 stackCentralOldState = BACKG_TAB;
1047         }
1048     }
1049
1050     i_bg_height = stackCentralW->height();
1051
1052     menuBar()->setVisible( !b_switch );
1053     controls->setVisible( !b_switch );
1054     statusBar()->setVisible( !b_switch );
1055     inputC->setVisible( !b_switch );
1056
1057     doComponentsUpdate();
1058
1059     emit minimalViewToggled( b_switch );
1060 }
1061
1062 /* toggling advanced controls buttons */
1063 void MainInterface::toggleAdvanced()
1064 {
1065     controls->toggleAdvanced();
1066 //    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1067 }
1068
1069 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1070 int MainInterface::getControlsVisibilityStatus()
1071 {
1072     return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1073                 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1074 }
1075
1076 #if 0
1077 void MainInterface::visual()
1078 {
1079     if( !VISIBLE( visualSelector) )
1080     {
1081         visualSelector->show();
1082         if( !THEMIM->getIM()->hasVideo() )
1083         {
1084             /* Show the background widget */
1085         }
1086         visualSelectorEnabled = true;
1087     }
1088     else
1089     {
1090         /* Stop any currently running visualization */
1091         visualSelector->hide();
1092         visualSelectorEnabled = false;
1093     }
1094     doComponentsUpdate();
1095 }
1096 #endif
1097
1098 /************************************************************************
1099  * Other stuff
1100  ************************************************************************/
1101 void MainInterface::setName( const QString& name )
1102 {
1103     input_name = name; /* store it for the QSystray use */
1104     /* Display it in the status bar, but also as a Tooltip in case it doesn't
1105        fit in the label */
1106     nameLabel->setText( " " + name + " " );
1107     nameLabel->setToolTip( " " + name +" " );
1108 }
1109
1110 /**
1111  * Give the decorations of the Main Window a correct Name.
1112  * If nothing is given, set it to VLC...
1113  **/
1114 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1115 {
1116     if( aTitle.isEmpty() )
1117     {
1118         setWindowTitle( qtr( "VLC media player" ) );
1119     }
1120     else
1121     {
1122         setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1123     }
1124 }
1125
1126 void MainInterface::showCryptedLabel( bool b_show )
1127 {
1128     if( cryptedLabel == NULL )
1129     {
1130         cryptedLabel = new QLabel;
1131         // The lock icon is not the right one for DRM protection/scrambled.
1132         //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1133         cryptedLabel->setText( "DRM" );
1134         statusBar()->addWidget( cryptedLabel );
1135     }
1136
1137     cryptedLabel->setVisible( b_show );
1138 }
1139
1140 /*****************************************************************************
1141  * Systray Icon and Systray Menu
1142  *****************************************************************************/
1143 #ifndef HAVE_MAEMO
1144 /**
1145  * Create a SystemTray icon and a menu that would go with it.
1146  * Connects to a click handler on the icon.
1147  **/
1148 void MainInterface::createSystray()
1149 {
1150     QIcon iconVLC;
1151     if( QDate::currentDate().dayOfYear() >= 354 )
1152         iconVLC =  QIcon( ":/logo/vlc128-christmas.png" );
1153     else
1154         iconVLC =  QIcon( ":/logo/vlc128.png" );
1155     sysTray = new QSystemTrayIcon( iconVLC, this );
1156     sysTray->setToolTip( qtr( "VLC media player" ));
1157
1158     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1159     systrayMenu->setIcon( iconVLC );
1160
1161     QVLCMenu::updateSystrayMenu( this, p_intf, true );
1162     sysTray->show();
1163
1164     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1165             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1166 }
1167
1168 /**
1169  * Updates the Systray Icon's menu and toggle the main interface
1170  */
1171 void MainInterface::toggleUpdateSystrayMenu()
1172 {
1173     /* If hidden, show it */
1174     if( isHidden() )
1175     {
1176         show();
1177         activateWindow();
1178     }
1179     else if( isMinimized() )
1180     {
1181         /* Minimized */
1182         showNormal();
1183         activateWindow();
1184     }
1185     else
1186     {
1187         /* Visible (possibly under other windows) */
1188 #ifdef WIN32
1189         /* check if any visible window is above vlc in the z-order,
1190          * but ignore the ones always on top
1191          * and the ones which can't be activated */
1192         WINDOWINFO wi;
1193         HWND hwnd;
1194         wi.cbSize = sizeof( WINDOWINFO );
1195         for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1196                 hwnd && ( !IsWindowVisible( hwnd ) ||
1197                     ( GetWindowInfo( hwnd, &wi ) &&
1198                       (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1199                 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1200             if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1201                 (wi.dwExStyle&WS_EX_TOPMOST) )
1202             {
1203                 hide();
1204             }
1205             else
1206             {
1207                 activateWindow();
1208             }
1209 #else
1210         hide();
1211 #endif
1212     }
1213     QVLCMenu::updateSystrayMenu( this, p_intf );
1214 }
1215
1216 void MainInterface::handleSystrayClick(
1217                                     QSystemTrayIcon::ActivationReason reason )
1218 {
1219     switch( reason )
1220     {
1221         case QSystemTrayIcon::Trigger:
1222         case QSystemTrayIcon::DoubleClick:
1223             toggleUpdateSystrayMenu();
1224             break;
1225         case QSystemTrayIcon::MiddleClick:
1226             sysTray->showMessage( qtr( "VLC media player" ),
1227                     qtr( "Control menu for the player" ),
1228                     QSystemTrayIcon::Information, 3000 );
1229             break;
1230         default:
1231             break;
1232     }
1233 }
1234
1235 /**
1236  * Updates the name of the systray Icon tooltip.
1237  * Doesn't check if the systray exists, check before you call it.
1238  **/
1239 void MainInterface::updateSystrayTooltipName( const QString& name )
1240 {
1241     if( name.isEmpty() )
1242     {
1243         sysTray->setToolTip( qtr( "VLC media player" ) );
1244     }
1245     else
1246     {
1247         sysTray->setToolTip( name );
1248         if( notificationEnabled && ( isHidden() || isMinimized() ) )
1249         {
1250             sysTray->showMessage( qtr( "VLC media player" ), name,
1251                     QSystemTrayIcon::NoIcon, 3000 );
1252         }
1253     }
1254
1255     QVLCMenu::updateSystrayMenu( this, p_intf );
1256 }
1257
1258 /**
1259  * Updates the status of the systray Icon tooltip.
1260  * Doesn't check if the systray exists, check before you call it.
1261  **/
1262 void MainInterface::updateSystrayTooltipStatus( int i_status )
1263 {
1264     switch( i_status )
1265     {
1266         case  0:
1267         case  END_S:
1268             {
1269                 sysTray->setToolTip( qtr( "VLC media player" ) );
1270                 break;
1271             }
1272         case PLAYING_S:
1273             {
1274                 sysTray->setToolTip( input_name );
1275                 break;
1276             }
1277         case PAUSE_S:
1278             {
1279                 sysTray->setToolTip( input_name + " - "
1280                         + qtr( "Paused") );
1281                 break;
1282             }
1283     }
1284     QVLCMenu::updateSystrayMenu( this, p_intf );
1285 }
1286 #endif
1287
1288 /************************************************************************
1289  * D&D Events
1290  ************************************************************************/
1291 void MainInterface::dropEvent(QDropEvent *event)
1292 {
1293     dropEventPlay( event, true );
1294 }
1295
1296 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1297 {
1298     event->setDropAction( Qt::CopyAction );
1299     if( !event->possibleActions() & Qt::CopyAction )
1300         return;
1301
1302     const QMimeData *mimeData = event->mimeData();
1303
1304     /* D&D of a subtitles file, add it on the fly */
1305     if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1306     {
1307         if( !input_AddSubtitle( THEMIM->getInput(),
1308                  qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1309                  true ) )
1310         {
1311             event->accept();
1312             return;
1313         }
1314     }
1315
1316     bool first = b_play;
1317     foreach( const QUrl &url, mimeData->urls() )
1318     {
1319         QString s = toNativeSeparators( url.toLocalFile() );
1320
1321         if( s.length() > 0 ) {
1322             char* psz_uri = make_URI( qtu(s) );
1323             playlist_Add( THEPL, psz_uri, NULL,
1324                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1325                           PLAYLIST_END, true, pl_Unlocked );
1326             free( psz_uri );
1327             first = false;
1328             RecentsMRL::getInstance( p_intf )->addRecent( s );
1329         }
1330     }
1331     event->accept();
1332 }
1333 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1334 {
1335      event->acceptProposedAction();
1336 }
1337 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1338 {
1339      event->acceptProposedAction();
1340 }
1341 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1342 {
1343      event->accept();
1344 }
1345
1346 /************************************************************************
1347  * Events stuff
1348  ************************************************************************/
1349 void MainInterface::customEvent( QEvent *event )
1350 {
1351 #if 0
1352     if( event->type() == PLDockEvent_Type )
1353     {
1354         PlaylistDialog::killInstance();
1355         playlistEmbeddedFlag = true;
1356         menuBar()->clear();
1357         QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1358         togglePlaylist();
1359     }
1360 #endif
1361     /*else */
1362     if ( event->type() == (int)SetVideoOnTopEvent_Type )
1363     {
1364         SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1365         if( p_event->OnTop() )
1366             setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1367         else
1368             setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1369         show(); /* necessary to apply window flags */
1370     }
1371 }
1372
1373 void MainInterface::keyPressEvent( QKeyEvent *e )
1374 {
1375     handleKeyPress( e );
1376 }
1377
1378 void MainInterface::handleKeyPress( QKeyEvent *e )
1379 {
1380     if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1381           && !menuBar()->isVisible() )
1382     {
1383         toggleMinimalView( false );
1384         e->accept();
1385     }
1386
1387     int i_vlck = qtEventToVLCKey( e );
1388     if( i_vlck > 0 )
1389     {
1390         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1391         e->accept();
1392     }
1393     else
1394         e->ignore();
1395 }
1396
1397 void MainInterface::resizeEvent( QResizeEvent * event )
1398 {
1399 #if 0
1400     if( b_keep_size )
1401     {
1402         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1403             i_visualmode == QT_MINIMAL_MODE )
1404         {
1405                 mainVideoSize = size();
1406         }
1407         else
1408         {
1409             if( VISIBLE( bgWidget) ||
1410                 ( videoIsActive && videoWidget->isVisible() )
1411               )
1412                 mainVideoSize = size();
1413             else
1414                 mainBasedSize = size();
1415         }
1416     }
1417 #endif
1418     QVLCMW::resizeEvent( event );
1419     msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1420 }
1421
1422 void MainInterface::wheelEvent( QWheelEvent *e )
1423 {
1424     int i_vlckey = qtWheelEventToVLCKey( e );
1425     var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1426     e->accept();
1427 }
1428
1429 void MainInterface::closeEvent( QCloseEvent *e )
1430 {
1431     e->accept();
1432     hide();
1433     THEDP->quit();
1434 }
1435
1436 void MainInterface::toggleFullScreen( void )
1437 {
1438     if( isFullScreen() )
1439     {
1440         showNormal();
1441         emit askUpdate(); // Needed if video was launched after the F11
1442         emit fullscreenInterfaceToggled( false );
1443     }
1444     else
1445     {
1446         showFullScreen();
1447         emit fullscreenInterfaceToggled( true );
1448     }
1449
1450 }
1451
1452 //moc doesn't know about #ifdef, so we have to build this method for every platform
1453 void MainInterface::changeThumbbarButtons( int i_status)
1454 {
1455 #ifdef WIN32
1456     // Define an array of two buttons. These buttons provide images through an
1457     // image list and also provide tooltips.
1458     DWORD dwMask = THB_BITMAP | THB_FLAGS;
1459
1460     THUMBBUTTON thbButtons[3];
1461     //prev
1462     thbButtons[0].dwMask = dwMask;
1463     thbButtons[0].iId = 0;
1464     thbButtons[0].iBitmap = 0;
1465
1466     //play/pause
1467     thbButtons[1].dwMask = dwMask;
1468     thbButtons[1].iId = 1;
1469
1470     //next
1471     thbButtons[2].dwMask = dwMask;
1472     thbButtons[2].iId = 2;
1473     thbButtons[2].iBitmap = 3;
1474
1475     switch( i_status )
1476     {
1477         case  0:
1478         case  END_S:
1479             {
1480                 thbButtons[0].dwFlags = THBF_HIDDEN;
1481                 thbButtons[1].dwFlags = THBF_HIDDEN;
1482                 thbButtons[2].dwFlags = THBF_HIDDEN;
1483                 break;
1484             }
1485         case PLAYING_S:
1486             {
1487                 thbButtons[0].dwFlags = THBF_ENABLED;
1488                 thbButtons[1].dwFlags = THBF_ENABLED;
1489                 thbButtons[2].dwFlags = THBF_ENABLED;
1490                 thbButtons[1].iBitmap = 1;
1491                 break;
1492             }
1493         case PAUSE_S:
1494             {
1495                 //thbButtons[0].dwFlags = THBF_ENABLED;
1496                 //thbButtons[1].dwFlags = THBF_ENABLED;
1497                 //thbButtons[2].dwFlags = THBF_ENABLED;
1498                 thbButtons[1].iBitmap = 2;
1499                 break;
1500             }
1501     }
1502
1503     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1504     if(S_OK != hr)
1505         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1506 #else
1507     ;
1508 #endif
1509 }
1510
1511 /*****************************************************************************
1512  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1513  *  We don't show the menu directly here because we don't want the
1514  *  caller to block for a too long time.
1515  *****************************************************************************/
1516 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1517                         vlc_value_t old_val, vlc_value_t new_val, void *param )
1518 {
1519     intf_thread_t *p_intf = (intf_thread_t *)param;
1520
1521     if( p_intf->pf_show_dialog )
1522     {
1523         p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1524                                 new_val.b_bool, NULL );
1525     }
1526
1527     return VLC_SUCCESS;
1528 }
1529
1530 /*****************************************************************************
1531  * IntfShowCB: callback triggered by the intf-show libvlc variable.
1532  *****************************************************************************/
1533 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1534                        vlc_value_t old_val, vlc_value_t new_val, void *param )
1535 {
1536     intf_thread_t *p_intf = (intf_thread_t *)param;
1537     p_intf->p_sys->p_mi->toggleFSC();
1538
1539     /* Show event */
1540      return VLC_SUCCESS;
1541 }