1 /*****************************************************************************
2 * iteminfo.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
5 * $Id: iteminfo.cpp,v 1.8 2004/01/29 17:51:08 zorglub Exp $
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->psz_uri),
148 wxDefaultPosition, wxSize( 300, -1 ),
151 wxBoxSizer *uri_sizer = new wxBoxSizer( wxHORIZONTAL );
153 uri_sizer->Add( uri_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
154 uri_sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
156 box_sizer->Add( uri_sizer, 1, wxEXPAND , 5);
159 wxStaticText *name_label =
160 new wxStaticText( info_panel, -1, wxU(_("Name")) );
163 new wxTextCtrl( info_panel, Uri_Event,
164 wxU(p_item->psz_name),
165 wxDefaultPosition, wxSize( 300, -1 ),
168 wxBoxSizer *name_sizer = new wxBoxSizer( wxHORIZONTAL );
170 name_sizer->Add( name_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
171 name_sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
172 name_sizer->Layout();
173 box_sizer->Add( name_sizer, 1 , wxEXPAND, 5 );
176 wxStaticText *author_label =
177 new wxStaticText( info_panel, -1, wxU(_("Author")) );
180 new wxTextCtrl( info_panel, Uri_Event,
181 wxU( playlist_ItemGetInfo( p_item,
182 _("General"), _("Author") ) ),
183 wxDefaultPosition, wxSize( 300, -1 ),
186 wxBoxSizer *author_sizer = new wxBoxSizer( wxHORIZONTAL );
187 author_sizer->Add( author_label, 0 , wxALIGN_RIGHT | wxALL , 5 );
188 author_sizer->Add( author_text, 1 , wxALIGN_RIGHT | wxALL , 5);
189 author_sizer->Layout();
190 box_sizer->Add( author_sizer, 1, wxEXPAND, 5 );
193 info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
195 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
198 box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
199 info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
201 info_panel->SetSizer( info_sizer );
202 info_sizer->Layout();
203 info_sizer->SetSizeHints( info_panel );
210 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
212 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
214 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
215 wxU(_("Group Info")) );
216 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
218 wxBoxSizer *subpanel_sizer;
219 group_subpanel = new wxPanel( panel, -1 );
220 subpanel_sizer = new wxBoxSizer( wxVERTICAL) ;
221 enabled_checkbox = new wxCheckBox( group_subpanel,
222 -1, wxU(_("Item Enabled")) );
224 enabled_checkbox->SetValue( p_item->b_enabled);
226 wxStaticText *group_label = new wxStaticText( group_subpanel,
227 -1, wxU(_("Group")) );
229 playlist_t *p_playlist =
230 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
232 if( p_playlist == NULL )
237 group_combo = new wxComboBox( group_subpanel, -1,
238 wxT(""),wxDefaultPosition, wxDefaultSize,
242 wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
243 wxU(_("New Group")));
245 for( int i=0; i< p_playlist->i_groups ; i++)
247 group_combo->Append( wxU( p_playlist->pp_groups[i]->psz_name ) );
248 if( p_playlist->pp_groups[i]->i_id == p_item->i_group )
250 group_combo->SetSelection( i );
251 group_combo->SetValue( wxU( p_playlist->pp_groups[i]->psz_name ) );
255 vlc_object_release ( p_playlist );
257 subpanel_sizer->Add( enabled_checkbox, 0, wxALIGN_RIGHT|
258 wxALIGN_CENTER_VERTICAL );
259 subpanel_sizer->Add( group_label, 0, wxALIGN_LEFT |
260 wxALIGN_CENTER_VERTICAL );
262 wxBoxSizer *group_sizer = new wxBoxSizer( wxHORIZONTAL);
263 group_sizer->Add(group_combo, 0, wxALIGN_LEFT|wxRIGHT, 5);
264 group_sizer->Add( newgroup_button, 0, wxALIGN_RIGHT|wxLEFT, 5);
265 group_sizer->Layout();
267 subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
269 group_subpanel->SetSizerAndFit( subpanel_sizer );
271 /* Stuff everything into the main panel */
272 panel_sizer->Add( group_subpanel, 0,
273 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
275 panel->SetSizerAndFit( panel_sizer );
281 void ItemInfoDialog::UpdateInfo()
285 info_root = info_tree->AddRoot( wxU( p_item->psz_name) );
288 /* Rebuild the tree */
289 for( int i = 0; i< p_item->i_categories ; i++)
291 if( !strcmp( p_item->pp_categories[i]->psz_name, _("Options") ) )
295 wxTreeItemId cat = info_tree->AppendItem( info_root,
296 wxU( p_item->pp_categories[i]->psz_name) );
298 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
300 info_tree->AppendItem( cat , (wxString)
301 wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
303 wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
308 /*****************************************************************************
310 *****************************************************************************/
311 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
313 vlc_mutex_lock( &p_item->lock );
314 p_item->psz_name = strdup( name_text->GetLineText(0).mb_str() );
315 p_item->psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
316 playlist_ItemAddInfo( p_item,"General","Author",
317 author_text->GetLineText(0).mb_str() );
318 vlc_bool_t b_old_enabled = p_item->b_enabled;
320 playlist_t * p_playlist =
321 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
323 if( p_playlist != NULL )
325 if( b_old_enabled == VLC_FALSE && enabled_checkbox->IsChecked() )
326 p_playlist->i_enabled ++;
327 else if( b_old_enabled == VLC_TRUE && !enabled_checkbox->IsChecked() )
328 p_playlist->i_enabled --;
330 for (int i=0 ; i< p_playlist->i_groups ; i++)
332 if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
333 group_combo->GetValue().mb_str() ))
335 p_item->i_group = p_playlist->pp_groups[i]->i_id;
340 vlc_object_release( p_playlist );
343 p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
344 vlc_mutex_unlock( &p_item->lock );
348 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
350 EndModal( wxID_CANCEL );
353 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
355 NewGroup *p_newgroup = NULL;
357 p_newgroup = new NewGroup( p_intf, this );
361 if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
363 group_combo->Append( wxU( p_newgroup->psz_name ) );
365 delete( p_newgroup );