1 /*****************************************************************************
2 * qt4.cpp : QT4 interface
3 ****************************************************************************
4 * Copyright (C) 2006 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. *****************************************************************************/
23 #include <QApplication>
25 #include "dialogs_provider.hpp"
26 #include "input_manager.hpp"
27 #include "main_interface.hpp"
28 #include "../../../share/vlc32x32.xpm"
30 /*****************************************************************************
32 *****************************************************************************/
33 static int Open ( vlc_object_t * );
34 static void Close ( vlc_object_t * );
35 static int OpenDialogs ( vlc_object_t * );
36 static void Run ( intf_thread_t * );
37 static void Init ( intf_thread_t * );
38 static void ShowDialog ( intf_thread_t *, int, int, intf_dialog_args_t * );
40 /*****************************************************************************
42 *****************************************************************************/
44 set_shortname( (char*)"QT" );
45 set_description( (char*)_("QT interface") );
46 set_category( CAT_INTERFACE) ;
47 set_subcategory( SUBCAT_INTERFACE_MAIN );
48 set_capability( "interface", 100 );
49 set_callbacks( Open, Close );
51 set_program( "qvlc" );
55 set_description( "Dialogs provider" );
56 set_capability( "dialogs provider", 51 );
57 add_bool( "qt-always-video", VLC_FALSE, NULL, "", "", VLC_TRUE );
58 set_callbacks( OpenDialogs, Close );
62 /*****************************************************************************
64 *****************************************************************************/
65 static int Open( vlc_object_t *p_this )
67 intf_thread_t *p_intf = (intf_thread_t *)p_this;
69 p_intf->p_sys = (intf_sys_t *)malloc(sizeof( intf_sys_t ) );
70 memset( p_intf->p_sys, 0, sizeof( intf_sys_t ) );
72 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
73 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
74 if( !p_intf->p_sys->p_playlist )
77 p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
82 static int OpenDialogs( vlc_object_t *p_this )
84 intf_thread_t *p_intf = (intf_thread_t *)p_this;
86 p_intf->pf_show_dialog = ShowDialog;
90 static void Close( vlc_object_t *p_this )
92 intf_thread_t *p_intf = (intf_thread_t *)p_this;
93 vlc_mutex_lock( &p_intf->object_lock );
94 p_intf->b_dead = VLC_TRUE;
95 vlc_mutex_unlock( &p_intf->object_lock );
97 vlc_object_release( p_intf->p_sys->p_playlist );
98 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
99 free( p_intf->p_sys );
103 /*****************************************************************************
104 * Initialize the interface or the dialogs provider
105 *****************************************************************************/
106 static void Run( intf_thread_t *p_intf )
108 if( p_intf->pf_show_dialog )
110 if( vlc_thread_create( p_intf, "QT dialogs", Init, 0, VLC_TRUE ) )
112 msg_Err( p_intf, "failed to create QT dialogs thread" );
121 static void Init( intf_thread_t *p_intf )
123 char *argv[] = { "" };
125 Q_INIT_RESOURCE( vlc );
127 QApplication *app = new QApplication( argc, argv , true );
128 app->setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
129 p_intf->p_sys->p_app = app;
132 DialogsProvider::getInstance( p_intf );
134 /* Normal interface */
135 if( !p_intf->pf_show_dialog )
137 MainInterface *p_mi = new MainInterface( p_intf );
138 p_intf->p_sys->p_mi = p_mi;
142 if( p_intf->pf_show_dialog )
143 vlc_thread_ready( p_intf );
145 app->setQuitOnLastWindowClosed( false );
147 MainInputManager::killInstance();
148 delete p_intf->p_sys->p_mi;
151 /*****************************************************************************
152 * Callback to show a dialog
153 *****************************************************************************/
154 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
155 intf_dialog_args_t *p_arg )
157 DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
158 QApplication::postEvent( DialogsProvider::getInstance( p_intf ),
159 static_cast<QEvent*>(event) );
162 /*****************************************************************************
163 * PopupMenuCB: callback to show the popupmenu.
164 * We don't show the menu directly here because we don't want the
165 * caller to block for a too long time.
166 *****************************************************************************/
167 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
168 vlc_value_t old_val, vlc_value_t new_val, void *param )
170 intf_thread_t *p_intf = (intf_thread_t *)param;
171 ShowDialog( p_intf, INTF_DIALOG_POPUPMENU, new_val.b_bool, 0 );