From 218ec083210906f0ece9ad9aa266f1d73fccb192 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sun, 9 Jun 2013 23:51:45 +0200 Subject: [PATCH] Add support for accepting Subscriptions to GTK frontend --- src/gui/gtk/JubGtkRosterUI.m | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/gui/gtk/JubGtkRosterUI.m b/src/gui/gtk/JubGtkRosterUI.m index 667760b..dcd6f7d 100644 --- a/src/gui/gtk/JubGtkRosterUI.m +++ b/src/gui/gtk/JubGtkRosterUI.m @@ -63,6 +63,15 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model, return TRUE; } +static void dialog_response_callback(GtkDialog *dialog, gint response_id, + gpointer user_data) +{ + void (^block)(gint) = user_data; + block(response_id); + [block release]; + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + @implementation JubGtkRosterUI - initWithClient: (JubChatClient*)client { @@ -275,6 +284,38 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model, withObject: group]; } +- (void)contactManager: (XMPPContactManager*)manager + didReceiveSubscriptionRequest: (XMPPPresence*)presence +{ + XMPPJID *JID = presence.from; + OFString *message = [OFString stringWithFormat: @"%@ would like " + @"to subscribe to your presence.", JID]; + of_log(@"%@", message); + g_idle_add_block(^{ + GtkWidget *dialog, *content_area, *label; + dialog = gtk_dialog_new_with_buttons("Subscription Request", + GTK_WINDOW(_roster_window), GTK_DIALOG_DESTROY_WITH_PARENT, + "Accept", GTK_RESPONSE_ACCEPT, + "Deny", GTK_RESPONSE_REJECT, NULL); + + content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + label = gtk_label_new(NULL); + gtk_label_set_markup(GTK_LABEL(label), [message UTF8String]); + + g_signal_connect(dialog, "response", + G_CALLBACK(dialog_response_callback), + [^(gint response_id) { + if (response_id == GTK_RESPONSE_ACCEPT) + [manager sendSubscribedToJID: JID]; + else if (response_id == GTK_RESPONSE_REJECT) + [manager sendUnsubscribedToJID: JID]; + } copy]); + + gtk_container_add(GTK_CONTAINER(content_area), label); + gtk_widget_show_all(dialog); + }); +} + - (void)contact: (XMPPContact*)contact willUpdateWithRosterItem: (XMPPRosterItem*)rosterItem; { -- 2.39.5