]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/updatevlc.cpp
Might fix a bit update layout in win32
[vlc] / modules / gui / wxwidgets / dialogs / updatevlc.cpp
1 /*****************************************************************************
2  * updatevlc.cpp : VLC Update checker
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "updatevlc.hpp"
28 #include <wx/imaglist.h>
29
30 #include "bitmaps/update_ascii.xpm"
31 #include "bitmaps/update_binary.xpm"
32 #include "bitmaps/update_document.xpm"
33 #include "bitmaps/update_info.xpm"
34 #include "bitmaps/update_source.xpm"
35
36 /*****************************************************************************
37  * Event Table.
38  *****************************************************************************/
39
40 /* IDs for the controls and the menu commands */
41 enum
42 {
43     Close_Event,
44     CheckForUpdate_Event,
45     ChooseItem_Event
46 };
47
48 BEGIN_EVENT_TABLE(UpdateVLC, wxFrame)
49     /* Button events */
50     EVT_BUTTON(wxID_OK, UpdateVLC::OnButtonClose)
51     EVT_BUTTON(CheckForUpdate_Event, UpdateVLC::OnCheckForUpdate)
52
53     /* CtrlList events */
54     EVT_LIST_ITEM_ACTIVATED( ChooseItem_Event, UpdateVLC::OnChooseItem )
55
56     /* Hide the window when the user closes the window */
57     EVT_CLOSE(UpdateVLC::OnClose)
58
59 END_EVENT_TABLE()
60
61 /*****************************************************************************
62  * Constructor.
63  *****************************************************************************/
64 UpdateVLC::UpdateVLC( intf_thread_t *_p_intf, wxWindow *p_parent ):
65     wxFrame( p_parent, -1, wxU(_("VLC media player - Updates")),
66              wxDefaultPosition, wxDefaultSize,
67          wxSYSTEM_MENU|wxCLOSE_BOX|wxFRAME_FLOAT_ON_PARENT|wxFRAME_TOOL_WINDOW)
68 {
69     /* Initializations */
70     p_intf = _p_intf;
71     SetIcon( *p_intf->p_sys->p_icon );
72     SetAutoLayout( TRUE );
73
74     panel = new wxPanel( this, -1 );
75     panel->SetAutoLayout( TRUE );
76
77     main_sizer = new wxBoxSizer( wxVERTICAL );
78     panel_sizer = new wxBoxSizer( wxVERTICAL );
79
80     update_button =  new wxButton( panel, CheckForUpdate_Event,
81                       wxU(_("Check for updates")) );
82     panel_sizer->Add( update_button, 0, wxALL, 5 );
83     panel_sizer->Layout();
84     panel->SetSizerAndFit( panel_sizer );
85     main_sizer->Add( panel_sizer );
86     main_sizer->Layout();
87     SetSizer( main_sizer );
88     Fit( );
89
90     p_u = update_New( p_intf );
91 }
92
93
94 UpdateVLC::~UpdateVLC()
95 {
96     update_Delete( p_u );
97 }
98
99 void UpdateVLC::OnButtonClose( wxCommandEvent& event )
100 {
101     wxCloseEvent cevent;
102     OnClose(cevent);
103 }
104
105 void UpdateVLC::OnClose( wxCloseEvent& WXUNUSED(event) )
106 {
107     Hide();
108 }
109
110 void UpdateVLC::OnCheckForUpdate( wxCommandEvent& event )
111 {
112     update_Check( p_u, VLC_FALSE );
113     update_iterator_t *p_uit = update_iterator_New( p_u );
114     if( p_uit )
115     {
116         panel_sizer->Remove( update_button );
117         panel->DestroyChildren();
118
119         p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
120         p_uit->i_t = UPDATE_FILE_TYPE_ALL;
121         update_iterator_Action( p_uit, UPDATE_MIRROR );
122
123
124         wxListCtrl *list =
125             new wxListCtrl( panel, ChooseItem_Event,
126                             wxDefaultPosition, wxSize( 400, 300 ),
127                             wxLC_AUTOARRANGE|wxLC_SINGLE_SEL );
128         wxImageList *images = new wxImageList( 32, 32, TRUE );
129         images->Add( wxIcon( update_ascii_xpm ) );
130         images->Add( wxIcon( update_info_xpm ) );
131         images->Add( wxIcon( update_source_xpm ) );
132         images->Add( wxIcon( update_binary_xpm ) );
133         images->Add( wxIcon( update_document_xpm ) );
134         list->AssignImageList( images, wxIMAGE_LIST_SMALL );
135         while( update_iterator_Action( p_uit, UPDATE_FILE ) != UPDATE_FAIL )
136         {
137             int i_image;
138             switch( p_uit->file.i_type )
139             {
140                 case UPDATE_FILE_TYPE_INFO:
141                     i_image = 1;
142                     break;
143                 case UPDATE_FILE_TYPE_SOURCE:
144                     i_image = 2;
145                     break;
146                 case UPDATE_FILE_TYPE_BINARY:
147                     i_image = 3;
148                     break;
149                 case UPDATE_FILE_TYPE_PLUGIN:
150                     i_image = 4;
151                     break;
152                 default:
153                     i_image = 0;
154             }
155             list->InsertItem( list->GetItemCount(),
156                               wxU(p_uit->file.psz_description)+wxU("\n")
157                               + wxU(p_uit->release.psz_version)+wxU(" (")
158                               + wxU(p_uit->release.psz_svn_revision)+wxU(")"),
159                               i_image );
160         }
161
162         panel_sizer->Add( new wxStaticText( panel, -1, wxU( _("\nAvailable updates and related downloads:\n(Double click on a file to download it)\n" ) ) ) );
163         panel_sizer->Add( list, 0, wxALL, 5 );
164         panel_sizer->Layout();
165         panel->SetSizerAndFit( panel_sizer );
166         main_sizer->Layout();
167         SetSizerAndFit( main_sizer );
168
169         update_iterator_Delete( p_uit );
170     }
171 }
172
173 void UpdateVLC::OnChooseItem( wxListEvent& event )
174 {
175     update_iterator_t *p_uit = update_iterator_New( p_u );
176     if( p_uit )
177     {
178         p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
179         p_uit->i_t = UPDATE_FILE_TYPE_ALL;
180         update_iterator_Action( p_uit, UPDATE_MIRROR );
181
182         int i_count = 0;
183         while( update_iterator_Action( p_uit, UPDATE_FILE ) != UPDATE_FAIL )
184         {
185             if( i_count == event.GetIndex() )
186                 break;
187             i_count++;
188         }
189         wxString url = wxU( p_uit->file.psz_url );
190         wxFileDialog *filedialog =
191                     new wxFileDialog( this, wxU(_("Save file...")),
192                         wxT(""), url.AfterLast( '/' ), wxT("*.*"),
193                         wxSAVE | wxOVERWRITE_PROMPT );
194         if( filedialog->ShowModal() == wxID_OK )
195         {
196             update_download( p_uit, filedialog->GetPath().mb_str() );
197         }
198         update_iterator_Delete( p_uit );
199         delete filedialog;
200     }
201 }