| 80 | | } |
|---|
| 81 | | |
|---|
| 82 | | //TODO break that |
|---|
| | 91 | i_old_playing_status = END_S; |
|---|
| | 92 | old_name=qfu(""); |
|---|
| | 93 | artUrl = qfu(""); |
|---|
| | 94 | emit positionUpdated( 0.0, 0 ,0 ); |
|---|
| | 95 | emit statusChanged( END_S ); |
|---|
| | 96 | emit nameChanged( "" ); |
|---|
| | 97 | emit artChanged( "" ); |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | void InputManager::delCallbacks( void ) |
|---|
| | 101 | { |
|---|
| | 102 | var_DelCallback( p_input, "audio-es", ChangeAudio, this ); |
|---|
| | 103 | var_DelCallback( p_input, "video-es", ChangeVideo, this ); |
|---|
| | 104 | var_DelCallback( THEPL, "state", ItemStateChanged, this ); |
|---|
| | 105 | var_DelCallback( p_input, "rate", ItemRateChanged, this ); |
|---|
| | 106 | var_DelCallback( p_input, "title", ItemTitleChanged, this ); |
|---|
| | 107 | var_DelCallback( p_input, "intf-change", InterfaceChanged, this ); |
|---|
| | 108 | var_DelCallback( THEPL, "item-change", ItemChanged, this ); |
|---|
| | 109 | } |
|---|
| | 110 | |
|---|
| | 111 | void InputManager::addCallbacks( void ) |
|---|
| | 112 | { |
|---|
| | 113 | var_AddCallback( p_input, "audio-es", ChangeAudio, this ); |
|---|
| | 114 | var_AddCallback( p_input, "video-es", ChangeVideo, this ); |
|---|
| | 115 | /* src/playlist/control.c */ |
|---|
| | 116 | var_AddCallback( THEPL, "state", ItemStateChanged, this ); |
|---|
| | 117 | /* src/input/input.c:1765 */ |
|---|
| | 118 | var_AddCallback( p_input, "rate", ItemRateChanged, this ); |
|---|
| | 119 | /* src/input/input.c:2003 */ |
|---|
| | 120 | var_AddCallback( p_input, "title", ItemTitleChanged, this ); |
|---|
| | 121 | /* src/input/input.c:734 for timers update*/ |
|---|
| | 122 | var_AddCallback( p_input, "intf-change", InterfaceChanged, this ); |
|---|
| | 123 | /* src/input/input.c:2076*/ |
|---|
| | 124 | var_AddCallback( THEPL, "item-change", ItemChanged, this ); |
|---|
| | 125 | } |
|---|
| | 126 | |
|---|
| | 127 | static int InterfaceChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 128 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 129 | { |
|---|
| | 130 | static int counter = 0; |
|---|
| | 131 | InputManager *im = (InputManager*)param; |
|---|
| | 132 | |
|---|
| | 133 | counter = counter++ % 4; |
|---|
| | 134 | if(!counter) |
|---|
| | 135 | return VLC_SUCCESS; |
|---|
| | 136 | IMEvent *event = new IMEvent( PositionUpdate_Type, 0 ); |
|---|
| | 137 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 138 | return VLC_SUCCESS; |
|---|
| | 139 | } |
|---|
| | 140 | |
|---|
| | 141 | static int ItemStateChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 142 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 143 | { |
|---|
| | 144 | InputManager *im = (InputManager*)param; |
|---|
| | 145 | |
|---|
| | 146 | IMEvent *event = new IMEvent( ItemStateChanged_Type, 0 ); |
|---|
| | 147 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 148 | return VLC_SUCCESS; |
|---|
| | 149 | } |
|---|
| | 150 | |
|---|
| | 151 | static int ItemRateChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 152 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 153 | { |
|---|
| | 154 | InputManager *im = (InputManager*)param; |
|---|
| | 155 | |
|---|
| | 156 | IMEvent *event = new IMEvent( ItemRateChanged_Type, 0 ); |
|---|
| | 157 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 158 | return VLC_SUCCESS; |
|---|
| | 159 | } |
|---|
| | 160 | |
|---|
| | 161 | static int ItemTitleChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 162 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 163 | { |
|---|
| | 164 | InputManager *im = (InputManager*)param; |
|---|
| | 165 | |
|---|
| | 166 | IMEvent *event = new IMEvent( ItemTitleChanged_Type, 0 ); |
|---|
| | 167 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 168 | return VLC_SUCCESS; |
|---|
| | 169 | } |
|---|
| | 170 | |
|---|
| | 171 | static int InputChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 172 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 173 | { |
|---|
| | 174 | MainInputManager *im = (MainInputManager*)param; |
|---|
| | 175 | |
|---|
| | 176 | IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int ); |
|---|
| | 177 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 178 | return VLC_SUCCESS; |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | static int ItemChanged( vlc_object_t *p_this, const char *psz_var, |
|---|
| | 182 | vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| | 183 | { |
|---|
| | 184 | InputManager *im = (InputManager*)param; |
|---|
| | 185 | |
|---|
| | 186 | IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int ); |
|---|
| | 187 | QApplication::postEvent( im, static_cast<QEvent*>(event) ); |
|---|
| | 188 | return VLC_SUCCESS; |
|---|
| | 189 | } |
|---|
| | 190 | |
|---|
| | 191 | void InputManager::customEvent( QEvent *event ) |
|---|
| | 192 | { |
|---|
| | 193 | int type = event->type(); |
|---|
| | 194 | if ( type != PositionUpdate_Type && type != ItemChanged_Type && |
|---|
| | 195 | type != ItemRateChanged_Type && type != ItemTitleChanged_Type && |
|---|
| | 196 | type != ItemStateChanged_Type ) |
|---|
| | 197 | return; |
|---|
| | 198 | |
|---|
| | 199 | if(!p_input || p_input->b_dead || p_input->b_die ) |
|---|
| | 200 | { |
|---|
| | 201 | delInput(); |
|---|
| | 202 | return; |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | |
|---|
| | 206 | IMEvent *ime = static_cast<IMEvent *>(event); |
|---|
| | 207 | |
|---|
| | 208 | if ( type == PositionUpdate_Type ) |
|---|
| | 209 | { |
|---|
| | 210 | UpdatePosition(); |
|---|
| | 211 | } |
|---|
| | 212 | else if ( type == ItemChanged_Type ) |
|---|
| | 213 | { |
|---|
| | 214 | UpdateMeta(); |
|---|
| | 215 | } |
|---|
| | 216 | else if ( type == ItemRateChanged_Type ) |
|---|
| | 217 | { |
|---|
| | 218 | UpdatePosition(); |
|---|
| | 219 | } |
|---|
| | 220 | else if ( type == ItemTitleChanged_Type ) |
|---|
| | 221 | { |
|---|
| | 222 | UpdateTitle(); |
|---|
| | 223 | } |
|---|
| | 224 | else if (type == ItemStateChanged_Type ) |
|---|
| | 225 | { |
|---|
| | 226 | UpdateStatus(); |
|---|
| | 227 | } |
|---|
| | 228 | } |
|---|
| | 229 | |
|---|
| | 230 | void InputManager::UpdatePosition( void ) |
|---|
| | 231 | { |
|---|
| | 232 | /* Update position */ |
|---|
| | 233 | int i_length, i_time; /* Int is enough, since we store seconds */ |
|---|
| | 234 | float f_pos; |
|---|
| | 235 | i_length = var_GetTime( p_input , "length" ) / 1000000; |
|---|
| | 236 | i_time = var_GetTime( p_input , "time") / 1000000; |
|---|
| | 237 | f_pos = var_GetFloat( p_input , "position" ); |
|---|
| | 238 | emit positionUpdated( f_pos, i_time, i_length ); |
|---|
| | 239 | } |
|---|
| | 240 | |
|---|
| | 241 | void InputManager::UpdateTitle( void ) |
|---|
| | 242 | { |
|---|
| | 243 | /* Update navigation status */ |
|---|
| | 244 | vlc_value_t val; val.i_int = 0; |
|---|
| | 245 | var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL ); |
|---|
| | 246 | if( val.i_int > 0 ) |
|---|
| | 247 | { |
|---|
| | 248 | val.i_int = 0; |
|---|
| | 249 | var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL ); |
|---|
| | 250 | emit navigationChanged( (val.i_int > 0) ? 1 : 2 ); |
|---|
| | 251 | } |
|---|
| | 252 | else |
|---|
| | 253 | { |
|---|
| | 254 | emit navigationChanged( 0 ); |
|---|
| | 255 | } |
|---|
| | 256 | } |
|---|
| | 257 | |
|---|
| | 258 | void InputManager::UpdateStatus( void ) |
|---|
| | 259 | { |
|---|
| | 260 | /* Update playing status */ |
|---|
| | 261 | vlc_value_t val; val.i_int = 0; |
|---|
| | 262 | var_Get( p_input, "state", &val ); |
|---|
| | 263 | if( i_old_playing_status != val.i_int ) |
|---|
| | 264 | { |
|---|
| | 265 | i_old_playing_status = val.i_int; |
|---|
| | 266 | emit statusChanged( val.i_int ); |
|---|
| | 267 | } |
|---|
| | 268 | } |
|---|
| | 269 | |
|---|
| | 270 | void InputManager::UpdateRate( void ) |
|---|
| | 271 | { |
|---|
| | 272 | /* Update Rate */ |
|---|
| | 273 | int i_new_rate = var_GetInteger( p_input, "rate"); |
|---|
| | 274 | if( i_new_rate != i_rate ) |
|---|
| | 275 | { |
|---|
| | 276 | i_rate = i_new_rate; |
|---|
| | 277 | /* Update rate */ |
|---|
| | 278 | emit rateChanged( i_rate ); |
|---|
| | 279 | } |
|---|
| | 280 | } |
|---|
| | 281 | |
|---|
| | 282 | void InputManager::UpdateMeta( void ) |
|---|
| | 283 | { |
|---|
| | 284 | /* Update text */ |
|---|
| | 285 | QString text; |
|---|
| | 286 | char *psz_name = input_item_GetTitle( input_GetItem( p_input ) ); |
|---|
| | 287 | char *psz_nowplaying = |
|---|
| | 288 | input_item_GetNowPlaying( input_GetItem( p_input ) ); |
|---|
| | 289 | char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) ); |
|---|
| | 290 | if( EMPTY_STR( psz_name ) ) |
|---|
| | 291 | { |
|---|
| | 292 | free( psz_name ); |
|---|
| | 293 | psz_name = input_item_GetName( input_GetItem( p_input ) ); |
|---|
| | 294 | } |
|---|
| | 295 | if( !EMPTY_STR( psz_nowplaying ) ) |
|---|
| | 296 | { |
|---|
| | 297 | text.sprintf( "%s - %s", psz_nowplaying, psz_name ); |
|---|
| | 298 | } |
|---|
| | 299 | else if( !EMPTY_STR( psz_artist ) ) |
|---|
| | 300 | { |
|---|
| | 301 | text.sprintf( "%s - %s", psz_artist, psz_name ); |
|---|
| | 302 | } |
|---|
| | 303 | else |
|---|
| | 304 | { |
|---|
| | 305 | text.sprintf( "%s", psz_name ); |
|---|
| | 306 | } |
|---|
| | 307 | free( psz_name ); |
|---|
| | 308 | free( psz_nowplaying ); |
|---|
| | 309 | free( psz_artist ); |
|---|
| | 310 | if( old_name != text ) |
|---|
| | 311 | { |
|---|
| | 312 | emit nameChanged( text ); |
|---|
| | 313 | old_name=text; |
|---|
| | 314 | } |
|---|
| | 315 | |
|---|
| | 316 | QString url; |
|---|
| | 317 | char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) ); |
|---|
| | 318 | url.sprintf("%s", psz_art ); |
|---|
| | 319 | free( psz_art ); |
|---|
| | 320 | if( artUrl != url ) |
|---|
| | 321 | { |
|---|
| | 322 | artUrl = url.replace( "file://",QString("" ) ); |
|---|
| | 323 | emit artChanged( artUrl ); |
|---|
| | 324 | } |
|---|
| | 325 | #ifdef ZVBI_COMPILED |
|---|
| | 326 | /* Update teletext status*/ |
|---|
| | 327 | emit teletextEnabled( true );/* FIXME */ |
|---|
| | 328 | #endif |
|---|
| | 329 | |
|---|
| | 330 | } |
|---|
| | 331 | |
|---|
| 85 | | /// \todo Emit the signals only if it changed |
|---|
| 86 | | if( !p_input ) |
|---|
| 87 | | { |
|---|
| 88 | | emit nameChanged( "" ); |
|---|
| 89 | | return; |
|---|
| 90 | | } |
|---|
| 91 | | |
|---|
| 92 | | if( p_input->b_dead || p_input->b_die ) |
|---|
| 93 | | { |
|---|
| 94 | | emit positionUpdated( 0.0, 0, 0 ); |
|---|
| 95 | | emit navigationChanged( 0 ); |
|---|
| 96 | | i_old_playing_status = 0; |
|---|
| 97 | | emit statusChanged( END_S ); // see vlc_input.h, input_state_e enum |
|---|
| 98 | | delInput(); |
|---|
| 99 | | emit artChanged( "" ); |
|---|
| 100 | | return; |
|---|
| 101 | | } |
|---|
| 102 | | |
|---|
| 103 | | /* Update position */ |
|---|
| 104 | | int i_length, i_time; /* Int is enough, since we store seconds */ |
|---|
| 105 | | float f_pos; |
|---|
| 106 | | i_length = var_GetTime( p_input, "length" ) / 1000000; |
|---|
| 107 | | i_time = var_GetTime( p_input, "time") / 1000000; |
|---|
| 108 | | f_pos = var_GetFloat( p_input, "position" ); |
|---|
| 109 | | emit positionUpdated( f_pos, i_time, i_length ); |
|---|
| 110 | | |
|---|
| 111 | | /* Update Rate */ |
|---|
| 112 | | int i_new_rate = var_GetInteger( p_input, "rate"); |
|---|
| 113 | | if( i_new_rate != i_rate ) |
|---|
| 114 | | { |
|---|
| 115 | | i_rate = i_new_rate; |
|---|
| 116 | | /* Update rate */ |
|---|
| 117 | | emit rateChanged( i_rate ); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | /* Update navigation status */ |
|---|
| 121 | | vlc_value_t val; val.i_int = 0; |
|---|
| 122 | | var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL ); |
|---|
| 123 | | if( val.i_int > 0 ) |
|---|
| 124 | | { |
|---|
| 125 | | val.i_int = 0; |
|---|
| 126 | | var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL ); |
|---|
| 127 | | emit navigationChanged( (val.i_int > 0) ? 1 : 2 ); |
|---|
| 128 | | /*if( val.i_int > 0 ) |
|---|
| 129 | | { |
|---|
| 130 | | emit navigationChanged( 1 ); // 1 = chapter, 2 = title, 0 = NO |
|---|
| 131 | | } |
|---|
| 132 | | else |
|---|
| 133 | | { |
|---|
| 134 | | emit navigationChanged( 2 ); |
|---|
| 135 | | }*/ |
|---|
| 136 | | } |
|---|
| 137 | | else |
|---|
| 138 | | { |
|---|
| 139 | | emit navigationChanged( 0 ); |
|---|
| 140 | | } |
|---|
| 141 | | |
|---|
| 142 | | #ifdef ZVBI_COMPILED |
|---|
| 143 | | /* Update teletext status*/ |
|---|
| 144 | | emit teletextEnabled( true );/* FIXME */ |
|---|
| 145 | | #endif |
|---|
| 146 | | |
|---|
| 147 | | /* Update text */ |
|---|
| 148 | | QString text; |
|---|
| 149 | | char *psz_name = input_item_GetTitle( input_GetItem( p_input ) ); |
|---|
| 150 | | char *psz_nowplaying = |
|---|
| 151 | | input_item_GetNowPlaying( input_GetItem( p_input ) ); |
|---|
| 152 | | char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) ); |
|---|
| 153 | | if( EMPTY_STR( psz_name ) ) |
|---|
| 154 | | { |
|---|
| 155 | | free( psz_name ); |
|---|
| 156 | | psz_name = input_item_GetName( input_GetItem( p_input ) ); |
|---|
| 157 | | } |
|---|
| 158 | | if( !EMPTY_STR( psz_nowplaying ) ) |
|---|
| 159 | | { |
|---|
| 160 | | text.sprintf( "%s - %s", psz_nowplaying, psz_name ); |
|---|
| 161 | | } |
|---|
| 162 | | else if( !EMPTY_STR( psz_artist ) ) |
|---|
| 163 | | { |
|---|
| 164 | | text.sprintf( "%s - %s", psz_artist, psz_name ); |
|---|
| 165 | | } |
|---|
| 166 | | else |
|---|
| 167 | | { |
|---|
| 168 | | text.sprintf( "%s", psz_name ); |
|---|
| 169 | | } |
|---|
| 170 | | free( psz_name ); |
|---|
| 171 | | free( psz_nowplaying ); |
|---|
| 172 | | free( psz_artist ); |
|---|
| 173 | | if( old_name != text ) |
|---|
| 174 | | { |
|---|
| 175 | | emit nameChanged( text ); |
|---|
| 176 | | old_name=text; |
|---|
| 177 | | } |
|---|
| 178 | | |
|---|
| 179 | | /* Update playing status */ |
|---|
| 180 | | var_Get( p_input, "state", &val ); |
|---|
| 181 | | val.i_int = val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S; |
|---|
| 182 | | if( i_old_playing_status != val.i_int ) |
|---|
| 183 | | { |
|---|
| 184 | | i_old_playing_status = val.i_int; |
|---|
| 185 | | emit statusChanged( val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S ); |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | QString url; |
|---|
| 189 | | char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) ); |
|---|
| 190 | | url.sprintf("%s", psz_art ); |
|---|
| 191 | | free( psz_art ); |
|---|
| 192 | | if( artUrl != url ) |
|---|
| 193 | | { |
|---|
| 194 | | artUrl = url.replace( "file://",QString("" ) ); |
|---|
| 195 | | emit artChanged( artUrl ); |
|---|
| 196 | | } |
|---|
| | 334 | |
|---|