libpurple/protocols/demo/purpledemoprotocolactions.c

changeset 42101
f22bea74160d
parent 42004
620d1adf91f2
child 42105
e431d160e3a1
equal deleted inserted replaced
42100:470d4d3c6faf 42101:f22bea74160d
18 18
19 #include <glib/gi18n-lib.h> 19 #include <glib/gi18n-lib.h>
20 20
21 #include "purpledemoprotocol.h" 21 #include "purpledemoprotocol.h"
22 #include "purpledemoprotocolactions.h" 22 #include "purpledemoprotocolactions.h"
23 #include "purpledemoresource.h"
23 24
24 /****************************************************************************** 25 /******************************************************************************
25 * Action Implementations 26 * Connection failure action implementations
26 *****************************************************************************/ 27 *****************************************************************************/
27 #define REAPER_BUDDY_NAME ("Gary") 28 #define REAPER_BUDDY_NAME ("Gary")
28 #define DEFAULT_REAP_TIME (5) /* seconds */ 29 #define DEFAULT_REAP_TIME (5) /* seconds */
29 #define FATAL_TICK_STR N_("Reaping connection in %d second...") 30 #define FATAL_TICK_STR N_("Reaping connection in %d second...")
30 #define FATAL_TICK_PLURAL_STR N_("Reaping connection in %d seconds...") 31 #define FATAL_TICK_PLURAL_STR N_("Reaping connection in %d seconds...")
31 #define FATAL_DISCONNECT_STR N_("%s reaped the connection") 32 #define FATAL_DISCONNECT_STR N_("%s reaped the connection")
32 #define TEMPORARY_TICK_STR N_("Pruning connection in %d second...") 33 #define TEMPORARY_TICK_STR N_("Pruning connection in %d second...")
33 #define TEMPORARY_TICK_PLURAL_STR N_("Pruning connection in %d seconds...") 34 #define TEMPORARY_TICK_PLURAL_STR N_("Pruning connection in %d seconds...")
34 #define TEMPORARY_DISCONNECT_STR N_("%s pruned the connection") 35 #define TEMPORARY_DISCONNECT_STR N_("%s pruned the connection")
35 36
36 static const gchar *contacts[] = {"Alice", "Bob", "Carlos", "Erin" };
37
38 static void
39 purple_demo_protocol_remote_add(G_GNUC_UNUSED GSimpleAction *action,
40 GVariant *parameter,
41 G_GNUC_UNUSED gpointer data)
42 {
43 PurpleAccount *account = NULL;
44 PurpleAccountManager *account_manager = NULL;
45 PurpleAddContactRequest *request = NULL;
46 PurpleNotification *notification = NULL;
47 PurpleNotificationManager *notification_manager = NULL;
48 const gchar *account_id = NULL;
49 static guint counter = 0;
50
51 account_id = g_variant_get_string(parameter, NULL);
52 account_manager = purple_account_manager_get_default();
53 account = purple_account_manager_find_by_id(account_manager, account_id);
54
55 request = purple_add_contact_request_new(account, contacts[counter]);
56 notification = purple_notification_new_from_add_contact_request(request);
57
58 notification_manager = purple_notification_manager_get_default();
59 purple_notification_manager_add(notification_manager, notification);
60
61 counter++;
62 if(counter >= G_N_ELEMENTS(contacts)) {
63 counter = 0;
64 }
65 }
66
67 static gboolean 37 static gboolean
68 purple_demo_protocol_failure_tick(gpointer data, 38 purple_demo_protocol_failure_tick(gpointer data,
69 PurpleConnectionError error_code, 39 PurpleConnectionError error_code,
70 const gchar *tick_str, 40 const gchar *tick_str,
71 const gchar *tick_plural_str, 41 const gchar *tick_plural_str,
131 gchar *status = NULL; 101 gchar *status = NULL;
132 102
133 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) { 103 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
134 g_critical("Demo failure action parameter is of incorrect type %s", 104 g_critical("Demo failure action parameter is of incorrect type %s",
135 g_variant_get_type_string(parameter)); 105 g_variant_get_type_string(parameter));
106 return;
136 } 107 }
137 108
138 account_id = g_variant_get_string(parameter, NULL); 109 account_id = g_variant_get_string(parameter, NULL);
139 manager = purple_account_manager_get_default(); 110 manager = purple_account_manager_get_default();
140 account = purple_account_manager_find_by_id(manager, account_id); 111 account = purple_account_manager_find_by_id(manager, account_id);
182 FATAL_TICK_PLURAL_STR, 153 FATAL_TICK_PLURAL_STR,
183 purple_demo_protocol_fatal_failure_cb); 154 purple_demo_protocol_fatal_failure_cb);
184 } 155 }
185 156
186 /****************************************************************************** 157 /******************************************************************************
158 * Request API action implementations
159 *****************************************************************************/
160
161 static void
162 purple_demo_protocol_request_input_ok_cb(G_GNUC_UNUSED gpointer data,
163 const char *value)
164 {
165 g_message(_("Successfully requested input from UI: %s"), value);
166 }
167
168 static void
169 purple_demo_protocol_request_input_cancel_cb(G_GNUC_UNUSED gpointer data,
170 G_GNUC_UNUSED const char *value)
171 {
172 g_message(_("UI cancelled input request"));
173 }
174
175 static void
176 purple_demo_protocol_request_input_activate(G_GNUC_UNUSED GSimpleAction *action,
177 GVariant *parameter,
178 G_GNUC_UNUSED gpointer data)
179 {
180 PurpleConnection *connection = NULL;
181 const gchar *account_id = NULL;
182 PurpleAccountManager *manager = NULL;
183 PurpleAccount *account = NULL;
184 static int form = 0;
185 gboolean multiline = FALSE, masked = FALSE;
186 char *secondary = NULL;
187
188 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
189 g_critical("Demo failure action parameter is of incorrect type %s",
190 g_variant_get_type_string(parameter));
191 return;
192 }
193
194 account_id = g_variant_get_string(parameter, NULL);
195 manager = purple_account_manager_get_default();
196 account = purple_account_manager_find_by_id(manager, account_id);
197 connection = purple_account_get_connection(account);
198
199 /* Alternate through all four combinations of {masked, multiline}. */
200 masked = form % 2 == 1;
201 multiline = (form / 2) % 2 == 1;
202 form++;
203 secondary = g_strdup_printf(_("The input will be %s %s."),
204 masked ? "masked" : "unmasked",
205 multiline ? "multiple lines" : "single line");
206
207 purple_request_input(connection, _("Request Input Demo"),
208 _("Please input some text…"), secondary, _("default"),
209 multiline, masked, NULL,
210 _("OK"),
211 G_CALLBACK(purple_demo_protocol_request_input_ok_cb),
212 _("Cancel"),
213 G_CALLBACK(purple_demo_protocol_request_input_cancel_cb),
214 purple_request_cpar_from_connection(connection), NULL);
215 }
216
217 static void
218 purple_demo_protocol_request_choice_ok_cb(G_GNUC_UNUSED gpointer data,
219 gpointer value)
220 {
221 const char *text = value;
222
223 g_message(_("Successfully requested a choice from UI: %s"), text);
224 }
225
226 static void
227 purple_demo_protocol_request_choice_cancel_cb(G_GNUC_UNUSED gpointer data,
228 G_GNUC_UNUSED gpointer value)
229 {
230 g_message(_("UI cancelled choice request"));
231 }
232
233 static void
234 purple_demo_protocol_request_choice_activate(G_GNUC_UNUSED GSimpleAction *action,
235 GVariant *parameter,
236 G_GNUC_UNUSED gpointer data)
237 {
238 PurpleConnection *connection = NULL;
239 const gchar *account_id = NULL;
240 PurpleAccountManager *manager = NULL;
241 PurpleAccount *account = NULL;
242
243 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
244 g_critical("Demo failure action parameter is of incorrect type %s",
245 g_variant_get_type_string(parameter));
246 return;
247 }
248
249 account_id = g_variant_get_string(parameter, NULL);
250 manager = purple_account_manager_get_default();
251 account = purple_account_manager_find_by_id(manager, account_id);
252 connection = purple_account_get_connection(account);
253
254 purple_request_choice(connection, _("Request Choice Demo"),
255 _("Please pick an option…"), NULL, _("foo"),
256 _("OK"),
257 G_CALLBACK(purple_demo_protocol_request_choice_ok_cb),
258 _("Cancel"),
259 G_CALLBACK(purple_demo_protocol_request_choice_cancel_cb),
260 purple_request_cpar_from_connection(connection),
261 NULL, _("foo"), "foo", _("bar"), "bar",
262 _("baz"), "baz", NULL);
263 }
264
265 static void
266 purple_demo_protocol_request_action_cb(G_GNUC_UNUSED gpointer data, int action)
267 {
268 g_message(_("Successfully requested an action from the UI: %d"), action);
269 }
270
271 static void
272 purple_demo_protocol_request_action_activate(G_GNUC_UNUSED GSimpleAction *action,
273 GVariant *parameter,
274 G_GNUC_UNUSED gpointer data)
275 {
276 PurpleConnection *connection = NULL;
277 const gchar *account_id = NULL;
278 PurpleAccountManager *manager = NULL;
279 PurpleAccount *account = NULL;
280
281 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
282 g_critical("Demo failure action parameter is of incorrect type %s",
283 g_variant_get_type_string(parameter));
284 return;
285 }
286
287 account_id = g_variant_get_string(parameter, NULL);
288 manager = purple_account_manager_get_default();
289 account = purple_account_manager_find_by_id(manager, account_id);
290 connection = purple_account_get_connection(account);
291
292 purple_request_action(connection, _("Request Action Demo"),
293 _("Please choose an action…"), NULL, 1,
294 purple_request_cpar_from_connection(connection),
295 NULL, 3,
296 _("foo"), purple_demo_protocol_request_action_cb,
297 _("bar"), purple_demo_protocol_request_action_cb,
298 _("baz"), purple_demo_protocol_request_action_cb);
299 }
300
301 typedef struct {
302 gint id;
303 gpointer ui_handle;
304 } PurpleDemoProtocolWaitData;
305
306 static gboolean
307 purple_demo_protocol_request_wait_pulse_cb(gpointer data) {
308 PurpleDemoProtocolWaitData *wait = data;
309
310 purple_request_wait_pulse(wait->ui_handle);
311
312 return G_SOURCE_CONTINUE;
313 }
314
315 static void
316 purple_demo_protocol_request_wait_cancel_cb(G_GNUC_UNUSED gpointer data) {
317 g_message(_("UI cancelled wait request"));
318 }
319
320 static void
321 purple_demo_protocol_request_wait_close_cb(gpointer data) {
322 PurpleDemoProtocolWaitData *wait = data;
323
324 g_source_remove(wait->id);
325 g_free(wait);
326 }
327
328 static void
329 purple_demo_protocol_request_wait_activate(G_GNUC_UNUSED GSimpleAction *action,
330 GVariant *parameter,
331 G_GNUC_UNUSED gpointer data)
332 {
333 PurpleConnection *connection = NULL;
334 const gchar *account_id = NULL;
335 PurpleAccountManager *manager = NULL;
336 PurpleAccount *account = NULL;
337 PurpleDemoProtocolWaitData *wait = NULL;
338
339 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
340 g_critical("Demo failure action parameter is of incorrect type %s",
341 g_variant_get_type_string(parameter));
342 return;
343 }
344
345 account_id = g_variant_get_string(parameter, NULL);
346 manager = purple_account_manager_get_default();
347 account = purple_account_manager_find_by_id(manager, account_id);
348 connection = purple_account_get_connection(account);
349
350 wait = g_new0(PurpleDemoProtocolWaitData, 1);
351
352 wait->ui_handle = purple_request_wait(connection, _("Request Wait Demo"),
353 _("Please wait…"), NULL, TRUE,
354 purple_demo_protocol_request_wait_cancel_cb,
355 purple_request_cpar_from_connection(connection),
356 wait);
357
358 wait->id = g_timeout_add(250, purple_demo_protocol_request_wait_pulse_cb,
359 wait);
360
361 purple_request_add_close_notify(wait->ui_handle,
362 purple_demo_protocol_request_wait_close_cb,
363 wait);
364 }
365
366 static void
367 purple_demo_protocol_request_fields_ok_cb(G_GNUC_UNUSED gpointer data,
368 PurpleRequestFields *fields)
369 {
370 PurpleAccount *account = NULL;
371 PurpleRequestField *field = NULL;
372 GList *list = NULL;
373 const char *tmp = NULL;
374 GString *info = NULL;
375
376 info = g_string_new(_("Basic group:\n"));
377
378 g_string_append_printf(info, _("\tString: %s\n"),
379 purple_request_fields_get_string(fields, "string"));
380 g_string_append_printf(info, _("\tMultiline string: %s\n"),
381 purple_request_fields_get_string(fields,
382 "multiline-string"));
383 g_string_append_printf(info, _("\tMasked string: %s\n"),
384 purple_request_fields_get_string(fields,
385 "masked-string"));
386 g_string_append_printf(info, _("\tAlphanumeric string: %s\n"),
387 purple_request_fields_get_string(fields,
388 "alphanumeric"));
389 g_string_append_printf(info, _("\tEmail string: %s\n"),
390 purple_request_fields_get_string(fields, "email"));
391 g_string_append_printf(info, _("\tInteger: %d\n"),
392 purple_request_fields_get_integer(fields, "int"));
393 g_string_append_printf(info, _("\tBoolean: %s\n"),
394 purple_request_fields_get_bool(fields, "bool") ?
395 _("TRUE") : _("FALSE"));
396
397 g_string_append(info, _("Multiple-choice group:\n"));
398
399 tmp = (const char *)purple_request_fields_get_choice(fields, "choice");
400 g_string_append_printf(info, _("\tChoice: %s\n"), tmp);
401
402 field = purple_request_fields_get_field(fields, "list");
403 list = purple_request_field_list_get_selected(field);
404 if(list != NULL) {
405 tmp = (const char *)list->data;
406 } else {
407 tmp = _("(unset)");
408 }
409 g_string_append_printf(info, _("\tList: %s\n"), tmp);
410
411 field = purple_request_fields_get_field(fields, "multilist");
412 list = purple_request_field_list_get_selected(field);
413 g_string_append(info, _("\tMulti-list: ["));
414 while(list != NULL) {
415 tmp = (const char *)list->data;
416 g_string_append_printf(info, "%s%s", tmp,
417 list->next != NULL ? ", " : "");
418 list = list->next;
419 }
420 g_string_append(info, _("]\n"));
421
422 g_string_append(info, _("Special group:\n"));
423
424 account = purple_request_fields_get_account(fields, "account");
425 if(PURPLE_IS_ACCOUNT(account)) {
426 tmp = purple_contact_info_get_name_for_display(PURPLE_CONTACT_INFO(account));
427 } else {
428 tmp = _("(unset)");
429 }
430 g_string_append_printf(info, _("\tAccount: %s\n"), tmp);
431
432 g_message(_("Successfully requested fields:\n%s"), info->str);
433
434 g_string_free(info, TRUE);
435 }
436
437 static void
438 purple_demo_protocol_request_fields_cancel_cb(G_GNUC_UNUSED gpointer data,
439 G_GNUC_UNUSED PurpleRequestFields *fields)
440 {
441 g_message(_("UI cancelled field request"));
442 }
443
444 static void
445 purple_demo_protocol_request_fields_activate(G_GNUC_UNUSED GSimpleAction *action,
446 GVariant *parameter,
447 G_GNUC_UNUSED gpointer data)
448 {
449 PurpleConnection *connection = NULL;
450 const gchar *account_id = NULL;
451 PurpleAccountManager *manager = NULL;
452 PurpleAccount *account = NULL;
453 PurpleRequestFields *fields = NULL;
454 PurpleRequestFieldGroup *group = NULL;
455 PurpleRequestField *field = NULL;
456 GBytes *icon = NULL;
457 gconstpointer icon_data = NULL;
458 gsize icon_len = 0;
459
460 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
461 g_critical("Demo failure action parameter is of incorrect type %s",
462 g_variant_get_type_string(parameter));
463 return;
464 }
465
466 account_id = g_variant_get_string(parameter, NULL);
467 manager = purple_account_manager_get_default();
468 account = purple_account_manager_find_by_id(manager, account_id);
469 connection = purple_account_get_connection(account);
470
471 fields = purple_request_fields_new();
472
473 /* This group will contain basic fields. */
474 group = purple_request_field_group_new(_("Basic"));
475 purple_request_fields_add_group(fields, group);
476
477 field = purple_request_field_label_new("basic-label",
478 _("This group contains basic fields"));
479 purple_request_field_group_add_field(group, field);
480
481 field = purple_request_field_string_new("string", _("A string"),
482 _("default"), FALSE);
483 purple_request_field_group_add_field(group, field);
484 field = purple_request_field_string_new("multiline-string",
485 _("A multiline string"),
486 _("default"), TRUE);
487 purple_request_field_group_add_field(group, field);
488 field = purple_request_field_string_new("masked-string",
489 _("A masked string"), _("default"),
490 FALSE);
491 purple_request_field_string_set_masked(field, TRUE);
492 purple_request_field_group_add_field(group, field);
493 field = purple_request_field_string_new("alphanumeric",
494 _("An alphanumeric string"),
495 _("default"), FALSE);
496 purple_request_field_set_validator(field,
497 purple_request_field_alphanumeric_validator,
498 NULL);
499 purple_request_field_group_add_field(group, field);
500 field = purple_request_field_string_new("email", _("An email"),
501 _("me@example.com"), FALSE);
502 purple_request_field_set_validator(field,
503 purple_request_field_email_validator,
504 NULL);
505 purple_request_field_group_add_field(group, field);
506 field = purple_request_field_int_new("int", _("An integer"), 123, -42, 1337);
507 purple_request_field_group_add_field(group, field);
508 field = purple_request_field_bool_new("bool", _("A boolean"), FALSE);
509 purple_request_field_group_add_field(group, field);
510
511 /* This group will contain fields with multiple options. */
512 group = purple_request_field_group_new(_("Multiple"));
513 purple_request_fields_add_group(fields, group);
514
515 field = purple_request_field_label_new("multiple-label",
516 _("This group contains fields with multiple options"));
517 purple_request_field_group_add_field(group, field);
518
519 field = purple_request_field_choice_new("choice", _("A choice"), "foo");
520 purple_request_field_choice_add(field, _("foo"), "foo");
521 purple_request_field_choice_add(field, _("bar"), "bar");
522 purple_request_field_choice_add(field, _("baz"), "baz");
523 purple_request_field_choice_add(field, _("quux"), "quux");
524 purple_request_field_group_add_field(group, field);
525
526 field = purple_request_field_list_new("list", _("A list"));
527 purple_request_field_list_add_icon(field, _("foo"), NULL, "foo");
528 purple_request_field_list_add_icon(field, _("bar"), NULL, "bar");
529 purple_request_field_list_add_icon(field, _("baz"), NULL, "baz");
530 purple_request_field_list_add_icon(field, _("quux"), NULL, "quux");
531 purple_request_field_group_add_field(group, field);
532
533 field = purple_request_field_list_new("multilist", _("A multi-select list"));
534 purple_request_field_list_set_multi_select(field, TRUE);
535 purple_request_field_list_add_icon(field, _("foo"), NULL, "foo");
536 purple_request_field_list_add_icon(field, _("bar"), NULL, "bar");
537 purple_request_field_list_add_icon(field, _("baz"), NULL, "baz");
538 purple_request_field_list_add_icon(field, _("quux"), NULL, "quux");
539 purple_request_field_group_add_field(group, field);
540
541 /* This group will contain specialized fields. */
542 group = purple_request_field_group_new(_("Special"));
543 purple_request_fields_add_group(fields, group);
544
545 field = purple_request_field_label_new("special-label",
546 _("This group contains specialized fields"));
547 purple_request_field_group_add_field(group, field);
548
549 icon = g_resource_lookup_data(purple_demo_get_resource(),
550 "/im/pidgin/purple/demo/icons/scalable/apps/im-purple-demo.svg",
551 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
552 icon_data = g_bytes_get_data(icon, &icon_len);
553 field = purple_request_field_image_new("image", _("An image"),
554 icon_data, icon_len);
555 purple_request_field_group_add_field(group, field);
556 g_bytes_unref(icon);
557
558 field = purple_request_field_account_new("account", _("An account"),
559 account);
560 purple_request_field_group_add_field(group, field);
561
562 purple_request_fields(connection, _("Request Fields Demo"),
563 _("Please fill out these fields…"), NULL, fields,
564 _("OK"),
565 G_CALLBACK(purple_demo_protocol_request_fields_ok_cb),
566 _("Cancel"),
567 G_CALLBACK(purple_demo_protocol_request_fields_cancel_cb),
568 purple_request_cpar_from_connection(connection),
569 NULL);
570 }
571
572 static void
573 purple_demo_protocol_request_path_ok_cb(gpointer data, const char *filename) {
574 const char *type = data;
575
576 g_message(_("Successfully requested %s from UI: %s"), type, filename);
577 }
578
579 static void
580 purple_demo_protocol_request_path_cancel_cb(gpointer data) {
581 const char *type = data;
582
583 g_message(_("UI cancelled %s request"), type);
584 }
585
586 static void
587 purple_demo_protocol_request_file_activate(G_GNUC_UNUSED GSimpleAction *action,
588 GVariant *parameter,
589 G_GNUC_UNUSED gpointer data)
590 {
591 PurpleConnection *connection = NULL;
592 const gchar *account_id = NULL;
593 PurpleAccountManager *manager = NULL;
594 PurpleAccount *account = NULL;
595
596 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
597 g_critical("Demo failure action parameter is of incorrect type %s",
598 g_variant_get_type_string(parameter));
599 return;
600 }
601
602 account_id = g_variant_get_string(parameter, NULL);
603 manager = purple_account_manager_get_default();
604 account = purple_account_manager_find_by_id(manager, account_id);
605 connection = purple_account_get_connection(account);
606
607 purple_request_file(connection, _("Request File Demo"),
608 "example.txt", FALSE,
609 G_CALLBACK(purple_demo_protocol_request_path_ok_cb),
610 G_CALLBACK(purple_demo_protocol_request_path_cancel_cb),
611 purple_request_cpar_from_connection(connection),
612 "file");
613 }
614
615 static void
616 purple_demo_protocol_request_folder_activate(G_GNUC_UNUSED GSimpleAction *action,
617 GVariant *parameter,
618 G_GNUC_UNUSED gpointer data)
619 {
620 PurpleConnection *connection = NULL;
621 const gchar *account_id = NULL;
622 PurpleAccountManager *manager = NULL;
623 PurpleAccount *account = NULL;
624
625 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
626 g_critical("Demo failure action parameter is of incorrect type %s",
627 g_variant_get_type_string(parameter));
628 return;
629 }
630
631 account_id = g_variant_get_string(parameter, NULL);
632 manager = purple_account_manager_get_default();
633 account = purple_account_manager_find_by_id(manager, account_id);
634 connection = purple_account_get_connection(account);
635
636 purple_request_folder(connection, _("Request Folder Demo"), NULL,
637 G_CALLBACK(purple_demo_protocol_request_path_ok_cb),
638 G_CALLBACK(purple_demo_protocol_request_path_cancel_cb),
639 purple_request_cpar_from_connection(connection),
640 "folder");
641 }
642
643 /******************************************************************************
644 * Contact action implementations
645 *****************************************************************************/
646 static const gchar *contacts[] = {"Alice", "Bob", "Carlos", "Erin" };
647
648 static void
649 purple_demo_protocol_remote_add(G_GNUC_UNUSED GSimpleAction *action,
650 GVariant *parameter,
651 G_GNUC_UNUSED gpointer data)
652 {
653 PurpleAccount *account = NULL;
654 PurpleAccountManager *account_manager = NULL;
655 PurpleAddContactRequest *request = NULL;
656 PurpleNotification *notification = NULL;
657 PurpleNotificationManager *notification_manager = NULL;
658 const gchar *account_id = NULL;
659 static guint counter = 0;
660
661 account_id = g_variant_get_string(parameter, NULL);
662 account_manager = purple_account_manager_get_default();
663 account = purple_account_manager_find_by_id(account_manager, account_id);
664
665 request = purple_add_contact_request_new(account, contacts[counter]);
666 notification = purple_notification_new_from_add_contact_request(request);
667
668 notification_manager = purple_notification_manager_get_default();
669 purple_notification_manager_add(notification_manager, notification);
670
671 counter++;
672 if(counter >= G_N_ELEMENTS(contacts)) {
673 counter = 0;
674 }
675 }
676
677 /******************************************************************************
187 * PurpleProtocolActions Implementation 678 * PurpleProtocolActions Implementation
188 *****************************************************************************/ 679 *****************************************************************************/
189 static const gchar * 680 static const gchar *
190 purple_demo_protocol_get_prefix(G_GNUC_UNUSED PurpleProtocolActions *actions) { 681 purple_demo_protocol_get_prefix(G_GNUC_UNUSED PurpleProtocolActions *actions) {
191 return "prpl-demo"; 682 return "prpl-demo";
199 GActionEntry entries[] = { 690 GActionEntry entries[] = {
200 { 691 {
201 .name = "temporary-failure", 692 .name = "temporary-failure",
202 .activate = purple_demo_protocol_temporary_failure_action_activate, 693 .activate = purple_demo_protocol_temporary_failure_action_activate,
203 .parameter_type = "s", 694 .parameter_type = "s",
204 }, 695 }, {
205 {
206 .name = "fatal-failure", 696 .name = "fatal-failure",
207 .activate = purple_demo_protocol_fatal_failure_action_activate, 697 .activate = purple_demo_protocol_fatal_failure_action_activate,
208 .parameter_type = "s", 698 .parameter_type = "s",
209 }, { 699 }, {
210 .name = "remote-add", 700 .name = "remote-add",
211 .activate = purple_demo_protocol_remote_add, 701 .activate = purple_demo_protocol_remote_add,
212 .parameter_type = "s", 702 .parameter_type = "s",
703 }, {
704 .name = "request-input",
705 .activate = purple_demo_protocol_request_input_activate,
706 .parameter_type = "s",
707 }, {
708 .name = "request-choice",
709 .activate = purple_demo_protocol_request_choice_activate,
710 .parameter_type = "s",
711 }, {
712 .name = "request-action",
713 .activate = purple_demo_protocol_request_action_activate,
714 .parameter_type = "s",
715 }, {
716 .name = "request-wait",
717 .activate = purple_demo_protocol_request_wait_activate,
718 .parameter_type = "s",
719 }, {
720 .name = "request-fields",
721 .activate = purple_demo_protocol_request_fields_activate,
722 .parameter_type = "s",
723 }, {
724 .name = "request-file",
725 .activate = purple_demo_protocol_request_file_activate,
726 .parameter_type = "s",
727 }, {
728 .name = "request-folder",
729 .activate = purple_demo_protocol_request_folder_activate,
730 .parameter_type = "s",
213 } 731 }
214 }; 732 };
215 gsize nentries = G_N_ELEMENTS(entries); 733 gsize nentries = G_N_ELEMENTS(entries);
216 734
217 group = g_simple_action_group_new(); 735 group = g_simple_action_group_new();
224 static GMenu * 742 static GMenu *
225 purple_demo_protocol_get_menu(G_GNUC_UNUSED PurpleProtocolActions *actions, 743 purple_demo_protocol_get_menu(G_GNUC_UNUSED PurpleProtocolActions *actions,
226 G_GNUC_UNUSED PurpleConnection *connection) 744 G_GNUC_UNUSED PurpleConnection *connection)
227 { 745 {
228 GMenu *menu = NULL; 746 GMenu *menu = NULL;
747 GMenu *submenu = NULL;
229 GMenuItem *item = NULL; 748 GMenuItem *item = NULL;
230 749
231 menu = g_menu_new(); 750 menu = g_menu_new();
232 751
233 item = g_menu_item_new(_("Trigger temporary connection failure..."), 752 item = g_menu_item_new(_("Trigger temporary connection failure..."),
248 "prpl-demo.remote-add"); 767 "prpl-demo.remote-add");
249 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s", 768 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
250 "account"); 769 "account");
251 g_menu_append_item(menu, item); 770 g_menu_append_item(menu, item);
252 g_object_unref(item); 771 g_object_unref(item);
772
773 submenu = g_menu_new();
774
775 item = g_menu_item_new(_("Input"), "prpl-demo.request-input");
776 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
777 "account");
778 g_menu_append_item(submenu, item);
779 g_object_unref(item);
780
781 item = g_menu_item_new(_("Choice"), "prpl-demo.request-choice");
782 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
783 "account");
784 g_menu_append_item(submenu, item);
785 g_object_unref(item);
786
787 item = g_menu_item_new(_("Action"), "prpl-demo.request-action");
788 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
789 "account");
790 g_menu_append_item(submenu, item);
791 g_object_unref(item);
792
793 item = g_menu_item_new(_("Wait"), "prpl-demo.request-wait");
794 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
795 "account");
796 g_menu_append_item(submenu, item);
797 g_object_unref(item);
798
799 item = g_menu_item_new(_("Fields"), "prpl-demo.request-fields");
800 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
801 "account");
802 g_menu_append_item(submenu, item);
803 g_object_unref(item);
804
805 item = g_menu_item_new(_("File"), "prpl-demo.request-file");
806 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
807 "account");
808 g_menu_append_item(submenu, item);
809 g_object_unref(item);
810
811 item = g_menu_item_new(_("Folder"), "prpl-demo.request-folder");
812 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
813 "account");
814 g_menu_append_item(submenu, item);
815 g_object_unref(item);
816
817 g_menu_append_submenu(menu, _("Trigger requests"), G_MENU_MODEL(submenu));
818 g_object_unref(submenu);
253 819
254 return menu; 820 return menu;
255 } 821 }
256 822
257 void 823 void

mercurial