]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/iteminfo.cpp
Install new required files for skins2 on make install
[vlc] / modules / gui / wxwindows / iteminfo.cpp
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 $
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->psz_uri),
148                                 wxDefaultPosition, wxSize( 300, -1 ),
149                                 wxTE_PROCESS_ENTER);
150
151     wxBoxSizer *uri_sizer = new wxBoxSizer( wxHORIZONTAL );
152
153     uri_sizer->Add( uri_label, 0 , wxALIGN_RIGHT |wxALL , 5 );
154     uri_sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
155     uri_sizer->Layout();
156     box_sizer->Add( uri_sizer, 1, wxEXPAND , 5);
157
158     /* Name Textbox */
159     wxStaticText *name_label =
160            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
161
162     name_text =
163                    new wxTextCtrl( info_panel, Uri_Event,
164                                    wxU(p_item->psz_name),
165                                    wxDefaultPosition, wxSize( 300, -1 ),
166                                    wxTE_PROCESS_ENTER);
167
168     wxBoxSizer *name_sizer = new wxBoxSizer( wxHORIZONTAL );
169
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 );
174
175     /* Author Textbox */
176     wxStaticText *author_label =
177            new wxStaticText( info_panel, -1, wxU(_("Author")) );
178
179     author_text =
180                    new wxTextCtrl( info_panel, Uri_Event,
181                                    wxU( playlist_ItemGetInfo( p_item,
182                                           _("General"), _("Author") ) ),
183                                    wxDefaultPosition, wxSize( 300, -1 ),
184                                    wxTE_PROCESS_ENTER);
185
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 );
191
192     /* Treeview */
193     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
194                                 wxSize(220,200),
195                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
196                                 wxTR_HIDE_ROOT );
197
198     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
199     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
200
201     info_panel->SetSizer( info_sizer );
202     info_sizer->Layout();
203     info_sizer->SetSizeHints( info_panel );
204
205     UpdateInfo();
206
207     return info_panel;
208 }
209
210 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
211 {
212     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
213                                   wxDefaultSize );
214     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
215                                    wxU(_("Group Info")) );
216     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
217                                                          wxVERTICAL);
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")) );
223
224     enabled_checkbox->SetValue( p_item->b_enabled);
225
226     wxStaticText *group_label = new wxStaticText( group_subpanel,
227                                         -1, wxU(_("Group")) );
228
229     playlist_t *p_playlist =
230                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
231                                        FIND_ANYWHERE );
232     if( p_playlist == NULL )
233     {
234         return NULL;
235     }
236
237     group_combo = new wxComboBox( group_subpanel, -1,
238                                  wxT(""),wxDefaultPosition, wxDefaultSize,
239                                  0, NULL,
240                                  wxCB_READONLY );
241
242     wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
243                                     wxU(_("New Group")));
244
245     for( int i=0; i< p_playlist->i_groups ; i++)
246     {
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 )
249         {
250             group_combo->SetSelection( i );
251             group_combo->SetValue( wxU( p_playlist->pp_groups[i]->psz_name ) );
252         }
253     }
254
255     vlc_object_release ( p_playlist );
256
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 );
261
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();
266
267     subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
268
269     group_subpanel->SetSizerAndFit( subpanel_sizer );
270
271     /* Stuff everything into the main panel */
272     panel_sizer->Add( group_subpanel, 0,
273                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
274
275     panel->SetSizerAndFit( panel_sizer );
276
277     /* Update panel */
278     return panel;
279 }
280
281 void ItemInfoDialog::UpdateInfo()
282 {
283     if( !info_root )
284     {
285        info_root = info_tree->AddRoot( wxU( p_item->psz_name) );
286     }
287
288     /* Rebuild the tree */
289     for( int i = 0; i< p_item->i_categories ; i++)
290     {
291         if( !strcmp( p_item->pp_categories[i]->psz_name, _("Options") ) )
292         {
293             continue;
294         }
295         wxTreeItemId cat = info_tree->AppendItem( info_root,
296                             wxU( p_item->pp_categories[i]->psz_name) );
297
298         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
299         {
300            info_tree->AppendItem( cat , (wxString)
301                       wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
302                       wxT(": ") +
303                       wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
304         }
305     }
306 }
307
308 /*****************************************************************************
309  * Events methods.
310  *****************************************************************************/
311 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
312 {
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;
319
320     playlist_t * p_playlist =
321           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
322                                        FIND_ANYWHERE );
323     if( p_playlist != NULL )
324     {
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 --;
329
330         for (int i=0 ; i< p_playlist->i_groups ; i++)
331         {
332            if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
333                             group_combo->GetValue().mb_str() ))
334            {
335                p_item->i_group = p_playlist->pp_groups[i]->i_id;
336                break;
337            }
338         }
339
340         vlc_object_release( p_playlist );
341     }
342
343     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
344     vlc_mutex_unlock( &p_item->lock );
345     EndModal( wxID_OK );
346 }
347
348 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
349 {
350     EndModal( wxID_CANCEL );
351 }
352
353 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
354 {
355     NewGroup *p_newgroup = NULL;
356
357     p_newgroup = new NewGroup( p_intf, this );
358
359     if( p_newgroup)
360     {
361         if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
362         {
363             group_combo->Append( wxU( p_newgroup->psz_name ) );
364         }
365         delete( p_newgroup );
366     }
367 }