]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/subtitles.cpp
c6061ffb46c3664f16a6bd085a0a46ce2167e3c0
[vlc] / modules / gui / wxwindows / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: subtitles.cpp,v 1.9 2003/12/22 15:42:44 gbazin Exp $
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 "wxwindows.h"
36 #include <wx/textctrl.h>
37 #include <wx/combobox.h>
38 #include <wx/spinctrl.h>
39 #include <wx/statline.h>
40
41 #ifndef wxRB_SINGLE
42 #   define wxRB_SINGLE 0
43 #endif
44
45 /*****************************************************************************
46  * Event Table.
47  *****************************************************************************/
48
49 /* IDs for the controls and the menu commands */
50 enum
51 {
52     FileBrowse_Event = wxID_HIGHEST,
53 };
54
55 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
56     /* Button events */
57     EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
58     EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
59     EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
60
61 END_EVENT_TABLE()
62
63 /*****************************************************************************
64  * Constructor.
65  *****************************************************************************/
66 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
67     wxDialog( _p_parent, -1, wxU(_("Open subtitles file")),
68               wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
69 {
70     /* Initializations */
71     p_intf = _p_intf;
72     p_parent = _p_parent;
73     SetIcon( *p_intf->p_sys->p_icon );
74
75     /* Create a panel to put everything in */
76     wxPanel *panel = new wxPanel( this, -1 );
77     panel->SetAutoLayout( TRUE );
78     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
79     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
80
81     /* Create the subtitles file textctrl */
82     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
83     wxStaticBox *file_box = new wxStaticBox( panel, -1,
84                                              wxU(_("Subtitles file")) );
85     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
86                                                         wxHORIZONTAL );
87     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
88     file_combo = new wxComboBox( panel, -1,
89                                  psz_subsfile ? wxL2U(psz_subsfile) : wxT(""),
90                                  wxPoint(20,25), wxSize(300, -1), 0, NULL );
91     if( psz_subsfile ) free( psz_subsfile );
92     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
93                                             wxU(_("Browse...")) );
94     file_sizer->Add( file_combo, 1, wxALL, 5 );
95     file_sizer->Add( browse_button, 0, wxALL, 5 );
96     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
97     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
98
99     /* Subtitles encoding */
100     encoding_combo = NULL;
101     module_config_t *p_item =
102         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
103     if( p_item )
104     {
105         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
106         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
107                                                 wxU(_("Subtitles encoding")) );
108         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
109                                                             wxHORIZONTAL );
110         wxStaticText *label =
111             new wxStaticText(panel, -1, wxU(p_item->psz_text));
112         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
113                                          wxDefaultPosition, wxDefaultSize,
114                                          0, NULL, wxCB_READONLY );
115
116         /* build a list of available options */
117         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
118              i_index++ )
119         {
120             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
121             if( p_item->psz_value && !strcmp( p_item->psz_value,
122                                               p_item->ppsz_list[i_index] ) )
123                 encoding_combo->SetSelection( i_index );
124         }
125
126         if( p_item->psz_value )
127         encoding_combo->SetValue( wxU(p_item->psz_value) );
128         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
129
130         enc_sizer->Add( label, 0, wxALL, 5 );
131         enc_sizer->Add( encoding_combo, 0, wxALL, 5 );
132         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
133         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
134     }
135
136     /* Misc Subtitles options */
137     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
138     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
139                                              wxU(_("Subtitles options")) );
140     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
141                                                          wxHORIZONTAL );
142     wxStaticText *label =
143         new wxStaticText(panel, -1, wxU(_("Delay subtitles (in 1/10s)")));
144     int i_delay = config_GetInt( p_intf, "sub-delay" );
145     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
146     wxString format_delay(wxString::Format(wxT("%d"), i_delay));
147     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
148                                      wxDefaultPosition, wxDefaultSize,
149                                      wxSP_ARROW_KEYS,
150                                      -650000, 650000, i_delay );
151
152     misc_sizer->Add( label, 0, wxALL, 5 );
153     misc_sizer->Add( delay_spinctrl, 0, wxALL, 5 );
154
155     label = new wxStaticText(panel, -1, wxU(_("Frames per second")));
156
157     float f_fps = config_GetFloat( p_intf, "sub-fps" );
158     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
159     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
160     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
161                                    wxDefaultPosition, wxDefaultSize,
162                                    wxSP_ARROW_KEYS,
163                                    0, 16000, (int)f_fps );
164     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
165                               "It will only work with MicroDVD subtitles.")) );
166     misc_sizer->Add( label, 0, wxALL, 5 );
167     misc_sizer->Add( fps_spinctrl, 0, wxALL, 5 );
168
169     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
170     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
171
172     /* Separation */
173     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
174
175     /* Create the buttons */
176     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
177     ok_button->SetDefault();
178     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
179                                             wxU(_("Cancel")) );
180
181     /* Place everything in sizers */
182     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
183     button_sizer->Add( ok_button, 0, wxALL, 5 );
184     button_sizer->Add( cancel_button, 0, wxALL, 5 );
185     button_sizer->Layout();
186
187     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
188     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
189                       wxALL, 5 );
190     panel_sizer->Layout();
191     panel->SetSizerAndFit( panel_sizer );
192     main_sizer->Add( panel, 1, wxGROW, 0 );
193     main_sizer->Layout();
194     SetSizerAndFit( main_sizer );
195 }
196
197 SubsFileDialog::~SubsFileDialog()
198 {
199 }
200
201 /*****************************************************************************
202  * Private methods.
203  *****************************************************************************/
204
205 /*****************************************************************************
206  * Events methods.
207  *****************************************************************************/
208 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
209 {
210     EndModal( wxID_OK );
211 }
212
213 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
214 {
215     EndModal( wxID_CANCEL );
216 }
217
218 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
219 {
220     wxFileDialog dialog( this, wxU(_("Open file")),
221                          wxT(""), wxT(""), wxT("*"), wxOPEN );
222
223     if( dialog.ShowModal() == wxID_OK )
224     {
225         file_combo->SetValue( dialog.GetPath() );
226     }
227 }