]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
89cc9e81e12f07f97689fa3e6bb211f3a57f1aed
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_inteface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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
23 #include "main_interface.hpp"
24 #include "input_manager.hpp"
25 #include "dialogs_provider.hpp"
26 #include <QCloseEvent>
27 #include <assert.h>
28
29 MainInterface::MainInterface( intf_thread_t *_p_intf ) :
30                             QWidget( NULL ), p_intf( _p_intf)
31 {
32     fprintf( stderr, "QT Main interface\n" );
33
34     /* Init UI */
35
36     /* Init input manager */
37     p_input = NULL;
38     main_input_manager = new InputManager( this, p_intf );
39 }
40
41 void MainInterface::init()
42 {
43     /* Get timer updates */
44     QObject::connect( DialogsProvider::getInstance(NULL)->fixed_timer,
45                       SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
46     /* Tell input manager about the input changes */
47     QObject::connect( this, SIGNAL( inputChanged( input_thread_t * ) ),
48                    main_input_manager, SLOT( setInput( input_thread_t * ) ) );
49
50 }
51
52 MainInterface::~MainInterface()
53 {
54 }
55
56 void MainInterface::updateOnTimer()
57 {
58     if( p_intf->b_die )
59     {
60         QApplication::quit();
61     }
62     vlc_mutex_lock( &p_intf->change_lock );
63     if( p_input && p_input->b_dead )
64     {
65         vlc_object_release( p_input );
66         p_input = NULL;
67         emit inputChanged( NULL );
68     }
69
70     if( !p_input )
71     {
72         playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf,
73                                         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
74         assert( p_playlist );
75         PL_LOCK;
76
77         p_input = p_playlist->p_input;
78         if( p_input )
79         {
80             vlc_object_yield( p_input );
81             fprintf( stderr, "Sending input\n");
82             emit inputChanged( p_input );
83         }
84
85         PL_UNLOCK;
86         vlc_object_release( p_playlist );
87     }
88     vlc_mutex_unlock( &p_intf->change_lock );
89 }
90
91 void MainInterface::closeEvent( QCloseEvent *e )
92 {
93     hide();
94     p_intf->b_die = VLC_TRUE;
95 }