1 /*****************************************************************************
2 * iteminfo.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: iteminfo.cpp,v 1.3 2003/10/29 17:32:54 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 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/notebook.h>
45 #include <wx/textctrl.h>
46 #include <wx/combobox.h>
47 #include <wx/spinctrl.h>
48 #include <wx/statline.h>
52 #include "wxwindows.h"
55 # define wxRB_SINGLE 0
58 /*****************************************************************************
60 *****************************************************************************/
62 /* IDs for the controls and the menu commands */
72 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
74 EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
75 EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
76 /* Events generated by the panels */
77 EVT_BUTTON( New_Event, ItemInfoDialog::OnNewGroup)
81 /*****************************************************************************
83 *****************************************************************************/
84 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
85 playlist_item_t *_p_item,
86 wxWindow* _p_parent ):
87 wxDialog( _p_parent, -1, wxU(_("Playlist Item options")),
88 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
94 SetIcon( *p_intf->p_sys->p_icon );
96 /* Create a panel to put everything in */
97 wxPanel *panel = new wxPanel( this, -1 );
98 panel->SetAutoLayout( TRUE );
100 /* Create the standard info panel */
101 wxPanel *info_panel = InfoPanel( panel );
103 /* Create the group panel */
104 wxPanel *group_panel = GroupPanel( panel );
107 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
109 /* Create the buttons */
110 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
111 ok_button->SetDefault();
112 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
115 /* Place everything in sizers */
116 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
117 button_sizer->Add( ok_button, 0, wxALL, 5 );
118 button_sizer->Add( cancel_button, 0, wxALL, 5 );
119 button_sizer->Layout();
120 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
121 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
122 panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
123 panel_sizer->Add( group_panel, 0, wxEXPAND | wxALL, 5 );
124 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
125 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
127 panel_sizer->Layout();
128 panel->SetSizerAndFit( panel_sizer );
129 main_sizer->Add( panel, 1, wxGROW, 0 );
130 main_sizer->Layout();
131 SetSizerAndFit( main_sizer );
134 ItemInfoDialog::~ItemInfoDialog()
138 /*****************************************************************************
140 *****************************************************************************/
141 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
143 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
146 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
147 wxU(_("Item informations")) );
148 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
151 info_subpanel = new wxPanel( panel, -1 );
153 wxFlexGridSizer *subpanel_sizer =
154 new wxFlexGridSizer( 3, 1 , 0 , 0 );
157 wxStaticText *uri_label =
158 new wxStaticText(info_subpanel, -1, wxU(_("URI")) );
160 uri_text = new wxTextCtrl( info_subpanel, Uri_Event,
161 wxU(p_item->psz_uri),
162 wxDefaultPosition, wxSize( 300, -1 ),
165 subpanel_sizer->Add( uri_label, 0, wxALIGN_LEFT |
166 wxALIGN_CENTER_VERTICAL );
167 subpanel_sizer->Add( uri_text, 0, wxALIGN_RIGHT |
168 wxALIGN_CENTER_VERTICAL );
172 wxStaticText *name_label =
173 new wxStaticText(info_subpanel, -1, wxU(_("Name")) );
176 new wxTextCtrl( info_subpanel, Uri_Event,
177 wxU(p_item->psz_name),
178 wxDefaultPosition, wxSize( 300, -1 ),
181 subpanel_sizer->Add( name_label, 0, wxALIGN_LEFT |
182 wxALIGN_CENTER_VERTICAL );
183 subpanel_sizer->Add( name_text, 0, wxALIGN_RIGHT |
184 wxALIGN_CENTER_VERTICAL );
187 wxStaticText *author_label =
188 new wxStaticText(info_subpanel, -1, wxU(_("Author")) );
191 new wxTextCtrl( info_subpanel, Uri_Event,
192 wxU(p_item->psz_author),
193 wxDefaultPosition, wxSize( 300, -1 ),
196 subpanel_sizer->Add( author_label, 0, wxALIGN_LEFT |
197 wxALIGN_CENTER_VERTICAL );
198 subpanel_sizer->Add( author_text, 0, wxALIGN_RIGHT |
199 wxALIGN_CENTER_VERTICAL );
201 info_subpanel->SetSizerAndFit( subpanel_sizer );
203 /* Stuff everything into the main panel */
204 panel_sizer->Add( info_subpanel, 1,
205 wxEXPAND | wxALIGN_LEFT |
206 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
208 panel->SetSizerAndFit( panel_sizer );
213 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
215 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
217 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
218 wxU(_("Group Info")) );
219 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
221 wxBoxSizer *subpanel_sizer;
222 group_subpanel = new wxPanel( panel, -1 );
223 subpanel_sizer = new wxBoxSizer( wxVERTICAL) ;
224 enabled_checkbox = new wxCheckBox( group_subpanel,
225 -1, wxU(_("Item enabled")) );
227 enabled_checkbox->SetValue( p_item->b_enabled);
229 wxStaticText *group_label = new wxStaticText( group_subpanel,
230 -1, wxU(_("Group")) );
232 playlist_t *p_playlist =
233 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
235 if( p_playlist == NULL )
240 group_combo = new wxComboBox( group_subpanel, -1,
241 wxT(""),wxDefaultPosition, wxDefaultSize,
245 wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
246 wxT(_("New Group")));
248 for( int i=0; i< p_playlist->i_groups ; i++)
250 group_combo->Append( wxT( p_playlist->pp_groups[i]->psz_name));
253 vlc_object_release ( p_playlist );
255 subpanel_sizer->Add( enabled_checkbox, 0, wxALIGN_RIGHT|
256 wxALIGN_CENTER_VERTICAL );
257 subpanel_sizer->Add( group_label, 0, wxALIGN_LEFT |
258 wxALIGN_CENTER_VERTICAL );
260 wxBoxSizer *group_sizer = new wxBoxSizer( wxHORIZONTAL);
261 group_sizer->Add(group_combo, 0, wxALIGN_LEFT|wxRIGHT, 5);
262 group_sizer->Add( newgroup_button, 0, wxALIGN_RIGHT|wxLEFT, 5);
263 group_sizer->Layout();
265 subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
267 group_subpanel->SetSizerAndFit( subpanel_sizer );
269 /* Stuff everything into the main panel */
270 panel_sizer->Add( group_subpanel, 0,
271 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
273 panel->SetSizerAndFit( panel_sizer );
279 /*****************************************************************************
281 *****************************************************************************/
282 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
284 p_item->psz_name = strdup( name_text->GetLineText(0).mb_str() );
285 p_item->psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
286 p_item->psz_author = strdup( author_text->GetLineText(0).mb_str() );
287 vlc_bool_t b_old_enabled = p_item->b_enabled;
289 playlist_t * p_playlist =
290 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
292 if( p_playlist != NULL )
294 if( b_old_enabled == VLC_FALSE && enabled_checkbox->IsChecked() )
295 p_playlist->i_enabled ++;
296 else if( b_old_enabled == VLC_TRUE && !enabled_checkbox->IsChecked() )
297 p_playlist->i_enabled --;
299 for (int i=0 ; i< p_playlist->i_groups ; i++)
301 if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
302 group_combo->GetValue() ))
304 p_item->i_group = p_playlist->pp_groups[i]->i_id;
309 vlc_object_release( p_playlist );
312 p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
316 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
318 EndModal( wxID_CANCEL );
321 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
323 NewGroup *p_newgroup = NULL;
325 p_newgroup = new NewGroup( p_intf, this );
329 if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
331 group_combo->Append( wxT( p_newgroup->psz_name));
333 delete( p_newgroup );