1 /*****************************************************************************
2 * subtitles.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #include "dialogs/subtitles.hpp"
25 #include <wx/combobox.h>
26 #include <wx/statline.h>
27 #include <wx/spinctrl.h>
30 # define wxRB_SINGLE 0
33 /*****************************************************************************
35 *****************************************************************************/
37 /* IDs for the controls and the menu commands */
40 FileBrowse_Event = wxID_HIGHEST,
43 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
45 EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
46 EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
47 EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
51 /*****************************************************************************
53 *****************************************************************************/
54 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
55 wxDialog( _p_parent, -1, wxU(_("Subtitle options")),
56 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
61 SetIcon( *p_intf->p_sys->p_icon );
63 /* Create a panel to put everything in */
64 wxPanel *panel = new wxPanel( this, -1 );
65 panel->SetAutoLayout( TRUE );
66 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
67 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
70 /* Create the subtitles file textctrl */
71 wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
72 wxStaticBox *file_box = new wxStaticBox( panel, -1,
73 wxU(_("Subtitles file")) );
74 wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
76 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
77 if( !psz_subsfile ) psz_subsfile = strdup("");
78 file_combo = new wxComboBox( panel, -1, wxL2U(psz_subsfile),
79 wxPoint(20,25), wxSize(300, -1) );
80 if( psz_subsfile ) free( psz_subsfile );
81 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
82 wxU(_("Browse...")) );
83 file_sizer->Add( file_combo, 1, wxALL, 5 );
84 file_sizer->Add( browse_button, 0, wxALL, 5 );
85 file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
86 panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
89 /* Subtitles encoding */
90 encoding_combo = NULL;
91 module_config_t *p_item =
92 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
95 wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
96 wxStaticBox *enc_box = new wxStaticBox( panel, -1,
97 wxU(_("Subtitles encoding")) );
98 wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
100 wxStaticText *label =
101 new wxStaticText(panel, -1, wxU(p_item->psz_text));
102 encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
103 wxDefaultPosition, wxDefaultSize,
104 0, NULL, wxCB_READONLY );
106 /* build a list of available options */
107 for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
110 encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
111 if( p_item->psz_value && !strcmp( p_item->psz_value,
112 p_item->ppsz_list[i_index] ) )
113 encoding_combo->SetSelection( i_index );
116 if( p_item->psz_value )
117 encoding_combo->SetValue( wxU(p_item->psz_value) );
118 encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
120 enc_sizer->Add( label, 0, wxALL | wxALIGN_CENTER, 5 );
121 enc_sizer->Add( encoding_combo, 0, wxEXPAND | wxALL | wxALIGN_CENTER, 5 );
122 enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
123 panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
126 /* Misc Subtitles options */
127 wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
128 wxStaticBox *misc_box = new wxStaticBox( panel, -1,
129 wxU(_("Subtitles options")) );
131 wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
134 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
138 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
141 wxBoxSizer *size_sizer = new wxBoxSizer( wxHORIZONTAL );
142 wxStaticText *label =
143 new wxStaticText(panel, -1, wxU(p_item->psz_text));
144 size_combo = new wxComboBox( panel, -1, wxT(""),
145 wxDefaultPosition, wxDefaultSize,
146 0, NULL, wxCB_READONLY );
148 /* build a list of available options */
149 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
151 size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
152 (void *)p_item->pi_list[i_index] );
153 if( p_item->i_value == p_item->pi_list[i_index] )
155 size_combo->SetSelection( i_index );
156 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
160 size_combo->SetToolTip( wxU(p_item->psz_longtext) );
162 size_sizer->Add( label, 0, wxRIGHT | wxALIGN_CENTER, 5 );
163 size_sizer->Add( size_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
164 grid_sizer->Add( size_sizer, 1, wxEXPAND | wxALL, 5 );
168 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
171 wxBoxSizer *align_sizer = new wxBoxSizer( wxHORIZONTAL );
172 wxStaticText *label =
173 new wxStaticText(panel, -1, wxU(p_item->psz_text));
174 align_combo = new wxComboBox( panel, -1, wxT(""),
175 wxDefaultPosition, wxDefaultSize,
176 0, NULL, wxCB_READONLY );
178 /* build a list of available options */
179 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
181 align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
182 (void *)p_item->pi_list[i_index] );
183 if( p_item->i_value == p_item->pi_list[i_index] )
185 align_combo->SetSelection( i_index );
186 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
190 align_combo->SetToolTip( wxU(p_item->psz_longtext) );
192 align_sizer->Add( label, 0, wxRIGHT | wxALIGN_CENTER, 5 );
193 align_sizer->Add( align_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
194 grid_sizer->Add( align_sizer, 1, wxEXPAND | wxALL, 5 );
197 misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
199 grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
201 wxStaticText *label =
202 new wxStaticText(panel, -1, wxU(_("Frames per second")));
204 float f_fps = config_GetFloat( p_intf, "sub-fps" );
205 /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
206 wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
207 fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
208 wxDefaultPosition, wxDefaultSize,
210 0, 16000, (int)f_fps );
211 fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
212 "It will only work with MicroDVD and SubRIP subtitles.")) );
213 grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
214 grid_sizer->Add( fps_spinctrl, 0,wxALIGN_CENTER, 5 );
217 wxStaticText *label_delay =
218 new wxStaticText(panel, -1, wxU(_("Delay")));
220 int i_delay = config_GetInt( p_intf, "sub-delay" );
221 /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
222 wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
223 delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
224 wxDefaultPosition, wxDefaultSize,
226 -30000, 30000, i_delay );
227 delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
229 grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
230 grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
232 misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
234 misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
236 panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
239 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
241 /* Create the buttons */
242 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
243 ok_button->SetDefault();
244 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
247 /* Place everything in sizers */
248 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
249 button_sizer->Add( ok_button, 0, wxALL, 5 );
250 button_sizer->Add( cancel_button, 0, wxALL, 5 );
251 button_sizer->Layout();
253 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
254 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
256 panel_sizer->Layout();
257 panel->SetSizerAndFit( panel_sizer );
258 main_sizer->Add( panel, 1, wxGROW, 0 );
259 main_sizer->Layout();
260 SetSizerAndFit( main_sizer );
263 SubsFileDialog::~SubsFileDialog()
267 /*****************************************************************************
269 *****************************************************************************/
271 /*****************************************************************************
273 *****************************************************************************/
274 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
279 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
281 EndModal( wxID_CANCEL );
284 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
287 wxFileDialog dialog( this, wxU(_("Open file")),
288 wxT(""), wxT(""), wxT("*"), wxOPEN );
290 if( dialog.ShowModal() == wxID_OK )
292 file_combo->SetValue( dialog.GetPath() );