57 "PEP avatars handling\n" \ |
58 "PEP avatars handling\n" \ |
58 "Recognizes options avatar_directory, avatar_font_height, avatar_font_width, avatar_max_height, avatar_max_width and avatar_background\n" \ |
59 "Recognizes options avatar_directory, avatar_font_height, avatar_font_width, avatar_max_height, avatar_max_width and avatar_background\n" \ |
59 "Provides command /avatar" ) |
60 "Provides command /avatar" ) |
60 static const gchar *deps[] = { "pep", NULL }; |
61 static const gchar *deps[] = { "pep", NULL }; |
61 |
62 |
62 static module_info_t info_avatar_experimental = { |
63 static module_info_t info_avatar_dev = { |
63 .branch = "experimental", |
64 .branch = "dev", |
64 .api = 28, |
65 .api = 20, |
65 .version = PROJECT_VERSION, |
66 .version = PROJECT_VERSION, |
66 .description = DESCRIPTION, |
67 .description = DESCRIPTION, |
67 .requires = deps, |
68 .requires = deps, |
68 .init = avatar_init, |
69 .init = avatar_init, |
69 .uninit = avatar_uninit, |
70 .uninit = avatar_uninit, |
70 .next = NULL, |
71 .next = NULL, |
71 }; |
72 }; |
72 |
73 |
73 static module_info_t info_avatar_dev = { |
74 module_info_t info_avatar_0_10_1 = { |
74 .branch = "dev", |
75 .branch = "0.10.1", |
75 .api = 13, |
76 .api = 1, |
76 .version = PROJECT_VERSION, |
77 .version = PROJECT_VERSION, |
77 .description = DESCRIPTION, |
78 .description = DESCRIPTION, |
78 .requires = deps, |
79 .requires = deps, |
79 .init = avatar_init, |
80 .init = avatar_init, |
80 .uninit = avatar_uninit, |
81 .uninit = avatar_uninit, |
81 .next = &info_avatar_experimental, |
82 .next = &info_avatar_dev, |
82 }; |
83 }; |
83 |
84 |
84 module_info_t info_avatar = { |
85 module_info_t info_avatar = { |
85 .branch = "0.10.0", |
86 .branch = "0.10.0", |
86 .api = 1, |
87 .api = 1, |
87 .version = PROJECT_VERSION, |
88 .version = PROJECT_VERSION, |
88 .description = DESCRIPTION, |
89 .description = DESCRIPTION, |
89 .requires = deps, |
90 .requires = deps, |
90 .init = avatar_init, |
91 .init = avatar_init, |
91 .uninit = avatar_uninit, |
92 .uninit = avatar_uninit, |
92 .next = &info_avatar_dev, |
93 .next = &info_avatar_0_10_1, |
93 }; |
94 }; |
94 |
95 |
95 // globals |
96 // globals |
96 |
97 |
97 #define NS_AVATAR_DATA ( "urn:xmpp:avatar:data" ) |
98 #define NS_AVATAR_DATA ( "urn:xmpp:avatar:data" ) |
98 #define NS_AVATAR_METADATA ( "urn:xmpp:avatar:metadata" ) |
99 #define NS_AVATAR_METADATA ( "urn:xmpp:avatar:metadata" ) |
99 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" ) |
100 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" ) |
100 |
101 |
101 #ifdef HAVE_CMD_ID |
102 #ifdef MCABBER_API_HAVE_CMD_ID |
102 static gpointer avatar_cmid = NULL; |
103 static gpointer avatar_cmid = NULL; |
103 #ifdef HAVE_CMD_SAFE |
|
104 static gboolean avatar_set_safe = FALSE; |
104 static gboolean avatar_set_safe = FALSE; |
105 #endif |
|
106 #endif |
105 #endif |
107 |
106 |
108 static guint avatar_hid_connect = 0; |
107 static guint avatar_hid_connect = 0; |
109 static guint avatar_hid_disconnect = 0; |
108 static guint avatar_hid_disconnect = 0; |
110 |
109 |
360 // re-calculate parameters, as they may change due to rounding (?) |
359 // re-calculate parameters, as they may change due to rounding (?) |
361 finalcharh = rescharh; |
360 finalcharh = rescharh; |
362 finalcharw = rescharw; |
361 finalcharw = rescharw; |
363 finalh = rescharh * aappch; |
362 finalh = rescharh * aappch; |
364 finalw = rescharw * aappcw; |
363 finalw = rescharw * aappcw; |
|
364 #if 0 |
|
365 // I do not know, why I added this here, and it needs more digging |
|
366 // to know, if this is supposed to be used somewhere, so, for now |
|
367 // let it be this way |
365 int finalh_rp; |
368 int finalh_rp; |
366 int finalw_rp; |
369 int finalw_rp; |
367 if (aapixelaspect > 1) { |
370 if (aapixelaspect > 1) { |
368 finalh_rp = finalh; |
371 finalh_rp = finalh; |
369 finalw_rp = (float) finalw * aapixelaspect; |
372 finalw_rp = (float) finalw * aapixelaspect; |
370 } else { |
373 } else { |
371 finalh_rp = (float) finalh / aapixelaspect; |
374 finalh_rp = (float) finalh / aapixelaspect; |
372 finalw_rp = finalw; |
375 finalw_rp = finalw; |
373 } |
376 } |
|
377 #endif |
374 finalratioh = (float) originh / finalh; |
378 finalratioh = (float) originh / finalh; |
375 finalratiow = (float) originw / finalw; |
379 finalratiow = (float) originw / finalw; |
376 |
380 |
377 // center image part actually used |
381 // center image part actually used |
378 int areah = (float) finalh * finalratioh; |
382 int areah = (float) finalh * finalratioh; |
910 |
914 |
911 node = lm_message_node_add_child (node, "metadata", NULL); |
915 node = lm_message_node_add_child (node, "metadata", NULL); |
912 lm_message_node_set_attribute (node, "xmlns", NS_AVATAR_METADATA); |
916 lm_message_node_set_attribute (node, "xmlns", NS_AVATAR_METADATA); |
913 |
917 |
914 if (len) { |
918 if (len) { |
915 gchar *bytes = g_strdup_printf ("%d", len); |
919 gchar *bytes = g_strdup_printf ("%u", (guint) len); |
916 |
920 |
917 node = lm_message_node_add_child (node, "info", NULL); |
921 node = lm_message_node_add_child (node, "info", NULL); |
918 lm_message_node_set_attributes (node, "bytes", bytes, "id", id, "type", "image/png", NULL); |
922 lm_message_node_set_attributes (node, "bytes", bytes, "id", id, "type", "image/png", NULL); |
919 |
923 |
920 g_free (bytes); |
924 g_free (bytes); |
1170 void avatar_init (void) |
1174 void avatar_init (void) |
1171 { |
1175 { |
1172 pep_register_xmlns_handler (NS_AVATAR_METADATA, avatar_handler, NULL, NULL); |
1176 pep_register_xmlns_handler (NS_AVATAR_METADATA, avatar_handler, NULL, NULL); |
1173 avatar_metadata_reply_handler = lm_message_handler_new (avatar_publish_metadata_reply_handler, NULL, NULL); |
1177 avatar_metadata_reply_handler = lm_message_handler_new (avatar_publish_metadata_reply_handler, NULL, NULL); |
1174 |
1178 |
1175 #ifndef HAVE_CMD_ID |
1179 #ifndef MCABBER_API_HAVE_CMD_ID |
1176 cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL); |
1180 cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL); |
1177 #else |
1181 #else |
1178 avatar_cmid = cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL); |
1182 avatar_cmid = cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL); |
1179 #ifdef HAVE_CMD_SAFE |
|
1180 avatar_set_safe = cmd_set_safe ("avatar", TRUE); |
1183 avatar_set_safe = cmd_set_safe ("avatar", TRUE); |
1181 #endif |
1184 #endif |
1182 #endif |
|
1183 |
1185 |
1184 avatar_hid_connect = hk_add_handler (avatar_hch, HOOK_POST_CONNECT, G_PRIORITY_DEFAULT, NULL); |
1186 avatar_hid_connect = hk_add_handler (avatar_hch, HOOK_POST_CONNECT, G_PRIORITY_DEFAULT, NULL); |
1185 avatar_hid_disconnect = hk_add_handler (avatar_hdh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL); |
1187 avatar_hid_disconnect = hk_add_handler (avatar_hdh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL); |
1186 |
1188 |
1187 xmpp_add_feature (NS_AVATAR_METADATA); |
1189 xmpp_add_feature (NS_AVATAR_METADATA); |
1194 xmpp_del_feature (NS_AVATAR_METADATA_NOTIFY); |
1196 xmpp_del_feature (NS_AVATAR_METADATA_NOTIFY); |
1195 |
1197 |
1196 hk_del_handler (HOOK_POST_CONNECT, avatar_hid_connect); |
1198 hk_del_handler (HOOK_POST_CONNECT, avatar_hid_connect); |
1197 hk_del_handler (HOOK_PRE_DISCONNECT, avatar_hid_disconnect); |
1199 hk_del_handler (HOOK_PRE_DISCONNECT, avatar_hid_disconnect); |
1198 |
1200 |
1199 #ifndef HAVE_CMD_ID |
1201 #ifndef MCABBER_API_HAVE_CMD_ID |
1200 cmd_del ("avatar"); |
1202 cmd_del ("avatar"); |
1201 #else |
1203 #else |
1202 if (avatar_cmid) |
1204 if (avatar_cmid) |
1203 cmd_del (avatar_cmid); |
1205 cmd_del (avatar_cmid); |
1204 #ifdef HAVE_CMD_SAFE |
|
1205 if (avatar_set_safe) |
1206 if (avatar_set_safe) |
1206 cmd_set_safe ("avatar", FALSE); |
1207 cmd_set_safe ("avatar", FALSE); |
1207 #endif |
1208 #endif |
1208 #endif |
|
1209 |
1209 |
1210 pep_unregister_xmlns_handler (NS_AVATAR_METADATA); |
1210 pep_unregister_xmlns_handler (NS_AVATAR_METADATA); |
1211 |
1211 |
1212 avatar_free_reply_handlers (); |
1212 avatar_free_reply_handlers (); |
1213 |
1213 |