finch: Mark unused variable.
[pidgin-git.git] / pidgin / pidginmessage.c
blob16f4113a8e34bef1f020fe3cab14d1dcdd92c51d
1 /* pidgin
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
5 * source distribution.
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 {
25 GObject parent;
27 PurpleMessage *msg;
28 GDateTime *timestamp;
31 enum {
32 PROP_0,
33 PROP_MESSAGE,
34 N_PROPERTIES,
35 /* overrides */
36 PROP_ID = N_PROPERTIES,
37 PROP_CONTENT_TYPE,
38 PROP_AUTHOR,
39 PROP_CONTENTS,
40 PROP_TIMESTAMP,
41 PROP_EDITED,
43 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
45 /******************************************************************************
46 * Helpers
47 *****************************************************************************/
48 static void
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 *****************************************************************************/
64 static void
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(
73 PidginMessage,
74 pidgin_message,
75 G_TYPE_OBJECT,
77 G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE, pidgin_message_talkatu_message_init)
80 static void
81 pidgin_message_get_property(GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) {
82 PidginMessage *msg = PIDGIN_MESSAGE(obj);
84 switch(param_id) {
85 case PROP_MESSAGE:
86 g_value_set_object(value, msg->msg);
87 break;
88 case PROP_ID:
89 g_value_set_uint(value, purple_message_get_id(msg->msg));
90 break;
91 case PROP_CONTENT_TYPE:
92 g_value_set_enum(value, TALKATU_CONTENT_TYPE_PLAIN);
93 break;
94 case PROP_AUTHOR:
95 g_value_set_string(value, purple_message_get_author(msg->msg));
96 break;
97 case PROP_CONTENTS:
98 g_value_set_string(value, purple_message_get_contents(msg->msg));
99 break;
100 case PROP_TIMESTAMP:
101 g_value_set_pointer(value, msg->timestamp);
102 break;
103 case PROP_EDITED:
104 g_value_set_boolean(value, FALSE);
105 break;
106 default:
107 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
108 break;
112 static void
113 pidgin_message_set_property(GObject *obj, guint param_id, const GValue *value, GParamSpec *pspec) {
114 PidginMessage *msg = PIDGIN_MESSAGE(obj);
116 switch(param_id) {
117 case PROP_MESSAGE:
118 pidgin_message_set_message(msg, g_value_get_object(value));
119 break;
120 case PROP_ID:
121 case PROP_CONTENT_TYPE:
122 case PROP_TIMESTAMP:
123 case PROP_AUTHOR:
124 case PROP_CONTENTS:
125 case PROP_EDITED:
126 /* we don't allow settings these */
127 break;
128 default:
129 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
130 break;
134 static void
135 pidgin_message_init(PidginMessage *msg) {
138 static void
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);
148 static void
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",
159 PURPLE_TYPE_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 /******************************************************************************
175 * API
176 *****************************************************************************/
177 PidginMessage *
178 pidgin_message_new(PurpleMessage *msg) {
179 return g_object_new(
180 PIDGIN_TYPE_MESSAGE,
181 "message", msg,
182 NULL
186 PurpleMessage *
187 pidgin_message_get_message(PidginMessage *msg) {
188 g_return_val_if_fail(PIDGIN_IS_MESSAGE(msg), NULL);
190 return msg->msg;