aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-call-window.c
blob: baa169755b94e579a773a25dfec022df21a6fe2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2007 Elliot Fairweather
 * Copyright (C) 2007 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
 *          Xavier Claessens <xclaesse@gmail.com>
 */

#include "config.h"

#include <gtk/gtk.h>

#include <libempathy/empathy-debug.h>

#include "empathy-call-window.h"
#include "empathy-ui-utils.h"

#define DEBUG_DOMAIN "CallWindow"

typedef struct {
    GtkWidget     *window;
    GtkWidget     *input_volume_scale;
    GtkWidget     *output_volume_scale;
    GtkWidget     *input_mute_togglebutton;
    GtkWidget     *output_mute_togglebutton;
    GtkWidget     *preview_video_frame;
    GtkWidget     *output_video_frame;
    GtkWidget     *preview_video_socket;
    GtkWidget     *output_video_socket;
    GtkWidget     *send_video_checkbutton;

    EmpathyTpCall *call;
} EmpathyCallWindow;

static void
call_window_output_volume_changed_cb (GtkWidget         *scale,
                      EmpathyCallWindow *window)
{
    guint volume;

    volume = (guint) gtk_range_get_value (GTK_RANGE (scale));
    empathy_tp_call_set_output_volume (window->call, volume);
}


static void
call_window_output_mute_toggled_cb (GtkWidget         *button,
                    EmpathyCallWindow *window)
{
    gboolean is_muted;

    is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
    empathy_tp_call_mute_output (window->call, is_muted);
}


static void
call_window_input_mute_toggled_cb (GtkWidget         *button,
                   EmpathyCallWindow *window)
{
    gboolean is_muted;

    is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
    empathy_tp_call_mute_input (window->call, is_muted);
}


static void
call_window_send_video_toggled_cb (GtkWidget         *button,
                   EmpathyCallWindow *window)
{
    gboolean is_sending;

    is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
    empathy_tp_call_send_video (window->call, is_sending);
}

static void
call_window_capabilities_notify_cb (EmpathyContact    *contact,
                    GParamSpec        *param,
                    EmpathyCallWindow *window)
{
    EmpathyCapabilities capabilities;

    capabilities = empathy_contact_get_capabilities (contact);
    empathy_tp_call_request_streams (window->call,
                     capabilities & EMPATHY_CAPABILITIES_AUDIO,
                     capabilities & EMPATHY_CAPABILITIES_VIDEO);
}

static void
call_window_status_notify_cb (EmpathyTpCall     *call,
                  GParamSpec        *param,
                  EmpathyCallWindow *window)
{
    guint status;

    status = empathy_tp_call_get_status (call);
    empathy_debug (DEBUG_DOMAIN, "Status changed to %d",
               status);

    if (status == EMPATHY_TP_CALL_STATUS_RINGING) {
        if (empathy_tp_call_is_incoming (window->call)) {
            empathy_tp_call_accept (window->call);
        } else {
            EmpathyContact *contact;

            contact = empathy_tp_call_get_contact (call);
            g_signal_connect (contact, "notify::capabilities",
                      G_CALLBACK (call_window_capabilities_notify_cb),
                      window);
            call_window_capabilities_notify_cb (contact, NULL, window);
        }
    }

    if (status == EMPATHY_TP_CALL_STATUS_RUNNING) {
        empathy_tp_call_set_output_window (window->call,
            gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
    }
}

static void
call_window_destroy_cb (GtkWidget         *widget,
            EmpathyCallWindow *window)
{
    g_object_unref (window->call);
    g_slice_free (EmpathyCallWindow, window);
}

void
empathy_call_window_show (EmpathyTpCall *call)
{
    EmpathyCallWindow *window;
    GladeXML          *glade;

    window = g_slice_new0 (EmpathyCallWindow);

    glade = empathy_glade_get_file ("empathy-call-window.glade",
                    "window",
                    NULL,
                    "window", &window->window,
                    "input_volume_scale", &window->input_volume_scale,
                    "output_volume_scale", &window->output_volume_scale,
                    "input_mute_togglebutton", &window->input_mute_togglebutton,
                    "output_mute_togglebutton", &window->output_mute_togglebutton,
                    "preview_video_frame", &window->preview_video_frame,
                    "output_video_frame", &window->output_video_frame,
                    "send_video_checkbutton", &window->send_video_checkbutton,
                    NULL);

    empathy_glade_connect (glade,
                   window,
                   "window", "destroy", call_window_destroy_cb,
                   "input_mute_togglebutton", "toggled", call_window_input_mute_toggled_cb,
                   "output_mute_togglebutton", "toggled", call_window_output_mute_toggled_cb,
                   "output_volume_scale", "value-changed", call_window_output_volume_changed_cb,
                   "send_video_checkbutton", "toggled", call_window_send_video_toggled_cb,
                   NULL);
    g_object_unref (glade);

    /* Set output window socket */
    window->output_video_socket = gtk_socket_new ();
    gtk_widget_show (window->output_video_socket);
    gtk_container_add (GTK_CONTAINER (window->output_video_frame),
               window->output_video_socket);

    /* Set preview window socket */
    window->preview_video_socket = gtk_socket_new ();
    gtk_widget_show (window->preview_video_socket);
    gtk_container_add (GTK_CONTAINER (window->preview_video_frame),
               window->preview_video_socket);

    /* Setup TpCall */
    window->call = g_object_ref (call);
    empathy_tp_call_add_preview_window (window->call,
        gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
    g_signal_connect (window->call, "notify::status",
              G_CALLBACK (call_window_status_notify_cb),
              window);

    gtk_widget_show (window->window);
}