diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-02-14 15:09:27 +0100 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-02-14 15:09:27 +0100 |
commit | 4b11bd6042edb71ac3e64c5cbe9b76aa0f732f58 (patch) | |
tree | 2794bdc97f90ce78d29b86e46cb651b53928ee5c /plugins/gtkui/fileman.c | |
parent | cd8d00859924c09d3054e33d92d9db5ceb7271e7 (diff) |
playlist refactoring WIP
Diffstat (limited to 'plugins/gtkui/fileman.c')
-rw-r--r-- | plugins/gtkui/fileman.c | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c index 1e1e4bd7..452e14f7 100644 --- a/plugins/gtkui/fileman.c +++ b/plugins/gtkui/fileman.c @@ -1,6 +1,7 @@ #include "../../deadbeef.h" #include <gtk/gtk.h> #include <stdlib.h> +#include <ctype.h> #include "gtkui.h" #include "gtkplaylist.h" @@ -40,6 +41,139 @@ gtkui_open_files (struct _GSList *lst) { deadbeef->thread_start (open_files_worker, lst); } +void +strcopy_special (char *dest, const char *src, int len) { + while (len > 0) { + if (*src == '%' && len >= 3) { + int charcode = 0; + int byte; + byte = tolower (src[2]); + if (byte >= '0' && byte <= '9') { + charcode = byte - '0'; + } + else if (byte >= 'a' && byte <= 'f') { + charcode = byte - 'a' + 10; + } + else { + charcode = '?'; + } + if (charcode != '?') { + byte = tolower (src[1]); + if (byte >= '0' && byte <= '9') { + charcode |= (byte - '0') << 4; + } + else if (byte >= 'a' && byte <= 'f') { + charcode |= (byte - 'a' + 10) << 4; + } + else { + charcode = '?'; + } + } + *dest = charcode; + dest++; + src += 3; + len -= 3; + continue; + } + else { + *dest++ = *src++; + len--; + } + } + *dest = 0; +} + +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 (DdbListviewIter it, void *data) { +// FIXME: port +#if 0 + if (progress_is_aborted ()) { + return -1; + } + g_idle_add (set_progress_text_idle, it->fname); +#endif + return 0; +} + +static gboolean +progress_show_idle (gpointer data) { + progress_show (); + return FALSE; +} + +static gboolean +progress_hide_idle (gpointer data) { + progress_hide (); + playlist_refresh (); + return FALSE; +} + +void +gtkpl_add_fm_dropped_files (char *ptr, int length, int drop_y) { + // FIXME: port +#if 0 + DdbListview *pl = DDB_LISTVIEW (lookup_widget (mainwin, "playlist")); + g_idle_add (progress_show_idle, NULL); + +// int drop_row = drop_y / rowheight + ddb_get_vscroll_pos (pl); + DdbListviewIter iter = ddb_listview_get_iter_from_coord (0, drop_y); + drop_before = ((DdbListviewIter )iter); + int drop_row = deadbeef->pl_get_idx_of (drop_before); +// DdbListviewIter drop_before = deadbeef->pl_get_for_idx_and_iter (drop_row, PL_MAIN); + DdbListviewIter after = NULL; + if (drop_before) { + after = PL_PREV (drop_before, PL_MAIN); + UNREF (drop_before); + drop_before = NULL; + } + else { + after = PL_TAIL (ps->iterator); + } + const uint8_t *p = (const uint8_t*)ptr; + while (*p) { + const uint8_t *pe = p; + while (*pe && *pe > ' ') { + pe++; + } + if (pe - p < 4096 && pe - p > 7) { + char fname[(int)(pe - p)]; + strcopy_special (fname, p, pe-p); + //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); + if (!inserted && !abort) { + inserted = deadbeef->pl_insert_file (after, fname, &abort, gtkpl_add_file_info_cb, NULL); + } + if (inserted) { + if (after) { + UNREF (after); + } + after = inserted; + } + } + p = pe; + // skip whitespace + while (*p && *p <= ' ') { + p++; + } + } + free (ptr); + + if (after) { + UNREF (after); + } + g_idle_add (progress_hide_idle, NULL); +#endif +} + struct fmdrop_data { char *mem; int length; |