Mercurial > audlegacy-plugins
comparison src/streambrowser/streambrowser.c @ 2913:113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
| author | Calin Crisan ccrisan@gmail.com |
|---|---|
| date | Fri, 15 Aug 2008 16:00:43 +0200 |
| parents | c27da2c06805 |
| children | 703cd5256849 |
comparison
equal
deleted
inserted
replaced
| 2891:c27da2c06805 | 2913:113454baecf8 |
|---|---|
| 55 static void sb_configure(); | 55 static void sb_configure(); |
| 56 static void sb_cleanup(); | 56 static void sb_cleanup(); |
| 57 | 57 |
| 58 static void gui_init(); | 58 static void gui_init(); |
| 59 static void gui_done(); | 59 static void gui_done(); |
| 60 static void config_load(); | |
| 61 static void config_save(); | |
| 62 | 60 |
| 63 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist); | 61 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist); |
| 64 static gpointer update_thread_core(gpointer user_data); | 62 static gpointer update_thread_core(gpointer user_data); |
| 65 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); | 63 static void streaminfo_add_to_playlist(streaminfo_t *streaminfo); |
| 66 static void on_plugin_services_menu_item_click(); | 64 static void on_plugin_services_menu_item_click(); |
| 148 | 146 |
| 149 aud_vfs_fclose(local_file); | 147 aud_vfs_fclose(local_file); |
| 150 aud_vfs_fclose(remote_file); | 148 aud_vfs_fclose(remote_file); |
| 151 | 149 |
| 152 return TRUE; | 150 return TRUE; |
| 151 } | |
| 152 | |
| 153 void config_load() | |
| 154 { | |
| 155 streambrowser_cfg.debug = FALSE; | |
| 156 streambrowser_cfg.bookmarks = NULL; | |
| 157 streambrowser_cfg.bookmarks_count = 0; | |
| 158 | |
| 159 mcs_handle_t *db; | |
| 160 if ((db = aud_cfg_db_open()) == NULL) { | |
| 161 failure("failed to load configuration\n"); | |
| 162 return; | |
| 163 } | |
| 164 | |
| 165 aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); | |
| 166 aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &streambrowser_cfg.bookmarks_count); | |
| 167 | |
| 168 debug("debug = %d\n", streambrowser_cfg.debug); | |
| 169 | |
| 170 if (streambrowser_cfg.bookmarks_count == 0) | |
| 171 streambrowser_cfg.bookmarks = NULL; | |
| 172 else | |
| 173 streambrowser_cfg.bookmarks = g_malloc(sizeof(bookmark_t) * streambrowser_cfg.bookmarks_count); | |
| 174 | |
| 175 int i; | |
| 176 gchar item[DEF_STRING_LEN]; | |
| 177 gchar *value; | |
| 178 for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { | |
| 179 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 180 if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { | |
| 181 strncpy(streambrowser_cfg.bookmarks[i].streamdir_name, value, DEF_STRING_LEN); | |
| 182 g_free(value); | |
| 183 } | |
| 184 else | |
| 185 streambrowser_cfg.bookmarks[i].streamdir_name[0] = '\0'; | |
| 186 | |
| 187 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 188 if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { | |
| 189 strncpy(streambrowser_cfg.bookmarks[i].name, value, DEF_STRING_LEN); | |
| 190 g_free(value); | |
| 191 } | |
| 192 else | |
| 193 streambrowser_cfg.bookmarks[i].name[0] = '\0'; | |
| 194 | |
| 195 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 196 if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { | |
| 197 strncpy(streambrowser_cfg.bookmarks[i].playlist_url, value, DEF_STRING_LEN); | |
| 198 g_free(value); | |
| 199 } | |
| 200 else | |
| 201 streambrowser_cfg.bookmarks[i].playlist_url[0] = '\0'; | |
| 202 | |
| 203 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 204 if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { | |
| 205 strncpy(streambrowser_cfg.bookmarks[i].url, value, DEF_STRING_LEN); | |
| 206 g_free(value); | |
| 207 } | |
| 208 else | |
| 209 streambrowser_cfg.bookmarks[i].url[0] = '\0'; | |
| 210 | |
| 211 debug("loaded a bookmark with streamdir_name = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", | |
| 212 streambrowser_cfg.bookmarks[i].streamdir_name, | |
| 213 streambrowser_cfg.bookmarks[i].name, | |
| 214 streambrowser_cfg.bookmarks[i].playlist_url, | |
| 215 streambrowser_cfg.bookmarks[i].url); | |
| 216 } | |
| 217 | |
| 218 debug("loaded %d bookmarks\n", streambrowser_cfg.bookmarks_count); | |
| 219 | |
| 220 aud_cfg_db_close(db); | |
| 221 | |
| 222 debug("configuration loaded\n"); | |
| 223 } | |
| 224 | |
| 225 void config_save() | |
| 226 { | |
| 227 mcs_handle_t *db; | |
| 228 if ((db = aud_cfg_db_open()) == NULL) { | |
| 229 failure("failed to save configuration\n"); | |
| 230 return; | |
| 231 } | |
| 232 | |
| 233 aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); | |
| 234 | |
| 235 int old_bookmarks_count, i; | |
| 236 gchar item[DEF_STRING_LEN]; | |
| 237 aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &old_bookmarks_count); | |
| 238 aud_cfg_db_set_int(db, "streambrowser", "bookmarks_count", streambrowser_cfg.bookmarks_count); | |
| 239 | |
| 240 for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { | |
| 241 debug("saving bookmark with streamdir_name = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", | |
| 242 streambrowser_cfg.bookmarks[i].streamdir_name, | |
| 243 streambrowser_cfg.bookmarks[i].name, | |
| 244 streambrowser_cfg.bookmarks[i].playlist_url, | |
| 245 streambrowser_cfg.bookmarks[i].url); | |
| 246 | |
| 247 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 248 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].streamdir_name); | |
| 249 | |
| 250 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 251 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].name); | |
| 252 | |
| 253 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 254 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].playlist_url); | |
| 255 | |
| 256 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 257 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].url); | |
| 258 } | |
| 259 | |
| 260 for (i = streambrowser_cfg.bookmarks_count; i < old_bookmarks_count; i++) { | |
| 261 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 262 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 263 | |
| 264 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 265 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 266 | |
| 267 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 268 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 269 | |
| 270 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 271 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 272 } | |
| 273 | |
| 274 aud_cfg_db_close(db); | |
| 275 | |
| 276 debug("configuration saved\n"); | |
| 153 } | 277 } |
| 154 | 278 |
| 155 gboolean mystrcasestr(const char *haystack, const char *needle) | 279 gboolean mystrcasestr(const char *haystack, const char *needle) |
| 156 { | 280 { |
| 157 int len_h = strlen(haystack) + 1; | 281 int len_h = strlen(haystack) + 1; |
| 247 if (update_thread_data_queue) | 371 if (update_thread_data_queue) |
| 248 g_queue_free(update_thread_data_queue); | 372 g_queue_free(update_thread_data_queue); |
| 249 update_thread_data_queue = NULL; | 373 update_thread_data_queue = NULL; |
| 250 | 374 |
| 251 debug("gui destroyed\n"); | 375 debug("gui destroyed\n"); |
| 252 } | |
| 253 | |
| 254 static void config_load() | |
| 255 { | |
| 256 streambrowser_cfg.debug = FALSE; | |
| 257 | |
| 258 mcs_handle_t *db; | |
| 259 if ((db = aud_cfg_db_open()) == NULL) { | |
| 260 failure("failed to load configuration\n"); | |
| 261 return; | |
| 262 } | |
| 263 | |
| 264 aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); | |
| 265 aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &streambrowser_cfg.bookmarks_count); | |
| 266 | |
| 267 streambrowser_cfg.bookmarks = g_malloc(sizeof(bookmark_t) * streambrowser_cfg.bookmarks_count); | |
| 268 | |
| 269 int i; | |
| 270 gchar item[DEF_STRING_LEN]; | |
| 271 gchar *value; | |
| 272 for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { | |
| 273 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 274 aud_cfg_db_get_string(db, "streambrowser", item, &value); | |
| 275 strncpy(streambrowser_cfg.bookmarks[i].streamdir_name, value, DEF_STRING_LEN); | |
| 276 g_free(value); | |
| 277 | |
| 278 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); | |
| 279 aud_cfg_db_get_string(db, "streambrowser", item, &value); | |
| 280 strncpy(streambrowser_cfg.bookmarks[i].category_name, value, DEF_STRING_LEN); | |
| 281 g_free(value); | |
| 282 | |
| 283 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 284 aud_cfg_db_get_string(db, "streambrowser", item, &value); | |
| 285 strncpy(streambrowser_cfg.bookmarks[i].name, value, DEF_STRING_LEN); | |
| 286 g_free(value); | |
| 287 | |
| 288 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 289 aud_cfg_db_get_string(db, "streambrowser", item, &value); | |
| 290 strncpy(streambrowser_cfg.bookmarks[i].playlist_url, value, DEF_STRING_LEN); | |
| 291 g_free(value); | |
| 292 | |
| 293 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 294 aud_cfg_db_get_string(db, "streambrowser", item, &value); | |
| 295 strncpy(streambrowser_cfg.bookmarks[i].url, value, DEF_STRING_LEN); | |
| 296 g_free(value); | |
| 297 } | |
| 298 | |
| 299 aud_cfg_db_close(db); | |
| 300 | |
| 301 debug("configuration loaded\n"); | |
| 302 debug("debug = %d\n", streambrowser_cfg.debug); | |
| 303 | |
| 304 // todo: write all other config options to the console | |
| 305 } | |
| 306 | |
| 307 static void config_save() | |
| 308 { | |
| 309 mcs_handle_t *db; | |
| 310 if ((db = aud_cfg_db_open()) == NULL) { | |
| 311 failure("failed to save configuration\n"); | |
| 312 return; | |
| 313 } | |
| 314 | |
| 315 aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); | |
| 316 | |
| 317 int old_bookmarks_count, i; | |
| 318 gchar item[DEF_STRING_LEN]; | |
| 319 aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &old_bookmarks_count); | |
| 320 aud_cfg_db_set_int(db, "streambrowser", "bookmarks_count", streambrowser_cfg.bookmarks_count); | |
| 321 | |
| 322 for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { | |
| 323 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 324 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].streamdir_name); | |
| 325 | |
| 326 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); | |
| 327 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].category_name); | |
| 328 | |
| 329 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 330 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].name); | |
| 331 | |
| 332 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 333 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].playlist_url); | |
| 334 | |
| 335 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 336 aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].url); | |
| 337 } | |
| 338 | |
| 339 for (i = streambrowser_cfg.bookmarks_count; i < old_bookmarks_count; i++) { | |
| 340 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); | |
| 341 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 342 | |
| 343 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); | |
| 344 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 345 | |
| 346 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); | |
| 347 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 348 | |
| 349 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); | |
| 350 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 351 | |
| 352 g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); | |
| 353 aud_cfg_db_unset_key(db, "streambrowser", item); | |
| 354 } | |
| 355 | |
| 356 aud_cfg_db_close(db); | |
| 357 | |
| 358 debug("configuration saved\n"); | |
| 359 } | 376 } |
| 360 | 377 |
| 361 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist) | 378 static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist) |
| 362 { | 379 { |
| 363 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s', add_to_playlist = %d)\n", | 380 debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s', add_to_playlist = %d)\n", |
| 514 gdk_threads_leave(); | 531 gdk_threads_leave(); |
| 515 } | 532 } |
| 516 } | 533 } |
| 517 /* bookmarks */ | 534 /* bookmarks */ |
| 518 else if (strncmp(data->streamdir->name, BOOKMARKS_NAME, strlen(BOOKMARKS_NAME)) == 0) { | 535 else if (strncmp(data->streamdir->name, BOOKMARKS_NAME, strlen(BOOKMARKS_NAME)) == 0) { |
| 519 streamdir_t *streamdir = bookmarks_streamdir_fetch(streambrowser_cfg.bookmarks, streambrowser_cfg.bookmarks_count); | 536 streamdir_t *streamdir = bookmarks_streamdir_fetch(&streambrowser_cfg.bookmarks, &streambrowser_cfg.bookmarks_count); |
| 520 if (streamdir != NULL) { | 537 if (streamdir != NULL) { |
| 521 gdk_threads_enter(); | 538 gdk_threads_enter(); |
| 522 streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); | 539 streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); |
| 523 gdk_threads_leave(); | 540 gdk_threads_leave(); |
| 524 } | 541 } |
| 539 gdk_threads_enter(); | 556 gdk_threads_enter(); |
| 540 streambrowser_win_set_streamdir(streamdir, XIPH_ICON); | 557 streambrowser_win_set_streamdir(streamdir, XIPH_ICON); |
| 541 gdk_threads_leave(); | 558 gdk_threads_leave(); |
| 542 } | 559 } |
| 543 /* bookmarks */ | 560 /* bookmarks */ |
| 544 streamdir = bookmarks_streamdir_fetch(streambrowser_cfg.bookmarks, streambrowser_cfg.bookmarks_count); | 561 streamdir = bookmarks_streamdir_fetch(&streambrowser_cfg.bookmarks, &streambrowser_cfg.bookmarks_count); |
| 545 if (streamdir != NULL) { | 562 if (streamdir != NULL) { |
| 546 gdk_threads_enter(); | 563 gdk_threads_enter(); |
| 547 streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); | 564 streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); |
| 548 gdk_threads_leave(); | 565 gdk_threads_leave(); |
| 566 | |
| 567 int i; | |
| 568 for (i = 0; i < category_get_count(streamdir); i++) | |
| 569 streamdir_update(streamdir, category_get_by_index(streamdir, i), NULL, FALSE); | |
| 549 } | 570 } |
| 550 } | 571 } |
| 551 | 572 |
| 552 g_free(data); | 573 g_free(data); |
| 553 | 574 |
| 590 } | 611 } |
| 591 } | 612 } |
| 592 | 613 |
| 593 static void on_plugin_services_menu_item_click() | 614 static void on_plugin_services_menu_item_click() |
| 594 { | 615 { |
| 595 debug("on_plugin_services_menu_item_click()\n"); | 616 debug("on_plugin_services_menu_item_click()\n"); |
| 596 | 617 |
| 597 streambrowser_win_show(); | 618 streambrowser_win_show(); |
| 598 streamdir_update(NULL, NULL, NULL, FALSE); | 619 streamdir_update(NULL, NULL, NULL, FALSE); |
| 599 } | 620 } |
| 600 | 621 |
