1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include <glib/gi18n.h>
25 #include "empathy-chat.h"
26 #include "empathy-ui-utils.h"
27 #include "empathy-theme-irc.h"
29 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv))
31 typedef struct _EmpathyThemeIrcPriv EmpathyThemeIrcPriv;
33 struct _EmpathyThemeIrcPriv {
37 static void theme_irc_finalize (GObject *object);
38 static void theme_irc_update_view (EmpathyTheme *theme,
39 EmpathyChatView *view);
40 static void theme_irc_append_message (EmpathyTheme *theme,
41 EmpathyChatView *view,
42 EmpathyMessage *message);
43 static void theme_irc_append_event (EmpathyTheme *theme,
44 EmpathyChatView *view,
46 static void theme_irc_append_timestamp (EmpathyTheme *theme,
47 EmpathyChatView *view,
48 EmpathyMessage *message,
51 static void theme_irc_append_spacing (EmpathyTheme *theme,
52 EmpathyChatView *view);
60 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_THEME);
63 empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
65 GObjectClass *object_class;
66 EmpathyThemeClass *theme_class;
68 object_class = G_OBJECT_CLASS (class);
69 theme_class = EMPATHY_THEME_CLASS (class);
71 object_class->finalize = theme_irc_finalize;
73 theme_class->update_view = theme_irc_update_view;
74 theme_class->append_message = theme_irc_append_message;
75 theme_class->append_event = theme_irc_append_event;
76 theme_class->append_timestamp = theme_irc_append_timestamp;
77 theme_class->append_spacing = theme_irc_append_spacing;
79 g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
83 empathy_theme_irc_init (EmpathyThemeIrc *presence)
85 EmpathyThemeIrcPriv *priv;
87 priv = GET_PRIV (presence);
91 theme_irc_finalize (GObject *object)
93 EmpathyThemeIrcPriv *priv;
95 priv = GET_PRIV (object);
97 (G_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
101 theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
103 EmpathyThemeIrcPriv *priv;
104 GtkTextBuffer *buffer;
106 priv = GET_PRIV (theme);
108 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
110 empathy_text_buffer_tag_set (buffer, "irc-spacing",
114 empathy_text_buffer_tag_set (buffer, "irc-nick-self",
115 "foreground", "sea green",
118 empathy_text_buffer_tag_set (buffer, "irc-body-self",
119 /* To get the default theme color: */
120 "foreground-set", FALSE,
123 empathy_text_buffer_tag_set (buffer, "irc-action-self",
124 "foreground", "brown4",
125 "style", PANGO_STYLE_ITALIC,
128 empathy_text_buffer_tag_set (buffer, "irc-nick-highlight",
129 "foreground", "indian red",
130 "weight", PANGO_WEIGHT_BOLD,
133 empathy_text_buffer_tag_set (buffer, "irc-nick-other",
134 "foreground", "skyblue4",
137 empathy_text_buffer_tag_set (buffer, "irc-body-other",
138 /* To get the default theme color: */
139 "foreground-set", FALSE,
142 empathy_text_buffer_tag_set (buffer, "irc-action-other",
143 "foreground", "brown4",
144 "style", PANGO_STYLE_ITALIC,
147 empathy_text_buffer_tag_set (buffer, "irc-time",
148 "foreground", "darkgrey",
149 "justification", GTK_JUSTIFY_CENTER,
152 empathy_text_buffer_tag_set (buffer, "irc-event",
153 "foreground", "PeachPuff4",
154 "justification", GTK_JUSTIFY_LEFT,
157 empathy_text_buffer_tag_set (buffer, "invite",
158 "foreground", "sienna",
161 empathy_text_buffer_tag_set (buffer, "irc-link",
162 "foreground", "steelblue",
163 "underline", PANGO_UNDERLINE_SINGLE,
169 theme_irc_update_view (EmpathyTheme *theme, EmpathyChatView *view)
171 theme_irc_apply_theme_classic (theme, view);
172 empathy_chat_view_set_margin (view, 3);
176 theme_irc_append_message (EmpathyTheme *theme,
177 EmpathyChatView *view,
178 EmpathyMessage *message)
180 GtkTextBuffer *buffer;
182 const gchar *nick_tag;
183 const gchar *body_tag;
186 EmpathyContact *contact;
188 empathy_theme_maybe_append_date_and_time (theme, view, message);
190 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
192 contact = empathy_message_get_sender (message);
193 name = empathy_contact_get_name (contact);
195 if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
196 if (empathy_contact_is_user (contact)) {
197 body_tag = "irc-action-self";
199 body_tag = "irc-action-other";
202 tmp = g_strdup_printf (" * %s %s",
203 empathy_contact_get_name (contact),
204 empathy_message_get_body (message));
205 empathy_theme_append_text (theme, view, tmp,
206 body_tag, "irc-link");
211 if (empathy_contact_is_user (contact)) {
212 nick_tag = "irc-nick-self";
213 body_tag = "irc-body-self";
215 if (empathy_message_should_highlight (message)) {
216 nick_tag = "irc-nick-highlight";
218 nick_tag = "irc-nick-other";
221 body_tag = "irc-body-other";
224 gtk_text_buffer_get_end_iter (buffer, &iter);
227 tmp = g_strdup_printf ("%s: ", name);
228 gtk_text_buffer_insert_with_tags_by_name (buffer,
238 empathy_theme_append_text (theme, view,
239 empathy_message_get_body (message),
240 body_tag, "irc-link");
244 theme_irc_append_event (EmpathyTheme *theme,
245 EmpathyChatView *view,
248 GtkTextBuffer *buffer;
252 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
254 empathy_theme_maybe_append_date_and_time (theme, view, NULL);
256 gtk_text_buffer_get_end_iter (buffer, &iter);
258 msg = g_strdup_printf (" - %s\n", str);
259 gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
267 theme_irc_append_timestamp (EmpathyTheme *theme,
268 EmpathyChatView *view,
269 EmpathyMessage *message,
273 GtkTextBuffer *buffer;
279 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
281 date = empathy_message_get_date_and_time (message, ×tamp);
283 str = g_string_new (NULL);
285 if (show_time || show_date) {
286 empathy_theme_append_spacing (theme, view);
288 g_string_append (str, "- ");
294 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
295 g_string_append (str, buf);
298 g_string_append (str, ", ");
307 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
308 g_string_append (str, tmp);
312 if (show_time || show_date) {
313 g_string_append (str, " -\n");
315 gtk_text_buffer_get_end_iter (buffer, &iter);
316 gtk_text_buffer_insert_with_tags_by_name (buffer,
322 empathy_chat_view_set_last_timestamp (view, timestamp);
325 g_string_free (str, TRUE);
329 theme_irc_append_spacing (EmpathyTheme *theme,
330 EmpathyChatView *view)
332 GtkTextBuffer *buffer;
335 g_return_if_fail (EMPATHY_IS_THEME (theme));
336 g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
338 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
340 gtk_text_buffer_get_end_iter (buffer, &iter);
341 gtk_text_buffer_insert_with_tags_by_name (buffer,