comparison src/streambrowser/streambrowser.c @ 2889:6c53f9fa9029

Backed out changeset 59ff744e1e23
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Aug 2008 20:29:49 +0300
parents 779125caa3ac
children c27da2c06805
comparison
equal deleted inserted replaced
2856:59ff744e1e23 2889:6c53f9fa9029
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 shoutcast_streaminfo_fetch(data->category, data->streaminfo);
370 }
371 /* xiph */
372 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) {
373 xiph_streaminfo_fetch(data->category, data->streaminfo);
374 }
375 }
360 376
361 gdk_threads_enter(); 377 gdk_threads_enter();
378 if (!data->add_to_playlist)
379 streambrowser_win_set_streaminfo(data->streamdir, data->category, data->streaminfo);
362 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, FALSE); 380 streambrowser_win_set_streaminfo_state(data->streamdir, data->category, data->streaminfo, FALSE);
363 gdk_threads_leave(); 381 gdk_threads_leave();
364 } 382 }
365 /* update a category */ 383 /* update a category */
366 else if (data->category != NULL) { 384 else if (data->category != NULL) {
385 gdk_threads_enter();
386 streambrowser_win_set_category_state(data->streamdir, data->category, TRUE);
387 gdk_threads_leave();
388
367 /* shoutcast */ 389 /* shoutcast */
368 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { 390 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); 391 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 } 392 }
380 /* xiph */ 393 /* xiph */
381 else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { 394 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); 395 xiph_category_fetch(data->category);
387 396 }
388 gdk_threads_enter(); 397
389 streambrowser_win_set_category(data->streamdir, data->category); 398 gdk_threads_enter();
390 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); 399 streambrowser_win_set_category(data->streamdir, data->category);
391 gdk_threads_leave(); 400 streambrowser_win_set_category_state(data->streamdir, data->category, FALSE);
392 } 401 gdk_threads_leave();
393 } 402 }
394 /* update a streamdir */ 403 /* update a streamdir */
395 else if (data->streamdir != NULL) { 404 else if (data->streamdir != NULL) {
396 /* shoutcast */ 405 /* shoutcast */
397 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { 406 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) {
464 aud_playlist_add(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); 473 aud_playlist_add(aud_playlist_get_active(), PLAYLIST_TEMP_FILE);
465 debug("stream playlist '%s' added\n", streaminfo->playlist_url); 474 debug("stream playlist '%s' added\n", streaminfo->playlist_url);
466 } 475 }
467 476
468 if (strlen(streaminfo->url) > 0) { 477 if (strlen(streaminfo->url) > 0) {
469 aud_playlist_add(aud_playlist_get_active(), streaminfo->url); 478 aud_playlist_add(aud_playlist_get_active(), streaminfo->url);
470 debug("stream '%s' added\n", streaminfo->url); 479 debug("stream '%s' added\n", streaminfo->url);
471 } 480 }
472 } 481 }
473 482
474 static void on_plugin_services_menu_item_click() 483 static void on_plugin_services_menu_item_click()
475 { 484 {
476 debug("on_plugin_services_menu_item_click()\n"); 485 debug("on_plugin_services_menu_item_click()\n");
477 486
478 streambrowser_win_show(); 487 streambrowser_win_show();
479 streamdir_update(NULL, NULL, NULL); 488 streamdir_update(NULL, NULL, NULL, FALSE);
480 } 489 }
481 490