changeset 6334:930708df05dd

[gaim-migrate @ 6833] When I got back from swimming, I found a bunch of IMs and chat requests from some annoying user who kept asking if I was dumb or dead. I decided to block this user, but realized just how ugly the dialog for doing so is. So, I rewrote it. Now I can block him in peace. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 30 Jul 2003 01:45:31 +0000
parents e06e04e44914
children ea47bddc7376
files src/dialogs.c src/gtkaccount.c src/gtkrequest.c
diffstat 3 files changed, 84 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/src/dialogs.c	Wed Jul 30 00:50:29 2003 +0000
+++ b/src/dialogs.c	Wed Jul 30 01:45:31 2003 +0000
@@ -84,13 +84,6 @@
 	GaimConnection *gc;
 };
 
-struct addperm {
-	GtkWidget *window;
-	GtkWidget *entry;
-	GaimConnection *gc;
-	gboolean permit;
-};
-
 struct findbyemail {
 	GtkWidget *window;
 	GtkWidget *emailentry;
@@ -123,6 +116,14 @@
 	GaimConnection *gc; 
 };
 
+typedef struct
+{
+	char *username;
+	gboolean block;
+	GaimConnection *gc;
+
+} GaimGtkBlockData;
+
 static GSList *info_dlgs = NULL;
 
 static struct info_dlg *find_info_dlg(GaimConnection *gc, const char *who)
@@ -379,13 +380,15 @@
 	gtk_widget_show_all(w->window);
 }
 
-void do_remove_chat(struct chat *chat)
+static void
+do_remove_chat(struct chat *chat)
 {
 	gaim_blist_remove_chat(chat);
 	gaim_blist_save();
 }
 
-void do_remove_buddy(struct buddy *b)
+static void
+do_remove_buddy(struct buddy *b)
 {
 	struct group *g;
 	GaimConversation *c;
@@ -2318,101 +2321,78 @@
 /*  The dialog for adding to permit/deny                                  */
 /*------------------------------------------------------------------------*/
 
-
-static void do_add_perm(GtkWidget *w, struct addperm *p)
+static void
+destroy_block_data_cb(GaimGtkBlockData *data)
 {
-
-	const char *who;
-
-	who = gtk_entry_get_text(GTK_ENTRY(p->entry));
-
-	if (!p->permit) {
-		if (gaim_privacy_deny_add(p->gc->account, who)) {
-			serv_add_deny(p->gc, who);
+	g_free(data->username);
+	g_free(data);
+}
+
+static void
+block_unblock_cb(GaimGtkBlockData *data)
+{
+	GaimAccount *account;
+
+	account = gaim_connection_get_account(data->gc);
+
+	if (data->block) {
+		if (gaim_privacy_deny_add(account, data->username)) {
+			serv_add_deny(data->gc, data->username);
 			build_block_list();
 			gaim_blist_save();
 		}
-	} else {
-		if (gaim_privacy_permit_add(p->gc->account, who)) {
-			serv_add_permit(p->gc, who);
+	}
+	else {
+		if (gaim_privacy_permit_add(account, data->username)) {
+			serv_add_permit(data->gc, data->username);
 			build_allow_list();
 			gaim_blist_save();
 		}
 	}
 
-	destroy_dialog(NULL, p->window);
+	destroy_block_data_cb(data);
 }
 
-
-
-void show_add_perm(GaimConnection *gc, char *who, gboolean permit)
+void
+show_add_perm(GaimConnection *gc, char *who, gboolean permit)
 {
-	GtkWidget *cancel;
-	GtkWidget *add;
-	GtkWidget *label;
-	GtkWidget *bbox;
-	GtkWidget *vbox;
-	GtkWidget *topbox;
-
-	struct addperm *p = g_new0(struct addperm, 1);
-	p->gc = gc;
-	p->permit = permit;
-
-	GAIM_DIALOG(p->window);
-	gtk_container_set_border_width(GTK_CONTAINER(p->window), 5);
-	gtk_window_set_resizable(GTK_WINDOW(p->window), FALSE);
-	gtk_widget_realize(p->window);
-
-	dialogwindows = g_list_prepend(dialogwindows, p->window);
-
-	bbox = gtk_hbox_new(FALSE, 5);
-	topbox = gtk_hbox_new(FALSE, 5);
-	vbox = gtk_vbox_new(FALSE, 5);
-	p->entry = gtk_entry_new();
-
-	/* Build Add Button */
-
-	if (permit)
-		add = gaim_pixbuf_button_from_stock(_("Permit"), GTK_STOCK_ADD, GAIM_BUTTON_HORIZONTAL);
+	char *primary, *secondary;
+	GaimGtkBlockData *data;
+
+	data = g_new0(GaimGtkBlockData, 1);
+
+	data->gc       = gc;
+	data->block    = !permit;
+	data->username = g_strdup(who);
+
+	if (permit) {
+		primary = g_strdup_printf(_("Unblock %s?"), who);
+		secondary = g_strdup_printf(
+				_("You are about to unblock %s. This will allow %s "
+				  "to speak to you again. Do you want to continue?"),
+				who, who);
+
+		gaim_request_action(gc, _("Unblock User"), primary, secondary,
+							0, data, 2,
+							_("Unblock"), G_CALLBACK(block_unblock_cb),
+							_("Cancel"), G_CALLBACK(destroy_block_data_cb));
+	}
 	else
-		add = gaim_pixbuf_button_from_stock(_("Deny"), GTK_STOCK_ADD, GAIM_BUTTON_HORIZONTAL);
-	cancel = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL);
-
-	/* End of Cancel Button */
-	if (who != NULL)
-		gtk_entry_set_text(GTK_ENTRY(p->entry), who);
-
-	/* Put the buttons in the box */
-
-	gtk_box_pack_end(GTK_BOX(bbox), add, FALSE, FALSE, 5);
-	gtk_box_pack_end(GTK_BOX(bbox), cancel, FALSE, FALSE, 5);
-
-	label = gtk_label_new(_("Add"));
-	gtk_box_pack_start(GTK_BOX(topbox), label, FALSE, FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(topbox), p->entry, FALSE, FALSE, 5);
-	/* And the boxes in the box */
-	gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5);
-	topbox=gtk_hbox_new(FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(topbox), vbox, FALSE, FALSE, 5);
-
-
-	/* Handle closes right */
-	g_signal_connect(G_OBJECT(p->window), "destroy", G_CALLBACK(destroy_dialog), p->window);
-	g_signal_connect(G_OBJECT(cancel), "clicked", G_CALLBACK(destroy_dialog), p->window);
-	g_signal_connect(G_OBJECT(add), "clicked", G_CALLBACK(do_add_perm), p);
-	g_signal_connect(G_OBJECT(p->entry), "activate", G_CALLBACK(do_add_perm), p);
-
-	/* Finish up */
-	if (permit)
-		gtk_window_set_title(GTK_WINDOW(p->window), _("Add Permit"));
-	else
-		gtk_window_set_title(GTK_WINDOW(p->window), _("Add Deny"));
-	gtk_window_set_focus(GTK_WINDOW(p->window), p->entry);
-	gtk_container_add(GTK_CONTAINER(p->window), topbox);
-	gtk_widget_realize(p->window);
-
-	gtk_widget_show_all(p->window);
+	{
+		primary = g_strdup_printf(_("Block %s?"), who);
+		secondary = g_strdup_printf(
+				_("You are about to block %s. This will prevent %s "
+				  "from speaking to you again. Do you want to continue?"),
+				who, who);
+
+		gaim_request_action(gc, _("Unblock User"), primary, secondary,
+							0, data, 2,
+							_("Block"), G_CALLBACK(block_unblock_cb),
+							_("Cancel"), G_CALLBACK(destroy_block_data_cb));
+	}
+
+	g_free(primary);
+	g_free(secondary);
 }
 
 
--- a/src/gtkaccount.c	Wed Jul 30 00:50:29 2003 +0000
+++ b/src/gtkaccount.c	Wed Jul 30 01:45:31 2003 +0000
@@ -178,7 +178,7 @@
 {
 	if ((dialog->plugin = gaim_find_prpl(protocol)) != NULL) {
 		dialog->prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(dialog->plugin);
-		dialog->protocol    = dialog->prpl_info->protocol;
+		dialog->protocol  = dialog->prpl_info->protocol;
 
 		if (dialog->protocol_id != NULL)
 			g_free(dialog->protocol_id);
--- a/src/gtkrequest.c	Wed Jul 30 00:50:29 2003 +0000
+++ b/src/gtkrequest.c	Wed Jul 30 01:45:31 2003 +0000
@@ -165,16 +165,18 @@
 static const char *
 text_to_stock(const char *text)
 {
-	STOCK_ITEMIZE(_("Yes"),    GTK_STOCK_YES);
-	STOCK_ITEMIZE(_("No"),     GTK_STOCK_NO);
-	STOCK_ITEMIZE(_("OK"),     GTK_STOCK_OK);
-	STOCK_ITEMIZE(_("Cancel"), GTK_STOCK_CANCEL);
-	STOCK_ITEMIZE(_("Apply"),  GTK_STOCK_APPLY);
-	STOCK_ITEMIZE(_("Close"),  GTK_STOCK_CLOSE);
-	STOCK_ITEMIZE(_("Delete"), GTK_STOCK_DELETE);
-	STOCK_ITEMIZE(_("Add"),    GTK_STOCK_ADD);
-	STOCK_ITEMIZE(_("Remove"), GTK_STOCK_REMOVE);
-	STOCK_ITEMIZE(_("Save"),   GTK_STOCK_SAVE);
+	STOCK_ITEMIZE(_("Yes"),     GTK_STOCK_YES);
+	STOCK_ITEMIZE(_("No"),      GTK_STOCK_NO);
+	STOCK_ITEMIZE(_("OK"),      GTK_STOCK_OK);
+	STOCK_ITEMIZE(_("Cancel"),  GTK_STOCK_CANCEL);
+	STOCK_ITEMIZE(_("Apply"),   GTK_STOCK_APPLY);
+	STOCK_ITEMIZE(_("Close"),   GTK_STOCK_CLOSE);
+	STOCK_ITEMIZE(_("Delete"),  GTK_STOCK_DELETE);
+	STOCK_ITEMIZE(_("Add"),     GTK_STOCK_ADD);
+	STOCK_ITEMIZE(_("Remove"),  GTK_STOCK_REMOVE);
+	STOCK_ITEMIZE(_("Save"),    GTK_STOCK_SAVE);
+	STOCK_ITEMIZE(_("Block"),   GAIM_STOCK_BLOCK);
+	STOCK_ITEMIZE(_("Unblock"), GTK_STOCK_REMOVE);
 
 	return text;
 }