| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
#ifdef HAVE_CONFIG_H |
|---|
| 35 |
# include "config.h" |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
#include <vlc_common.h> |
|---|
| 39 |
|
|---|
| 40 |
#include <vlc_interface.h> |
|---|
| 41 |
#include "interface.h" |
|---|
| 42 |
#include "libvlc.h" |
|---|
| 43 |
|
|---|
| 44 |
#include <assert.h> |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
static interaction_t * InteractionGet( vlc_object_t * ); |
|---|
| 50 |
static void InteractionSearchInterface( interaction_t * ); |
|---|
| 51 |
static void* InteractionLoop( vlc_object_t * ); |
|---|
| 52 |
static void InteractionManage( interaction_t * ); |
|---|
| 53 |
|
|---|
| 54 |
static interaction_dialog_t *DialogGetById( interaction_t* , int ); |
|---|
| 55 |
static void DialogDestroy( interaction_dialog_t * ); |
|---|
| 56 |
static int DialogSend( vlc_object_t *, interaction_dialog_t * ); |
|---|
| 57 |
|
|---|
| 58 |
#define DIALOG_INIT( type ) \ |
|---|
| 59 |
DECMALLOC_ERR( p_new, interaction_dialog_t ); \ |
|---|
| 60 |
memset( p_new, 0, sizeof( interaction_dialog_t ) ); \ |
|---|
| 61 |
p_new->b_cancelled = false; \ |
|---|
| 62 |
p_new->i_status = NEW_DIALOG; \ |
|---|
| 63 |
p_new->i_flags = 0; \ |
|---|
| 64 |
p_new->i_type = INTERACT_DIALOG_##type; \ |
|---|
| 65 |
p_new->psz_returned[0] = NULL; \ |
|---|
| 66 |
p_new->psz_returned[1] = NULL |
|---|
| 67 |
|
|---|
| 68 |
#define FORMAT_DESC \ |
|---|
| 69 |
va_start( args, psz_format ); \ |
|---|
| 70 |
if( vasprintf( &p_new->psz_description, psz_format, args ) == -1 ) \ |
|---|
| 71 |
return VLC_EGENERIC; \ |
|---|
| 72 |
va_end( args ) |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
int __intf_UserFatal( vlc_object_t *p_this, bool b_blocking, |
|---|
| 84 |
const char *psz_title, |
|---|
| 85 |
const char *psz_format, ... ) |
|---|
| 86 |
{ |
|---|
| 87 |
va_list args; |
|---|
| 88 |
DIALOG_INIT( ONEWAY ); |
|---|
| 89 |
|
|---|
| 90 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 91 |
FORMAT_DESC; |
|---|
| 92 |
|
|---|
| 93 |
if( b_blocking ) |
|---|
| 94 |
p_new->i_flags = DIALOG_BLOCKING_ERROR; |
|---|
| 95 |
else |
|---|
| 96 |
p_new->i_flags = DIALOG_NONBLOCKING_ERROR; |
|---|
| 97 |
|
|---|
| 98 |
return DialogSend( p_this, p_new ); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
int __intf_UserWarn( vlc_object_t *p_this, |
|---|
| 110 |
const char *psz_title, |
|---|
| 111 |
const char *psz_format, ... ) |
|---|
| 112 |
{ |
|---|
| 113 |
va_list args; |
|---|
| 114 |
DIALOG_INIT( ONEWAY ); |
|---|
| 115 |
|
|---|
| 116 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 117 |
FORMAT_DESC; |
|---|
| 118 |
|
|---|
| 119 |
p_new->i_flags = DIALOG_WARNING; |
|---|
| 120 |
|
|---|
| 121 |
return DialogSend( p_this, p_new ); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
int __intf_UserYesNo( vlc_object_t *p_this, |
|---|
| 136 |
const char *psz_title, |
|---|
| 137 |
const char *psz_description, |
|---|
| 138 |
const char *psz_default, |
|---|
| 139 |
const char *psz_alternate, |
|---|
| 140 |
const char *psz_other ) |
|---|
| 141 |
{ |
|---|
| 142 |
DIALOG_INIT( TWOWAY ); |
|---|
| 143 |
|
|---|
| 144 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 145 |
p_new->psz_description = strdup( psz_description ); |
|---|
| 146 |
p_new->i_flags = DIALOG_YES_NO_CANCEL; |
|---|
| 147 |
p_new->psz_default_button = strdup( psz_default ); |
|---|
| 148 |
p_new->psz_alternate_button = strdup( psz_alternate ); |
|---|
| 149 |
if( psz_other ) |
|---|
| 150 |
p_new->psz_other_button = strdup( psz_other ); |
|---|
| 151 |
|
|---|
| 152 |
return DialogSend( p_this, p_new ); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
int __intf_Progress( vlc_object_t *p_this, const char *psz_title, |
|---|
| 166 |
const char *psz_status, float f_pos, int i_time ) |
|---|
| 167 |
{ |
|---|
| 168 |
DIALOG_INIT( ONEWAY ); |
|---|
| 169 |
p_new->psz_description = strdup( psz_status ); |
|---|
| 170 |
p_new->val.f_float = f_pos; |
|---|
| 171 |
p_new->i_timeToGo = i_time; |
|---|
| 172 |
p_new->psz_alternate_button = strdup( _( "Cancel" ) ); |
|---|
| 173 |
|
|---|
| 174 |
if( psz_title ) |
|---|
| 175 |
{ |
|---|
| 176 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 177 |
p_new->i_flags = DIALOG_USER_PROGRESS; |
|---|
| 178 |
} |
|---|
| 179 |
else |
|---|
| 180 |
p_new->i_flags = DIALOG_INTF_PROGRESS; |
|---|
| 181 |
|
|---|
| 182 |
DialogSend( p_this, p_new ); |
|---|
| 183 |
return p_new->i_id; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
void __intf_ProgressUpdate( vlc_object_t *p_this, int i_id, |
|---|
| 197 |
const char *psz_status, float f_pos, int i_time ) |
|---|
| 198 |
{ |
|---|
| 199 |
interaction_t *p_interaction = InteractionGet( p_this ); |
|---|
| 200 |
interaction_dialog_t *p_dialog; |
|---|
| 201 |
|
|---|
| 202 |
if( !p_interaction ) return; |
|---|
| 203 |
|
|---|
| 204 |
vlc_object_lock( p_interaction ); |
|---|
| 205 |
p_dialog = DialogGetById( p_interaction, i_id ); |
|---|
| 206 |
|
|---|
| 207 |
if( !p_dialog ) |
|---|
| 208 |
{ |
|---|
| 209 |
vlc_object_unlock( p_interaction ); |
|---|
| 210 |
vlc_object_release( p_interaction ); |
|---|
| 211 |
return; |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
free( p_dialog->psz_description ); |
|---|
| 215 |
p_dialog->psz_description = strdup( psz_status ); |
|---|
| 216 |
|
|---|
| 217 |
p_dialog->val.f_float = f_pos; |
|---|
| 218 |
p_dialog->i_timeToGo = i_time; |
|---|
| 219 |
|
|---|
| 220 |
p_dialog->i_status = UPDATED_DIALOG; |
|---|
| 221 |
|
|---|
| 222 |
vlc_object_signal_unlocked( p_interaction ); |
|---|
| 223 |
vlc_object_unlock( p_interaction ); |
|---|
| 224 |
vlc_object_release( p_interaction ); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
bool __intf_UserProgressIsCancelled( vlc_object_t *p_this, int i_id ) |
|---|
| 236 |
{ |
|---|
| 237 |
interaction_t *p_interaction = InteractionGet( p_this ); |
|---|
| 238 |
interaction_dialog_t *p_dialog; |
|---|
| 239 |
bool b_cancel; |
|---|
| 240 |
|
|---|
| 241 |
if( !p_interaction ) return true; |
|---|
| 242 |
|
|---|
| 243 |
vlc_object_lock( p_interaction ); |
|---|
| 244 |
p_dialog = DialogGetById( p_interaction, i_id ); |
|---|
| 245 |
if( !p_dialog ) |
|---|
| 246 |
{ |
|---|
| 247 |
vlc_object_unlock( p_interaction ) ; |
|---|
| 248 |
vlc_object_release( p_interaction ); |
|---|
| 249 |
return true; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
b_cancel = p_dialog->b_cancelled; |
|---|
| 253 |
vlc_object_unlock( p_interaction ); |
|---|
| 254 |
vlc_object_release( p_interaction ); |
|---|
| 255 |
return b_cancel; |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
int __intf_UserLoginPassword( vlc_object_t *p_this, |
|---|
| 269 |
const char *psz_title, |
|---|
| 270 |
const char *psz_description, |
|---|
| 271 |
char **ppsz_login, |
|---|
| 272 |
char **ppsz_password ) |
|---|
| 273 |
{ |
|---|
| 274 |
int i_ret; |
|---|
| 275 |
DIALOG_INIT( TWOWAY ); |
|---|
| 276 |
p_new->i_type = INTERACT_DIALOG_TWOWAY; |
|---|
| 277 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 278 |
p_new->psz_description = strdup( psz_description ); |
|---|
| 279 |
p_new->psz_default_button = strdup( _("OK" ) ); |
|---|
| 280 |
p_new->psz_alternate_button = strdup( _("Cancel" ) ); |
|---|
| 281 |
|
|---|
| 282 |
p_new->i_flags = DIALOG_LOGIN_PW_OK_CANCEL; |
|---|
| 283 |
|
|---|
| 284 |
i_ret = DialogSend( p_this, p_new ); |
|---|
| 285 |
|
|---|
| 286 |
if( i_ret != DIALOG_CANCELLED && i_ret != VLC_EGENERIC ) |
|---|
| 287 |
{ |
|---|
| 288 |
*ppsz_login = p_new->psz_returned[0]? |
|---|
| 289 |
strdup( p_new->psz_returned[0] ) : NULL; |
|---|
| 290 |
*ppsz_password = p_new->psz_returned[1]? |
|---|
| 291 |
strdup( p_new->psz_returned[1] ) : NULL; |
|---|
| 292 |
} |
|---|
| 293 |
return i_ret; |
|---|
| 294 |
} |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
int __intf_UserStringInput( vlc_object_t *p_this, |
|---|
| 306 |
const char *psz_title, |
|---|
| 307 |
const char *psz_description, |
|---|
| 308 |
char **ppsz_usersString ) |
|---|
| 309 |
{ |
|---|
| 310 |
int i_ret; |
|---|
| 311 |
DIALOG_INIT( TWOWAY ); |
|---|
| 312 |
p_new->i_type = INTERACT_DIALOG_TWOWAY; |
|---|
| 313 |
p_new->psz_title = strdup( psz_title ); |
|---|
| 314 |
p_new->psz_description = strdup( psz_description ); |
|---|
| 315 |
|
|---|
| 316 |
p_new->i_flags = DIALOG_PSZ_INPUT_OK_CANCEL; |
|---|
| 317 |
|
|---|
| 318 |
i_ret = DialogSend( p_this, p_new ); |
|---|
| 319 |
|
|---|
| 320 |
if( i_ret != DIALOG_CANCELLED ) |
|---|
| 321 |
{ |
|---|
| 322 |
*ppsz_usersString = p_new->psz_returned[0]? |
|---|
| 323 |
strdup( p_new->psz_returned[0] ) : NULL; |
|---|
| 324 |
} |
|---|
| 325 |
return i_ret; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
void __intf_UserHide( vlc_object_t *p_this, int i_id ) |
|---|
| 336 |
{ |
|---|
| 337 |
interaction_t *p_interaction = InteractionGet( p_this ); |
|---|
| 338 |
interaction_dialog_t *p_dialog; |
|---|
| 339 |
|
|---|
| 340 |
if( !p_interaction ) return; |
|---|
| 341 |
|
|---|
| 342 |
vlc_object_lock( p_interaction ); |
|---|
| 343 |
p_dialog = DialogGetById( p_interaction, i_id ); |
|---|
| 344 |
|
|---|
| 345 |
if( p_dialog ) |
|---|
| 346 |
{ |
|---|
| 347 |
p_dialog->i_status = ANSWERED_DIALOG; |
|---|
| 348 |
vlc_object_signal_unlocked( p_interaction ); |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
vlc_object_unlock( p_interaction ); |
|---|
| 352 |
vlc_object_release( p_interaction ); |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
interaction_t * interaction_Init( libvlc_int_t *p_libvlc ) |
|---|
| 362 |
{ |
|---|
| 363 |
interaction_t *p_interaction; |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
assert( libvlc_priv(p_libvlc)->p_interaction == NULL ); |
|---|
| 367 |
|
|---|
| 368 |
p_interaction = vlc_custom_create( VLC_OBJECT(p_libvlc), |
|---|
| 369 |
sizeof( *p_interaction ), |
|---|
| 370 |
VLC_OBJECT_GENERIC, "interaction" ); |
|---|
| 371 |
if( !p_interaction ) |
|---|
| 372 |
return NULL; |
|---|
| 373 |
|
|---|
| 374 |
vlc_object_attach( p_interaction, p_libvlc ); |
|---|
| 375 |
p_interaction->i_dialogs = 0; |
|---|
| 376 |
p_interaction->pp_dialogs = NULL; |
|---|
| 377 |
p_interaction->p_intf = NULL; |
|---|
| 378 |
p_interaction->i_last_id = 0; |
|---|
| 379 |
|
|---|
| 380 |
if( vlc_thread_create( p_interaction, "Interaction control", |
|---|
| 381 |
InteractionLoop, VLC_THREAD_PRIORITY_LOW, |
|---|
| 382 |
false ) ) |
|---|
| 383 |
{ |
|---|
| 384 |
msg_Err( p_interaction, "Interaction control thread creation failed, " |
|---|
| 385 |
"interaction will not be displayed" ); |
|---|
| 386 |
vlc_object_detach( p_interaction ); |
|---|
| 387 |
vlc_object_release( p_interaction ); |
|---|
| 388 |
return NULL; |
|---|
| 389 |
} |
|---|
| 390 |
|
|---|
| 391 |
return p_interaction; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
void interaction_Destroy( interaction_t *p_interaction ) |
|---|
| 395 |
{ |
|---|
| 396 |
if( !p_interaction ) |
|---|
| 397 |
return; |
|---|
| 398 |
|
|---|
| 399 |
vlc_object_kill( p_interaction ); |
|---|
| 400 |
vlc_thread_join( p_interaction ); |
|---|
| 401 |
vlc_object_release( p_interaction ); |
|---|
| 402 |
} |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
static interaction_t * InteractionGet( vlc_object_t *p_this ) |
|---|
| 410 |
{ |
|---|
| 411 |
interaction_t *obj = libvlc_priv(p_this->p_libvlc)->p_interaction; |
|---|
| 412 |
if( obj ) |
|---|
| 413 |
vlc_object_hold( obj ); |
|---|
| 414 |
return obj; |
|---|
| 415 |
} |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
static void InteractionSearchInterface( interaction_t *p_interaction ) |
|---|
| 420 |
{ |
|---|
| 421 |
vlc_list_t *p_list; |
|---|
| 422 |
int i_index; |
|---|
| 423 |
|
|---|
| 424 |
p_interaction->p_intf = NULL; |
|---|
| 425 |
|
|---|
| 426 |
p_list = vlc_list_find( p_interaction, VLC_OBJECT_INTF, FIND_ANYWHERE ); |
|---|
| 427 |
if( !p_list ) |
|---|
| 428 |
{ |
|---|
| 429 |
msg_Err( p_interaction, "unable to create module list" ); |
|---|
| 430 |
return; |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
for( i_index = 0; i_index < p_list->i_count; i_index ++ ) |
|---|
| 434 |
{ |
|---|
| 435 |
intf_thread_t *p_intf = (intf_thread_t *) |
|---|
| 436 |
p_list->p_values[i_index].p_object; |
|---|
| 437 |
if( p_intf->b_interaction ) |
|---|
| 438 |
{ |
|---|
| 439 |
p_interaction->p_intf = p_intf; |
|---|
| 440 |
break; |
|---|
| 441 |
} |
|---|
| 442 |
} |
|---|
| 443 |
vlc_list_release ( p_list ); |
|---|
| 444 |
} |
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
static interaction_dialog_t *DialogGetById( interaction_t *p_interaction, |
|---|
| 448 |
int i_id ) |
|---|
| 449 |
{ |
|---|
| 450 |
int i; |
|---|
| 451 |
for( i = 0 ; i< p_interaction->i_dialogs; i++ ) |
|---|
| 452 |
{ |
|---|
| 453 |
if( p_interaction->pp_dialogs[i]->i_id == i_id ) |
|---|
| 454 |
return p_interaction->pp_dialogs[i]; |
|---|
| 455 |
} |
|---|
| 456 |
return NULL; |
|---|
| 457 |
} |
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
static void DialogDestroy( interaction_dialog_t *p_dialog ) |
|---|
| 461 |
{ |
|---|
| 462 |
free( p_dialog->psz_title ); |
|---|
| 463 |
free( p_dialog->psz_description ); |
|---|
| 464 |
free( p_dialog->psz_default_button ); |
|---|
| 465 |
free( p_dialog->psz_alternate_button ); |
|---|
| 466 |
free( p_dialog->psz_other_button ); |
|---|
| 467 |
free( p_dialog ); |
|---|
| 468 |
} |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog ) |
|---|
| 473 |
{ |
|---|
| 474 |
interaction_t *p_interaction = InteractionGet( p_this ); |
|---|
| 475 |
|
|---|
| 476 |
if( !p_interaction ) |
|---|
| 477 |
return VLC_EGENERIC; |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
vlc_object_lock( p_interaction ); |
|---|
| 481 |
if( p_dialog->i_id == 0 ) |
|---|
| 482 |
p_dialog->i_id = ++p_interaction->i_last_id; |
|---|
| 483 |
vlc_object_unlock( p_interaction ); |
|---|
| 484 |
|
|---|
| 485 |
if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT ) |
|---|
| 486 |
{ |
|---|
| 487 |
vlc_object_release( p_interaction ); |
|---|
| 488 |
return VLC_EGENERIC; |
|---|
| 489 |
} |
|---|
| 490 |
|
|---|
| 491 |
if( config_GetInt( p_this, "interact" ) || |
|---|
| 492 |
p_dialog->i_flags & DIALOG_BLOCKING_ERROR || |
|---|
| 493 |
p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR ) |
|---|
| 494 |
{ |
|---|
| 495 |
bool b_found = false; |
|---|
| 496 |
int i; |
|---|
| 497 |
p_dialog->p_interaction = p_interaction; |
|---|
| 498 |
p_dialog->p_parent = p_this; |
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
vlc_object_lock( p_interaction ); |
|---|
| 502 |
for( i = 0 ; i< p_interaction->i_dialogs; i++ ) |
|---|
| 503 |
{ |
|---|
| 504 |
if( p_interaction->pp_dialogs[i]->i_id == p_dialog->i_id ) |
|---|
| 505 |
b_found = true; |
|---|
| 506 |
} |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
if( ! b_found ) |
|---|
| 510 |
{ |
|---|
| 511 |
INSERT_ELEM( p_interaction->pp_dialogs, |
|---|
| 512 |
p_interaction->i_dialogs, |
|---|
| 513 |
p_interaction->i_dialogs, |
|---|
| 514 |
p_dialog ); |
|---|
| 515 |
} |
|---|
| 516 |
else |
|---|
| 517 |
p_dialog->i_status = UPDATED_DIALOG; |
|---|
| 518 |
|
|---|
| 519 |
if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY ) |
|---|
| 520 |
{ |
|---|
| 521 |
vlc_object_signal_unlocked( p_interaction ); |
|---|
| 522 |
while( p_dialog->i_status != ANSWERED_DIALOG && |
|---|
| 523 |
p_dialog->i_status != HIDING_DIALOG && |
|---|
| 524 |
p_dialog->i_status != HIDDEN_DIALOG && |
|---|
| 525 |
!p_dialog->p_parent->b_die ) |
|---|
| 526 |
{ |
|---|
| 527 |
vlc_object_unlock( p_interaction ); |
|---|
| 528 |
msleep( 100000 ); |
|---|
| 529 |
vlc_object_lock( p_interaction ); |
|---|
| 530 |
} |
|---|
| 531 |
if( p_dialog->p_parent->b_die ) |
|---|
| 532 |
{ |
|---|
| 533 |
p_dialog->i_return = DIALOG_CANCELLED; |
|---|
| 534 |
p_dialog->i_status = ANSWERED_DIALOG; |
|---|
| 535 |
} |
|---|
| 536 |
p_dialog->i_flags |= DIALOG_GOT_ANSWER; |
|---|
| 537 |
vlc_object_signal_unlocked( p_interaction ); |
|---|
| 538 |
vlc_object_unlock( p_interaction ); |
|---|
| 539 |
vlc_object_release( p_interaction ); |
|---|
| 540 |
return p_dialog->i_return; |
|---|
| 541 |
} |
|---|
| 542 |
else |
|---|
| 543 |
{ |
|---|
| 544 |
|
|---|
| 545 |
p_dialog->i_flags |= DIALOG_GOT_ANSWER; |
|---|
| 546 |
vlc_object_signal_unlocked( p_interaction ); |
|---|
| 547 |
vlc_object_unlock( p_interaction ); |
|---|
| 548 |
vlc_object_release( p_interaction ); |
|---|
| 549 |
return VLC_SUCCESS; |
|---|
| 550 |
} |
|---|
| 551 |
} |
|---|
| 552 |
else |
|---|
| 553 |
{ |
|---|
| 554 |
vlc_object_release( p_interaction ); |
|---|
| 555 |
return VLC_EGENERIC; |
|---|
| 556 |
} |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
static void* InteractionLoop( vlc_object_t *p_this ) |
|---|
| 560 |
{ |
|---|
| 561 |
interaction_t *p_interaction = (interaction_t*) p_this; |
|---|
| 562 |
int canc = vlc_savecancel (); |
|---|
| 563 |
|
|---|
| 564 |
vlc_object_lock( p_this ); |
|---|
| 565 |
while( vlc_object_alive( p_this ) ) |
|---|
| 566 |
{ |
|---|
| 567 |
InteractionManage( p_interaction ); |
|---|
| 568 |
vlc_object_wait( p_this ); |
|---|
| 569 |
} |
|---|
| 570 |
vlc_object_unlock( p_this ); |
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
for( int i = p_interaction->i_dialogs -1 ; i >= 0; i-- ) |
|---|
| 574 |
{ |
|---|
| 575 |
interaction_dialog_t * p_dialog = p_interaction->pp_dialogs[i]; |
|---|
| 576 |
DialogDestroy( p_dialog ); |
|---|
| 577 |
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i ); |
|---|
| 578 |
} |
|---|
| 579 |
vlc_restorecancel (canc); |
|---|
| 580 |
return NULL; |
|---|
| 581 |
} |
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
static void InteractionManage( interaction_t *p_interaction ) |
|---|
| 591 |
{ |
|---|
| 592 |
vlc_value_t val; |
|---|
| 593 |
int i_index; |
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
if( p_interaction->i_dialogs == 0 ) return; |
|---|
| 597 |
|
|---|
| 598 |
InteractionSearchInterface( p_interaction ); |
|---|
| 599 |
if( !p_interaction->p_intf ) |
|---|
| 600 |
{ |
|---|
| 601 |
|
|---|
| 602 |
for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) |
|---|
| 603 |
{ |
|---|
| 604 |
interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index]; |
|---|
| 605 |
p_dialog->i_return = DIALOG_DEFAULT; |
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
if( p_dialog->i_status == HIDDEN_DIALOG ) |
|---|
| 609 |
p_dialog->i_status = DESTROYED_DIALOG; |
|---|
| 610 |
else |
|---|
| 611 |
p_dialog->i_status = HIDING_DIALOG; |
|---|
| 612 |
} |
|---|
| 613 |
} |
|---|
| 614 |
else |
|---|
| 615 |
vlc_object_hold( p_interaction->p_intf ); |
|---|
| 616 |
|
|---|
| 617 |
for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) |
|---|
| 618 |
{ |
|---|
| 619 |
interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index]; |
|---|
| 620 |
switch( p_dialog->i_status ) |
|---|
| 621 |
{ |
|---|
| 622 |
case ANSWERED_DIALOG: |
|---|
| 623 |
|
|---|
| 624 |
p_dialog->i_action = INTERACT_HIDE; |
|---|
| 625 |
val.p_address = p_dialog; |
|---|
| 626 |
if( p_interaction->p_intf ) |
|---|
| 627 |
var_Set( p_interaction->p_intf, "interaction", val ); |
|---|
| 628 |
p_dialog->i_status = HIDING_DIALOG; |
|---|
| 629 |
break; |
|---|
| 630 |
case UPDATED_DIALOG: |
|---|
| 631 |
p_dialog->i_action = INTERACT_UPDATE; |
|---|
| 632 |
val.p_address = p_dialog; |
|---|
| 633 |
if( p_interaction->p_intf ) |
|---|
| 634 |
var_Set( p_interaction->p_intf, "interaction", val ); |
|---|
| 635 |
p_dialog->i_status = SENT_DIALOG; |
|---|
| 636 |
break; |
|---|
| 637 |
case HIDDEN_DIALOG: |
|---|
| 638 |
if( !(p_dialog->i_flags & DIALOG_GOT_ANSWER) ) break; |
|---|
| 639 |
p_dialog->i_action = INTERACT_DESTROY; |
|---|
| 640 |
val.p_address = p_dialog; |
|---|
| 641 |
if( p_interaction->p_intf ) |
|---|
| 642 |
var_Set( p_interaction->p_intf, "interaction", val ); |
|---|
| 643 |
break; |
|---|
| 644 |
case DESTROYED_DIALOG: |
|---|
| 645 |
|
|---|
| 646 |
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, |
|---|
| 647 |
i_index); |
|---|
| 648 |
i_index--; |
|---|
| 649 |
DialogDestroy( p_dialog ); |
|---|
| 650 |
break; |
|---|
| 651 |
case NEW_DIALOG: |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
p_dialog->i_action = INTERACT_NEW; |
|---|
| 655 |
val.p_address = p_dialog; |
|---|
| 656 |
if( p_interaction->p_intf ) |
|---|
| 657 |
var_Set( p_interaction->p_intf, "interaction", val ); |
|---|
| 658 |
p_dialog->i_status = SENT_DIALOG; |
|---|
| 659 |
break; |
|---|
| 660 |
} |
|---|
| 661 |
} |
|---|
| 662 |
|
|---|
| 663 |
if( p_interaction->p_intf ) |
|---|
| 664 |
vlc_object_release( p_interaction->p_intf ); |
|---|
| 665 |
} |
|---|