1 /*****************************************************************************
2 * iteminfo.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.org>
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 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #include <wx/combobox.h>
35 #include <wx/statline.h>
39 #include "wxwindows.h"
42 # define wxRB_SINGLE 0
45 /*****************************************************************************
47 *****************************************************************************/
49 /* IDs for the controls and the menu commands */
59 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
61 EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
62 EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
63 /* Events generated by the panels */
64 EVT_BUTTON( New_Event, ItemInfoDialog::OnNewGroup)
68 /*****************************************************************************
70 *****************************************************************************/
71 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
72 playlist_item_t *_p_item,
73 wxWindow* _p_parent ):
74 wxDialog( _p_parent, -1, wxU(_("Playlist item info")),
75 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
81 SetIcon( *p_intf->p_sys->p_icon );
83 /* Create a panel to put everything in */
84 wxPanel *panel = new wxPanel( this, -1 );
85 panel->SetAutoLayout( TRUE );
87 /* Create the standard info panel */
88 wxPanel *info_panel = InfoPanel( panel );
90 /* Create the group panel */
91 wxPanel *group_panel = GroupPanel( panel );
94 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
96 /* Create the buttons */
97 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
98 ok_button->SetDefault();
99 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
102 /* Place everything in sizers */
103 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
104 button_sizer->Add( ok_button, 0, wxALL, 5 );
105 button_sizer->Add( cancel_button, 0, wxALL, 5 );
106 button_sizer->Layout();
107 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
108 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
109 panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
110 panel_sizer->Add( group_panel, 0, wxEXPAND | wxALL, 5 );
111 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
112 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
114 panel_sizer->Layout();
115 panel->SetSizerAndFit( panel_sizer );
116 main_sizer->Add( panel, 1, wxGROW, 0 );
117 main_sizer->Layout();
118 SetSizerAndFit( main_sizer );
121 ItemInfoDialog::~ItemInfoDialog()
125 /*****************************************************************************
127 *****************************************************************************/
128 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
130 wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
132 info_panel->SetAutoLayout( TRUE );
133 wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
135 /* Create a box to surround the controls */
136 wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
137 wxU(_("Item Info")) );
139 wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
143 wxStaticText *uri_label =
144 new wxStaticText( info_panel, -1, wxU(_("URI")) );
146 uri_text = new wxTextCtrl( info_panel, Uri_Event,
147 wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
148 wxTE_PROCESS_ENTER );
150 wxBoxSizer *uri_sizer = new wxBoxSizer( wxHORIZONTAL );
152 uri_sizer->Add( uri_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
153 uri_sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
155 box_sizer->Add( uri_sizer, 1, wxEXPAND , 5);
158 wxStaticText *name_label =
159 new wxStaticText( info_panel, -1, wxU(_("Name")) );
161 name_text = new wxTextCtrl( info_panel, Uri_Event,
162 wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
163 wxTE_PROCESS_ENTER );
165 wxBoxSizer *name_sizer = new wxBoxSizer( wxHORIZONTAL );
167 name_sizer->Add( name_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
168 name_sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
169 name_sizer->Layout();
170 box_sizer->Add( name_sizer, 1 , wxEXPAND, 5 );
173 wxStaticText *author_label =
174 new wxStaticText( info_panel, -1, wxU(_("Author")) );
177 new wxTextCtrl( info_panel, Uri_Event,
178 wxU( playlist_ItemGetInfo( p_item,
179 _("General"), _("Author") ) ),
180 wxDefaultPosition, wxSize( 300, -1 ),
183 wxBoxSizer *author_sizer = new wxBoxSizer( wxHORIZONTAL );
184 author_sizer->Add( author_label, 0 , wxALIGN_RIGHT | wxALL , 5 );
185 author_sizer->Add( author_text, 1 , wxALIGN_RIGHT | wxALL , 5);
186 author_sizer->Layout();
187 box_sizer->Add( author_sizer, 1, wxEXPAND, 5 );
190 info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
192 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
195 box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
196 info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
198 info_panel->SetSizer( info_sizer );
199 info_sizer->Layout();
200 info_sizer->SetSizeHints( info_panel );
207 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
209 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
211 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
212 wxU(_("Group Info")) );
213 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
215 wxBoxSizer *subpanel_sizer;
216 group_subpanel = new wxPanel( panel, -1 );
217 subpanel_sizer = new wxBoxSizer( wxVERTICAL) ;
218 enabled_checkbox = new wxCheckBox( group_subpanel,
219 -1, wxU(_("Item Enabled")) );
221 enabled_checkbox->SetValue( p_item->b_enabled);
223 wxStaticText *group_label = new wxStaticText( group_subpanel,
224 -1, wxU(_("Group")) );
226 playlist_t *p_playlist =
227 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
229 if( p_playlist == NULL )
234 group_combo = new wxComboBox( group_subpanel, -1,
235 wxT(""),wxDefaultPosition, wxDefaultSize,
239 wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
240 wxU(_("New Group")));
242 for( int i=0; i< p_playlist->i_groups ; i++)
244 group_combo->Append( wxU( p_playlist->pp_groups[i]->psz_name ) );
245 if( p_playlist->pp_groups[i]->i_id == p_item->i_group )
247 group_combo->SetSelection( i );
248 group_combo->SetValue( wxU( p_playlist->pp_groups[i]->psz_name ) );
252 vlc_object_release ( p_playlist );
254 subpanel_sizer->Add( enabled_checkbox, 0, wxALIGN_RIGHT|
255 wxALIGN_CENTER_VERTICAL );
256 subpanel_sizer->Add( group_label, 0, wxALIGN_LEFT |
257 wxALIGN_CENTER_VERTICAL );
259 wxBoxSizer *group_sizer = new wxBoxSizer( wxHORIZONTAL);
260 group_sizer->Add(group_combo, 0, wxALIGN_LEFT|wxRIGHT, 5);
261 group_sizer->Add( newgroup_button, 0, wxALIGN_RIGHT|wxLEFT, 5);
262 group_sizer->Layout();
264 subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
266 group_subpanel->SetSizerAndFit( subpanel_sizer );
268 /* Stuff everything into the main panel */
269 panel_sizer->Add( group_subpanel, 0,
270 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
272 panel->SetSizerAndFit( panel_sizer );
278 void ItemInfoDialog::UpdateInfo()
282 info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
285 /* Rebuild the tree */
286 for( int i = 0; i< p_item->input.i_categories ; i++)
288 if( !strcmp( p_item->input.pp_categories[i]->psz_name, _("Options") ) )
292 wxTreeItemId cat = info_tree->AppendItem( info_root,
293 wxU( p_item->input.pp_categories[i]->psz_name) );
295 for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
297 info_tree->AppendItem( cat , (wxString)
298 wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
300 wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
305 /*****************************************************************************
307 *****************************************************************************/
308 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
310 vlc_mutex_lock( &p_item->input.lock );
311 p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
312 p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
313 playlist_ItemAddInfo( p_item,"General","Author",
314 author_text->GetLineText(0).mb_str() );
315 vlc_bool_t b_old_enabled = p_item->b_enabled;
317 playlist_t * p_playlist =
318 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
320 if( p_playlist != NULL )
322 if( b_old_enabled == VLC_FALSE && enabled_checkbox->IsChecked() )
323 p_playlist->i_enabled ++;
324 else if( b_old_enabled == VLC_TRUE && !enabled_checkbox->IsChecked() )
325 p_playlist->i_enabled --;
327 for (int i=0 ; i< p_playlist->i_groups ; i++)
329 if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
330 group_combo->GetValue().mb_str() ))
332 p_item->i_group = p_playlist->pp_groups[i]->i_id;
337 vlc_object_release( p_playlist );
340 p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
341 vlc_mutex_unlock( &p_item->input.lock );
345 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
347 EndModal( wxID_CANCEL );
350 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
352 NewGroup *p_newgroup = NULL;
354 p_newgroup = new NewGroup( p_intf, this );
358 if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
360 group_combo->Append( wxU( p_newgroup->psz_name ) );
362 delete( p_newgroup );