]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/iteminfo.cpp
* src/playlist/* && Makefile.am
[vlc] / modules / gui / wxwindows / iteminfo.cpp
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 $
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 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.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>
49
50 #include <vlc/intf.h>
51
52 #include "wxwindows.h"
53
54 #ifndef wxRB_SINGLE
55 #   define wxRB_SINGLE 0
56 #endif
57
58 /*****************************************************************************
59  * Event Table.
60  *****************************************************************************/
61
62 /* IDs for the controls and the menu commands */
63 enum
64 {
65     Uri_Event,
66     Name_Event,
67     Author_Event,
68     Enabled_Event,
69     New_Event,
70 };
71
72 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
73     /* Button events */
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)
78
79 END_EVENT_TABLE()
80
81 /*****************************************************************************
82  * Constructor.
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 )
89 {
90     /* Initializations */
91     p_intf = _p_intf;
92     p_parent = _p_parent;
93     p_item = _p_item;
94     SetIcon( *p_intf->p_sys->p_icon );
95
96     /* Create a panel to put everything in */
97     wxPanel *panel = new wxPanel( this, -1 );
98     panel->SetAutoLayout( TRUE );
99
100     /* Create the standard info panel */
101     wxPanel *info_panel = InfoPanel( panel );
102
103     /* Create the group panel */
104     wxPanel *group_panel = GroupPanel( panel );
105
106     /* Separation */
107     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
108
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,
113                                             wxU(_("Cancel")) );
114
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 |
126                       wxALL, 5 );
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 );
132 }
133
134 ItemInfoDialog::~ItemInfoDialog()
135 {
136 }
137
138 /*****************************************************************************
139  * Private methods.
140  *****************************************************************************/
141 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
142 {
143     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
144                                   wxDefaultSize );
145
146     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
147                                    wxU(_("Item informations")) );
148     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
149                                                           wxVERTICAL );
150
151     info_subpanel = new wxPanel( panel, -1 );
152
153     wxFlexGridSizer *subpanel_sizer =
154                     new wxFlexGridSizer( 3, 1 , 0 , 0 );
155
156     /* URI Textbox */
157     wxStaticText *uri_label =
158            new wxStaticText(info_subpanel, -1, wxU(_("URI")) );
159
160     uri_text =  new wxTextCtrl( info_subpanel, Uri_Event,
161                                 wxU(p_item->psz_uri),
162                                 wxDefaultPosition, wxSize( 300, -1 ),
163                                 wxTE_PROCESS_ENTER);
164
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 );
169
170
171     /* Name Textbox */
172     wxStaticText *name_label =
173            new wxStaticText(info_subpanel, -1, wxU(_("Name")) );
174
175     name_text =
176                    new wxTextCtrl( info_subpanel, Uri_Event,
177                                    wxU(p_item->psz_name),
178                                    wxDefaultPosition, wxSize( 300, -1 ),
179                                    wxTE_PROCESS_ENTER);
180
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 );
185
186     /* Author Textbox */
187     wxStaticText *author_label =
188            new wxStaticText(info_subpanel, -1, wxU(_("Author")) );
189
190     author_text =
191                    new wxTextCtrl( info_subpanel, Uri_Event,
192                                    wxU(p_item->psz_author),
193                                    wxDefaultPosition, wxSize( 300, -1 ),
194                                    wxTE_PROCESS_ENTER);
195
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 );
200
201     info_subpanel->SetSizerAndFit( subpanel_sizer );
202
203     /* Stuff everything into the main panel */
204     panel_sizer->Add( info_subpanel, 1,
205                       wxEXPAND | wxALIGN_LEFT |
206                       wxALIGN_CENTER_VERTICAL | wxALL, 5 );
207
208     panel->SetSizerAndFit( panel_sizer );
209
210     return panel;
211 }
212
213 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
214 {
215     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
216                                   wxDefaultSize );
217     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
218                                    wxU(_("Group Info")) );
219     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
220                                                          wxVERTICAL);
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")) );
226
227     enabled_checkbox->SetValue( p_item->b_enabled);
228
229     wxStaticText *group_label = new wxStaticText( group_subpanel,
230                                         -1, wxU(_("Group")) );
231
232     playlist_t *p_playlist =
233                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
234                                        FIND_ANYWHERE );
235     if( p_playlist == NULL )
236     {
237         return NULL;
238     }
239
240     group_combo = new wxComboBox( group_subpanel, -1,
241                                  wxT(""),wxDefaultPosition, wxDefaultSize,
242                                  0, NULL,
243                                  wxCB_READONLY );
244
245     wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
246                                     wxT(_("New Group")));
247
248     for( int i=0; i< p_playlist->i_groups ; i++)
249     {
250         group_combo->Append( wxT( p_playlist->pp_groups[i]->psz_name));
251     }
252
253     vlc_object_release ( p_playlist );
254
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 );
259
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();
264
265     subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
266
267     group_subpanel->SetSizerAndFit( subpanel_sizer );
268
269     /* Stuff everything into the main panel */
270     panel_sizer->Add( group_subpanel, 0,
271                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
272
273     panel->SetSizerAndFit( panel_sizer );
274
275     /* Update panel */
276     return panel;
277 }
278
279 /*****************************************************************************
280  * Events methods.
281  *****************************************************************************/
282 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
283 {
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;
288
289     playlist_t * p_playlist =
290           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
291                                        FIND_ANYWHERE );
292     if( p_playlist != NULL )
293     {
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 --;
298
299         for (int i=0 ; i< p_playlist->i_groups ; i++)
300         {
301            if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
302                            group_combo->GetValue() ))
303            {
304                p_item->i_group = p_playlist->pp_groups[i]->i_id;
305                break;
306            }
307         }
308
309         vlc_object_release( p_playlist );
310     }
311
312     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
313     EndModal( wxID_OK );
314 }
315
316 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
317 {
318     EndModal( wxID_CANCEL );
319 }
320
321 void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
322 {
323     NewGroup *p_newgroup = NULL;
324
325     p_newgroup = new NewGroup( p_intf, this );
326
327     if( p_newgroup)
328     {
329         if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
330         {
331             group_combo->Append( wxT( p_newgroup->psz_name));
332         }
333         delete( p_newgroup );
334     }
335 }