diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-03 19:39:25 +0100 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-03 19:39:25 +0100 |
commit | fd71c5952690f419b919eb3bc5facc9d332a98b9 (patch) | |
tree | 307bf5b9f314eef67af22f1275774a51cef979f3 /plugins/gtkui | |
parent | 553d1c27fec6e5ef1743f97e2e7c612ec8678ab8 (diff) |
changed action API to be backwards compatible with 0.5 on source level
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/actions.c | 46 | ||||
-rw-r--r-- | plugins/gtkui/actions.h | 6 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 8 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 78 | ||||
-rw-r--r-- | plugins/gtkui/hotkeys.c | 2 | ||||
-rw-r--r-- | plugins/gtkui/plcommon.c | 32 | ||||
-rw-r--r-- | plugins/gtkui/pltmenu.c | 7 | ||||
-rw-r--r-- | plugins/gtkui/widgets.c | 8 |
8 files changed, 108 insertions, 79 deletions
diff --git a/plugins/gtkui/actions.c b/plugins/gtkui/actions.c index a85851e9..74a2175f 100644 --- a/plugins/gtkui/actions.c +++ b/plugins/gtkui/actions.c @@ -24,6 +24,7 @@ #include "gtkui.h" #include "../../deadbeef.h" #include "support.h" +#include "actions.h" #define trace(...) { fprintf(stderr, __VA_ARGS__); } //#define trace(fmt,...) @@ -35,7 +36,12 @@ static gboolean menu_action_cb (void *ctx) { DB_plugin_action_t *action = ctx; - action->callback (action, DDB_ACTION_CTX_MAIN); + if (action->callback) { + gtkui_exec_action_14 (action, -1); + } + else if (action->callback2) { + action->callback2 (action, DDB_ACTION_CTX_MAIN); + } return FALSE; } @@ -94,7 +100,7 @@ add_mainmenu_actions (void) { char *tmp = NULL; - int has_addmenu = (action->flags & DB_ACTION_COMMON) && ((action->flags & DB_ACTION_ADD_MENU) | (action->flags & DB_ACTION_USING_API_14)); + int has_addmenu = (action->flags & DB_ACTION_COMMON) && ((action->flags & DB_ACTION_ADD_MENU) || (action->callback)); if (!has_addmenu) continue; @@ -183,3 +189,39 @@ add_mainmenu_actions (void) } } +void +gtkui_exec_action_14 (DB_plugin_action_t *action, int cursor) { + // Plugin can handle all tracks by itself + if (action->flags & DB_ACTION_CAN_MULTIPLE_TRACKS) + { + action->callback (action, NULL); + return; + } + + // For single-track actions just invoke it with first selected track + if (!(action->flags & DB_ACTION_MULTIPLE_TRACKS)) + { + if (cursor == -1) { + cursor = deadbeef->pl_get_cursor (PL_MAIN); + } + if (cursor == -1) + { + return; + } + DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (cursor, PL_MAIN); + action->callback (action, it); + deadbeef->pl_item_unref (it); + return; + } + + //We end up here if plugin won't traverse tracks and we have to do it ourselves + DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); + while (it) { + if (deadbeef->pl_is_selected (it)) { + action->callback (action, it); + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); + deadbeef->pl_item_unref (it); + it = next; + } +} diff --git a/plugins/gtkui/actions.h b/plugins/gtkui/actions.h index 815e99cc..e2c1f5a5 100644 --- a/plugins/gtkui/actions.h +++ b/plugins/gtkui/actions.h @@ -21,6 +21,10 @@ #ifndef __ACTIONS_H #define __ACTIONS_H -void add_mainmenu_actions (void); +void +add_mainmenu_actions (void); + +void +gtkui_exec_action_14 (DB_plugin_action_t *action, int cursor); #endif diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index b551f7d7..e1f943ee 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -50,6 +50,7 @@ #include "widgets.h" #include "../hotkeys/hotkeys.h" #include "actionhandlers.h" +#include "actions.h" //#define trace(...) { fprintf (stderr, __VA_ARGS__); } #define trace(fmt,...) @@ -204,11 +205,14 @@ on_mainwin_key_press_event (GtkWidget *widget, if (hkplug) { int ctx; DB_plugin_action_t *act = ((DB_hotkeys_plugin_t *)hkplug)->get_action_for_keycombo (accel_key, mods, 0, &ctx); - if (act && act->callback) { + if (act && act->callback2) { trace ("executing action %s in ctx %d\n", act->name, ctx); - act->callback (act, ctx); + act->callback2 (act, ctx); return TRUE; } + else if (act && act->callback) { + gtkui_exec_action_14 (act, -1); + } } trace ("action not found\n"); return FALSE; diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 3d958163..53f45f1f 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -1295,7 +1295,7 @@ static DB_plugin_action_t action_deselect_all = { .title = "Edit/Deselect All", .name = "deselect_all", .flags = DB_ACTION_COMMON, - .callback = action_deselect_all_handler, + .callback2 = action_deselect_all_handler, .next = NULL }; @@ -1303,7 +1303,7 @@ static DB_plugin_action_t action_select_all = { .title = "Edit/Select All", .name = "select_all", .flags = DB_ACTION_COMMON, - .callback = action_select_all_handler, + .callback2 = action_select_all_handler, .next = &action_deselect_all }; @@ -1311,7 +1311,7 @@ static DB_plugin_action_t action_quit = { .title = "Quit", .name = "quit", .flags = DB_ACTION_COMMON, - .callback = action_quit_handler, + .callback2 = action_quit_handler, .next = &action_select_all }; @@ -1319,7 +1319,7 @@ static DB_plugin_action_t action_delete_from_disk = { .title = "Delete From Disk", .name = "delete_from_disk", .flags = DB_ACTION_MULTIPLE_TRACKS, - .callback = action_delete_from_disk_handler, + .callback2 = action_delete_from_disk_handler, .next = &action_quit }; @@ -1327,7 +1327,7 @@ static DB_plugin_action_t action_add_location = { .title = "File/Add Location", .name = "add_location", .flags = DB_ACTION_COMMON, - .callback = action_add_location_handler, + .callback2 = action_add_location_handler, .next = &action_delete_from_disk }; @@ -1335,7 +1335,7 @@ static DB_plugin_action_t action_add_folders = { .title = "File/Add Folder(s)", .name = "add_folders", .flags = DB_ACTION_COMMON, - .callback = action_add_folders_handler, + .callback2 = action_add_folders_handler, .next = &action_add_location }; @@ -1343,7 +1343,7 @@ static DB_plugin_action_t action_add_files = { .title = "File/Add File(s)", .name = "add_files", .flags = DB_ACTION_COMMON, - .callback = action_add_files_handler, + .callback2 = action_add_files_handler, .next = &action_add_folders }; @@ -1351,7 +1351,7 @@ static DB_plugin_action_t action_open_files = { .title = "File/Open File(s)", .name = "open_files", .flags = DB_ACTION_COMMON, - .callback = action_open_files_handler, + .callback2 = action_open_files_handler, .next = &action_add_files }; @@ -1360,7 +1360,7 @@ static DB_plugin_action_t action_track_properties = { .title = "Track properties", .name = "track_properties", .flags = DB_ACTION_MULTIPLE_TRACKS, - .callback = action_show_track_properties_handler, + .callback2 = action_show_track_properties_handler, .next = &action_open_files }; @@ -1368,7 +1368,7 @@ static DB_plugin_action_t action_show_help = { .title = "Help/Show help page", .name = "help", .flags = DB_ACTION_COMMON, - .callback = action_show_help_handler, + .callback2 = action_show_help_handler, .next = &action_track_properties }; @@ -1376,7 +1376,7 @@ static DB_plugin_action_t action_playback_loop_cycle = { .title = "Playback/Cycle playback looping mode", .name = "loop_cycle", .flags = DB_ACTION_COMMON, - .callback = action_playback_loop_cycle_handler, + .callback2 = action_playback_loop_cycle_handler, .next = &action_show_help }; @@ -1384,7 +1384,7 @@ static DB_plugin_action_t action_playback_loop_off = { .title = "Playback/Playback looping - Don't loop", .name = "loop_off", .flags = DB_ACTION_COMMON, - .callback = action_playback_loop_off_handler, + .callback2 = action_playback_loop_off_handler, .next = &action_playback_loop_cycle }; @@ -1392,7 +1392,7 @@ static DB_plugin_action_t action_playback_loop_single = { .title = "Playback/Playback looping - Single track", .name = "loop_track", .flags = DB_ACTION_COMMON, - .callback = action_playback_loop_single_handler, + .callback2 = action_playback_loop_single_handler, .next = &action_playback_loop_off }; @@ -1400,7 +1400,7 @@ static DB_plugin_action_t action_playback_loop_all = { .title = "Playback/Playback looping - All", .name = "loop_all", .flags = DB_ACTION_COMMON, - .callback = action_playback_loop_all_handler, + .callback2 = action_playback_loop_all_handler, .next = &action_playback_loop_single }; @@ -1408,7 +1408,7 @@ static DB_plugin_action_t action_playback_order_cycle = { .title = "Playback/Cycle playback order", .name = "order_cycle", .flags = DB_ACTION_COMMON, - .callback = action_playback_order_cycle_handler, + .callback2 = action_playback_order_cycle_handler, .next = &action_playback_loop_all }; @@ -1416,7 +1416,7 @@ static DB_plugin_action_t action_playback_order_random = { .title = "Playback/Playback order - Random", .name = "order_random", .flags = DB_ACTION_COMMON, - .callback = action_playback_order_random_handler, + .callback2 = action_playback_order_random_handler, .next = &action_playback_order_cycle }; @@ -1424,7 +1424,7 @@ static DB_plugin_action_t action_playback_order_shuffle_albums = { .title = "Playback/Playback order - Shuffle albums", .name = "order_shuffle_albums", .flags = DB_ACTION_COMMON, - .callback = action_playback_order_shuffle_albums_handler, + .callback2 = action_playback_order_shuffle_albums_handler, .next = &action_playback_order_random }; @@ -1432,7 +1432,7 @@ static DB_plugin_action_t action_playback_order_shuffle = { .title = "Playback/Playback order - Shuffle tracks", .name = "order_shuffle", .flags = DB_ACTION_COMMON, - .callback = action_playback_order_shuffle_handler, + .callback2 = action_playback_order_shuffle_handler, .next = &action_playback_order_shuffle_albums }; @@ -1440,7 +1440,7 @@ static DB_plugin_action_t action_playback_order_linear = { .title = "Playback/Playback order - Linear", .name = "order_linear", .flags = DB_ACTION_COMMON, - .callback = action_playback_order_linear_handler, + .callback2 = action_playback_order_linear_handler, .next = &action_playback_order_shuffle }; @@ -1449,7 +1449,7 @@ static DB_plugin_action_t action_cursor_follows_playback = { .title = "Playback/Cursor follows playback toggle", .name = "toggle_cursor_follows_playback", .flags = DB_ACTION_COMMON, - .callback = action_cursor_follows_playback_handler, + .callback2 = action_cursor_follows_playback_handler, .next = &action_playback_order_linear }; @@ -1458,7 +1458,7 @@ static DB_plugin_action_t action_scroll_follows_playback = { .title = "Playback/Scroll follows playback toggle", .name = "toggle_scroll_follows_playback", .flags = DB_ACTION_COMMON, - .callback = action_scroll_follows_playback_handler, + .callback2 = action_scroll_follows_playback_handler, .next = &action_cursor_follows_playback }; @@ -1466,7 +1466,7 @@ static DB_plugin_action_t action_toggle_menu = { .title = "View/Show\\/Hide menu", .name = "toggle_menu", .flags = DB_ACTION_COMMON, - .callback = action_toggle_menu_handler, + .callback2 = action_toggle_menu_handler, .next = &action_scroll_follows_playback }; @@ -1474,7 +1474,7 @@ static DB_plugin_action_t action_toggle_statusbar = { .title = "View/Show\\/Hide statusbar", .name = "toggle_statusbar", .flags = DB_ACTION_COMMON, - .callback = action_toggle_statusbar_handler, + .callback2 = action_toggle_statusbar_handler, .next = &action_toggle_menu }; @@ -1482,7 +1482,7 @@ static DB_plugin_action_t action_toggle_designmode = { .title = "Edit/Toggle design mode", .name = "toggle_design_mode", .flags = DB_ACTION_COMMON, - .callback = action_toggle_designmode_handler, + .callback2 = action_toggle_designmode_handler, .next = &action_toggle_statusbar }; @@ -1490,7 +1490,7 @@ static DB_plugin_action_t action_preferences = { .title = "Edit/Preferences", .name = "preferences", .flags = DB_ACTION_COMMON, - .callback = action_preferences_handler, + .callback2 = action_preferences_handler, .next = &action_toggle_designmode }; @@ -1498,7 +1498,7 @@ static DB_plugin_action_t action_sort_custom = { .title = "Edit/Sort Custom", .name = "sort_custom", .flags = DB_ACTION_COMMON, - .callback = action_sort_custom_handler, + .callback2 = action_sort_custom_handler, .next = &action_preferences }; @@ -1506,7 +1506,7 @@ static DB_plugin_action_t action_crop_selected = { .title = "Edit/Crop Selected", .name = "crop_selected", .flags = DB_ACTION_COMMON, - .callback = action_crop_selected_handler, + .callback2 = action_crop_selected_handler, .next = &action_sort_custom }; @@ -1514,7 +1514,7 @@ static DB_plugin_action_t action_remove_from_playlist = { .title = "Edit/Remove from current playlist", .name = "remove_from_playlist", .flags = DB_ACTION_MULTIPLE_TRACKS, - .callback = action_remove_from_playlist_handler, + .callback2 = action_remove_from_playlist_handler, .next = &action_crop_selected }; @@ -1522,7 +1522,7 @@ static DB_plugin_action_t action_save_playlist = { .title = "File/Save playlist", .name = "save_playlist", .flags = DB_ACTION_COMMON, - .callback = action_save_playlist_handler, + .callback2 = action_save_playlist_handler, .next = &action_remove_from_playlist }; @@ -1530,7 +1530,7 @@ static DB_plugin_action_t action_load_playlist = { .title = "File/Load playlist", .name = "load_playlist", .flags = DB_ACTION_COMMON, - .callback = action_load_playlist_handler, + .callback2 = action_load_playlist_handler, .next = &action_save_playlist }; @@ -1538,7 +1538,7 @@ static DB_plugin_action_t action_remove_current_playlist = { .title = "File/Remove current playlist", .name = "remove_current_playlist", .flags = DB_ACTION_COMMON, - .callback = action_remove_current_playlist_handler, + .callback2 = action_remove_current_playlist_handler, .next = &action_load_playlist }; @@ -1547,7 +1547,7 @@ static DB_plugin_action_t action_new_playlist = { .title = "File/New Playlist", .name = "new_playlist", .flags = DB_ACTION_COMMON, - .callback = action_new_playlist_handler, + .callback2 = action_new_playlist_handler, .next = &action_remove_current_playlist }; @@ -1555,7 +1555,7 @@ static DB_plugin_action_t action_toggle_eq = { .title = "View/Show\\/Hide Equalizer", .name = "toggle_eq", .flags = DB_ACTION_COMMON, - .callback = action_toggle_eq_handler, + .callback2 = action_toggle_eq_handler, .next = &action_new_playlist }; @@ -1563,7 +1563,7 @@ static DB_plugin_action_t action_hide_eq = { .title = "View/Hide Equalizer", .name = "hide_eq", .flags = DB_ACTION_COMMON, - .callback = action_hide_eq_handler, + .callback2 = action_hide_eq_handler, .next = &action_toggle_eq }; @@ -1571,7 +1571,7 @@ static DB_plugin_action_t action_show_eq = { .title = "View/Show Equalizer", .name = "show_eq", .flags = DB_ACTION_COMMON, - .callback = action_show_eq_handler, + .callback2 = action_show_eq_handler, .next = &action_hide_eq }; @@ -1579,7 +1579,7 @@ static DB_plugin_action_t action_toggle_mainwin = { .title = "View/Show\\/Hide Player Window", .name = "toggle_player_window", .flags = DB_ACTION_COMMON, - .callback = action_toggle_mainwin_handler, + .callback2 = action_toggle_mainwin_handler, .next = &action_show_eq }; @@ -1587,7 +1587,7 @@ static DB_plugin_action_t action_hide_mainwin = { .title = "View/Hide Player Window", .name = "hide_player_window", .flags = DB_ACTION_COMMON, - .callback = action_hide_mainwin_handler, + .callback2 = action_hide_mainwin_handler, .next = &action_toggle_mainwin }; @@ -1595,7 +1595,7 @@ static DB_plugin_action_t action_show_mainwin = { .title = "View/Show Player Window", .name = "show_player_window", .flags = DB_ACTION_COMMON, - .callback = action_show_mainwin_handler, + .callback2 = action_show_mainwin_handler, .next = &action_hide_mainwin }; @@ -1603,7 +1603,7 @@ static DB_plugin_action_t action_find = { .title = "Edit/Find", .name = "find", .flags = DB_ACTION_COMMON, - .callback = action_find_handler, + .callback2 = action_find_handler, .next = &action_show_mainwin }; diff --git a/plugins/gtkui/hotkeys.c b/plugins/gtkui/hotkeys.c index 33bf01e2..f176cf8d 100644 --- a/plugins/gtkui/hotkeys.c +++ b/plugins/gtkui/hotkeys.c @@ -344,7 +344,7 @@ init_action_tree (GtkWidget *actions, const char *act, int ctx) { unescape_forward_slash (t, title, sizeof (title)); gtk_tree_store_set (actions_store, &iter, 0, title, 1, actions->name, 2, DDB_ACTION_CTX_MAIN, -1); } - if (actions->flags & (DB_ACTION_SINGLE_TRACK | DB_ACTION_MULTIPLE_TRACKS | DB_ACTION_CAN_MULTIPLE_TRACKS__DEPRECATED)) { + if (actions->flags & (DB_ACTION_SINGLE_TRACK | DB_ACTION_MULTIPLE_TRACKS | DB_ACTION_CAN_MULTIPLE_TRACKS)) { t = action_tree_append (actions->title, actions_store, &action_selection_iter, &iter); unescape_forward_slash (t, title, sizeof (title)); gtk_tree_store_set (actions_store, &iter, 0, title, 1, actions->name, 2, DDB_ACTION_CTX_SELECTION, -1); diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c index 08f7e3fa..299384d0 100644 --- a/plugins/gtkui/plcommon.c +++ b/plugins/gtkui/plcommon.c @@ -467,37 +467,11 @@ void actionitem_activate (GtkMenuItem *menuitem, DB_plugin_action_t *action) { - if (action->flags & DB_ACTION_USING_API_14) { - typedef int (*action_callback_14_t)(struct DB_plugin_action_s *action, void *userdata); - // Plugin can handle all tracks by itself - if (action->flags & DB_ACTION_CAN_MULTIPLE_TRACKS__DEPRECATED) - { - ((action_callback_14_t)action->callback) (action, NULL); - return; - } - - // For single-track actions just invoke it with first selected track - if (!(action->flags & DB_ACTION_MULTIPLE_TRACKS)) - { - DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (clicked_idx, PL_MAIN); - ((action_callback_14_t)action->callback) (action, it); - deadbeef->pl_item_unref (it); - return; - } - - //We end up here if plugin won't traverse tracks and we have to do it ourselves - DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); - while (it) { - if (deadbeef->pl_is_selected (it)) { - ((action_callback_14_t)action->callback) (action, it); - } - DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); - deadbeef->pl_item_unref (it); - it = next; - } + if (action->callback) { + gtkui_exec_action_14 (action, clicked_idx); } else { - action->callback (action, DDB_ACTION_CTX_SELECTION); + action->callback2 (action, DDB_ACTION_CTX_SELECTION); } } diff --git a/plugins/gtkui/pltmenu.c b/plugins/gtkui/pltmenu.c index eb6c4b3d..6fd803a2 100644 --- a/plugins/gtkui/pltmenu.c +++ b/plugins/gtkui/pltmenu.c @@ -105,19 +105,18 @@ static void on_actionitem_activate (GtkMenuItem *menuitem, DB_plugin_action_t *action) { - if (action->flags & DB_ACTION_USING_API_14) { + if (action->callback) { ddb_playlist_t *plt = NULL; if (pltmenu_idx != -1) { plt = deadbeef->plt_get_for_idx (pltmenu_idx); } - typedef int (*action_callback_14_t)(struct DB_plugin_action_s *action, void *userdata); - ((action_callback_14_t)action->callback) (action, plt); + action->callback (action, plt); if (plt) { deadbeef->plt_unref (plt); } } else { - action->callback (action, DDB_ACTION_CTX_PLAYLIST); + action->callback2 (action, DDB_ACTION_CTX_PLAYLIST); } } diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index d65987f1..d4f58d0a 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -3224,7 +3224,13 @@ on_button_clicked (GtkButton *button, DB_plugin_action_t *acts = plugins[i]->get_actions (NULL); while (acts) { if (!strcmp (acts->name, w->action)) { - acts->callback (acts, w->action_ctx); + if (acts->callback) { +#warning FIXME: context + acts->callback (acts, NULL); + } + else if (acts->callback2) { + acts->callback2 (acts, w->action_ctx); + } return; } acts = acts->next; |