~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to gnome/src/shortcuts.c

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
3
 *  Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
14
14
 *
15
15
 *  You should have received a copy of the GNU General Public License
16
16
 *  along with this program; if not, write to the Free Software
17
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
18
18
 *
19
19
 *  Additional permission under GNU GPL version 3 section 7:
20
20
 *
40
40
 
41
41
#include "shortcuts.h"
42
42
#include "mainwindow.h"
43
 
#include "logger.h"
44
43
#include "callable_obj.h"
45
44
#include "contacts/calltab.h"
46
45
#include "sflphone_const.h"
47
46
#include "dbus.h"
48
47
#include "actions.h"
49
 
#include "unused.h"
50
48
 
51
49
static void
52
50
ungrab_key(guint key, GdkModifierType mask, GdkWindow *root);
69
67
 * filter used when an event is catched
70
68
 */
71
69
static GdkFilterReturn
72
 
filter_keys(const GdkXEvent *xevent, const GdkEvent *event UNUSED, gpointer data UNUSED)
 
70
filter_keys(const GdkXEvent *xevent, G_GNUC_UNUSED const GdkEvent *event, G_GNUC_UNUSED gpointer data)
73
71
{
74
72
    if (((XEvent *) xevent)->type != KeyPress)
75
73
        return GDK_FILTER_CONTINUE;
79
77
 
80
78
    for (int i = 0; accelerators_list[i].action; ++i)
81
79
        if (accelerators_list[i].key == key->keycode && accelerators_list[i].mask == keystate) {
82
 
            accelerators_list[i].callback();
 
80
            accelerators_list[i].callback(accelerators_list[i].data);
83
81
            return GDK_FILTER_REMOVE;
84
82
        }
85
83
 
90
88
 * Callbacks
91
89
 */
92
90
static void
93
 
toggle_pick_up_hang_up_callback()
 
91
toggle_pick_up_hang_up_callback(SFLPhoneClient *client)
94
92
{
95
93
    callable_obj_t * selectedCall = calltab_get_selected_call(active_calltree_tab);
96
94
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
97
95
 
98
 
    DEBUG("Shortcuts: Toggle pickup/hangup callback");
 
96
    g_debug("Shortcuts: Toggle pickup/hangup callback");
99
97
 
100
98
    if (selectedCall) {
101
99
        switch (selectedCall->_state) {
102
100
            case CALL_STATE_INCOMING:
103
101
            case CALL_STATE_TRANSFER:
104
 
                sflphone_pick_up();
 
102
                sflphone_pick_up(client);
105
103
                break;
106
104
            case CALL_STATE_DIALING:
107
105
            case CALL_STATE_HOLD:
108
106
            case CALL_STATE_CURRENT:
109
107
            case CALL_STATE_RINGING:
110
 
                sflphone_hang_up();
 
108
                sflphone_hang_up(client);
111
109
                break;
112
110
            default:
113
111
                break;
115
113
    } else if (selectedConf) {
116
114
        dbus_hang_up_conference(selectedConf);
117
115
    } else
118
 
        sflphone_pick_up();
119
 
}
120
 
 
121
 
static void
122
 
pick_up_callback()
123
 
{
124
 
    sflphone_pick_up();
125
 
}
126
 
 
127
 
static void
128
 
hang_up_callback()
129
 
{
130
 
    sflphone_hang_up();
131
 
}
132
 
 
133
 
static void
134
 
toggle_hold_callback()
 
116
        sflphone_pick_up(client);
 
117
}
 
118
 
 
119
static void
 
120
pick_up_callback(gpointer data)
 
121
{
 
122
    sflphone_pick_up(data);
 
123
}
 
124
 
 
125
static void
 
126
hang_up_callback(gpointer data)
 
127
{
 
128
    sflphone_hang_up(data);
 
129
}
 
130
 
 
131
static void
 
132
toggle_hold_callback(G_GNUC_UNUSED gpointer data)
135
133
{
136
134
    callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab);
137
135
    conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree_tab);
150
148
    } else if (selectedConf)
151
149
        dbus_hold_conference(selectedConf);
152
150
    else {
153
 
        ERROR("Shortcuts: Error: No callable object selected");
 
151
        g_warning("Shortcuts: Error: No callable object selected");
154
152
    }
155
153
}
156
154
 
157
155
static void
158
 
popup_window_callback()
 
156
popup_window_callback(SFLPhoneClient *client)
159
157
{
160
 
    gtk_widget_hide(GTK_WIDGET(get_main_window()));
161
 
    gtk_widget_show(GTK_WIDGET(get_main_window()));
 
158
    gtk_widget_hide(client->win);
 
159
    gtk_widget_show(client->win);
162
160
}
163
161
 
164
162
static void
165
 
default_callback()
 
163
default_callback(G_GNUC_UNUSED gpointer data)
166
164
{
167
 
    ERROR("Shortcuts: Error: Missing shortcut callback");
 
165
    g_warning("Shortcuts: Error: Missing shortcut callback");
168
166
}
169
167
 
170
168
/*
201
199
static void
202
200
remove_bindings()
203
201
{
 
202
    if (!accelerators_list)
 
203
        return;
 
204
 
204
205
    GdkDisplay *display = NULL;
205
206
    GdkScreen *screen = NULL;
206
207
    GdkWindow *root = NULL;
284
285
    }
285
286
 
286
287
    if (accelerators_list[i].action == NULL) {
287
 
        ERROR("Shortcut: Error: Cannot find corresponding action");
 
288
        g_warning("Shortcut: Error: Cannot find corresponding action");
288
289
        return;
289
290
    }
290
291
 
300
301
 * Prepare accelerators list
301
302
 */
302
303
static void
303
 
initialize_accelerators_list()
 
304
initialize_accelerators_list(SFLPhoneClient *client)
304
305
{
305
306
    GList* shortcutsKeysElement, *shortcutsKeys;
306
307
    int i = 0;
316
317
 
317
318
        accelerators_list[i].action = g_strdup(action);
318
319
        accelerators_list[i].callback = get_action_callback(action);
 
320
        accelerators_list[i].data = client;
319
321
        accelerators_list[i].mask = 0;
320
322
        accelerators_list[i].key = 0;
321
323
 
349
351
    while (accelerators_list[i].action != NULL) {
350
352
        if (accelerators_list[i].key == key && accelerators_list[i].mask == mask
351
353
                && accelerators_list[i].key != 0) {
352
 
            DEBUG("Shortcuts: Existing mapping found %d+%d", mask, key);
 
354
            g_debug("Shortcuts: Existing mapping found %d+%d", mask, key);
353
355
 
354
356
            // disable old binding
355
357
            accelerators_list[i].key = 0;
399
401
 * Initialize bindings with configuration retrieved from dbus
400
402
 */
401
403
void
402
 
shortcuts_initialize_bindings()
 
404
shortcuts_initialize_bindings(SFLPhoneClient *client)
403
405
{
404
406
    GList* shortcutsKeys, *shortcutsKeysElement = NULL;
405
407
    gchar* action, *maskAndKey, *token1, *token2 = NULL;
406
408
    guint mask, key = 0;
407
409
 
408
 
    DEBUG("Shortcuts: Initialize bindings");
 
410
    g_debug("Shortcuts: Initialize bindings");
409
411
 
410
412
    // get shortcuts stored in config through dbus
411
413
    shortcutsMap = dbus_get_shortcuts();
412
414
 
413
415
    // initialize list of keys
414
 
    initialize_accelerators_list();
 
416
    initialize_accelerators_list(client);
415
417
 
416
418
    // iterate through keys to initialize bindings
417
419
    shortcutsKeys = g_hash_table_get_keys(shortcutsMap);
429
431
 
430
432
        // Value not setted
431
433
        if (token1 && token2) {
432
 
            DEBUG("Shortcuts: token1 %s, token2 %s", token1, token2);
 
434
            g_debug("Shortcuts: token1 %s, token2 %s", token1, token2);
433
435
 
434
436
            mask = atoi(token1);
435
437
            key = atoi(token2);
447
449
shortcuts_destroy_bindings()
448
450
{
449
451
    int i = 0;
 
452
    if (!accelerators_list)
 
453
        return;
450
454
 
451
455
    // remove bindings
452
456
    remove_bindings();
472
476
static void
473
477
ungrab_key(guint key, GdkModifierType mask, GdkWindow *root)
474
478
{
475
 
    DEBUG("Shortcuts: Ungrabbing key %d+%d", mask, key);
 
479
    g_debug("Shortcuts: Ungrabbing key %d+%d", mask, key);
476
480
 
477
481
    gdk_error_trap_push();
478
482
    Display *d = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
491
495
    gdk_flush();
492
496
 
493
497
    if (gdk_error_trap_pop())
494
 
        ERROR("Shortcuts: Error: Ungrabbing key %d+%d", mask, key);
 
498
        g_warning("Shortcuts: Error: Ungrabbing key %d+%d", mask, key);
495
499
}
496
500
 
497
501
/*
502
506
{
503
507
    gdk_error_trap_push();
504
508
 
505
 
    DEBUG("Shortcuts: Grabbing key %d+%d", mask, key);
 
509
    g_debug("Shortcuts: Grabbing key %d+%d", mask, key);
506
510
 
507
511
    Display *d = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
508
512
    XID x = GDK_WINDOW_XID(root);
519
523
    gdk_flush();
520
524
 
521
525
    if (gdk_error_trap_pop())
522
 
        ERROR("Shortcuts: Error: Grabbing key %d+%d", mask, key);
 
526
        g_warning("Shortcuts: Error: Grabbing key %d+%d", mask, key);
523
527
}