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

iteminfo.cpp

00001 /*****************************************************************************
00002  * iteminfo.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: iteminfo.cpp 11981 2005-08-03 15:03:23Z xtophe $
00006  *
00007  * Authors: Clément Stenac <[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 
00034 #include <wx/combobox.h>
00035 #include <wx/statline.h>
00036 
00037 #include <vlc/intf.h>
00038 
00039 #include "wxwidgets.h"
00040 
00041 #ifndef wxRB_SINGLE
00042 #   define wxRB_SINGLE 0
00043 #endif
00044 
00045 /*****************************************************************************
00046  * Event Table.
00047  *****************************************************************************/
00048 
00049 /* IDs for the controls and the menu commands */
00050 enum
00051 {
00052     Uri_Event,
00053     Name_Event,
00054     Enabled_Event,
00055 };
00056 
00057 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
00058     /* Button events */
00059     EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
00060     EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
00061 
00062 END_EVENT_TABLE()
00063 
00064 /*****************************************************************************
00065  * Constructor.
00066  *****************************************************************************/
00067 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
00068                                 playlist_item_t *_p_item,
00069                                 wxWindow* _p_parent ):
00070     wxDialog( _p_parent, -1, wxU(_("Playlist item info")),
00071              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
00072 {
00073     /* Initializations */
00074     p_intf = _p_intf;
00075     p_parent = _p_parent;
00076     p_item = _p_item;
00077     SetIcon( *p_intf->p_sys->p_icon );
00078 
00079     /* Create a panel to put everything in */
00080     wxPanel *panel = new wxPanel( this, -1 );
00081     panel->SetAutoLayout( TRUE );
00082 
00083     /* Create the standard info panel */
00084     wxPanel *info_panel = InfoPanel( panel );
00085 
00086     /* Separation */
00087     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
00088 
00089     /* Create the buttons */
00090     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
00091     ok_button->SetDefault();
00092     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
00093                                             wxU(_("Cancel")) );
00094 
00095     /* Place everything in sizers */
00096     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
00097     button_sizer->Add( ok_button, 0, wxALL, 5 );
00098     button_sizer->Add( cancel_button, 0, wxALL, 5 );
00099     button_sizer->Layout();
00100     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
00101     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
00102     panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
00103     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
00104     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
00105                       wxALL, 5 );
00106     panel_sizer->Layout();
00107     panel->SetSizerAndFit( panel_sizer );
00108     main_sizer->Add( panel, 1, wxGROW, 0 );
00109     main_sizer->Layout();
00110     SetSizerAndFit( main_sizer );
00111 }
00112 
00113 ItemInfoDialog::~ItemInfoDialog()
00114 {
00115 }
00116 
00117 /*****************************************************************************
00118  * Private methods.
00119  *****************************************************************************/
00120 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
00121 {
00122     wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
00123                                   wxDefaultSize );
00124     info_panel->SetAutoLayout( TRUE );
00125     wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
00126 
00127     /* Create a box to surround the controls */
00128     wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
00129                                    wxU(_("Item Info")) );
00130 
00131     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
00132                                                           wxVERTICAL );
00133 
00134     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,3,20);
00135     /* URI Textbox */
00136     wxStaticText *uri_label =
00137            new wxStaticText( info_panel, -1, wxU(_("URI")) );
00138 
00139     uri_text = new wxTextCtrl( info_panel, Uri_Event,
00140         wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
00141         wxTE_PROCESS_ENTER );
00142 
00143     sizer->Add( uri_label, 0 , wxALIGN_LEFT |wxALL , 5 );
00144     sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
00145 
00146     /* Name Textbox */
00147     wxStaticText *name_label =
00148            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
00149 
00150     name_text = new wxTextCtrl( info_panel, Uri_Event,
00151         wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
00152         wxTE_PROCESS_ENTER );
00153 
00154     sizer->Add( name_label, 0 , wxALIGN_LEFT |wxALL , 5  );
00155     sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
00156 
00157     /* Treeview */
00158     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
00159                                 wxSize(220,200),
00160                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
00161                                 wxTR_HIDE_ROOT );
00162 
00163     sizer->Layout();
00164     box_sizer->Add( sizer, 0, wxEXPAND, 5 );
00165     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
00166     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
00167 
00168     info_panel->SetSizer( info_sizer );
00169     info_sizer->Layout();
00170     info_sizer->SetSizeHints( info_panel );
00171 
00172     UpdateInfo();
00173 
00174     return info_panel;
00175 }
00176 
00177 void ItemInfoDialog::UpdateInfo()
00178 {
00179     if( !info_root )
00180     {
00181        info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
00182     }
00183 
00184     /* Rebuild the tree */
00185     for( int i = 0; i< p_item->input.i_categories ; i++)
00186     {
00187         wxTreeItemId cat = info_tree->AppendItem( info_root,
00188                             wxU( p_item->input.pp_categories[i]->psz_name) );
00189 
00190         for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
00191         {
00192            info_tree->AppendItem( cat , (wxString)
00193                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
00194                wxT(": ") +
00195                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
00196         }
00197 
00198         info_tree->Expand( cat );
00199     }
00200 }
00201 
00202 /*****************************************************************************
00203  * Events methods.
00204  *****************************************************************************/
00205 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
00206 {
00207     vlc_mutex_lock( &p_item->input.lock );
00208     p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
00209     p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
00210     vlc_mutex_unlock( &p_item->input.lock );
00211     EndModal( wxID_OK );
00212 }
00213 
00214 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
00215 {
00216     EndModal( wxID_CANCEL );
00217 }

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