diff options
author | waker <wakeroid@gmail.com> | 2012-11-18 21:06:03 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-11-18 21:06:03 +0100 |
commit | ce61239ec9771efb95790bbbb349ecfdf21f1ac9 (patch) | |
tree | 25f898a6502bb74ae8cac6825403fa92a9010d8e | |
parent | c07825fe34a7c935372961725f46a3288de8ee85 (diff) |
gtkui: added track properties hotkey impl
-rw-r--r-- | plugins/gtkui/actionhandlers.c | 13 | ||||
-rw-r--r-- | plugins/gtkui/actionhandlers.h | 6 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/plcommon.c | 2 | ||||
-rw-r--r-- | plugins/gtkui/trkproperties.c | 76 | ||||
-rw-r--r-- | plugins/gtkui/trkproperties.h | 2 |
6 files changed, 77 insertions, 28 deletions
diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index a7337a1a..d6c7c93e 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -35,6 +35,7 @@ #include "support.h" #include "wingeom.h" #include "interface.h" +#include "trkproperties.h" extern GtkWidget *mainwin; extern DB_functions_t *deadbeef; @@ -559,3 +560,15 @@ action_delete_from_disk_handler (DB_plugin_action_t *act, int ctx) { gdk_threads_add_idle (action_delete_from_disk_handler_cb, (void *)(intptr_t)ctx); return 0; } + +gboolean +action_show_track_properties_handler_cb (void *data) { + show_track_properties_dlg ((intptr_t)data); + return FALSE; +} + +int +action_show_track_properties_handler (DB_plugin_action_t *act, int ctx) { + gdk_threads_add_idle (action_show_track_properties_handler_cb, (void *)(intptr_t)ctx); + return 0; +} diff --git a/plugins/gtkui/actionhandlers.h b/plugins/gtkui/actionhandlers.h index 03af45d2..cd4808c7 100644 --- a/plugins/gtkui/actionhandlers.h +++ b/plugins/gtkui/actionhandlers.h @@ -108,4 +108,10 @@ action_delete_from_disk_handler_cb (void *data); int action_delete_from_disk_handler (DB_plugin_action_t *act, int ctx); +gboolean +action_show_track_properties_handler_cb (void *data); + +int +action_show_track_properties_handler (DB_plugin_action_t *act, int ctx); + #endif diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 43a093bc..742cc1e5 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -1463,7 +1463,7 @@ static DB_plugin_action_t action_quit = { static DB_plugin_action_t action_delete_from_disk = { .title = "Delete From Disk", .name = "delete_from_disk", - .flags = DB_ACTION_SINGLE_TRACK | DB_ACTION_MULTIPLE_TRACKS, + .flags = DB_ACTION_MULTIPLE_TRACKS, .callback = action_delete_from_disk_handler, .next = &action_quit }; @@ -1502,10 +1502,10 @@ static DB_plugin_action_t action_open_files = { static DB_plugin_action_t action_track_properties = { - .title = "[stub] Track properties", + .title = "Track properties", .name = "track_properties", .flags = DB_ACTION_MULTIPLE_TRACKS, - .callback = NULL, + .callback = action_show_track_properties_handler, .next = &action_open_files }; diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c index 77127bea..0f4d565c 100644 --- a/plugins/gtkui/plcommon.c +++ b/plugins/gtkui/plcommon.c @@ -295,7 +295,7 @@ void main_properties_activate (GtkMenuItem *menuitem, gpointer user_data) { - show_track_properties_dlg (); + action_show_track_properties_handler_cb ((void *)(intptr_t)DDB_ACTION_CTX_SELECTION); } void diff --git a/plugins/gtkui/trkproperties.c b/plugins/gtkui/trkproperties.c index 36d3d2c4..4c559a55 100644 --- a/plugins/gtkui/trkproperties.c +++ b/plugins/gtkui/trkproperties.c @@ -51,6 +51,7 @@ static DB_playItem_t **tracks; static int numtracks; static GtkWidget *progressdlg; static int progress_aborted; +static int last_ctx; int build_key_list (const char ***pkeys, int props, DB_playItem_t **tracks, int numtracks) { @@ -383,9 +384,8 @@ trkproperties_fill_metadata (void) { } void -show_track_properties_dlg (void) { - - deadbeef->pl_lock (); +show_track_properties_dlg (int ctx) { + last_ctx = ctx; if (tracks) { for (int i = 0; i < numtracks; i++) { @@ -396,29 +396,59 @@ show_track_properties_dlg (void) { numtracks = 0; } - int nsel = deadbeef->pl_getselcount (); - if (0 < nsel) { - tracks = malloc (sizeof (DB_playItem_t *) * nsel); - if (tracks) { - int n = 0; - DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); - while (it) { - if (deadbeef->pl_is_selected (it)) { - assert (n < nsel); - deadbeef->pl_item_ref (it); - tracks[n++] = it; - } - DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); - deadbeef->pl_item_unref (it); - it = next; - } - numtracks = nsel; - } - else { + deadbeef->pl_lock (); + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (!plt) { + deadbeef->pl_unlock (); + return; + } + int num = 0; + if (ctx == DDB_ACTION_CTX_SELECTION) { + num = deadbeef->plt_getselcount (plt); + } + else if (ctx == DDB_ACTION_CTX_PLAYLIST) { + num = deadbeef->plt_get_item_count (plt, PL_MAIN); + } + else if (ctx == DDB_ACTION_CTX_NOWPLAYING) { + num = 1; + } + if (num <= 0) { + deadbeef->pl_unlock (); + return; + } + + tracks = malloc (sizeof (DB_playItem_t *) * num); + if (!tracks) { + fprintf (stderr, "gtkui: failed to alloc %d bytes to store selected tracks\n", num * sizeof (void *)); + deadbeef->pl_unlock (); + return; + } + + if (ctx == DDB_ACTION_CTX_NOWPLAYING) { + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (!it) { + free (tracks); + tracks = NULL; deadbeef->pl_unlock (); return; } + tracks[0] = it; + } + else { + int n = 0; + DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); + while (it) { + if (ctx == DDB_ACTION_CTX_PLAYLIST || deadbeef->pl_is_selected (it)) { + assert (n < num); + deadbeef->pl_item_ref (it); + tracks[n++] = it; + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); + deadbeef->pl_item_unref (it); + it = next; + } } + numtracks = num; deadbeef->pl_unlock (); @@ -516,7 +546,7 @@ write_finished_cb (void *ctx) { main_refresh (); search_refresh (); trkproperties_modified = 0; - show_track_properties_dlg (); + show_track_properties_dlg (last_ctx); return FALSE; } diff --git a/plugins/gtkui/trkproperties.h b/plugins/gtkui/trkproperties.h index ef1e530c..b081fcef 100644 --- a/plugins/gtkui/trkproperties.h +++ b/plugins/gtkui/trkproperties.h @@ -24,7 +24,7 @@ struct DB_playItem_s; void -show_track_properties_dlg (void); +show_track_properties_dlg (int ctx); void trkproperties_destroy (void); |