Mercurial > audlegacy-plugins
comparison src/streambrowser/streambrowser.c @ 2848:fbb32674bfd2
click on a stream updates; more comments; more proper stream icons
| author | Calin Crisan ccrisan@gmail.com |
|---|---|
| date | Mon, 28 Jul 2008 23:43:31 +0300 |
| parents | 779125caa3ac |
| children | 587b3657990d |
comparison
equal
deleted
inserted
replaced
| 2845:d0cbf303869b | 2848:fbb32674bfd2 |
|---|---|
| 32 | 32 |
| 33 typedef struct { | 33 typedef struct { |
| 34 streamdir_t *streamdir; | 34 streamdir_t *streamdir; |
| 35 category_t *category; | 35 category_t *category; |
| 36 streaminfo_t *streaminfo; | 36 streaminfo_t *streaminfo; |
| 37 gboolean add_to_playlist; | |
| 37 } update_thread_data_t; | 38 } update_thread_data_t; |
| 38 | 39 |
| 39 | 40 |
| 40 static void sb_init(); | 41 static void sb_init(); |
| 41 static void sb_about(); | 42 static void sb_about(); |
| 45 static void gui_init(); | 46 static void gui_init(); |
| 46 static void gui_done(); | 47 static void gui_done(); |
| 47 static void config_load(); | 48 static void config_load(); |
| 48 static void config_save(); | 49 static void config_save(); |
| 49 | 50 |
| 50 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo); | 51 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist); |
| 51 static gpointer update_thread_core(gpointer user_data); | 52 static gpointer update_thread_core(gpointer user_data); |
| 52 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); | 53 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); |
| 53 static void on_plugin_services_menu_item_click(); | 54 static void on_plugin_services_menu_item_click(); |
| 54 | 55 |
| 55 static GtkWidget *playlist_menu_item; | 56 static GtkWidget *playlist_menu_item; |
| 269 aud_cfg_db_close(db); | 270 aud_cfg_db_close(db); |
| 270 | 271 |
| 271 debug("configuration saved\n"); | 272 debug("configuration saved\n"); |
| 272 } | 273 } |
| 273 | 274 |
| 274 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo) | 275 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist) |
| 275 { | 276 { |
| 276 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s')\n", | 277 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s', add_to_playlist = %d)\n", |
| 277 streamdir == NULL ? "" : streamdir->name, | 278 streamdir == NULL ? "" : streamdir->name, |
| 278 category == NULL ? "" : category->name, | 279 category == NULL ? "" : category->name, |
| 279 streaminfo == NULL ? "" : streaminfo->name); | 280 streaminfo == NULL ? "" : streaminfo->name, |
| 281 add_to_playlist); | |
| 280 | 282 |
| 281 if (g_queue_get_length(update_thread_data_queue) >= MAX_UPDATE_THREADS) { | 283 if (g_queue_get_length(update_thread_data_queue) >= MAX_UPDATE_THREADS) { |
| 282 debug("another %d streamdir updates are pending, this request will be dropped\n", g_queue_get_length(update_thread_data_queue)); | 284 debug("another %d streamdir updates are pending, this request will be dropped\n", g_queue_get_length(update_thread_data_queue)); |
| 283 } | 285 } |
| 284 else { | 286 else { |
| 293 /* search for another identic update request */ | 295 /* search for another identic update request */ |
| 294 for (i = 0; i < g_queue_get_length(update_thread_data_queue); i++) { | 296 for (i = 0; i < g_queue_get_length(update_thread_data_queue); i++) { |
| 295 update_thread_data = g_queue_peek_nth(update_thread_data_queue, i); | 297 update_thread_data = g_queue_peek_nth(update_thread_data_queue, i); |
| 296 if (update_thread_data->streamdir == streamdir && | 298 if (update_thread_data->streamdir == streamdir && |
| 297 update_thread_data->category == category && | 299 update_thread_data->category == category && |
| 298 update_thread_data->streaminfo == streaminfo) { | 300 update_thread_data->streaminfo == streaminfo && |
| 301 update_thread_data->add_to_playlist == add_to_playlist) { | |
| 299 exists = TRUE; | 302 exists = TRUE; |
| 300 break; | 303 break; |
| 301 } | 304 } |
| 302 } | 305 } |
| 303 | 306 |
| 308 update_thread_data = g_malloc(sizeof(update_thread_data_t)); | 311 update_thread_data = g_malloc(sizeof(update_thread_data_t)); |
| 309 | 312 |
| 310 update_thread_data->streamdir = streamdir; | 313 update_thread_data->streamdir = streamdir; |
| 311 update_thread_data->category = category; | 314 update_thread_data->category = category; |
| 312 update_thread_data->streaminfo = streaminfo; | 315 update_thread_data->streaminfo = streaminfo; |
| 316 update_thread_data->add_to_playlist = add_to_playlist; | |
| 313 | 317 |
| 314 g_queue_push_tail(update_thread_data_queue, update_thread_data); | 318 g_queue_push_tail(update_thread_data_queue, update_thread_data); |
| 315 } | 319 } |
| 316 else { | 320 else { |
| 317 debug("this request is already present in the queue, dropping\n"); | 321 debug("this request is already present in the queue, dropping\n"); |
| 324 update_thread_data_t *data = g_malloc(sizeof(update_thread_data_t)); | 328 update_thread_data_t *data = g_malloc(sizeof(update_thread_data_t)); |
| 325 | 329 |
| 326 data->streamdir = streamdir; | 330 data->streamdir = streamdir; |
| 327 data->category = category; | 331 data->category = category; |
| 328 data->streaminfo = streaminfo; | 332 data->streaminfo = streaminfo; |
| 333 data->add_to_playlist = add_to_playlist; | |
| 329 | 334 |
| 330 g_queue_push_tail(update_thread_data_queue, data); | 335 g_queue_push_tail(update_thread_data_queue, data); |
| 331 | 336 |
| 332 g_thread_create((GThreadFunc) update_thread_core, NULL, FALSE, NULL); | 337 g_thread_create((GThreadFunc) update_thread_core, NULL, FALSE, NULL); |
| 333 } | 338 } |
| 348 } | 353 } |
| 349 g_mutex_unlock(update_thread_mutex); | 354 g_mutex_unlock(update_thread_mutex); |
| 350 | 355 |
| 351 /* repetitively process the queue elements, until queue is empty */ | 356 /* repetitively process the queue elements, until queue is empty */ |
| 352 while (data != NULL && g_queue_get_length(update_thread_data_queue) > 0) { | 357 while (data != NULL && g_queue_get_length(update_thread_data_queue) > 0) { |
| 353 /* update a streaminfo - that is - add this streaminfo to playlist */ | 358 /* update a streaminfo */ |
| 354 if (data->streaminfo != NULL) { | 359 if (data->streaminfo != NULL) { |
| 355 gdk_threads_enter(); | 360 gdk_threads_enter(); |
| 356 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, TRUE); | 361 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, TRUE); |
| 357 gdk_threads_leave(); | 362 gdk_threads_leave(); |
| 358 | 363 |
| 359 streaminfo_add_to_playlist(data->streaminfo); | 364 if (data->add_to_playlist) |
| 365 streaminfo_add_to_playlist(data->streaminfo); | |
| 366 else { | |
| 367 /* shoutcast */ | |
| 368 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | |
| 369 printf("DAAAA!\n"); | |
| 370 shoutcast_streaminfo_fetch(data->category, data->streaminfo); | |
| 371 } | |
| 372 /* xiph */ | |
| 373 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { | |
| 374 //xiph_category_fetch(data->category); | |
| 375 } | |
| 376 } | |
| 360 | 377 |
| 361 gdk_threads_enter(); | 378 gdk_threads_enter(); |
| 379 if (!data->add_to_playlist) | |
| 380 streambrowser_win_set_streaminfo(data->streamdir, data->category, data->streaminfo); | |
| 362 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, FALSE); | 381 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, FALSE); |
| 363 gdk_threads_leave(); | 382 gdk_threads_leave(); |
| 364 } | 383 } |
| 365 /* update a category */ | 384 /* update a category */ |
| 366 else if (data->category != NULL) { | 385 else if (data->category != NULL) { |
| 386 gdk_threads_enter(); | |
| 387 streambrowser_win_set_category_state(data->streamdir, data->category, TRUE); | |
| 388 gdk_threads_leave(); | |
| 389 | |
| 367 /* shoutcast */ | 390 /* shoutcast */ |
| 368 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | 391 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { |
| 369 gdk_threads_enter(); | |
| 370 streambrowser_win_set_category_state(data->streamdir, data->category, TRUE); | |
| 371 gdk_threads_leave(); | |
| 372 | |
| 373 shoutcast_category_fetch(data->category); | 392 shoutcast_category_fetch(data->category); |
| 374 | |
| 375 gdk_threads_enter(); | |
| 376 streambrowser_win_set_category(data->streamdir, data->category); | |
| 377 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); | |
| 378 gdk_threads_leave(); | |
| 379 } | 393 } |
| 380 /* xiph */ | 394 /* xiph */ |
| 381 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { | 395 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { |
| 382 gdk_threads_enter(); | |
| 383 streambrowser_win_set_category_state(data->streamdir, data->category, TRUE); | |
| 384 gdk_threads_leave(); | |
| 385 | |
| 386 xiph_category_fetch(data->category); | 396 xiph_category_fetch(data->category); |
| 387 | 397 } |
| 388 gdk_threads_enter(); | 398 |
| 389 streambrowser_win_set_category(data->streamdir, data->category); | 399 gdk_threads_enter(); |
| 390 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); | 400 streambrowser_win_set_category(data->streamdir, data->category); |
| 391 gdk_threads_leave(); | 401 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); |
| 392 } | 402 gdk_threads_leave(); |
| 393 } | 403 } |
| 394 /* update a streamdir */ | 404 /* update a streamdir */ |
| 395 else if (data->streamdir != NULL) { | 405 else if (data->streamdir != NULL) { |
| 396 /* shoutcast */ | 406 /* shoutcast */ |
| 397 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | 407 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { |
| 474 static void on_plugin_services_menu_item_click() | 484 static void on_plugin_services_menu_item_click() |
| 475 { | 485 { |
| 476 debug("on_plugin_services_menu_item_click()\n"); | 486 debug("on_plugin_services_menu_item_click()\n"); |
| 477 | 487 |
| 478 streambrowser_win_show(); | 488 streambrowser_win_show(); |
| 479 streamdir_update(NULL, NULL, NULL); | 489 streamdir_update(NULL, NULL, NULL, FALSE); |
| 480 } | 490 } |
| 481 | 491 |
