1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include "main_interface.hpp"
27 #include "input_manager.hpp"
28 #include "util/qvlcframe.hpp"
29 #include "util/customwidgets.hpp"
30 #include "dialogs_provider.hpp"
31 #include "components/interface_widgets.hpp"
32 #include "dialogs/playlist.hpp"
36 #include <QCloseEvent>
37 #include <QPushButton>
41 #include <QSystemTrayIcon>
46 #include <QWidgetAction>
60 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
61 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
62 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
64 #define DS(i) i.width(),i.height()
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
70 vlc_value_t old_val, vlc_value_t new_val, void *param );
71 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
74 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
75 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
77 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
79 static void DoRelease( intf_thread_t *p_intf, void *p_win )
81 return p_intf->p_sys->p_mi->releaseVideo( p_win );
83 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
85 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
88 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
90 /* Variables initialisation */
91 need_components_update = false;
92 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
93 embeddedPlaylistWasActive = videoIsActive = false;
97 * Configuration and settings
99 settings = new QSettings( "vlc", "vlc-qt-interface" );
100 settings->beginGroup( "MainWindow" );
103 setFocusPolicy( Qt::StrongFocus );
104 setAcceptDrops(true);
105 setWindowIcon( QApplication::windowIcon() );
106 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
108 /* Set The Video In emebedded Mode or not */
109 videoEmbeddedFlag = false;
110 if( config_GetInt( p_intf, "embedded-video" ) )
111 videoEmbeddedFlag = true;
113 alwaysVideoFlag = false;
114 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
115 alwaysVideoFlag = true;
117 /* Set the other interface settings */
118 playlistEmbeddedFlag = settings->value( "playlist-embedded", true).toBool();
119 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
120 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
122 /**************************
123 * UI and Widgets design
124 **************************/
125 setVLCWindowsTitle();
126 handleMainUi( settings );
129 QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag,
130 visualSelectorEnabled );
134 * TODO: clicking on the elapsed time should switch to the remaining time
137 * TODO: do we add a label for the current Volume ?
139 b_remainingTime = false;
140 timeLabel = new QLabel;
141 nameLabel = new QLabel;
142 speedLabel = new QLabel( "1.0x" );
143 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
144 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
145 statusBar()->addWidget( nameLabel, 8 );
146 statusBar()->addPermanentWidget( speedLabel, 0 );
147 statusBar()->addPermanentWidget( timeLabel, 2 );
148 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
149 timeLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
150 timeLabel->installEventFilter( this );
151 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
152 this, showSpeedMenu( QPoint ) );
153 CONNECT( timeLabel, customContextMenuRequested( QPoint ),
154 this, showTimeMenu( QPoint ) );
156 /**********************
157 * Systray Management *
158 **********************/
160 bool b_createSystray = false;
161 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
162 if( config_GetInt( p_intf, "qt-start-minimized") )
164 if( b_systrayAvailable ){
165 b_createSystray = true;
168 else msg_Warn( p_intf, "You can't minize if you haven't a system "
171 if( config_GetInt( p_intf, "qt-system-tray") )
172 b_createSystray = true;
174 if( b_systrayAvailable && b_createSystray )
177 /* Init input manager */
178 MainInputManager::getInstance( p_intf );
179 ON_TIMEOUT( updateOnTimer() );
185 /* Connect the input manager to the GUI elements it manages */
186 /* It is also connected to the control->slider, see the ControlsWidget */
187 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
188 this, setDisplayPosition( float, int, int ) );
190 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
192 /** Connects on nameChanged() */
193 /* Naming in the controller statusbar */
194 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
195 setName( QString ) );
196 /* and in the systray */
199 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
200 updateSystrayTooltipName( QString ) );
202 /* and in the title of the controller */
203 if( config_GetInt( p_intf, "qt-name-in-title" ) )
205 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
206 setVLCWindowsTitle( QString ) );
209 /** CONNECTS on PLAY_STATUS **/
210 /* Status on the main controller */
211 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
212 /* and in the systray */
215 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
216 updateSystrayTooltipStatus( int ) );
222 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
223 var_AddCallback( p_intf, "interaction", InteractCallback, this );
224 p_intf->b_interaction = VLC_TRUE;
226 /* Register callback for the intf-popupmenu variable */
227 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
228 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
229 if( p_playlist != NULL )
231 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
232 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
233 vlc_object_release( p_playlist );
237 MainInterface::~MainInterface()
239 /* Unregister callback for the intf-popupmenu variable */
240 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
241 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
242 if( p_playlist != NULL )
244 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
245 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
246 vlc_object_release( p_playlist );
249 settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
250 settings->setValue( "adv-controls", getControlsVisibilityStatus() & 0x1 );
251 settings->setValue( "pos", pos() );
252 settings->endGroup();
254 p_intf->b_interaction = VLC_FALSE;
255 var_DelCallback( p_intf, "interaction", InteractCallback, this );
257 p_intf->pf_request_window = NULL;
258 p_intf->pf_release_window = NULL;
259 p_intf->pf_control_window = NULL;
262 /*****************************
264 *****************************/
267 * Give the decorations of the Main Window a correct Name.
268 * If nothing is given, set it to VLC...
270 void MainInterface::setVLCWindowsTitle( QString aTitle )
272 if( aTitle.isEmpty() )
274 setWindowTitle( qtr( "VLC media player" ) );
278 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
283 void MainInterface::handleMainUi( QSettings *settings )
285 /* Create the main Widget and the mainLayout */
286 QWidget *main = new QWidget( this );
287 mainLayout = new QVBoxLayout( main );
288 setCentralWidget( main );
290 /* Margins, spacing */
291 main->setContentsMargins( 0, 0, 0, 0 );
292 mainLayout->setMargin( 0 );
294 /* Create the CONTROLS Widget */
295 controls = new ControlsWidget( p_intf,
296 settings->value( "adv-controls", false ).toBool() );
298 /* Configure the Controls */
299 BUTTON_SET_IMG( controls->playlistButton, "" , playlist_icon.png,
300 playlistEmbeddedFlag ? qtr( "Show playlist" ) :
301 qtr( "Open playlist" ) );
302 BUTTONACT( controls->playlistButton, togglePlaylist() );
304 /* Add the controls Widget to the main Widget */
305 mainLayout->addWidget( controls );
307 /* Create the Speed Control Widget */
308 speedControl = new SpeedControlWidget( p_intf );
309 speedControlMenu = new QMenu( this );
310 QWidgetAction *widgetAction = new QWidgetAction( this );
311 widgetAction->setDefaultWidget( speedControl );
312 speedControlMenu->addAction( widgetAction );
314 /* Set initial size */
315 resize( PREF_W, PREF_H );
316 addSize = QSize( mainLayout->margin() * 2, PREF_H );
319 visualSelector = new VisualSelector( p_intf );
320 mainLayout->insertWidget( 0, visualSelector );
321 visualSelector->hide();
323 /* And video Outputs */
324 if( alwaysVideoFlag )
326 bgWidget = new BackgroundWidget( p_intf );
327 bgWidget->widgetSize = settings->value( "backgroundSize",
328 QSize( 300, 300 ) ).toSize();
329 bgWidget->resize( bgWidget->widgetSize );
330 bgWidget->updateGeometry();
331 mainLayout->insertWidget( 0, bgWidget );
334 if( videoEmbeddedFlag )
336 videoWidget = new VideoWidget( p_intf );
337 videoWidget->widgetSize = QSize( 1, 1 );
338 //videoWidget->resize( videoWidget->widgetSize );
339 mainLayout->insertWidget( 0, videoWidget );
341 p_intf->pf_request_window = ::DoRequest;
342 p_intf->pf_release_window = ::DoRelease;
343 p_intf->pf_control_window = ::DoControl;
346 /* Finish the sizing */
347 setMinimumSize( PREF_W, addSize.height() );
350 /**********************************************************************
351 * Handling of sizing of the components
352 **********************************************************************/
353 void MainInterface::calculateInterfaceSize()
355 int width = 0, height = 0;
356 if( VISIBLE( bgWidget ) )
358 width = bgWidget->widgetSize.width();
359 height = bgWidget->widgetSize.height();
360 assert( !(playlistWidget && playlistWidget->isVisible() ) );
362 else if( VISIBLE( playlistWidget ) )
364 width = playlistWidget->widgetSize.width();
365 height = playlistWidget->widgetSize.height();
367 else if( videoIsActive )
369 width = videoWidget->widgetSize.width() ;
370 height = videoWidget->widgetSize.height();
374 width = PREF_W - addSize.width();
375 height = PREF_H - addSize.height();
377 if( VISIBLE( visualSelector ) )
378 height += visualSelector->height();
379 /* if( VISIBLE( advControls) )
381 height += advControls->sizeHint().height();
383 mainSize = QSize( width + addSize.width(), height + addSize.height() );
386 void MainInterface::resizeEvent( QResizeEvent *e )
388 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
389 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
391 SET_WH( videoWidget, e->size().width() - addSize.width(),
392 e->size().height() - addSize.height() );
393 videoWidget->updateGeometry();
395 if( VISIBLE( playlistWidget ) )
397 SET_WH( playlistWidget , e->size().width() - addSize.width(),
398 e->size().height() - addSize.height() );
399 playlistWidget->updateGeometry();
403 /****************************************************************************
404 * Small right-click menus
405 ****************************************************************************/
406 void MainInterface::showSpeedMenu( QPoint pos )
408 speedControlMenu->exec( QCursor::pos() );
411 void MainInterface::showTimeMenu( QPoint pos )
414 menu.addAction( qtr("Elapsed Time") , this, SLOT( setElapsedTime() ) );
415 menu.addAction( qtr("Remaining Time") , this, SLOT( setRemainTime() ) );
416 menu.exec( QCursor::pos() );
419 /****************************************************************************
421 ****************************************************************************/
422 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
423 int *pi_y, unsigned int *pi_width,
424 unsigned int *pi_height )
426 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
429 videoIsActive = true;
430 if( VISIBLE( playlistWidget ) )
432 embeddedPlaylistWasActive = true;
433 // playlistWidget->hide();
435 bool bgWasVisible = false;
436 if( VISIBLE( bgWidget) )
441 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
443 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
445 else /* Background widget available, use its size */
447 /* Ok, our visualizations are bad, so don't do this for the moment
448 * use the requested size anyway */
449 // videoWidget->widgetSize = bgWidget->widgeTSize;
450 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
452 videoWidget->updateGeometry(); // Needed for deinterlace
453 need_components_update = true;
458 void MainInterface::releaseVideo( void *p_win )
460 videoWidget->release( p_win );
461 videoWidget->widgetSize = QSize( 0, 0 );
462 videoWidget->resize( videoWidget->widgetSize );
464 if( embeddedPlaylistWasActive )
465 playlistWidget->show();
469 videoIsActive = false;
470 need_components_update = true;
473 class SetVideoOnTopQtEvent : public QEvent
476 SetVideoOnTopQtEvent( bool _onTop ) :
477 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
490 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
492 int i_ret = VLC_EGENERIC;
497 unsigned int *pi_width = va_arg( args, unsigned int * );
498 unsigned int *pi_height = va_arg( args, unsigned int * );
499 *pi_width = videoWidget->widgetSize.width();
500 *pi_height = videoWidget->widgetSize.height();
506 unsigned int i_width = va_arg( args, unsigned int );
507 unsigned int i_height = va_arg( args, unsigned int );
508 videoWidget->widgetSize = QSize( i_width, i_height );
509 // videoWidget->updateGeometry();
510 need_components_update = true;
514 case VOUT_SET_STAY_ON_TOP:
516 int i_arg = va_arg( args, int );
517 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
522 msg_Warn( p_intf, "unsupported control query" );
528 /*****************************************************************************
529 * Playlist, Visualisation and Menus handling
530 *****************************************************************************/
532 * Toggle the playlist widget or dialog
534 void MainInterface::togglePlaylist()
536 // Toggle the playlist dialog if not embedded and return
537 if( !playlistEmbeddedFlag )
543 THEDP->playlistDialog();
547 // Create the playlist Widget and destroy the existing dialog
548 if( !playlistWidget )
550 PlaylistDialog::killInstance();
551 playlistWidget = new PlaylistWidget( p_intf );
552 mainLayout->insertWidget( 0, playlistWidget );
553 playlistWidget->widgetSize = settings->value( "playlistSize",
554 QSize( 650, 310 ) ).toSize();
555 playlistWidget->hide();
557 CONNECT( playlistWidget, artSet( QString ), bgWidget, setArt(QString) );
560 // And toggle visibility
561 if( VISIBLE( playlistWidget ) )
563 playlistWidget->hide();
564 if( bgWidget ) bgWidget->show();
567 videoWidget->widgetSize = savedVideoSize;
568 videoWidget->resize( videoWidget->widgetSize );
569 videoWidget->updateGeometry();
570 if( bgWidget ) bgWidget->hide();
575 playlistWidget->show();
578 savedVideoSize = videoWidget->widgetSize;
579 videoWidget->widgetSize.setHeight( 0 );
580 videoWidget->resize( videoWidget->widgetSize );
581 videoWidget->updateGeometry();
583 if( VISIBLE( bgWidget ) ) bgWidget->hide();
586 doComponentsUpdate();
589 void MainInterface::undockPlaylist()
593 playlistWidget->hide();
594 playlistWidget->deleteLater();
595 mainLayout->removeWidget( playlistWidget );
596 playlistWidget = NULL;
597 playlistEmbeddedFlag = false;
600 QVLCMenu::createMenuBar( this, p_intf, false, visualSelectorEnabled);
604 videoWidget->widgetSize = savedVideoSize;
605 videoWidget->resize( videoWidget->widgetSize );
606 videoWidget->updateGeometry();
609 doComponentsUpdate();
610 THEDP->playlistDialog();
615 void MainInterface::visual()
617 if( !VISIBLE( visualSelector) )
619 visualSelector->show();
620 if( !THEMIM->getIM()->hasVideo() )
622 /* Show the background widget */
624 visualSelectorEnabled = true;
628 /* Stop any currently running visualization */
629 visualSelector->hide();
630 visualSelectorEnabled = false;
632 doComponentsUpdate();
636 void MainInterface::toggleMenus()
638 msg_Dbg( p_intf, "I HAS HERE, HIDING YOUR MENUZ: \\_o<~~ coin coin" );
640 TOGGLEV( statusBar() );
644 /* Video widget cannot do this synchronously as it runs in another thread */
645 /* Well, could it, actually ? Probably dangerous ... */
646 void MainInterface::doComponentsUpdate()
648 calculateInterfaceSize();
652 void MainInterface::toggleAdvanced()
654 controls->toggleAdvanced();
657 int MainInterface::getControlsVisibilityStatus()
659 return( (controls->isVisible() ? 0x2 : 0x0 )
660 + controls->b_advancedVisible );
663 /************************************************************************
665 ************************************************************************/
666 void MainInterface::setDisplayPosition( float pos, int time, int length )
668 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
669 secstotimestr( psz_length, length );
670 secstotimestr( psz_time, b_remainingTime ? length - time : time );
671 QString title; title.sprintf( "%s/%s", psz_time, psz_length );
672 if( b_remainingTime ) timeLabel->setText( " -"+title+" " );
673 else timeLabel->setText( " "+title+" " );
676 void MainInterface::toggleTimeDisplay()
678 b_remainingTime = ( b_remainingTime ? false : true );
681 void MainInterface::setElapsedTime(){ b_remainingTime = false; }
682 void MainInterface::setRemainTime(){ b_remainingTime = true; }
684 void MainInterface::setName( QString name )
687 nameLabel->setText( " " + name+" " );
690 void MainInterface::setStatus( int status )
692 controls->setStatus( status );
694 updateSystrayMenu( status );
697 void MainInterface::setRate( int rate )
700 str.setNum( ( 1000/(double)rate), 'f', 2 );
702 speedLabel->setText( str );
703 speedControl->updateControls( rate );
706 void MainInterface::updateOnTimer()
708 /* \todo Make this event-driven */
709 if( intf_ShouldDie( p_intf ) )
711 QApplication::closeAllWindows();
712 QApplication::quit();
714 if( need_components_update )
716 doComponentsUpdate();
717 need_components_update = false;
720 controls->updateOnTimer();
723 /*****************************************************************************
724 * Systray Icon and Systray Menu
725 *****************************************************************************/
728 * Create a SystemTray icon and a menu that would go with it.
729 * Connects to a click handler on the icon.
731 void MainInterface::createSystray()
733 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
734 sysTray = new QSystemTrayIcon( iconVLC, this );
735 sysTray->setToolTip( qtr( "VLC media player" ));
737 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
738 systrayMenu->setIcon( iconVLC );
740 QVLCMenu::updateSystrayMenu( this, p_intf, true );
743 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
744 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
748 * Update the menu of the Systray Icon.
749 * May be unneedded, since it just calls QVLCMenu::update
752 void MainInterface::updateSystrayMenu( int status )
754 QVLCMenu::updateSystrayMenu( this, p_intf ) ;
758 * Updates the Systray Icon's menu and toggle the main interface
760 void MainInterface::toggleUpdateSystrayMenu()
770 /* check if any visible window is above vlc in the z-order,
771 * but ignore the ones always on top */
774 wi.cbSize = sizeof( WINDOWINFO );
775 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
776 hwnd && !IsWindowVisible( hwnd );
777 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
778 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
779 (wi.dwExStyle&WS_EX_TOPMOST) )
781 if( isActiveWindow() )
791 QVLCMenu::updateSystrayMenu( this, p_intf );
794 void MainInterface::handleSystrayClick(
795 QSystemTrayIcon::ActivationReason reason )
799 case QSystemTrayIcon::Trigger:
800 toggleUpdateSystrayMenu();
802 case QSystemTrayIcon::MiddleClick:
803 sysTray->showMessage( qtr( "VLC media player" ),
804 qtr( "Control menu for the player" ),
805 QSystemTrayIcon::Information, 4000 );
811 * Updates the name of the systray Icon tooltip.
812 * Doesn't check if the systray exists, check before you call it.
813 * FIXME !!! Fusion with next function ?
815 void MainInterface::updateSystrayTooltipName( QString name )
819 sysTray->setToolTip( qtr( "VLC media player" ) );
823 sysTray->setToolTip( name );
824 if( notificationEnabled )
826 sysTray->showMessage( qtr( "VLC media player" ), name,
827 QSystemTrayIcon::NoIcon, 4000 );
833 * Updates the status of the systray Icon tooltip.
834 * Doesn't check if the systray exists, check before you call it.
836 void MainInterface::updateSystrayTooltipStatus( int i_status )
842 sysTray->setToolTip( qtr( "VLC media player" ) );
847 sysTray->setToolTip( input_name );
848 //+ " - " + qtr( "Playing" ) );
853 sysTray->setToolTip( input_name + " - "
860 /************************************************************************
862 ************************************************************************/
863 void MainInterface::dropEvent(QDropEvent *event)
865 const QMimeData *mimeData = event->mimeData();
867 /* D&D of a subtitles file, add it on the fly */
868 if( mimeData->urls().size() == 1 )
870 if( THEMIM->getIM()->hasInput() )
872 if( input_AddSubtitles( THEMIM->getInput(),
873 qtu( mimeData->urls()[0].toString() ),
876 event->acceptProposedAction();
882 foreach( QUrl url, mimeData->urls() ) {
883 QString s = url.toString();
884 if( s.length() > 0 ) {
885 playlist_Add( THEPL, qtu(s), NULL,
886 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
887 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
891 event->acceptProposedAction();
893 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
895 event->acceptProposedAction();
897 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
899 event->acceptProposedAction();
901 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
906 /************************************************************************
908 ************************************************************************/
909 void MainInterface::customEvent( QEvent *event )
911 if( event->type() == PLDockEvent_Type )
913 PlaylistDialog::killInstance();
914 playlistEmbeddedFlag = true;
916 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
919 else if ( event->type() == SetVideoOnTopEvent_Type )
921 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
922 if( p_event->OnTop() )
923 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
925 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
926 show(); /* necessary to apply window flags?? */
930 bool MainInterface::eventFilter(QObject *obj, QEvent *event)
932 if( (obj == timeLabel) && (event->type() == QEvent::MouseButtonPress) ) toggleTimeDisplay();
936 void MainInterface::keyPressEvent( QKeyEvent *e )
938 int i_vlck = qtEventToVLCKey( e );
941 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
948 void MainInterface::wheelEvent( QWheelEvent *e )
950 int i_vlckey = qtWheelEventToVLCKey( e );
951 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
955 void MainInterface::closeEvent( QCloseEvent *e )
958 vlc_object_kill( p_intf );
961 /*****************************************************************************
963 *****************************************************************************/
964 static int InteractCallback( vlc_object_t *p_this,
965 const char *psz_var, vlc_value_t old_val,
966 vlc_value_t new_val, void *param )
968 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
969 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
970 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
971 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
975 /*****************************************************************************
976 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
977 * We don't show the menu directly here because we don't want the
978 * caller to block for a too long time.
979 *****************************************************************************/
980 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
981 vlc_value_t old_val, vlc_value_t new_val, void *param )
983 intf_thread_t *p_intf = (intf_thread_t *)param;
985 if( p_intf->pf_show_dialog )
987 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
994 /*****************************************************************************
995 * IntfShowCB: callback triggered by the intf-show playlist variable.
996 *****************************************************************************/
997 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
998 vlc_value_t old_val, vlc_value_t new_val, void *param )
1000 intf_thread_t *p_intf = (intf_thread_t *)param;
1001 //p_intf->p_sys->b_intf_show = VLC_TRUE;