diff src/dialogs.c @ 6371:8f94cce8faa5

[gaim-migrate @ 6876] I think I touched almost every file. Here's what happened. I started off fixing up the Makefile.am and configure.ac files to help with the core/UI split some. Then I got annoyed with the build_{allow,deny}_list() functions that everything used, and decided to core/UI split privacy. While doing that, I decided to redesign the dialog. So now, a lot has changed, but not really so much. Just that most files got affected. Oh yeah, and the UI stuff was taken out of internal.h and moved to gtkinternal.h. If you use this, please be aware of this change. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 05 Aug 2003 10:55:04 +0000
parents 3381f1a85d8f
children 9dd4bb3cf1df
line wrap: on
line diff
--- a/src/dialogs.c	Tue Aug 05 03:21:40 2003 +0000
+++ b/src/dialogs.c	Tue Aug 05 10:55:04 2003 +0000
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
-#include "internal.h"
+#include "gtkinternal.h"
 
 #include "debug.h"
 #include "log.h"
@@ -597,8 +597,9 @@
 	gtk_widget_show_all(window);
 }
 
-void show_info_select_account(GObject *w, GaimAccount *account,
-							  struct getuserinfo *info)
+static void
+show_info_select_account(GObject *w, GaimAccount *account,
+						 struct getuserinfo *info)
 {
 	info->gc = gaim_account_get_connection(account);
 }
@@ -1359,481 +1360,6 @@
 }
 
 
-
-/*------------------------------------------------------------------------*
- *  Privacy Settings                                                      *
- *------------------------------------------------------------------------*/
-static GtkWidget *privacy_win;
-static GtkWidget *privacy_sensbox;
-
-static GtkWidget *deny_type = NULL;
-static GtkWidget *deny_conn_hbox = NULL;
-static GtkWidget *deny_opt_menu = NULL;
-static GaimConnection *current_deny_gc = NULL;
-static gboolean current_is_deny = FALSE;
-static GtkWidget *allow_list = NULL;
-static GtkWidget *block_list = NULL;
-
-static GtkListStore *block_store = NULL;
-static GtkListStore *allow_store = NULL;
-
-static void set_deny_mode(GtkWidget *w, int data)
-{
-	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
-		return;
-
-	gaim_debug(GAIM_DEBUG_INFO, "privacy", "Setting deny mode %d\n", data);
-	current_deny_gc->account->perm_deny = data;
-	serv_set_permit_deny(current_deny_gc);
-	gaim_blist_save();
-}
-
-static GtkWidget *deny_opt(char *label, int which, GtkWidget *set)
-{
-	GtkWidget *opt;
-
-	if (!set)
-		opt = gtk_radio_button_new_with_label(NULL, label);
-	else
-		opt =
-		    gtk_radio_button_new_with_label(gtk_radio_button_get_group(
-						GTK_RADIO_BUTTON(set)),
-						    label);
-
-	g_signal_connect(G_OBJECT(opt), "toggled", G_CALLBACK(set_deny_mode), (void *)which);
-	gtk_widget_show(opt);
-	if (current_deny_gc->account->perm_deny == which)
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(opt), TRUE);
-
-	return opt;
-}
-
-static void des_deny_opt(GtkWidget *d, gpointer e)
-{
-	gtk_widget_destroy(d);
-	current_deny_gc = NULL;
-	deny_conn_hbox = NULL;
-	deny_type = NULL;
-	deny_opt_menu = NULL;
-	current_is_deny = FALSE;
-	allow_list = NULL;
-	allow_store = NULL;
-
-	block_list = NULL;
-	block_store = NULL;
-}
-
-static void set_deny_type()
-{
-	GSList *bg = gtk_radio_button_get_group(GTK_RADIO_BUTTON(deny_type));
-
-	switch (current_deny_gc->account->perm_deny) {
-	case 5:
-		bg = bg->next->next;
-		break;
-	case 4:
-		break;
-	case 3:
-		bg = bg->next->next->next;
-		break;
-	case 2:
-		bg = bg->next;
-		break;
-	case 1:
-		bg = bg->next->next->next->next;
-		break;
-	}
-
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bg->data), TRUE);
-}
-
-void build_allow_list()
-{
-	GSList *p;
-	GtkListStore *ls;
-	GtkTreeIter iter;
-
-	if (!current_is_deny)
-		return;
-
-	p = current_deny_gc->account->permit;
-
-	gtk_list_store_clear(GTK_LIST_STORE(allow_store));
-
-	while (p) {
-		ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(allow_list)));
-
-		gtk_list_store_append(ls, &iter);
-		gtk_list_store_set(ls, &iter, 0, p->data, -1);
-
-		p = p->next;
-	}
-}
-
-
-void build_block_list()
-{
-	GSList *d;
-	GtkListStore *ls;
-	GtkTreeIter iter;
-
-	if (!current_is_deny)
-		return;
-
-	d = current_deny_gc->account->deny;
-
-	gtk_list_store_clear(GTK_LIST_STORE(block_store));
-
-	while (d) {
-		ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(block_list)));
-
-		gtk_list_store_append(ls, &iter);
-		gtk_list_store_set(ls, &iter, 0, d->data, -1);
-
-		d = d->next;
-	}
-}
-
-static void deny_gc_opt(GtkWidget *opt, GaimConnection *gc)
-{
-	current_deny_gc = gc;
-	set_deny_type();
-	build_allow_list();
-	build_block_list();
-}
-
-static void build_deny_menu()
-{
-	GtkWidget *menu;
-	GtkWidget *opt;
-	GList *c = gaim_connections_get_all();
-	GaimConnection *gc;
-	GaimAccount *account;
-	int count = 0;
-	gboolean found = FALSE;
-	char buf[2048];
-
-	if (g_list_length(gaim_connections_get_all()) == 1) {
-		gtk_widget_hide(deny_conn_hbox);
-		return;
-	} else
-		gtk_widget_show(deny_conn_hbox);
-
-	menu = gtk_menu_new();
-
-	while (c) {
-		gc = (GaimConnection *)c->data;
-		c = c->next;
-
-		if (!GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->set_permit_deny)
-			continue;
-
-		account = gaim_connection_get_account(gc);
-
-		g_snprintf(buf, sizeof buf, "%s (%s)",
-				   gaim_account_get_username(account), gc->prpl->info->name);
-		opt = gtk_menu_item_new_with_label(buf);
-		g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(deny_gc_opt), gc);
-		gtk_widget_show(opt);
-		gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
-		if (gc == current_deny_gc)
-			found = TRUE;
-		else if (!found)
-			count++;
-	}
-
-	if (!found) {
-		current_deny_gc = gaim_connections_get_all()->data;
-		count = 0;
-	}
-
-	gtk_option_menu_remove_menu(GTK_OPTION_MENU(deny_opt_menu));
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(deny_opt_menu), menu);
-	gtk_option_menu_set_history(GTK_OPTION_MENU(deny_opt_menu), count);
-
-	gtk_widget_show(menu);
-	gtk_widget_show(deny_opt_menu);
-}
-
-static void pref_deny_add(GtkWidget *button, gboolean permit)
-{
-	show_add_perm(current_deny_gc, NULL, permit);
-}
-
-
-gchar *find_permdeny_by_name(GSList *l, char *who) {
-	gchar *name;
-	
-	while (l) {
-		name = (gchar *)l->data;
-		if (!strcmp(name, who)) {
-			return name;
-		}
-		
-		l = l->next;
-	}
-
-	return NULL;
-}
-
-static void pref_deny_rem(GtkWidget *button, gboolean permit)
-{
-	gchar *who;
-	GtkTreeIter iter;
-	GtkTreeModel *mod;
-	GtkTreeSelection *sel;
-
-	if (permit) {
-		mod = gtk_tree_view_get_model(GTK_TREE_VIEW(allow_list));
-		sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(allow_list));
-	} else {
-		mod = gtk_tree_view_get_model(GTK_TREE_VIEW(block_list));
-		sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(block_list));
-	}
-
-	if (gtk_tree_selection_get_selected(sel, NULL, &iter))
-		gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 0, &who, -1);
-	else {
-		return;
-	}
-
-	if (permit && !allow_list)
-		return;
-
-	if (!permit && !block_list)
-		return;
-
-	if (permit) {
-		char *name = find_permdeny_by_name(current_deny_gc->account->permit, who);
-
-		if (name) {
-			gaim_privacy_permit_remove(current_deny_gc->account, name);
-			serv_rem_permit(current_deny_gc, who);
-			build_allow_list();
-		}
-	} else {
-		char *name = find_permdeny_by_name(current_deny_gc->account->deny, who);
-
-		if (name) {
-			gaim_privacy_deny_remove(current_deny_gc->account, name);
-			serv_rem_deny(current_deny_gc, who);
-			build_block_list();
-		}
-	}
-
-	gaim_blist_save();
-}
-
-void update_privacy_connections() { /* This is a slightly better name */
-	gboolean needdeny = FALSE;
-	GList *c = gaim_connections_get_all();
-	GaimConnection *gc = NULL;
-
-	if (!privacy_win)
-		return;
-
-	while (c) {
-		gc = c->data;
-		if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->set_permit_deny)
-			break;
-		gc = NULL;
-		c = c->next;
-	}
-	needdeny = (gc != NULL);
-	
-
-	if (needdeny) {
-		gtk_widget_set_sensitive(privacy_sensbox, TRUE);
-		build_deny_menu();
-		build_allow_list();
-		build_block_list();
-	} else {
-		gtk_widget_set_sensitive(privacy_sensbox, FALSE);
-	}
-}
-static void destroy_privacy() {
-	current_deny_gc = NULL;
-	privacy_win = NULL;
-	privacy_sensbox = NULL;
-}
-
-void show_privacy_options() {
-	GtkWidget *pwin;
-	GtkWidget *box;
-	GtkWidget *box2;
-	GtkWidget *hbox;
-	GtkWidget *label;
-	GtkWidget *sw;
-	GtkWidget *bbox;
-	GtkWidget *button;
-	GtkWidget *sep;
-	GtkWidget *close_button;
-	GtkSizeGroup *sg1 = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
-	GtkSizeGroup *sg2 = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
-	GtkCellRenderer *rend;
-	GtkTreeViewColumn *col;
-	GtkWidget *table;
-
-	if (privacy_win != NULL) {
-		gtk_widget_show(privacy_win);
-		gdk_window_raise(privacy_win->window);
-		return;
-	}
-
-	current_deny_gc = gaim_connections_get_all()->data;	/* this is safe because this screen will only be
-						   available when there are gaim_connections_get_all() */
-	current_is_deny = TRUE;
-
-	privacy_win = pwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_resizable(GTK_WINDOW(pwin), FALSE);
-	gtk_window_set_role(GTK_WINDOW(pwin), "privacy");
-	gtk_window_set_title(GTK_WINDOW(pwin), _("Privacy"));
-	g_signal_connect(G_OBJECT(pwin), "destroy", G_CALLBACK(destroy_privacy), NULL);
-	gtk_widget_realize(pwin);
-
-	gtk_widget_set_size_request(pwin, -1, 400);
-
-	box = gtk_vbox_new(FALSE, 5);
-	gtk_container_set_border_width(GTK_CONTAINER(box), 5);
-	gtk_container_add(GTK_CONTAINER(pwin), box);
-	gtk_widget_show(box);
-
-	privacy_sensbox = box2 = gtk_vbox_new(FALSE, 5);
-	gtk_container_set_border_width(GTK_CONTAINER(box2), 5);
-	gtk_box_pack_start(GTK_BOX(box), box2, TRUE, TRUE, 0);
-	gtk_widget_show(box2);
-
-	label = gtk_label_new(_("Changes to privacy settings take effect immediately."));
-	gtk_box_pack_start(GTK_BOX(box2), label, FALSE, FALSE, 0);
-	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-	gtk_widget_show(label);
-
-	deny_conn_hbox = gtk_hbox_new(FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(box2), deny_conn_hbox, FALSE, FALSE, 5);
-	gtk_widget_show(deny_conn_hbox);
-
-	label = gtk_label_new(_("Set privacy for:"));
-	gtk_box_pack_start(GTK_BOX(deny_conn_hbox), label, FALSE, FALSE, 5);
-	gtk_widget_show(label);
-
-	deny_opt_menu = gtk_option_menu_new();
-	gtk_box_pack_start(GTK_BOX(deny_conn_hbox), deny_opt_menu, FALSE, FALSE, 5);
-	g_signal_connect(G_OBJECT(deny_opt_menu), "destroy", G_CALLBACK(des_deny_opt), NULL);
-	gtk_widget_show(deny_opt_menu);
-
-	build_deny_menu();
-
-	table = gtk_table_new(5, 2, FALSE);
-	gtk_box_pack_start(GTK_BOX(box2), table, TRUE, TRUE, 0);
-	gtk_table_set_row_spacings(GTK_TABLE(table), 7);
-	gtk_table_set_col_spacings(GTK_TABLE(table), 5);
-	gtk_widget_show(table);
-
-	deny_type = deny_opt(_("Allow all users to contact me"), 1, NULL);
-	gtk_size_group_add_widget(sg1, deny_type);
-	gtk_table_attach(GTK_TABLE(table), deny_type, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
-	
-	deny_type = deny_opt(_("Allow only users on my buddy list"), 5, deny_type);
-	gtk_size_group_add_widget(sg1, deny_type);
-	gtk_table_attach(GTK_TABLE(table), deny_type, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
-
-	deny_type = deny_opt(_("Allow only the users below"), 3, deny_type);
-	gtk_size_group_add_widget(sg1, deny_type);
-	gtk_table_attach(GTK_TABLE(table), deny_type, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
-
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-	gtk_table_attach(GTK_TABLE(table), sw, 0, 1, 3, 4, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-	gtk_widget_show(sw);
-
-	allow_store = gtk_list_store_new(1, G_TYPE_STRING);
-	allow_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(allow_store));
-
-	rend = gtk_cell_renderer_text_new();
-	col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL);
-	gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE);
-	gtk_tree_view_append_column(GTK_TREE_VIEW(allow_list), col);
-	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(allow_list), FALSE);
-	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), allow_list);
-	gtk_widget_show(allow_list);
-
-	build_allow_list();
-
-	bbox = gtk_hbox_new(TRUE, 0);
-	gtk_widget_show(bbox);
-	gtk_table_attach(GTK_TABLE(table), bbox, 0, 1, 4, 5, GTK_FILL, 0, 0, 0);
-
-	button = gtk_button_new_from_stock(GTK_STOCK_ADD);
-	gtk_size_group_add_widget(sg2, button);
-	gtk_widget_show(button);
-	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(pref_deny_add), (void *)TRUE);
-	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-
-	button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
-	gtk_size_group_add_widget(sg2, button);
-	gtk_widget_show(button);
-	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(pref_deny_rem), (void *)TRUE);
-	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-
-	deny_type = deny_opt(_("Deny all users"), 2, deny_type);
-	gtk_size_group_add_widget(sg1, deny_type);
-	gtk_table_attach(GTK_TABLE(table), deny_type, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
-
-	deny_type = deny_opt(_("Block the users below"), 4, deny_type);
-	gtk_size_group_add_widget(sg1, deny_type);
-	gtk_table_attach(GTK_TABLE(table), deny_type, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
-
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-	gtk_table_attach(GTK_TABLE(table), sw, 1, 2, 3, 4, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-	gtk_widget_show(sw);
-
-	block_store = gtk_list_store_new(1, G_TYPE_STRING);
-	block_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(block_store));
-
-	rend = gtk_cell_renderer_text_new();
-	col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL);
-	gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE);
-	gtk_tree_view_append_column(GTK_TREE_VIEW(block_list), col);
-	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(block_list), FALSE);
-	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), block_list);
-	gtk_widget_show(block_list);
-
-	build_block_list();
-
-	bbox = gtk_hbox_new(TRUE, 0);
-	gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 4, 5, GTK_FILL, 0, 0, 0);
-	gtk_widget_show(bbox);
-
-	button = gtk_button_new_from_stock(GTK_STOCK_ADD);
-	gtk_size_group_add_widget(sg2, button);
-	gtk_widget_show(button);
-	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(pref_deny_add), FALSE);	
-	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-
-	button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
-	gtk_size_group_add_widget(sg2, button);
-	gtk_widget_show(button);
-	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(pref_deny_rem), FALSE);
-	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-
-	sep = gtk_hseparator_new();
-	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5);
-	gtk_widget_show(sep);
-
-	hbox = gtk_hbox_new(FALSE, 0);
-	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
-	gtk_widget_show(hbox);
-
-	close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-	gtk_box_pack_end(GTK_BOX(hbox), close_button, FALSE, FALSE, 0);
-	g_signal_connect_swapped(G_OBJECT(close_button), "clicked", G_CALLBACK(gtk_widget_destroy), pwin);
-	gtk_widget_show(close_button);
-
-	gtk_widget_show(pwin);
-}
-
-
 /*------------------------------------------------------------------------*/
 /*  The dialog for SET INFO / SET DIR INFO                                */
 /*------------------------------------------------------------------------*/
@@ -2318,84 +1844,6 @@
 		serv_get_away(gc, who);
 }
 
-/*------------------------------------------------------------------------*/
-/*  The dialog for adding to permit/deny                                  */
-/*------------------------------------------------------------------------*/
-
-static void
-destroy_block_data_cb(GaimGtkBlockData *data)
-{
-	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(account, data->username)) {
-			serv_add_permit(data->gc, data->username);
-			build_allow_list();
-			gaim_blist_save();
-		}
-	}
-
-	destroy_block_data_cb(data);
-}
-
-void
-show_add_perm(GaimConnection *gc, char *who, gboolean permit)
-{
-	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
-	{
-		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);
-}
-
 
 /*------------------------------------------------------------------------*/
 /*  Functions Called To Add A Log                                          */