1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "main_interface.hpp"
26 #include "input_manager.hpp"
27 #include "util/input_slider.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>
57 #define VISIBLE(i) (i && i->isVisible())
59 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
60 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
61 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
63 #define DS(i) i.width(),i.height()
67 /* Callback prototypes */
68 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
69 vlc_value_t old_val, vlc_value_t new_val, void *param );
70 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
71 vlc_value_t old_val, vlc_value_t new_val, void *param );
72 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
75 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
76 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
78 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
80 static void DoRelease( intf_thread_t *p_intf, void *p_win )
82 return p_intf->p_sys->p_mi->releaseVideo( p_win );
84 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
86 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
89 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
91 /* Variables initialisation */
92 need_components_update = false;
93 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
94 embeddedPlaylistWasActive = videoIsActive = false;
96 bool b_createSystray = false;
100 * Configuration and settings
102 settings = new QSettings( "VideoLAN", "VLC" );
103 settings->beginGroup( "MainWindow" );
106 setFocusPolicy( Qt::StrongFocus );
107 setAcceptDrops(true);
108 setWindowIcon( QApplication::windowIcon() );
110 /* Set The Video In emebedded Mode or not */
111 videoEmbeddedFlag = false;
112 if( config_GetInt( p_intf, "embedded-video" ) )
113 videoEmbeddedFlag = true;
115 alwaysVideoFlag = false;
116 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
117 alwaysVideoFlag = true;
119 /* Set the other interface settings */
120 playlistEmbeddedFlag = settings->value("playlist-embedded", true).toBool();
121 advControlsEnabled= settings->value( "adv-controls", false ).toBool();
122 visualSelectorEnabled= settings->value( "visual-selector", false ).toBool();
126 palette2.setColor(this->backgroundRole(), Qt::magenta);
127 setPalette(palette2);
133 setVLCWindowsTitle();
134 handleMainUi( settings );
137 QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag,
138 advControlsEnabled, visualSelectorEnabled );
141 timeLabel = new QLabel;
142 nameLabel = new QLabel;
143 speedLabel = new QLabel( "1.0x" );
144 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
145 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
146 statusBar()->addWidget( nameLabel, 8 );
147 statusBar()->addPermanentWidget( speedLabel, 0 );
148 statusBar()->addPermanentWidget( timeLabel, 2 );
152 if( config_GetInt( p_intf, "qt-start-minimized") )
155 b_createSystray = true;
157 if( config_GetInt( p_intf, "qt-system-tray") )
158 b_createSystray = true;
159 if (QSystemTrayIcon::isSystemTrayAvailable() && b_createSystray )
162 /* Init input manager */
163 MainInputManager::getInstance( p_intf );
164 ON_TIMEOUT( updateOnTimer() );
171 CONNECT( ui.volumeSlider, valueChanged(int), this, updateVolume(int) );
173 /* Connect the input manager to the GUI elements it manages */
174 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
175 slider, setPosition( float,int, int ) );
176 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
177 this, setDisplay( float, int, int ) );
179 /* Naming in the controller */
180 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
181 setName( QString ) );
182 if( config_GetInt( p_intf, "qt-system-tray" ) && sysTray )
184 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
185 updateSystrayTooltipName( QString ) );
187 if( config_GetInt( p_intf, "qt-name-in-title" ) )
189 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
190 setVLCWindowsTitle( QString ) );
194 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
195 CONNECT( THEMIM->getIM(), navigationChanged( int ),
196 this, setNavigation(int) );
197 if( config_GetInt( p_intf, "qt-system-tray" ) && sysTray )
199 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
200 updateSystrayTooltipStatus( int ) );
202 CONNECT( slider, sliderDragged( float ),
203 THEMIM->getIM(), sliderUpdate( float ) );
206 CONNECT( ui.prevSectionButton, clicked(), THEMIM->getIM(),
208 CONNECT( ui.nextSectionButton, clicked(), THEMIM->getIM(),
210 CONNECT( ui.menuButton, clicked(), THEMIM->getIM(),
216 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
217 var_AddCallback( p_intf, "interaction", InteractCallback, this );
218 p_intf->b_interaction = VLC_TRUE;
220 /* Register callback for the intf-popupmenu variable */
221 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
222 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
223 if( p_playlist != NULL )
225 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
226 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
227 vlc_object_release( p_playlist );
231 MainInterface::~MainInterface()
233 /* Unregister callback for the intf-popupmenu variable */
234 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
235 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
236 if( p_playlist != NULL )
238 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
239 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
240 vlc_object_release( p_playlist );
243 settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
244 settings->setValue( "adv-controls", advControlsEnabled );
245 settings->setValue( "pos", pos() );
246 settings->endGroup();
248 p_intf->b_interaction = VLC_FALSE;
249 var_DelCallback( p_intf, "interaction", InteractCallback, this );
251 p_intf->pf_request_window = NULL;
252 p_intf->pf_release_window = NULL;
253 p_intf->pf_control_window = NULL;
256 /*****************************
258 *****************************/
261 * Give the decorations of the Main Window a correct Name.
262 * If nothing is given, set it to VLC...
264 void MainInterface::setVLCWindowsTitle( QString aTitle )
266 if( aTitle.isEmpty() )
268 setWindowTitle( qtr( "VLC media player" ) );
272 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
276 void MainInterface::handleMainUi( QSettings *settings )
278 QWidget *main = new QWidget( this );
279 QVBoxLayout *mainLayout = new QVBoxLayout( main );
280 setCentralWidget( main );
282 /* Margins, spacing */
283 main->setContentsMargins( 0, 0, 0, 0 );
284 mainLayout->setMargin( 0 );
287 QWidget *controls = new QWidget;
288 ui.setupUi( controls );
290 /* Configure the UI */
291 slider = new InputSlider( Qt::Horizontal, NULL );
292 ui.vboxLayout->insertWidget( 0, slider );
293 ui.discFrame->hide();
295 BUTTON_SET_IMG( ui.prevSectionButton, "", previous.png, "" );
296 BUTTON_SET_IMG( ui.nextSectionButton, "", next.png, "" );
297 BUTTON_SET_IMG( ui.menuButton, "", previous.png, "" );
299 BUTTON_SET_ACT_I( ui.prevButton, "" , previous.png,
300 qtr("Previous"), prev() );
301 BUTTON_SET_ACT_I( ui.nextButton, "", next.png, qtr("Next"), next() );
302 BUTTON_SET_ACT_I( ui.playButton, "", play.png, qtr("Play"), play() );
303 BUTTON_SET_ACT_I( ui.stopButton, "", stop.png, qtr("Stop"), stop() );
306 ui.volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
307 ui.volumeSlider->setMaximum( 100 );
308 ui.volMuteLabel->setToolTip( qtr( "Mute" ) );
309 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
310 ui.volMuteLabel->installEventFilter(h);
311 ui.volumeSlider->setFocusPolicy( Qt::NoFocus );
313 BUTTON_SET_IMG( ui.playlistButton, "" , playlist_icon.png,
314 playlistEmbeddedFlag ? qtr( "Show playlist" ) :
315 qtr( "Open playlist" ) );
316 BUTTONACT( ui.playlistButton, playlist() );
320 palette.setColor(main->backgroundRole(), Qt::green);
321 main->setPalette(palette);
324 /* Add the controls Widget */
325 mainLayout->addWidget( controls );
327 /* Set initial size */
328 resize ( PREF_W, PREF_H );
330 addSize = QSize( mainLayout->margin() * 2, PREF_H );
332 /* advanced Controls handling */
333 advControls = new ControlsWidget( p_intf );
334 mainLayout->insertWidget( 0, advControls );
335 advControls->updateGeometry();
336 if( !advControlsEnabled ) advControls->hide();
337 need_components_update = true;
340 visualSelector = new VisualSelector( p_intf );
341 mainLayout->insertWidget( 0, visualSelector );
342 visualSelector->hide();
344 /* And video Outputs */
345 if( alwaysVideoFlag )
347 bgWidget = new BackgroundWidget( p_intf );
348 bgWidget->widgetSize = settings->value( "backgroundSize",
349 QSize( 200, 200 ) ).toSize();
350 bgWidget->resize( bgWidget->widgetSize );
351 bgWidget->updateGeometry();
352 mainLayout->insertWidget( 0, bgWidget );
355 if( videoEmbeddedFlag )
357 videoWidget = new VideoWidget( p_intf );
358 videoWidget->widgetSize = QSize( 1, 1 );
359 //videoWidget->resize( videoWidget->widgetSize );
360 mainLayout->insertWidget( 0, videoWidget );
362 p_intf->pf_request_window = ::DoRequest;
363 p_intf->pf_release_window = ::DoRelease;
364 p_intf->pf_control_window = ::DoControl;
367 /* Finish the sizing */
368 setMinimumSize( PREF_W, addSize.height() );
371 /**********************************************************************
372 * Handling of the components
373 **********************************************************************/
374 void MainInterface::calculateInterfaceSize()
376 int width = 0, height = 0;
377 if( VISIBLE( bgWidget ) )
379 width = bgWidget->widgetSize.width();
380 height = bgWidget->widgetSize.height();
381 assert( !(playlistWidget && playlistWidget->isVisible() ) );
383 else if( VISIBLE( playlistWidget ) )
385 width = playlistWidget->widgetSize.width();
386 height = playlistWidget->widgetSize.height();
388 else if( videoIsActive )
390 width = videoWidget->widgetSize.width() ;
391 height = videoWidget->widgetSize.height();
395 width = PREF_W - addSize.width();
396 height = PREF_H - addSize.height();
398 if( VISIBLE( visualSelector ) )
399 height += visualSelector->height();
400 if( VISIBLE( advControls) )
402 height += advControls->sizeHint().height();
404 mainSize = QSize( width + addSize.width(), height + addSize.height() );
407 void MainInterface::resizeEvent( QResizeEvent *e )
409 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
410 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
412 SET_WH( videoWidget, e->size().width() - addSize.width(),
413 e->size().height() - addSize.height() );
414 videoWidget->updateGeometry();
416 if( VISIBLE( playlistWidget ) )
418 SET_WH( playlistWidget , e->size().width() - addSize.width(),
419 e->size().height() - addSize.height() );
420 playlistWidget->updateGeometry();
424 /*****************************************************************************
425 * Systray Icon and Systray Menu
426 *****************************************************************************/
429 * Create a SystemTray icon and a menu that would go with it.
430 * Connects to a click handler on the icon.
432 void MainInterface::createSystray()
434 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
435 sysTray = new QSystemTrayIcon( iconVLC, this );
436 sysTray->setToolTip( qtr( "VLC media player" ));
438 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
439 systrayMenu->setIcon( iconVLC );
441 QVLCMenu::updateSystrayMenu( this, p_intf, true );
444 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
445 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
449 * Update the menu of the Systray Icon.
450 * May be unneedded, since it just calls QVLCMenu::update
453 void MainInterface::updateSystrayMenu( int status )
455 QVLCMenu::updateSystrayMenu( this, p_intf ) ;
459 * Updates the Systray Icon's menu and toggle the main interface
461 void MainInterface::toggleUpdateSystrayMenu()
464 QVLCMenu::updateSystrayMenu( this, p_intf );
467 void MainInterface::handleSystrayClick(
468 QSystemTrayIcon::ActivationReason reason )
472 case QSystemTrayIcon::Trigger:
473 toggleUpdateSystrayMenu();
475 case QSystemTrayIcon::MiddleClick:
476 sysTray->showMessage( qtr( "VLC media player" ),
477 qtr( "Control menu for the player" ),
478 QSystemTrayIcon::Information, 4000 );
484 * Updates the name of the systray Icon tooltip.
485 * Doesn't check if the systray exists, check before you call it.
486 * FIXME !!! Fusion with next function ?
488 void MainInterface::updateSystrayTooltipName( QString name )
492 sysTray->setToolTip( qtr( "VLC media player" ) );
496 sysTray->setToolTip( name );
501 * Updates the status of the systray Icon tooltip.
502 * Doesn't check if the systray exists, check before you call it.
504 void MainInterface::updateSystrayTooltipStatus( int i_status )
510 sysTray->setToolTip( qtr( "VLC media player" ) );
515 sysTray->setToolTip( input_name );
516 //+ " - " + qtr( "Playing" ) );
521 sysTray->setToolTip( input_name + " - "
527 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
528 int *pi_y, unsigned int *pi_width,
529 unsigned int *pi_height )
531 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
534 videoIsActive = true;
535 if( VISIBLE( playlistWidget ) )
537 embeddedPlaylistWasActive = true;
538 // playlistWidget->hide();
540 bool bgWasVisible = false;
541 if( VISIBLE( bgWidget) )
546 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
548 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
550 else /* Background widget available, use its size */
552 /* Ok, our visualizations are bad, so don't do this for the moment
553 * use the requested size anyway */
554 // videoWidget->widgetSize = bgWidget->widgeTSize;
555 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
557 // videoWidget->updateGeometry(); /// FIXME: Needed ?
558 need_components_update = true;
563 void MainInterface::releaseVideo( void *p_win )
565 videoWidget->release( p_win );
566 videoWidget->widgetSize = QSize( 0, 0 );
567 videoWidget->resize( videoWidget->widgetSize );
569 if( embeddedPlaylistWasActive )
570 ;//playlistWidget->show();
574 videoIsActive = false;
575 need_components_update = true;
578 class SetVideoOnTopQtEvent : public QEvent
581 SetVideoOnTopQtEvent( bool _onTop ) :
582 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
595 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
597 int i_ret = VLC_EGENERIC;
602 unsigned int *pi_width = va_arg( args, unsigned int * );
603 unsigned int *pi_height = va_arg( args, unsigned int * );
604 *pi_width = videoWidget->widgetSize.width();
605 *pi_height = videoWidget->widgetSize.height();
611 unsigned int i_width = va_arg( args, unsigned int );
612 unsigned int i_height = va_arg( args, unsigned int );
613 videoWidget->widgetSize = QSize( i_width, i_height );
614 // videoWidget->updateGeometry();
615 need_components_update = true;
619 case VOUT_SET_STAY_ON_TOP:
621 int i_arg = va_arg( args, int );
622 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
627 msg_Warn( p_intf, "unsupported control query" );
633 void MainInterface::advanced()
635 if( !VISIBLE( advControls ) )
638 advControlsEnabled = true;
643 advControlsEnabled = false;
645 doComponentsUpdate();
648 void MainInterface::visual()
650 if( !VISIBLE( visualSelector) )
652 visualSelector->show();
653 if( !THEMIM->getIM()->hasVideo() )
655 /* Show the background widget */
657 visualSelectorEnabled = true;
661 /* Stop any currently running visualization */
662 visualSelector->hide();
663 visualSelectorEnabled = false;
665 doComponentsUpdate();
668 void MainInterface::playlist()
670 // Toggle the playlist dialog
671 if( !playlistEmbeddedFlag )
677 THEDP->playlistDialog();
681 if( !playlistWidget )
683 PlaylistDialog::killInstance();
684 playlistWidget = new PlaylistWidget( p_intf );
685 ui.vboxLayout->insertWidget( 0, playlistWidget );
686 playlistWidget->widgetSize = settings->value( "playlistSize",
687 QSize( 650, 310 ) ).toSize();
688 playlistWidget->hide();
690 if( VISIBLE( playlistWidget ) )
692 playlistWidget->hide();
695 videoWidget->widgetSize = savedVideoSize;
696 videoWidget->resize( videoWidget->widgetSize );
697 videoWidget->updateGeometry();
699 if( bgWidget ) bgWidget->show();
703 playlistWidget->show();
706 savedVideoSize = videoWidget->widgetSize;
707 videoWidget->widgetSize.setHeight( 0 );
708 videoWidget->resize( videoWidget->widgetSize );
709 videoWidget->updateGeometry();
711 if( VISIBLE( bgWidget ) ) bgWidget->hide();
713 doComponentsUpdate();
716 /* Video widget cannot do this synchronously as it runs in another thread */
717 /* Well, could it, actually ? Probably dangerous ... */
718 void MainInterface::doComponentsUpdate()
720 calculateInterfaceSize();
724 void MainInterface::undockPlaylist()
728 playlistWidget->hide();
729 playlistWidget->deleteLater();
730 ui.vboxLayout->removeWidget( playlistWidget );
731 playlistWidget = NULL;
732 playlistEmbeddedFlag = false;
735 QVLCMenu::createMenuBar( this, p_intf, false, advControlsEnabled,
736 visualSelectorEnabled);
740 videoWidget->widgetSize = savedVideoSize;
741 videoWidget->resize( videoWidget->widgetSize );
742 videoWidget->updateGeometry();
745 doComponentsUpdate();
746 THEDP->playlistDialog();
750 void MainInterface::toggleMenus()
752 if( menuBar()->isVisible() ) menuBar()->hide();
753 else menuBar()->show();
754 msg_Dbg( p_intf, "I was there: \\_o<~~ coin coin" );
757 void MainInterface::customEvent( QEvent *event )
759 if( event->type() == PLDockEvent_Type )
761 PlaylistDialog::killInstance();
762 playlistEmbeddedFlag = true;
764 QVLCMenu::createMenuBar(this, p_intf, true, advControlsEnabled,
765 visualSelectorEnabled);
768 else if ( event->type() == SetVideoOnTopEvent_Type )
770 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
771 if( p_event->OnTop() )
772 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
774 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
775 show(); /* necessary to apply window flags?? */
780 /************************************************************************
782 ************************************************************************/
783 void MainInterface::dropEvent(QDropEvent *event)
785 const QMimeData *mimeData = event->mimeData();
787 /* D&D of a subtitles file, add it on the fly */
788 if( mimeData->urls().size() == 1 )
790 if( THEMIM->getIM()->hasInput() )
792 if( input_AddSubtitles( THEMIM->getInput(),
793 qtu( mimeData->urls()[0].toString() ),
796 event->acceptProposedAction();
802 foreach( QUrl url, mimeData->urls() ) {
803 QString s = url.toString();
804 if( s.length() > 0 ) {
805 playlist_Add( THEPL, qtu(s), NULL,
806 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
807 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
811 event->acceptProposedAction();
813 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
815 event->acceptProposedAction();
817 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
819 event->acceptProposedAction();
821 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
826 /************************************************************************
828 ************************************************************************/
829 void MainInterface::keyPressEvent( QKeyEvent *e )
831 int i_vlck = qtEventToVLCKey( e );
834 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
841 void MainInterface::wheelEvent( QWheelEvent *e )
843 int i_vlckey = qtWheelEventToVLCKey( e );
844 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
848 void MainInterface::stop()
853 void MainInterface::play()
855 if( playlist_IsEmpty(THEPL) )
857 /* The playlist is empty, open a file requester */
858 THEDP->openFileDialog();
862 THEMIM->togglePlayPause();
865 void MainInterface::prev()
870 void MainInterface::next()
875 void MainInterface::setDisplay( float pos, int time, int length )
877 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
878 secstotimestr( psz_length, length );
879 secstotimestr( psz_time, time );
881 title.sprintf( "%s/%s", psz_time, psz_length );
882 timeLabel->setText( " "+title+" " );
885 void MainInterface::setName( QString name )
888 nameLabel->setText( " " + name+" " );
891 void MainInterface::setStatus( int status )
893 if( status == 1 ) // Playing
894 ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
896 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
898 updateSystrayMenu( status );
901 #define HELP_MENU N_("Menu")
902 #define HELP_PCH N_("Previous chapter")
903 #define HELP_NCH N_("Next chapter")
904 #define HELP_PTR N_("Previous track")
905 #define HELP_NTR N_("Next track")
907 void MainInterface::setNavigation( int navigation )
909 // 1 = chapter, 2 = title, 0 = no
910 if( navigation == 0 )
912 ui.discFrame->hide();
913 } else if( navigation == 1 ) {
914 ui.prevSectionButton->show();
915 ui.prevSectionButton->setToolTip( qfu(HELP_PCH) );
916 ui.nextSectionButton->show();
917 ui.nextSectionButton->setToolTip( qfu(HELP_NCH) );
918 ui.menuButton->show();
919 ui.discFrame->show();
921 ui.prevSectionButton->show();
922 ui.prevSectionButton->setToolTip( qfu(HELP_PCH) );
923 ui.nextSectionButton->show();
924 ui.nextSectionButton->setToolTip( qfu(HELP_NCH) );
925 ui.menuButton->hide();
926 ui.discFrame->show();
930 static bool b_my_volume;
932 void MainInterface::updateOnTimer()
934 /* \todo Make this event-driven */
935 advControls->enableInput( THEMIM->getIM()->hasInput() );
936 advControls->enableVideo( THEMIM->getIM()->hasVideo() );
938 if( intf_ShouldDie( p_intf ) )
940 QApplication::closeAllWindows();
941 QApplication::quit();
943 if( need_components_update )
945 doComponentsUpdate();
946 need_components_update = false;
949 audio_volume_t i_volume;
950 aout_VolumeGet( p_intf, &i_volume );
951 i_volume = (i_volume * 200 )/ AOUT_VOLUME_MAX ;
952 int i_gauge = ui.volumeSlider->value();
954 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
957 ui.volumeSlider->setValue( i_volume );
962 void MainInterface::closeEvent( QCloseEvent *e )
965 vlc_object_kill( p_intf );
968 void MainInterface::updateVolume( int sliderVolume )
972 int i_res = sliderVolume * AOUT_VOLUME_MAX /
973 (2*ui.volumeSlider->maximum() );
974 aout_VolumeSet( p_intf, i_res );
978 static int InteractCallback( vlc_object_t *p_this,
979 const char *psz_var, vlc_value_t old_val,
980 vlc_value_t new_val, void *param )
982 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
983 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
984 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
985 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
989 /*****************************************************************************
990 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
991 * We don't show the menu directly here because we don't want the
992 * caller to block for a too long time.
993 *****************************************************************************/
994 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
995 vlc_value_t old_val, vlc_value_t new_val, void *param )
997 intf_thread_t *p_intf = (intf_thread_t *)param;
999 if( p_intf->pf_show_dialog )
1001 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1002 new_val.b_bool, 0 );
1008 /*****************************************************************************
1009 * IntfShowCB: callback triggered by the intf-show playlist variable.
1010 *****************************************************************************/
1011 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1012 vlc_value_t old_val, vlc_value_t new_val, void *param )
1014 intf_thread_t *p_intf = (intf_thread_t *)param;
1015 //p_intf->p_sys->b_intf_show = VLC_TRUE;