]> git.sesse.net Git - vlc/blob - modules/gui/qt4/qt4.cpp
Cosmetics:
[vlc] / modules / gui / qt4 / qt4.cpp
1 /*****************************************************************************
2  * qt4.cpp : QT4 interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
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 <QApplication>
24 #include "qt4.hpp"
25 #include "dialogs_provider.hpp"
26 #include "input_manager.hpp"
27 #include "main_interface.hpp"
28 #include "../../../share/vlc32x32.xpm"
29
30 /*****************************************************************************
31  * Local prototypes.
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 * );
39
40 /*****************************************************************************
41  * Module descriptor
42  *****************************************************************************/
43 vlc_module_begin();
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 );
50
51     set_program( "qvlc" );
52     add_shortcut("qt");
53
54     add_submodule();
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 );
59 vlc_module_end();
60
61
62 /*****************************************************************************
63  * Module callbacks
64  *****************************************************************************/
65 static int Open( vlc_object_t *p_this )
66 {
67     intf_thread_t *p_intf = (intf_thread_t *)p_this;
68     p_intf->pf_run = Run;
69     p_intf->p_sys = (intf_sys_t *)malloc(sizeof( intf_sys_t ) );
70     memset( p_intf->p_sys, 0, sizeof( intf_sys_t ) );
71
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 )
75         return VLC_EGENERIC;
76
77     p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
78
79     return VLC_SUCCESS;
80 }
81
82 static int OpenDialogs( vlc_object_t *p_this )
83 {
84     intf_thread_t *p_intf = (intf_thread_t *)p_this;
85     Open( p_this );
86     p_intf->pf_show_dialog = ShowDialog;
87     return VLC_SUCCESS;
88 }
89
90 static void Close( vlc_object_t *p_this )
91 {
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 );
96
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 );
100 }
101
102
103 /*****************************************************************************
104  * Initialize the interface or the dialogs provider
105  *****************************************************************************/
106 static void Run( intf_thread_t *p_intf )
107 {
108     if( p_intf->pf_show_dialog )
109     {
110         if( vlc_thread_create( p_intf, "QT dialogs", Init, 0, VLC_TRUE ) )
111         {
112             msg_Err( p_intf, "failed to create QT dialogs thread" );
113         }
114     }
115     else
116     {
117         Init( p_intf );
118     }
119 }
120
121 static void Init( intf_thread_t *p_intf )
122 {
123     char *argv[] = { "" };
124     int argc = 1;
125     Q_INIT_RESOURCE( vlc );
126
127     QApplication *app = new QApplication( argc, argv , true );
128     app->setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
129     p_intf->p_sys->p_app = app;
130
131     // Initialize timers
132     DialogsProvider::getInstance( p_intf );
133
134     /* Normal interface */
135     if( !p_intf->pf_show_dialog )
136     {
137         MainInterface *p_mi = new MainInterface( p_intf );
138         p_intf->p_sys->p_mi = p_mi;
139         p_mi->show();
140     }
141
142     if( p_intf->pf_show_dialog )
143         vlc_thread_ready( p_intf );
144
145     app->setQuitOnLastWindowClosed( false );
146     app->exec();
147     MainInputManager::killInstance();
148     delete p_intf->p_sys->p_mi;
149 }
150
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 )
156 {
157     DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
158     QApplication::postEvent( DialogsProvider::getInstance( p_intf ),
159                              static_cast<QEvent*>(event) );
160 }
161
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 )
169 {
170     intf_thread_t *p_intf = (intf_thread_t *)param;
171     ShowDialog( p_intf, INTF_DIALOG_POPUPMENU, new_val.b_bool, 0 );
172     return VLC_SUCCESS;
173 }