3 * 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
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "pidginmessage.h"
24 struct _PidginMessage
{
36 PROP_ID
= N_PROPERTIES
,
43 static GParamSpec
*properties
[N_PROPERTIES
] = {NULL
, };
45 /******************************************************************************
47 *****************************************************************************/
49 pidgin_message_set_message(PidginMessage
*msg
, PurpleMessage
*purple_msg
) {
50 if(g_set_object(&msg
->msg
, purple_msg
)) {
51 g_clear_pointer(&msg
->timestamp
, g_date_time_unref
);
52 msg
->timestamp
= g_date_time_new_from_unix_local(purple_message_get_time(purple_msg
));
54 g_object_freeze_notify(G_OBJECT(msg
));
55 g_object_notify_by_pspec(G_OBJECT(msg
), properties
[PROP_MESSAGE
]);
56 g_object_notify(G_OBJECT(msg
), "timestamp");
57 g_object_thaw_notify(G_OBJECT(msg
));
61 /******************************************************************************
62 * TalkatuMessage Implementation
63 *****************************************************************************/
65 pidgin_message_talkatu_message_init(TalkatuMessageInterface
*iface
) {
66 /* we don't actually change behavior, we just override properties */
69 /******************************************************************************
70 * GObject Implementation
71 *****************************************************************************/
72 G_DEFINE_TYPE_EXTENDED(
77 G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE
, pidgin_message_talkatu_message_init
)
81 pidgin_message_get_property(GObject
*obj
, guint param_id
, GValue
*value
, GParamSpec
*pspec
) {
82 PidginMessage
*msg
= PIDGIN_MESSAGE(obj
);
86 g_value_set_object(value
, msg
->msg
);
89 g_value_set_uint(value
, purple_message_get_id(msg
->msg
));
91 case PROP_CONTENT_TYPE
:
92 g_value_set_enum(value
, TALKATU_CONTENT_TYPE_PLAIN
);
95 g_value_set_string(value
, purple_message_get_author(msg
->msg
));
98 g_value_set_string(value
, purple_message_get_contents(msg
->msg
));
101 g_value_set_pointer(value
, msg
->timestamp
);
104 g_value_set_boolean(value
, FALSE
);
107 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
113 pidgin_message_set_property(GObject
*obj
, guint param_id
, const GValue
*value
, GParamSpec
*pspec
) {
114 PidginMessage
*msg
= PIDGIN_MESSAGE(obj
);
118 pidgin_message_set_message(msg
, g_value_get_object(value
));
121 case PROP_CONTENT_TYPE
:
126 /* we don't allow settings these */
129 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
135 pidgin_message_init(PidginMessage
*msg
) {
139 pidgin_message_finalize(GObject
*obj
) {
140 PidginMessage
*msg
= PIDGIN_MESSAGE(obj
);
142 g_clear_object(&msg
->msg
);
143 g_clear_pointer(&msg
->timestamp
, g_date_time_unref
);
145 G_OBJECT_CLASS(pidgin_message_parent_class
)->finalize(obj
);
149 pidgin_message_class_init(PidginMessageClass
*klass
) {
150 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
152 obj_class
->get_property
= pidgin_message_get_property
;
153 obj_class
->set_property
= pidgin_message_set_property
;
154 obj_class
->finalize
= pidgin_message_finalize
;
156 /* add our custom properties */
157 properties
[PROP_MESSAGE
] = g_param_spec_object(
158 "message", "message", "The purple message",
160 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
163 g_object_class_install_properties(obj_class
, N_PROPERTIES
, properties
);
165 /* add our overridden properties */
166 g_object_class_override_property(obj_class
, PROP_ID
, "id");
167 g_object_class_override_property(obj_class
, PROP_TIMESTAMP
, "timestamp");
168 g_object_class_override_property(obj_class
, PROP_CONTENT_TYPE
, "content-type");
169 g_object_class_override_property(obj_class
, PROP_AUTHOR
, "author");
170 g_object_class_override_property(obj_class
, PROP_CONTENTS
, "contents");
171 g_object_class_override_property(obj_class
, PROP_EDITED
, "edited");
174 /******************************************************************************
176 *****************************************************************************/
178 pidgin_message_new(PurpleMessage
*msg
) {
187 pidgin_message_get_message(PidginMessage
*msg
) {
188 g_return_val_if_fail(PIDGIN_IS_MESSAGE(msg
), NULL
);