]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Add support for accepting Subscriptions to GTK frontend
authorFlorian Zeitz <florob@babelmonkeys.de>
Sun, 9 Jun 2013 21:51:45 +0000 (23:51 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sun, 9 Jun 2013 21:51:45 +0000 (23:51 +0200)
src/gui/gtk/JubGtkRosterUI.m

index 667760b0734cff566e6f9ed3a23791cc6340159b..dcd6f7d8b42553d6e50049a3ea1a39739f366417 100644 (file)
@@ -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: @"<b>%@</b> 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;
 {