📄 preferences.cpp
字号:
/***************************************************************************** * preferences.cpp : wxWindows plugin for vlc ***************************************************************************** * Copyright (C) 2000-2004 VideoLAN * $Id: preferences.cpp 11508 2005-06-23 18:58:12Z zorglub $ * * Authors: Gildas Bazin <gbazin@netcourrier.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <errno.h> /* ENOMEM */#include <string.h> /* strerror() */#include <stdio.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc_config_cat.h>#include "wxwindows.h"#include "preferences_widgets.h"#include <wx/combobox.h>#include <wx/statline.h>#include <wx/clntdata.h>#include <wx/dynarray.h>#include <wx/imaglist.h>#include "bitmaps/type_net.xpm"#include "bitmaps/codec.xpm"#include "bitmaps/video.xpm"#include "bitmaps/type_playlist.xpm"#include "bitmaps/advanced.xpm"#include "bitmaps/intf.xpm"#include "bitmaps/audio.xpm"#ifndef wxRB_SINGLE# define wxRB_SINGLE 0#endif#define TYPE_CATEGORY 0#define TYPE_CATSUBCAT 1 /* Category with embedded subcategory */#define TYPE_SUBCATEGORY 2#define TYPE_MODULE 3/***************************************************************************** * Classes declarations. *****************************************************************************/class ConfigTreeData;class PrefsTreeCtrl : public wxTreeCtrl{public: PrefsTreeCtrl() { } PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf, PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer ); virtual ~PrefsTreeCtrl(); void ApplyChanges(); void CleanChanges();private: /* Event handlers (these functions should _not_ be virtual) */ void OnSelectTreeItem( wxTreeEvent& event ); void OnAdvanced( wxCommandEvent& event ); ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data ); DECLARE_EVENT_TABLE() intf_thread_t *p_intf; PrefsDialog *p_prefs_dialog; wxBoxSizer *p_sizer; wxWindow *p_parent; vlc_bool_t b_advanced; wxTreeItemId root_item; wxTreeItemId plugins_item;};WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);class PrefsPanel : public wxPanel{public: PrefsPanel() { } PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf, PrefsDialog *, ConfigTreeData* ); virtual ~PrefsPanel() {} void ApplyChanges(); void SwitchAdvanced( vlc_bool_t );private: intf_thread_t *p_intf; PrefsDialog *p_prefs_dialog; vlc_bool_t b_advanced; wxStaticText *hidden_text; wxBoxSizer *config_sizer; wxScrolledWindow *config_window; ArrayOfConfigControls config_array;};class ConfigTreeData : public wxTreeItemData{public: ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL; psz_help = NULL; } virtual ~ConfigTreeData() { if( panel ) delete panel; if( psz_name ) free( psz_name ); if( psz_help ) free( psz_help ); }; vlc_bool_t b_submodule; PrefsPanel *panel; wxBoxSizer *sizer; int i_object_id; int i_subcat_id; int i_type; char *psz_name; char *psz_help;};/***************************************************************************** * Event Table. *****************************************************************************//* IDs for the controls and the menu commands */enum{ Notebook_Event = wxID_HIGHEST, MRL_Event, ResetAll_Event, Advanced_Event,};BEGIN_EVENT_TABLE(PrefsDialog, wxFrame) /* Button events */ EVT_BUTTON(wxID_OK, PrefsDialog::OnOk) EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel) EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave) EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll) EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced) /* Don't destroy the window when the user closes it */ EVT_CLOSE(PrefsDialog::OnClose)END_EVENT_TABLE()// menu and control idsenum{ PrefsTree_Ctrl = wxID_HIGHEST};BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl) EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem) EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)END_EVENT_TABLE()/***************************************************************************** * Constructor. *****************************************************************************/PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent) : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition, wxSize(700,450), wxDEFAULT_FRAME_STYLE ){ /* Initializations */ p_intf = _p_intf; SetIcon( *p_intf->p_sys->p_icon ); /* Create a panel to put everything in */ wxPanel *panel = new wxPanel( this, -1 ); panel->SetAutoLayout( TRUE ); /* Create the preferences tree control */ wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL ); prefs_tree = new PrefsTreeCtrl( panel, p_intf, this, controls_sizer ); /* Separation */ wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK ); /* Create the buttons */ wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) ); ok_button->SetDefault(); wxButton *cancel_button = new wxButton( panel, wxID_CANCEL, wxU(_("Cancel")) ); wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) ); wxButton *reset_button = new wxButton( panel, ResetAll_Event, wxU(_("Reset All")) ); wxPanel *dummy_panel = new wxPanel( this, -1 ); wxCheckBox *advanced_checkbox = new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) ); if( config_GetInt( p_intf, "advanced" ) ) { advanced_checkbox->SetValue(TRUE); wxCommandEvent dummy_event; dummy_event.SetInt(TRUE); OnAdvanced( dummy_event ); } /* Place everything in sizers */ wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); button_sizer->Add( ok_button, 0, wxALL, 5 ); button_sizer->Add( cancel_button, 0, wxALL, 5 ); button_sizer->Add( save_button, 0, wxALL, 5 ); button_sizer->Add( reset_button, 0, wxALL, 5 ); button_sizer->Add( dummy_panel, 1, wxALL, 5 ); button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 0 ); button_sizer->Layout(); wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL ); panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 ); panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 ); panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM | wxALL | wxEXPAND, 5 ); panel_sizer->Layout(); panel->SetSizer( panel_sizer ); main_sizer->Add( panel, 1, wxEXPAND, 0 ); main_sizer->Layout(); SetSizer( main_sizer );}PrefsDialog::~PrefsDialog(){}/***************************************************************************** * Private methods. *****************************************************************************//***************************************************************************** * Events methods. *****************************************************************************/void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) ){ prefs_tree->ApplyChanges(); this->Hide(); prefs_tree->CleanChanges();}void PrefsDialog::OnClose( wxCloseEvent& WXUNUSED(event) ){ wxCommandEvent cevent; OnCancel(cevent);}void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) ){ this->Hide(); prefs_tree->CleanChanges();}void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) ){ prefs_tree->ApplyChanges(); config_SaveConfigFile( p_intf, NULL ); this->Hide();}void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) ){ wxMessageDialog dlg( this, wxU(_("Beware this will reset your VLC media player preferences.\n" "Are you sure you want to continue?")), wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE ); if ( dlg.ShowModal() == wxID_YES ) { /* TODO: need to reset all the controls */ config_ResetAll( p_intf ); prefs_tree->CleanChanges(); config_SaveConfigFile( p_intf, NULL ); }}void PrefsDialog::OnAdvanced( wxCommandEvent& event ){ wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event ); newevent.SetInt( event.GetInt() ); prefs_tree->AddPendingEvent( newevent );}/***************************************************************************** * PrefsTreeCtrl class definition. *****************************************************************************/PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, PrefsDialog *_p_prefs_dialog, wxBoxSizer *_p_sizer ) : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1), wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT | wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER ){ vlc_list_t *p_list = NULL;; module_t *p_module; module_config_t *p_item; int i_index, i_image=0; /* Initializations */ p_intf = _p_intf; p_prefs_dialog = _p_prefs_dialog; p_sizer = _p_sizer; p_parent = _p_parent; b_advanced = VLC_FALSE; root_item = AddRoot( wxT("") ); wxASSERT_MSG(root_item.IsOk(), "Could not add root item"); wxImageList *p_images = new wxImageList( 16,16,TRUE ); p_images->Add( wxIcon( audio_xpm ) ); p_images->Add( wxIcon( video_xpm ) ); p_images->Add( wxIcon( codec_xpm ) ); p_images->Add( wxIcon( type_net_xpm ) ); p_images->Add( wxIcon( advanced_xpm ) ); p_images->Add( wxIcon( type_playlist_xpm ) ); p_images->Add( wxIcon( intf_xpm ) ); AssignImageList( p_images ); /* List the plugins */ p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); if( !p_list ) return; /* Build the categories list */ for( i_index = 0; i_index < p_list->i_count; i_index++ ) { p_module = (module_t *)p_list->p_values[i_index].p_object; if( !strcmp( p_module->psz_object_name, "main" ) ) break; } if( i_index < p_list->i_count ) { wxTreeItemId current_item; char *psz_help; /* We found the main module */ /* Enumerate config categories and store a reference so we can * generate their config panel them when it is asked by the user. */ p_item = p_module->p_config; if( p_item ) do { ConfigTreeData *config_data;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -