aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:11:09 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:11:09 +0800
commitd253320e38f1d4f79f610d6473787726abf6be19 (patch)
tree21fc33a0f052b3d75a3283fa108e35faa778dd17 /src
parenta0a612ae36134189ebb1de3647eca79e45d749e7 (diff)
downloadgsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar.gz
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar.bz2
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar.lz
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar.xz
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.tar.zst
gsoc2013-empathy-d253320e38f1d4f79f610d6473787726abf6be19.zip
Update for new API and cleanup the code.
svn path=/trunk/; revision=908
Diffstat (limited to 'src')
-rw-r--r--src/empathy-call-window.c425
-rw-r--r--src/empathy-call-window.glade6
2 files changed, 186 insertions, 245 deletions
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index 8e31294c5..f8a199ca9 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -20,15 +20,13 @@
#include <string.h>
-#include <libtelepathy/tp-chan.h>
+#include <glade/glade.h>
+#include <glib/gi18n.h>
-#include <libmissioncontrol/mc-account.h>
-#include <libmissioncontrol/mc-account-monitor.h>
-#include <libmissioncontrol/mission-control.h>
+#include <telepathy-glib/enums.h>
#include <libempathy/empathy-contact.h>
#include <libempathy/empathy-tp-call.h>
-#include <libempathy/empathy-chandler.h>
#include <libempathy/empathy-debug.h>
#include <libempathy/empathy-utils.h>
#include <libempathy-gtk/empathy-ui-utils.h>
@@ -85,14 +83,10 @@ call_window_update_timer (gpointer data)
hours = time % 60;
if (hours > 0)
- {
str = g_strdup_printf ("Connected - %02ld : %02ld : %02ld", hours,
minutes, seconds);
- }
else
- {
str = g_strdup_printf ("Connected - %02ld : %02ld", minutes, seconds);
- }
gtk_label_set_text (GTK_LABEL (window->status_label), str);
@@ -104,18 +98,11 @@ call_window_update_timer (gpointer data)
static void
call_window_stop_timeout (EmpathyCallWindow *window)
{
- GMainContext *context;
- GSource *source;
-
- context = g_main_context_default ();
-
empathy_debug (DEBUG_DOMAIN, "Timer stopped");
if (window->timeout_event_id)
{
- source = g_main_context_find_source_by_id (context,
- window->timeout_event_id);
- g_source_destroy (source);
+ g_source_remove (window->timeout_event_id);
window->timeout_event_id = 0;
}
}
@@ -131,195 +118,43 @@ call_window_set_output_video_is_drawing (EmpathyCallWindow *window,
empathy_debug (DEBUG_DOMAIN,
"Setting output video is drawing - %d", is_drawing);
- if (is_drawing)
+ if (is_drawing && !window->is_drawing)
{
- if (!window->is_drawing)
- {
- if (child)
- {
- gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
- child);
- }
- gtk_container_add (GTK_CONTAINER (window->output_video_frame),
- window->output_video_socket);
- gtk_widget_show (window->output_video_socket);
- empathy_tp_call_add_output_video (window->call,
- gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
- window->is_drawing = is_drawing;
- }
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
+ child);
+ gtk_container_add (GTK_CONTAINER (window->output_video_frame),
+ window->output_video_socket);
+ gtk_widget_show (window->output_video_socket);
+ empathy_tp_call_add_output_video (window->call,
+ gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
}
- else
+ if (!is_drawing && window->is_drawing)
{
- if (window->is_drawing)
- {
- empathy_tp_call_add_output_video (window->call, 0);
- if (child)
- {
- gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
- child);
- }
- gtk_container_add (GTK_CONTAINER (window->output_video_frame),
- window->output_video_label);
- gtk_widget_show (window->output_video_label);
- window->is_drawing = is_drawing;
- }
+ empathy_tp_call_add_output_video (window->call, 0);
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
+ child);
+ gtk_container_add (GTK_CONTAINER (window->output_video_frame),
+ window->output_video_label);
+ gtk_widget_show (window->output_video_label);
}
-}
-static gboolean
-call_window_delete_event_cb (GtkWidget *widget,
- GdkEvent *event,
- EmpathyCallWindow *window)
-{
- GtkWidget *dialog;
- gint result;
- guint status;
-
- empathy_debug (DEBUG_DOMAIN, "Delete event occurred");
-
- g_object_get (G_OBJECT (window->call), "status", &status, NULL);
-
- if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
- {
- dialog = gtk_message_dialog_new (GTK_WINDOW (window->window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
- "This call will be ended. Continue?");
-
- result = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- switch (result)
- {
- case GTK_RESPONSE_YES:
- call_window_stop_timeout (window);
- call_window_set_output_video_is_drawing (window, FALSE);
- empathy_tp_call_close_channel (window->call);
- empathy_tp_call_remove_preview_video (window->call,
- gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
- return FALSE;
- default:
- return TRUE;
- }
- }
- else
- {
- empathy_tp_call_remove_preview_video (window->call,
- gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
- return FALSE;
- }
-}
-
-static void
-call_window_video_button_toggled_cb (GtkWidget *button,
- EmpathyCallWindow *window)
-{
- gboolean is_sending;
-
- is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- empathy_debug (DEBUG_DOMAIN, "Send video toggled - %d", is_sending);
-
- empathy_tp_call_request_video_stream_direction (window->call, is_sending);
+ window->is_drawing = is_drawing;
}
static void
-call_window_status_changed_cb (EmpathyTpCall *call,
- EmpathyCallWindow *window)
+call_window_finalize (EmpathyCallWindow *window)
{
- EmpathyContact *contact;
- guint status;
- guint stream_state;
- EmpathyTpCallStream *audio_stream;
- EmpathyTpCallStream *video_stream;
- gboolean is_incoming;
- gchar *title;
-
- g_object_get (window->call,
- "status", &status,
- "audio-stream", &audio_stream,
- "video-stream", &video_stream,
- NULL);
-
- if (video_stream->state > audio_stream->state)
- stream_state = video_stream->state;
- else
- stream_state = audio_stream->state;
-
- empathy_debug (DEBUG_DOMAIN, "Status changed - status: %d, stream state: %d",
- status, stream_state);
-
- if (window->timeout_event_id)
+ if (window->call)
+ {
call_window_stop_timeout (window);
-
- if (status == EMPATHY_TP_CALL_STATUS_CLOSED)
- {
- gtk_label_set_text (GTK_LABEL (window->status_label), "Closed");
- gtk_widget_set_sensitive (window->end_call_button, FALSE);
- gtk_widget_set_sensitive (window->start_call_button, FALSE);
-
call_window_set_output_video_is_drawing (window, FALSE);
+ empathy_tp_call_remove_preview_video (window->call,
+ gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
+ g_object_unref (window->call);
+ window->call = NULL;
}
- else if (stream_state == TP_MEDIA_STREAM_STATE_DISCONNECTED)
- gtk_label_set_text (GTK_LABEL (window->status_label), "Disconnected");
- else if (status == EMPATHY_TP_CALL_STATUS_PENDING)
- {
- g_object_get (G_OBJECT (window->call), "contact", &contact, NULL);
-
- title = g_strdup_printf ("%s - Empathy Call",
- empathy_contact_get_name (contact));
- gtk_window_set_title (GTK_WINDOW (window->window), title);
-
- gtk_label_set_text (GTK_LABEL (window->status_label), "Ringing");
- gtk_widget_set_sensitive (window->end_call_button, TRUE);
- gtk_widget_set_sensitive (window->video_button, TRUE);
-
- g_object_get (G_OBJECT (window->call), "is-incoming", &is_incoming, NULL);
- if (is_incoming)
- gtk_widget_set_sensitive (window->start_call_button, TRUE);
- else
- g_signal_connect (GTK_OBJECT (window->video_button), "toggled",
- G_CALLBACK (call_window_video_button_toggled_cb),
- window);
- }
- else if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
- {
- if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTING)
- gtk_label_set_text (GTK_LABEL (window->status_label), "Connecting");
- else if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTED)
- {
- if ((window->start_time).tv_sec == 0)
- g_get_current_time (&(window->start_time));
- window->timeout_event_id = g_timeout_add (1000,
- call_window_update_timer, window);
- empathy_debug (DEBUG_DOMAIN, "Timer started");
- }
- }
-}
-
-static void
-call_window_receiving_video_cb (EmpathyTpCall *call,
- gboolean receiving_video,
- EmpathyCallWindow *window)
-{
- empathy_debug (DEBUG_DOMAIN, "Receiving video signal received");
-
- call_window_set_output_video_is_drawing (window, receiving_video);
-}
-
-static void
-call_window_sending_video_cb (EmpathyTpCall *call,
- gboolean sending_video,
- EmpathyCallWindow *window)
-{
- empathy_debug (DEBUG_DOMAIN, "Sending video signal received");
-
- g_signal_handlers_block_by_func (window->video_button,
- call_window_video_button_toggled_cb, window);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (window->video_button),
- sending_video);
- g_signal_handlers_unblock_by_func (window->video_button,
- call_window_video_button_toggled_cb, window);
}
static void
@@ -333,31 +168,30 @@ call_window_socket_realized_cb (GtkWidget *widget,
gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
}
else
- {
empathy_debug (DEBUG_DOMAIN, "Output socket realized");
- }
+}
+
+static void
+call_window_video_button_toggled_cb (GtkWidget *button,
+ EmpathyCallWindow *window)
+{
+ gboolean is_sending;
+
+ is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ empathy_debug (DEBUG_DOMAIN, "Send video toggled - %d", is_sending);
+
+ empathy_tp_call_request_video_stream_direction (window->call, is_sending);
}
static void
call_window_start_call_button_clicked_cb (GtkWidget *widget,
EmpathyCallWindow *window)
{
- gboolean send_video;
- gboolean is_incoming;
-
empathy_debug (DEBUG_DOMAIN, "Start call clicked");
gtk_widget_set_sensitive (window->start_call_button, FALSE);
- g_object_get (G_OBJECT (window->call), "is-incoming", &is_incoming, NULL);
- if (is_incoming)
- {
- empathy_tp_call_accept_incoming_call (window->call);
- send_video = gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (window->video_button));
- empathy_tp_call_request_video_stream_direction (window->call, send_video);
- g_signal_connect (GTK_OBJECT (window->video_button), "toggled",
- G_CALLBACK (call_window_video_button_toggled_cb), window);
- }
+ empathy_tp_call_accept_incoming_call (window->call);
}
static void
@@ -366,10 +200,8 @@ call_window_end_call_button_clicked_cb (GtkWidget *widget,
{
empathy_debug (DEBUG_DOMAIN, "End call clicked");
- call_window_set_output_video_is_drawing (window, FALSE);
- empathy_tp_call_close_channel (window->call);
gtk_widget_set_sensitive (window->end_call_button, FALSE);
- gtk_widget_set_sensitive (window->start_call_button, FALSE);
+ call_window_finalize (window);
}
static void
@@ -411,31 +243,158 @@ call_window_input_mute_button_toggled_cb (GtkWidget *button,
empathy_tp_call_mute_input (window->call, is_muted);
}
+static gboolean
+call_window_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ EmpathyCallWindow *window)
+{
+ GtkWidget *dialog;
+ gint result;
+ guint status;
+
+ empathy_debug (DEBUG_DOMAIN, "Delete event occurred");
+
+ g_object_get (G_OBJECT (window->call), "status", &status, NULL);
+ if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window->window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+ "This call will be ended. Continue?");
+
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ if (result != GTK_RESPONSE_YES)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
call_window_destroy_cb (GtkWidget *widget,
EmpathyCallWindow *window)
{
- g_signal_handlers_disconnect_by_func (window->call,
- call_window_status_changed_cb, window);
- g_signal_handlers_disconnect_by_func (window->call,
- call_window_receiving_video_cb, window);
- g_signal_handlers_disconnect_by_func (window->call,
- call_window_sending_video_cb, window);
-
- g_object_unref (window->call);
+ call_window_finalize (window);
g_object_unref (window->output_video_socket);
g_object_unref (window->preview_video_socket);
g_object_unref (window->output_video_label);
-
g_slice_free (EmpathyCallWindow, window);
}
+static void
+call_window_update (EmpathyCallWindow *window)
+{
+ EmpathyContact *contact;
+ guint status;
+ guint stream_state;
+ EmpathyTpCallStream *audio_stream;
+ EmpathyTpCallStream *video_stream;
+ gboolean is_incoming;
+ gchar *title;
+
+ g_object_get (window->call,
+ "status", &status,
+ "audio-stream", &audio_stream,
+ "video-stream", &video_stream,
+ "contact", &contact,
+ "is-incoming", &is_incoming,
+ NULL);
+
+ if (video_stream->state > audio_stream->state)
+ stream_state = video_stream->state;
+ else
+ stream_state = audio_stream->state;
+
+ empathy_debug (DEBUG_DOMAIN, "Status changed - status: %d, stream state: %d, "
+ "is-incoming: %d video-stream direction: %d",
+ status, stream_state, is_incoming, video_stream->direction);
+
+ /* Depending on the status we have to set:
+ * - window's title
+ * - status's label
+ * - sensibility of all buttons
+ * */
+ if (status == EMPATHY_TP_CALL_STATUS_READYING)
+ {
+ gtk_window_set_title (GTK_WINDOW (window->window), _("Empathy Call"));
+ gtk_label_set_text (GTK_LABEL (window->status_label), _("Readying"));
+ gtk_widget_set_sensitive (window->start_call_button, is_incoming);
+ gtk_widget_set_sensitive (window->end_call_button, FALSE);
+ gtk_widget_set_sensitive (window->video_button, FALSE);
+ gtk_widget_set_sensitive (window->input_volume_scale, FALSE);
+ gtk_widget_set_sensitive (window->output_volume_scale, FALSE);
+ gtk_widget_set_sensitive (window->input_mute_button, FALSE);
+ gtk_widget_set_sensitive (window->output_mute_button, FALSE);
+ }
+ else if (status == EMPATHY_TP_CALL_STATUS_PENDING)
+ {
+ title = g_strdup_printf (_("%s - Empathy Call"),
+ empathy_contact_get_name (contact));
+
+ gtk_window_set_title (GTK_WINDOW (window->window), title);
+ gtk_label_set_text (GTK_LABEL (window->status_label), _("Ringing"));
+ gtk_widget_set_sensitive (window->start_call_button, is_incoming);
+ gtk_widget_set_sensitive (window->end_call_button, TRUE);
+ }
+ else if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
+ {
+ gboolean receiving_video;
+ gboolean sending_video;
+
+ if (stream_state == TP_MEDIA_STREAM_STATE_DISCONNECTED)
+ gtk_label_set_text (GTK_LABEL (window->status_label), "Disconnected");
+ if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTING)
+ gtk_label_set_text (GTK_LABEL (window->status_label), "Connecting");
+ else if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTED &&
+ window->timeout_event_id == 0)
+ {
+ /* The call started, launch the timer */
+ g_get_current_time (&(window->start_time));
+ window->timeout_event_id = g_timeout_add_seconds (1,
+ call_window_update_timer, window);
+ call_window_update_timer (window);
+ }
+
+ receiving_video = video_stream->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE;
+ sending_video = video_stream->direction & TP_MEDIA_STREAM_DIRECTION_SEND;
+ call_window_set_output_video_is_drawing (window, receiving_video);
+ g_signal_handlers_block_by_func (window->video_button,
+ call_window_video_button_toggled_cb, window);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (window->video_button),
+ sending_video);
+ g_signal_handlers_unblock_by_func (window->video_button,
+ call_window_video_button_toggled_cb, window);
+
+ gtk_widget_set_sensitive (window->video_button, TRUE);
+ gtk_widget_set_sensitive (window->input_volume_scale, TRUE);
+ gtk_widget_set_sensitive (window->output_volume_scale, TRUE);
+ gtk_widget_set_sensitive (window->input_mute_button, TRUE);
+ gtk_widget_set_sensitive (window->output_mute_button, TRUE);
+ }
+ else if (status == EMPATHY_TP_CALL_STATUS_CLOSED)
+ {
+ gtk_label_set_text (GTK_LABEL (window->status_label), "Closed");
+ gtk_widget_set_sensitive (window->start_call_button, FALSE);
+ gtk_widget_set_sensitive (window->end_call_button, FALSE);
+ gtk_widget_set_sensitive (window->video_button, FALSE);
+ gtk_widget_set_sensitive (window->input_volume_scale, FALSE);
+ gtk_widget_set_sensitive (window->output_volume_scale, FALSE);
+ gtk_widget_set_sensitive (window->input_mute_button, FALSE);
+ gtk_widget_set_sensitive (window->output_mute_button, FALSE);
+
+ call_window_finalize (window);
+ }
+
+ g_object_unref (contact);
+}
+
GtkWidget *
empathy_call_window_new (EmpathyTpCall *call)
{
EmpathyCallWindow *window;
GladeXML *glade;
- guint status;
gchar *filename;
g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), NULL);
@@ -470,6 +429,7 @@ empathy_call_window_new (EmpathyTpCall *call)
"output_volume_scale", "value-changed", call_window_output_volume_changed_cb,
"start_call_button", "clicked", call_window_start_call_button_clicked_cb,
"end_call_button", "clicked", call_window_end_call_button_clicked_cb,
+ "video_button", "toggled", call_window_video_button_toggled_cb,
NULL);
g_object_unref (glade);
@@ -494,26 +454,11 @@ empathy_call_window_new (EmpathyTpCall *call)
window->preview_video_socket);
gtk_widget_show (window->preview_video_socket);
- g_signal_connect (G_OBJECT (window->call), "status-changed",
- G_CALLBACK (call_window_status_changed_cb),
- window);
- g_signal_connect (G_OBJECT (window->call), "receiving-video",
- G_CALLBACK (call_window_receiving_video_cb),
- window);
- g_signal_connect (G_OBJECT (window->call), "sending-video",
- G_CALLBACK (call_window_sending_video_cb),
+ g_signal_connect_swapped (G_OBJECT (window->call), "notify",
+ G_CALLBACK (call_window_update),
window);
- window->is_drawing = FALSE;
-
- g_object_get (G_OBJECT (window->call), "status", &status, NULL);
-
- if (status == EMPATHY_TP_CALL_STATUS_READYING)
- {
- gtk_window_set_title (GTK_WINDOW (window->window), "Empathy Call");
- gtk_label_set_text (GTK_LABEL (window->status_label), "Readying");
- }
-
+ call_window_update (window);
gtk_widget_show (window->window);
return window->window;
diff --git a/src/empathy-call-window.glade b/src/empathy-call-window.glade
index 7659f5278..1fdc38937 100644
--- a/src/empathy-call-window.glade
+++ b/src/empathy-call-window.glade
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.2 on Fri Apr 4 14:52:59 2008 -->
+<!--Generated with glade3 3.4.2 on Wed Apr 9 11:17:00 2008 -->
<glade-interface>
<widget class="GtkWindow" id="window">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -222,12 +222,10 @@
<child>
<widget class="GtkCheckButton" id="video_button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Send Video</property>
<property name="response_id">0</property>
- <property name="active">True</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
@@ -251,7 +249,6 @@
<child>
<widget class="GtkButton" id="start_call_button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -269,7 +266,6 @@
<child>
<widget class="GtkButton" id="end_call_button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>