]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
Fix playlist crasher and simplify a few things
[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     /* Connect the slider and the input manager */
51     // both ways 
52
53     /* Connect the display and the input manager */
54 }
55
56 MainInterface::~MainInterface()
57 {
58 }
59
60 void MainInterface::updateOnTimer()
61 {
62     if( p_intf->b_die )
63     {
64         QApplication::quit();
65     }
66     vlc_mutex_lock( &p_intf->change_lock );
67     if( p_input && p_input->b_dead )
68     {
69         vlc_object_release( p_input );
70         p_input = NULL;
71         emit inputChanged( NULL );
72     }
73
74     if( !p_input )
75     {
76         playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf,
77                                         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
78         assert( p_playlist );
79         PL_LOCK;
80
81         p_input = p_playlist->p_input;
82         if( p_input )
83         {
84             vlc_object_yield( p_input );
85             fprintf( stderr, "Sending input\n");
86             emit inputChanged( p_input );
87         }
88
89         PL_UNLOCK;
90         vlc_object_release( p_playlist );
91     }
92     vlc_mutex_unlock( &p_intf->change_lock );
93 }
94
95 void MainInterface::closeEvent( QCloseEvent *e )
96 {
97     hide();
98     p_intf->b_die = VLC_TRUE;
99 }