Mercurial > pidgin
comparison src/gtkutils.c @ 7712:2823111061ba
[gaim-migrate @ 8357]
I did a few things to my drag-and-drop patch. First, I moved the
application/x-im-contact parsing code into its own function, so we don't
have to duplicate stuff. The reason I did this is because Sean suggested
support for dragging x-im-contacts into conversation windows, which is
also implemented now, and it rocks. :)
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Wed, 03 Dec 2003 02:03:25 +0000 |
| parents | 357eb1c39b72 |
| children | db3bdae1761e |
comparison
equal
deleted
inserted
replaced
| 7711:ebd43be54140 | 7712:2823111061ba |
|---|---|
| 1138 filename = g_build_filename(gaim_user_dir(), G_DIR_SEPARATOR_S, | 1138 filename = g_build_filename(gaim_user_dir(), G_DIR_SEPARATOR_S, |
| 1139 "accels", NULL); | 1139 "accels", NULL); |
| 1140 gtk_accel_map_load(filename); | 1140 gtk_accel_map_load(filename); |
| 1141 g_free(filename); | 1141 g_free(filename); |
| 1142 } | 1142 } |
| 1143 | |
| 1144 gboolean | |
| 1145 gaim_gtk_parse_x_im_contact(const char *msg, gboolean all_accounts, | |
| 1146 GaimAccount **ret_account, char **ret_protocol, | |
| 1147 char **ret_username, char **ret_alias) | |
| 1148 { | |
| 1149 char *protocol = NULL; | |
| 1150 char *username = NULL; | |
| 1151 char *alias = NULL; | |
| 1152 char *str; | |
| 1153 char *c, *s; | |
| 1154 gboolean valid; | |
| 1155 | |
| 1156 g_return_val_if_fail(msg != NULL, FALSE); | |
| 1157 g_return_val_if_fail(ret_protocol != NULL, FALSE); | |
| 1158 g_return_val_if_fail(ret_username != NULL, FALSE); | |
| 1159 | |
| 1160 s = str = g_strdup(msg); | |
| 1161 | |
| 1162 while (*s != '\r' && *s != '\n' && *s != '\0') | |
| 1163 { | |
| 1164 char *key, *value; | |
| 1165 | |
| 1166 key = s; | |
| 1167 | |
| 1168 /* Grab the key */ | |
| 1169 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ' ') | |
| 1170 s++; | |
| 1171 | |
| 1172 if (*s == '\r') s++; | |
| 1173 | |
| 1174 if (*s == '\n') | |
| 1175 { | |
| 1176 s++; | |
| 1177 continue; | |
| 1178 } | |
| 1179 | |
| 1180 if (*s != '\0') *s++ = '\0'; | |
| 1181 | |
| 1182 /* Clear past any whitespace */ | |
| 1183 while (*s != '\0' && *s == ' ') | |
| 1184 s++; | |
| 1185 | |
| 1186 /* Now let's grab until the end of the line. */ | |
| 1187 value = s; | |
| 1188 | |
| 1189 while (*s != '\r' && *s != '\n' && *s != '\0') | |
| 1190 s++; | |
| 1191 | |
| 1192 if (*s == '\r') *s++ = '\0'; | |
| 1193 if (*s == '\n') *s++ = '\0'; | |
| 1194 | |
| 1195 if ((c = strchr(key, ':')) != NULL) | |
| 1196 { | |
| 1197 if (!g_ascii_strcasecmp(key, "X-IM-Username:")) | |
| 1198 username = g_strdup(value); | |
| 1199 else if (!g_ascii_strcasecmp(key, "X-IM-Protocol:")) | |
| 1200 protocol = g_strdup(value); | |
| 1201 else if (!g_ascii_strcasecmp(key, "X-IM-Alias:")) | |
| 1202 alias = g_strdup(value); | |
| 1203 } | |
| 1204 } | |
| 1205 | |
| 1206 if (username != NULL && protocol != NULL) | |
| 1207 { | |
| 1208 valid = TRUE; | |
| 1209 | |
| 1210 *ret_username = username; | |
| 1211 *ret_protocol = protocol; | |
| 1212 | |
| 1213 if (ret_alias != NULL) | |
| 1214 *ret_alias = alias; | |
| 1215 | |
| 1216 /* Check for a compatible account. */ | |
| 1217 if (ret_account != NULL) | |
| 1218 { | |
| 1219 GList *list; | |
| 1220 GaimAccount *account = NULL; | |
| 1221 GList *l; | |
| 1222 const char *protoname; | |
| 1223 | |
| 1224 if (all_accounts) | |
| 1225 list = gaim_accounts_get_all(); | |
| 1226 else | |
| 1227 list = gaim_connections_get_all(); | |
| 1228 | |
| 1229 for (l = list; l != NULL; l = l->next) | |
| 1230 { | |
| 1231 GaimConnection *gc; | |
| 1232 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 1233 GaimPlugin *plugin; | |
| 1234 | |
| 1235 if (all_accounts) | |
| 1236 { | |
| 1237 account = (GaimAccount *)l->data; | |
| 1238 | |
| 1239 plugin = gaim_plugins_find_with_id( | |
| 1240 gaim_account_get_protocol_id(account)); | |
| 1241 | |
| 1242 if (plugin == NULL) | |
| 1243 { | |
| 1244 account = NULL; | |
| 1245 | |
| 1246 continue; | |
| 1247 } | |
| 1248 | |
| 1249 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
| 1250 } | |
| 1251 else | |
| 1252 { | |
| 1253 gc = (GaimConnection *)l->data; | |
| 1254 account = gaim_connection_get_account(gc); | |
| 1255 | |
| 1256 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1257 } | |
| 1258 | |
| 1259 protoname = prpl_info->list_icon(account, NULL); | |
| 1260 | |
| 1261 if (!strcmp(protoname, protocol)) | |
| 1262 break; | |
| 1263 | |
| 1264 account = NULL; | |
| 1265 } | |
| 1266 | |
| 1267 /* Special case for AIM and ICQ */ | |
| 1268 if (account == NULL && (!strcmp(protocol, "aim") || | |
| 1269 !strcmp(protocol, "icq"))) | |
| 1270 { | |
| 1271 for (l = list; l != NULL; l = l->next) | |
| 1272 { | |
| 1273 GaimConnection *gc; | |
| 1274 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 1275 GaimPlugin *plugin; | |
| 1276 | |
| 1277 if (all_accounts) | |
| 1278 { | |
| 1279 account = (GaimAccount *)l->data; | |
| 1280 | |
| 1281 plugin = gaim_plugins_find_with_id( | |
| 1282 gaim_account_get_protocol_id(account)); | |
| 1283 | |
| 1284 if (plugin == NULL) | |
| 1285 { | |
| 1286 account = NULL; | |
| 1287 | |
| 1288 continue; | |
| 1289 } | |
| 1290 | |
| 1291 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
| 1292 } | |
| 1293 else | |
| 1294 { | |
| 1295 gc = (GaimConnection *)l->data; | |
| 1296 account = gaim_connection_get_account(gc); | |
| 1297 | |
| 1298 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1299 } | |
| 1300 | |
| 1301 protoname = prpl_info->list_icon(account, NULL); | |
| 1302 | |
| 1303 if (!strcmp(protoname, "aim") || !strcmp(protoname, "icq")) | |
| 1304 break; | |
| 1305 | |
| 1306 account = NULL; | |
| 1307 } | |
| 1308 } | |
| 1309 | |
| 1310 *ret_account = account; | |
| 1311 } | |
| 1312 } | |
| 1313 else | |
| 1314 { | |
| 1315 valid = FALSE; | |
| 1316 | |
| 1317 if (username != NULL) g_free(username); | |
| 1318 if (protocol != NULL) g_free(protocol); | |
| 1319 if (alias != NULL) g_free(alias); | |
| 1320 } | |
| 1321 | |
| 1322 g_free(str); | |
| 1323 | |
| 1324 return valid; | |
| 1325 } |
