Mercurial > pidgin
annotate src/protocols/msn/object.c @ 10108:f0100b414d98
[gaim-migrate @ 11141]
Two things:
a. Added Enter as a gtk_binding to GtkIMHtml. This fixes everything.
Input methods now work. The "Enter sends" and "Ctrl-Enter sends" preferences
were removed and defaulted to yes and no respectively, BUT, in a very super-cool
turn of events, you can now add your own bindings to .gtkrc to make WHATEVER
YOU WANT send. Awesome. Someone should use g_signal_accumulator_true_handled
or something to make profiles and away messages able to insert newlines.
b. Removed "Use multi-colored screennames in chats," defaulted to yes, and
wrote a nifty algorithm to automatically adjust the colors to accomodate the
background (see http://gaim.sf.net/sean/porn-chat.png). People should play
around and tweak it a bit. The algorithm takes into consideration the
luminosity of the current background and the base hue to use for the screenname
in generating the new colors. Note that it does this while maintaining the hues.
Someone should optimize this so it skips over the floating point arithmatic when
the background color is white.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sun, 17 Oct 2004 23:55:49 +0000 |
| parents | 9d839c9f6c2d |
| children | 9f358a718f38 |
| rev | line source |
|---|---|
| 9193 | 1 /** |
| 2 * @file object.c MSNObject API | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
| 9193 | 9 * |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 24 #include "object.h" | |
| 25 | |
| 26 #define GET_STRING_TAG(field, id) \ | |
| 27 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
| 28 { \ | |
| 29 tag += strlen(id "=\""); \ | |
| 30 c = strchr(tag, '"'); \ | |
| 10093 | 31 if (obj->field != NULL) \ |
| 32 g_free(obj->field); \ | |
| 9193 | 33 obj->field = g_strndup(tag, c - tag); \ |
| 34 } | |
| 35 | |
| 36 #define GET_INT_TAG(field, id) \ | |
| 37 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
| 38 { \ | |
| 39 char buf[16]; \ | |
| 9823 | 40 size_t offset; \ |
| 9193 | 41 tag += strlen(id "=\""); \ |
| 42 c = strchr(tag, '"'); \ | |
| 9823 | 43 if (c != NULL) \ |
| 44 { \ | |
| 45 memset(buf, 0, sizeof(buf)); \ | |
| 46 offset = c - tag; \ | |
| 47 if (offset >= sizeof(buf)) \ | |
| 48 offset = sizeof(buf) - 1; \ | |
| 49 strncpy(buf, tag, offset); \ | |
| 50 obj->field = atoi(buf); \ | |
| 51 } \ | |
| 9193 | 52 } |
| 53 | |
| 54 static GList *local_objs; | |
| 55 | |
| 56 MsnObject * | |
| 57 msn_object_new(void) | |
| 58 { | |
| 59 MsnObject *obj; | |
| 60 | |
| 61 obj = g_new0(MsnObject, 1); | |
| 62 | |
| 63 msn_object_set_type(obj, MSN_OBJECT_UNKNOWN); | |
| 64 msn_object_set_friendly(obj, "AAA="); | |
| 65 | |
| 66 return obj; | |
| 67 } | |
| 68 | |
| 69 MsnObject * | |
| 70 msn_object_new_from_string(const char *str) | |
| 71 { | |
| 72 MsnObject *obj; | |
| 73 char *tag, *c; | |
| 74 | |
| 75 g_return_val_if_fail(str != NULL, NULL); | |
| 76 g_return_val_if_fail(!strncmp(str, "<msnobj ", 8), NULL); | |
| 77 | |
| 78 obj = msn_object_new(); | |
| 79 | |
| 80 GET_STRING_TAG(creator, "Creator"); | |
| 81 GET_INT_TAG(size, "Size"); | |
| 82 GET_INT_TAG(type, "Type"); | |
| 83 GET_STRING_TAG(location, "Location"); | |
| 84 GET_STRING_TAG(friendly, "Friendly"); | |
| 85 GET_STRING_TAG(sha1d, "SHA1D"); | |
| 86 GET_STRING_TAG(sha1c, "SHA1C"); | |
| 87 | |
| 9776 | 88 /* If we are missing any of the required elements then discard the object */ |
| 89 if (obj->creator == NULL || obj->size == 0 || obj->type == 0 | |
| 90 || obj->location == NULL || obj->friendly == NULL | |
| 91 || obj->sha1d == NULL || obj->sha1c == NULL) { | |
| 92 msn_object_destroy(obj); | |
| 93 obj = NULL; | |
| 94 } | |
| 95 | |
| 9193 | 96 return obj; |
| 97 } | |
| 98 | |
| 99 void | |
| 100 msn_object_destroy(MsnObject *obj) | |
| 101 { | |
| 102 g_return_if_fail(obj != NULL); | |
| 103 | |
| 104 if (obj->creator != NULL) | |
| 105 g_free(obj->creator); | |
| 106 | |
| 107 if (obj->location != NULL) | |
| 108 g_free(obj->location); | |
| 109 | |
| 110 if (obj->friendly != NULL) | |
| 111 g_free(obj->friendly); | |
| 112 | |
| 113 if (obj->sha1d != NULL) | |
| 114 g_free(obj->sha1d); | |
| 115 | |
| 116 if (obj->sha1c != NULL) | |
| 117 g_free(obj->sha1c); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
118 |
| 9193 | 119 if (obj->local) |
| 120 local_objs = g_list_remove(local_objs, obj); | |
| 121 | |
| 122 g_free(obj); | |
| 123 } | |
| 124 | |
| 125 char * | |
| 126 msn_object_to_string(const MsnObject *obj) | |
| 127 { | |
| 128 char *str; | |
| 129 | |
| 130 g_return_val_if_fail(obj != NULL, NULL); | |
| 131 | |
| 132 str = g_strdup_printf("<msnobj Creator=\"%s\" Size=\"%d\" Type=\"%d\" " | |
| 133 "Location=\"%s\" Friendly=\"%s\" SHA1D=\"%s\" " | |
| 134 "SHA1C=\"%s\"/>", | |
| 135 msn_object_get_creator(obj), | |
| 136 msn_object_get_size(obj), | |
| 137 msn_object_get_type(obj), | |
| 138 msn_object_get_location(obj), | |
| 139 msn_object_get_friendly(obj), | |
| 140 msn_object_get_sha1d(obj), | |
| 141 msn_object_get_sha1c(obj)); | |
| 142 | |
| 143 return str; | |
| 144 } | |
| 145 | |
| 146 void | |
| 147 msn_object_set_creator(MsnObject *obj, const char *creator) | |
| 148 { | |
| 149 g_return_if_fail(obj != NULL); | |
| 150 | |
| 151 if (obj->creator != NULL) | |
| 152 g_free(obj->creator); | |
| 153 | |
| 154 obj->creator = (creator == NULL ? NULL : g_strdup(creator)); | |
| 155 } | |
| 156 | |
| 157 void | |
| 158 msn_object_set_size(MsnObject *obj, int size) | |
| 159 { | |
| 160 g_return_if_fail(obj != NULL); | |
| 161 | |
| 162 obj->size = size; | |
| 163 } | |
| 164 | |
| 165 void | |
| 166 msn_object_set_type(MsnObject *obj, MsnObjectType type) | |
| 167 { | |
| 168 g_return_if_fail(obj != NULL); | |
| 169 | |
| 170 obj->type = type; | |
| 171 } | |
| 172 | |
| 173 void | |
| 174 msn_object_set_location(MsnObject *obj, const char *location) | |
| 175 { | |
| 176 g_return_if_fail(obj != NULL); | |
| 177 | |
| 178 if (obj->location != NULL) | |
| 179 g_free(obj->location); | |
| 180 | |
| 181 obj->location = (location == NULL ? NULL : g_strdup(location)); | |
| 182 } | |
| 183 | |
| 184 void | |
| 185 msn_object_set_friendly(MsnObject *obj, const char *friendly) | |
| 186 { | |
| 187 g_return_if_fail(obj != NULL); | |
| 188 | |
| 189 if (obj->friendly != NULL) | |
| 190 g_free(obj->friendly); | |
| 191 | |
| 192 obj->friendly = (friendly == NULL ? NULL : g_strdup(friendly)); | |
| 193 } | |
| 194 | |
| 195 void | |
| 196 msn_object_set_sha1d(MsnObject *obj, const char *sha1d) | |
| 197 { | |
| 198 g_return_if_fail(obj != NULL); | |
| 199 | |
| 200 if (obj->sha1d != NULL) | |
| 201 g_free(obj->sha1d); | |
| 202 | |
| 203 obj->sha1d = (sha1d == NULL ? NULL : g_strdup(sha1d)); | |
| 204 } | |
| 205 | |
| 206 void | |
| 207 msn_object_set_sha1c(MsnObject *obj, const char *sha1c) | |
| 208 { | |
| 209 g_return_if_fail(obj != NULL); | |
| 210 | |
| 211 if (obj->sha1c != NULL) | |
| 212 g_free(obj->sha1c); | |
| 213 | |
| 214 obj->sha1c = (sha1c == NULL ? NULL : g_strdup(sha1c)); | |
| 215 } | |
| 216 | |
| 217 const char * | |
| 218 msn_object_get_creator(const MsnObject *obj) | |
| 219 { | |
| 220 g_return_val_if_fail(obj != NULL, NULL); | |
| 221 | |
| 222 return obj->creator; | |
| 223 } | |
| 224 | |
| 225 int | |
| 226 msn_object_get_size(const MsnObject *obj) | |
| 227 { | |
| 228 g_return_val_if_fail(obj != NULL, 0); | |
| 229 | |
| 230 return obj->size; | |
| 231 } | |
| 232 | |
| 233 MsnObjectType | |
| 234 msn_object_get_type(const MsnObject *obj) | |
| 235 { | |
| 236 g_return_val_if_fail(obj != NULL, MSN_OBJECT_UNKNOWN); | |
| 237 | |
| 238 return obj->type; | |
| 239 } | |
| 240 | |
| 241 const char * | |
| 242 msn_object_get_location(const MsnObject *obj) | |
| 243 { | |
| 244 g_return_val_if_fail(obj != NULL, NULL); | |
| 245 | |
| 246 return obj->location; | |
| 247 } | |
| 248 | |
| 249 const char * | |
| 250 msn_object_get_friendly(const MsnObject *obj) | |
| 251 { | |
| 252 g_return_val_if_fail(obj != NULL, NULL); | |
| 253 | |
| 254 return obj->friendly; | |
| 255 } | |
| 256 | |
| 257 const char * | |
| 258 msn_object_get_sha1d(const MsnObject *obj) | |
| 259 { | |
| 260 g_return_val_if_fail(obj != NULL, NULL); | |
| 261 | |
| 262 return obj->sha1d; | |
| 263 } | |
| 264 | |
| 265 const char * | |
| 266 msn_object_get_sha1c(const MsnObject *obj) | |
| 267 { | |
| 268 g_return_val_if_fail(obj != NULL, NULL); | |
| 269 | |
| 270 return obj->sha1c; | |
| 271 } | |
| 272 | |
| 273 MsnObject * | |
| 274 msn_object_find_local(const char *sha1c) | |
| 275 { | |
| 276 GList *l; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
277 |
| 9193 | 278 g_return_val_if_fail(sha1c != NULL, NULL); |
| 279 | |
| 280 for (l = local_objs; l != NULL; l = l->next) | |
| 281 { | |
| 282 MsnObject *local_obj = l->data; | |
| 283 | |
| 284 if (!strcmp(msn_object_get_sha1c(local_obj), sha1c)) | |
| 285 return local_obj; | |
| 286 } | |
| 287 | |
| 288 return NULL; | |
| 289 | |
| 290 } | |
| 291 | |
| 292 void | |
| 293 msn_object_set_local(MsnObject *obj) | |
| 294 { | |
| 295 g_return_if_fail(obj != NULL); | |
| 296 | |
| 297 obj->local = TRUE; | |
| 298 | |
| 299 local_objs = g_list_append(local_objs, obj); | |
| 300 } | |
| 301 | |
| 302 void | |
| 303 msn_object_set_real_location(MsnObject *obj, const char *real_location) | |
| 304 { | |
| 305 g_return_if_fail(obj != NULL); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
306 |
| 9193 | 307 /* obj->local = TRUE; */ |
| 308 | |
| 309 if (obj->real_location != NULL) | |
| 310 g_free(obj->real_location); | |
| 311 | |
| 312 obj->real_location = | |
| 313 (real_location == NULL ? NULL : g_strdup(real_location)); | |
| 314 } | |
| 315 | |
| 316 const char * | |
| 317 msn_object_get_real_location(const MsnObject *obj) | |
| 318 { | |
| 319 MsnObject *local_obj; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
320 |
| 9193 | 321 g_return_val_if_fail(obj != NULL, NULL); |
| 322 | |
| 323 local_obj = msn_object_find_local(msn_object_get_sha1c(obj)); | |
| 324 | |
| 325 if (local_obj != NULL) | |
| 326 return local_obj->real_location; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
327 |
| 9193 | 328 return NULL; |
| 329 } |
