| 45 * Represents an active connection on an account. |
45 * Represents an active connection on an account. |
| 46 */ |
46 */ |
| 47 struct _PurpleConnection { |
47 struct _PurpleConnection { |
| 48 GObject gparent; |
48 GObject gparent; |
| 49 |
49 |
| |
50 gchar *id; |
| |
51 |
| 50 PurpleProtocol *protocol; /* The protocol. */ |
52 PurpleProtocol *protocol; /* The protocol. */ |
| 51 PurpleConnectionFlags flags; /* Connection flags. */ |
53 PurpleConnectionFlags flags; /* Connection flags. */ |
| 52 |
54 |
| 53 PurpleConnectionState state; /* The connection state. */ |
55 PurpleConnectionState state; /* The connection state. */ |
| 54 |
56 |
| 271 PurpleAccount * |
274 PurpleAccount * |
| 272 purple_connection_get_account(PurpleConnection *gc) { |
275 purple_connection_get_account(PurpleConnection *gc) { |
| 273 g_return_val_if_fail(PURPLE_IS_CONNECTION(gc), NULL); |
276 g_return_val_if_fail(PURPLE_IS_CONNECTION(gc), NULL); |
| 274 |
277 |
| 275 return gc->account; |
278 return gc->account; |
| |
279 } |
| |
280 |
| |
281 const gchar * |
| |
282 purple_connection_get_id(PurpleConnection *connection) { |
| |
283 g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), NULL); |
| |
284 |
| |
285 return connection->id; |
| 276 } |
286 } |
| 277 |
287 |
| 278 PurpleProtocol * |
288 PurpleProtocol * |
| 279 purple_connection_get_protocol(PurpleConnection *gc) { |
289 purple_connection_get_protocol(PurpleConnection *gc) { |
| 280 g_return_val_if_fail(PURPLE_IS_CONNECTION(gc), NULL); |
290 g_return_val_if_fail(PURPLE_IS_CONNECTION(gc), NULL); |
| 639 } |
649 } |
| 640 |
650 |
| 641 return type; |
651 return type; |
| 642 } |
652 } |
| 643 |
653 |
| |
654 |
| |
655 /************************************************************************** |
| |
656 * Helpers |
| |
657 **************************************************************************/ |
| |
658 static void |
| |
659 purple_connection_set_id(PurpleConnection *connection, const gchar *id) { |
| |
660 g_free(connection->id); |
| |
661 connection->id = g_strdup(id); |
| |
662 |
| |
663 g_object_notify_by_pspec(G_OBJECT(connection), properties[PROP_ID]); |
| |
664 } |
| |
665 |
| 644 /************************************************************************** |
666 /************************************************************************** |
| 645 * GObject code |
667 * GObject code |
| 646 **************************************************************************/ |
668 **************************************************************************/ |
| 647 |
669 |
| 648 static void |
670 static void |
| 650 const GValue *value, GParamSpec *pspec) |
672 const GValue *value, GParamSpec *pspec) |
| 651 { |
673 { |
| 652 PurpleConnection *gc = PURPLE_CONNECTION(obj); |
674 PurpleConnection *gc = PURPLE_CONNECTION(obj); |
| 653 |
675 |
| 654 switch (param_id) { |
676 switch (param_id) { |
| |
677 case PROP_ID: |
| |
678 purple_connection_set_id(gc, g_value_get_string(value)); |
| |
679 break; |
| 655 case PROP_PROTOCOL: |
680 case PROP_PROTOCOL: |
| 656 gc->protocol = g_value_get_object(value); |
681 gc->protocol = g_value_get_object(value); |
| 657 break; |
682 break; |
| 658 case PROP_FLAGS: |
683 case PROP_FLAGS: |
| 659 purple_connection_set_flags(gc, g_value_get_flags(value)); |
684 purple_connection_set_flags(gc, g_value_get_flags(value)); |
| 682 GParamSpec *pspec) |
707 GParamSpec *pspec) |
| 683 { |
708 { |
| 684 PurpleConnection *gc = PURPLE_CONNECTION(obj); |
709 PurpleConnection *gc = PURPLE_CONNECTION(obj); |
| 685 |
710 |
| 686 switch (param_id) { |
711 switch (param_id) { |
| |
712 case PROP_ID: |
| |
713 g_value_set_string(value, purple_connection_get_id(gc)); |
| |
714 break; |
| 687 case PROP_PROTOCOL: |
715 case PROP_PROTOCOL: |
| 688 g_value_set_object(value, purple_connection_get_protocol(gc)); |
716 g_value_set_object(value, purple_connection_get_protocol(gc)); |
| 689 break; |
717 break; |
| 690 case PROP_FLAGS: |
718 case PROP_FLAGS: |
| 691 g_value_set_flags(value, purple_connection_get_flags(gc)); |
719 g_value_set_flags(value, purple_connection_get_flags(gc)); |
| 718 purple_connection_constructed(GObject *object) { |
746 purple_connection_constructed(GObject *object) { |
| 719 PurpleConnection *gc = PURPLE_CONNECTION(object); |
747 PurpleConnection *gc = PURPLE_CONNECTION(object); |
| 720 PurpleAccount *account; |
748 PurpleAccount *account; |
| 721 |
749 |
| 722 G_OBJECT_CLASS(purple_connection_parent_class)->constructed(object); |
750 G_OBJECT_CLASS(purple_connection_parent_class)->constructed(object); |
| |
751 |
| |
752 if(gc->id == NULL) { |
| |
753 gchar *uuid = g_uuid_string_random(); |
| |
754 |
| |
755 purple_connection_set_id(gc, uuid); |
| |
756 |
| |
757 g_free(uuid); |
| |
758 } |
| 723 |
759 |
| 724 g_object_get(gc, "account", &account, NULL); |
760 g_object_get(gc, "account", &account, NULL); |
| 725 purple_account_set_connection(account, gc); |
761 purple_account_set_connection(account, gc); |
| 726 g_object_unref(account); |
762 g_object_unref(account); |
| 727 |
763 |
| 806 |
843 |
| 807 obj_class->get_property = purple_connection_get_property; |
844 obj_class->get_property = purple_connection_get_property; |
| 808 obj_class->set_property = purple_connection_set_property; |
845 obj_class->set_property = purple_connection_set_property; |
| 809 obj_class->finalize = purple_connection_finalize; |
846 obj_class->finalize = purple_connection_finalize; |
| 810 obj_class->constructed = purple_connection_constructed; |
847 obj_class->constructed = purple_connection_constructed; |
| |
848 |
| |
849 properties[PROP_ID] = g_param_spec_string( |
| |
850 "id", "id", |
| |
851 "The identifier of the account", |
| |
852 NULL, |
| |
853 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); |
| 811 |
854 |
| 812 properties[PROP_PROTOCOL] = g_param_spec_object( |
855 properties[PROP_PROTOCOL] = g_param_spec_object( |
| 813 "protocol", "Protocol", |
856 "protocol", "Protocol", |
| 814 "The protocol that the connection is using.", |
857 "The protocol that the connection is using.", |
| 815 PURPLE_TYPE_PROTOCOL, |
858 PURPLE_TYPE_PROTOCOL, |