]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/iteminfo.cpp
8c12d31b169296909a43d1462672a0bbda9bce97
[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 };
57
58 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
59     /* Button events */
60     EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
61     EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
62
63 END_EVENT_TABLE()
64
65 /*****************************************************************************
66  * Constructor.
67  *****************************************************************************/
68 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
69                                 playlist_item_t *_p_item,
70                                 wxWindow* _p_parent ):
71     wxDialog( _p_parent, -1, wxU(_("Playlist item info")),
72              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
73 {
74     /* Initializations */
75     p_intf = _p_intf;
76     p_parent = _p_parent;
77     p_item = _p_item;
78     SetIcon( *p_intf->p_sys->p_icon );
79
80     /* Create a panel to put everything in */
81     wxPanel *panel = new wxPanel( this, -1 );
82     panel->SetAutoLayout( TRUE );
83
84     /* Create the standard info panel */
85     wxPanel *info_panel = InfoPanel( panel );
86
87     /* Separation */
88     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
89
90     /* Create the buttons */
91     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
92     ok_button->SetDefault();
93     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
94                                             wxU(_("Cancel")) );
95
96     /* Place everything in sizers */
97     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
98     button_sizer->Add( ok_button, 0, wxALL, 5 );
99     button_sizer->Add( cancel_button, 0, wxALL, 5 );
100     button_sizer->Layout();
101     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
102     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
103     panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
104     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
105     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
106                       wxALL, 5 );
107     panel_sizer->Layout();
108     panel->SetSizerAndFit( panel_sizer );
109     main_sizer->Add( panel, 1, wxGROW, 0 );
110     main_sizer->Layout();
111     SetSizerAndFit( main_sizer );
112 }
113
114 ItemInfoDialog::~ItemInfoDialog()
115 {
116 }
117
118 /*****************************************************************************
119  * Private methods.
120  *****************************************************************************/
121 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
122 {
123     wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
124                                   wxDefaultSize );
125     info_panel->SetAutoLayout( TRUE );
126     wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
127
128     /* Create a box to surround the controls */
129     wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
130                                    wxU(_("Item Info")) );
131
132     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
133                                                           wxVERTICAL );
134
135     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,3,20);
136     /* URI Textbox */
137     wxStaticText *uri_label =
138            new wxStaticText( info_panel, -1, wxU(_("URI")) );
139
140     uri_text = new wxTextCtrl( info_panel, Uri_Event,
141         wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
142         wxTE_PROCESS_ENTER );
143
144     sizer->Add( uri_label, 0 , wxALIGN_LEFT |wxALL , 5 );
145     sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
146
147     /* Name Textbox */
148     wxStaticText *name_label =
149            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
150
151     name_text = new wxTextCtrl( info_panel, Uri_Event,
152         wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
153         wxTE_PROCESS_ENTER );
154
155     sizer->Add( name_label, 0 , wxALIGN_LEFT |wxALL , 5  );
156     sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
157
158     /* Author Textbox */
159     wxStaticText *author_label =
160            new wxStaticText( info_panel, -1, wxU(_("Author")) );
161
162     author_text = new wxTextCtrl( info_panel, Uri_Event,
163                                    wxU( playlist_ItemGetInfo( p_item,
164                                           _("General"), _("Author") ) ),
165                                    wxDefaultPosition, wxSize( 300, -1 ),
166                                    wxTE_PROCESS_ENTER);
167
168     sizer->Add( author_label, 0 , wxALIGN_LEFT | wxALL , 5 );
169     sizer->Add( author_text, 1 , wxALIGN_RIGHT | wxALL , 5);
170
171     /* Treeview */
172     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
173                                 wxSize(220,200),
174                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
175                                 wxTR_HIDE_ROOT );
176
177     sizer->Layout();
178     box_sizer->Add( sizer, 0, wxEXPAND, 5 );
179     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
180     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
181
182     info_panel->SetSizer( info_sizer );
183     info_sizer->Layout();
184     info_sizer->SetSizeHints( info_panel );
185
186     UpdateInfo();
187
188     return info_panel;
189 }
190
191 void ItemInfoDialog::UpdateInfo()
192 {
193     if( !info_root )
194     {
195        info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
196     }
197
198     /* Rebuild the tree */
199     for( int i = 0; i< p_item->input.i_categories ; i++)
200     {
201         wxTreeItemId cat = info_tree->AppendItem( info_root,
202                             wxU( p_item->input.pp_categories[i]->psz_name) );
203
204         for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
205         {
206            info_tree->AppendItem( cat , (wxString)
207                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
208                wxT(": ") +
209                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
210         }
211
212         info_tree->Expand( cat );
213     }
214 }
215
216 /*****************************************************************************
217  * Events methods.
218  *****************************************************************************/
219 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
220 {
221     vlc_mutex_lock( &p_item->input.lock );
222     p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
223     p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
224     playlist_ItemAddInfo( p_item,"General","Author",
225                             author_text->GetLineText(0).mb_str() );
226     vlc_mutex_unlock( &p_item->input.lock );
227     EndModal( wxID_OK );
228 }
229
230 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
231 {
232     EndModal( wxID_CANCEL );
233 }