Mercurial > pidgin
comparison src/account.c @ 5794:5e93fc46d1af
[gaim-migrate @ 6219]
Removed the __ prefix from static functions. I love them, but ANSI C
knocked on my door and threatened to sue, saying they own all rights to
them, so I was forced to remove them.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 07 Jun 2003 07:57:24 +0000 |
parents | d89cadcafbec |
children | dbed8c87f750 |
comparison
equal
deleted
inserted
replaced
5793:952710ac6635 | 5794:5e93fc46d1af |
---|---|
91 static GList *accounts = NULL; | 91 static GList *accounts = NULL; |
92 static guint accounts_save_timer = 0; | 92 static guint accounts_save_timer = 0; |
93 static gboolean accounts_loaded = FALSE; | 93 static gboolean accounts_loaded = FALSE; |
94 | 94 |
95 static void | 95 static void |
96 __delete_setting(void *data) | 96 delete_setting(void *data) |
97 { | 97 { |
98 GaimAccountSetting *setting = (GaimAccountSetting *)data; | 98 GaimAccountSetting *setting = (GaimAccountSetting *)data; |
99 | 99 |
100 if (setting->ui != NULL) | 100 if (setting->ui != NULL) |
101 g_free(setting->ui); | 101 g_free(setting->ui); |
105 | 105 |
106 g_free(setting); | 106 g_free(setting); |
107 } | 107 } |
108 | 108 |
109 static gboolean | 109 static gboolean |
110 __accounts_save_cb(gpointer unused) | 110 accounts_save_cb(gpointer unused) |
111 { | 111 { |
112 gaim_accounts_sync(); | 112 gaim_accounts_sync(); |
113 accounts_save_timer = 0; | 113 accounts_save_timer = 0; |
114 | 114 |
115 return FALSE; | 115 return FALSE; |
117 | 117 |
118 static void | 118 static void |
119 schedule_accounts_save() | 119 schedule_accounts_save() |
120 { | 120 { |
121 if (!accounts_save_timer) | 121 if (!accounts_save_timer) |
122 accounts_save_timer = g_timeout_add(5000, __accounts_save_cb, NULL); | 122 accounts_save_timer = g_timeout_add(5000, accounts_save_cb, NULL); |
123 } | 123 } |
124 | 124 |
125 GaimAccount * | 125 GaimAccount * |
126 gaim_account_new(const char *username, GaimProtocol protocol) | 126 gaim_account_new(const char *username, GaimProtocol protocol) |
127 { | 127 { |
133 | 133 |
134 gaim_account_set_username(account, username); | 134 gaim_account_set_username(account, username); |
135 gaim_account_set_protocol(account, protocol); | 135 gaim_account_set_protocol(account, protocol); |
136 | 136 |
137 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, | 137 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
138 g_free, __delete_setting); | 138 g_free, delete_setting); |
139 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, | 139 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
140 g_free, (GDestroyNotify)g_hash_table_destroy); | 140 g_free, (GDestroyNotify)g_hash_table_destroy); |
141 | 141 |
142 return account; | 142 return account; |
143 } | 143 } |
331 g_return_if_fail(account != NULL); | 331 g_return_if_fail(account != NULL); |
332 | 332 |
333 g_hash_table_destroy(account->settings); | 333 g_hash_table_destroy(account->settings); |
334 | 334 |
335 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, | 335 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
336 g_free, __delete_setting); | 336 g_free, delete_setting); |
337 } | 337 } |
338 | 338 |
339 void | 339 void |
340 gaim_account_set_int(GaimAccount *account, const char *name, int value) | 340 gaim_account_set_int(GaimAccount *account, const char *name, int value) |
341 { | 341 { |
390 | 390 |
391 schedule_accounts_save(); | 391 schedule_accounts_save(); |
392 } | 392 } |
393 | 393 |
394 static GHashTable * | 394 static GHashTable * |
395 _get_ui_settings_table(GaimAccount *account, const char *ui) | 395 get_ui_settings_table(GaimAccount *account, const char *ui) |
396 { | 396 { |
397 GHashTable *table; | 397 GHashTable *table; |
398 | 398 |
399 table = g_hash_table_lookup(account->ui_settings, ui); | 399 table = g_hash_table_lookup(account->ui_settings, ui); |
400 | 400 |
401 if (table == NULL) { | 401 if (table == NULL) { |
402 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | 402 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
403 __delete_setting); | 403 delete_setting); |
404 g_hash_table_insert(account->ui_settings, g_strdup(ui), table); | 404 g_hash_table_insert(account->ui_settings, g_strdup(ui), table); |
405 } | 405 } |
406 | 406 |
407 return table; | 407 return table; |
408 } | 408 } |
422 | 422 |
423 setting->type = GAIM_PREF_INT; | 423 setting->type = GAIM_PREF_INT; |
424 setting->ui = g_strdup(ui); | 424 setting->ui = g_strdup(ui); |
425 setting->value.integer = value; | 425 setting->value.integer = value; |
426 | 426 |
427 table = _get_ui_settings_table(account, ui); | 427 table = get_ui_settings_table(account, ui); |
428 | 428 |
429 g_hash_table_insert(table, g_strdup(name), setting); | 429 g_hash_table_insert(table, g_strdup(name), setting); |
430 | 430 |
431 schedule_accounts_save(); | 431 schedule_accounts_save(); |
432 } | 432 } |
446 | 446 |
447 setting->type = GAIM_PREF_STRING; | 447 setting->type = GAIM_PREF_STRING; |
448 setting->ui = g_strdup(ui); | 448 setting->ui = g_strdup(ui); |
449 setting->value.string = g_strdup(value); | 449 setting->value.string = g_strdup(value); |
450 | 450 |
451 table = _get_ui_settings_table(account, ui); | 451 table = get_ui_settings_table(account, ui); |
452 | 452 |
453 g_hash_table_insert(table, g_strdup(name), setting); | 453 g_hash_table_insert(table, g_strdup(name), setting); |
454 | 454 |
455 schedule_accounts_save(); | 455 schedule_accounts_save(); |
456 } | 456 } |
470 | 470 |
471 setting->type = GAIM_PREF_BOOLEAN; | 471 setting->type = GAIM_PREF_BOOLEAN; |
472 setting->ui = g_strdup(ui); | 472 setting->ui = g_strdup(ui); |
473 setting->value.bool = value; | 473 setting->value.bool = value; |
474 | 474 |
475 table = _get_ui_settings_table(account, ui); | 475 table = get_ui_settings_table(account, ui); |
476 | 476 |
477 g_hash_table_insert(table, g_strdup(name), setting); | 477 g_hash_table_insert(table, g_strdup(name), setting); |
478 | 478 |
479 schedule_accounts_save(); | 479 schedule_accounts_save(); |
480 } | 480 } |
700 return setting->value.bool; | 700 return setting->value.bool; |
701 } | 701 } |
702 | 702 |
703 /* XML Stuff */ | 703 /* XML Stuff */ |
704 static void | 704 static void |
705 __free_parser_data(gpointer user_data) | 705 free_parser_data(gpointer user_data) |
706 { | 706 { |
707 AccountParserData *data = user_data; | 707 AccountParserData *data = user_data; |
708 | 708 |
709 if (data->buffer != NULL) | 709 if (data->buffer != NULL) |
710 g_free(data->buffer); | 710 g_free(data->buffer); |
714 | 714 |
715 g_free(data); | 715 g_free(data); |
716 } | 716 } |
717 | 717 |
718 static void | 718 static void |
719 __start_element_handler(GMarkupParseContext *context, | 719 start_element_handler(GMarkupParseContext *context, |
720 const gchar *element_name, | 720 const gchar *element_name, |
721 const gchar **attribute_names, | 721 const gchar **attribute_names, |
722 const gchar **attribute_values, | 722 const gchar **attribute_values, |
723 gpointer user_data, GError **error) | 723 gpointer user_data, GError **error) |
724 { | 724 { |
725 const char *value; | 725 const char *value; |
726 AccountParserData *data = user_data; | 726 AccountParserData *data = user_data; |
727 GHashTable *atts; | 727 GHashTable *atts; |
728 int i; | 728 int i; |
783 } | 783 } |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 static void | 787 static void |
788 __end_element_handler(GMarkupParseContext *context, const gchar *element_name, | 788 end_element_handler(GMarkupParseContext *context, const gchar *element_name, |
789 gpointer user_data, GError **error) | 789 gpointer user_data, GError **error) |
790 { | 790 { |
791 AccountParserData *data = user_data; | 791 AccountParserData *data = user_data; |
792 gchar *buffer; | 792 gchar *buffer; |
793 | 793 |
794 if (data->buffer == NULL) | 794 if (data->buffer == NULL) |
925 | 925 |
926 g_free(buffer); | 926 g_free(buffer); |
927 } | 927 } |
928 | 928 |
929 static void | 929 static void |
930 __text_handler(GMarkupParseContext *context, const gchar *text, | 930 text_handler(GMarkupParseContext *context, const gchar *text, |
931 gsize text_len, gpointer user_data, GError **error) | 931 gsize text_len, gpointer user_data, GError **error) |
932 { | 932 { |
933 AccountParserData *data = user_data; | 933 AccountParserData *data = user_data; |
934 | 934 |
935 if (data->buffer == NULL) | 935 if (data->buffer == NULL) |
936 data->buffer = g_string_new_len(text, text_len); | 936 data->buffer = g_string_new_len(text, text_len); |
938 g_string_append_len(data->buffer, text, text_len); | 938 g_string_append_len(data->buffer, text, text_len); |
939 } | 939 } |
940 | 940 |
941 static GMarkupParser accounts_parser = | 941 static GMarkupParser accounts_parser = |
942 { | 942 { |
943 __start_element_handler, | 943 start_element_handler, |
944 __end_element_handler, | 944 end_element_handler, |
945 __text_handler, | 945 text_handler, |
946 NULL, | 946 NULL, |
947 NULL | 947 NULL |
948 }; | 948 }; |
949 | 949 |
950 gboolean | 950 gboolean |
973 } | 973 } |
974 | 974 |
975 parser_data = g_new0(AccountParserData, 1); | 975 parser_data = g_new0(AccountParserData, 1); |
976 | 976 |
977 context = g_markup_parse_context_new(&accounts_parser, 0, | 977 context = g_markup_parse_context_new(&accounts_parser, 0, |
978 parser_data, __free_parser_data); | 978 parser_data, free_parser_data); |
979 | 979 |
980 if (!g_markup_parse_context_parse(context, contents, length, NULL)) { | 980 if (!g_markup_parse_context_parse(context, contents, length, NULL)) { |
981 g_markup_parse_context_free(context); | 981 g_markup_parse_context_free(context); |
982 g_free(contents); | 982 g_free(contents); |
983 | 983 |
1006 | 1006 |
1007 return TRUE; | 1007 return TRUE; |
1008 } | 1008 } |
1009 | 1009 |
1010 static void | 1010 static void |
1011 _write_setting(gpointer key, gpointer value, gpointer user_data) | 1011 write_setting(gpointer key, gpointer value, gpointer user_data) |
1012 { | 1012 { |
1013 GaimAccountSetting *setting; | 1013 GaimAccountSetting *setting; |
1014 const char *name; | 1014 const char *name; |
1015 FILE *fp; | 1015 FILE *fp; |
1016 | 1016 |
1031 name, setting->value.bool); | 1031 name, setting->value.bool); |
1032 } | 1032 } |
1033 } | 1033 } |
1034 | 1034 |
1035 static void | 1035 static void |
1036 _write_ui_setting_list(gpointer key, gpointer value, gpointer user_data) | 1036 write_ui_setting_list(gpointer key, gpointer value, gpointer user_data) |
1037 { | 1037 { |
1038 GHashTable *table; | 1038 GHashTable *table; |
1039 const char *ui; | 1039 const char *ui; |
1040 FILE *fp; | 1040 FILE *fp; |
1041 | 1041 |
1042 table = (GHashTable *)value; | 1042 table = (GHashTable *)value; |
1043 ui = (const char *)key; | 1043 ui = (const char *)key; |
1044 fp = (FILE *)user_data; | 1044 fp = (FILE *)user_data; |
1045 | 1045 |
1046 fprintf(fp, " <settings ui='%s'>\n", ui); | 1046 fprintf(fp, " <settings ui='%s'>\n", ui); |
1047 g_hash_table_foreach(table, _write_setting, fp); | 1047 g_hash_table_foreach(table, write_setting, fp); |
1048 fprintf(fp, " </settings>\n"); | 1048 fprintf(fp, " </settings>\n"); |
1049 } | 1049 } |
1050 | 1050 |
1051 static void | 1051 static void |
1052 gaim_accounts_write(FILE *fp, GaimAccount *account) | 1052 gaim_accounts_write(FILE *fp, GaimAccount *account) |
1086 fprintf(fp, " <buddyicon>%s</buddyicon>\n", esc); | 1086 fprintf(fp, " <buddyicon>%s</buddyicon>\n", esc); |
1087 g_free(esc); | 1087 g_free(esc); |
1088 } | 1088 } |
1089 | 1089 |
1090 fprintf(fp, " <settings>\n"); | 1090 fprintf(fp, " <settings>\n"); |
1091 g_hash_table_foreach(account->settings, _write_setting, fp); | 1091 g_hash_table_foreach(account->settings, write_setting, fp); |
1092 fprintf(fp, " </settings>\n"); | 1092 fprintf(fp, " </settings>\n"); |
1093 | 1093 |
1094 g_hash_table_foreach(account->ui_settings, _write_ui_setting_list, fp); | 1094 g_hash_table_foreach(account->ui_settings, write_ui_setting_list, fp); |
1095 | 1095 |
1096 if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL && | 1096 if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL && |
1097 (proxy_type = gaim_proxy_info_get_type(proxy_info)) != GAIM_PROXY_NONE) | 1097 (proxy_type = gaim_proxy_info_get_type(proxy_info)) != GAIM_PROXY_NONE) |
1098 { | 1098 { |
1099 const char *value; | 1099 const char *value; |