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