Mercurial > pidgin-twitter
comparison pidgin-twitter.c @ 95:ab612180e7d0
- added identica support. linkfy and character counter work. icon support has not implemented yet.
- put common code together.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 10 Jul 2008 00:12:03 +0900 |
parents | 31cddb2c2acc |
children | 987607b5ba32 |
comparison
equal
deleted
inserted
replaced
94:31cddb2c2acc | 95:ab612180e7d0 |
---|---|
23 /* globals */ | 23 /* globals */ |
24 static GRegex *regp[7]; | 24 static GRegex *regp[7]; |
25 static gboolean suppress_oops = FALSE; | 25 static gboolean suppress_oops = FALSE; |
26 static GHashTable *icon_data_by_user = NULL; | 26 static GHashTable *icon_data_by_user = NULL; |
27 static GHashTable *icon_data_by_user2 = NULL; | 27 static GHashTable *icon_data_by_user2 = NULL; |
28 static GHashTable *icon_data_by_user3 = NULL; | |
28 static GHashTable *conv_hash = NULL; | 29 static GHashTable *conv_hash = NULL; |
29 | 30 |
30 #define WASSR_POST_LEN (255 * 4) | 31 #define WASSR_POST_LEN (255 * 4) |
31 static gchar *wassr_post = NULL; | 32 static gchar *wassr_post = NULL; |
32 | 33 |
38 } icon_data; | 39 } icon_data; |
39 | 40 |
40 enum { | 41 enum { |
41 unknown_service = 0, | 42 unknown_service = 0, |
42 twitter_service, | 43 twitter_service, |
43 wassr_service | 44 wassr_service, |
45 identica_service | |
44 }; | 46 }; |
45 | 47 |
46 typedef struct _eval_data { | 48 typedef struct _eval_data { |
47 gint which; | 49 gint which; |
48 gint service; | 50 gint service; |
509 | 511 |
510 twitter_debug("which = %d service = %d\n", which, service); | 512 twitter_debug("which = %d service = %d\n", which, service); |
511 | 513 |
512 if(which == RECIPIENT) { | 514 if(which == RECIPIENT) { |
513 gchar *match = g_match_info_fetch(match_info, 1); | 515 gchar *match = g_match_info_fetch(match_info, 1); |
514 | 516 const gchar *format = NULL; |
515 switch(service) { | 517 switch(service) { |
516 case twitter_service: | 518 case twitter_service: |
517 snprintf(sub, 128, RECIPIENT_FORMAT, match, match); | 519 format = RECIPIENT_FORMAT_TWITTER; |
518 break; | 520 break; |
519 case wassr_service: | 521 case wassr_service: |
520 snprintf(sub, 128, RECIPIENT_FORMAT_WASSR, match, match); | 522 format = RECIPIENT_FORMAT_WASSR; |
523 break; | |
524 case identica_service: | |
525 format = RECIPIENT_FORMAT_IDENTICA; | |
521 break; | 526 break; |
522 default: | 527 default: |
523 twitter_debug("unknown service\n"); | 528 twitter_debug("unknown service\n"); |
524 break; | 529 break; |
525 } | 530 } |
526 | 531 snprintf(sub, 128, format, match, match); |
527 g_free(match); | 532 g_free(match); |
528 } | 533 } |
529 else if(which == SENDER) { | 534 else if(which == SENDER) { |
530 gchar *match1 = g_match_info_fetch(match_info, 1); //preceding CR|LF | 535 gchar *match1 = g_match_info_fetch(match_info, 1); //preceding CR|LF |
531 gchar *match2 = g_match_info_fetch(match_info, 2); //sender | 536 gchar *match2 = g_match_info_fetch(match_info, 2); //sender |
537 const gchar *format = NULL; | |
532 | 538 |
533 switch(service) { | 539 switch(service) { |
534 case twitter_service: | 540 case twitter_service: |
535 snprintf(sub, 128, SENDER_FORMAT, match1 ? match1: "", | 541 format = SENDER_FORMAT_TWITTER; |
536 match2, match2); | |
537 break; | 542 break; |
538 case wassr_service: | 543 case wassr_service: |
539 snprintf(sub, 128, SENDER_FORMAT_WASSR, match1 ? match1: "", | 544 format = SENDER_FORMAT_WASSR; |
540 match2, match2); | 545 break; |
546 case identica_service: | |
547 format = SENDER_FORMAT_IDENTICA; | |
541 break; | 548 break; |
542 default: | 549 default: |
543 twitter_debug("unknown service\n"); | 550 twitter_debug("unknown service\n"); |
544 break; | 551 break; |
545 } | 552 } |
553 | |
554 snprintf(sub, 128, format, match1 ? match1: "", match2, match2); | |
546 | 555 |
547 g_free(match1); | 556 g_free(match1); |
548 g_free(match2); | 557 g_free(match2); |
549 } | 558 } |
550 | 559 |
693 count = gtk_text_buffer_get_char_count(textbuffer) + | 702 count = gtk_text_buffer_get_char_count(textbuffer) + |
694 (unsigned int)g_utf8_strlen(new_text, -1); | 703 (unsigned int)g_utf8_strlen(new_text, -1); |
695 | 704 |
696 switch(service) { | 705 switch(service) { |
697 case twitter_service: | 706 case twitter_service: |
707 case identica_service: | |
698 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", | 708 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", |
699 count <= 140 ? "black" : "red", count); | 709 count <= 140 ? "black" : "red", count); |
700 break; | 710 break; |
701 case wassr_service: | 711 case wassr_service: |
702 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", | 712 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", |
731 (gtk_text_iter_get_offset(end_pos) - | 741 (gtk_text_iter_get_offset(end_pos) - |
732 gtk_text_iter_get_offset(start_pos)); | 742 gtk_text_iter_get_offset(start_pos)); |
733 | 743 |
734 switch(service) { | 744 switch(service) { |
735 case twitter_service: | 745 case twitter_service: |
746 case identica_service: | |
736 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", | 747 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", |
737 count <= 140 ? "black" : "red", count); | 748 count <= 140 ? "black" : "red", count); |
738 break; | 749 break; |
739 case wassr_service: | 750 case wassr_service: |
740 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", | 751 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", |
764 PurpleConversation *conv = | 775 PurpleConversation *conv = |
765 pidgin_conv_window_get_active_conversation(win); | 776 pidgin_conv_window_get_active_conversation(win); |
766 gint service = get_service_type(conv); | 777 gint service = get_service_type(conv); |
767 switch(service) { | 778 switch(service) { |
768 case twitter_service: | 779 case twitter_service: |
769 detach_from_conv(conv, NULL); | |
770 break; | |
771 case wassr_service: | 780 case wassr_service: |
781 case identica_service: | |
772 detach_from_conv(conv, NULL); | 782 detach_from_conv(conv, NULL); |
773 break; | 783 break; |
774 default: | 784 default: |
775 twitter_debug("unknown service\n"); | 785 twitter_debug("unknown service\n"); |
776 break; | 786 break; |
872 gint service = get_service_type(conv); | 882 gint service = get_service_type(conv); |
873 /* only attach to twitter conversation window */ | 883 /* only attach to twitter conversation window */ |
874 switch(service) { | 884 switch(service) { |
875 case twitter_service: | 885 case twitter_service: |
876 case wassr_service: | 886 case wassr_service: |
887 case identica_service: | |
877 attach_to_conv(conv, NULL); | 888 attach_to_conv(conv, NULL); |
878 break; | 889 break; |
879 default: | 890 default: |
880 twitter_debug("unknown service\n"); | 891 twitter_debug("unknown service\n"); |
881 break; | 892 break; |
948 { | 959 { |
949 const gchar *proto = purple_account_get_protocol_id(account); | 960 const gchar *proto = purple_account_get_protocol_id(account); |
950 | 961 |
951 twitter_debug("name = %s proto = %s\n", name, proto); | 962 twitter_debug("name = %s proto = %s\n", name, proto); |
952 | 963 |
953 if(!strcmp(name, "twitter@twitter.com") && | 964 if(g_strstr_len(name, 19, "twitter@twitter.com") && |
954 !strcmp(proto, "prpl-jabber")) { | 965 g_strstr_len(proto, 11, "prpl-jabber")) { |
955 return TRUE; | 966 return TRUE; |
956 } | 967 } |
957 | 968 |
958 return FALSE; | 969 return FALSE; |
959 } | 970 } |
972 { | 983 { |
973 const gchar *proto = purple_account_get_protocol_id(account); | 984 const gchar *proto = purple_account_get_protocol_id(account); |
974 | 985 |
975 twitter_debug("name = %s proto = %s\n", name, proto); | 986 twitter_debug("name = %s proto = %s\n", name, proto); |
976 | 987 |
977 if(strstr(name, "wassr-bot@wassr.jp") && | 988 if(g_strstr_len(name, 18, "wassr-bot@wassr.jp") && |
978 !strcmp(proto, "prpl-jabber")) { | 989 g_strstr_len(proto, 11, "prpl-jabber")) { |
979 return TRUE; | 990 return TRUE; |
980 } | 991 } |
981 | 992 |
982 return FALSE; | 993 return FALSE; |
983 } | 994 } |
987 { | 998 { |
988 const char *name = purple_conversation_get_name(conv); | 999 const char *name = purple_conversation_get_name(conv); |
989 PurpleAccount *account = purple_conversation_get_account(conv); | 1000 PurpleAccount *account = purple_conversation_get_account(conv); |
990 | 1001 |
991 return is_wassr_account(account, name); | 1002 return is_wassr_account(account, name); |
1003 } | |
1004 | |
1005 static gboolean | |
1006 is_identica_account(PurpleAccount *account, const char *name) | |
1007 { | |
1008 const gchar *proto = purple_account_get_protocol_id(account); | |
1009 | |
1010 twitter_debug("name = %s proto = %s\n", name, proto); | |
1011 | |
1012 if(g_strstr_len(name, 16, "update@identi.ca") && | |
1013 g_strstr_len(proto, 11, "prpl-jabber")) { | |
1014 return TRUE; | |
1015 } | |
1016 | |
1017 return FALSE; | |
1018 } | |
1019 | |
1020 static gboolean | |
1021 is_identica_conv(PurpleConversation *conv) | |
1022 { | |
1023 const char *name = purple_conversation_get_name(conv); | |
1024 PurpleAccount *account = purple_conversation_get_account(conv); | |
1025 | |
1026 return is_identica_account(account, name); | |
992 } | 1027 } |
993 | 1028 |
994 static gint | 1029 static gint |
995 get_service_type(PurpleConversation *conv) | 1030 get_service_type(PurpleConversation *conv) |
996 { | 1031 { |
1000 | 1035 |
1001 if(is_twitter_conv(conv)) | 1036 if(is_twitter_conv(conv)) |
1002 service = twitter_service; | 1037 service = twitter_service; |
1003 else if(is_wassr_conv(conv)) | 1038 else if(is_wassr_conv(conv)) |
1004 service = wassr_service; | 1039 service = wassr_service; |
1040 else if(is_identica_conv(conv)) | |
1041 service = identica_service; | |
1005 | 1042 |
1006 return service; | 1043 return service; |
1007 } | 1044 } |
1008 | 1045 |
1009 static void | 1046 static void |
1015 gint service = get_service_type(conv); | 1052 gint service = get_service_type(conv); |
1016 /* only attach to twitter conversation window */ | 1053 /* only attach to twitter conversation window */ |
1017 switch(service) { | 1054 switch(service) { |
1018 case twitter_service: | 1055 case twitter_service: |
1019 case wassr_service: | 1056 case wassr_service: |
1057 case identica_service: | |
1020 attach_to_conv(conv, NULL); | 1058 attach_to_conv(conv, NULL); |
1021 break; | 1059 break; |
1022 default: | 1060 default: |
1023 twitter_debug("unknown service\n"); | 1061 twitter_debug("unknown service\n"); |
1024 break; | 1062 break; |
1027 | 1065 |
1028 static void | 1066 static void |
1029 deleting_conv_cb(PurpleConversation *conv) | 1067 deleting_conv_cb(PurpleConversation *conv) |
1030 { | 1068 { |
1031 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); | 1069 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); |
1070 | |
1032 g_return_if_fail(gtkconv != NULL); | 1071 g_return_if_fail(gtkconv != NULL); |
1033 | 1072 |
1034 gint service = get_service_type(conv); | 1073 gint service = get_service_type(conv); |
1074 GHashTable *hash = NULL; | |
1075 | |
1035 /* only attach to twitter conversation window */ | 1076 /* only attach to twitter conversation window */ |
1036 switch(service) { | 1077 switch(service) { |
1037 case twitter_service: | 1078 case twitter_service: |
1038 delete_requested_icon_marks(gtkconv, icon_data_by_user); | 1079 hash = icon_data_by_user; |
1039 break; | 1080 break; |
1040 case wassr_service: | 1081 case wassr_service: |
1041 delete_requested_icon_marks(gtkconv, icon_data_by_user2); | 1082 hash = icon_data_by_user2; |
1083 break; | |
1084 case identica_service: | |
1085 hash = icon_data_by_user3; | |
1042 break; | 1086 break; |
1043 default: | 1087 default: |
1044 twitter_debug("unknown service\n"); | 1088 twitter_debug("unknown service\n"); |
1045 break; | 1089 break; |
1046 } | 1090 } |
1091 | |
1092 if(hash) | |
1093 delete_requested_icon_marks(gtkconv, hash); | |
1047 } | 1094 } |
1048 | 1095 |
1049 static gboolean | 1096 static gboolean |
1050 receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, | 1097 receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, |
1051 PurpleConversation *conv, PurpleMessageFlags *flags, void *data) | 1098 PurpleConversation *conv, PurpleMessageFlags *flags, void *data) |
1106 GtkIMHtml *target_imhtml = NULL; | 1153 GtkIMHtml *target_imhtml = NULL; |
1107 GtkTextBuffer *target_buffer = NULL; | 1154 GtkTextBuffer *target_buffer = NULL; |
1108 GtkTextIter insertion_point; | 1155 GtkTextIter insertion_point; |
1109 gint icon_id; | 1156 gint icon_id; |
1110 icon_data *data = NULL; | 1157 icon_data *data = NULL; |
1158 GHashTable *hash = NULL; | |
1111 | 1159 |
1112 twitter_debug("called: service = %d\n", service); | 1160 twitter_debug("called: service = %d\n", service); |
1113 | 1161 |
1114 /* find the conversation that contains the mark */ | 1162 /* find the conversation that contains the mark */ |
1115 for(win_list = pidgin_conv_windows_get_list(); win_list; | 1163 for(win_list = pidgin_conv_windows_get_list(); win_list; |
1147 &insertion_point, requested_mark); | 1195 &insertion_point, requested_mark); |
1148 | 1196 |
1149 /* insert icon */ | 1197 /* insert icon */ |
1150 switch(service) { | 1198 switch(service) { |
1151 case twitter_service: | 1199 case twitter_service: |
1152 data = (icon_data *)g_hash_table_lookup(icon_data_by_user, user_name); | 1200 hash = icon_data_by_user; |
1153 break; | 1201 break; |
1154 case wassr_service: | 1202 case wassr_service: |
1155 data = (icon_data *)g_hash_table_lookup(icon_data_by_user2, user_name); | 1203 hash = icon_data_by_user2; |
1204 break; | |
1205 case identica_service: | |
1206 hash = icon_data_by_user3; | |
1156 break; | 1207 break; |
1157 default: | 1208 default: |
1158 twitter_debug("unknown service\n"); | 1209 twitter_debug("unknown service\n"); |
1159 } | 1210 } |
1211 | |
1212 if(hash) | |
1213 data = (icon_data *)g_hash_table_lookup(hash, user_name); | |
1160 | 1214 |
1161 if(data) | 1215 if(data) |
1162 icon_id = data->icon_id; | 1216 icon_id = data->icon_id; |
1163 else | 1217 else |
1164 icon_id = 0; | 1218 icon_id = 0; |
1176 static void | 1230 static void |
1177 insert_requested_icon(const gchar *user_name, gint service) | 1231 insert_requested_icon(const gchar *user_name, gint service) |
1178 { | 1232 { |
1179 icon_data *data = NULL; | 1233 icon_data *data = NULL; |
1180 GList *mark_list = NULL; | 1234 GList *mark_list = NULL; |
1235 GHashTable *hash = NULL; | |
1236 | |
1237 twitter_debug("called\n"); | |
1181 | 1238 |
1182 switch(service) { | 1239 switch(service) { |
1183 case twitter_service: | 1240 case twitter_service: |
1184 data = (icon_data *)g_hash_table_lookup(icon_data_by_user, user_name); | 1241 hash = icon_data_by_user; |
1185 break; | 1242 break; |
1186 case wassr_service: | 1243 case wassr_service: |
1187 data = (icon_data *)g_hash_table_lookup(icon_data_by_user2, user_name); | 1244 hash = icon_data_by_user2; |
1245 break; | |
1246 case identica_service: | |
1247 hash = icon_data_by_user3; | |
1188 break; | 1248 break; |
1189 default: | 1249 default: |
1190 twitter_debug("unknown service\n"); | 1250 twitter_debug("unknown service\n"); |
1191 break; | 1251 break; |
1192 } | 1252 } |
1253 | |
1254 if(hash) | |
1255 data = (icon_data *)g_hash_table_lookup(hash, user_name); | |
1193 | 1256 |
1194 if(!data) | 1257 if(!data) |
1195 return; | 1258 return; |
1196 | 1259 |
1197 mark_list = data->request_list; | 1260 mark_list = data->request_list; |
1198 | 1261 |
1199 got_icon_data *gotdata = g_new0(got_icon_data, 1); | 1262 got_icon_data *gotdata = g_new0(got_icon_data, 1); |
1200 gotdata->user_name = g_strdup(user_name); | 1263 gotdata->user_name = g_strdup(user_name); |
1201 gotdata->service = service; | 1264 gotdata->service = service; |
1265 | |
1266 twitter_debug("about to insert icon\n"); | |
1202 | 1267 |
1203 if(mark_list) { | 1268 if(mark_list) { |
1204 g_list_foreach(mark_list, (GFunc) insert_icon_at_mark, gotdata); | 1269 g_list_foreach(mark_list, (GFunc) insert_icon_at_mark, gotdata); |
1205 mark_list = g_list_remove_all(mark_list, NULL); | 1270 mark_list = g_list_remove_all(mark_list, NULL); |
1206 g_list_free(mark_list); | 1271 g_list_free(mark_list); |
1218 gchar *user_name = gotdata->user_name; | 1283 gchar *user_name = gotdata->user_name; |
1219 gint service = gotdata->service; | 1284 gint service = gotdata->service; |
1220 | 1285 |
1221 gint icon_id; | 1286 gint icon_id; |
1222 icon_data *data = NULL; | 1287 icon_data *data = NULL; |
1288 GHashTable *hash = NULL; | |
1223 | 1289 |
1224 twitter_debug("called: service = %d\n", service); | 1290 twitter_debug("called: service = %d\n", service); |
1225 | 1291 |
1226 switch(service) { | 1292 switch(service) { |
1227 case twitter_service: | 1293 case twitter_service: |
1228 data = (icon_data *)g_hash_table_lookup(icon_data_by_user, user_name); | 1294 hash = icon_data_by_user; |
1229 break; | 1295 break; |
1230 case wassr_service: | 1296 case wassr_service: |
1231 data = (icon_data *)g_hash_table_lookup(icon_data_by_user2, user_name); | 1297 hash = icon_data_by_user2; |
1298 break; | |
1299 case identica_service: | |
1300 hash = icon_data_by_user3; | |
1232 break; | 1301 break; |
1233 default: | 1302 default: |
1234 twitter_debug("unknown service\n"); | 1303 twitter_debug("unknown service\n"); |
1235 } | 1304 } |
1305 | |
1306 if(hash) | |
1307 data = (icon_data *)g_hash_table_lookup(hash, user_name); | |
1236 | 1308 |
1237 /* return if download failed */ | 1309 /* return if download failed */ |
1238 if(!url_text) { | 1310 if(!url_text) { |
1239 twitter_debug("downloading %s's icon failed : %s\n", | 1311 twitter_debug("downloading %s's icon failed : %s\n", |
1240 user_name, error_message); | 1312 user_name, error_message); |
1267 data = g_new0(icon_data, 1); | 1339 data = g_new0(icon_data, 1); |
1268 } | 1340 } |
1269 | 1341 |
1270 data->icon_id = icon_id; | 1342 data->icon_id = icon_id; |
1271 | 1343 |
1272 switch(service) { | 1344 if(hash) |
1273 case twitter_service: | 1345 g_hash_table_insert(hash, g_strdup(user_name), data); |
1274 g_hash_table_insert(icon_data_by_user, | |
1275 g_strdup(user_name), data); | |
1276 break; | |
1277 case wassr_service: | |
1278 g_hash_table_insert(icon_data_by_user2, | |
1279 g_strdup(user_name), data); | |
1280 break; | |
1281 default: | |
1282 twitter_debug("unknown service\n"); | |
1283 break; | |
1284 } | |
1285 | 1346 |
1286 const gchar *dirname = purple_prefs_get_string(OPT_ICON_DIR); | 1347 const gchar *dirname = purple_prefs_get_string(OPT_ICON_DIR); |
1287 | 1348 |
1288 /* store retrieved image to a file in icon dir */ | 1349 /* store retrieved image to a file in icon dir */ |
1289 if(ensure_path_exists(dirname)) { | 1350 if(ensure_path_exists(dirname)) { |
1291 gchar *path = NULL; | 1352 gchar *path = NULL; |
1292 FILE *fp = NULL; | 1353 FILE *fp = NULL; |
1293 | 1354 |
1294 switch(service) { | 1355 switch(service) { |
1295 case twitter_service: | 1356 case twitter_service: |
1296 filename = g_strdup_printf("%s.gif", user_name); | 1357 filename = g_strdup_printf("%s_twitter.gif", user_name); |
1297 break; | 1358 break; |
1298 case wassr_service: | 1359 case wassr_service: |
1299 filename = g_strdup_printf("%s_wassr.png", user_name); | 1360 filename = g_strdup_printf("%s_wassr.png", user_name); |
1361 break; | |
1362 case identica_service: | |
1363 filename = g_strdup_printf("%s_identica.png", user_name); | |
1300 break; | 1364 break; |
1301 default: | 1365 default: |
1302 twitter_debug("unknown service\n"); | 1366 twitter_debug("unknown service\n"); |
1303 break; | 1367 break; |
1304 } | 1368 } |
1333 | 1397 |
1334 /* look local icon cache for the requested icon */ | 1398 /* look local icon cache for the requested icon */ |
1335 gchar *filename = NULL; | 1399 gchar *filename = NULL; |
1336 gchar *path = NULL; | 1400 gchar *path = NULL; |
1337 icon_data *data = NULL; | 1401 icon_data *data = NULL; |
1402 GHashTable *hash = NULL; | |
1403 const gchar *suffix = NULL; | |
1338 | 1404 |
1339 switch(service) { | 1405 switch(service) { |
1340 case twitter_service: | 1406 case twitter_service: |
1341 data = (icon_data *)g_hash_table_lookup(icon_data_by_user, user_name); | 1407 hash = icon_data_by_user; |
1408 suffix = "twitter"; | |
1342 break; | 1409 break; |
1343 case wassr_service: | 1410 case wassr_service: |
1344 data = (icon_data *)g_hash_table_lookup(icon_data_by_user2, user_name); | 1411 hash = icon_data_by_user2; |
1412 suffix = "wassr"; | |
1413 break; | |
1414 case identica_service: | |
1415 suffix = "identica"; | |
1416 hash = icon_data_by_user3; | |
1345 break; | 1417 break; |
1346 default: | 1418 default: |
1347 twitter_debug("unknown service\n"); | 1419 twitter_debug("unknown service\n"); |
1420 break; | |
1421 } | |
1422 | |
1423 if(!hash) | |
1348 return; | 1424 return; |
1349 break; | 1425 |
1350 } | 1426 /* since this function is called after mark_icon_for_user(), data |
1351 | 1427 * must exist here. */ |
1352 if(!data) { | 1428 data = (icon_data *)g_hash_table_lookup(hash, user_name); |
1353 data = g_new0(icon_data, 1); | 1429 g_hash_table_insert(hash, g_strdup(user_name), data); |
1354 switch(service) { | |
1355 case twitter_service: | |
1356 g_hash_table_insert(icon_data_by_user, | |
1357 g_strdup(user_name), data); | |
1358 break; | |
1359 case wassr_service: | |
1360 g_hash_table_insert(icon_data_by_user2, | |
1361 g_strdup(user_name), data); | |
1362 break; | |
1363 default: | |
1364 twitter_debug("unknown service\n"); | |
1365 return; | |
1366 break; | |
1367 } | |
1368 } | |
1369 | 1430 |
1370 /* if img has been registerd, just return */ | 1431 /* if img has been registerd, just return */ |
1371 if(data->icon_id) | 1432 if(data->icon_id > 0) |
1372 return; | 1433 return; |
1373 | 1434 |
1374 /* check if saved file exists */ | 1435 /* check if saved file exists */ |
1375 switch(service) { | 1436 if(suffix) { |
1376 case twitter_service: | 1437 filename = g_strdup_printf("%s_%s.gif", user_name, suffix); |
1377 filename = g_strdup_printf("%s.gif", user_name); | |
1378 path = g_build_filename( | 1438 path = g_build_filename( |
1379 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); | 1439 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); |
1380 | 1440 |
1381 if(!g_file_test(path, G_FILE_TEST_EXISTS)) { | 1441 if(!g_file_test(path, G_FILE_TEST_EXISTS)) { |
1382 g_free(path); | 1442 g_free(path); |
1383 filename = g_strdup_printf("%s.png", user_name); | 1443 filename = g_strdup_printf("%s_%s.png", user_name, suffix); |
1384 path = g_build_filename( | 1444 path = g_build_filename( |
1385 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); | 1445 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); |
1386 } | 1446 } |
1387 break; | 1447 } |
1388 case wassr_service: | 1448 |
1389 filename = g_strdup_printf("%s_wassr.gif", user_name); | 1449 twitter_debug("path = %s\n", path); |
1390 path = g_build_filename( | |
1391 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); | |
1392 | |
1393 if(!g_file_test(path, G_FILE_TEST_EXISTS)) { | |
1394 g_free(path); | |
1395 filename = g_strdup_printf("%s_wassr.png", user_name); | |
1396 path = g_build_filename( | |
1397 purple_prefs_get_string(OPT_ICON_DIR), filename, NULL); | |
1398 } | |
1399 break; | |
1400 default: | |
1401 twitter_debug("unknown service\n"); | |
1402 break; | |
1403 } | |
1404 | 1450 |
1405 /* build image from file, if file exists */ | 1451 /* build image from file, if file exists */ |
1406 if(g_file_test(path, G_FILE_TEST_EXISTS)) { | 1452 if(g_file_test(path, G_FILE_TEST_EXISTS)) { |
1407 gchar *imgdata = NULL; | 1453 gchar *imgdata = NULL; |
1408 size_t len; | 1454 size_t len; |
1441 break; | 1487 break; |
1442 case wassr_service: | 1488 case wassr_service: |
1443 url = g_strdup_printf("http://wassr.jp/user/%s/profile_img.png.64", | 1489 url = g_strdup_printf("http://wassr.jp/user/%s/profile_img.png.64", |
1444 user_name); | 1490 user_name); |
1445 break; | 1491 break; |
1492 case identica_service: | |
1493 twitter_debug("identica icon support has not implemented yet.\n"); | |
1494 break; | |
1446 default: | 1495 default: |
1447 twitter_debug("unknown service\n"); | 1496 twitter_debug("unknown service\n"); |
1448 break; | 1497 break; |
1449 } | 1498 } |
1450 | 1499 |
1451 got_icon_data *gotdata = g_new0(got_icon_data, 1); | 1500 if(url) { |
1452 gotdata->user_name = g_strdup(user_name); | 1501 got_icon_data *gotdata = g_new0(got_icon_data, 1); |
1453 gotdata->service = service; | 1502 gotdata->user_name = g_strdup(user_name); |
1454 | 1503 gotdata->service = service; |
1455 /* gotdata will be released in got_icon_cb */ | 1504 |
1456 data->fetch_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, | 1505 /* gotdata will be released in got_icon_cb */ |
1457 got_icon_cb, gotdata); | 1506 data->fetch_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, |
1458 g_free(url); url = NULL; | 1507 got_icon_cb, gotdata); |
1459 | 1508 g_free(url); url = NULL; |
1460 twitter_debug("request %s's icon\n", user_name); | 1509 |
1510 twitter_debug("request %s's icon\n", user_name); | |
1511 } | |
1461 } | 1512 } |
1462 | 1513 |
1463 static void | 1514 static void |
1464 mark_icon_for_user(GtkTextMark *mark, const gchar *user_name, gint service) | 1515 mark_icon_for_user(GtkTextMark *mark, const gchar *user_name, gint service) |
1465 { | 1516 { |
1466 icon_data *data = NULL; | 1517 icon_data *data = NULL; |
1518 GHashTable *hash = NULL; | |
1467 | 1519 |
1468 twitter_debug("called\n"); | 1520 twitter_debug("called\n"); |
1469 | 1521 |
1470 switch(service) { | 1522 switch(service) { |
1471 case twitter_service: | 1523 case twitter_service: |
1472 data = (icon_data *)g_hash_table_lookup(icon_data_by_user, user_name); | 1524 hash = icon_data_by_user; |
1473 break; | 1525 break; |
1474 case wassr_service: | 1526 case wassr_service: |
1475 data = (icon_data *)g_hash_table_lookup(icon_data_by_user2, user_name); | 1527 hash = icon_data_by_user2; |
1528 break; | |
1529 case identica_service: | |
1530 hash = icon_data_by_user3; | |
1476 break; | 1531 break; |
1477 default: | 1532 default: |
1478 twitter_debug("unknown service\n"); | 1533 twitter_debug("unknown service\n"); |
1479 break; | 1534 break; |
1480 } | 1535 } |
1481 | 1536 |
1537 if(hash) | |
1538 data = (icon_data *)g_hash_table_lookup(hash, user_name); | |
1539 | |
1482 if(!data) { | 1540 if(!data) { |
1483 data = g_new0(icon_data, 1); | 1541 data = g_new0(icon_data, 1); |
1484 switch(service) { | 1542 g_hash_table_insert(hash, g_strdup(user_name), data); |
1485 case twitter_service: | |
1486 g_hash_table_insert(icon_data_by_user, | |
1487 g_strdup(user_name), data); | |
1488 break; | |
1489 case wassr_service: | |
1490 g_hash_table_insert(icon_data_by_user2, | |
1491 g_strdup(user_name), data); | |
1492 break; | |
1493 default: | |
1494 twitter_debug("unknown service\n"); | |
1495 break; | |
1496 } | |
1497 } | 1543 } |
1498 | 1544 |
1499 data->request_list = g_list_append(data->request_list, mark); | 1545 data->request_list = g_list_append(data->request_list, mark); |
1500 } | 1546 } |
1501 | 1547 |
1512 | 1558 |
1513 if(service == unknown_service) { | 1559 if(service == unknown_service) { |
1514 twitter_debug("neither twitter or wassr conv\n"); | 1560 twitter_debug("neither twitter or wassr conv\n"); |
1515 return FALSE; | 1561 return FALSE; |
1516 } | 1562 } |
1517 | |
1518 | 1563 |
1519 /* get text buffer */ | 1564 /* get text buffer */ |
1520 imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml); | 1565 imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml); |
1521 text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)); | 1566 text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)); |
1522 | 1567 |
1539 GtkTextIter insertion_point; | 1584 GtkTextIter insertion_point; |
1540 gint icon_id = 0; | 1585 gint icon_id = 0; |
1541 gint service = get_service_type(conv); | 1586 gint service = get_service_type(conv); |
1542 icon_data *data = NULL; | 1587 icon_data *data = NULL; |
1543 gint linenumber; | 1588 gint linenumber; |
1589 GHashTable *hash = NULL; | |
1544 | 1590 |
1545 twitter_debug("called\n"); | 1591 twitter_debug("called\n"); |
1546 | 1592 |
1547 if(service == unknown_service) { | 1593 if(service == unknown_service) { |
1548 twitter_debug("neither twitter or wassr conv\n"); | 1594 twitter_debug("unknown service\n"); |
1549 return; | 1595 return; |
1550 } | 1596 } |
1551 | 1597 |
1552 /* get user's name */ | 1598 /* get user's name */ |
1553 g_regex_match(regp[USER_FORMATTED], message, 0, &match_info); | 1599 g_regex_match(regp[USER_FORMATTED], message, 0, &match_info); |
1568 linenumber = GPOINTER_TO_INT(g_hash_table_lookup(conv_hash, conv)); | 1614 linenumber = GPOINTER_TO_INT(g_hash_table_lookup(conv_hash, conv)); |
1569 gtk_text_buffer_get_iter_at_line(text_buffer, | 1615 gtk_text_buffer_get_iter_at_line(text_buffer, |
1570 &insertion_point, | 1616 &insertion_point, |
1571 linenumber); | 1617 linenumber); |
1572 | 1618 |
1573 | |
1574 switch(service) { | 1619 switch(service) { |
1575 case twitter_service: | 1620 case twitter_service: |
1576 data = g_hash_table_lookup(icon_data_by_user, user_name); | 1621 hash = icon_data_by_user; |
1577 break; | 1622 break; |
1578 case wassr_service: | 1623 case wassr_service: |
1579 data = g_hash_table_lookup(icon_data_by_user2, user_name); | 1624 hash = icon_data_by_user2; |
1580 break; | 1625 break; |
1581 } | 1626 case identica_service: |
1627 hash = icon_data_by_user3; | |
1628 break; | |
1629 default: | |
1630 twitter_debug("unknown service\n"); | |
1631 break; | |
1632 } | |
1633 | |
1634 if(hash) | |
1635 data = g_hash_table_lookup(hash, user_name); | |
1582 | 1636 |
1583 if(data) | 1637 if(data) |
1584 icon_id = data->icon_id; | 1638 icon_id = data->icon_id; |
1585 | 1639 |
1586 /* if we don't have the icon for this user, put a mark instead and | 1640 /* if we don't have the icon for this user, put a mark instead and |
1587 * request the icon */ | 1641 * request the icon */ |
1588 if(!icon_id) { | 1642 if(!icon_id) { |
1589 twitter_debug("%s's icon is not in memory.\n", user_name); | 1643 twitter_debug("%s's icon is not in memory.\n", user_name); |
1590 mark_icon_for_user(gtk_text_buffer_create_mark( | 1644 mark_icon_for_user(gtk_text_buffer_create_mark( |
1591 text_buffer, NULL, &insertion_point, FALSE), | 1645 text_buffer, NULL, &insertion_point, FALSE), |
1592 user_name, service); | 1646 user_name, service); |
1593 /* request to attach icon to the buffer */ | 1647 /* request to attach icon to the buffer */ |
1594 request_icon(user_name, service); | 1648 request_icon(user_name, service); |
1595 g_free(user_name); user_name = NULL; | 1649 g_free(user_name); user_name = NULL; |
1596 return; | 1650 return; |
1635 regp[USER_FORMATTED] = g_regex_new(P_USER_FORMATTED, G_REGEX_RAW, 0, NULL); | 1689 regp[USER_FORMATTED] = g_regex_new(P_USER_FORMATTED, G_REGEX_RAW, 0, NULL); |
1636 | 1690 |
1637 icon_data_by_user = g_hash_table_new_full(g_str_hash, g_str_equal, | 1691 icon_data_by_user = g_hash_table_new_full(g_str_hash, g_str_equal, |
1638 g_free, NULL); | 1692 g_free, NULL); |
1639 icon_data_by_user2 = g_hash_table_new_full(g_str_hash, g_str_equal, | 1693 icon_data_by_user2 = g_hash_table_new_full(g_str_hash, g_str_equal, |
1694 g_free, NULL); | |
1695 icon_data_by_user3 = g_hash_table_new_full(g_str_hash, g_str_equal, | |
1640 g_free, NULL); | 1696 g_free, NULL); |
1641 conv_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, | 1697 conv_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, |
1642 NULL, NULL); | 1698 NULL, NULL); |
1643 | 1699 |
1644 /* attach counter to the existing twitter window */ | 1700 /* attach counter to the existing twitter window */ |
1707 g_regex_unref(regp[USER_FORMATTED]); | 1763 g_regex_unref(regp[USER_FORMATTED]); |
1708 | 1764 |
1709 /* remove mark list in each hash entry */ | 1765 /* remove mark list in each hash entry */ |
1710 g_hash_table_foreach(icon_data_by_user, (GHFunc)remove_marks_func, NULL); | 1766 g_hash_table_foreach(icon_data_by_user, (GHFunc)remove_marks_func, NULL); |
1711 g_hash_table_foreach(icon_data_by_user2, (GHFunc)remove_marks_func, NULL); | 1767 g_hash_table_foreach(icon_data_by_user2, (GHFunc)remove_marks_func, NULL); |
1768 g_hash_table_foreach(icon_data_by_user3, (GHFunc)remove_marks_func, NULL); | |
1712 | 1769 |
1713 /* cancel request that has not been finished yet */ | 1770 /* cancel request that has not been finished yet */ |
1714 g_hash_table_foreach(icon_data_by_user, (GHFunc)cancel_fetch_func, NULL); | 1771 g_hash_table_foreach(icon_data_by_user, (GHFunc)cancel_fetch_func, NULL); |
1715 g_hash_table_foreach(icon_data_by_user2, (GHFunc)cancel_fetch_func, NULL); | 1772 g_hash_table_foreach(icon_data_by_user2, (GHFunc)cancel_fetch_func, NULL); |
1773 g_hash_table_foreach(icon_data_by_user3, (GHFunc)cancel_fetch_func, NULL); | |
1716 | 1774 |
1717 /* destroy hash table for icon_data */ | 1775 /* destroy hash table for icon_data */ |
1718 g_hash_table_destroy(icon_data_by_user); //XXX all memory freed? --yaz | 1776 g_hash_table_destroy(icon_data_by_user); //XXX all memory freed? --yaz |
1719 g_hash_table_destroy(icon_data_by_user2); //XXX all memory freed? --yaz | 1777 g_hash_table_destroy(icon_data_by_user2); |
1778 g_hash_table_destroy(icon_data_by_user3); | |
1720 g_hash_table_destroy(conv_hash); | 1779 g_hash_table_destroy(conv_hash); |
1721 | 1780 |
1722 /* detach from twitter window */ | 1781 /* detach from twitter window */ |
1723 detach_from_window(); | 1782 detach_from_window(); |
1724 | 1783 |