| 111 |
111 |
| 112 g_object_notify_by_pspec(G_OBJECT(notification), properties[PROP_TYPE]); |
112 g_object_notify_by_pspec(G_OBJECT(notification), properties[PROP_TYPE]); |
| 113 } |
113 } |
| 114 |
114 |
| 115 static void |
115 static void |
| 116 purple_notification_set_account(PurpleNotification *notification, |
|
| 117 PurpleAccount *account) |
|
| 118 { |
|
| 119 PurpleNotificationPrivate *priv = NULL; |
|
| 120 |
|
| 121 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification)); |
|
| 122 |
|
| 123 priv = purple_notification_get_instance_private(notification); |
|
| 124 |
|
| 125 if(g_set_object(&priv->account, account)) { |
|
| 126 g_object_notify_by_pspec(G_OBJECT(notification), |
|
| 127 properties[PROP_ACCOUNT]); |
|
| 128 } |
|
| 129 } |
|
| 130 |
|
| 131 static void |
|
| 132 purple_notification_set_data(PurpleNotification *notification, gpointer data) { |
116 purple_notification_set_data(PurpleNotification *notification, gpointer data) { |
| 133 PurpleNotificationPrivate *priv = NULL; |
117 PurpleNotificationPrivate *priv = NULL; |
| 134 |
118 |
| 135 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification)); |
119 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification)); |
| 136 |
120 |
| 170 case PROP_ID: |
154 case PROP_ID: |
| 171 g_value_set_string(value, |
155 g_value_set_string(value, |
| 172 purple_notification_get_id(notification)); |
156 purple_notification_get_id(notification)); |
| 173 break; |
157 break; |
| 174 case PROP_TYPE: |
158 case PROP_TYPE: |
| |
159 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 175 g_value_set_enum(value, |
160 g_value_set_enum(value, |
| 176 purple_notification_get_notification_type(notification)); |
161 purple_notification_get_notification_type(notification)); |
| |
162 G_GNUC_END_IGNORE_DEPRECATIONS |
| 177 break; |
163 break; |
| 178 case PROP_ACCOUNT: |
164 case PROP_ACCOUNT: |
| 179 g_value_set_object(value, |
165 g_value_set_object(value, |
| 180 purple_notification_get_account(notification)); |
166 purple_notification_get_account(notification)); |
| 181 break; |
167 break; |
| 206 case PROP_PERSISTENT: |
192 case PROP_PERSISTENT: |
| 207 g_value_set_boolean(value, |
193 g_value_set_boolean(value, |
| 208 purple_notification_get_persistent(notification)); |
194 purple_notification_get_persistent(notification)); |
| 209 break; |
195 break; |
| 210 case PROP_DATA: |
196 case PROP_DATA: |
| |
197 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 211 g_value_set_pointer(value, |
198 g_value_set_pointer(value, |
| 212 purple_notification_get_data(notification)); |
199 purple_notification_get_data(notification)); |
| |
200 G_GNUC_END_IGNORE_DEPRECATIONS |
| 213 break; |
201 break; |
| 214 default: |
202 default: |
| 215 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
203 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
| 216 break; |
204 break; |
| 217 } |
205 } |
| 299 |
287 |
| 300 G_OBJECT_CLASS(purple_notification_parent_class)->finalize(obj); |
288 G_OBJECT_CLASS(purple_notification_parent_class)->finalize(obj); |
| 301 } |
289 } |
| 302 |
290 |
| 303 static void |
291 static void |
| 304 purple_notification_init(PurpleNotification *notification) { |
292 purple_notification_init(G_GNUC_UNUSED PurpleNotification *notification) { |
| 305 purple_notification_set_id(notification, NULL); |
|
| 306 } |
293 } |
| 307 |
294 |
| 308 static void |
295 static void |
| 309 purple_notification_class_init(PurpleNotificationClass *klass) { |
296 purple_notification_class_init(PurpleNotificationClass *klass) { |
| 310 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
297 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| 314 obj_class->finalize = purple_notification_finalize; |
301 obj_class->finalize = purple_notification_finalize; |
| 315 |
302 |
| 316 /** |
303 /** |
| 317 * PurpleNotification:id: |
304 * PurpleNotification:id: |
| 318 * |
305 * |
| 319 * The ID of the notification. Used for things that need to address it. |
306 * The ID of the notification. |
| 320 * This is auto populated at creation time. |
307 * |
| |
308 * This used for things that need to address it. |
| |
309 * |
| |
310 * If not set, this will be auto populated at creation time. |
| 321 * |
311 * |
| 322 * Since: 3.0 |
312 * Since: 3.0 |
| 323 */ |
313 */ |
| 324 properties[PROP_ID] = g_param_spec_string( |
314 properties[PROP_ID] = g_param_spec_string( |
| 325 "id", NULL, NULL, |
315 "id", NULL, NULL, |
| 326 NULL, |
316 NULL, |
| 327 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
317 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
| 328 |
318 |
| 329 /** |
319 /** |
| 330 * PurpleNotification:type: |
320 * PurpleNotification:type: |
| 331 * |
321 * |
| 332 * The [enum@NotificationType] of this notification. |
322 * The [enum@NotificationType] of this notification. |
| 335 */ |
325 */ |
| 336 properties[PROP_TYPE] = g_param_spec_enum( |
326 properties[PROP_TYPE] = g_param_spec_enum( |
| 337 "type", NULL, NULL, |
327 "type", NULL, NULL, |
| 338 PURPLE_TYPE_NOTIFICATION_TYPE, |
328 PURPLE_TYPE_NOTIFICATION_TYPE, |
| 339 PURPLE_NOTIFICATION_TYPE_UNKNOWN, |
329 PURPLE_NOTIFICATION_TYPE_UNKNOWN, |
| 340 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
330 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED | |
| |
331 G_PARAM_STATIC_STRINGS); |
| 341 |
332 |
| 342 /** |
333 /** |
| 343 * PurpleNotification:account: |
334 * PurpleNotification:account: |
| 344 * |
335 * |
| 345 * An optional [class@Account] that this notification is for. |
336 * An optional [class@Account] that this notification is for. |
| 347 * Since: 3.0 |
338 * Since: 3.0 |
| 348 */ |
339 */ |
| 349 properties[PROP_ACCOUNT] = g_param_spec_object( |
340 properties[PROP_ACCOUNT] = g_param_spec_object( |
| 350 "account", NULL, NULL, |
341 "account", NULL, NULL, |
| 351 PURPLE_TYPE_ACCOUNT, |
342 PURPLE_TYPE_ACCOUNT, |
| 352 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
343 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 353 |
344 |
| 354 /** |
345 /** |
| 355 * PurpleNotification:created-timestamp: |
346 * PurpleNotification:created-timestamp: |
| 356 * |
347 * |
| 357 * The creation time of this notification. This always represented as UTC |
348 * The creation time of this notification. This always represented as UTC |
| 449 * |
440 * |
| 450 * Since: 3.0 |
441 * Since: 3.0 |
| 451 */ |
442 */ |
| 452 properties[PROP_DATA] = g_param_spec_pointer( |
443 properties[PROP_DATA] = g_param_spec_pointer( |
| 453 "data", NULL, NULL, |
444 "data", NULL, NULL, |
| 454 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
445 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED | |
| |
446 G_PARAM_STATIC_STRINGS); |
| 455 |
447 |
| 456 /** |
448 /** |
| 457 * PurpleNotification:data-destroy-func: |
449 * PurpleNotification:data-destroy-func: |
| 458 * |
450 * |
| 459 * A function to call to free [property@PurpleNotification:data]. |
451 * A function to call to free [property@PurpleNotification:data]. |
| 460 * |
452 * |
| 461 * Since: 3.0 |
453 * Since: 3.0 |
| 462 */ |
454 */ |
| 463 properties[PROP_DATA_DESTROY_FUNC] = g_param_spec_pointer( |
455 properties[PROP_DATA_DESTROY_FUNC] = g_param_spec_pointer( |
| 464 "data-destroy-func", NULL, NULL, |
456 "data-destroy-func", NULL, NULL, |
| 465 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
457 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED | |
| |
458 G_PARAM_STATIC_STRINGS); |
| 466 |
459 |
| 467 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
460 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
| 468 |
461 |
| 469 /** |
462 /** |
| 470 * PurpleNotification::deleted: |
463 * PurpleNotification::deleted: |
| 492 *****************************************************************************/ |
485 *****************************************************************************/ |
| 493 PurpleNotification * |
486 PurpleNotification * |
| 494 purple_notification_new(PurpleNotificationType type, PurpleAccount *account, |
487 purple_notification_new(PurpleNotificationType type, PurpleAccount *account, |
| 495 gpointer data, GDestroyNotify data_destroy_func) |
488 gpointer data, GDestroyNotify data_destroy_func) |
| 496 { |
489 { |
| 497 return g_object_new(PURPLE_TYPE_NOTIFICATION, |
490 PurpleNotification *notification = NULL; |
| |
491 char *envvar = NULL; |
| |
492 |
| |
493 /* This is temporary until this function gets replaced with the generic one |
| |
494 * below. |
| |
495 */ |
| |
496 envvar = g_strdup(g_getenv("G_ENABLE_DIAGNOSTIC")); |
| |
497 g_unsetenv("G_ENABLE_DIAGNOSTIC"); |
| |
498 |
| |
499 notification = g_object_new(PURPLE_TYPE_NOTIFICATION, |
| 498 "type", type, |
500 "type", type, |
| 499 "account", account, |
501 "account", account, |
| 500 "data", data, |
502 "data", data, |
| 501 "data-destroy-func", data_destroy_func, |
503 "data-destroy-func", data_destroy_func, |
| 502 NULL); |
504 NULL); |
| |
505 |
| |
506 g_setenv("G_ENABLE_DIAGNOSTIC", envvar, FALSE); |
| |
507 g_free(envvar); |
| |
508 |
| |
509 return notification; |
| |
510 } |
| |
511 |
| |
512 PurpleNotification * |
| |
513 purple_notification_new_generic(const char *id, const char *title) { |
| |
514 return g_object_new(PURPLE_TYPE_NOTIFICATION, |
| |
515 "id", id, |
| |
516 "title", title, |
| |
517 NULL); |
| 503 } |
518 } |
| 504 |
519 |
| 505 PurpleNotification * |
520 PurpleNotification * |
| 506 purple_notification_new_from_add_contact_request(PurpleAddContactRequest *request) |
521 purple_notification_new_from_add_contact_request(PurpleAddContactRequest *request) |
| 507 { |
522 { |
| 521 |
536 |
| 522 g_return_val_if_fail(PURPLE_IS_AUTHORIZATION_REQUEST(authorization_request), |
537 g_return_val_if_fail(PURPLE_IS_AUTHORIZATION_REQUEST(authorization_request), |
| 523 NULL); |
538 NULL); |
| 524 |
539 |
| 525 account = purple_authorization_request_get_account(authorization_request); |
540 account = purple_authorization_request_get_account(authorization_request); |
| |
541 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 526 notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_AUTHORIZATION_REQUEST, |
542 notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_AUTHORIZATION_REQUEST, |
| 527 account, authorization_request, |
543 account, authorization_request, |
| 528 g_object_unref); |
544 g_object_unref); |
| |
545 G_GNUC_END_IGNORE_DEPRECATIONS |
| 529 |
546 |
| 530 username = purple_authorization_request_get_username(authorization_request); |
547 username = purple_authorization_request_get_username(authorization_request); |
| 531 alias = purple_authorization_request_get_alias(authorization_request); |
548 alias = purple_authorization_request_get_alias(authorization_request); |
| 532 |
549 |
| 533 if(alias != NULL && *alias != '\0') { |
550 if(alias != NULL && *alias != '\0') { |
| 550 |
567 |
| 551 PurpleNotification * |
568 PurpleNotification * |
| 552 purple_notification_new_from_connection_error(PurpleAccount *account, |
569 purple_notification_new_from_connection_error(PurpleAccount *account, |
| 553 PurpleConnectionErrorInfo *info) |
570 PurpleConnectionErrorInfo *info) |
| 554 { |
571 { |
| |
572 PurpleConnectionErrorInfo *copy = NULL; |
| 555 PurpleNotification *notification = NULL; |
573 PurpleNotification *notification = NULL; |
| 556 PurpleProtocol *protocol = NULL; |
574 PurpleProtocol *protocol = NULL; |
| 557 char *title = NULL; |
575 char *title = NULL; |
| 558 const char *username = NULL; |
576 const char *username = NULL; |
| 559 |
577 |
| 560 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); |
578 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); |
| 561 g_return_val_if_fail(info != NULL, NULL); |
579 g_return_val_if_fail(info != NULL, NULL); |
| 562 |
580 |
| |
581 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| |
582 copy = purple_connection_error_info_copy(info); |
| 563 notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR, |
583 notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR, |
| 564 account, info, NULL); |
584 account, copy, |
| |
585 (GDestroyNotify)purple_connection_error_info_free); |
| |
586 G_GNUC_END_IGNORE_DEPRECATIONS |
| 565 |
587 |
| 566 /* Set the title of the notification. */ |
588 /* Set the title of the notification. */ |
| 567 username = purple_account_get_username(account); |
589 username = purple_account_get_username(account); |
| 568 if(purple_account_get_enabled(account)) { |
590 if(purple_account_get_enabled(account)) { |
| 569 title = g_strdup_printf(_("%s disconnected"), username); |
591 title = g_strdup_printf(_("%s disconnected"), username); |
| 618 priv = purple_notification_get_instance_private(notification); |
640 priv = purple_notification_get_instance_private(notification); |
| 619 |
641 |
| 620 return priv->account; |
642 return priv->account; |
| 621 } |
643 } |
| 622 |
644 |
| |
645 void |
| |
646 purple_notification_set_account(PurpleNotification *notification, |
| |
647 PurpleAccount *account) |
| |
648 { |
| |
649 PurpleNotificationPrivate *priv = NULL; |
| |
650 |
| |
651 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification)); |
| |
652 |
| |
653 priv = purple_notification_get_instance_private(notification); |
| |
654 |
| |
655 if(g_set_object(&priv->account, account)) { |
| |
656 g_object_notify_by_pspec(G_OBJECT(notification), |
| |
657 properties[PROP_ACCOUNT]); |
| |
658 } |
| |
659 } |
| |
660 |
| 623 GDateTime * |
661 GDateTime * |
| 624 purple_notification_get_created_timestamp(PurpleNotification *notification) { |
662 purple_notification_get_created_timestamp(PurpleNotification *notification) { |
| 625 PurpleNotificationPrivate *priv = NULL; |
663 PurpleNotificationPrivate *priv = NULL; |
| 626 |
664 |
| 627 g_return_val_if_fail(PURPLE_IS_NOTIFICATION(notification), NULL); |
665 g_return_val_if_fail(PURPLE_IS_NOTIFICATION(notification), NULL); |
| 736 |
774 |
| 737 if(g_set_str(&priv->icon_name, icon_name)) { |
775 if(g_set_str(&priv->icon_name, icon_name)) { |
| 738 g_object_notify_by_pspec(G_OBJECT(notification), |
776 g_object_notify_by_pspec(G_OBJECT(notification), |
| 739 properties[PROP_ICON_NAME]); |
777 properties[PROP_ICON_NAME]); |
| 740 } |
778 } |
| 741 |
|
| 742 } |
779 } |
| 743 |
780 |
| 744 gboolean |
781 gboolean |
| 745 purple_notification_get_read(PurpleNotification *notification) { |
782 purple_notification_get_read(PurpleNotification *notification) { |
| 746 PurpleNotificationPrivate *priv = NULL; |
783 PurpleNotificationPrivate *priv = NULL; |