Mercurial > pidgin
comparison libpurple/protocols/msn/msn.c @ 22512:b65997110933
The patch to msn to allow sending custom smileys. Doesn't send all the custom smileys correctly at the moment. References #1187.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 07 Mar 2008 23:19:47 +0000 |
parents | 6e5d37105189 |
children | 48e33e3673e2 |
comparison
equal
deleted
inserted
replaced
22511:0ae4d67bd6b1 | 22512:b65997110933 |
---|---|
30 #include "msg.h" | 30 #include "msg.h" |
31 #include "page.h" | 31 #include "page.h" |
32 #include "pluginpref.h" | 32 #include "pluginpref.h" |
33 #include "prefs.h" | 33 #include "prefs.h" |
34 #include "session.h" | 34 #include "session.h" |
35 #include "smiley.h" | |
35 #include "state.h" | 36 #include "state.h" |
36 #include "util.h" | 37 #include "util.h" |
37 #include "cmds.h" | 38 #include "cmds.h" |
38 #include "core.h" | 39 #include "core.h" |
39 #include "prpl.h" | 40 #include "prpl.h" |
80 char *msg; | 81 char *msg; |
81 PurpleMessageFlags flags; | 82 PurpleMessageFlags flags; |
82 time_t when; | 83 time_t when; |
83 } MsnIMData; | 84 } MsnIMData; |
84 | 85 |
86 typedef struct | |
87 { | |
88 char *smile; | |
89 MsnObject *obj; | |
90 } MsnEmoticon; | |
91 | |
85 static const char * | 92 static const char * |
86 msn_normalize(const PurpleAccount *account, const char *str) | 93 msn_normalize(const PurpleAccount *account, const char *str) |
87 { | 94 { |
88 static char buf[BUF_LEN]; | 95 static char buf[BUF_LEN]; |
89 char *tmp; | 96 char *tmp; |
113 | 120 |
114 if (swboard == NULL) | 121 if (swboard == NULL) |
115 return FALSE; | 122 return FALSE; |
116 | 123 |
117 msn_switchboard_send_msg(swboard, msg, TRUE); | 124 msn_switchboard_send_msg(swboard, msg, TRUE); |
125 msn_message_destroy(msg); | |
118 | 126 |
119 return TRUE; | 127 return TRUE; |
120 } | 128 } |
121 | 129 |
122 static GList * | 130 static GList * |
909 g_free(imdata->msg); | 917 g_free(imdata->msg); |
910 g_free(imdata); | 918 g_free(imdata); |
911 return FALSE; | 919 return FALSE; |
912 } | 920 } |
913 | 921 |
922 static GString* | |
923 msn_msg_emoticon_add(GString *current, MsnEmoticon *emoticon) | |
924 { | |
925 MsnObject *obj; | |
926 char *strobj; | |
927 | |
928 if (emoticon == NULL) | |
929 return current; | |
930 | |
931 obj = emoticon->obj; | |
932 | |
933 if (!obj) | |
934 return current; | |
935 | |
936 strobj = msn_object_to_string(obj); | |
937 | |
938 if (current) | |
939 g_string_append_printf(current, "\t%s\t%s", | |
940 emoticon->smile, strobj); | |
941 else { | |
942 current = g_string_new(""); | |
943 g_string_printf(current,"%s\t%s", | |
944 emoticon->smile, strobj); | |
945 } | |
946 | |
947 g_free(strobj); | |
948 | |
949 return current; | |
950 } | |
951 | |
952 static void | |
953 msn_send_emoticons(MsnSwitchBoard *swboard, GString *body) | |
954 { | |
955 MsnMessage *msg; | |
956 | |
957 g_return_if_fail(body != NULL); | |
958 | |
959 msg = msn_message_new(MSN_MSG_SLP); | |
960 msn_message_set_content_type(msg, "text/x-mms-emoticon"); | |
961 msn_message_set_flag(msg, 'N'); | |
962 msn_message_set_bin_data(msg, body->str, body->len); | |
963 | |
964 msn_switchboard_send_msg(swboard, msg, TRUE); | |
965 msn_message_destroy(msg); | |
966 } | |
967 | |
968 static void msn_emoticon_destroy(MsnEmoticon *emoticon) | |
969 { | |
970 if (emoticon->obj) | |
971 msn_object_destroy(emoticon->obj); | |
972 g_free(emoticon->smile); | |
973 g_free(emoticon); | |
974 } | |
975 | |
976 static GSList* msn_msg_grab_emoticons(const char *msg, const char *username) | |
977 { | |
978 GSList *list; | |
979 GList *smileys; | |
980 PurpleSmiley *smiley; | |
981 PurpleStoredImage *img; | |
982 char *ptr; | |
983 MsnEmoticon *emoticon; | |
984 int length; | |
985 | |
986 list = NULL; | |
987 smileys = purple_smileys_get_all(); | |
988 length = strlen(msg); | |
989 | |
990 for (; smileys; smileys = g_list_delete_link(smileys, smileys)) { | |
991 smiley = smileys->data; | |
992 | |
993 ptr = g_strstr_len(msg, length, purple_smiley_get_shortcut(smiley)); | |
994 | |
995 if (!ptr) | |
996 continue; | |
997 | |
998 img = purple_smiley_get_stored_image(smiley); | |
999 | |
1000 emoticon = g_new0(MsnEmoticon, 1); | |
1001 emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley)); | |
1002 emoticon->obj = msn_object_new_from_image(img, | |
1003 purple_imgstore_get_filename(img), | |
1004 username, MSN_OBJECT_EMOTICON); | |
1005 | |
1006 purple_imgstore_unref(img); | |
1007 list = g_slist_prepend(list, emoticon); | |
1008 } | |
1009 | |
1010 return list; | |
1011 } | |
1012 | |
914 static int | 1013 static int |
915 msn_send_im(PurpleConnection *gc, const char *who, const char *message, | 1014 msn_send_im(PurpleConnection *gc, const char *who, const char *message, |
916 PurpleMessageFlags flags) | 1015 PurpleMessageFlags flags) |
917 { | 1016 { |
918 PurpleAccount *account; | 1017 PurpleAccount *account; |
919 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); | 1018 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); |
920 MsnMessage *msg; | 1019 MsnMessage *msg; |
921 char *msgformat; | 1020 char *msgformat; |
922 char *msgtext; | 1021 char *msgtext; |
1022 const char *username; | |
923 | 1023 |
924 purple_debug_info("MSNP14","send IM {%s} to %s\n",message,who); | 1024 purple_debug_info("MSNP14","send IM {%s} to %s\n",message,who); |
925 account = purple_connection_get_account(gc); | 1025 account = purple_connection_get_account(gc); |
1026 username = purple_account_get_username(account); | |
926 | 1027 |
927 if (buddy) { | 1028 if (buddy) { |
928 PurplePresence *p = purple_buddy_get_presence(buddy); | 1029 PurplePresence *p = purple_buddy_get_presence(buddy); |
929 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { | 1030 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { |
930 char *text = purple_markup_strip_html(message); | 1031 char *text = purple_markup_strip_html(message); |
953 | 1054 |
954 g_free(msgformat); | 1055 g_free(msgformat); |
955 g_free(msgtext); | 1056 g_free(msgtext); |
956 | 1057 |
957 purple_debug_info("MSNP14","prepare to send online Message\n"); | 1058 purple_debug_info("MSNP14","prepare to send online Message\n"); |
958 if (g_ascii_strcasecmp(who, purple_account_get_username(account))) | 1059 if (g_ascii_strcasecmp(who, username)) |
959 { | 1060 { |
960 MsnSession *session; | 1061 MsnSession *session; |
961 MsnSwitchBoard *swboard; | 1062 MsnSwitchBoard *swboard; |
1063 MsnEmoticon *smile; | |
1064 GSList *smileys; | |
1065 GString *emoticons = NULL; | |
962 | 1066 |
963 session = gc->proto_data; | 1067 session = gc->proto_data; |
964 if(msn_user_is_yahoo(account,who)){ | 1068 if(msn_user_is_yahoo(account,who)){ |
965 /*we send the online and offline Message to Yahoo User via UBM*/ | 1069 /*we send the online and offline Message to Yahoo User via UBM*/ |
966 purple_debug_info("MSNP14","send to Yahoo User\n"); | 1070 purple_debug_info("MSNP14","send to Yahoo User\n"); |
967 uum_send_msg(session,msg); | 1071 uum_send_msg(session,msg); |
968 }else{ | 1072 }else{ |
969 purple_debug_info("MSNP14","send via switchboard\n"); | 1073 purple_debug_info("MSNP14","send via switchboard\n"); |
970 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); | 1074 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); |
1075 smileys = msn_msg_grab_emoticons(message, username); | |
1076 while (smileys) { | |
1077 smile = (MsnEmoticon*)smileys->data; | |
1078 emoticons = msn_msg_emoticon_add(emoticons, smile); | |
1079 msn_emoticon_destroy(smile); | |
1080 smileys = g_slist_delete_link(smileys, smileys); | |
1081 } | |
1082 | |
1083 if (emoticons) { | |
1084 msn_send_emoticons(swboard, emoticons); | |
1085 g_string_free(emoticons, TRUE); | |
1086 } | |
1087 | |
971 msn_switchboard_send_msg(swboard, msg, TRUE); | 1088 msn_switchboard_send_msg(swboard, msg, TRUE); |
972 } | 1089 } |
973 } | 1090 } |
974 else | 1091 else |
975 { | 1092 { |