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