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