]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/iteminfo.cpp
* src/input/control.c: added INPUT_ADD_INFO/INPUT_SET_NAME to input_Control().
[vlc] / modules / gui / wxwindows / iteminfo.cpp
1 /*****************************************************************************
2  * iteminfo.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #include <wx/combobox.h>
35 #include <wx/statline.h>
36
37 #include <vlc/intf.h>
38
39 #include "wxwindows.h"
40
41 #ifndef wxRB_SINGLE
42 #   define wxRB_SINGLE 0
43 #endif
44
45 /*****************************************************************************
46  * Event Table.
47  *****************************************************************************/
48
49 /* IDs for the controls and the menu commands */
50 enum
51 {
52     Uri_Event,
53     Name_Event,
54     Author_Event,
55     Enabled_Event,
56     New_Event,
57 };
58
59 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
60     /* Button events */
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)
65
66 END_EVENT_TABLE()
67
68 /*****************************************************************************
69  * Constructor.
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 )
76 {
77     /* Initializations */
78     p_intf = _p_intf;
79     p_parent = _p_parent;
80     p_item = _p_item;
81     SetIcon( *p_intf->p_sys->p_icon );
82
83     /* Create a panel to put everything in */
84     wxPanel *panel = new wxPanel( this, -1 );
85     panel->SetAutoLayout( TRUE );
86
87     /* Create the standard info panel */
88     wxPanel *info_panel = InfoPanel( panel );
89
90     /* Create the group panel */
91     wxPanel *group_panel = GroupPanel( panel );
92
93     /* Separation */
94     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
95
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,
100                                             wxU(_("Cancel")) );
101
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 |
113                       wxALL, 5 );
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 );
119 }
120
121 ItemInfoDialog::~ItemInfoDialog()
122 {
123 }
124
125 /*****************************************************************************
126  * Private methods.
127  *****************************************************************************/
128 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
129 {
130     wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
131                                   wxDefaultSize );
132     info_panel->SetAutoLayout( TRUE );
133     wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
134
135     /* Create a box to surround the controls */
136     wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
137                                    wxU(_("Item Info")) );
138
139     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
140                                                           wxVERTICAL );
141
142     /* URI Textbox */
143     wxStaticText *uri_label =
144            new wxStaticText( info_panel, -1, wxU(_("URI")) );
145
146     uri_text = new wxTextCtrl( info_panel, Uri_Event,
147         wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
148         wxTE_PROCESS_ENTER );
149
150     wxBoxSizer *uri_sizer = new wxBoxSizer( wxHORIZONTAL );
151
152     uri_sizer->Add( uri_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
153     uri_sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
154     uri_sizer->Layout();
155     box_sizer->Add( uri_sizer, 1, wxEXPAND , 5);
156
157     /* Name Textbox */
158     wxStaticText *name_label =
159            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
160
161     name_text = new wxTextCtrl( info_panel, Uri_Event,
162         wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
163         wxTE_PROCESS_ENTER );
164
165     wxBoxSizer *name_sizer = new wxBoxSizer( wxHORIZONTAL );
166
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 );
171
172     /* Author Textbox */
173     wxStaticText *author_label =
174            new wxStaticText( info_panel, -1, wxU(_("Author")) );
175
176     author_text =
177                    new wxTextCtrl( info_panel, Uri_Event,
178                                    wxU( playlist_ItemGetInfo( p_item,
179                                           _("General"), _("Author") ) ),
180                                    wxDefaultPosition, wxSize( 300, -1 ),
181                                    wxTE_PROCESS_ENTER);
182
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 );
188
189     /* Treeview */
190     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
191                                 wxSize(220,200),
192                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
193                                 wxTR_HIDE_ROOT );
194
195     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
196     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
197
198     info_panel->SetSizer( info_sizer );
199     info_sizer->Layout();
200     info_sizer->SetSizeHints( info_panel );
201
202     UpdateInfo();
203
204     return info_panel;
205 }
206
207 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
208 {
209     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
210                                   wxDefaultSize );
211     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
212                                    wxU(_("Group Info")) );
213     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
214                                                          wxVERTICAL);
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")) );
220
221     enabled_checkbox->SetValue( p_item->b_enabled);
222
223     wxStaticText *group_label = new wxStaticText( group_subpanel,
224                                         -1, wxU(_("Group")) );
225
226     playlist_t *p_playlist =
227                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
228                                        FIND_ANYWHERE );
229     if( p_playlist == NULL )
230     {
231         return NULL;
232     }
233
234     group_combo = new wxComboBox( group_subpanel, -1,
235                                  wxT(""),wxDefaultPosition, wxDefaultSize,
236                                  0, NULL,
237                                  wxCB_READONLY );
238
239     wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
240                                     wxU(_("New Group")));
241
242     for( int i=0; i< p_playlist->i_groups ; i++)
243     {
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 )
246         {
247             group_combo->SetSelection( i );
248             group_combo->SetValue( wxU( p_playlist->pp_groups[i]->psz_name ) );
249         }
250     }
251
252     vlc_object_release ( p_playlist );
253
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 );
258
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();
263
264     subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
265
266     group_subpanel->SetSizerAndFit( subpanel_sizer );
267
268     /* Stuff everything into the main panel */
269     panel_sizer->Add( group_subpanel, 0,
270                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
271
272     panel->SetSizerAndFit( panel_sizer );
273
274     /* Update panel */
275     return panel;
276 }
277
278 void ItemInfoDialog::UpdateInfo()
279 {
280     if( !info_root )
281     {
282        info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
283     }
284
285     /* Rebuild the tree */
286     for( int i = 0; i< p_item->input.i_categories ; i++)
287     {
288         if( !strcmp( p_item->input.pp_categories[i]->psz_name, _("Options") ) )
289         {
290             continue;
291         }
292         wxTreeItemId cat = info_tree->AppendItem( info_root,
293                             wxU( p_item->input.pp_categories[i]->psz_name) );
294
295         for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
296         {
297            info_tree->AppendItem( cat , (wxString)
298                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
299                wxT(": ") +
300                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
301         }
302     }
303 }
304
305 /*****************************************************************************
306  * Events methods.
307  *****************************************************************************/
308 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
309 {
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;
316
317     playlist_t * p_playlist =
318           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
319                                        FIND_ANYWHERE );
320     if( p_playlist != NULL )
321     {
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 --;
326
327         for (int i=0 ; i< p_playlist->i_groups ; i++)
328         {
329            if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
330                             group_combo->GetValue().mb_str() ))
331            {
332                p_item->i_group = p_playlist->pp_groups[i]->i_id;
333                break;
334            }
335         }
336
337         vlc_object_release( p_playlist );
338     }
339
340     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
341     vlc_mutex_unlock( &p_item->input.lock );
342     EndModal( wxID_OK );
343 }
344
345 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
346 {
347     EndModal( wxID_CANCEL );
348 }
349
350 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
351 {
352     NewGroup *p_newgroup = NULL;
353
354     p_newgroup = new NewGroup( p_intf, this );
355
356     if( p_newgroup)
357     {
358         if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
359         {
360             group_combo->Append( wxU( p_newgroup->psz_name ) );
361         }
362         delete( p_newgroup );
363     }
364 }