From daad4ed47ad2a21b46d19829c8627eeaf24fe82a Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 18 Nov 2012 22:14:05 +0100 Subject: gtkuiL: hotkeys WIP --- plugins/gtkui/actionhandlers.c | 201 +++++++++++++++++++++++++++++++++++++++++ plugins/gtkui/actionhandlers.h | 30 ++++++ plugins/gtkui/gtkui.c | 173 +++++------------------------------ plugins/hotkeys/hotkeys.c | 10 +- 4 files changed, 256 insertions(+), 158 deletions(-) diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index d6c7c93e..2802abd5 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -572,3 +572,204 @@ 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; } + +gboolean +action_find_handler_cb (void *data) { + search_start (); + return FALSE; +} + +int +action_find_handler (DB_plugin_action_t *act, int ctx) { + gdk_threads_add_idle (action_find_handler_cb, NULL); + return 0; +} + +gboolean +action_scroll_follows_playback_handler_cb (void *data) { + int val = 1 - deadbeef->conf_get_int ("playlist.scroll.followplayback", 0); + deadbeef->conf_set_int ("playlist.scroll.followplayback", val); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (lookup_widget (mainwin, "scroll_follows_playback")), val); + return FALSE; +} + +int +action_scroll_follows_playback_handler (DB_plugin_action_t *act, int ctx) { + g_idle_add (action_scroll_follows_playback_handler_cb, NULL); + return 0; +} + +gboolean +action_cursor_follows_playback_handler_cb (void *data) { + int val = 1 - deadbeef->conf_get_int ("playlist.scroll.cursorfollowplayback", 0); + deadbeef->conf_set_int ("playlist.scroll.cursorfollowplayback", val); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (lookup_widget (mainwin, "cursor_follows_playback")), val); + return FALSE; +} + +int +action_cursor_follows_playback_handler (DB_plugin_action_t *act, int ctx) { + g_idle_add (action_cursor_follows_playback_handler_cb, NULL); + return 0; +} + +static gboolean +playlist_filter_func (const GtkFileFilterInfo *filter_info, gpointer data) { + // get ext + const char *p = strrchr (filter_info->filename, '.'); + if (!p) { + return FALSE; + } + p++; + DB_playlist_t **plug = deadbeef->plug_get_playlist_list (); + for (int i = 0; plug[i]; i++) { + if (plug[i]->extensions && plug[i]->load) { + const char **exts = plug[i]->extensions; + if (exts) { + for (int e = 0; exts[e]; e++) { + if (!strcasecmp (exts[e], p)) { + return TRUE; + } + } + } + } + } + return FALSE; +} + +static 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 (); +} + + +gboolean +action_load_playlist_handler_cb (void *data) { + GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Load Playlist"), GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); + + // restore folder + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); + deadbeef->conf_unlock (); + + GtkFileFilter* flt; + flt = gtk_file_filter_new (); + gtk_file_filter_set_name (flt, "Supported playlist formats"); + gtk_file_filter_add_custom (flt, GTK_FILE_FILTER_FILENAME, playlist_filter_func, NULL, NULL); + gtk_file_filter_add_pattern (flt, "*.dbpl"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dlg), flt); + flt = gtk_file_filter_new (); + gtk_file_filter_set_name (flt, _("Other files (*)")); + gtk_file_filter_add_pattern (flt, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); + + int res = gtk_dialog_run (GTK_DIALOG (dlg)); + // store folder + gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); + if (folder) { + deadbeef->conf_set_str ("filechooser.playlist.lastdir", folder); + g_free (folder); + } + if (res == GTK_RESPONSE_OK) + { + gchar *fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg)); + gtk_widget_destroy (dlg); + if (fname) { + uintptr_t tid = deadbeef->thread_start (load_playlist_thread, fname); + deadbeef->thread_detach (tid); + } + } + else { + gtk_widget_destroy (dlg); + } + return FALSE; +} + +int +action_load_playlist_handler (DB_plugin_action_t *act, int ctx) { + gdk_threads_add_idle (action_load_playlist_handler_cb, NULL); + return 0; +} + +gboolean +action_save_playlist_handler_cb (void *data) { + GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Save Playlist As"), GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); + + gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dlg), TRUE); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dlg), "untitled.dbpl"); + // restore folder + deadbeef->conf_lock (); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); + deadbeef->conf_unlock (); + + GtkFileFilter* flt; + flt = gtk_file_filter_new (); + gtk_file_filter_set_name (flt, _("DeaDBeeF playlist files (*.dbpl)")); + gtk_file_filter_add_pattern (flt, "*.dbpl"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); + DB_playlist_t **plug = deadbeef->plug_get_playlist_list (); + for (int i = 0; plug[i]; i++) { + if (plug[i]->extensions && plug[i]->load) { + const char **exts = plug[i]->extensions; + if (exts && plug[i]->save) { + for (int e = 0; exts[e]; e++) { + char s[100]; + flt = gtk_file_filter_new (); + gtk_file_filter_set_name (flt, exts[e]); + snprintf (s, sizeof (s), "*.%s", exts[e]); + gtk_file_filter_add_pattern (flt, s); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); + } + } + } + } + + int res = gtk_dialog_run (GTK_DIALOG (dlg)); + // store folder + gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); + if (folder) { + deadbeef->conf_set_str ("filechooser.playlist.lastdir", folder); + g_free (folder); + } + if (res == GTK_RESPONSE_OK) + { + 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) { + int res = deadbeef->plt_save (plt, NULL, NULL, fname, NULL, NULL, NULL); + if (res >= 0 && strlen (fname) < 1024) { + deadbeef->conf_set_str ("gtkui.last_playlist_save_name", fname); + } + deadbeef->plt_unref (plt); + } + g_free (fname); + } + } + else { + gtk_widget_destroy (dlg); + } + return FALSE; +} + +int +action_save_playlist_handler (DB_plugin_action_t *act, int ctx) { + gdk_threads_add_idle (action_save_playlist_handler_cb, NULL); + return 0; +} + diff --git a/plugins/gtkui/actionhandlers.h b/plugins/gtkui/actionhandlers.h index cd4808c7..fbe2b5ca 100644 --- a/plugins/gtkui/actionhandlers.h +++ b/plugins/gtkui/actionhandlers.h @@ -114,4 +114,34 @@ action_show_track_properties_handler_cb (void *data); int action_show_track_properties_handler (DB_plugin_action_t *act, int ctx); +gboolean +action_find_handler_cb (void *data); + +int +action_find_handler (DB_plugin_action_t *act, int ctx); + +gboolean +action_scroll_follows_playback_handler_cb (void *data); + +int +action_scroll_follows_playback_handler (DB_plugin_action_t *act, int ctx); + +gboolean +action_cursor_follows_playback_handler_cb (void *data); + +int +action_cursor_follows_playback_handler (DB_plugin_action_t *act, int ctx); + +gboolean +action_load_playlist_handler_cb (void *data); + +int +action_load_playlist_handler (DB_plugin_action_t *act, int ctx); + +gboolean +action_save_playlist_handler_cb (void *data); + +int +action_save_playlist_handler (DB_plugin_action_t *act, int ctx); + #endif diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 8f4de0b3..69aa12b6 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -617,74 +617,18 @@ outputchanged_cb (gpointer nothing) { return FALSE; } -char last_playlist_save_name[1024] = ""; - void save_playlist_as (void) { - GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Save Playlist As"), GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); - - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dlg), TRUE); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dlg), "untitled.dbpl"); - // restore folder - deadbeef->conf_lock (); - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); - deadbeef->conf_unlock (); - - GtkFileFilter* flt; - flt = gtk_file_filter_new (); - gtk_file_filter_set_name (flt, _("DeaDBeeF playlist files (*.dbpl)")); - gtk_file_filter_add_pattern (flt, "*.dbpl"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); - DB_playlist_t **plug = deadbeef->plug_get_playlist_list (); - for (int i = 0; plug[i]; i++) { - if (plug[i]->extensions && plug[i]->load) { - const char **exts = plug[i]->extensions; - if (exts && plug[i]->save) { - for (int e = 0; exts[e]; e++) { - char s[100]; - flt = gtk_file_filter_new (); - gtk_file_filter_set_name (flt, exts[e]); - snprintf (s, sizeof (s), "*.%s", exts[e]); - gtk_file_filter_add_pattern (flt, s); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); - } - } - } - } - - int res = gtk_dialog_run (GTK_DIALOG (dlg)); - // store folder - gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); - if (folder) { - deadbeef->conf_set_str ("filechooser.playlist.lastdir", folder); - g_free (folder); - } - if (res == GTK_RESPONSE_OK) - { - 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) { - int res = deadbeef->plt_save (plt, NULL, NULL, fname, NULL, NULL, NULL); - if (res >= 0 && strlen (fname) < 1024) { - strcpy (last_playlist_save_name, fname); - } - deadbeef->plt_unref (plt); - } - g_free (fname); - } - } - else { - gtk_widget_destroy (dlg); - } + action_save_playlist_handler_cb (NULL); } +#if 0 void on_playlist_save_activate (GtkMenuItem *menuitem, gpointer user_data) { + char last_playlist_save_name[1024]; + deadbeef->conf_get_str ("gtkui.last_playlist_save_name", "", last_playlist_save_name, sizeof (last_playlist_save_name)); if (!last_playlist_save_name[0]) { save_playlist_as (); } @@ -696,6 +640,7 @@ on_playlist_save_activate (GtkMenuItem *menuitem, } } } +#endif void @@ -705,89 +650,11 @@ on_playlist_save_as_activate (GtkMenuItem *menuitem, save_playlist_as (); } -static gboolean -playlist_filter_func (const GtkFileFilterInfo *filter_info, gpointer data) { - // get ext - const char *p = strrchr (filter_info->filename, '.'); - if (!p) { - return FALSE; - } - p++; - DB_playlist_t **plug = deadbeef->plug_get_playlist_list (); - for (int i = 0; plug[i]; i++) { - if (plug[i]->extensions && plug[i]->load) { - const char **exts = plug[i]->extensions; - if (exts) { - for (int e = 0; exts[e]; e++) { - if (!strcasecmp (exts[e], p)) { - return TRUE; - } - } - } - } - } - return FALSE; -} - -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) { - GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Load Playlist"), GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); - - // restore folder - deadbeef->conf_lock (); - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dlg), deadbeef->conf_get_str_fast ("filechooser.playlist.lastdir", "")); - deadbeef->conf_unlock (); - - GtkFileFilter* flt; - flt = gtk_file_filter_new (); - gtk_file_filter_set_name (flt, "Supported playlist formats"); - gtk_file_filter_add_custom (flt, GTK_FILE_FILTER_FILENAME, playlist_filter_func, NULL, NULL); - gtk_file_filter_add_pattern (flt, "*.dbpl"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dlg), flt); - flt = gtk_file_filter_new (); - gtk_file_filter_set_name (flt, _("Other files (*)")); - gtk_file_filter_add_pattern (flt, "*"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt); - - int res = gtk_dialog_run (GTK_DIALOG (dlg)); - // store folder - gchar *folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dlg)); - if (folder) { - deadbeef->conf_set_str ("filechooser.playlist.lastdir", folder); - g_free (folder); - } - if (res == GTK_RESPONSE_OK) - { - gchar *fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg)); - gtk_widget_destroy (dlg); - if (fname) { - uintptr_t tid = deadbeef->thread_start (load_playlist_thread, fname); - deadbeef->thread_detach (tid); - } - } - else { - gtk_widget_destroy (dlg); - } + action_load_playlist_handler_cb (NULL); } void @@ -1521,12 +1388,21 @@ static DB_plugin_action_t action_show_help = { .next = &action_track_properties }; +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, + .next = &action_show_help +}; + + static DB_plugin_action_t action_scroll_follows_playback = { - .title = "Playback/[stub] Scroll follows playback toggle", + .title = "Playback/Scroll follows playback toggle", .name = "toggle_scroll_follows_playback", .flags = DB_ACTION_COMMON, - .callback = NULL, - .next = &action_show_help + .callback = action_scroll_follows_playback_handler, + .next = &action_cursor_follows_playback }; static DB_plugin_action_t action_toggle_menu = { @@ -1593,20 +1469,19 @@ static DB_plugin_action_t action_remove_from_playlist = { .next = &action_crop_selected }; - static DB_plugin_action_t action_save_playlist = { - .title = "File/[stub] Save Playlist", + .title = "File/Save playlist", .name = "save_playlist", .flags = DB_ACTION_COMMON, - .callback = NULL, + .callback = action_save_playlist_handler, .next = &action_remove_from_playlist }; static DB_plugin_action_t action_load_playlist = { - .title = "File/[stub] Load Playlist", + .title = "File/Load playlist", .name = "load_playlist", .flags = DB_ACTION_COMMON, - .callback = NULL, + .callback = action_load_playlist_handler, .next = &action_save_playlist }; @@ -1676,10 +1551,10 @@ static DB_plugin_action_t action_show_mainwin = { }; static DB_plugin_action_t action_find = { - .title = "Edit/[stub] Find", + .title = "Edit/Find", .name = "find", .flags = DB_ACTION_COMMON, - .callback = NULL, + .callback = action_find_handler, .next = &action_show_mainwin }; diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c index 7ca57fe3..6c8ca0d7 100644 --- a/plugins/hotkeys/hotkeys.c +++ b/plugins/hotkeys/hotkeys.c @@ -706,20 +706,12 @@ static DB_plugin_action_t action_jump_to_current = { .next = &action_reload_metadata }; -static DB_plugin_action_t action_toggle_cursor_follows_playback = { - .title = "Playback/[stub] Cursor follows playback toggle", - .name = "toggle_cursor_follows_playback", - .flags = DB_ACTION_COMMON, - .callback = NULL, - .next = &action_jump_to_current -}; - static DB_plugin_action_t action_playback_loop_off = { .title = "Playback/[stub] Playback looping - Don't loop", .name = "loop_off", .flags = DB_ACTION_COMMON, .callback = NULL, - .next = &action_toggle_cursor_follows_playback + .next = &action_jump_to_current }; static DB_plugin_action_t action_playback_loop_single = { -- cgit v1.2.3