40 #include <mcabber/screen.h> |
40 #include <mcabber/screen.h> |
41 #include <mcabber/hbuf.h> |
41 #include <mcabber/hbuf.h> |
42 #include <mcabber/hooks.h> |
42 #include <mcabber/hooks.h> |
43 #include <mcabber/settings.h> |
43 #include <mcabber/settings.h> |
44 #include <mcabber/modules.h> |
44 #include <mcabber/modules.h> |
|
45 #include <mcabber/xmpp_helper.h> |
45 |
46 |
46 #include <mcabber/pep.h> |
47 #include <mcabber/pep.h> |
47 |
48 |
48 #include "config.h" |
49 #include "config.h" |
49 |
50 |
84 |
85 |
85 #define NS_AVATAR_DATA ( "urn:xmpp:avatar:data" ) |
86 #define NS_AVATAR_DATA ( "urn:xmpp:avatar:data" ) |
86 #define NS_AVATAR_METADATA ( "urn:xmpp:avatar:metadata" ) |
87 #define NS_AVATAR_METADATA ( "urn:xmpp:avatar:metadata" ) |
87 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" ) |
88 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" ) |
88 |
89 |
89 static guint avatar_cid = 0; |
|
90 static guint avatar_hid_connect = 0; |
90 static guint avatar_hid_connect = 0; |
91 static guint avatar_hid_disconnect = 0; |
91 static guint avatar_hid_disconnect = 0; |
92 |
92 |
93 static GSList *reply_handlers = NULL; |
93 static GSList *reply_handlers = NULL; |
94 |
94 |
95 static LmMessageHandler *avatar_metadata_reply_handler = NULL; |
95 static LmMessageHandler *avatar_metadata_reply_handler = NULL; |
96 |
96 |
97 static gboolean publish_delayed = FALSE; |
97 static gboolean publish_delayed = FALSE; |
98 static gsize publish_len = 0; |
98 static gsize publish_len = 0; |
99 static gchar *publish_data = NULL; |
99 static guchar *publish_data = NULL; |
100 |
100 |
101 // predeclarations |
101 // predeclarations |
102 |
102 |
103 static LmHandlerResult avatar_retrieve_data_reply_handler (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer userdata); |
103 static LmHandlerResult avatar_retrieve_data_reply_handler (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer userdata); |
104 |
104 |
267 // I hope, compiler will optimize out all these variables... |
267 // I hope, compiler will optimize out all these variables... |
268 |
268 |
269 // font size in font pixels (real?) |
269 // font size in font pixels (real?) |
270 //int fonth = 16; |
270 //int fonth = 16; |
271 //int fontw = 8; |
271 //int fontw = 8; |
272 float fontaspect = (float) fontw / fonth; |
272 //float fontaspect = (float) fontw / fonth; |
273 // aa pixels per character |
273 // aa pixels per character |
274 const int aappch = 2; |
274 const int aappch = 2; |
275 const int aappcw = 2; |
275 const int aappcw = 2; |
276 const float aaaspect = (float) aappcw / aappch; |
276 //const float aaaspect = (float) aappcw / aappch; |
277 // font pixels per aa pixel |
277 // font pixels per aa pixel |
278 int aappph = (float) fonth / aappch; |
278 int aappph = (float) fonth / aappch; |
279 int aapppw = (float) fontw / aappcw; |
279 int aapppw = (float) fontw / aappcw; |
280 float aapixelaspect = (float) aapppw / aappph; |
280 float aapixelaspect = (float) aapppw / aappph; |
281 // original image size in real pixels |
281 // original image size in real pixels |
331 } else { |
331 } else { |
332 resh = (float) resh_rp * aapixelaspect; |
332 resh = (float) resh_rp * aapixelaspect; |
333 resw = resw_rp; |
333 resw = resw_rp; |
334 } |
334 } |
335 // number of original image pixels per one resulting image pixel |
335 // number of original image pixels per one resulting image pixel |
336 int ratioh = (float) originh / resh; |
336 //int ratioh = (float) originh / resh; |
337 int ratiow = (float) originw / resw; |
337 //int ratiow = (float) originw / resw; |
338 // resulting image size in chars |
338 // resulting image size in chars |
339 int rescharh = (float) resh / aappch; |
339 int rescharh = (float) resh / aappch; |
340 int rescharw = (float) resw / aappcw; |
340 int rescharw = (float) resw / aappcw; |
341 |
341 |
342 // re-calculate parameters, as they may change due to rounding (?) |
342 // re-calculate parameters, as they may change due to rounding (?) |
413 // render ascii image |
413 // render ascii image |
414 aa_render (context, &aa_defrenderparams, 0, 0, aa_scrwidth (context), aa_scrheight (context)); |
414 aa_render (context, &aa_defrenderparams, 0, 0, aa_scrwidth (context), aa_scrheight (context)); |
415 aa_flush (context); |
415 aa_flush (context); |
416 |
416 |
417 { // format the result |
417 { // format the result |
418 char *text = aa_text (context); |
418 char *text = (char *) aa_text (context); |
419 int width = aa_scrwidth (context); |
419 int width = aa_scrwidth (context); |
420 int height = aa_scrheight (context); |
420 int height = aa_scrheight (context); |
421 GString *avatar = g_string_new (NULL); |
421 GString *avatar = g_string_new (NULL); |
422 char *end = text + width * height; |
422 char *end = text + width * height; |
423 |
423 |
825 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
825 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
826 } |
826 } |
827 |
827 |
828 // data is image/png data of length len |
828 // data is image/png data of length len |
829 // call with len = 0 to publish empty avatar |
829 // call with len = 0 to publish empty avatar |
830 static void avatar_publish (const gchar *data, gsize len) |
830 static void avatar_publish (const guchar *data, gsize len) |
831 { |
831 { |
832 LmMessage *datarequest; |
832 LmMessage *datarequest; |
833 LmMessageHandler *handler; |
833 gchar *id; |
834 gchar *id; |
834 LmMessage *request; |
835 LmMessage *request; |
835 LmMessageNode *node; |
836 LmMessageNode *node; |
836 GError *error = NULL; |
837 GError *error = NULL; |
|
838 |
837 |
839 if (!xmpp_is_online ()) { |
838 if (!xmpp_is_online ()) { |
840 scr_log_print (LPRINT_DEBUG, "avatar: Not connected, delaying publish."); |
839 scr_log_print (LPRINT_DEBUG, "avatar: Not connected, delaying publish."); |
841 |
840 |
842 g_free (publish_data); |
841 g_free (publish_data); |
843 |
842 |
844 publish_data = g_strndup (data, len); |
843 publish_data = (guchar *) g_strndup ((gchar *) data, len); |
845 publish_len = len; |
844 publish_len = len; |
846 publish_delayed = TRUE; |
845 publish_delayed = TRUE; |
847 |
846 |
848 return; |
847 return; |
849 } |
848 } |
1133 } |
1132 } |
1134 |
1133 |
1135 static guint avatar_hch (const gchar *hid, hk_arg_t *args, gpointer userdata) |
1134 static guint avatar_hch (const gchar *hid, hk_arg_t *args, gpointer userdata) |
1136 { |
1135 { |
1137 if (publish_data) { |
1136 if (publish_data) { |
1138 char *tmp_data = publish_data; |
1137 guchar *tmp_data = publish_data; |
1139 |
1138 |
1140 scr_log_print (LPRINT_DEBUG, "avatar: Publishing delayed data."); |
1139 scr_log_print (LPRINT_DEBUG, "avatar: Publishing delayed data."); |
1141 |
1140 |
1142 publish_data = NULL; |
1141 publish_data = NULL; |
1143 publish_delayed = FALSE; |
1142 publish_delayed = FALSE; |