diff options
author | Jonny Lamb <jonnylamb@gnome.org> | 2010-12-15 16:56:03 +0800 |
---|---|---|
committer | Jonny Lamb <jonnylamb@gnome.org> | 2010-12-15 16:56:03 +0800 |
commit | 2ec9b6e89141999f919f8a3bd4a44fd8abad86ff (patch) | |
tree | 10f81107c111564ec160d173db3b265a9573c4ff /src | |
parent | 2e38a9c56cdac919f424107928dbbf35d69a41ed (diff) | |
parent | 225ca2e12b053a6c8ece18179d470f01ed1d6fb7 (diff) | |
download | gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar.gz gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar.bz2 gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar.lz gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar.xz gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.tar.zst gsoc2013-empathy-2ec9b6e89141999f919f8a3bd4a44fd8abad86ff.zip |
Merge branch 'sasl-gui'
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-event-manager.c | 127 | ||||
-rw-r--r-- | src/empathy-event-manager.h | 2 | ||||
-rw-r--r-- | src/empathy-main-window.c | 149 | ||||
-rw-r--r-- | src/empathy-main-window.ui | 14 | ||||
-rw-r--r-- | src/empathy-notifications-approver.c | 10 | ||||
-rw-r--r-- | src/empathy-status-icon.c | 2 |
6 files changed, 279 insertions, 25 deletions
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index 5516328cc..93656c3a9 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -76,6 +76,7 @@ typedef struct { typedef struct { TpBaseClient *approver; + TpBaseClient *auth_approver; EmpathyContactManager *contact_manager; GSList *events; /* Ongoing approvals */ @@ -165,10 +166,8 @@ event_free (EventPriv *event) if (event->autoremove_timeout_id != 0) g_source_remove (event->autoremove_timeout_id); - if (event->public.contact) - { - g_object_unref (event->public.contact); - } + tp_clear_object (&(event->public.contact)); + tp_clear_object (&(event->public.account)); g_slice_free (EventPriv, event); } @@ -212,6 +211,7 @@ display_notify_area (EmpathyEventManager *self) static void event_manager_add (EmpathyEventManager *manager, + TpAccount *account, EmpathyContact *contact, EmpathyEventType type, const gchar *icon_name, @@ -225,6 +225,7 @@ event_manager_add (EmpathyEventManager *manager, EventPriv *event; event = g_slice_new0 (EventPriv); + event->public.account = account != NULL ? g_object_ref (account) : NULL; event->public.contact = contact ? g_object_ref (contact) : NULL; event->public.type = type; event->public.icon_name = g_strdup (icon_name); @@ -421,11 +422,46 @@ out: } static void +reject_auth_channel_claim_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source); + GError *error = NULL; + + if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error)) + { + DEBUG ("Failed to claim channel: %s", error->message); + + g_error_free (error); + return; + } + + tp_cli_channel_call_close (TP_CHANNEL (user_data), -1, + NULL, NULL, NULL, NULL); +} + +static void reject_approval (EventManagerApproval *approval) { /* We have to claim the channel before closing it */ - tp_channel_dispatch_operation_claim_async (approval->operation, - reject_channel_claim_cb, g_object_ref (approval->handler_instance)); + + /* Unfortunately, we need to special case the auth channels for the + * time being as they don't have a wrapper object handler in + * approval->handler_instance as they're not actually handled by + * this process, so we can just use a noddy callback to call Close() + * directly. */ + if (approval->handler_instance != NULL) + { + tp_channel_dispatch_operation_claim_async (approval->operation, + reject_channel_claim_cb, g_object_ref (approval->handler_instance)); + } + else if (tp_channel_get_channel_type_id (approval->main_channel) + == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION) + { + tp_channel_dispatch_operation_claim_async (approval->operation, + reject_auth_channel_claim_cb, approval->main_channel); + } } static void @@ -549,9 +585,9 @@ event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat, event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, msg); else - event_manager_add (approval->manager, sender, EMPATHY_EVENT_TYPE_CHAT, - EMPATHY_IMAGE_NEW_MESSAGE, header, msg, approval, - event_text_channel_process_func, NULL); + event_manager_add (approval->manager, NULL, sender, + EMPATHY_EVENT_TYPE_CHAT, EMPATHY_IMAGE_NEW_MESSAGE, header, msg, + approval, event_text_channel_process_func, NULL); empathy_sound_manager_play (priv->sound_mgr, window, EMPATHY_SOUND_CONVERSATION_NEW); @@ -625,8 +661,8 @@ event_manager_media_channel_got_contact (EventManagerApproval *approval) video ? _("Incoming video call from %s") :_("Incoming call from %s"), empathy_contact_get_alias (approval->contact)); - event_manager_add (approval->manager, approval->contact, - EMPATHY_EVENT_TYPE_VOIP, + event_manager_add (approval->manager, NULL, + approval->contact, EMPATHY_EVENT_TYPE_VOIP, video ? EMPATHY_IMAGE_VIDEO_CALL : EMPATHY_IMAGE_VOIP, header, NULL, approval, event_channel_process_voip_func, NULL); @@ -758,9 +794,10 @@ display_invite_room_dialog (EventManagerApproval *approval) tp_channel_get_identifier (approval->main_channel)); } - event_manager_add (approval->manager, approval->contact, - EMPATHY_EVENT_TYPE_INVITATION, EMPATHY_IMAGE_GROUP_MESSAGE, msg, - invite_msg, approval, event_room_channel_process_func, NULL); + event_manager_add (approval->manager, NULL, + approval->contact, EMPATHY_EVENT_TYPE_INVITATION, + EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg, approval, + event_room_channel_process_func, NULL); empathy_sound_manager_play (priv->sound_mgr, window, EMPATHY_SOUND_CONVERSATION_NEW); @@ -807,8 +844,9 @@ event_manager_ft_got_contact_cb (TpConnection *connection, header = g_strdup_printf (_("Incoming file transfer from %s"), empathy_contact_get_alias (approval->contact)); - event_manager_add (approval->manager, approval->contact, - EMPATHY_EVENT_TYPE_TRANSFER, EMPATHY_IMAGE_DOCUMENT_SEND, header, NULL, + event_manager_add (approval->manager, NULL, + approval->contact, EMPATHY_EVENT_TYPE_TRANSFER, + EMPATHY_IMAGE_DOCUMENT_SEND, header, NULL, approval, event_channel_process_func, NULL); /* FIXME better sound for incoming file transfers ?*/ @@ -819,8 +857,14 @@ event_manager_ft_got_contact_cb (TpConnection *connection, g_object_unref (window); } -/* If there is a file-transfer or media channel consider it as the - * main one. */ +static void +event_manager_auth_process_func (EventPriv *event) +{ + empathy_event_approve ((EmpathyEvent *) event); +} + +/* If there is a file-transfer, media, or auth channel consider it as + * the main one. */ static TpChannel * find_main_channel (GList *channels) { @@ -838,7 +882,8 @@ find_main_channel (GList *channels) channel_type = tp_channel_get_channel_type_id (channel); if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA || - channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) + channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER || + channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION) return channel; else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) @@ -962,6 +1007,13 @@ approve_channels (TpSimpleApprover *approver, empathy_tp_contact_factory_get_from_handle (connection, handle, event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (self)); } + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION) + { + event_manager_add (approval->manager, account, NULL, EMPATHY_EVENT_TYPE_AUTH, + GTK_STOCK_DIALOG_AUTHENTICATION, tp_account_get_display_name (account), + _("Password required"), approval, + event_manager_auth_process_func, NULL); + } else { GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, @@ -1023,7 +1075,7 @@ event_manager_pendings_changed_cb (EmpathyContactList *list, else event_msg = NULL; - event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_SUBSCRIPTION, + event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_SUBSCRIPTION, GTK_STOCK_DIALOG_QUESTION, header, event_msg, NULL, event_pending_subscribe_func, NULL); @@ -1066,7 +1118,7 @@ event_manager_presence_changed_cb (EmpathyContact *contact, header = g_strdup_printf (_("%s is now offline."), empathy_contact_get_alias (contact)); - event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE, + event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_PRESENCE, EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL); } } @@ -1087,7 +1139,7 @@ event_manager_presence_changed_cb (EmpathyContact *contact, header = g_strdup_printf (_("%s is now online."), empathy_contact_get_alias (contact)); - event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE, + event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_PRESENCE, EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL); } } @@ -1150,6 +1202,7 @@ event_manager_finalize (GObject *object) g_slist_free (priv->approvals); g_object_unref (priv->contact_manager); g_object_unref (priv->approver); + g_object_unref (priv->auth_approver); g_object_unref (priv->gsettings_notif); g_object_unref (priv->gsettings_ui); g_object_unref (priv->sound_mgr); @@ -1191,7 +1244,6 @@ empathy_event_manager_class_init (EmpathyEventManagerClass *klass) g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - g_type_class_add_private (object_class, sizeof (EmpathyEventManagerPriv)); } @@ -1262,12 +1314,41 @@ empathy_event_manager_init (EmpathyEventManager *manager) TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, NULL)); + /* I don't feel good about doing this, and I'm sorry, but the + * capabilities connection feature is added earlier because it's + * needed for EmpathyTpChat. If the capabilities feature is required + * then preparing an auth channel (which of course appears in the + * CONNECTING state) will never be prepared. So the options are + * either to create another approver like I've done, or to port + * EmpathyTpChat and its users to not depend on the connection being + * prepared with capabilities. I chose the former, obviously. :-) */ + + priv->auth_approver = tp_simple_approver_new (dbus, + "Empathy.AuthEventManager", FALSE, approve_channels, manager, + NULL); + + /* SASL auth channels */ + tp_base_client_take_approver_filter (priv->auth_approver, + tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION, + TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION_AUTHENTICATION_METHOD, + G_TYPE_STRING, + TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION, + NULL)); + if (!tp_base_client_register (priv->approver, &error)) { DEBUG ("Failed to register Approver: %s", error->message); g_error_free (error); } + if (!tp_base_client_register (priv->auth_approver, &error)) + { + DEBUG ("Failed to register auth Approver: %s", error->message); + g_error_free (error); + } + g_object_unref (dbus); } diff --git a/src/empathy-event-manager.h b/src/empathy-event-manager.h index cc81d2ddb..16d97c6df 100644 --- a/src/empathy-event-manager.h +++ b/src/empathy-event-manager.h @@ -55,9 +55,11 @@ typedef enum { EMPATHY_EVENT_TYPE_SUBSCRIPTION, EMPATHY_EVENT_TYPE_PRESENCE, EMPATHY_EVENT_TYPE_INVITATION, + EMPATHY_EVENT_TYPE_AUTH, } EmpathyEventType; typedef struct { + TpAccount *account; EmpathyContact *contact; EmpathyEventType type; gchar *icon_name; diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 64438ed0f..b1e26f5e5 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -122,6 +122,7 @@ struct _EmpathyMainWindowPriv { GtkWidget *presence_toolbar; GtkWidget *presence_chooser; GtkWidget *errors_vbox; + GtkWidget *auth_vbox; GtkWidget *search_bar; GtkWidget *notebook; GtkWidget *no_entry_label; @@ -142,8 +143,13 @@ struct _EmpathyMainWindowPriv { GtkWidget *edit_context_separator; guint size_timeout_id; + + /* reffed TpAccount* => visible GtkInfoBar* */ GHashTable *errors; + /* EmpathyEvent* => visible GtkInfoBar* */ + GHashTable *auths; + /* stores a mapping from TpAccount to Handler ID to prevent * to listen more than once to the status-changed signal */ GHashTable *status_changed_handlers; @@ -286,12 +292,146 @@ main_window_flash_start (EmpathyMainWindow *window) } static void +main_window_remove_auth (EmpathyMainWindow *window, + EmpathyEvent *event) +{ + EmpathyMainWindowPriv *priv = GET_PRIV (window); + GtkWidget *error_widget; + + error_widget = g_hash_table_lookup (priv->auths, event); + if (error_widget != NULL) { + gtk_widget_destroy (error_widget); + g_hash_table_remove (priv->auths, event); + } +} + +static void +main_window_auth_add_clicked_cb (GtkButton *button, + EmpathyMainWindow *window) +{ + EmpathyEvent *event; + + event = g_object_get_data (G_OBJECT (button), "event"); + + empathy_event_approve (event); + + main_window_remove_auth (window, event); +} + +static void +main_window_auth_close_clicked_cb (GtkButton *button, + EmpathyMainWindow *window) +{ + EmpathyEvent *event; + + event = g_object_get_data (G_OBJECT (button), "event"); + + empathy_event_decline (event); + main_window_remove_auth (window, event); +} + +static void +main_window_auth_display (EmpathyMainWindow *window, + EmpathyEvent *event) +{ + EmpathyMainWindowPriv *priv = GET_PRIV (window); + TpAccount *account = event->account; + GtkWidget *info_bar; + GtkWidget *content_area; + GtkWidget *image; + GtkWidget *label; + GtkWidget *add_button; + GtkWidget *close_button; + GtkWidget *action_area; + GtkWidget *action_table; + const gchar *icon_name; + gchar *str; + + if (g_hash_table_lookup (priv->auths, event) != NULL) { + return; + } + + info_bar = gtk_info_bar_new (); + gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION); + + gtk_widget_set_no_show_all (info_bar, TRUE); + gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0); + gtk_widget_show (info_bar); + + icon_name = tp_account_get_icon_name (account); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (image); + + str = g_markup_printf_escaped ("<b>%s</b>\n%s", + tp_account_get_display_name (account), + _("Password required")); + + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_widget_show (label); + + g_free (str); + + content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar)); + gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0); + + image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); + add_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (add_button), image); + gtk_widget_set_tooltip_text (add_button, _("Provide Password")); + gtk_widget_show (add_button); + + image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON); + close_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (close_button), image); + gtk_widget_set_tooltip_text (close_button, _("Disconnect")); + gtk_widget_show (close_button); + + action_table = gtk_table_new (1, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (action_table), 6); + gtk_widget_show (action_table); + + action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar)); + gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0); + + gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_SHRINK), + (GtkAttachOptions) (GTK_SHRINK), 0, 0); + gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_SHRINK), + (GtkAttachOptions) (GTK_SHRINK), 0, 0); + + g_object_set_data_full (G_OBJECT (info_bar), + "event", event, NULL); + g_object_set_data_full (G_OBJECT (add_button), + "event", event, NULL); + g_object_set_data_full (G_OBJECT (close_button), + "event", event, NULL); + + g_signal_connect (add_button, "clicked", + G_CALLBACK (main_window_auth_add_clicked_cb), + window); + g_signal_connect (close_button, "clicked", + G_CALLBACK (main_window_auth_close_clicked_cb), + window); + + gtk_widget_show (priv->auth_vbox); + + g_hash_table_insert (priv->auths, event, info_bar); +} + +static void main_window_event_added_cb (EmpathyEventManager *manager, EmpathyEvent *event, EmpathyMainWindow *window) { if (event->contact) { main_window_flash_start (window); + } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) { + main_window_auth_display (window, event); } } @@ -303,6 +443,11 @@ main_window_event_removed_cb (EmpathyEventManager *manager, EmpathyMainWindowPriv *priv = GET_PRIV (window); FlashForeachData data; + if (event->type == EMPATHY_EVENT_TYPE_AUTH) { + main_window_remove_auth (window, event); + return; + } + if (!event->contact) { return; } @@ -712,6 +857,7 @@ empathy_main_window_finalize (GObject *window) g_object_unref (priv->contact_manager); g_object_unref (priv->sound_mgr); g_hash_table_destroy (priv->errors); + g_hash_table_destroy (priv->auths); /* disconnect all handlers of status-changed signal */ g_hash_table_iter_init (&iter, priv->status_changed_handlers); @@ -1592,6 +1738,7 @@ empathy_main_window_init (EmpathyMainWindow *window) gui = empathy_builder_get_file (filename, "main_vbox", &priv->main_vbox, "errors_vbox", &priv->errors_vbox, + "auth_vbox", &priv->auth_vbox, "ui_manager", &priv->ui_manager, "view_show_offline", &show_offline_widget, "view_show_protocols", &priv->show_protocols, @@ -1661,6 +1808,8 @@ empathy_main_window_init (EmpathyMainWindow *window) g_object_unref, NULL); + priv->auths = g_hash_table_new (NULL, NULL); + priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 8356a1af7..e684c6bdf 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -309,6 +309,18 @@ </packing> </child> <child> + <object class="GtkVBox" id="auth_vbox"> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> + </packing> + </child> + <child> <object class="GtkNotebook" id="notebook"> <property name="visible">True</property> <property name="can_focus">True</property> @@ -340,7 +352,7 @@ </child> </object> <packing> - <property name="position">3</property> + <property name="position">4</property> </packing> </child> </object> diff --git a/src/empathy-notifications-approver.c b/src/empathy-notifications-approver.c index 0bfe03274..e0d540cdc 100644 --- a/src/empathy-notifications-approver.c +++ b/src/empathy-notifications-approver.c @@ -314,7 +314,11 @@ event_added_cb (EmpathyEventManager *manager, if (self->priv->event != NULL) return; + if (event->type == EMPATHY_EVENT_TYPE_AUTH) + return; + self->priv->event = event; + update_notification (self); } @@ -326,6 +330,9 @@ event_removed_cb (EmpathyEventManager *manager, if (event != self->priv->event) return; + if (event->type == EMPATHY_EVENT_TYPE_AUTH) + return; + self->priv->event = empathy_event_manager_get_top_event ( self->priv->event_mgr); @@ -340,6 +347,9 @@ event_updated_cb (EmpathyEventManager *manager, if (event != self->priv->event) return; + if (event->type == EMPATHY_EVENT_TYPE_AUTH) + return; + if (empathy_notify_manager_notification_is_enabled (self->priv->notify_mgr)) update_notification (self); } diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index 0c834a670..38a68d433 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -159,7 +159,7 @@ status_icon_event_added_cb (EmpathyEventManager *manager, DEBUG ("New event %p", event); priv->event = event; - if (event->must_ack) { + if (event->must_ack || event->type == EMPATHY_EVENT_TYPE_AUTH) { priv->showing_event_icon = TRUE; status_icon_update_icon (icon); status_icon_update_tooltip (icon); |