# HG changeset patch # User Christian Hammond # Date 1054935887 0 # Node ID 1f786fb43ee61675ca3f829d89962a5cde500154 # Parent 147f4c25af154628896994ff24bbb4745253bf3d [gaim-migrate @ 6202] Added UI-specific account settings. committer: Tailor Script diff -r 147f4c25af15 -r 1f786fb43ee6 src/account.c --- a/src/account.c Fri Jun 06 16:53:22 2003 +0000 +++ b/src/account.c Fri Jun 06 21:44:47 2003 +0000 @@ -57,6 +57,8 @@ { GaimPrefType type; + char *ui; + union { int integer; @@ -79,6 +81,7 @@ GString *buffer; GaimPrefType setting_type; + char *setting_ui; char *setting_name; gboolean in_proxy; @@ -94,6 +97,9 @@ { GaimAccountSetting *setting = (GaimAccountSetting *)data; + if (setting->ui != NULL) + g_free(setting->ui); + if (setting->type == GAIM_PREF_STRING) g_free(setting->value.string); @@ -131,6 +137,9 @@ 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); + return account; } @@ -195,7 +204,7 @@ void gaim_account_set_password(GaimAccount *account, const char *password) { - g_return_if_fail(account != NULL); + g_return_if_fail(account != NULL); if (account->password != NULL) g_free(account->password); @@ -221,7 +230,7 @@ void gaim_account_set_user_info(GaimAccount *account, const char *user_info) { - g_return_if_fail(account != NULL); + g_return_if_fail(account != NULL); if (account->user_info != NULL) g_free(account->user_info); @@ -372,6 +381,69 @@ schedule_accounts_save(); } +void +gaim_account_set_ui_int(GaimAccount *account, const char *ui, + const char *name, int value) +{ + GaimAccountSetting *setting; + + g_return_if_fail(account != NULL); + g_return_if_fail(ui != NULL); + g_return_if_fail(name != NULL); + + setting = g_new0(GaimAccountSetting, 1); + + setting->type = GAIM_PREF_INT; + setting->ui = g_strdup(ui); + setting->value.integer = value; + + g_hash_table_insert(account->ui_settings, g_strdup(name), setting); + + schedule_accounts_save(); +} + +void +gaim_account_set_ui_string(GaimAccount *account, const char *ui, + const char *name, const char *value) +{ + GaimAccountSetting *setting; + + g_return_if_fail(account != NULL); + g_return_if_fail(ui != NULL); + g_return_if_fail(name != NULL); + + setting = g_new0(GaimAccountSetting, 1); + + setting->type = GAIM_PREF_STRING; + setting->ui = g_strdup(ui); + setting->value.string = g_strdup(value); + + g_hash_table_insert(account->ui_settings, g_strdup(name), setting); + + schedule_accounts_save(); +} + +void +gaim_account_set_ui_bool(GaimAccount *account, const char *ui, + const char *name, gboolean value) +{ + GaimAccountSetting *setting; + + g_return_if_fail(account != NULL); + g_return_if_fail(ui != NULL); + g_return_if_fail(name != NULL); + + setting = g_new0(GaimAccountSetting, 1); + + setting->type = GAIM_PREF_BOOLEAN; + setting->ui = g_strdup(ui); + setting->value.bool = value; + + g_hash_table_insert(account->ui_settings, g_strdup(name), setting); + + schedule_accounts_save(); +} + gboolean gaim_account_is_connected(const GaimAccount *account) { @@ -540,9 +612,18 @@ const gchar **attribute_values, gpointer user_data, GError **error) { + const char *value; AccountParserData *data = user_data; + GHashTable *atts; int i; + atts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + + for (i = 0; attribute_names[i] != NULL; i++) { + g_hash_table_insert(atts, g_strdup(attribute_names[i]), + g_strdup(attribute_values[i])); + } + if (data->buffer != NULL) { g_string_free(data->buffer, TRUE); data->buffer = NULL; @@ -571,22 +652,23 @@ data->tag = TAG_HOST; 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) + data->setting_ui = g_strdup(value); + } else if (!strcmp(element_name, "setting")) { data->tag = TAG_SETTING; - for (i = 0; attribute_names[i] != NULL; i++) { - - if (!strcmp(attribute_names[i], "name")) - data->setting_name = g_strdup(attribute_values[i]); - else if (!strcmp(attribute_names[i], "type")) { + if ((value = g_hash_table_lookup(atts, "name")) != NULL) + data->setting_name = g_strdup(value); - if (!strcmp(attribute_values[i], "string")) - data->setting_type = GAIM_PREF_STRING; - else if (!strcmp(attribute_values[i], "int")) - data->setting_type = GAIM_PREF_INT; - else if (!strcmp(attribute_values[i], "bool")) - data->setting_type = GAIM_PREF_BOOLEAN; - } + if ((value = g_hash_table_lookup(atts, "type")) != NULL) { + if (!strcmp(value, "string")) + data->setting_type = GAIM_PREF_STRING; + else if (!strcmp(value, "int")) + data->setting_type = GAIM_PREF_INT; + else if (!strcmp(value, "bool")) + data->setting_type = GAIM_PREF_BOOLEAN; } } } @@ -681,15 +763,29 @@ } } else if (data->tag == TAG_SETTING) { - if (data->setting_type == GAIM_PREF_STRING) - gaim_account_set_string(data->account, data->setting_name, - buffer); - else if (data->setting_type == GAIM_PREF_INT) - gaim_account_set_int(data->account, data->setting_name, - atoi(buffer)); - else if (data->setting_type == GAIM_PREF_BOOLEAN) - gaim_account_set_bool(data->account, data->setting_name, - (*buffer == '0' ? FALSE : TRUE)); + if (data->setting_ui != NULL) { + if (data->setting_type == GAIM_PREF_STRING) + gaim_account_set_ui_string(data->account, data->setting_ui, + data->setting_name, buffer); + else if (data->setting_type == GAIM_PREF_INT) + gaim_account_set_ui_int(data->account, data->setting_ui, + data->setting_name, atoi(buffer)); + else if (data->setting_type == GAIM_PREF_BOOLEAN) + gaim_account_set_ui_bool(data->account, data->setting_ui, + data->setting_name, + (*buffer == '0' ? FALSE : TRUE)); + } + else { + if (data->setting_type == GAIM_PREF_STRING) + gaim_account_set_string(data->account, data->setting_name, + buffer); + else if (data->setting_type == GAIM_PREF_INT) + gaim_account_set_int(data->account, data->setting_name, + atoi(buffer)); + else if (data->setting_type == GAIM_PREF_BOOLEAN) + gaim_account_set_bool(data->account, data->setting_name, + (*buffer == '0' ? FALSE : TRUE)); + } g_free(data->setting_name); data->setting_name = NULL; @@ -705,6 +801,12 @@ gaim_account_set_proxy_info(data->account, data->proxy_info); } } + else if (!strcmp(element_name, "settings")) { + if (data->setting_ui != NULL) { + g_free(data->setting_ui); + data->setting_ui = NULL; + } + } data->tag = TAG_NONE; diff -r 147f4c25af15 -r 1f786fb43ee6 src/account.h --- a/src/account.h Fri Jun 06 16:53:22 2003 +0000 +++ b/src/account.h Fri Jun 06 21:44:47 2003 +0000 @@ -47,6 +47,7 @@ GaimConnection *gc; /**< The connection handle. */ GHashTable *settings; /**< Protocol-specific settings. */ + GHashTable *ui_settings; /**< UI-specific settings. */ GaimProxyInfo *proxy_info; /**< Proxy information. */ @@ -204,6 +205,38 @@ void gaim_account_set_bool(GaimAccount *account, const char *name, gboolean value); +/** + * Sets a UI-specific integer setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param value The setting's value. + */ +void gaim_account_set_ui_int(GaimAccount *account, const char *ui, + const char *name, int value); + +/** + * Sets a UI-specific string setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param value The setting's value. + */ +void gaim_account_set_ui_string(GaimAccount *account, const char *ui, + const char *name, const char *string); + +/** + * Sets a UI-specific boolean setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param value The setting's value. + */ +void gaim_account_set_ui_bool(GaimAccount *account, const char *ui, + const char *name, gboolean value); /** * Returns whether or not the account is connected. @@ -342,6 +375,46 @@ gboolean default_value); /** + * Returns a UI-specific integer setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param default_value The default value. + * + * @return The value. + */ +int gaim_account_get_ui_int(const GaimAccount *account, const char *ui, + const char *name, int default_value); + +/** + * Returns a UI-specific string setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param default_value The default value. + * + * @return The value. + */ +const char *gaim_account_get_ui_string(const GaimAccount *account, + const char *ui, const char *name, + const char *default_value); + +/** + * Returns a UI-specific boolean setting for an account. + * + * @param account The account. + * @param ui The UI name. + * @param name The name of the setting. + * @param default_value The default value. + * + * @return The value. + */ +gboolean gaim_account_get_ui_bool(const GaimAccount *account, const char *ui, + const char *name, gboolean default_value); + +/** * Loads the accounts. */ gboolean gaim_accounts_load();