pidgin/pidginmessage.c

changeset 40951
c83bf354d142
parent 40541
9ceb8d25d4d9
child 41019
f1bdc43bf086
equal deleted inserted replaced
40950:c3fc77a3c015 40951:c83bf354d142
1 /* pidgin 1 /*
2 * Pidgin - Internet Messenger
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
2 * 4 *
3 * Pidgin is the legal property of its developers, whose names are too numerous 5 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this 6 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution. 7 * source distribution.
6 * 8 *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 17 * GNU General Public License for more details.
16 * 18 *
17 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 */ 21 */
21 22
22 #include "pidginmessage.h" 23 #include "pidginmessage.h"
23 24
24 #include "pidginattachment.h" 25 #include "pidginattachment.h"
26 #include "pidgincolor.h"
25 27
26 struct _PidginMessage { 28 struct _PidginMessage {
27 GObject parent; 29 GObject parent;
28 30
29 PurpleMessage *message; 31 PurpleMessage *message;
40 N_PROPERTIES, 42 N_PROPERTIES,
41 /* overrides */ 43 /* overrides */
42 PROP_ID = N_PROPERTIES, 44 PROP_ID = N_PROPERTIES,
43 PROP_CONTENT_TYPE, 45 PROP_CONTENT_TYPE,
44 PROP_AUTHOR, 46 PROP_AUTHOR,
47 PROP_AUTHOR_NAME_COLOR,
45 PROP_CONTENTS, 48 PROP_CONTENTS,
46 PROP_TIMESTAMP, 49 PROP_TIMESTAMP,
47 PROP_EDITED, 50 PROP_EDITED,
48 }; 51 };
49 static GParamSpec *properties[N_PROPERTIES] = {NULL, }; 52 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
54 static void 57 static void
55 pidgin_message_set_message(PidginMessage *message, PurpleMessage *purple_msg) { 58 pidgin_message_set_message(PidginMessage *message, PurpleMessage *purple_msg) {
56 if(g_set_object(&message->message, purple_msg)) { 59 if(g_set_object(&message->message, purple_msg)) {
57 g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_MESSAGE]); 60 g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_MESSAGE]);
58 } 61 }
62 }
63
64 static GdkRGBA *
65 pidgin_message_parse_author_name_color(PidginMessage *message) {
66 GdkRGBA *ret = NULL;
67 const gchar *color = NULL;
68 gboolean set = FALSE;
69
70 ret = g_new0(GdkRGBA, 1);
71
72 color = purple_message_get_author_name_color(message->message);
73 if(color != NULL && gdk_rgba_parse(ret, color)) {
74 set = TRUE;
75 }
76
77 if(!set) {
78 const gchar *author = purple_message_get_author_alias(message->message);
79
80 if(author == NULL) {
81 author = purple_message_get_author(message->message);
82 }
83
84 pidgin_color_calculate_for_text(author, ret);
85 }
86
87 return ret;
59 } 88 }
60 89
61 /****************************************************************************** 90 /******************************************************************************
62 * TalkatuMessage Implementation 91 * TalkatuMessage Implementation
63 *****************************************************************************/ 92 *****************************************************************************/
166 G_DEFINE_TYPE_EXTENDED( 195 G_DEFINE_TYPE_EXTENDED(
167 PidginMessage, 196 PidginMessage,
168 pidgin_message, 197 pidgin_message,
169 G_TYPE_OBJECT, 198 G_TYPE_OBJECT,
170 0, 199 0,
171 G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE, pidgin_message_talkatu_message_init) 200 G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE,
201 pidgin_message_talkatu_message_init)
172 ); 202 );
173 203
174 static void 204 static void
175 pidgin_message_get_property(GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) { 205 pidgin_message_get_property(GObject *obj, guint param_id, GValue *value,
206 GParamSpec *pspec)
207 {
176 PidginMessage *message = PIDGIN_MESSAGE(obj); 208 PidginMessage *message = PIDGIN_MESSAGE(obj);
177 209
178 switch(param_id) { 210 switch(param_id) {
179 case PROP_MESSAGE: 211 case PROP_MESSAGE:
180 g_value_set_object(value, message->message); 212 g_value_set_object(value, message->message);
184 break; 216 break;
185 case PROP_CONTENT_TYPE: 217 case PROP_CONTENT_TYPE:
186 g_value_set_enum(value, TALKATU_CONTENT_TYPE_PLAIN); 218 g_value_set_enum(value, TALKATU_CONTENT_TYPE_PLAIN);
187 break; 219 break;
188 case PROP_AUTHOR: 220 case PROP_AUTHOR:
189 g_value_set_string(value, purple_message_get_author(message->message)); 221 g_value_set_string(value,
222 purple_message_get_author(message->message));
223 break;
224 case PROP_AUTHOR_NAME_COLOR:
225 g_value_take_boxed(value,
226 pidgin_message_parse_author_name_color(message));
190 break; 227 break;
191 case PROP_CONTENTS: 228 case PROP_CONTENTS:
192 g_value_set_string(value, purple_message_get_contents(message->message)); 229 g_value_set_string(value,
230 purple_message_get_contents(message->message));
193 break; 231 break;
194 case PROP_TIMESTAMP: 232 case PROP_TIMESTAMP:
195 g_value_set_boxed(value, purple_message_get_timestamp(message->message)); 233 g_value_set_boxed(value,
234 purple_message_get_timestamp(message->message));
196 break; 235 break;
197 case PROP_EDITED: 236 case PROP_EDITED:
198 g_value_set_boolean(value, FALSE); 237 g_value_set_boolean(value, FALSE);
199 break; 238 break;
200 default: 239 default:
202 break; 241 break;
203 } 242 }
204 } 243 }
205 244
206 static void 245 static void
207 pidgin_message_set_property(GObject *obj, guint param_id, const GValue *value, GParamSpec *pspec) { 246 pidgin_message_set_property(GObject *obj, guint param_id, const GValue *value,
247 GParamSpec *pspec)
248 {
208 PidginMessage *message = PIDGIN_MESSAGE(obj); 249 PidginMessage *message = PIDGIN_MESSAGE(obj);
209 250
210 switch(param_id) { 251 switch(param_id) {
211 case PROP_MESSAGE: 252 case PROP_MESSAGE:
212 pidgin_message_set_message(message, g_value_get_object(value)); 253 pidgin_message_set_message(message, g_value_get_object(value));
213 break; 254 break;
214 case PROP_ID: 255 case PROP_ID:
215 case PROP_CONTENT_TYPE: 256 case PROP_CONTENT_TYPE:
216 case PROP_TIMESTAMP: 257 case PROP_TIMESTAMP:
217 case PROP_AUTHOR: 258 case PROP_AUTHOR:
259 case PROP_AUTHOR_NAME_COLOR:
218 case PROP_CONTENTS: 260 case PROP_CONTENTS:
219 case PROP_EDITED: 261 case PROP_EDITED:
220 /* we don't allow settings these */ 262 /* we don't allow settings these */
221 break; 263 break;
222 default: 264 default:
256 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); 298 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
257 299
258 /* add our overridden properties */ 300 /* add our overridden properties */
259 g_object_class_override_property(obj_class, PROP_ID, "id"); 301 g_object_class_override_property(obj_class, PROP_ID, "id");
260 g_object_class_override_property(obj_class, PROP_TIMESTAMP, "timestamp"); 302 g_object_class_override_property(obj_class, PROP_TIMESTAMP, "timestamp");
261 g_object_class_override_property(obj_class, PROP_CONTENT_TYPE, "content-type"); 303 g_object_class_override_property(obj_class, PROP_CONTENT_TYPE,
304 "content-type");
262 g_object_class_override_property(obj_class, PROP_AUTHOR, "author"); 305 g_object_class_override_property(obj_class, PROP_AUTHOR, "author");
306 g_object_class_override_property(obj_class, PROP_AUTHOR_NAME_COLOR,
307 "author-name-color");
263 g_object_class_override_property(obj_class, PROP_CONTENTS, "contents"); 308 g_object_class_override_property(obj_class, PROP_CONTENTS, "contents");
264 g_object_class_override_property(obj_class, PROP_EDITED, "edited"); 309 g_object_class_override_property(obj_class, PROP_EDITED, "edited");
265 } 310 }
266 311
267 /****************************************************************************** 312 /******************************************************************************

mercurial