diff options
author | waker <wakeroid@gmail.com> | 2011-04-27 22:00:33 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-04-27 22:01:00 +0200 |
commit | 8aae15388fcb39f9976114774305f7351c669abe (patch) | |
tree | 96b44faee3e3c71aeed8de920844470a43793453 | |
parent | bcd4de4a08ca7d62b5dd73fe3fabe9c4186c1d17 (diff) |
added progress dialog to pls and m3u loaders
-rw-r--r-- | playlist.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 66 | ||||
-rw-r--r-- | plugins/gtkui/progress.c | 21 | ||||
-rw-r--r-- | plugins/m3u/m3u.c | 9 |
4 files changed, 57 insertions, 45 deletions
@@ -2264,7 +2264,6 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in trace ("plt_load: failed to open %s\n", fname); return NULL; } - LOCK; // try plugins 1st const char *ext = strrchr (fname, '.'); @@ -2275,8 +2274,7 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in for (p = 0; plug[p]; p++) { for (e = 0; plug[p]->extensions[e]; e++) { if (plug[p]->load && !strcasecmp (ext, plug[p]->extensions[e])) { - DB_playItem_t *it = plug[p]->load (NULL, fname, NULL, NULL, NULL); - UNLOCK; + DB_playItem_t *it = plug[p]->load ((DB_playItem_t *)after, fname, pabort, (int (*)(DB_playItem_t *, void *))cb, user_data); return (playItem_t *)it; } } @@ -2522,7 +2520,6 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in } } - UNLOCK; if (fp) { fclose (fp); } @@ -2530,7 +2527,6 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in return last_added; load_fail: fprintf (stderr, "playlist load fail (%s)!\n", fname); - UNLOCK; if (fp) { fclose (fp); } diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 331cb56a..0759497a 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -737,6 +737,23 @@ playlist_filter_func (const GtkFileFilterInfo *filter_info, gpointer data) { } void +load_playlist_thread (void *data) { + char *fname = data; + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (plt) { + deadbeef->plt_clear (plt); + int abort = 0; + DB_playItem_t *it = deadbeef->plt_load (plt, NULL, fname, &abort, NULL, NULL); + if (it) { + deadbeef->pl_item_unref (it); + } + deadbeef->plt_unref (plt); + } + g_free (fname); + gtkui_playlist_changed (); +} + +void on_playlist_load_activate (GtkMenuItem *menuitem, gpointer user_data) { @@ -771,18 +788,8 @@ on_playlist_load_activate (GtkMenuItem *menuitem, gchar *fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg)); gtk_widget_destroy (dlg); if (fname) { - ddb_playlist_t *plt = deadbeef->plt_get_curr (); - if (plt) { - deadbeef->plt_clear (plt); - DB_playItem_t *it = deadbeef->plt_load (plt, NULL, fname, NULL, NULL, NULL); - if (it) { - deadbeef->pl_item_unref (it); - } - deadbeef->plt_unref (plt); - } - g_free (fname); - main_refresh (); - search_refresh (); + uintptr_t tid = deadbeef->thread_start (load_playlist_thread, fname); + deadbeef->thread_detach (tid); } } else { @@ -1106,12 +1113,6 @@ gtkui_thread (void *ctx) { } gboolean -gtkui_progress_show_idle (gpointer data) { - progress_show (); - return FALSE; -} - -gboolean gtkui_set_progress_text_idle (gpointer data) { char *text = (char *)data; if (text) { @@ -1121,13 +1122,6 @@ gtkui_set_progress_text_idle (gpointer data) { return FALSE; } -gboolean -gtkui_progress_hide_idle (gpointer data) { - progress_hide (); - //deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0); - return FALSE; -} - int gtkui_add_file_info_cb (DB_playItem_t *it, void *data) { if (progress_is_aborted ()) { @@ -1145,6 +1139,8 @@ int (*gtkui_original_pl_add_file) (const char *fname, int (*cb)(DB_playItem_t *i int (*gtkui_original_pl_add_files_begin) (ddb_playlist_t *plt); void (*gtkui_original_pl_add_files_end) (void); +DB_playItem_t * (*gtkui_original_plt_load) (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); + int gtkui_pl_add_dir (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data) { int res = gtkui_original_pl_add_dir (dirname, gtkui_add_file_info_cb, NULL); @@ -1159,16 +1155,27 @@ gtkui_pl_add_file (const char *filename, int (*cb)(DB_playItem_t *it, void *data int gtkui_pl_add_files_begin (ddb_playlist_t *plt) { - g_idle_add (gtkui_progress_show_idle, NULL); + progress_show (); return gtkui_original_pl_add_files_begin (plt); } void gtkui_pl_add_files_end (void) { - g_idle_add (gtkui_progress_hide_idle, NULL); + progress_hide (); gtkui_original_pl_add_files_end (); } +DB_playItem_t * +gtkui_plt_load (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data) { + if (deadbeef->pl_add_files_begin (plt) < 0) { + return NULL; + } + DB_playItem_t *it = gtkui_original_plt_load (plt, after, fname, pabort, gtkui_add_file_info_cb, user_data); + deadbeef->pl_add_files_end (); + + return it; +} + void gtkui_focus_on_playing_track (void) { DB_playItem_t *it = deadbeef->streamer_get_playing_track (); @@ -1205,7 +1212,7 @@ gtkui_start (void) { usleep (10000); } - // override default pl_add_dir + // override default file adding APIs to show progress bar gtkui_original_pl_add_dir = deadbeef->pl_add_dir; deadbeef->pl_add_dir = gtkui_pl_add_dir; @@ -1218,6 +1225,9 @@ gtkui_start (void) { gtkui_original_pl_add_files_end = deadbeef->pl_add_files_end; deadbeef->pl_add_files_end = gtkui_pl_add_files_end; + gtkui_original_plt_load = deadbeef->plt_load; + deadbeef->plt_load = gtkui_plt_load; + return 0; } diff --git a/plugins/gtkui/progress.c b/plugins/gtkui/progress.c index 1941c40e..359b0eae 100644 --- a/plugins/gtkui/progress.c +++ b/plugins/gtkui/progress.c @@ -81,9 +81,8 @@ progress_settext (const char *text) { gtk_entry_set_text (GTK_ENTRY (progressitem), text); } -void -progress_show (void) { - progress_aborted = 0; +gboolean +gtkui_progress_show_idle (gpointer data) { GtkWidget *playlist = lookup_widget (mainwin, "playlist"); if (playlist) { gtk_widget_set_sensitive (playlist, FALSE); @@ -92,15 +91,29 @@ progress_show (void) { gtk_widget_show_all (progressdlg); gtk_window_present (GTK_WINDOW (progressdlg)); gtk_window_set_transient_for (GTK_WINDOW (progressdlg), GTK_WINDOW (mainwin)); + return FALSE; } void -progress_hide (void) { +progress_show (void) { + progress_aborted = 0; + g_idle_add (gtkui_progress_show_idle, NULL); +} + +gboolean +gtkui_progress_hide_idle (gpointer data) { gtk_widget_hide (progressdlg); GtkWidget *playlist = lookup_widget (mainwin, "playlist"); if (playlist) { gtk_widget_set_sensitive (playlist, TRUE); } + //deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0); + return FALSE; +} + +void +progress_hide (void) { + g_idle_add (gtkui_progress_hide_idle, NULL); } void diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index e701e7ef..18ed73c2 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -40,6 +40,7 @@ skipspaces (const uint8_t *p, const uint8_t *end) { static DB_playItem_t * load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data) { + printf ("load_m3u: cb=%p\n", cb); const char *slash = strrchr (fname, '/'); trace ("enter pl_insert_m3u\n"); // skip all empty lines and comments @@ -60,7 +61,6 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla deadbeef->fclose (fp); const uint8_t *p = buffer; const uint8_t *end = buffer+sz; - deadbeef->pl_lock (); while (p < end) { p = skipspaces (p, end); if (p >= end) { @@ -104,7 +104,6 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); free (buffer); return after; } @@ -116,7 +115,6 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); trace ("leave pl_insert_m3u\n"); free (buffer); return after; @@ -186,7 +184,6 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla char title[1024] = ""; char length[20] = ""; int lastidx = -1; - deadbeef->pl_lock (); while (p < end) { p = skipspaces (p, end); if (p >= end) { @@ -215,7 +212,6 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); free (buffer); return after; } @@ -256,7 +252,6 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); free (buffer); return after; } @@ -296,7 +291,6 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); free (buffer); return after; } @@ -341,7 +335,6 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla if (after) { deadbeef->pl_item_ref (after); } - deadbeef->pl_unlock (); free (buffer); return after; } |