comparison libpurple/protocols/myspace/myspace.c @ 17963:8305709dd0b9

Allow sending zaps through buddy list menu.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 21 Jul 2007 07:53:22 +0000
parents 8e351e08aba0
children e3687194f2b2
comparison
equal deleted inserted replaced
17962:8e351e08aba0 17963:8305709dd0b9
130 130
131 131
132 return types; 132 return types;
133 } 133 }
134 134
135 /** Zap someone. Callback from msim_blist_node_menu zap menu. */
136 void
137 msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr)
138 {
139 PurpleBuddy *buddy;
140 PurpleConnection *gc;
141 MsimSession *session;
142 gchar *username, *zap_string, *zap_text;
143 guint zap;
144 const gchar *zap_gerund[10];
145
146 if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
147 {
148 /* Only know about buddies for now. */
149 return;
150 }
151
152 zap_gerund[0] = _("Zapping");
153 zap_gerund[1] = _("Whacking");
154 zap_gerund[2] = _("Torching");
155 zap_gerund[3] = _("Smooching");
156 zap_gerund[4] = _("Hugging");
157 zap_gerund[5] = _("Bslapping");
158 zap_gerund[6] = _("Goosing");
159 zap_gerund[7] = _("Hi-fiving");
160 zap_gerund[8] = _("Punking");
161 zap_gerund[9] = _("Raspberry'ing");
162
163 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
164
165 buddy = (PurpleBuddy *)node;
166 gc = purple_account_get_connection(buddy->account);
167 g_return_if_fail(gc != NULL);
168
169 session = (MsimSession *)(gc->proto_data);
170 g_return_if_fail(session != NULL);
171
172 username = buddy->name;
173 g_return_if_fail(username != NULL);
174
175 zap = GPOINTER_TO_INT(zap_num_ptr);
176 zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", zap);
177 zap_text = g_strdup_printf("*** %s! ***", zap_gerund[zap]);
178
179 serv_got_im(session->gc, username, zap_text,
180 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL));
181
182 if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION))
183 {
184 purple_debug_info("msim_send_zap", "msim_send_bm failed: zapping %s with %s",
185 username, zap_string);
186 }
187
188 g_free(zap_string);
189 g_free(zap_text);
190 return;
191 }
192
193
194 /** Return menu, if any, for a buddy list node. */
195 GList *
196 msim_blist_node_menu(PurpleBlistNode *node)
197 {
198 GList *menu, *zap_menu;
199 PurpleMenuAction *act;
200 const gchar *zap_names[10];
201 guint i;
202
203 if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
204 {
205 /* Only know about buddies for now. */
206 return NULL;
207 }
208
209 /* Names from official client. */
210 zap_names[0] = _("zap");
211 zap_names[1] = _("whack");
212 zap_names[2] = _("torch");
213 zap_names[3] = _("smooch");
214 zap_names[4] = _("hug");
215 zap_names[5] = _("bslap");
216 zap_names[6] = _("goose");
217 zap_names[7] = _("hi-five");
218 zap_names[8] = _("punk'd");
219 zap_names[9] = _("raspberry");
220
221 menu = zap_menu = NULL;
222
223 for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i)
224 {
225 act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap),
226 GUINT_TO_POINTER(i), NULL);
227 zap_menu = g_list_append(zap_menu, act);
228 }
229
230 act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu);
231 menu = g_list_append(menu, act);
232
233 return menu;
234 }
235
135 /** 236 /**
136 * Return the icon name for a buddy and account. 237 * Return the icon name for a buddy and account.
137 * 238 *
138 * @param acct The account to find the icon for, or NULL for protocol icon. 239 * @param acct The account to find the icon for, or NULL for protocol icon.
139 * @param buddy The buddy to find the icon for, or NULL for the account icon. 240 * @param buddy The buddy to find the icon for, or NULL for the account icon.
1302 gboolean 1403 gboolean
1303 msim_incoming_zap(MsimSession *session, MsimMessage *msg) 1404 msim_incoming_zap(MsimSession *session, MsimMessage *msg)
1304 { 1405 {
1305 gchar *msg_text, *username, *zap_text; 1406 gchar *msg_text, *username, *zap_text;
1306 gint zap; 1407 gint zap;
1307 /* Names from official client dropdown menu. */ 1408 const gchar *zap_past_tense[10];
1308 static const gchar *zap_names[] =
1309 {
1310 "zap", "whack", "torch", "smooch", "hug", "bslap", "goose",
1311 "hi-five", "punk'd", "raspberry"
1312 };
1313 const gchar *zap_past_tense[sizeof(zap_names) / sizeof(zap_names[0])];
1314 1409
1315 zap_past_tense[0] = _("zapped"); 1410 zap_past_tense[0] = _("zapped");
1316 zap_past_tense[1] = _("whacked"); 1411 zap_past_tense[1] = _("whacked");
1317 zap_past_tense[2] = _("torched"); 1412 zap_past_tense[2] = _("torched");
1318 zap_past_tense[3] = _("smooched"); 1413 zap_past_tense[3] = _("smooched");
1331 1426
1332 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE); 1427 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE);
1333 1428
1334 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0])); 1429 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0]));
1335 1430
1336 zap_text = g_strdup_printf(_("You have been %s!"), zap_past_tense[zap]); 1431 zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]);
1337 1432
1338 serv_got_im(session->gc, username, zap_text, 1433 serv_got_im(session->gc, username, zap_text,
1339 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL)); 1434 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL));
1340 1435
1341 g_free(zap_text); 1436 g_free(zap_text);
3367 msim_list_icon, /* list_icon */ 3462 msim_list_icon, /* list_icon */
3368 NULL, /* list_emblems */ 3463 NULL, /* list_emblems */
3369 msim_status_text, /* status_text */ 3464 msim_status_text, /* status_text */
3370 msim_tooltip_text, /* tooltip_text */ 3465 msim_tooltip_text, /* tooltip_text */
3371 msim_status_types, /* status_types */ 3466 msim_status_types, /* status_types */
3372 NULL, /* blist_node_menu */ 3467 msim_blist_node_menu, /* blist_node_menu */
3373 NULL, /* chat_info */ 3468 NULL, /* chat_info */
3374 NULL, /* chat_info_defaults */ 3469 NULL, /* chat_info_defaults */
3375 msim_login, /* login */ 3470 msim_login, /* login */
3376 msim_close, /* close */ 3471 msim_close, /* close */
3377 msim_send_im, /* send_im */ 3472 msim_send_im, /* send_im */