diff options
author | waker <wakeroid@gmail.com> | 2012-11-04 16:07:02 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-11-04 16:07:02 +0100 |
commit | 43b652d530275a24e13283d955428337f4aa8400 (patch) | |
tree | 1890437491a89330d13ca5e7c2e6e656d5d6d415 | |
parent | b0c2f00aba0a451e81a8369a594aac6a73daa8a0 (diff) |
gtkui: hotkeys configuration: add/remove; save/load; apply/revert buttons, etc
-rw-r--r-- | plugins/gtkui/callbacks.h | 8 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 49 | ||||
-rw-r--r-- | plugins/gtkui/hotkeys.c | 142 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 33 |
4 files changed, 185 insertions, 47 deletions
diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index abf7a7c4..97e40c8a 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -1239,3 +1239,11 @@ gboolean on_hotkey_keycombo_focus_in_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_data); + +void +on_hotkeys_apply_clicked (GtkButton *button, + gpointer user_data); + +void +on_hotkeys_revert_clicked (GtkButton *button, + gpointer user_data); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index af213d1a..115dd97b 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -5083,15 +5083,15 @@ SOCKS5_HOSTNAME</property> <widget class="GtkHButtonBox" id="hbuttonbox3"> <property name="visible">True</property> <property name="layout_style">GTK_BUTTONBOX_END</property> - <property name="spacing">0</property> + <property name="spacing">8</property> <child> <widget class="GtkButton" id="hotkey_add"> <property name="visible">True</property> <property name="can_default">True</property> <property name="can_focus">True</property> - <property name="label" translatable="yes">Add</property> - <property name="use_underline">True</property> + <property name="label">gtk-add</property> + <property name="use_stock">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_hotkey_add_clicked" last_modification_time="Tue, 30 Oct 2012 20:39:18 GMT"/> @@ -5103,8 +5103,8 @@ SOCKS5_HOSTNAME</property> <property name="visible">True</property> <property name="can_default">True</property> <property name="can_focus">True</property> - <property name="label" translatable="yes">Remove</property> - <property name="use_underline">True</property> + <property name="label">gtk-remove</property> + <property name="use_stock">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_hotkey_remove_clicked" last_modification_time="Tue, 30 Oct 2012 20:39:23 GMT"/> @@ -5304,6 +5304,45 @@ SOCKS5_HOSTNAME</property> <property name="fill">True</property> </packing> </child> + + <child> + <widget class="GtkHButtonBox" id="hbuttonbox4"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + <property name="spacing">8</property> + + <child> + <widget class="GtkButton" id="hotkeys_apply"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-apply</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_hotkeys_apply_clicked" last_modification_time="Sun, 04 Nov 2012 14:52:51 GMT"/> + </widget> + </child> + + <child> + <widget class="GtkButton" id="hotkeys_revert"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-revert-to-saved</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_hotkeys_revert_clicked" last_modification_time="Sun, 04 Nov 2012 14:53:09 GMT"/> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> </widget> <packing> <property name="tab_expand">False</property> diff --git a/plugins/gtkui/hotkeys.c b/plugins/gtkui/hotkeys.c index ec852710..0a24e04a 100644 --- a/plugins/gtkui/hotkeys.c +++ b/plugins/gtkui/hotkeys.c @@ -101,42 +101,11 @@ find_action_by_name (const char *command) { return actions; } -void -prefwin_init_hotkeys (GtkWidget *_prefwin) { - ctx_names[DDB_ACTION_CTX_MAIN] = _("Main"); - ctx_names[DDB_ACTION_CTX_SELECTION] = _("Selection"); - ctx_names[DDB_ACTION_CTX_PLAYLIST] = _("Playlist"); - ctx_names[DDB_ACTION_CTX_NOWPLAYING] = _("Now playing"); - - prefwin = _prefwin; +static void +hotkeys_load (void) { GtkWidget *hotkeys = lookup_widget (prefwin, "hotkeys_list"); - GtkWidget *actions = lookup_widget (prefwin, "hotkeys_actions"); - - // setup hotkeys list - GtkTreeViewColumn *hk_col1 = gtk_tree_view_column_new_with_attributes (_("Key combination"), gtk_cell_renderer_text_new (), "text", 0, NULL); - gtk_tree_view_column_set_resizable (hk_col1, TRUE); - GtkTreeViewColumn *hk_col2 = gtk_tree_view_column_new_with_attributes (_("Action"), gtk_cell_renderer_text_new (), "text", 1, NULL); - gtk_tree_view_column_set_resizable (hk_col2, TRUE); - GtkTreeViewColumn *hk_col3 = gtk_tree_view_column_new_with_attributes (_("Context"), gtk_cell_renderer_text_new (), "text", 2, NULL); - gtk_tree_view_column_set_resizable (hk_col3, TRUE); - GtkTreeViewColumn *hk_col4 = gtk_tree_view_column_new_with_attributes (_("Is global"), gtk_cell_renderer_text_new (), "text", 3, NULL); - gtk_tree_view_column_set_resizable (hk_col4, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col1); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col2); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col3); - gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col4); - // column0: keycombo string - // column1: action title - // column2: context title - // column3: is_global - // column4: action title id (hidden) - // column5: context id (hidden) - GtkListStore *hkstore = gtk_list_store_new (6, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_INT); - - gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkeys_actions"), FALSE); - gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkey_is_global"), FALSE); - gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkey_keycombo"), FALSE); - + GtkListStore *hkstore = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (hotkeys))); + gtk_list_store_clear (hkstore); int has_items = 0; DB_conf_item_t *item = deadbeef->conf_find ("hotkey.", NULL); while (item) { @@ -177,9 +146,76 @@ prefwin_init_hotkeys (GtkWidget *_prefwin) { out: item = deadbeef->conf_find ("hotkey.", item); } +} + +static void +hotkeys_save (void) { + GtkWidget *hotkeys = lookup_widget (prefwin, "hotkeys_list"); + GtkListStore *hkstore = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (hotkeys))); +// deadbeef->conf_remove_items ("hotkey.key"); + + GtkTreePath *path = gtk_tree_path_new_first (); + GtkTreeIter iter; + gboolean res = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (hkstore), &iter); + int i = 1; + while (res) { + GValue keycombo = {0,}, action = {0,}, context = {0,}, global = {0,}; + gtk_tree_model_get_value (GTK_TREE_MODEL (hkstore), &iter, 0, &keycombo); + gtk_tree_model_get_value (GTK_TREE_MODEL (hkstore), &iter, 4, &action); + gtk_tree_model_get_value (GTK_TREE_MODEL (hkstore), &iter, 5, &context); + gtk_tree_model_get_value (GTK_TREE_MODEL (hkstore), &iter, 3, &global); + char key[100]; + snprintf (key, sizeof (key), "hotkey.key%d", i); + char value[1000]; + snprintf (value, sizeof (value), "\"%s\" %d %d %s", g_value_get_string (&keycombo), g_value_get_int (&context), g_value_get_boolean (&global), g_value_get_string (&action)); + deadbeef->conf_set_str (key, value); + + res = gtk_tree_model_iter_next (GTK_TREE_MODEL (hkstore), &iter); + i++; + } +} + +void + +prefwin_init_hotkeys (GtkWidget *_prefwin) { + ctx_names[DDB_ACTION_CTX_MAIN] = _("Main"); + ctx_names[DDB_ACTION_CTX_SELECTION] = _("Selection"); + ctx_names[DDB_ACTION_CTX_PLAYLIST] = _("Playlist"); + ctx_names[DDB_ACTION_CTX_NOWPLAYING] = _("Now playing"); + + prefwin = _prefwin; + GtkWidget *hotkeys = lookup_widget (prefwin, "hotkeys_list"); + GtkWidget *actions = lookup_widget (prefwin, "hotkeys_actions"); + + // setup hotkeys list + GtkTreeViewColumn *hk_col1 = gtk_tree_view_column_new_with_attributes (_("Key combination"), gtk_cell_renderer_text_new (), "text", 0, NULL); + gtk_tree_view_column_set_resizable (hk_col1, TRUE); + GtkTreeViewColumn *hk_col2 = gtk_tree_view_column_new_with_attributes (_("Action"), gtk_cell_renderer_text_new (), "text", 1, NULL); + gtk_tree_view_column_set_resizable (hk_col2, TRUE); + GtkTreeViewColumn *hk_col3 = gtk_tree_view_column_new_with_attributes (_("Context"), gtk_cell_renderer_text_new (), "text", 2, NULL); + gtk_tree_view_column_set_resizable (hk_col3, TRUE); + GtkTreeViewColumn *hk_col4 = gtk_tree_view_column_new_with_attributes (_("Is global"), gtk_cell_renderer_text_new (), "text", 3, NULL); + gtk_tree_view_column_set_resizable (hk_col4, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col1); + gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col2); + gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col3); + gtk_tree_view_append_column (GTK_TREE_VIEW (hotkeys), hk_col4); + // column0: keycombo string + // column1: action title + // column2: context title + // column3: is_global + // column4: action title id (hidden) + // column5: context id (hidden) + GtkListStore *hkstore = gtk_list_store_new (6, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_INT); + + gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkeys_actions"), FALSE); + gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkey_is_global"), FALSE); + gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkey_keycombo"), FALSE); gtk_tree_view_set_model (GTK_TREE_VIEW (hotkeys), GTK_TREE_MODEL (hkstore)); + hotkeys_load (); + // setup action tree GtkTreeViewColumn *hk_act_col1 = gtk_tree_view_column_new_with_attributes (_("Action"), gtk_cell_renderer_text_new (), "text", 0, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (actions), hk_act_col1); @@ -253,8 +289,7 @@ set_current_action (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g gtk_tree_model_get_value (model, iter, 2, &ctx_val); actionbinding_t *binding = data; const char *name = g_value_get_string (&val); - if (name && !strcmp (binding->name, name) && binding->ctx == g_value_get_int (&ctx_val)) { - printf ("set cursor to %s\n", name); + if (name && binding->name && !strcmp (binding->name, name) && binding->ctx == g_value_get_int (&ctx_val)) { gtk_tree_view_expand_to_path (GTK_TREE_VIEW (lookup_widget (prefwin, "hotkeys_actions")), path); gtk_tree_view_set_cursor (GTK_TREE_VIEW (lookup_widget (prefwin, "hotkeys_actions")), path, NULL, FALSE); return TRUE; @@ -293,7 +328,8 @@ on_hotkeys_list_cursor_changed (GtkTreeView *treeview, gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkey_keycombo"), TRUE); GValue val_keycombo = {0,}; gtk_tree_model_get_value (model, &iter, 0, &val_keycombo); - gtk_entry_set_text (GTK_ENTRY (lookup_widget (prefwin, "hotkey_keycombo")), g_value_get_string (&val_keycombo)); + const char *keycombo = g_value_get_string (&val_keycombo); + gtk_entry_set_text (GTK_ENTRY (lookup_widget (prefwin, "hotkey_keycombo")), keycombo ? keycombo : ""); } else { gtk_widget_set_sensitive (lookup_widget (prefwin, "hotkeys_actions"), FALSE); @@ -313,7 +349,11 @@ void on_hotkey_add_clicked (GtkButton *button, gpointer user_data) { - + GtkWidget *hotkeys = lookup_widget (prefwin, "hotkeys_list"); + GtkListStore *hkstore = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (hotkeys))); + GtkTreeIter iter; + gtk_list_store_append (hkstore, &iter); + gtk_list_store_set (hkstore, &iter, 0, _("<Not set>"), 1, _("<Not set>"), 2, _("<Not set>"), 3, 0, 4, NULL, 5, -1, -1); } @@ -321,7 +361,13 @@ void on_hotkey_remove_clicked (GtkButton *button, gpointer user_data) { - + GtkWidget *hotkeys = lookup_widget (prefwin, "hotkeys_list"); + GtkTreePath *path; + gtk_tree_view_get_cursor (GTK_TREE_VIEW (hotkeys), &path, NULL); + GtkListStore *hkstore = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (hotkeys))); + GtkTreeIter iter; + gtk_tree_model_get_iter (GTK_TREE_MODEL (hkstore), &iter, path); + gtk_list_store_remove (hkstore, &iter); } @@ -615,3 +661,19 @@ on_hotkey_keycombo_button_release_event return TRUE; } + +void +on_hotkeys_apply_clicked (GtkButton *button, + gpointer user_data) +{ + hotkeys_save (); +} + + +void +on_hotkeys_revert_clicked (GtkButton *button, + gpointer user_data) +{ + hotkeys_load (); +} + diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index 8802e866..2214e2d5 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1799,6 +1799,9 @@ create_prefwin (void) GtkWidget *hbox107; GtkWidget *hotkey_keycombo; GtkWidget *hotkey_is_global; + GtkWidget *hbuttonbox4; + GtkWidget *hotkeys_apply; + GtkWidget *hotkeys_revert; GtkWidget *label132; GtkWidget *hpaned1; GtkWidget *scrolledwindow2; @@ -2529,13 +2532,14 @@ create_prefwin (void) gtk_widget_show (hbuttonbox3); gtk_box_pack_start (GTK_BOX (vbox36), hbuttonbox3, FALSE, TRUE, 0); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox3), GTK_BUTTONBOX_END); + gtk_box_set_spacing (GTK_BOX (hbuttonbox3), 8); - hotkey_add = gtk_button_new_with_mnemonic (_("Add")); + hotkey_add = gtk_button_new_from_stock ("gtk-add"); gtk_widget_show (hotkey_add); gtk_container_add (GTK_CONTAINER (hbuttonbox3), hotkey_add); gtk_widget_set_can_default(hotkey_add, TRUE); - hotkey_remove = gtk_button_new_with_mnemonic (_("Remove")); + hotkey_remove = gtk_button_new_from_stock ("gtk-remove"); gtk_widget_show (hotkey_remove); gtk_container_add (GTK_CONTAINER (hbuttonbox3), hotkey_remove); gtk_widget_set_can_default(hotkey_remove, TRUE); @@ -2590,6 +2594,22 @@ create_prefwin (void) gtk_widget_show (hotkey_is_global); gtk_box_pack_start (GTK_BOX (hbox107), hotkey_is_global, FALSE, FALSE, 0); + hbuttonbox4 = gtk_hbutton_box_new (); + gtk_widget_show (hbuttonbox4); + gtk_box_pack_start (GTK_BOX (vbox36), hbuttonbox4, TRUE, TRUE, 0); + gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox4), GTK_BUTTONBOX_END); + gtk_box_set_spacing (GTK_BOX (hbuttonbox4), 8); + + hotkeys_apply = gtk_button_new_from_stock ("gtk-apply"); + gtk_widget_show (hotkeys_apply); + gtk_container_add (GTK_CONTAINER (hbuttonbox4), hotkeys_apply); + gtk_widget_set_can_default(hotkeys_apply, TRUE); + + hotkeys_revert = gtk_button_new_from_stock ("gtk-revert-to-saved"); + gtk_widget_show (hotkeys_revert); + gtk_container_add (GTK_CONTAINER (hbuttonbox4), hotkeys_revert); + gtk_widget_set_can_default(hotkeys_revert, TRUE); + label132 = gtk_label_new (_("Hotkeys")); gtk_widget_show (label132); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 6), label132); @@ -2907,6 +2927,12 @@ create_prefwin (void) g_signal_connect ((gpointer) hotkey_is_global, "toggled", G_CALLBACK (on_hotkey_is_global_toggled), NULL); + g_signal_connect ((gpointer) hotkeys_apply, "clicked", + G_CALLBACK (on_hotkeys_apply_clicked), + NULL); + g_signal_connect ((gpointer) hotkeys_revert, "clicked", + G_CALLBACK (on_hotkeys_revert_clicked), + NULL); g_signal_connect ((gpointer) pref_pluginlist, "cursor_changed", G_CALLBACK (on_pref_pluginlist_cursor_changed), NULL); @@ -3074,6 +3100,9 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, hbox107, "hbox107"); GLADE_HOOKUP_OBJECT (prefwin, hotkey_keycombo, "hotkey_keycombo"); GLADE_HOOKUP_OBJECT (prefwin, hotkey_is_global, "hotkey_is_global"); + GLADE_HOOKUP_OBJECT (prefwin, hbuttonbox4, "hbuttonbox4"); + GLADE_HOOKUP_OBJECT (prefwin, hotkeys_apply, "hotkeys_apply"); + GLADE_HOOKUP_OBJECT (prefwin, hotkeys_revert, "hotkeys_revert"); GLADE_HOOKUP_OBJECT (prefwin, label132, "label132"); GLADE_HOOKUP_OBJECT (prefwin, hpaned1, "hpaned1"); GLADE_HOOKUP_OBJECT (prefwin, scrolledwindow2, "scrolledwindow2"); |