]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/main_slider_manager.cpp
p( vlc.getInterfaces().getInterface( "wxwidgets" ).isBroken() ) = 1/2
[vlc] / modules / gui / wxwidgets / main_slider_manager.cpp
1 /*****************************************************************************
2  * slider_manager.cpp : Manage an input slider
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: timer.cpp 11981 2005-08-03 15:03:23Z xtophe $
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 "main_slider_manager.hpp"
25 #include "interface.hpp"
26
27 #include <vlc_meta.h>
28
29 /*****************************************************************************
30  * Constructor.
31  *****************************************************************************/
32 MainSliderManager::MainSliderManager( intf_thread_t *_p_intf,
33                                       Interface *_p_main_intf ) :
34         SliderManager( _p_intf )
35 {
36     p_main_intf = _p_main_intf;
37     _slider = p_main_intf->slider;
38 }
39
40 MainSliderManager::~MainSliderManager()
41 {
42     vlc_mutex_lock( &p_intf->change_lock );
43     if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
44     p_intf->p_sys->p_input = NULL;
45     vlc_mutex_unlock( &p_intf->change_lock );
46 }
47
48 /*****************************************************************************
49  * Private methods.
50  *****************************************************************************/
51
52 void MainSliderManager::UpdateInput()
53 {
54     playlist_t *p_playlist =
55             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
56                                                    FIND_ANYWHERE );
57     if( p_playlist != NULL )
58     {
59         LockPlaylist( p_intf->p_sys, p_playlist );
60         p_input = p_intf->p_sys->p_input = p_playlist->p_input;
61         if( p_intf->p_sys->p_input )
62              vlc_object_yield( p_intf->p_sys->p_input );
63         UnlockPlaylist( p_intf->p_sys, p_playlist );
64         vlc_object_release( p_playlist );
65     }
66 }
67
68 void MainSliderManager::UpdateNowPlaying()
69 {
70     char *psz_now_playing = vlc_input_item_GetInfo(
71     p_intf->p_sys->p_input->input.p_item,
72                 _("Meta-information"), _(VLC_META_NOW_PLAYING) );
73     if( psz_now_playing && *psz_now_playing )
74     {
75         p_main_intf->statusbar->SetStatusText(
76                     wxString(wxU(psz_now_playing)) + wxT( " - " ) +
77                     wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
78     }
79     else
80     {
81         p_main_intf->statusbar->SetStatusText(
82                    wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
83     }
84     free( psz_now_playing );
85 }
86
87 void MainSliderManager::UpdateButtons( vlc_bool_t b_play )
88 {
89     if( b_play )
90     {
91         p_main_intf->TogglePlayButton( PLAYING_S );
92 #ifdef wxHAS_TASK_BAR_ICON
93         if( p_main_intf->p_systray )
94         {
95             p_main_intf->p_systray->UpdateTooltip(
96                   wxU( p_intf->p_sys->p_input->input.p_item->psz_name ) +
97                   wxString(wxT(" - ")) + wxU(_("Playing")));
98         }
99 #endif
100     }
101     else
102     {
103         p_main_intf->TogglePlayButton( PAUSE_S );
104         p_main_intf->statusbar->SetStatusText( wxT(""), 0 );
105         p_main_intf->statusbar->SetStatusText( wxT(""), 2 );
106 #ifdef wxHAS_TASK_BAR_ICON
107         if( p_main_intf->p_systray )
108         {
109             p_main_intf->p_systray->UpdateTooltip( wxString(wxT("VLC media player - ")) + wxU(_("Stopped")) );
110         }
111 #endif
112     }
113 }
114
115 void MainSliderManager::HideControls()
116 {
117     p_main_intf->m_controls_timer.Start(200, wxTIMER_ONE_SHOT);
118 }
119
120 void MainSliderManager::DontHide()
121 {
122     p_main_intf->m_controls_timer.Stop();
123
124     /* New input or stream map change */
125     p_intf->p_sys->b_playing = VLC_TRUE;
126 }
127
128 void MainSliderManager::UpdateDiscButtons()
129 {
130     vlc_value_t val;
131     var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
132     if( val.i_int > 0 && !p_main_intf->disc_frame->IsShown() )
133     {
134         vlc_value_t val;
135
136         #define HELP_MENU N_("Menu")
137         #define HELP_PCH N_("Previous chapter")
138         #define HELP_NCH N_("Next chapter")
139         #define HELP_PTR N_("Previous track")
140         #define HELP_NTR N_("Next track")
141
142         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
143
144         if( val.i_int > 0 )
145         {
146             p_main_intf->disc_menu_button->Show();
147             p_main_intf->disc_sizer->Show(
148                         p_main_intf->disc_menu_button );
149             p_main_intf->disc_sizer->Layout();
150             p_main_intf->disc_sizer->Fit(
151             p_main_intf->disc_frame );
152             p_main_intf->disc_menu_button->SetToolTip(
153                         wxU(_( HELP_MENU ) ) );
154             p_main_intf->disc_prev_button->SetToolTip(
155                         wxU(_( HELP_PCH ) ) );
156             p_main_intf->disc_next_button->SetToolTip(
157                         wxU(_( HELP_NCH ) ) );
158         }
159         else
160         {
161             p_main_intf->disc_menu_button->Hide();
162             p_main_intf->disc_sizer->Hide(
163                         p_main_intf->disc_menu_button );
164             p_main_intf->disc_prev_button->SetToolTip(
165                         wxU(_( HELP_PTR ) ) );
166             p_main_intf->disc_next_button->SetToolTip(
167                         wxU(_( HELP_NTR ) ) );
168         }
169
170         p_main_intf->ShowDiscFrame();
171     }
172     else if( val.i_int == 0 && p_main_intf->disc_frame->IsShown() )
173     {
174         p_main_intf->HideDiscFrame();
175     }
176 }
177
178 vlc_bool_t MainSliderManager::IsShown()
179 {
180     return p_main_intf->slider_frame->IsShown();
181 }
182
183 void MainSliderManager::ShowSlider()
184 {
185     p_main_intf->ShowSlider();
186 }
187
188 void MainSliderManager::HideSlider()
189 {
190     p_main_intf->m_slider_timer.Start( 200, wxTIMER_ONE_SHOT );
191 }
192
193 vlc_bool_t MainSliderManager::IsFree()
194 {
195     return p_intf->p_sys->b_slider_free;
196 }
197
198 vlc_bool_t MainSliderManager::IsPlaying()
199 {
200     return p_intf->p_sys->b_playing;
201 }
202
203 void MainSliderManager::UpdateTime( char *psz_time, char *psz_total )
204 {
205     p_main_intf->statusbar->SetStatusText(
206                  wxU(psz_time) + wxString(wxT(" / ")) +wxU(psz_total), 0 );
207 }