Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/myspace.c @ 17944:c109b7f1c739
Allow setting status string messages. Known bug: custom status messages always
make you go away, instead of to what status primitive you set it to be.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Thu, 12 Jul 2007 03:21:07 +0000 |
parents | 949fddc9d82f |
children | cf55077a3752 |
comparison
equal
deleted
inserted
replaced
17943:12606e503d70 | 17944:c109b7f1c739 |
---|---|
70 | 70 |
71 purple_debug_info("myspace", "returning status types\n"); | 71 purple_debug_info("myspace", "returning status types\n"); |
72 | 72 |
73 types = NULL; | 73 types = NULL; |
74 | 74 |
75 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, NULL, NULL, FALSE, TRUE, FALSE); | 75 /* Statuses are almost all the same. Define a macro to reduce code repetition. */ |
76 types = g_list_append(types, status); | 76 #define _MSIM_ADD_NEW_STATUS(prim) status = \ |
77 | 77 purple_status_type_new_with_attrs( \ |
78 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, NULL, NULL, FALSE, TRUE, FALSE); | 78 prim, /* PurpleStatusPrimitive */ \ |
79 types = g_list_append(types, status); | 79 NULL, /* id - use default */ \ |
80 | 80 NULL, /* name - use default */ \ |
81 status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE); | 81 TRUE, /* savable */ \ |
82 types = g_list_append(types, status); | 82 TRUE, /* user_settable */ \ |
83 | 83 FALSE, /* not independent */ \ |
84 status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, NULL, NULL, FALSE, TRUE, FALSE); | 84 \ |
85 types = g_list_append(types, status); | 85 /* Attributes - each status can have a message. */ \ |
86 "message", \ | |
87 _("Message"), \ | |
88 purple_value_new(PURPLE_TYPE_STRING), \ | |
89 NULL); \ | |
90 \ | |
91 \ | |
92 types = g_list_append(types, status) | |
93 | |
94 | |
95 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE); | |
96 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY); | |
97 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE); | |
98 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE); | |
99 | |
86 | 100 |
87 return types; | 101 return types; |
88 } | 102 } |
89 | 103 |
90 /** | 104 /** |
203 * | 217 * |
204 */ | 218 */ |
205 gboolean | 219 gboolean |
206 msim_send_raw(MsimSession *session, const gchar *msg) | 220 msim_send_raw(MsimSession *session, const gchar *msg) |
207 { | 221 { |
208 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); | |
209 | |
210 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); | 222 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
211 g_return_val_if_fail(msg != NULL, FALSE); | 223 g_return_val_if_fail(msg != NULL, FALSE); |
224 | |
225 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); | |
212 | 226 |
213 return msim_send_really_raw(session->gc, msg, strlen(msg)) == | 227 return msim_send_really_raw(session->gc, msg, strlen(msg)) == |
214 strlen(msg); | 228 strlen(msg); |
215 } | 229 } |
216 | 230 |
1320 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg); | 1334 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg); |
1321 | 1335 |
1322 g_free(user_to_lookup); | 1336 g_free(user_to_lookup); |
1323 } | 1337 } |
1324 | 1338 |
1325 /** Set your status - callback for when user manually sets it. */ | 1339 /** Set your status - callback for when user manually sets it. |
1340 * TODO: find out why when setting status with a message, it ALWAYS goes to away! */ | |
1326 void | 1341 void |
1327 msim_set_status(PurpleAccount *account, PurpleStatus *status) | 1342 msim_set_status(PurpleAccount *account, PurpleStatus *status) |
1328 { | 1343 { |
1329 PurpleStatusType *type; | 1344 PurpleStatusType *type; |
1330 MsimSession *session; | 1345 MsimSession *session; |
1331 guint status_code; | 1346 guint status_code; |
1347 const gchar *statstring; | |
1332 | 1348 |
1333 session = (MsimSession *)account->gc->proto_data; | 1349 session = (MsimSession *)account->gc->proto_data; |
1334 | 1350 |
1335 g_return_if_fail(MSIM_SESSION_VALID(session)); | 1351 g_return_if_fail(MSIM_SESSION_VALID(session)); |
1336 | 1352 |
1337 type = purple_status_get_type(status); | 1353 type = purple_status_get_type(status); |
1338 | 1354 |
1339 switch (purple_status_type_get_primitive(type)) | 1355 switch (purple_status_type_get_primitive(type)) |
1340 { | 1356 { |
1341 case PURPLE_STATUS_AVAILABLE: | 1357 case PURPLE_STATUS_AVAILABLE: |
1358 purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE, | |
1359 MSIM_STATUS_CODE_ONLINE); | |
1342 status_code = MSIM_STATUS_CODE_ONLINE; | 1360 status_code = MSIM_STATUS_CODE_ONLINE; |
1343 break; | 1361 break; |
1344 | 1362 |
1345 case PURPLE_STATUS_INVISIBLE: | 1363 case PURPLE_STATUS_INVISIBLE: |
1364 purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE, | |
1365 MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN); | |
1346 status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN; | 1366 status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN; |
1347 break; | 1367 break; |
1348 | 1368 |
1349 case PURPLE_STATUS_AWAY: | 1369 case PURPLE_STATUS_AWAY: |
1370 purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY, | |
1371 MSIM_STATUS_CODE_AWAY); | |
1350 status_code = MSIM_STATUS_CODE_AWAY; | 1372 status_code = MSIM_STATUS_CODE_AWAY; |
1351 break; | 1373 break; |
1352 | 1374 |
1353 default: | 1375 default: |
1354 purple_debug_info("msim", "msim_set_status: unknown " | 1376 purple_debug_info("msim", "msim_set_status: unknown " |
1355 "status interpreting as online"); | 1377 "status interpreting as online"); |
1356 status_code = MSIM_STATUS_CODE_ONLINE; | 1378 status_code = MSIM_STATUS_CODE_ONLINE; |
1357 break; | 1379 break; |
1358 } | 1380 } |
1359 | 1381 |
1360 | 1382 statstring = purple_status_get_attr_string(status, "message"); |
1361 msim_set_status_code(session, status_code); | 1383 |
1384 if (!statstring) | |
1385 statstring = g_strdup(""); | |
1386 | |
1387 msim_set_status_code(session, status_code, g_strdup(statstring)); | |
1362 } | 1388 } |
1363 | 1389 |
1364 /** Go idle. */ | 1390 /** Go idle. */ |
1365 void | 1391 void |
1366 msim_set_idle(PurpleConnection *gc, int time) | 1392 msim_set_idle(PurpleConnection *gc, int time) |
1377 { | 1403 { |
1378 /* Going back from idle. In msim, idle is mutually exclusive | 1404 /* Going back from idle. In msim, idle is mutually exclusive |
1379 * from the other states (you can only be away or idle, but not | 1405 * from the other states (you can only be away or idle, but not |
1380 * both, for example), so by going non-idle I go online. | 1406 * both, for example), so by going non-idle I go online. |
1381 */ | 1407 */ |
1382 msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE); | 1408 /* TODO: find out how to keep old status string? */ |
1409 msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup("")); | |
1383 } else { | 1410 } else { |
1384 /* msim doesn't support idle time, so just go idle */ | 1411 /* msim doesn't support idle time, so just go idle */ |
1385 msim_set_status_code(session, MSIM_STATUS_CODE_IDLE); | 1412 msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup("")); |
1386 } | 1413 } |
1387 } | 1414 } |
1388 | 1415 |
1389 /** Set status using an MSIM_STATUS_CODE_* value. (TODO: also set message) */ | 1416 /** Set status using an MSIM_STATUS_CODE_* value. |
1417 * @param status_code An MSIM_STATUS_CODE_* value. | |
1418 * @param statstring Status string, must be a dynamic string (will be freed by msim_send). | |
1419 */ | |
1390 void | 1420 void |
1391 msim_set_status_code(MsimSession *session, guint status_code) | 1421 msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring) |
1392 { | 1422 { |
1393 g_return_if_fail(MSIM_SESSION_VALID(session)); | 1423 g_return_if_fail(MSIM_SESSION_VALID(session)); |
1424 | |
1425 purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n", | |
1426 status_code, statstring); | |
1394 | 1427 |
1395 if (!msim_send(session, | 1428 if (!msim_send(session, |
1396 "status", MSIM_TYPE_INTEGER, status_code, | 1429 "status", MSIM_TYPE_INTEGER, status_code, |
1397 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, | 1430 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
1398 "statstring", MSIM_TYPE_STRING, g_strdup(""), | 1431 "statstring", MSIM_TYPE_STRING, statstring, |
1399 "locstring", MSIM_TYPE_STRING, g_strdup(""), | 1432 "locstring", MSIM_TYPE_STRING, g_strdup(""), |
1400 NULL)) | 1433 NULL)) |
1401 { | 1434 { |
1402 purple_debug_info("msim", "msim_set_status: failed to set status"); | 1435 purple_debug_info("msim", "msim_set_status: failed to set status"); |
1403 } | 1436 } |
1658 * which is weird, but happens because you login with your email | 1691 * which is weird, but happens because you login with your email |
1659 * address and not username. Will be freed in msim_session_destroy(). */ | 1692 * address and not username. Will be freed in msim_session_destroy(). */ |
1660 session->username = msim_msg_get_string(msg, "uniquenick"); | 1693 session->username = msim_msg_get_string(msg, "uniquenick"); |
1661 | 1694 |
1662 #ifdef MSIM_FAKE_SELF_ONLINE | 1695 #ifdef MSIM_FAKE_SELF_ONLINE |
1663 /* Fake our self coming online. */ | 1696 purple_debug_info("msim", "msim_we_are_logged_on: faking self as coming online\n"); |
1664 purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); | 1697 /* Fake our self coming online. TODO: do we need this anymore?! */ |
1698 purple_prpl_got_user_status(session->account, session->username, | |
1699 purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); | |
1665 #endif | 1700 #endif |
1666 | 1701 |
1702 purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n"); | |
1667 /* Notify servers of our current status. */ | 1703 /* Notify servers of our current status. */ |
1668 msim_set_status(session->account, | 1704 msim_set_status(session->account, |
1669 purple_account_get_active_status(session->account)); | 1705 purple_account_get_active_status(session->account)); |
1670 | 1706 |
1671 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, msim_check_alive, session); | 1707 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, msim_check_alive, session); |