changeset 5779:758fa27534b3

[gaim-migrate @ 6204] Auto-login support is back in, and we have UI-specific settings, and some bugs were fixed in the account editor (including a crash on gtk 2.0, I hope!) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 07 Jun 2003 00:30:09 +0000
parents a6947aef5f13
children a9029bed0479
files src/account.c src/account.h src/gtkaccount.c src/ui.h
diffstat 4 files changed, 223 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Fri Jun 06 21:46:16 2003 +0000
+++ b/src/account.c	Sat Jun 07 00:30:09 2003 +0000
@@ -136,9 +136,8 @@
 
 	account->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
 											  g_free, __delete_setting);
-
 	account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
-												 g_free, __delete_setting);
+				g_free, (GDestroyNotify)g_hash_table_destroy);
 
 	return account;
 }
@@ -158,6 +157,7 @@
 	if (account->protocol_id != NULL) g_free(account->protocol_id);
 
 	g_hash_table_destroy(account->settings);
+	g_hash_table_destroy(account->ui_settings);
 
 	g_free(account);
 }
@@ -303,6 +303,16 @@
 }
 
 void
+gaim_account_set_auto_login(GaimAccount *account, const char *ui,
+							gboolean value)
+{
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(ui      != NULL);
+
+	gaim_account_set_ui_bool(account, ui, "auto-login", value);
+}
+
+void
 gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info)
 {
 	g_return_if_fail(account != NULL);
@@ -381,11 +391,28 @@
 	schedule_accounts_save();
 }
 
+static GHashTable *
+_get_ui_settings_table(GaimAccount *account, const char *ui)
+{
+	GHashTable *table;
+
+	table = g_hash_table_lookup(account->ui_settings, ui);
+	
+	if (table == NULL) {
+		table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+									  __delete_setting);
+		g_hash_table_insert(account->ui_settings, g_strdup(ui), table);
+	}
+
+	return table;
+}
+
 void
 gaim_account_set_ui_int(GaimAccount *account, const char *ui,
 						const char *name, int value)
 {
 	GaimAccountSetting *setting;
+	GHashTable *table;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(ui      != NULL);
@@ -397,7 +424,9 @@
 	setting->ui            = g_strdup(ui);
 	setting->value.integer = value;
 
-	g_hash_table_insert(account->ui_settings, g_strdup(name), setting);
+	table = _get_ui_settings_table(account, ui);
+
+	g_hash_table_insert(table, g_strdup(name), setting);
 
 	schedule_accounts_save();
 }
@@ -407,6 +436,7 @@
 						   const char *name, const char *value)
 {
 	GaimAccountSetting *setting;
+	GHashTable *table;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(ui      != NULL);
@@ -418,7 +448,9 @@
 	setting->ui           = g_strdup(ui);
 	setting->value.string = g_strdup(value);
 
-	g_hash_table_insert(account->ui_settings, g_strdup(name), setting);
+	table = _get_ui_settings_table(account, ui);
+
+	g_hash_table_insert(table, g_strdup(name), setting);
 
 	schedule_accounts_save();
 }
@@ -428,6 +460,7 @@
 						 const char *name, gboolean value)
 {
 	GaimAccountSetting *setting;
+	GHashTable *table;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(ui      != NULL);
@@ -439,7 +472,9 @@
 	setting->ui         = g_strdup(ui);
 	setting->value.bool = value;
 
-	g_hash_table_insert(account->ui_settings, g_strdup(name), setting);
+	table = _get_ui_settings_table(account, ui);
+
+	g_hash_table_insert(table, g_strdup(name), setting);
 
 	schedule_accounts_save();
 }
@@ -525,6 +560,15 @@
 	return account->check_mail;
 }
 
+gboolean
+gaim_account_get_auto_login(const GaimAccount *account, const char *ui)
+{
+	g_return_val_if_fail(account != NULL, FALSE);
+	g_return_val_if_fail(ui      != NULL, FALSE);
+
+	return gaim_account_get_ui_bool(account, ui, "auto-login", FALSE);
+}
+
 GaimProxyInfo *
 gaim_account_get_proxy_info(const GaimAccount *account)
 {
@@ -590,6 +634,72 @@
 	return setting->value.bool;
 }
 
+int
+gaim_account_get_ui_int(const GaimAccount *account, const char *ui,
+						const char *name, int default_value)
+{
+	GaimAccountSetting *setting;
+	GHashTable *table;
+
+	g_return_val_if_fail(account != NULL, default_value);
+	g_return_val_if_fail(ui      != NULL, default_value);
+	g_return_val_if_fail(name    != NULL, default_value);
+
+	if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL)
+		return default_value;
+
+	if ((setting = g_hash_table_lookup(table, name)) == NULL)
+		return default_value;
+
+	g_return_val_if_fail(setting->type == GAIM_PREF_INT, default_value);
+
+	return setting->value.integer;
+}
+
+const char *
+gaim_account_get_ui_string(const GaimAccount *account, const char *ui,
+						   const char *name, const char *default_value)
+{
+	GaimAccountSetting *setting;
+	GHashTable *table;
+
+	g_return_val_if_fail(account != NULL, default_value);
+	g_return_val_if_fail(ui      != NULL, default_value);
+	g_return_val_if_fail(name    != NULL, default_value);
+
+	if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL)
+		return default_value;
+
+	if ((setting = g_hash_table_lookup(table, name)) == NULL)
+		return default_value;
+
+	g_return_val_if_fail(setting->type == GAIM_PREF_STRING, default_value);
+
+	return setting->value.string;
+}
+
+gboolean
+gaim_account_get_ui_bool(const GaimAccount *account, const char *ui,
+						 const char *name, gboolean default_value)
+{
+	GaimAccountSetting *setting;
+	GHashTable *table;
+
+	g_return_val_if_fail(account != NULL, default_value);
+	g_return_val_if_fail(ui      != NULL, default_value);
+	g_return_val_if_fail(name    != NULL, default_value);
+
+	if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL)
+		return default_value;
+
+	if ((setting = g_hash_table_lookup(table, name)) == NULL)
+		return default_value;
+
+	g_return_val_if_fail(setting->type == GAIM_PREF_BOOLEAN, default_value);
+
+	return setting->value.bool;
+}
+
 /* XML Stuff */
 static void
 __free_parser_data(gpointer user_data)
@@ -653,8 +763,10 @@
 	else if (!strcmp(element_name, "port"))
 		data->tag = TAG_PORT;
 	else if (!strcmp(element_name, "settings")) {
-		if ((value = g_hash_table_lookup(atts, "ui")) != NULL)
+		if ((value = g_hash_table_lookup(atts, "ui")) != NULL) {
+			gaim_debug(GAIM_DEBUG_INFO, "account", "Found ui: %s\n", value);
 			data->setting_ui = g_strdup(value);
+		}
 	}
 	else if (!strcmp(element_name, "setting")) {
 		data->tag = TAG_SETTING;
@@ -764,6 +876,10 @@
 	}
 	else if (data->tag == TAG_SETTING) {
 		if (data->setting_ui != NULL) {
+			gaim_debug(GAIM_DEBUG_INFO, "account",
+					   "Setting account. UI = %s, setting = %s, buffer = %s\n",
+					   data->setting_ui, data->setting_name, buffer);
+
 			if (data->setting_type == GAIM_PREF_STRING)
 				gaim_account_set_ui_string(data->account, data->setting_ui,
 										   data->setting_name, buffer);
@@ -899,7 +1015,7 @@
 }
 
 static void
-__write_setting(gpointer key, gpointer value, gpointer user_data)
+_write_setting(gpointer key, gpointer value, gpointer user_data)
 {
 	GaimAccountSetting *setting;
 	const char *name;
@@ -924,6 +1040,22 @@
 }
 
 static void
+_write_ui_setting_list(gpointer key, gpointer value, gpointer user_data)
+{
+	GHashTable *table;
+	const char *ui;
+	FILE *fp;
+
+	table = (GHashTable *)value;
+	ui    = (const char *)key;
+	fp    = (FILE *)user_data;
+
+	fprintf(fp, "  <settings ui='%s'>\n", ui);
+	g_hash_table_foreach(table, _write_setting, fp);
+	fprintf(fp, "  </settings>\n");
+}
+
+static void
 gaim_accounts_write(FILE *fp, GaimAccount *account)
 {
 	GaimProxyInfo *proxy_info;
@@ -963,9 +1095,11 @@
 	}
 
 	fprintf(fp, "  <settings>\n");
-	g_hash_table_foreach(account->settings, __write_setting, fp);
+	g_hash_table_foreach(account->settings, _write_setting, fp);
 	fprintf(fp, "  </settings>\n");
 
+	g_hash_table_foreach(account->ui_settings, _write_ui_setting_list, fp);
+
 	if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL &&
 		(proxy_type = gaim_proxy_info_get_type(proxy_info)) != GAIM_PROXY_NONE)
 	{
@@ -1079,6 +1213,22 @@
 }
 
 void
+gaim_accounts_auto_login(const char *ui)
+{
+	GaimAccount *account;
+	GList *l;
+
+	g_return_if_fail(ui != NULL);
+
+	for (l = gaim_connections_get_all(); l != NULL; l = l->next) {
+		account = l->data;
+
+		if (gaim_account_get_auto_login(account, ui))
+			gaim_account_connect(account);
+	}
+}
+
+void
 gaim_accounts_reorder(GaimAccount *account, size_t new_index)
 {
 	size_t index;
--- a/src/account.h	Fri Jun 06 21:46:16 2003 +0000
+++ b/src/account.h	Sat Jun 07 00:30:09 2003 +0000
@@ -162,6 +162,17 @@
 void gaim_account_set_check_mail(GaimAccount *account, gboolean value);
 
 /**
+ * Sets whether or not this account should auto-login for the specified
+ * UI.
+ *
+ * @param account The account.
+ * @param ui      The UI.
+ * @param value   @c TRUE if it should check for mail.
+ */
+void gaim_account_set_auto_login(GaimAccount *account, const char *ui,
+								 gboolean value);
+
+/**
  * Sets the account's proxy information.
  * 
  * @param account The account.
@@ -329,6 +340,18 @@
 gboolean gaim_account_get_check_mail(const GaimAccount *account);
 
 /**
+ * Returns whether or not this account should auto-login for the
+ * specified UI.
+ *
+ * @param account The account.
+ * @param ui      The UI.
+ *
+ * @return @c TRUE if it should auto-login on this UI.
+ */
+gboolean gaim_account_get_auto_login(const GaimAccount *account,
+									 const char *ui);
+
+/**
  * Returns the account's proxy information.
  *
  * @param account The account.
@@ -439,6 +462,13 @@
 void gaim_accounts_remove(GaimAccount *account);
 
 /**
+ * Auto-logins to all accounts set to auto-login under the specified UI.
+ *
+ * @param ui The UI.
+ */
+void gaim_accounts_auto_login(const char *ui);
+
+/**
  * Reorders an account.
  *
  * @param account   The account to reorder.
--- a/src/gtkaccount.c	Fri Jun 06 21:46:16 2003 +0000
+++ b/src/gtkaccount.c	Sat Jun 07 00:30:09 2003 +0000
@@ -45,8 +45,8 @@
 enum
 {
 	COLUMN_ICON,
+	COLUMN_SCREENNAME,
 	COLUMN_PROTOCOL,
-	COLUMN_SCREENNAME,
 	COLUMN_ONLINE,
 	COLUMN_AUTOLOGIN,
 	COLUMN_DATA,
@@ -1380,7 +1380,23 @@
 autologin_cb(GtkCellRendererToggle *renderer, gchar *path_str,
 			   gpointer data)
 {
-	
+	AccountsDialog *dialog = (AccountsDialog *)data;
+	GaimAccount *account;
+	GtkTreeModel *model = GTK_TREE_MODEL(dialog->model);
+	GtkTreeIter iter;
+	gboolean autologin;
+
+	gtk_tree_model_get_iter_from_string(model, &iter, path_str);
+	gtk_tree_model_get(model, &iter,
+					   COLUMN_DATA, &account,
+					   COLUMN_AUTOLOGIN, &autologin,
+					   -1);
+
+	gaim_account_set_auto_login(account, GAIM_GTK_UI, !autologin);
+
+	gtk_list_store_set(dialog->model, &iter,
+					   COLUMN_AUTOLOGIN, !autologin,
+					   -1);
 }
 
 static void
@@ -1389,18 +1405,18 @@
 	GtkCellRenderer *renderer;
 	GtkTreeViewColumn *column;
 
-	/* Protocol */
+	/* Screen name column */
 	column = gtk_tree_view_column_new();
 	gtk_tree_view_column_set_title(column, _("Screenname"));
 	gtk_tree_view_insert_column(GTK_TREE_VIEW(treeview), column, -1);
 
-	/* Icon text */
+	/* Icon */
 	renderer = gtk_cell_renderer_pixbuf_new();
 	gtk_tree_view_column_pack_start(column, renderer, FALSE);
 	gtk_tree_view_column_add_attribute(column, renderer,
 					   "pixbuf", COLUMN_ICON);
 
-	/* Screennames */
+	/* Screen name */
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
 	gtk_tree_view_column_add_attribute(column, renderer,
@@ -1456,11 +1472,15 @@
 	if (pixbuf != NULL)
 		scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
 
+	gaim_debug(GAIM_DEBUG_MISC, "gtkaccount", "auto-login for %s: %d\n",
+			   gaim_account_get_username(account),
+			   gaim_account_get_auto_login(account, GAIM_GTK_UI));
+
 	gtk_list_store_set(store, iter,
 			COLUMN_ICON, scale,
 			COLUMN_SCREENNAME, gaim_account_get_username(account),
 			COLUMN_ONLINE, gaim_account_is_connected(account),
-			COLUMN_AUTOLOGIN, FALSE,
+			COLUMN_AUTOLOGIN, gaim_account_get_auto_login(account, GAIM_GTK_UI),
 			COLUMN_PROTOCOL, proto_name(gaim_account_get_protocol(account)),
 			COLUMN_DATA, account,
 			-1);
@@ -1542,9 +1562,9 @@
 	/* Setup DND. I wanna be an orc! */
 	gtk_tree_view_enable_model_drag_source(
 			GTK_TREE_VIEW(treeview), GDK_BUTTON1_MASK, gte,
-			2, GDK_ACTION_COPY);
+			1, GDK_ACTION_COPY);
 	gtk_tree_view_enable_model_drag_dest(
-			GTK_TREE_VIEW(treeview), gte, 2,
+			GTK_TREE_VIEW(treeview), gte, 1,
 			GDK_ACTION_COPY | GDK_ACTION_MOVE);
 
 	g_signal_connect(G_OBJECT(treeview), "drag-data-received",
--- a/src/ui.h	Fri Jun 06 21:46:16 2003 +0000
+++ b/src/ui.h	Sat Jun 07 00:30:09 2003 +0000
@@ -39,6 +39,13 @@
 #include "gtkutils.h"
 #include "stock.h"
 
+
+/**
+ * Our UI's identifier.
+ */
+#define GAIM_GTK_UI "gtk-gaim"
+
+
 #define GAIM_DIALOG(x)	x = gtk_window_new(GTK_WINDOW_TOPLEVEL); \
 			gtk_window_set_type_hint(GTK_WINDOW(x), GDK_WINDOW_TYPE_HINT_DIALOG)
 #define GAIM_WINDOW_ICONIFIED(x) (gdk_window_get_state(GTK_WIDGET(x)->window) & GDK_WINDOW_STATE_ICONIFIED)