From 1a20e32e750ae032f21c13f8001c718e42aeff41 Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 6 Nov 2012 20:31:23 +0100 Subject: gtkui: removed old hotkey config code --- plugins/gtkui/prefwin.c | 349 ------------------------------------------------ 1 file changed, 349 deletions(-) diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index 2a462c09..ca14c4ea 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -30,7 +30,6 @@ #include "interface.h" #include "callbacks.h" #include "drawing.h" -#include "../hotkeys/hotkeys.h" #include "eq.h" #include "ddblistview.h" #include "pluginconf.h" @@ -99,185 +98,6 @@ preferences_fill_soundcards (void) { } } -static gboolean -add_hotkey_to_config (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { - int *counter = (int *)data; - GValue key = {0,}, value = {0,}; - gtk_tree_model_get_value (model, iter, 2, &key); - gtk_tree_model_get_value (model, iter, 1, &value); - const char *skey = g_value_get_string (&key); - const char *svalue = g_value_get_string (&value); - - char conf_name[100]; - char conf_value[100]; - snprintf (conf_name, sizeof (conf_name), "hotkeys.key%d", *counter); - (*counter)++; - snprintf (conf_value, sizeof (conf_value), "%s: %s", svalue, skey); - deadbeef->conf_set_str (conf_name, conf_value); - - g_value_unset (&key); - g_value_unset (&value); - - return FALSE; -} - -void -hotkeys_apply (GtkTreeModel *model) { - DB_plugin_t *hotkeys = deadbeef->plug_get_for_id ("hotkeys"); - if (hotkeys) { - // rebuild config - deadbeef->conf_remove_items ("hotkeys.key"); - int counter = 1; - gtk_tree_model_foreach (model, add_hotkey_to_config, &counter); - - ((DB_hotkeys_plugin_t *)hotkeys)->reset (); - } -} - -#if 0 // this doesn't work well with combobox cells -void -on_hk_slot_edited (GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data) { - if (!new_text || !new_text[0]) { - return; - } - GtkListStore *store = GTK_LIST_STORE (user_data); - GtkTreePath *treepath = gtk_tree_path_new_from_string (path); - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, treepath); - gtk_tree_path_free (treepath); - gtk_list_store_set (store, &iter, 0, new_text, -1); -} -#endif - -void -on_hk_slot_changed (GtkCellRendererCombo *combo, gchar *path, GtkTreeIter *new_iter, gpointer user_data) { - GtkTreeModel *combo_model = NULL; - g_object_get (combo, "model", &combo_model, NULL); - GValue gtitle = {0,}, gname = {0,}; - gtk_tree_model_get_value (combo_model, new_iter, 0, >itle); - gtk_tree_model_get_value (combo_model, new_iter, 1, &gname); - - const char *title = g_value_get_string (>itle); - const char *name = g_value_get_string (&gname); - - GtkListStore *store = GTK_LIST_STORE (user_data); - GtkTreePath *treepath = gtk_tree_path_new_from_string (path); - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, treepath); - gtk_tree_path_free (treepath); - - gtk_list_store_set (store, &iter, 0, title, 2, name, -1); - - g_value_unset (>itle); - g_value_unset (&gname); - hotkeys_apply (GTK_TREE_MODEL (store)); -} - -void -on_hk_binding_edited (GtkCellRendererAccel *accel, gchar *path, guint accel_key, GdkModifierType accel_mods, guint hardware_keycode, gpointer user_data) { - GtkListStore *store = GTK_LIST_STORE (user_data); - GtkTreePath *treepath = gtk_tree_path_new_from_string (path); - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, treepath); - gtk_tree_path_free (treepath); - - // build value - char new_value[1000] = ""; - if (accel_mods & GDK_SHIFT_MASK) { - strcat (new_value, "Shift "); - } - if (accel_mods & GDK_CONTROL_MASK) { - strcat (new_value, "Ctrl "); - } - if (accel_mods & GDK_SUPER_MASK) { - strcat (new_value, "Super "); - } - if (accel_mods & GDK_MOD1_MASK) { - strcat (new_value, "Alt "); - } - - // translate numlock keycodes into non-numlock codes - switch (accel_key) { - case GDK_KP_0: - accel_key = GDK_KP_Insert; - break; - case GDK_KP_1: - accel_key = GDK_KP_End; - break; - case GDK_KP_2: - accel_key = GDK_KP_Down; - break; - case GDK_KP_3: - accel_key = GDK_KP_Page_Down; - break; - case GDK_KP_4: - accel_key = GDK_KP_Left; - break; - case GDK_KP_6: - accel_key = GDK_KP_Right; - break; - case GDK_KP_7: - accel_key = GDK_KP_Home; - break; - case GDK_KP_8: - accel_key = GDK_KP_Up; - break; - case GDK_KP_9: - accel_key = GDK_KP_Page_Up; - break; - } - - // find key name from hotkeys plugin - DB_plugin_t *hotkeys = deadbeef->plug_get_for_id ("hotkeys"); - if (hotkeys) { - const char *name = ((DB_hotkeys_plugin_t *)hotkeys)->get_name_for_keycode (accel_key); - strcat (new_value, name); - gtk_list_store_set (store, &iter, 1, new_value, -1); - - hotkeys_apply (GTK_TREE_MODEL (store)); - } -} - -void -on_addhotkey_clicked (GtkButton *button, gpointer user_data) { - GtkListStore *store = GTK_LIST_STORE (user_data); - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - DB_plugin_t **plugins = deadbeef->plug_get_list (); - for (int i = 0; plugins[i]; i++) { - DB_plugin_t *p = plugins[i]; - if (p->get_actions) { - DB_plugin_action_t *actions = plugins[i]->get_actions (NULL); - while (actions) { - if (actions->name && actions->title) { // only add actions with both the name and the title - gtk_list_store_set (store, &iter, 0, actions->title, 1, "", 2, actions->name, -1); - break; - } - actions = actions->next; - } - if (actions) { - break; - } - } - } -} - -void -on_removehotkey_clicked (GtkButton *button, gpointer user_data) { - GtkTreeView *tree = GTK_TREE_VIEW (user_data); - GtkTreeModel *model = gtk_tree_view_get_model (tree); - if (model) { - GtkTreeSelection *sel = gtk_tree_view_get_selection (tree); - if (sel) { - GtkTreeIter iter; - if (gtk_tree_selection_get_selected (sel, NULL, &iter)) { - gtk_list_store_remove (GTK_LIST_STORE (model), &iter); - } - } - } - hotkeys_apply (model); -} - void prefwin_init_theme_colors (void) { GdkColor clr; @@ -311,175 +131,6 @@ unescape_forward_slash (const char *src, char *dst, int size) { *dst = 0; } -// this should be in separate plugin -void -prefwin_add_hotkeys_tab (GtkWidget *prefwin) { - GtkWidget *vbox17; - GtkWidget *scrolledwindow6; - GtkWidget *hotkeystree; - GtkWidget *hbuttonbox3; - GtkWidget *addhotkey; - GtkWidget *removehotkey; - GtkWidget *label66; - - GtkWidget *notebook2 = lookup_widget (prefwin, "notebook"); - - vbox17 = gtk_vbox_new (FALSE, 8); - gtk_widget_show (vbox17); - gtk_container_add (GTK_CONTAINER (notebook2), vbox17); - gtk_container_set_border_width (GTK_CONTAINER (vbox17), 12); - - scrolledwindow6 = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scrolledwindow6); - gtk_box_pack_start (GTK_BOX (vbox17), scrolledwindow6, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow6), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow6), GTK_SHADOW_IN); - - hotkeystree = gtk_tree_view_new (); - gtk_widget_show (hotkeystree); - gtk_container_add (GTK_CONTAINER (scrolledwindow6), hotkeystree); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (hotkeystree), FALSE); - - hbuttonbox3 = gtk_hbutton_box_new (); - gtk_widget_show (hbuttonbox3); - gtk_box_pack_start (GTK_BOX (vbox17), hbuttonbox3, FALSE, FALSE, 0); - gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox3), GTK_BUTTONBOX_END); - - addhotkey = gtk_button_new_with_mnemonic (_("Add")); - gtk_widget_show (addhotkey); - gtk_container_add (GTK_CONTAINER (hbuttonbox3), addhotkey); - gtk_widget_set_can_default (addhotkey, TRUE); - - removehotkey = gtk_button_new_with_mnemonic (_("Remove")); - gtk_widget_show (removehotkey); - gtk_container_add (GTK_CONTAINER (hbuttonbox3), removehotkey); - gtk_widget_set_can_default (removehotkey, TRUE); - - label66 = gtk_label_new (_("Global Hotkeys")); - gtk_widget_show (label66); - int npages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook2)); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), npages-1), label66); - - GLADE_HOOKUP_OBJECT (prefwin, hotkeystree, "hotkeystree"); - GLADE_HOOKUP_OBJECT (prefwin, addhotkey, "addhotkey"); - GLADE_HOOKUP_OBJECT (prefwin, removehotkey, "removehotkey"); - - GtkListStore *hkstore = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - GtkCellRenderer *rend_hk_slot = gtk_cell_renderer_combo_new (); - - g_signal_connect ((gpointer)addhotkey, "clicked", G_CALLBACK (on_addhotkey_clicked), hkstore); - g_signal_connect ((gpointer)removehotkey, "clicked", G_CALLBACK (on_removehotkey_clicked), GTK_TREE_VIEW (hotkeystree)); - - GtkListStore *slots_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - // traverse all plugins and collect all exported actions to dropdown - // column0: title - // column1: name (invisible) - DB_plugin_t **plugins = deadbeef->plug_get_list (); - for (int i = 0; plugins[i]; i++) { - DB_plugin_t *p = plugins[i]; - if (p->get_actions) { - DB_plugin_action_t *actions = p->get_actions (NULL); - while (actions) { - if (actions->name && actions->title) { // only add actions with both the name and the title - GtkTreeIter iter; - gtk_list_store_append (slots_store, &iter); - char title[100]; - unescape_forward_slash (actions->title, title, sizeof (title)); - gtk_list_store_set (slots_store, &iter, 0, title, 1, actions->name, -1); - } - else { -// fprintf (stderr, "WARNING: action %s/%s from plugin %s is missing name and/or title\n", actions->name, actions->title, p->name); - } - actions = actions->next; - } - } - } - - g_object_set (G_OBJECT (rend_hk_slot), "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL); - g_object_set (G_OBJECT (rend_hk_slot), "has-entry", FALSE, NULL); - g_object_set (G_OBJECT (rend_hk_slot), "text-column", 0, NULL); - g_object_set (G_OBJECT (rend_hk_slot), "model", slots_store, NULL); - g_object_set (G_OBJECT (rend_hk_slot), "editable", TRUE, NULL); - - g_signal_connect ((gpointer)rend_hk_slot, "changed", - G_CALLBACK (on_hk_slot_changed), - hkstore); - - GtkCellRenderer *rend_hk_binding = gtk_cell_renderer_accel_new (); - g_object_set (G_OBJECT (rend_hk_binding), "editable", TRUE, NULL); - - g_signal_connect ((gpointer)rend_hk_binding, "accel-edited", - G_CALLBACK (on_hk_binding_edited), - hkstore); - - - GtkTreeViewColumn *hk_col1 = gtk_tree_view_column_new_with_attributes (_("Action"), rend_hk_slot, "text", 0, NULL); - GtkTreeViewColumn *hk_col2 = gtk_tree_view_column_new_with_attributes (_("Key combination"), rend_hk_binding, "text", 1, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeystree), hk_col1); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeystree), hk_col2); - - // fetch hotkeys from config, and add them to list - // model: - // column0: title of action - // column1: key combination - // column2 (hidden): name of action - DB_conf_item_t *item = deadbeef->conf_find ("hotkeys.", NULL); - while (item) { - size_t l = strlen (item->value); - char param[l+1]; - memcpy (param, item->value, l+1); - - char* colon = strchr (param, ':'); - if (!colon) - { - fprintf (stderr, "hotkeys: bad config option %s %s\n", item->key, item->value); - continue; - } - char* command = colon+1; - *colon = 0; - while (*command && ((uint8_t)*command) <= 0x20) { - command++; - } - if (*command) { - // find action with this name, and add to list - DB_plugin_action_t *actions = NULL; - DB_plugin_t **plugins = deadbeef->plug_get_list (); - for (int i = 0; plugins[i]; i++) { - DB_plugin_t *p = plugins[i]; - if (p->get_actions) { - actions = p->get_actions (NULL); - while (actions) { - if (actions->name && actions->title && !strcasecmp (actions->name, command)) { // only add actions with both the name and the title - GtkTreeIter iter; - gtk_list_store_append (hkstore, &iter); - char title[100]; - unescape_forward_slash (actions->title, title, sizeof (title)); - gtk_list_store_set (hkstore, &iter, 0, title, 1, param, 2, actions->name, -1); - break; // found - } - actions = actions->next; - } - if (actions) { - break; - } - } - } - - if (!actions) { - // not found, add anyway to avoid removal from config file - // (might be missing plugin) - GtkTreeIter iter; - gtk_list_store_append (hkstore, &iter); - gtk_list_store_set (hkstore, &iter, 0, command, 1, param, 2, command, -1); - } - - item = deadbeef->conf_find ("hotkeys.", item); - } - } - gtk_tree_view_set_model (GTK_TREE_VIEW (hotkeystree), GTK_TREE_MODEL (hkstore)); - -} - void on_preferences_activate (GtkMenuItem *menuitem, gpointer user_data) -- cgit v1.2.3