Fri, 20 Oct 2023 02:10:54 -0500
Prefix version.h with purple
And split constants into a separate file as in hasl.
Testing Done:
Compiled.
Reviewed at https://reviews.imfreedom.org/r/2680/
| 41749 | 1 | /* |
| 2 | * Purple - Internet Messaging Library | |
| 3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> | |
| 4 | * | |
| 5 | * This program is free software; you can redistribute it and/or modify | |
| 6 | * it under the terms of the GNU General Public License as published by | |
| 7 | * the Free Software Foundation; either version 2 of the License, or | |
| 8 | * (at your option) any later version. | |
| 9 | * | |
| 10 | * This program is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #include "purpleperson.h" | |
| 20 | ||
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
21 | #include "util.h" |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
22 | |
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
23 | #include "util.h" |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
24 | |
| 41749 | 25 | struct _PurplePerson { |
| 26 | GObject parent; | |
| 27 | ||
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
28 | char *id; |
| 41749 | 29 | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
30 | gchar *alias; |
|
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
31 | PurpleAvatar *avatar; |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
32 | char *color; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
33 | |
| 41749 | 34 | PurpleTags *tags; |
| 35 | ||
| 36 | GPtrArray *contacts; | |
| 37 | }; | |
| 38 | ||
| 39 | enum { | |
| 40 | PROP_0, | |
| 41 | PROP_ID, | |
| 42 | PROP_ALIAS, | |
| 43 | PROP_AVATAR, | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
44 | PROP_AVATAR_FOR_DISPLAY, |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
45 | PROP_COLOR, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
46 | PROP_COLOR_FOR_DISPLAY, |
| 41749 | 47 | PROP_TAGS, |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
48 | PROP_NAME_FOR_DISPLAY, |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
49 | PROP_PRIORITY_CONTACT_INFO, |
| 41749 | 50 | N_PROPERTIES |
| 51 | }; | |
| 52 | static GParamSpec *properties[N_PROPERTIES] = {NULL, }; | |
| 53 | ||
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
54 | static void |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
55 | purple_person_priority_contact_info_notify_cb(GObject *obj, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
56 | G_GNUC_UNUSED GParamSpec *pspec, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
57 | gpointer data); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
58 | |
| 41749 | 59 | /****************************************************************************** |
| 60 | * Helpers | |
| 61 | *****************************************************************************/ | |
| 62 | static void | |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
63 | purple_person_set_id(PurplePerson *person, const char *id) { |
| 41749 | 64 | g_return_if_fail(PURPLE_IS_PERSON(person)); |
| 65 | ||
| 66 | g_free(person->id); | |
| 67 | ||
| 68 | if(id != NULL) { | |
| 69 | person->id = g_strdup(id); | |
| 70 | } else { | |
| 71 | person->id = g_uuid_string_random(); | |
| 72 | } | |
| 73 | ||
| 74 | g_object_notify_by_pspec(G_OBJECT(person), properties[PROP_ID]); | |
| 75 | } | |
| 76 | ||
| 77 | static gint | |
| 78 | purple_person_contact_compare(gconstpointer a, gconstpointer b) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
79 | PurpleContactInfo *c1 = *(PurpleContactInfo **)a; |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
80 | PurpleContactInfo *c2 = *(PurpleContactInfo **)b; |
| 41749 | 81 | PurplePresence *p1 = NULL; |
| 82 | PurplePresence *p2 = NULL; | |
| 83 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
84 | p1 = purple_contact_info_get_presence(c1); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
85 | p2 = purple_contact_info_get_presence(c2); |
| 41749 | 86 | |
| 87 | return purple_presence_compare(p1, p2); | |
| 88 | } | |
| 89 | ||
| 90 | static void | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
91 | purple_person_sort_contacts(PurplePerson *person, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
92 | PurpleContactInfo *original_priority) |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
93 | { |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
94 | PurpleContactInfo *new_priority = NULL; |
| 41749 | 95 | guint n_items = person->contacts->len; |
| 96 | ||
| 97 | g_ptr_array_sort(person->contacts, purple_person_contact_compare); | |
| 98 | ||
| 99 | /* Tell the list we update our stuff. */ | |
| 100 | g_list_model_items_changed(G_LIST_MODEL(person), 0, n_items, n_items); | |
| 101 | ||
| 102 | /* See if the priority contact changed. */ | |
| 103 | new_priority = g_ptr_array_index(person->contacts, 0); | |
| 104 | if(original_priority != new_priority) { | |
|
42314
37eca344465a
Fix some issues with PurplePerson->avatar
Gary Kramlich <grim@reaperworld.com>
parents:
42312
diff
changeset
|
105 | PurpleAvatar *old_avatar = NULL; |
|
37eca344465a
Fix some issues with PurplePerson->avatar
Gary Kramlich <grim@reaperworld.com>
parents:
42312
diff
changeset
|
106 | PurpleAvatar *new_avatar = NULL; |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
107 | GObject *obj = G_OBJECT(person); |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
108 | const char *old_color = NULL; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
109 | const char *new_color = NULL; |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
110 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
111 | if(PURPLE_IS_CONTACT_INFO(original_priority)) { |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
112 | old_avatar = purple_contact_info_get_avatar(original_priority); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
113 | old_color = purple_contact_info_get_color(original_priority); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
114 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
115 | g_signal_handlers_disconnect_by_func(original_priority, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
116 | purple_person_priority_contact_info_notify_cb, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
117 | person); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
118 | } |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
119 | |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
120 | if(PURPLE_IS_CONTACT_INFO(new_priority)) { |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
121 | new_avatar = purple_contact_info_get_avatar(new_priority); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
122 | new_color = purple_contact_info_get_color(new_priority); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
123 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
124 | g_signal_connect_object(new_priority, "notify", |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
125 | G_CALLBACK(purple_person_priority_contact_info_notify_cb), |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
126 | person, 0); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
127 | } |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
128 | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
129 | g_object_freeze_notify(obj); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
130 | g_object_notify_by_pspec(obj, properties[PROP_NAME_FOR_DISPLAY]); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
131 | g_object_notify_by_pspec(obj, properties[PROP_PRIORITY_CONTACT_INFO]); |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
132 | |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
133 | /* If the color isn't overridden by the person, check if it has |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
134 | * changed. |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
135 | */ |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
136 | if(purple_strempty(person->color)) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
137 | if(!purple_strequal(old_color, new_color)) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
138 | g_object_notify_by_pspec(obj, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
139 | properties[PROP_COLOR_FOR_DISPLAY]); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
140 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
141 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
142 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
143 | /* If the person doesn't have an avatar set, check if the avatar |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
144 | * changed and notify if it has. |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
145 | */ |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
146 | if(!PURPLE_IS_AVATAR(person->avatar)) { |
|
42314
37eca344465a
Fix some issues with PurplePerson->avatar
Gary Kramlich <grim@reaperworld.com>
parents:
42312
diff
changeset
|
147 | if(old_avatar != new_avatar) { |
|
37eca344465a
Fix some issues with PurplePerson->avatar
Gary Kramlich <grim@reaperworld.com>
parents:
42312
diff
changeset
|
148 | g_object_notify_by_pspec(obj, properties[PROP_AVATAR_FOR_DISPLAY]); |
|
37eca344465a
Fix some issues with PurplePerson->avatar
Gary Kramlich <grim@reaperworld.com>
parents:
42312
diff
changeset
|
149 | } |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
150 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
151 | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
152 | g_object_thaw_notify(obj); |
| 41749 | 153 | } |
| 154 | } | |
| 155 | ||
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
156 | /* This function is used by purple_person_matches to determine if a contact info |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
157 | * matches the needle. |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
158 | */ |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
159 | static gboolean |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
160 | purple_person_matches_find_func(gconstpointer a, gconstpointer b) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
161 | PurpleContactInfo *info = (gpointer)a; |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
162 | const char *needle = b; |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
163 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
164 | return purple_contact_info_matches(info, needle); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
165 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
166 | |
| 41749 | 167 | /****************************************************************************** |
| 168 | * Callbacks | |
| 169 | *****************************************************************************/ | |
| 170 | static void | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
171 | purple_person_priority_contact_info_notify_cb(G_GNUC_UNUSED GObject *obj, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
172 | GParamSpec *pspec, |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
173 | gpointer data) |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
174 | { |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
175 | PurplePerson *person = data; |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
176 | const char *property = NULL; |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
177 | |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
178 | property = g_param_spec_get_name(pspec); |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
179 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
180 | if(purple_strequal(property, "name-for-display")) { |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
181 | g_object_notify_by_pspec(G_OBJECT(person), |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
182 | properties[PROP_NAME_FOR_DISPLAY]); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
183 | } else if(purple_strequal(property, "avatar")) { |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
184 | g_object_notify_by_pspec(G_OBJECT(person), |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
185 | properties[PROP_AVATAR_FOR_DISPLAY]); |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
186 | } else if(purple_strequal(property, "color")) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
187 | g_object_notify_by_pspec(G_OBJECT(person), |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
188 | properties[PROP_COLOR_FOR_DISPLAY]); |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
189 | } |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
190 | } |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
191 | |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
192 | static void |
| 41749 | 193 | purple_person_presence_notify_cb(G_GNUC_UNUSED GObject *obj, |
| 194 | G_GNUC_UNUSED GParamSpec *pspec, | |
| 195 | gpointer data) | |
| 196 | { | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
197 | PurplePerson *person = data; |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
198 | PurpleContactInfo *current_priority = NULL; |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
199 | |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
200 | current_priority = purple_person_get_priority_contact_info(person); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
201 | |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
202 | purple_person_sort_contacts(person, current_priority); |
| 41749 | 203 | } |
| 204 | ||
| 205 | /****************************************************************************** | |
| 206 | * GListModel Implementation | |
| 207 | *****************************************************************************/ | |
| 208 | static GType | |
| 209 | purple_person_get_item_type(G_GNUC_UNUSED GListModel *list) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
210 | return PURPLE_TYPE_CONTACT_INFO; |
| 41749 | 211 | } |
| 212 | ||
| 213 | static guint | |
| 214 | purple_person_get_n_items(GListModel *list) { | |
| 215 | PurplePerson *person = PURPLE_PERSON(list); | |
| 216 | ||
| 217 | return person->contacts->len; | |
| 218 | } | |
| 219 | ||
| 220 | static gpointer | |
| 221 | purple_person_get_item(GListModel *list, guint position) { | |
| 222 | PurplePerson *person = PURPLE_PERSON(list); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
223 | PurpleContactInfo *info = NULL; |
| 41749 | 224 | |
| 225 | if(position < person->contacts->len) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
226 | info = g_ptr_array_index(person->contacts, position); |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
227 | g_object_ref(info); |
| 41749 | 228 | } |
| 229 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
230 | return info; |
| 41749 | 231 | } |
| 232 | ||
| 233 | static void | |
| 234 | purple_person_list_model_init(GListModelInterface *iface) { | |
| 235 | iface->get_item_type = purple_person_get_item_type; | |
| 236 | iface->get_n_items = purple_person_get_n_items; | |
| 237 | iface->get_item = purple_person_get_item; | |
| 238 | } | |
| 239 | ||
| 240 | /****************************************************************************** | |
| 241 | * GObject Implementation | |
| 242 | *****************************************************************************/ | |
| 243 | G_DEFINE_TYPE_EXTENDED(PurplePerson, purple_person, G_TYPE_OBJECT, 0, | |
| 244 | G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL, | |
| 245 | purple_person_list_model_init)) | |
| 246 | ||
| 247 | static void | |
| 248 | purple_person_get_property(GObject *obj, guint param_id, GValue *value, | |
| 249 | GParamSpec *pspec) | |
| 250 | { | |
| 251 | PurplePerson *person = PURPLE_PERSON(obj); | |
| 252 | ||
| 253 | switch(param_id) { | |
| 254 | case PROP_ID: | |
| 255 | g_value_set_string(value, purple_person_get_id(person)); | |
| 256 | break; | |
| 257 | case PROP_ALIAS: | |
| 258 | g_value_set_string(value, purple_person_get_alias(person)); | |
| 259 | break; | |
| 260 | case PROP_AVATAR: | |
| 261 | g_value_set_object(value, purple_person_get_avatar(person)); | |
| 262 | break; | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
263 | case PROP_AVATAR_FOR_DISPLAY: |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
264 | g_value_set_object(value, purple_person_get_avatar_for_display(person)); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
265 | break; |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
266 | case PROP_COLOR: |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
267 | g_value_set_string(value, purple_person_get_color(person)); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
268 | break; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
269 | case PROP_COLOR_FOR_DISPLAY: |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
270 | g_value_set_string(value, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
271 | purple_person_get_color_for_display(person)); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
272 | break; |
| 41749 | 273 | case PROP_TAGS: |
| 274 | g_value_set_object(value, purple_person_get_tags(person)); | |
| 275 | break; | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
276 | case PROP_NAME_FOR_DISPLAY: |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
277 | g_value_set_string(value, |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
278 | purple_person_get_name_for_display(person)); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
279 | break; |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
280 | case PROP_PRIORITY_CONTACT_INFO: |
| 41749 | 281 | g_value_set_object(value, |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
282 | purple_person_get_priority_contact_info(person)); |
| 41749 | 283 | break; |
| 284 | default: | |
| 285 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); | |
| 286 | break; | |
| 287 | } | |
| 288 | } | |
| 289 | ||
| 290 | static void | |
| 291 | purple_person_set_property(GObject *obj, guint param_id, const GValue *value, | |
| 292 | GParamSpec *pspec) | |
| 293 | { | |
| 294 | PurplePerson *person = PURPLE_PERSON(obj); | |
| 295 | ||
| 296 | switch(param_id) { | |
| 297 | case PROP_ID: | |
| 298 | purple_person_set_id(person, g_value_get_string(value)); | |
| 299 | break; | |
| 300 | case PROP_ALIAS: | |
| 301 | purple_person_set_alias(person, g_value_get_string(value)); | |
| 302 | break; | |
| 303 | case PROP_AVATAR: | |
| 304 | purple_person_set_avatar(person, g_value_get_object(value)); | |
| 305 | break; | |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
306 | case PROP_COLOR: |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
307 | purple_person_set_color(person, g_value_get_string(value)); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
308 | break; |
| 41749 | 309 | default: |
| 310 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); | |
| 311 | break; | |
| 312 | } | |
| 313 | } | |
| 314 | ||
| 315 | static void | |
| 316 | purple_person_dispose(GObject *obj) { | |
| 317 | PurplePerson *person = PURPLE_PERSON(obj); | |
| 318 | ||
| 319 | g_clear_object(&person->avatar); | |
| 320 | g_clear_object(&person->tags); | |
| 321 | ||
| 322 | if(person->contacts != NULL) { | |
| 323 | g_ptr_array_free(person->contacts, TRUE); | |
| 324 | person->contacts = NULL; | |
| 325 | } | |
| 326 | ||
| 327 | G_OBJECT_CLASS(purple_person_parent_class)->dispose(obj); | |
| 328 | } | |
| 329 | ||
| 330 | static void | |
| 331 | purple_person_finalize(GObject *obj) { | |
| 332 | PurplePerson *person = PURPLE_PERSON(obj); | |
| 333 | ||
| 334 | g_clear_pointer(&person->id, g_free); | |
| 335 | g_clear_pointer(&person->alias, g_free); | |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
336 | g_clear_pointer(&person->color, g_free); |
| 41749 | 337 | |
| 338 | G_OBJECT_CLASS(purple_person_parent_class)->finalize(obj); | |
| 339 | } | |
| 340 | ||
| 341 | static void | |
| 342 | purple_person_constructed(GObject *obj) { | |
| 343 | PurplePerson *person = NULL; | |
| 344 | ||
| 345 | G_OBJECT_CLASS(purple_person_parent_class)->constructed(obj); | |
| 346 | ||
| 347 | person = PURPLE_PERSON(obj); | |
| 348 | if(person->id == NULL) { | |
| 349 | purple_person_set_id(person, NULL); | |
| 350 | } | |
| 351 | } | |
| 352 | ||
| 353 | static void | |
| 354 | purple_person_init(PurplePerson *person) { | |
| 355 | person->tags = purple_tags_new(); | |
| 356 | person->contacts = g_ptr_array_new_full(0, (GDestroyNotify)g_object_unref); | |
| 357 | } | |
| 358 | ||
| 359 | static void | |
| 360 | purple_person_class_init(PurplePersonClass *klass) { | |
| 361 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
| 362 | ||
| 363 | obj_class->get_property = purple_person_get_property; | |
| 364 | obj_class->set_property = purple_person_set_property; | |
| 365 | obj_class->constructed = purple_person_constructed; | |
| 366 | obj_class->dispose = purple_person_dispose; | |
| 367 | obj_class->finalize = purple_person_finalize; | |
| 368 | ||
| 369 | /** | |
| 370 | * PurplePerson:id: | |
| 371 | * | |
| 372 | * The protocol specific id for the contact. | |
| 373 | * | |
| 374 | * Since: 3.0.0 | |
| 375 | */ | |
| 376 | properties[PROP_ID] = g_param_spec_string( | |
| 377 | "id", "id", | |
| 378 | "The id of this contact", | |
| 379 | NULL, | |
| 380 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); | |
| 381 | ||
| 382 | /** | |
| 383 | * PurplePerson:alias: | |
| 384 | * | |
| 385 | * The alias for this person. This is controlled by the libpurple user. | |
| 386 | * | |
| 387 | * Since: 3.0.0 | |
| 388 | */ | |
| 389 | properties[PROP_ALIAS] = g_param_spec_string( | |
| 390 | "alias", "alias", | |
| 391 | "The alias of this person.", | |
| 392 | NULL, | |
| 393 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); | |
| 394 | ||
| 395 | /** | |
| 396 | * PurplePerson:avatar: | |
| 397 | * | |
| 398 | * The avatar for this person. This is controlled by the libpurple user, | |
| 399 | * which they can use to set a custom avatar. | |
| 400 | * | |
| 401 | * Since: 3.0.0 | |
| 402 | */ | |
| 403 | properties[PROP_AVATAR] = g_param_spec_object( | |
| 404 | "avatar", "avatar", | |
| 405 | "The avatar of this person", | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
406 | PURPLE_TYPE_AVATAR, |
| 41749 | 407 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 408 | ||
| 409 | /** | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
410 | * PurplePerson:avatar-for-display |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
411 | * |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
412 | * The avatar to show for the person. If [property@Purple.Person:avatar] is |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
413 | * set, it will be returned. Otherwise the value of |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
414 | * [property@Purple.ContactInfo:avatar] for |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
415 | * [property@Purple.Person:priority-contact-info] will be returned. |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
416 | * |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
417 | * Since: 3.0.0 |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
418 | */ |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
419 | properties[PROP_AVATAR_FOR_DISPLAY] = g_param_spec_object( |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
420 | "avatar-for-display", "avatar-for-display", |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
421 | "The avatar to display for this person", |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
422 | PURPLE_TYPE_AVATAR, |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
423 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
424 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
425 | /** |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
426 | * PurplePerson:color: |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
427 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
428 | * A custom color to use for this person which will override any colors for |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
429 | * the contacts that belong to this person. |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
430 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
431 | * This is an RGB hex code that user interfaces can use when rendering the |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
432 | * person. |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
433 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
434 | * Since: 3.0.0 |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
435 | */ |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
436 | properties[PROP_COLOR] = g_param_spec_string( |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
437 | "color", "color", |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
438 | "The custom color for this person.", |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
439 | NULL, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
440 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
441 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
442 | /** |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
443 | * PurplePerson:color-for-display: |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
444 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
445 | * The color to use for this person. |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
446 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
447 | * This will return the value of [property@Person:color] if it is set, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
448 | * otherwise it will return the value of [property@ContactInfo:color] of |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
449 | * the priority contact info. |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
450 | * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
451 | * Since: 3.0.0 |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
452 | */ |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
453 | properties[PROP_COLOR_FOR_DISPLAY] = g_param_spec_string( |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
454 | "color-for-display", "color-for-display", |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
455 | "The color to use when displaying this person.", |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
456 | NULL, |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
457 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
458 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
459 | /** |
| 41749 | 460 | * PurplePerson:tags: |
| 461 | * | |
| 462 | * The [class@Purple.Tags] for this person. | |
| 463 | * | |
| 464 | * Since: 3.0.0 | |
| 465 | */ | |
| 466 | properties[PROP_TAGS] = g_param_spec_object( | |
| 467 | "tags", "tags", | |
| 468 | "The tags for this person", | |
| 469 | PURPLE_TYPE_TAGS, | |
| 470 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | |
| 471 | ||
| 472 | /** | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
473 | * PurplePerson:name-for-display: |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
474 | * |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
475 | * The name that should be displayed for this person. |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
476 | * |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
477 | * If [property@Purple.Person:alias] is set that will be returned. If not |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
478 | * the value of [method@Purple.ContactInfo.get_name_for_display] for |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
479 | * [property@Purple.Person:priority-contact-info] will be used. If |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
480 | * [property@Purple.Person:priority-contact-info] is %NULL, then %NULL will |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
481 | * be returned. |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
482 | * |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
483 | * Since: 3.0.0 |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
484 | */ |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
485 | properties[PROP_NAME_FOR_DISPLAY] = g_param_spec_string( |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
486 | "name-for-display", "name-for-display", |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
487 | "The name that should be displayed for the person", |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
488 | NULL, |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
489 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
490 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
491 | /** |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
492 | * PurplePerson:priority-contact-info: |
| 41749 | 493 | * |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
494 | * The [class@Purple.ContactInfo] that currently has the highest priority. |
| 41749 | 495 | * |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
496 | * This is used by user interfaces to determine which |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
497 | * [class@Purple.ContactInfo] to use when messaging and so on. |
| 41749 | 498 | * |
| 499 | * Since: 3.0.0 | |
| 500 | */ | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
501 | properties[PROP_PRIORITY_CONTACT_INFO] = g_param_spec_object( |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
502 | "priority-contact-info", "priority-contact-info", |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
503 | "The priority contact info for the person", |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
504 | PURPLE_TYPE_CONTACT_INFO, |
| 41749 | 505 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
| 506 | ||
| 507 | g_object_class_install_properties(obj_class, N_PROPERTIES, properties); | |
| 508 | } | |
| 509 | ||
| 510 | /****************************************************************************** | |
| 511 | * Public API | |
| 512 | *****************************************************************************/ | |
| 513 | PurplePerson * | |
| 514 | purple_person_new(void) { | |
| 515 | return g_object_new(PURPLE_TYPE_PERSON, NULL); | |
| 516 | } | |
| 517 | ||
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
518 | const char * |
| 41749 | 519 | purple_person_get_id(PurplePerson *person) { |
| 520 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); | |
| 521 | ||
| 522 | return person->id; | |
| 523 | } | |
| 524 | ||
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
525 | const char * |
| 41749 | 526 | purple_person_get_alias(PurplePerson *person) { |
| 527 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); | |
| 528 | ||
| 529 | return person->alias; | |
| 530 | } | |
| 531 | ||
| 532 | void | |
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
533 | purple_person_set_alias(PurplePerson *person, const char *alias) { |
| 41749 | 534 | g_return_if_fail(PURPLE_IS_PERSON(person)); |
| 535 | ||
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
536 | if(!purple_strequal(person->alias, alias)) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
537 | GObject *obj = G_OBJECT(person); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
538 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
539 | g_free(person->alias); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
540 | person->alias = g_strdup(alias); |
| 41749 | 541 | |
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
542 | g_object_freeze_notify(obj); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
543 | g_object_notify_by_pspec(obj, properties[PROP_ALIAS]); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
544 | g_object_notify_by_pspec(obj, properties[PROP_NAME_FOR_DISPLAY]); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
545 | g_object_thaw_notify(obj); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
546 | } |
| 41749 | 547 | } |
| 548 | ||
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
549 | PurpleAvatar * |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
550 | purple_person_get_avatar_for_display(PurplePerson *person) { |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
551 | PurpleContactInfo *priority = NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
552 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
553 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
554 | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
555 | if(PURPLE_IS_AVATAR(person->avatar)) { |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
556 | return person->avatar; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
557 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
558 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
559 | priority = purple_person_get_priority_contact_info(person); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
560 | if(PURPLE_IS_CONTACT_INFO(priority)) { |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
561 | return purple_contact_info_get_avatar(priority); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
562 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
563 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
564 | return NULL; |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
565 | } |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
566 | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
567 | PurpleAvatar * |
| 41749 | 568 | purple_person_get_avatar(PurplePerson *person) { |
| 569 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); | |
| 570 | ||
| 571 | return person->avatar; | |
| 572 | } | |
| 573 | ||
| 574 | void | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42309
diff
changeset
|
575 | purple_person_set_avatar(PurplePerson *person, PurpleAvatar *avatar) { |
| 41749 | 576 | g_return_if_fail(PURPLE_IS_PERSON(person)); |
| 577 | ||
| 578 | if(g_set_object(&person->avatar, avatar)) { | |
|
42054
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
579 | GObject *obj = G_OBJECT(person); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
580 | |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
581 | g_object_freeze_notify(obj); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
582 | g_object_notify_by_pspec(obj, properties[PROP_AVATAR]); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
583 | g_object_notify_by_pspec(obj, properties[PROP_AVATAR_FOR_DISPLAY]); |
|
7aa77854392d
Add a property and accessor for getting the avatar to display for a PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42053
diff
changeset
|
584 | g_object_thaw_notify(obj); |
| 41749 | 585 | } |
| 586 | } | |
| 587 | ||
|
42309
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
588 | const char * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
589 | purple_person_get_color(PurplePerson *person) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
590 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
591 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
592 | return person->color; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
593 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
594 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
595 | void |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
596 | purple_person_set_color(PurplePerson *person, const char *color) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
597 | g_return_if_fail(PURPLE_IS_PERSON(person)); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
598 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
599 | if(!purple_strequal(person->color, color)) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
600 | GObject *obj = G_OBJECT(person); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
601 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
602 | g_free(person->color); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
603 | person->color = g_strdup(color); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
604 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
605 | g_object_freeze_notify(obj); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
606 | g_object_notify_by_pspec(obj, properties[PROP_COLOR]); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
607 | g_object_notify_by_pspec(obj, properties[PROP_COLOR_FOR_DISPLAY]); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
608 | g_object_thaw_notify(obj); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
609 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
610 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
611 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
612 | const char * |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
613 | purple_person_get_color_for_display(PurplePerson *person) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
614 | PurpleContactInfo *priority = NULL; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
615 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
616 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
617 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
618 | if(!purple_strempty(person->color)) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
619 | return person->color; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
620 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
621 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
622 | priority = purple_person_get_priority_contact_info(person); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
623 | if(PURPLE_IS_CONTACT_INFO(priority)) { |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
624 | return purple_contact_info_get_color(priority); |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
625 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
626 | |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
627 | return NULL; |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
628 | } |
|
52571584c0ae
Add color and color-for-display properties to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
42270
diff
changeset
|
629 | |
| 41749 | 630 | PurpleTags * |
| 631 | purple_person_get_tags(PurplePerson *person) { | |
| 632 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); | |
| 633 | ||
| 634 | return person->tags; | |
| 635 | } | |
| 636 | ||
|
42053
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
637 | const char * |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
638 | purple_person_get_name_for_display(PurplePerson *person) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
639 | PurpleContactInfo *priority = NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
640 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
641 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
642 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
643 | if(!purple_strempty(person->alias)) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
644 | return person->alias; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
645 | } |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
646 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
647 | priority = purple_person_get_priority_contact_info(person); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
648 | if(PURPLE_IS_CONTACT_INFO(priority)) { |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
649 | return purple_contact_info_get_name_for_display(priority); |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
650 | } |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
651 | |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
652 | return NULL; |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
653 | } |
|
742efe62e610
Add a name-for-display property to PurplePerson
Gary Kramlich <grim@reaperworld.com>
parents:
41975
diff
changeset
|
654 | |
| 41749 | 655 | void |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
656 | purple_person_add_contact_info(PurplePerson *person, |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
657 | PurpleContactInfo *info) |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
658 | { |
| 41749 | 659 | PurplePresence *presence = NULL; |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
660 | PurpleContactInfo *current_priority = NULL; |
| 41749 | 661 | |
| 662 | g_return_if_fail(PURPLE_IS_PERSON(person)); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
663 | g_return_if_fail(PURPLE_IS_CONTACT_INFO(info)); |
| 41749 | 664 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
665 | current_priority = purple_person_get_priority_contact_info(person); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
666 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
667 | g_ptr_array_add(person->contacts, g_object_ref(info)); |
| 41749 | 668 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
669 | presence = purple_contact_info_get_presence(info); |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
670 | g_signal_connect_object(presence, "notify", |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
671 | G_CALLBACK(purple_person_presence_notify_cb), |
| 41749 | 672 | person, 0); |
| 673 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
674 | purple_contact_info_set_person(info, person); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
675 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
676 | purple_person_sort_contacts(person, current_priority); |
| 41749 | 677 | } |
| 678 | ||
| 679 | gboolean | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
680 | purple_person_remove_contact_info(PurplePerson *person, |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
681 | PurpleContactInfo *info) |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
682 | { |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
683 | PurpleContactInfo *current_priority = NULL; |
| 41749 | 684 | gboolean removed = FALSE; |
| 685 | ||
| 686 | g_return_val_if_fail(PURPLE_IS_PERSON(person), FALSE); | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
687 | g_return_val_if_fail(PURPLE_IS_CONTACT_INFO(info), FALSE); |
| 41749 | 688 | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
689 | /* Ref the contact info to avoid a use-after free. */ |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
690 | g_object_ref(info); |
| 41749 | 691 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
692 | current_priority = purple_person_get_priority_contact_info(person); |
|
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
693 | |
| 41749 | 694 | /* g_ptr_array_remove calls g_object_unref because we passed it in as a |
| 695 | * GDestroyNotify. | |
| 696 | */ | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
697 | removed = g_ptr_array_remove(person->contacts, info); |
| 41749 | 698 | |
| 699 | if(removed) { | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
700 | PurplePresence *presence = purple_contact_info_get_presence(info); |
| 41749 | 701 | |
|
41771
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
702 | g_signal_handlers_disconnect_by_func(presence, |
|
c5877e2c93f2
Create and add PurpleContacts to the manager when purple_buddy_new is called
Gary Kramlich <grim@reaperworld.com>
parents:
41761
diff
changeset
|
703 | purple_person_presence_notify_cb, |
| 41749 | 704 | person); |
| 705 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
706 | purple_contact_info_set_person(info, NULL); |
|
41761
9dc5d28fca99
When a Contact is added to a Person set the Contact's Person to that Person.
Gary Kramlich <grim@reaperworld.com>
parents:
41749
diff
changeset
|
707 | |
|
42270
1bdd57a0c0d1
Propagate notify signals from the priority contact of a person
Gary Kramlich <grim@reaperworld.com>
parents:
42060
diff
changeset
|
708 | purple_person_sort_contacts(person, current_priority); |
| 41749 | 709 | } |
| 710 | ||
| 711 | /* Remove our reference. */ | |
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
712 | g_object_unref(info); |
| 41749 | 713 | |
| 714 | return removed; | |
| 715 | } | |
| 716 | ||
|
41948
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
717 | PurpleContactInfo * |
|
6d844d2faff1
Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
41771
diff
changeset
|
718 | purple_person_get_priority_contact_info(PurplePerson *person) { |
| 41749 | 719 | g_return_val_if_fail(PURPLE_IS_PERSON(person), NULL); |
| 720 | ||
| 721 | if(person->contacts->len == 0) { | |
| 722 | return NULL; | |
| 723 | } | |
| 724 | ||
| 725 | return g_ptr_array_index(person->contacts, 0); | |
| 726 | } | |
|
41975
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
727 | |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
728 | gboolean |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
729 | purple_person_has_contacts(PurplePerson *person) { |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
730 | g_return_val_if_fail(PURPLE_IS_PERSON(person), FALSE); |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
731 | |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
732 | return person->contacts->len > 0; |
|
3ef645de21e7
Add tracking of PurplePerson's to PurpleContactManager
Gary Kramlich <grim@reaperworld.com>
parents:
41948
diff
changeset
|
733 | } |
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
734 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
735 | gboolean |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
736 | purple_person_matches(PurplePerson *person, const char *needle) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
737 | g_return_val_if_fail(PURPLE_IS_PERSON(person), FALSE); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
738 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
739 | if(purple_strempty(needle)) { |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
740 | return TRUE; |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
741 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
742 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
743 | /* Check if the person's alias matches. */ |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
744 | if(!purple_strempty(person->alias)) { |
|
42060
d55b605fdafb
Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents:
42059
diff
changeset
|
745 | if(purple_strmatches(needle, person->alias)) { |
|
42059
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
746 | return TRUE; |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
747 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
748 | } |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
749 | |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
750 | /* See if any of the contact infos match. */ |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
751 | return g_ptr_array_find_with_equal_func(person->contacts, needle, |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
752 | purple_person_matches_find_func, |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
753 | NULL); |
|
e6dcbf0db616
Add search support to the contact list
Gary Kramlich <grim@reaperworld.com>
parents:
42054
diff
changeset
|
754 | } |