~ubuntu-branches/ubuntu/raring/sflphone/raring

« back to all changes in this revision

Viewing changes to .pc/06_use_XkbKeycodeToKeysym.patch/gnome/src/config/shortcuts-config.c

  • Committer: Package Import Robot
  • Author(s): Whoopie
  • Date: 2012-03-22 10:29:10 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120322102910-tb8hugi2su1tguwh
Tags: 1.0.2-1ubuntu1
* Apply some upstream patches to fix FTBFS (LP: #913018):
  - debian/patches/05_glib_includes.patch: fix glib includes.
  - debian/patches/06_use_XkbKeycodeToKeysym.patch: use 
    XkbKeycodeToKeysym instead of (deprecated) XKeycodeToKeysym.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
3
 *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
21
 *  If you modify this program, or any covered work, by linking or
 
22
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
23
 *  modified version of that library), containing parts covered by the
 
24
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
25
 *  grants you additional permission to convey the resulting work.
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#include <glib/gi18n.h>
 
32
#include <gdk/gdk.h>
 
33
#include "shortcuts-config.h"
 
34
#include "shortcuts.h"
 
35
#include "unused.h"
 
36
#include "logger.h"
 
37
 
 
38
 
 
39
static void
 
40
accel_cleared(GtkCellRendererAccel *renderer UNUSED, gchar *path,
 
41
              GtkTreeView *treeview)
 
42
{
 
43
    // Update treeview
 
44
    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
 
45
 
 
46
    GtkTreeIter iter;
 
47
 
 
48
    if (gtk_tree_model_get_iter_from_string(model, &iter, path))
 
49
        gtk_list_store_set(GTK_LIST_STORE(model), &iter, MASK, 0, VALUE, 0, -1);
 
50
 
 
51
    // Update GDK bindings
 
52
    shortcuts_update_bindings(atoi(path), 0, 0);
 
53
}
 
54
 
 
55
static void
 
56
accel_edited(GtkCellRendererAccel *renderer UNUSED, gchar *path, guint accel_key,
 
57
             GdkModifierType mask, guint hardware_keycode UNUSED, GtkTreeView *treeview)
 
58
{
 
59
    // Disable existing binding if key already used
 
60
    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
 
61
    GtkTreeIter iter;
 
62
    gtk_tree_model_get_iter_first(model, &iter);
 
63
 
 
64
    Accelerator* list = shortcuts_get_list();
 
65
    const guint code = XKeysymToKeycode(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), accel_key);
 
66
    for (guint i = 0; list[i].action != NULL; ++i) {
 
67
        if (list[i].key == code && list[i].mask == mask) {
 
68
            gtk_list_store_set(GTK_LIST_STORE(model), &iter, MASK, 0, VALUE, 0,
 
69
                               -1);
 
70
            WARN("This key was already affected");
 
71
        }
 
72
 
 
73
        gtk_tree_model_iter_next(model, &iter);
 
74
    }
 
75
 
 
76
    // Update treeview
 
77
    if (gtk_tree_model_get_iter_from_string(model, &iter, path))
 
78
        gtk_list_store_set(GTK_LIST_STORE(model), &iter, MASK, (gint) mask,
 
79
                           VALUE, accel_key, -1);
 
80
 
 
81
    // Update GDK bindings
 
82
    shortcuts_update_bindings(atoi(path), code, mask);
 
83
}
 
84
 
 
85
/*
 
86
 * Create a tree view with two columns. The first is an action and the
 
87
 * second is a keyboard accelerator.
 
88
 */
 
89
static void
 
90
setup_tree_view(GtkWidget *treeview)
 
91
{
 
92
    GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
 
93
    GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes("Action", renderer,
 
94
                                "text", ACTION, NULL);
 
95
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
 
96
 
 
97
    renderer = gtk_cell_renderer_accel_new();
 
98
    g_object_set(renderer, "accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_GTK,
 
99
                 "editable", TRUE, NULL);
 
100
    column = gtk_tree_view_column_new_with_attributes("Shortcut", renderer,
 
101
             "accel-mods", MASK, "accel-key", VALUE, NULL);
 
102
 
 
103
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
 
104
    g_signal_connect(renderer, "accel_edited", G_CALLBACK(accel_edited),
 
105
                     (gpointer) treeview);
 
106
    g_signal_connect(renderer, "accel_cleared", G_CALLBACK(accel_cleared),
 
107
                     (gpointer) treeview);
 
108
}
 
109
 
 
110
GtkWidget*
 
111
create_shortcuts_settings()
 
112
{
 
113
    GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
114
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
 
115
 
 
116
    GtkWidget * result_frame = gnome_main_section_new(_("General"));
 
117
 
 
118
    GtkWidget *label = gtk_label_new(_("Be careful: these shortcuts might "
 
119
                                       "override system-wide shortcuts."));
 
120
    GtkWidget *treeview = gtk_tree_view_new();
 
121
    setup_tree_view(treeview);
 
122
 
 
123
    GtkListStore *store = gtk_list_store_new(COLUMNS, G_TYPE_STRING, G_TYPE_INT,
 
124
                          G_TYPE_UINT);
 
125
 
 
126
    Accelerator* list = shortcuts_get_list();
 
127
 
 
128
    for (guint i = 0; list[i].action != NULL; ++i) {
 
129
        GtkTreeIter iter;
 
130
        gtk_list_store_append(store, &iter);
 
131
        gtk_list_store_set(store, &iter, ACTION, _(list[i].action), MASK,
 
132
                           (gint) list[i].mask, VALUE,
 
133
                           XKeycodeToKeysym(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), list[i].key, 0), -1);
 
134
    }
 
135
 
 
136
    gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
 
137
    g_object_unref(store);
 
138
 
 
139
    gtk_container_add(GTK_CONTAINER(result_frame), treeview);
 
140
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 
141
    gtk_box_pack_start(GTK_BOX(vbox), result_frame, FALSE, FALSE, 0);
 
142
 
 
143
    gtk_widget_show_all(vbox);
 
144
 
 
145
    return vbox;
 
146
}
 
147