Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

subtitles.cpp

00001 /*****************************************************************************
00002  * subtitles.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2001 the VideoLAN team
00005  * $Id: subtitles.cpp 11981 2005-08-03 15:03:23Z xtophe $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <errno.h>                                                 /* ENOMEM */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034 
00035 #include "wxwidgets.h"
00036 #include <wx/combobox.h>
00037 #include <wx/statline.h>
00038 
00039 #ifndef wxRB_SINGLE
00040 #   define wxRB_SINGLE 0
00041 #endif
00042 
00043 /*****************************************************************************
00044  * Event Table.
00045  *****************************************************************************/
00046 
00047 /* IDs for the controls and the menu commands */
00048 enum
00049 {
00050     FileBrowse_Event = wxID_HIGHEST,
00051 };
00052 
00053 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
00054     /* Button events */
00055     EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
00056     EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
00057     EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
00058 
00059 END_EVENT_TABLE()
00060 
00061 /*****************************************************************************
00062  * Constructor.
00063  *****************************************************************************/
00064 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
00065     wxDialog( _p_parent, -1, wxU(_("Subtitle options")),
00066               wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
00067 {
00068     /* Initializations */
00069     p_intf = _p_intf;
00070     p_parent = _p_parent;
00071     SetIcon( *p_intf->p_sys->p_icon );
00072 
00073     /* Create a panel to put everything in */
00074     wxPanel *panel = new wxPanel( this, -1 );
00075     panel->SetAutoLayout( TRUE );
00076     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
00077     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
00078 
00079     /* Create the subtitles file textctrl */
00080     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
00081     wxStaticBox *file_box = new wxStaticBox( panel, -1,
00082                                              wxU(_("Subtitles file")) );
00083     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
00084                                                         wxHORIZONTAL );
00085     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
00086     if( !psz_subsfile ) psz_subsfile = strdup("");
00087     file_combo = new wxComboBox( panel, -1, wxL2U(psz_subsfile),
00088                                  wxPoint(20,25), wxSize(300, -1) );
00089     if( psz_subsfile ) free( psz_subsfile );
00090     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
00091                                             wxU(_("Browse...")) );
00092     file_sizer->Add( file_combo, 1, wxALL, 5 );
00093     file_sizer->Add( browse_button, 0, wxALL, 5 );
00094     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
00095     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
00096 
00097     /* Subtitles encoding */
00098     encoding_combo = NULL;
00099     module_config_t *p_item =
00100         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
00101     if( p_item )
00102     {
00103         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
00104         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
00105                                                 wxU(_("Subtitles encoding")) );
00106         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
00107                                                             wxHORIZONTAL );
00108         wxStaticText *label =
00109             new wxStaticText(panel, -1, wxU(p_item->psz_text));
00110         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
00111                                          wxDefaultPosition, wxDefaultSize,
00112                                          0, NULL, wxCB_READONLY );
00113 
00114         /* build a list of available options */
00115         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
00116              i_index++ )
00117         {
00118             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
00119             if( p_item->psz_value && !strcmp( p_item->psz_value,
00120                                               p_item->ppsz_list[i_index] ) )
00121                 encoding_combo->SetSelection( i_index );
00122         }
00123 
00124         if( p_item->psz_value )
00125         encoding_combo->SetValue( wxU(p_item->psz_value) );
00126         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
00127 
00128         enc_sizer->Add( label, 0, wxALL | wxALIGN_CENTER, 5 );
00129         enc_sizer->Add( encoding_combo, 0, wxEXPAND | wxALL | wxALIGN_CENTER, 5 );
00130         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
00131         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
00132     }
00133 
00134     /* Misc Subtitles options */
00135     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
00136     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
00137                                              wxU(_("Subtitles options")) );
00138 
00139     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
00140                                                          wxVERTICAL );
00141 
00142     wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
00143 
00144     /* Font size */
00145     p_item =
00146         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
00147     if( p_item )
00148     {
00149         wxBoxSizer *size_sizer = new wxBoxSizer( wxHORIZONTAL );
00150         wxStaticText *label =
00151             new wxStaticText(panel, -1, wxU(p_item->psz_text));
00152         size_combo = new wxComboBox( panel, -1, wxT(""),
00153                                      wxDefaultPosition, wxDefaultSize,
00154                                      0, NULL, wxCB_READONLY );
00155 
00156         /* build a list of available options */
00157         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
00158         {
00159             size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
00160                                 (void *)p_item->pi_list[i_index] );
00161             if( p_item->i_value == p_item->pi_list[i_index] )
00162             {
00163                 size_combo->SetSelection( i_index );
00164                 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
00165             }
00166         }
00167 
00168         size_combo->SetToolTip( wxU(p_item->psz_longtext) );
00169 
00170         size_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
00171         size_sizer->Add( size_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
00172         grid_sizer->Add( size_sizer, 1, wxEXPAND | wxALL, 5 );
00173     }
00174 
00175     p_item =
00176         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
00177     if( p_item )
00178     {
00179         wxBoxSizer *align_sizer = new wxBoxSizer( wxHORIZONTAL );
00180         wxStaticText *label =
00181             new wxStaticText(panel, -1, wxU(p_item->psz_text));
00182         align_combo = new wxComboBox( panel, -1, wxT(""),
00183                                      wxDefaultPosition, wxDefaultSize,
00184                                      0, NULL, wxCB_READONLY );
00185 
00186         /* build a list of available options */
00187         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
00188         {
00189             align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
00190                                 (void *)p_item->pi_list[i_index] );
00191             if( p_item->i_value == p_item->pi_list[i_index] )
00192             {
00193                 align_combo->SetSelection( i_index );
00194                 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
00195             }
00196         }
00197 
00198         align_combo->SetToolTip( wxU(p_item->psz_longtext) );
00199 
00200         align_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
00201         align_sizer->Add( align_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
00202         grid_sizer->Add( align_sizer, 1, wxEXPAND | wxALL, 5 );
00203     }
00204 
00205     misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
00206 
00207     grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
00208 
00209     wxStaticText *label =
00210         new wxStaticText(panel, -1, wxU(_("Frames per second")));
00211 
00212     float f_fps = config_GetFloat( p_intf, "sub-fps" );
00213     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
00214     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
00215     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
00216                                    wxDefaultPosition, wxDefaultSize,
00217                                    wxSP_ARROW_KEYS,
00218                                    0, 16000, (int)f_fps );
00219     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
00220                "It will only work with MicroDVD and SubRIP subtitles.")) );
00221     grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
00222     grid_sizer->Add( fps_spinctrl, 0,wxALIGN_CENTER, 5 );
00223 
00224 
00225     wxStaticText *label_delay =
00226         new wxStaticText(panel, -1, wxU(_("Delay")));
00227 
00228     int i_delay = config_GetInt( p_intf, "sub-delay" );
00229     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
00230     wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
00231     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
00232                                      wxDefaultPosition, wxDefaultSize,
00233                                      wxSP_ARROW_KEYS,
00234                                      -30000, 30000, i_delay );
00235     delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
00236 
00237     grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
00238     grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
00239 
00240     misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
00241 
00242     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
00243 
00244     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
00245 
00246     /* Separation */
00247     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
00248 
00249     /* Create the buttons */
00250     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
00251     ok_button->SetDefault();
00252     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
00253                                             wxU(_("Cancel")) );
00254 
00255     /* Place everything in sizers */
00256     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
00257     button_sizer->Add( ok_button, 0, wxALL, 5 );
00258     button_sizer->Add( cancel_button, 0, wxALL, 5 );
00259     button_sizer->Layout();
00260 
00261     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
00262     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
00263                       wxALL, 5 );
00264     panel_sizer->Layout();
00265     panel->SetSizerAndFit( panel_sizer );
00266     main_sizer->Add( panel, 1, wxGROW, 0 );
00267     main_sizer->Layout();
00268     SetSizerAndFit( main_sizer );
00269 }
00270 
00271 SubsFileDialog::~SubsFileDialog()
00272 {
00273 }
00274 
00275 /*****************************************************************************
00276  * Private methods.
00277  *****************************************************************************/
00278 
00279 /*****************************************************************************
00280  * Events methods.
00281  *****************************************************************************/
00282 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
00283 {
00284     EndModal( wxID_OK );
00285 }
00286 
00287 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
00288 {
00289     EndModal( wxID_CANCEL );
00290 }
00291 
00292 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
00293 {
00294     wxFileDialog dialog( this, wxU(_("Open file")),
00295                          wxT(""), wxT(""), wxT("*"), wxOPEN );
00296 
00297     if( dialog.ShowModal() == wxID_OK )
00298     {
00299         file_combo->SetValue( dialog.GetPath() );
00300     }
00301 }

Generated on Tue Dec 20 10:14:46 2005 for vlc-0.8.4a by  doxygen 1.4.2