]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/iteminfo.cpp
contrib/makefile: add libmpcdec (Musepack) to win contribs
[vlc] / modules / gui / wxwidgets / dialogs / iteminfo.cpp
1 /*****************************************************************************
2  * iteminfo.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
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 #include "dialogs/iteminfo.hpp"
25 #include <wx/combobox.h>
26 #include <wx/statline.h>
27
28 #ifndef wxRB_SINGLE
29 #   define wxRB_SINGLE 0
30 #endif
31
32 /*****************************************************************************
33  * Event Table.
34  *****************************************************************************/
35
36 /* IDs for the controls and the menu commands */
37 enum
38 {
39     Uri_Event,
40     Name_Event,
41     Enabled_Event,
42 };
43
44 BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
45     /* Button events */
46     EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
47     EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
48
49 END_EVENT_TABLE()
50
51 /*****************************************************************************
52  * Constructor.
53  *****************************************************************************/
54 ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
55                                 playlist_item_t *_p_item,
56                                 wxWindow* _p_parent ):
57     wxDialog( _p_parent, -1, wxU(_("Playlist item info")),
58              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
59 {
60     /* Initializations */
61     p_intf = _p_intf;
62     p_parent = _p_parent;
63     p_item = _p_item;
64     SetIcon( *p_intf->p_sys->p_icon );
65
66     /* Create a panel to put everything in */
67     wxPanel *panel = new wxPanel( this, -1 );
68     panel->SetAutoLayout( TRUE );
69
70     /* Create the standard info panel */
71     wxPanel *info_panel = InfoPanel( panel );
72
73     /* Separation */
74     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
75
76     /* Create the buttons */
77     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
78     ok_button->SetDefault();
79     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
80                                             wxU(_("Cancel")) );
81
82     /* Place everything in sizers */
83     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
84     button_sizer->Add( ok_button, 0, wxALL, 5 );
85     button_sizer->Add( cancel_button, 0, wxALL, 5 );
86     button_sizer->Layout();
87     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
88     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
89     panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
90     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
91     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
92                       wxALL, 5 );
93     panel_sizer->Layout();
94     panel->SetSizerAndFit( panel_sizer );
95     main_sizer->Add( panel, 1, wxGROW, 0 );
96     main_sizer->Layout();
97     SetSizerAndFit( main_sizer );
98 }
99
100 ItemInfoDialog::~ItemInfoDialog()
101 {
102 }
103
104 /*****************************************************************************
105  * Private methods.
106  *****************************************************************************/
107 wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
108 {
109     wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
110                                   wxDefaultSize );
111     info_panel->SetAutoLayout( TRUE );
112     wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
113
114     /* Create a box to surround the controls */
115     wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
116                                    wxU(_("Item Info")) );
117
118     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
119                                                           wxVERTICAL );
120
121     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,3,20);
122     /* URI Textbox */
123     wxStaticText *uri_label =
124            new wxStaticText( info_panel, -1, wxU(_("URI")) );
125
126     uri_text = new wxTextCtrl( info_panel, Uri_Event,
127         wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
128         wxTE_PROCESS_ENTER );
129
130     sizer->Add( uri_label, 0 , wxALIGN_LEFT |wxALL , 5 );
131     sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
132
133     /* Name Textbox */
134     wxStaticText *name_label =
135            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
136
137     name_text = new wxTextCtrl( info_panel, Uri_Event,
138         wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
139         wxTE_PROCESS_ENTER );
140
141     sizer->Add( name_label, 0 , wxALIGN_LEFT |wxALL , 5  );
142     sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
143
144     /* Treeview */
145     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
146                                 wxSize(220,200),
147                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
148                                 wxTR_HIDE_ROOT );
149
150     sizer->Layout();
151     box_sizer->Add( sizer, 0, wxEXPAND, 5 );
152     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
153     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
154
155     info_panel->SetSizer( info_sizer );
156     info_sizer->Layout();
157     info_sizer->SetSizeHints( info_panel );
158
159     UpdateInfo();
160
161     return info_panel;
162 }
163
164 void ItemInfoDialog::UpdateInfo()
165 {
166     if( !info_root )
167     {
168        info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
169     }
170
171     /* Rebuild the tree */
172     for( int i = 0; i< p_item->input.i_categories ; i++)
173     {
174         wxTreeItemId cat = info_tree->AppendItem( info_root,
175                             wxU( p_item->input.pp_categories[i]->psz_name) );
176
177         for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
178         {
179            info_tree->AppendItem( cat , (wxString)
180                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
181                wxT(": ") +
182                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
183         }
184
185         info_tree->Expand( cat );
186     }
187 }
188
189 /*****************************************************************************
190  * Events methods.
191  *****************************************************************************/
192 void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
193 {
194     vlc_mutex_lock( &p_item->input.lock );
195     p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
196     p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
197     vlc_mutex_unlock( &p_item->input.lock );
198     EndModal( wxID_OK );
199 }
200
201 void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
202 {
203     EndModal( wxID_CANCEL );
204 }