]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/iteminfo.cpp
* include/vlc_playlist.h
[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.1 2003/10/06 16:23:30 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 };
70
71 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
72     /* Button events */
73     EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
74     EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
75
76     /* Events generated by the panels */
77
78 END_EVENT_TABLE()
79
80 /*****************************************************************************
81  * Constructor.
82  *****************************************************************************/
83 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
84                                 playlist_item_t *_p_item,
85                                 wxWindow* _p_parent ):
86     wxDialog( _p_parent, -1, wxU(_("Playlist Item options")),
87              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
88 {
89     /* Initializations */
90     p_intf = _p_intf;
91     p_parent = _p_parent;
92     p_item = _p_item;
93     SetIcon( *p_intf->p_sys->p_icon );
94
95     /* Create a panel to put everything in */
96     wxPanel *panel = new wxPanel( this, -1 );
97     panel->SetAutoLayout( TRUE );
98
99     /* Create the standard info panel */
100     wxPanel *info_panel = InfoPanel( panel );
101
102     /* Create the group panel */
103     wxPanel *group_panel = GroupPanel( panel );
104
105     /* Separation */
106     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
107
108     /* Create the buttons */
109     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
110     ok_button->SetDefault();
111     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
112                                             wxU(_("Cancel")) );
113
114     /* Place everything in sizers */
115     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
116     button_sizer->Add( ok_button, 0, wxALL, 5 );
117     button_sizer->Add( cancel_button, 0, wxALL, 5 );
118     button_sizer->Layout();
119     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
120     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
121     panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
122     panel_sizer->Add( group_panel, 0, wxEXPAND | wxALL, 5 );
123     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
124     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
125                       wxALL, 5 );
126     panel_sizer->Layout();
127     panel->SetSizerAndFit( panel_sizer );
128     main_sizer->Add( panel, 1, wxGROW, 0 );
129     main_sizer->Layout();
130     SetSizerAndFit( main_sizer );
131 }
132
133 ItemInfoDialog::~ItemInfoDialog()
134 {
135 }
136
137 /*****************************************************************************
138  * Private methods.
139  *****************************************************************************/
140 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
141 {
142     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
143                                   wxDefaultSize );
144
145     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
146                                    wxU(_("Item informations")) );
147     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
148                                                           wxVERTICAL );
149
150     info_subpanel = new wxPanel( panel, -1 );
151
152     wxFlexGridSizer *subpanel_sizer =
153                     new wxFlexGridSizer( 3, 1 , 0 , 0 );
154
155     /* URI Textbox */
156     wxStaticText *uri_label =
157            new wxStaticText(info_subpanel, -1, wxU(_("URI")) );
158
159     uri_text =  new wxTextCtrl( info_subpanel, Uri_Event,
160                                 wxT(p_item->psz_uri),
161                                 wxDefaultPosition, wxSize( 300, -1 ),
162                                 wxTE_PROCESS_ENTER);
163
164     subpanel_sizer->Add( uri_label, 0, wxALIGN_LEFT |
165                          wxALIGN_CENTER_VERTICAL );
166     subpanel_sizer->Add( uri_text, 0, wxALIGN_RIGHT |
167                          wxALIGN_CENTER_VERTICAL );
168
169
170     /* Name Textbox */
171     wxStaticText *name_label =
172            new wxStaticText(info_subpanel, -1, wxU(_("Name")) );
173
174     name_text =
175                    new wxTextCtrl( info_subpanel, Uri_Event,
176                                    wxT(p_item->psz_name),
177                                    wxDefaultPosition, wxSize( 300, -1 ),
178                                    wxTE_PROCESS_ENTER);
179
180     subpanel_sizer->Add( name_label, 0, wxALIGN_LEFT |
181                          wxALIGN_CENTER_VERTICAL );
182     subpanel_sizer->Add( name_text, 0, wxALIGN_RIGHT |
183                          wxALIGN_CENTER_VERTICAL );
184
185     /* Author Textbox */
186     wxStaticText *author_label =
187            new wxStaticText(info_subpanel, -1, wxU(_("Author")) );
188
189     author_text =
190                    new wxTextCtrl( info_subpanel, Uri_Event,
191                                    wxT(p_item->psz_author),
192                                    wxDefaultPosition, wxSize( 300, -1 ),
193                                    wxTE_PROCESS_ENTER);
194
195     subpanel_sizer->Add( author_label, 0, wxALIGN_LEFT |
196                          wxALIGN_CENTER_VERTICAL );
197     subpanel_sizer->Add( author_text, 0, wxALIGN_RIGHT |
198                          wxALIGN_CENTER_VERTICAL );
199
200     info_subpanel->SetSizerAndFit( subpanel_sizer );
201
202     /* Stuff everything into the main panel */
203     panel_sizer->Add( info_subpanel, 1,
204                       wxEXPAND | wxALIGN_LEFT |
205                       wxALIGN_CENTER_VERTICAL | wxALL, 5 );
206
207     panel->SetSizerAndFit( panel_sizer );
208
209     return panel;
210 }
211
212 wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
213 {
214     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
215                                   wxDefaultSize );
216
217     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
218                                    wxU(_("Group Info")) );
219
220     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
221                                                          wxVERTICAL);
222
223     wxBoxSizer *subpanel_sizer;
224
225     group_subpanel = new wxPanel( panel, -1 );
226
227     subpanel_sizer = new wxBoxSizer( wxVERTICAL) ;
228
229     enabled_checkbox = new wxCheckBox( group_subpanel,
230                                      -1,
231                                      wxU(_("Item enabled")) );
232
233     enabled_checkbox->SetValue( p_item->b_enabled);
234
235     wxStaticText *group_label = new wxStaticText( group_subpanel,
236                                         -1, wxU(_("Group")) );
237     group_spin = new wxSpinCtrl( group_subpanel,
238                                              -1 );
239     group_spin->SetValue( p_item->i_group > 0 ? p_item->i_group : 0);
240
241     subpanel_sizer->Add( enabled_checkbox, 0, wxALIGN_RIGHT|
242                          wxALIGN_CENTER_VERTICAL );
243     subpanel_sizer->Add( group_label, 0, wxALIGN_LEFT |
244                          wxALIGN_CENTER_VERTICAL );
245     subpanel_sizer->Add( group_spin, 0, wxALIGN_RIGHT );
246
247     group_subpanel->SetSizerAndFit( subpanel_sizer );
248
249     /* Stuff everything into the main panel */
250      panel_sizer->Add( group_subpanel, 0,
251                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
252
253     panel->SetSizerAndFit( panel_sizer );
254
255     /* Update panel */
256     return panel;
257 }
258
259 /*****************************************************************************
260  * Events methods.
261  *****************************************************************************/
262 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
263 {
264     p_item->psz_name = strdup( name_text->GetLineText(0) );
265     p_item->psz_uri = strdup( uri_text->GetLineText(0) );
266     p_item->psz_author = strdup( author_text->GetLineText(0) );
267     vlc_bool_t b_old_enabled = p_item->b_enabled;
268
269     playlist_t * p_playlist =
270           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
271                                        FIND_ANYWHERE );
272     if( p_playlist != NULL )
273     {
274         if( b_old_enabled == VLC_FALSE && enabled_checkbox->IsChecked() )
275             p_playlist->i_enabled ++;
276         else if( b_old_enabled == VLC_TRUE && !enabled_checkbox->IsChecked() )
277             p_playlist->i_enabled --;
278
279         vlc_object_release( p_playlist );
280     }
281
282     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
283     p_item->i_group = group_spin->GetValue();
284     EndModal( wxID_OK );
285 }
286
287 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
288 {
289     EndModal( wxID_CANCEL );
290 }
291
292 /******************************************************************************
293  * Info panel event methods.
294  ******************************************************************************/