diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-08-29 19:44:28 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-08-29 19:44:28 +0200 |
commit | f61d17119ceb939ec9b840dc39a6a064b11668a8 (patch) | |
tree | 6195644729abc7ccb2eee6ee44988fed290155f6 | |
parent | cb82c2caec2ac65722d65ccc1b3768cd6f69d915 (diff) |
gtkui plugin overrides pl_add_file and pl_add_dir API functions and shows progress dialog
-rw-r--r-- | deadbeef.h | 2 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | playlist.c | 8 | ||||
-rw-r--r-- | playlist.h | 6 | ||||
-rw-r--r-- | plugins.c | 2 | ||||
-rw-r--r-- | plugins/gtkui/ddblistview.c | 3 | ||||
-rw-r--r-- | plugins/gtkui/fileman.c | 56 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 72 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.h | 15 |
9 files changed, 127 insertions, 45 deletions
@@ -357,6 +357,8 @@ typedef struct { void (*pl_item_copy) (DB_playItem_t *out, DB_playItem_t *in); int (*pl_add_file) (const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); int (*pl_add_dir) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); + void (*pl_add_files_begin) (void); + void (*pl_add_files_end) (void); DB_playItem_t *(*pl_insert_item) (DB_playItem_t *after, DB_playItem_t *it); DB_playItem_t *(*pl_insert_dir) (DB_playItem_t *after, const char *dirname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); DB_playItem_t *(*pl_insert_file) (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); @@ -225,6 +225,9 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi pl_clear (); pl_reset_cursor (); } + if (parg < pend) { + deadbeef->pl_add_files_begin (); + } while (parg < pend) { char resolved[PATH_MAX]; const char *pname; @@ -234,14 +237,15 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi else { pname = parg; } - if (pl_add_dir (pname, NULL, NULL) < 0) { - if (pl_add_file (pname, NULL, NULL) < 0) { + if (deadbeef->pl_add_dir (pname, NULL, NULL) < 0) { + if (deadbeef->pl_add_file (pname, NULL, NULL) < 0) { fprintf (stderr, "failed to add file or folder %s\n", pname); } } parg += strlen (parg); parg++; } + deadbeef->pl_add_files_end (); messagepump_push (M_PLAYLISTREFRESH, 0, 0, 0); if (!queue) { messagepump_push (M_PLAYSONG, 0, 1, 0); @@ -1448,6 +1448,14 @@ pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *us return -1; } +void +pl_add_files_begin (void) { +} + +void +pl_add_files_end (void) { +} + int plt_remove_item (playlist_t *playlist, playItem_t *it) { if (!it) @@ -144,6 +144,12 @@ pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *us int pl_add_file (const char *fname, int (*cb)(playItem_t *it, void *data), void *user_data); +void +pl_add_files_begin (void); + +void +pl_add_files_end (void); + playItem_t * pl_insert_dir (playItem_t *after, const char *dirname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); @@ -128,6 +128,8 @@ static DB_functions_t deadbeef_api = { .pl_item_copy = (void (*)(DB_playItem_t *, DB_playItem_t *))pl_item_copy, .pl_add_file = (int (*) (const char *, int (*cb)(DB_playItem_t *it, void *data), void *))pl_add_file, .pl_add_dir = (int (*) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data))pl_add_dir, + .pl_add_files_begin = pl_add_files_begin, + .pl_add_files_end = pl_add_files_end, .pl_insert_item = (DB_playItem_t *(*) (DB_playItem_t *after, DB_playItem_t *it))pl_insert_item, .pl_insert_dir = (DB_playItem_t *(*) (DB_playItem_t *after, const char *dirname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data))pl_insert_dir, .pl_insert_file = (DB_playItem_t *(*) (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data))pl_insert_file, diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c index 5508adc2..93176d18 100644 --- a/plugins/gtkui/ddblistview.c +++ b/plugins/gtkui/ddblistview.c @@ -2805,6 +2805,7 @@ ddb_listview_free_groups (DdbListview *listview) { void ddb_listview_build_groups (DdbListview *listview) { + deadbeef->pl_lock (); ddb_listview_free_groups (listview); listview->fullheight = 0; @@ -2837,6 +2838,7 @@ ddb_listview_build_groups (DdbListview *listview) { // } listview->fullheight = grp->height; listview->fullheight += listview->grouptitle_height; + deadbeef->pl_unlock (); return; } if (!grp || strcmp (str, curr)) { @@ -2871,6 +2873,7 @@ ddb_listview_build_groups (DdbListview *listview) { } listview->fullheight += grp->height; } + deadbeef->pl_unlock (); } void ddb_listview_set_vscroll (DdbListview *listview, gboolean scroll) { diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c index 4fe56298..3f58bb09 100644 --- a/plugins/gtkui/fileman.c +++ b/plugins/gtkui/fileman.c @@ -7,70 +7,40 @@ #include "progress.h" #include "support.h" -static gboolean -progress_show_idle (gpointer data) { - progress_show (); - return FALSE; -} - -static gboolean -set_progress_text_idle (gpointer data) { - const char *text = (const char *)data; - progress_settext (text); - return FALSE; -} - -int -gtkpl_add_file_info_cb (DB_playItem_t *it, void *data) { - if (progress_is_aborted ()) { - return -1; - } - g_idle_add (set_progress_text_idle, it->fname); - return 0; -} - -static gboolean -progress_hide_idle (gpointer data) { - progress_hide (); - deadbeef->sendmessage (M_PLAYLISTREFRESH, 0, 0, 0); - //playlist_refresh (); - return FALSE; -} - void gtkpl_add_dir (DdbListview *ps, char *folder) { - g_idle_add (progress_show_idle, NULL); - deadbeef->pl_add_dir (folder, gtkpl_add_file_info_cb, NULL); + g_idle_add (gtkui_progress_show_idle, NULL); + gtkui_original_pl_add_dir (folder, gtkui_add_file_info_cb, NULL); g_free (folder); - g_idle_add (progress_hide_idle, NULL); + g_idle_add (gtkui_progress_hide_idle, NULL); } static void gtkpl_adddir_cb (gpointer data, gpointer userdata) { - deadbeef->pl_add_dir (data, gtkpl_add_file_info_cb, userdata); + gtkui_original_pl_add_dir (data, gtkui_add_file_info_cb, userdata); g_free (data); } void gtkpl_add_dirs (GSList *lst) { - g_idle_add (progress_show_idle, NULL); + g_idle_add (gtkui_progress_show_idle, NULL); g_slist_foreach(lst, gtkpl_adddir_cb, NULL); g_slist_free (lst); - g_idle_add (progress_hide_idle, NULL); + g_idle_add (gtkui_progress_hide_idle, NULL); } static void gtkpl_addfile_cb (gpointer data, gpointer userdata) { - deadbeef->pl_add_file (data, gtkpl_add_file_info_cb, userdata); + gtkui_original_pl_add_file (data, gtkui_add_file_info_cb, userdata); g_free (data); } void gtkpl_add_files (GSList *lst) { - g_idle_add (progress_show_idle, NULL); + g_idle_add (gtkui_progress_show_idle, NULL); g_slist_foreach(lst, gtkpl_addfile_cb, NULL); g_slist_free (lst); - g_idle_add (progress_hide_idle, NULL); + g_idle_add (gtkui_progress_hide_idle, NULL); } static void @@ -170,7 +140,7 @@ set_dnd_cursor_idle (gpointer data) { void gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { DdbListview *pl = DDB_LISTVIEW (lookup_widget (mainwin, "playlist")); - g_idle_add (progress_show_idle, NULL); + g_idle_add (gtkui_progress_show_idle, NULL); DdbListviewIter first = NULL; DdbListviewIter after = NULL; @@ -192,9 +162,9 @@ gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { //strncpy (fname, p, pe - p); //fname[pe - p] = 0; int abort = 0; - DdbListviewIter inserted = deadbeef->pl_insert_dir (after, fname, &abort, gtkpl_add_file_info_cb, NULL); + DdbListviewIter inserted = deadbeef->pl_insert_dir (after, fname, &abort, gtkui_add_file_info_cb, NULL); if (!inserted && !abort) { - inserted = deadbeef->pl_insert_file (after, fname, &abort, gtkpl_add_file_info_cb, NULL); + inserted = deadbeef->pl_insert_file (after, fname, &abort, gtkui_add_file_info_cb, NULL); } if (inserted) { if (!first) { @@ -218,7 +188,7 @@ gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { } free (ptr); - g_idle_add (progress_hide_idle, NULL); + g_idle_add (gtkui_progress_hide_idle, NULL); g_idle_add (set_dnd_cursor_idle, first); } diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 5b41dcf0..31cc5f85 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -993,6 +993,65 @@ gtkui_thread (void *ctx) { gdk_threads_leave (); } +gboolean +gtkui_progress_show_idle (gpointer data) { + progress_show (); + return FALSE; +} + +gboolean +gtkui_set_progress_text_idle (gpointer data) { + const char *text = (const char *)data; + progress_settext (text); + return FALSE; +} + +gboolean +gtkui_progress_hide_idle (gpointer data) { + progress_hide (); + deadbeef->sendmessage (M_PLAYLISTREFRESH, 0, 0, 0); + //playlist_refresh (); + return FALSE; +} + +int +gtkui_add_file_info_cb (DB_playItem_t *it, void *data) { + if (progress_is_aborted ()) { + return -1; + } + g_idle_add (gtkui_set_progress_text_idle, it->fname); + return 0; +} + +int (*gtkui_original_pl_add_dir) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); +int (*gtkui_original_pl_add_file) (const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); +void (*gtkui_original_pl_add_files_begin) (void); +void (*gtkui_original_pl_add_files_end) (void); + +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); + return res; +} + +int +gtkui_pl_add_file (const char *filename, int (*cb)(DB_playItem_t *it, void *data), void *user_data) { + int res = gtkui_original_pl_add_file (filename, gtkui_add_file_info_cb, NULL); + return res; +} + +void +gtkui_pl_add_files_begin (void) { + g_idle_add (gtkui_progress_show_idle, NULL); + gtkui_original_pl_add_files_begin (); +} + +void +gtkui_pl_add_files_end (void) { + g_idle_add (gtkui_progress_hide_idle, NULL); + gtkui_original_pl_add_files_end (); +} + static int gtkui_start (void) { // gtk must be running in separate thread @@ -1003,6 +1062,19 @@ gtkui_start (void) { usleep (10000); } + // override default pl_add_dir + gtkui_original_pl_add_dir = deadbeef->pl_add_dir; + deadbeef->pl_add_dir = gtkui_pl_add_dir; + + gtkui_original_pl_add_file = deadbeef->pl_add_file; + deadbeef->pl_add_file = gtkui_pl_add_file; + + gtkui_original_pl_add_files_begin = deadbeef->pl_add_files_begin; + deadbeef->pl_add_files_begin = gtkui_pl_add_files_begin; + + gtkui_original_pl_add_files_end = deadbeef->pl_add_files_end; + deadbeef->pl_add_files_end = gtkui_pl_add_files_end; + return 0; } diff --git a/plugins/gtkui/gtkui.h b/plugins/gtkui/gtkui.h index 178792b8..5ab30376 100644 --- a/plugins/gtkui/gtkui.h +++ b/plugins/gtkui/gtkui.h @@ -139,4 +139,19 @@ gtkui_playlist_changed (void); void gtkui_set_titlebar (DB_playItem_t *it); +gboolean +gtkui_progress_show_idle (gpointer data); + +gboolean +gtkui_progress_hide_idle (gpointer data); + +gboolean +gtkui_set_progress_text_idle (gpointer data); + +int +gtkui_add_file_info_cb (DB_playItem_t *it, void *data); + +extern int (*gtkui_original_pl_add_dir) (const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); +extern int (*gtkui_original_pl_add_file) (const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); + #endif |