Mercurial > audlegacy-plugins
comparison src/streambrowser/streambrowser.c @ 2788:3a615c9d2bb1
reindent
| author | mf0102 <0102@gmx.at> |
|---|---|
| date | Wed, 09 Jul 2008 13:23:22 +0200 |
| parents | 30b1a9a6b768 |
| children | c156102069ae |
comparison
equal
deleted
inserted
replaced
| 2787:30b1a9a6b768 | 2788:3a615c9d2bb1 |
|---|---|
| 10 #include "gui/streambrowser_win.h" | 10 #include "gui/streambrowser_win.h" |
| 11 #include "gui/about_win.h" | 11 #include "gui/about_win.h" |
| 12 | 12 |
| 13 | 13 |
| 14 typedef struct { | 14 typedef struct { |
| 15 | 15 streamdir_t *streamdir; |
| 16 streamdir_t* streamdir; | 16 category_t *category; |
| 17 category_t* category; | 17 streaminfo_t *streaminfo; |
| 18 streaminfo_t* streaminfo; | |
| 19 | |
| 20 } update_thread_data_t; | 18 } update_thread_data_t; |
| 21 | 19 |
| 22 | 20 |
| 23 static void sb_init(); | 21 static void sb_init(); |
| 24 static void sb_about(); | 22 static void sb_about(); |
| 25 static void sb_configure(); | 23 static void sb_configure(); |
| 26 static void sb_cleanup(); | 24 static void sb_cleanup(); |
| 27 | 25 |
| 28 static void gui_init(); | 26 static void gui_init(); |
| 29 static void gui_done(); | 27 static void gui_done(); |
| 30 static void config_load(); | 28 static void config_load(); |
| 31 static void config_save(); | 29 static void config_save(); |
| 32 | 30 |
| 33 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo); | 31 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo); |
| 34 static gpointer update_thread_core(update_thread_data_t *data); | 32 static gpointer update_thread_core(update_thread_data_t *data); |
| 35 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); | 33 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); |
| 36 static void on_plugin_services_menu_item_click(); | 34 static void on_plugin_services_menu_item_click(); |
| 37 | 35 |
| 38 static GtkWidget* playlist_menu_item; | 36 static GtkWidget *playlist_menu_item; |
| 39 static GtkWidget* main_menu_item; | 37 static GtkWidget *main_menu_item; |
| 40 static GQueue* update_thread_data_queue = NULL; | 38 static GQueue *update_thread_data_queue = NULL; |
| 41 static gint update_thread_count = 0; | 39 static GMutex *update_thread_mutex = NULL; |
| 42 static GMutex* update_thread_mutex = NULL; | 40 static gint update_thread_count = 0; |
| 43 | 41 |
| 44 | 42 streambrowser_cfg_t streambrowser_cfg; |
| 45 streambrowser_cfg_t streambrowser_cfg; | |
| 46 | 43 |
| 47 static GeneralPlugin sb_plugin = | 44 static GeneralPlugin sb_plugin = |
| 48 { | 45 { |
| 49 .description = "Stream Browser", | 46 .description = "Stream Browser", |
| 50 .init = sb_init, | 47 .init = sb_init, |
| 51 .about = sb_about, | 48 .about = sb_about, |
| 52 .configure = sb_configure, | 49 .configure = sb_configure, |
| 53 .cleanup = sb_cleanup | 50 .cleanup = sb_cleanup |
| 54 }; | 51 }; |
| 55 | 52 |
| 56 GeneralPlugin *sb_gplist[] = | 53 GeneralPlugin *sb_gplist[] = |
| 57 { | 54 { |
| 58 &sb_plugin, | 55 &sb_plugin, |
| 59 NULL | 56 NULL |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 SIMPLE_GENERAL_PLUGIN(streambrowser, sb_gplist); | 59 SIMPLE_GENERAL_PLUGIN(streambrowser, sb_gplist); |
| 63 | 60 |
| 64 | 61 |
| 65 void debug(const char *fmt, ...) | 62 void debug(const char *fmt, ...) |
| 66 { | 63 { |
| 67 if (streambrowser_cfg.debug) { | 64 if (streambrowser_cfg.debug) { |
| 68 va_list ap; | 65 va_list ap; |
| 69 fprintf(stderr, "* streambrowser: "); | 66 fprintf(stderr, "* streambrowser: "); |
| 70 va_start(ap, fmt); | 67 va_start(ap, fmt); |
| 71 vfprintf(stderr, fmt, ap); | 68 vfprintf(stderr, fmt, ap); |
| 72 va_end(ap); | 69 va_end(ap); |
| 73 } | 70 } |
| 74 } | 71 } |
| 75 | 72 |
| 76 void failure(const char *fmt, ...) | 73 void failure(const char *fmt, ...) |
| 77 { | 74 { |
| 78 va_list ap; | 75 va_list ap; |
| 79 fprintf(stderr, "! streambrowser: "); | 76 fprintf(stderr, "! streambrowser: "); |
| 80 va_start(ap, fmt); | 77 va_start(ap, fmt); |
| 81 vfprintf(stderr, fmt, ap); | 78 vfprintf(stderr, fmt, ap); |
| 82 va_end(ap); | 79 va_end(ap); |
| 83 } | 80 } |
| 84 | 81 |
| 85 gboolean fetch_remote_to_local_file(gchar *remote_url, gchar *local_url) | 82 gboolean fetch_remote_to_local_file(gchar *remote_url, gchar *local_url) |
| 86 { | 83 { |
| 87 VFSFile *remote_file = aud_vfs_fopen(remote_url, "r"); | 84 VFSFile *remote_file = aud_vfs_fopen(remote_url, "r"); |
| 88 if (remote_file == NULL) { | 85 if (remote_file == NULL) { |
| 89 failure("failed to fetch file '%s'\n", remote_url); | 86 failure("failed to fetch file '%s'\n", remote_url); |
| 90 return FALSE; | 87 return FALSE; |
| 91 } | 88 } |
| 92 | 89 |
| 93 VFSFile *local_file = aud_vfs_fopen(local_url, "w"); | 90 VFSFile *local_file = aud_vfs_fopen(local_url, "w"); |
| 94 if (local_file == NULL) { | 91 if (local_file == NULL) { |
| 95 aud_vfs_fclose(remote_file); | 92 aud_vfs_fclose(remote_file); |
| 96 | 93 |
| 97 failure("failed to create local file '%s'\n", local_file); | 94 failure("failed to create local file '%s'\n", local_file); |
| 98 return FALSE; | 95 return FALSE; |
| 99 } | 96 } |
| 100 | 97 |
| 101 unsigned char buff[DEF_BUFFER_SIZE]; | 98 unsigned char buff[DEF_BUFFER_SIZE]; |
| 102 int size; | 99 int size; |
| 103 while (!aud_vfs_feof(remote_file)) { | 100 while (!aud_vfs_feof(remote_file)) { |
| 104 size = aud_vfs_fread(buff, 1, DEF_BUFFER_SIZE, remote_file); | 101 size = aud_vfs_fread(buff, 1, DEF_BUFFER_SIZE, remote_file); |
| 105 | 102 |
| 106 // i don't know why aud_vfs_feof() doesn't ever return TRUE | 103 // i don't know why aud_vfs_feof() doesn't ever return TRUE |
| 107 // so this is a workaround to properly end the loop | 104 // so this is a workaround to properly end the loop |
| 108 if (size == 0) | 105 if (size == 0) |
| 109 break; | 106 break; |
| 110 | 107 |
| 111 size = aud_vfs_fwrite(buff, 1, size, local_file); | 108 size = aud_vfs_fwrite(buff, 1, size, local_file); |
| 112 if (size == 0) { | 109 if (size == 0) { |
| 113 aud_vfs_fclose(local_file); | 110 aud_vfs_fclose(local_file); |
| 114 aud_vfs_fclose(remote_file); | 111 aud_vfs_fclose(remote_file); |
| 115 | 112 |
| 116 failure("failed to write to local file '%s'\n", local_file); | 113 failure("failed to write to local file '%s'\n", local_file); |
| 117 return FALSE; | 114 return FALSE; |
| 118 } | 115 } |
| 119 } | 116 } |
| 120 | 117 |
| 121 aud_vfs_fclose(local_file); | 118 aud_vfs_fclose(local_file); |
| 122 aud_vfs_fclose(remote_file); | 119 aud_vfs_fclose(remote_file); |
| 123 | 120 |
| 124 return TRUE; | 121 return TRUE; |
| 125 } | 122 } |
| 126 | 123 |
| 127 | 124 |
| 128 static void sb_init() | 125 static void sb_init() |
| 129 { | 126 { |
| 130 /* workaround to print sb_init() */ | 127 /* workaround to print sb_init() */ |
| 131 streambrowser_cfg.debug = TRUE; | 128 streambrowser_cfg.debug = TRUE; |
| 132 debug("sb_init()\n"); | 129 debug("sb_init()\n"); |
| 133 streambrowser_cfg.debug = FALSE; | 130 streambrowser_cfg.debug = FALSE; |
| 134 | 131 |
| 135 config_load(); | 132 config_load(); |
| 136 gui_init(); | 133 gui_init(); |
| 137 } | 134 } |
| 138 | 135 |
| 139 static void sb_about() | 136 static void sb_about() |
| 140 { | 137 { |
| 141 debug("sb_about()\n"); | 138 debug("sb_about()\n"); |
| 142 } | 139 } |
| 143 | 140 |
| 144 static void sb_configure() | 141 static void sb_configure() |
| 145 { | 142 { |
| 146 debug("sb_configure()\n"); | 143 debug("sb_configure()\n"); |
| 147 } | 144 } |
| 148 | 145 |
| 149 static void sb_cleanup() | 146 static void sb_cleanup() |
| 150 { | 147 { |
| 151 debug("sb_cleanup()\n"); | 148 debug("sb_cleanup()\n"); |
| 152 | 149 |
| 153 gui_done(); | 150 gui_done(); |
| 154 config_save(); | 151 config_save(); |
| 155 } | 152 } |
| 156 | 153 |
| 157 static void gui_init() | 154 static void gui_init() |
| 158 { | 155 { |
| 159 /* the plugin services menu */ | 156 /* the plugin services menu */ |
| 160 playlist_menu_item = gtk_image_menu_item_new_with_label("Streambrowser"); | 157 playlist_menu_item = gtk_image_menu_item_new_with_label("Streambrowser"); |
| 161 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(playlist_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); | 158 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(playlist_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
| 162 gtk_widget_show(playlist_menu_item); | 159 gtk_widget_show(playlist_menu_item); |
| 163 g_signal_connect(G_OBJECT(playlist_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL); | 160 g_signal_connect(G_OBJECT(playlist_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL); |
| 164 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, playlist_menu_item); | 161 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, playlist_menu_item); |
| 165 | 162 |
| 166 main_menu_item = gtk_image_menu_item_new_with_label("Streambrowser"); | 163 main_menu_item = gtk_image_menu_item_new_with_label("Streambrowser"); |
| 167 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(main_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); | 164 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(main_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
| 168 gtk_widget_show(main_menu_item); | 165 gtk_widget_show(main_menu_item); |
| 169 g_signal_connect(G_OBJECT(main_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL); | 166 g_signal_connect(G_OBJECT(main_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL); |
| 170 audacious_menu_plugin_item_add(AUDACIOUS_MENU_MAIN, main_menu_item); | 167 audacious_menu_plugin_item_add(AUDACIOUS_MENU_MAIN, main_menu_item); |
| 171 | 168 |
| 172 /* main streambrowser window */ | 169 /* main streambrowser window */ |
| 173 streambrowser_win_init(); | 170 streambrowser_win_init(); |
| 174 streambrowser_win_set_update_function(streamdir_update); | 171 streambrowser_win_set_update_function(streamdir_update); |
| 175 | 172 |
| 176 /* others */ | 173 /* others */ |
| 177 update_thread_mutex = g_mutex_new(); | 174 update_thread_mutex = g_mutex_new(); |
| 178 update_thread_data_queue = g_queue_new(); | 175 update_thread_data_queue = g_queue_new(); |
| 179 | 176 |
| 180 debug("gui initialized\n"); | 177 debug("gui initialized\n"); |
| 181 } | 178 } |
| 182 | 179 |
| 183 static void gui_done() | 180 static void gui_done() |
| 184 { | 181 { |
| 185 /* the plugin services menu */ | 182 /* the plugin services menu */ |
| 186 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_PLAYLIST_RCLICK, playlist_menu_item); | 183 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_PLAYLIST_RCLICK, playlist_menu_item); |
| 187 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_MAIN, main_menu_item); | 184 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_MAIN, main_menu_item); |
| 188 | 185 |
| 189 /* main streambrowser window */ | 186 /* main streambrowser window */ |
| 190 streambrowser_win_hide(); | 187 streambrowser_win_hide(); |
| 191 streambrowser_win_done(); | 188 streambrowser_win_done(); |
| 192 | 189 |
| 193 /* others */ | 190 /* others */ |
| 194 if (update_thread_mutex) | 191 if (update_thread_mutex) |
| 195 g_mutex_free(update_thread_mutex); | 192 g_mutex_free(update_thread_mutex); |
| 196 update_thread_mutex = NULL; | 193 update_thread_mutex = NULL; |
| 197 if (update_thread_data_queue) | 194 if (update_thread_data_queue) |
| 198 g_queue_free(update_thread_data_queue); | 195 g_queue_free(update_thread_data_queue); |
| 199 update_thread_data_queue = NULL; | 196 update_thread_data_queue = NULL; |
| 200 | 197 |
| 201 debug("gui destroyed\n"); | 198 debug("gui destroyed\n"); |
| 202 } | 199 } |
| 203 | 200 |
| 204 static void config_load() | 201 static void config_load() |
| 205 { | 202 { |
| 206 streambrowser_cfg.debug = FALSE; | 203 streambrowser_cfg.debug = FALSE; |
| 207 | 204 |
| 208 mcs_handle_t *db; | 205 mcs_handle_t *db; |
| 209 if ((db = aud_cfg_db_open()) == NULL) { | 206 if ((db = aud_cfg_db_open()) == NULL) { |
| 210 failure("failed to load configuration\n"); | 207 failure("failed to load configuration\n"); |
| 211 return; | 208 return; |
| 212 } | 209 } |
| 213 | 210 |
| 214 aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); | 211 aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); |
| 215 | 212 |
| 216 aud_cfg_db_close(db); | 213 aud_cfg_db_close(db); |
| 217 | 214 |
| 218 debug("configuration loaded\n"); | 215 debug("configuration loaded\n"); |
| 219 debug("debug = %d\n", streambrowser_cfg.debug); | 216 debug("debug = %d\n", streambrowser_cfg.debug); |
| 220 } | 217 } |
| 221 | 218 |
| 222 static void config_save() | 219 static void config_save() |
| 223 { | 220 { |
| 224 mcs_handle_t *db; | 221 mcs_handle_t *db; |
| 225 if ((db = aud_cfg_db_open()) == NULL) { | 222 if ((db = aud_cfg_db_open()) == NULL) { |
| 226 failure("failed to save configuration\n"); | 223 failure("failed to save configuration\n"); |
| 227 return; | 224 return; |
| 228 } | 225 } |
| 229 | 226 |
| 230 aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); | 227 aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); |
| 231 | 228 |
| 232 aud_cfg_db_close(db); | 229 aud_cfg_db_close(db); |
| 233 | 230 |
| 234 debug("configuration saved\n"); | 231 debug("configuration saved\n"); |
| 235 } | 232 } |
| 236 | 233 |
| 237 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo) | 234 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo) |
| 238 { | 235 { |
| 239 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s')\n", | 236 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s')\n", |
| 240 streamdir == NULL ? "" : streamdir->name, | 237 streamdir == NULL ? "" : streamdir->name, |
| 241 category == NULL ? "" : category->name, | 238 category == NULL ? "" : category->name, |
| 242 streaminfo == NULL ? "" : streaminfo->name); | 239 streaminfo == NULL ? "" : streaminfo->name); |
| 243 | 240 |
| 244 if (update_thread_count >= MAX_UPDATE_THREADS) { | 241 if (update_thread_count >= MAX_UPDATE_THREADS) { |
| 245 debug("another %d streamdir updates are pending, this request will be dropped\n", update_thread_count); | 242 debug("another %d streamdir updates are pending, this request will be dropped\n", update_thread_count); |
| 246 } | 243 } |
| 247 else | 244 else |
| 248 if (update_thread_count > 0) { | 245 if (update_thread_count > 0) { |
| 249 int i; | 246 int i; |
| 250 gboolean exists = FALSE; | 247 gboolean exists = FALSE; |
| 251 update_thread_data_t *update_thread_data; | 248 update_thread_data_t *update_thread_data; |
| 252 | 249 |
| 253 g_mutex_lock(update_thread_mutex); | 250 g_mutex_lock(update_thread_mutex); |
| 254 for (i = 0; i < g_queue_get_length(update_thread_data_queue); i++) { | 251 for (i = 0; i < g_queue_get_length(update_thread_data_queue); i++) { |
| 255 update_thread_data = g_queue_peek_nth(update_thread_data_queue, i); | 252 update_thread_data = g_queue_peek_nth(update_thread_data_queue, i); |
| 256 if (update_thread_data->streamdir == streamdir && | 253 if (update_thread_data->streamdir == streamdir && |
| 257 update_thread_data->category == category && | 254 update_thread_data->category == category && |
| 258 update_thread_data->streaminfo == streaminfo) { | 255 update_thread_data->streaminfo == streaminfo) { |
| 259 exists = TRUE; | 256 exists = TRUE; |
| 260 break; | 257 break; |
| 261 } | 258 } |
| 262 } | 259 } |
| 263 g_mutex_unlock(update_thread_mutex); | 260 g_mutex_unlock(update_thread_mutex); |
| 264 | 261 |
| 265 if (!exists) { | 262 if (!exists) { |
| 266 debug("another %d streamdir updates are pending, this request will be queued\n", update_thread_count); | 263 debug("another %d streamdir updates are pending, this request will be queued\n", update_thread_count); |
| 267 | 264 |
| 268 g_mutex_lock(update_thread_mutex); | 265 g_mutex_lock(update_thread_mutex); |
| 269 | 266 |
| 270 update_thread_data = g_malloc(sizeof(update_thread_data_t)); | 267 update_thread_data = g_malloc(sizeof(update_thread_data_t)); |
| 271 | 268 |
| 272 update_thread_data->streamdir = streamdir; | 269 update_thread_data->streamdir = streamdir; |
| 273 update_thread_data->category = category; | 270 update_thread_data->category = category; |
| 274 update_thread_data->streaminfo = streaminfo; | 271 update_thread_data->streaminfo = streaminfo; |
| 275 g_queue_push_tail(update_thread_data_queue, update_thread_data); | 272 g_queue_push_tail(update_thread_data_queue, update_thread_data); |
| 276 | 273 |
| 277 update_thread_count++; | 274 update_thread_count++; |
| 278 | 275 |
| 279 g_mutex_unlock(update_thread_mutex); | 276 g_mutex_unlock(update_thread_mutex); |
| 280 } | 277 } |
| 281 else { | 278 else { |
| 282 debug("this request is already present in the queue, dropping\n"); | 279 debug("this request is already present in the queue, dropping\n"); |
| 283 } | 280 } |
| 284 } | 281 } |
| 285 else { | 282 else { |
| 286 update_thread_data_t *data = g_malloc(sizeof(update_thread_data_t)); | 283 update_thread_data_t *data = g_malloc(sizeof(update_thread_data_t)); |
| 287 | 284 |
| 288 data->streamdir = streamdir; | 285 data->streamdir = streamdir; |
| 289 data->category = category; | 286 data->category = category; |
| 290 data->streaminfo = streaminfo; | 287 data->streaminfo = streaminfo; |
| 291 | 288 |
| 292 g_thread_create((GThreadFunc) update_thread_core, data, FALSE, NULL); | 289 g_thread_create((GThreadFunc) update_thread_core, data, FALSE, NULL); |
| 293 } | 290 } |
| 294 } | 291 } |
| 295 | 292 |
| 296 static gpointer update_thread_core(update_thread_data_t *data) | 293 static gpointer update_thread_core(update_thread_data_t *data) |
| 297 { | 294 { |
| 298 g_mutex_lock(update_thread_mutex); | 295 g_mutex_lock(update_thread_mutex); |
| 299 update_thread_count++; | 296 update_thread_count++; |
| 300 g_mutex_unlock(update_thread_mutex); | 297 g_mutex_unlock(update_thread_mutex); |
| 301 | 298 |
| 302 /* update a streaminfo - that is - add this streaminfo to playlist */ | 299 /* update a streaminfo - that is - add this streaminfo to playlist */ |
| 303 if (data->streaminfo != NULL) { | 300 if (data->streaminfo != NULL) { |
| 304 streaminfo_add_to_playlist(data->streaminfo); | 301 streaminfo_add_to_playlist(data->streaminfo); |
| 305 } | 302 } |
| 306 /* update a category */ | 303 /* update a category */ |
| 307 else if (data->category != NULL) { | 304 else if (data->category != NULL) { |
| 308 /* shoutcast */ | 305 /* shoutcast */ |
| 309 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | 306 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { |
| 310 shoutcast_category_fetch(data->category); | 307 shoutcast_category_fetch(data->category); |
| 311 | 308 |
| 312 gdk_threads_enter(); | 309 gdk_threads_enter(); |
| 313 streambrowser_win_set_category(data->streamdir, data->category); | 310 streambrowser_win_set_category(data->streamdir, data->category); |
| 314 gdk_threads_leave(); | 311 gdk_threads_leave(); |
| 315 } | 312 } |
| 316 } | 313 } |
| 317 /* update a streamdir */ | 314 /* update a streamdir */ |
| 318 else if (data->streamdir != NULL) { | 315 else if (data->streamdir != NULL) { |
| 319 /* shoutcast */ | 316 /* shoutcast */ |
| 320 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { | 317 if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { |
| 321 streamdir_t *streamdir = shoutcast_streamdir_fetch(); | 318 streamdir_t *streamdir = shoutcast_streamdir_fetch(); |
| 322 if (streamdir != NULL) { | 319 if (streamdir != NULL) { |
| 323 gdk_threads_enter(); | 320 gdk_threads_enter(); |
| 324 streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); | 321 streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); |
| 325 gdk_threads_leave(); | 322 gdk_threads_leave(); |
| 326 } | 323 } |
| 327 } | 324 } |
| 328 } | 325 } |
| 329 /* update all streamdirs */ | 326 /* update all streamdirs */ |
| 330 else { | 327 else { |
| 331 /* shoutcast */ | 328 /* shoutcast */ |
| 332 streamdir_t *shoutcast_streamdir = shoutcast_streamdir_fetch(); | 329 streamdir_t *shoutcast_streamdir = shoutcast_streamdir_fetch(); |
| 333 if (shoutcast_streamdir != NULL) { | 330 if (shoutcast_streamdir != NULL) { |
| 334 gdk_threads_enter(); | 331 gdk_threads_enter(); |
| 335 streambrowser_win_set_streamdir(shoutcast_streamdir, SHOUTCAST_ICON); | 332 streambrowser_win_set_streamdir(shoutcast_streamdir, SHOUTCAST_ICON); |
| 336 gdk_threads_leave(); | 333 gdk_threads_leave(); |
| 337 } | 334 } |
| 338 } | 335 } |
| 339 | 336 |
| 340 g_free(data); | 337 g_free(data); |
| 341 | 338 |
| 342 /* check to see if there are pending update requests */ | 339 /* check to see if there are pending update requests */ |
| 343 | 340 |
| 344 data = NULL; | 341 data = NULL; |
| 345 g_mutex_lock(update_thread_mutex); | 342 g_mutex_lock(update_thread_mutex); |
| 346 update_thread_count--; | 343 update_thread_count--; |
| 347 | 344 |
| 348 if (update_thread_count > 0) { | 345 if (update_thread_count > 0) { |
| 349 data = g_queue_pop_head(update_thread_data_queue); | 346 data = g_queue_pop_head(update_thread_data_queue); |
| 350 | 347 |
| 351 update_thread_count--; | 348 update_thread_count--; |
| 352 } | 349 } |
| 353 g_mutex_unlock(update_thread_mutex); | 350 g_mutex_unlock(update_thread_mutex); |
| 354 | 351 |
| 355 if (data != NULL) | 352 if (data != NULL) |
| 356 update_thread_core(data); | 353 update_thread_core(data); |
| 357 | 354 |
| 358 return NULL; | 355 return NULL; |
| 359 } | 356 } |
| 360 | 357 |
| 361 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo) | 358 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo) |
| 362 { | 359 { |
| 363 debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); | 360 debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); |
| 364 if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { | 361 if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { |
| 365 failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); | 362 failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); |
| 366 return; | 363 return; |
| 367 } | 364 } |
| 368 debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); | 365 debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); |
| 369 | 366 |
| 370 aud_playlist_add_url(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); | 367 aud_playlist_add_url(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); |
| 371 } | 368 } |
| 372 | 369 |
| 373 static void on_plugin_services_menu_item_click() | 370 static void on_plugin_services_menu_item_click() |
| 374 { | 371 { |
| 375 debug("on_plugin_services_menu_item_click()\n"); | 372 debug("on_plugin_services_menu_item_click()\n"); |
| 376 | 373 |
| 377 streambrowser_win_show(); | 374 streambrowser_win_show(); |
| 378 streamdir_update(NULL, NULL, NULL); | 375 streamdir_update(NULL, NULL, NULL); |
| 379 } | 376 } |
| 380 | 377 |
