]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/subtitles.cpp
ea6fdbaa4f4232f7c595d1027ec0889b92794c2a
[vlc] / modules / gui / wxwidgets / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 #include "wxwidgets.h"
36 #include <wx/combobox.h>
37 #include <wx/statline.h>
38
39 #ifndef wxRB_SINGLE
40 #   define wxRB_SINGLE 0
41 #endif
42
43 /*****************************************************************************
44  * Event Table.
45  *****************************************************************************/
46
47 /* IDs for the controls and the menu commands */
48 enum
49 {
50     FileBrowse_Event = wxID_HIGHEST,
51 };
52
53 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
54     /* Button events */
55     EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
56     EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
57     EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
58
59 END_EVENT_TABLE()
60
61 /*****************************************************************************
62  * Constructor.
63  *****************************************************************************/
64 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
65     wxDialog( _p_parent, -1, wxU(_("Subtitle options")),
66               wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
67 {
68     /* Initializations */
69     p_intf = _p_intf;
70     p_parent = _p_parent;
71     SetIcon( *p_intf->p_sys->p_icon );
72
73     /* Create a panel to put everything in */
74     wxPanel *panel = new wxPanel( this, -1 );
75     panel->SetAutoLayout( TRUE );
76     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
77     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
78
79     /* Create the subtitles file textctrl */
80     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
81     wxStaticBox *file_box = new wxStaticBox( panel, -1,
82                                              wxU(_("Subtitles file")) );
83     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
84                                                         wxHORIZONTAL );
85     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
86     if( !psz_subsfile ) psz_subsfile = strdup("");
87     file_combo = new wxComboBox( panel, -1, wxL2U(psz_subsfile),
88                                  wxPoint(20,25), wxSize(300, -1) );
89     if( psz_subsfile ) free( psz_subsfile );
90     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
91                                             wxU(_("Browse...")) );
92     file_sizer->Add( file_combo, 1, wxALL, 5 );
93     file_sizer->Add( browse_button, 0, wxALL, 5 );
94     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
95     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
96
97     /* Subtitles encoding */
98     encoding_combo = NULL;
99     module_config_t *p_item =
100         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
101     if( p_item )
102     {
103         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
104         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
105                                                 wxU(_("Subtitles encoding")) );
106         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
107                                                             wxHORIZONTAL );
108         wxStaticText *label =
109             new wxStaticText(panel, -1, wxU(p_item->psz_text));
110         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
111                                          wxDefaultPosition, wxDefaultSize,
112                                          0, NULL, wxCB_READONLY );
113
114         /* build a list of available options */
115         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
116              i_index++ )
117         {
118             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
119             if( p_item->psz_value && !strcmp( p_item->psz_value,
120                                               p_item->ppsz_list[i_index] ) )
121                 encoding_combo->SetSelection( i_index );
122         }
123
124         if( p_item->psz_value )
125         encoding_combo->SetValue( wxU(p_item->psz_value) );
126         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
127
128         enc_sizer->Add( label, 0, wxALL | wxALIGN_CENTER, 5 );
129         enc_sizer->Add( encoding_combo, 0, wxEXPAND | wxALL | wxALIGN_CENTER, 5 );
130         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
131         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
132     }
133
134     /* Misc Subtitles options */
135     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
136     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
137                                              wxU(_("Subtitles options")) );
138
139     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
140                                                          wxVERTICAL );
141
142     wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
143
144     /* Font size */
145     p_item =
146         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
147     if( p_item )
148     {
149         wxBoxSizer *size_sizer = new wxBoxSizer( wxHORIZONTAL );
150         wxStaticText *label =
151             new wxStaticText(panel, -1, wxU(p_item->psz_text));
152         size_combo = new wxComboBox( panel, -1, wxT(""),
153                                      wxDefaultPosition, wxDefaultSize,
154                                      0, NULL, wxCB_READONLY );
155
156         /* build a list of available options */
157         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
158         {
159             size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
160                                 (void *)p_item->pi_list[i_index] );
161             if( p_item->i_value == p_item->pi_list[i_index] )
162             {
163                 size_combo->SetSelection( i_index );
164                 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
165             }
166         }
167
168         size_combo->SetToolTip( wxU(p_item->psz_longtext) );
169
170         size_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
171         size_sizer->Add( size_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
172         grid_sizer->Add( size_sizer, 1, wxEXPAND | wxALL, 5 );
173     }
174
175     p_item =
176         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
177     if( p_item )
178     {
179         wxBoxSizer *align_sizer = new wxBoxSizer( wxHORIZONTAL );
180         wxStaticText *label =
181             new wxStaticText(panel, -1, wxU(p_item->psz_text));
182         align_combo = new wxComboBox( panel, -1, wxT(""),
183                                      wxDefaultPosition, wxDefaultSize,
184                                      0, NULL, wxCB_READONLY );
185
186         /* build a list of available options */
187         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
188         {
189             align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
190                                 (void *)p_item->pi_list[i_index] );
191             if( p_item->i_value == p_item->pi_list[i_index] )
192             {
193                 align_combo->SetSelection( i_index );
194                 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
195             }
196         }
197
198         align_combo->SetToolTip( wxU(p_item->psz_longtext) );
199
200         align_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
201         align_sizer->Add( align_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
202         grid_sizer->Add( align_sizer, 1, wxEXPAND | wxALL, 5 );
203     }
204
205     misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
206
207     grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
208
209     wxStaticText *label =
210         new wxStaticText(panel, -1, wxU(_("Frames per second")));
211
212     float f_fps = config_GetFloat( p_intf, "sub-fps" );
213     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
214     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
215     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
216                                    wxDefaultPosition, wxDefaultSize,
217                                    wxSP_ARROW_KEYS,
218                                    0, 16000, (int)f_fps );
219     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
220                "It will only work with MicroDVD and SubRIP subtitles.")) );
221     grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
222     grid_sizer->Add( fps_spinctrl, 0,wxALIGN_CENTER, 5 );
223
224
225     wxStaticText *label_delay =
226         new wxStaticText(panel, -1, wxU(_("Delay")));
227
228     int i_delay = config_GetInt( p_intf, "sub-delay" );
229     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
230     wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
231     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
232                                      wxDefaultPosition, wxDefaultSize,
233                                      wxSP_ARROW_KEYS,
234                                      -30000, 30000, i_delay );
235     delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
236
237     grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
238     grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
239
240     misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
241
242     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
243
244     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
245
246     /* Separation */
247     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
248
249     /* Create the buttons */
250     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
251     ok_button->SetDefault();
252     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
253                                             wxU(_("Cancel")) );
254
255     /* Place everything in sizers */
256     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
257     button_sizer->Add( ok_button, 0, wxALL, 5 );
258     button_sizer->Add( cancel_button, 0, wxALL, 5 );
259     button_sizer->Layout();
260
261     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
262     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
263                       wxALL, 5 );
264     panel_sizer->Layout();
265     panel->SetSizerAndFit( panel_sizer );
266     main_sizer->Add( panel, 1, wxGROW, 0 );
267     main_sizer->Layout();
268     SetSizerAndFit( main_sizer );
269 }
270
271 SubsFileDialog::~SubsFileDialog()
272 {
273 }
274
275 /*****************************************************************************
276  * Private methods.
277  *****************************************************************************/
278
279 /*****************************************************************************
280  * Events methods.
281  *****************************************************************************/
282 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
283 {
284     EndModal( wxID_OK );
285 }
286
287 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
288 {
289     EndModal( wxID_CANCEL );
290 }
291
292 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
293 {
294     wxFileDialog dialog( this, wxU(_("Open file")),
295                          wxT(""), wxT(""), wxT("*"), wxOPEN );
296
297     if( dialog.ShowModal() == wxID_OK )
298     {
299         file_combo->SetValue( dialog.GetPath() );
300     }
301 }