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 <libempathy/empathy-utils.h>
26 #include "empathy-chat.h"
27 #include "empathy-ui-utils.h"
28 #include "empathy-theme-irc.h"
30 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeIrc)
33 } EmpathyThemeIrcPriv;
35 static void theme_irc_finalize (GObject *object);
36 static void theme_irc_update_view (EmpathyTheme *theme,
37 EmpathyChatView *view);
38 static void theme_irc_append_message (EmpathyTheme *theme,
39 EmpathyChatView *view,
40 EmpathyMessage *message);
41 static void theme_irc_append_event (EmpathyTheme *theme,
42 EmpathyChatView *view,
44 static void theme_irc_append_timestamp (EmpathyTheme *theme,
45 EmpathyChatView *view,
46 EmpathyMessage *message,
49 static void theme_irc_append_spacing (EmpathyTheme *theme,
50 EmpathyChatView *view);
58 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_THEME);
61 empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
63 GObjectClass *object_class;
64 EmpathyThemeClass *theme_class;
66 object_class = G_OBJECT_CLASS (class);
67 theme_class = EMPATHY_THEME_CLASS (class);
69 object_class->finalize = theme_irc_finalize;
71 theme_class->update_view = theme_irc_update_view;
72 theme_class->append_message = theme_irc_append_message;
73 theme_class->append_event = theme_irc_append_event;
74 theme_class->append_timestamp = theme_irc_append_timestamp;
75 theme_class->append_spacing = theme_irc_append_spacing;
77 g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
81 empathy_theme_irc_init (EmpathyThemeIrc *theme)
83 EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
84 EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
90 theme_irc_finalize (GObject *object)
92 EmpathyThemeIrcPriv *priv;
94 priv = GET_PRIV (object);
96 (G_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
100 theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
102 EmpathyThemeIrcPriv *priv;
103 GtkTextBuffer *buffer;
105 priv = GET_PRIV (theme);
107 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
109 empathy_text_buffer_tag_set (buffer, "irc-spacing",
113 empathy_text_buffer_tag_set (buffer, "irc-nick-self",
114 "foreground", "sea green",
117 empathy_text_buffer_tag_set (buffer, "irc-body-self",
118 /* To get the default theme color: */
119 "foreground-set", FALSE,
122 empathy_text_buffer_tag_set (buffer, "irc-action-self",
123 "foreground", "brown4",
124 "style", PANGO_STYLE_ITALIC,
127 empathy_text_buffer_tag_set (buffer, "irc-nick-highlight",
128 "foreground", "indian red",
129 "weight", PANGO_WEIGHT_BOLD,
132 empathy_text_buffer_tag_set (buffer, "irc-nick-other",
133 "foreground", "skyblue4",
136 empathy_text_buffer_tag_set (buffer, "irc-body-other",
137 /* To get the default theme color: */
138 "foreground-set", FALSE,
141 empathy_text_buffer_tag_set (buffer, "irc-action-other",
142 "foreground", "brown4",
143 "style", PANGO_STYLE_ITALIC,
146 empathy_text_buffer_tag_set (buffer, "irc-time",
147 "foreground", "darkgrey",
148 "justification", GTK_JUSTIFY_CENTER,
151 empathy_text_buffer_tag_set (buffer, "irc-event",
152 "foreground", "PeachPuff4",
153 "justification", GTK_JUSTIFY_LEFT,
156 empathy_text_buffer_tag_set (buffer, "invite",
157 "foreground", "sienna",
160 empathy_text_buffer_tag_set (buffer, "irc-link",
161 "foreground", "steelblue",
162 "underline", PANGO_UNDERLINE_SINGLE,
168 theme_irc_update_view (EmpathyTheme *theme, EmpathyChatView *view)
170 theme_irc_apply_theme_classic (theme, view);
171 empathy_chat_view_set_margin (view, 3);
175 theme_irc_append_message (EmpathyTheme *theme,
176 EmpathyChatView *view,
177 EmpathyMessage *message)
179 GtkTextBuffer *buffer;
181 const gchar *nick_tag;
182 const gchar *body_tag;
185 EmpathyContact *contact;
187 empathy_theme_maybe_append_date_and_time (theme, view, message);
189 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
191 contact = empathy_message_get_sender (message);
192 name = empathy_contact_get_name (contact);
194 if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
195 if (empathy_contact_is_user (contact)) {
196 body_tag = "irc-action-self";
198 body_tag = "irc-action-other";
201 tmp = g_strdup_printf (" * %s %s",
202 empathy_contact_get_name (contact),
203 empathy_message_get_body (message));
204 empathy_theme_append_text (theme, view, tmp,
205 body_tag, "irc-link");
210 if (empathy_contact_is_user (contact)) {
211 nick_tag = "irc-nick-self";
212 body_tag = "irc-body-self";
214 if (empathy_message_should_highlight (message)) {
215 nick_tag = "irc-nick-highlight";
217 nick_tag = "irc-nick-other";
220 body_tag = "irc-body-other";
223 gtk_text_buffer_get_end_iter (buffer, &iter);
226 tmp = g_strdup_printf ("%s: ", name);
227 gtk_text_buffer_insert_with_tags_by_name (buffer,
237 empathy_theme_append_text (theme, view,
238 empathy_message_get_body (message),
239 body_tag, "irc-link");
243 theme_irc_append_event (EmpathyTheme *theme,
244 EmpathyChatView *view,
247 GtkTextBuffer *buffer;
251 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
253 empathy_theme_maybe_append_date_and_time (theme, view, NULL);
255 gtk_text_buffer_get_end_iter (buffer, &iter);
257 msg = g_strdup_printf (" - %s\n", str);
258 gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
266 theme_irc_append_timestamp (EmpathyTheme *theme,
267 EmpathyChatView *view,
268 EmpathyMessage *message,
272 GtkTextBuffer *buffer;
278 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
280 date = empathy_message_get_date_and_time (message, ×tamp);
282 str = g_string_new (NULL);
284 if (show_time || show_date) {
285 empathy_theme_append_spacing (theme, view);
287 g_string_append (str, "- ");
293 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
294 g_string_append (str, buf);
297 g_string_append (str, ", ");
306 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
307 g_string_append (str, tmp);
311 if (show_time || show_date) {
312 g_string_append (str, " -\n");
314 gtk_text_buffer_get_end_iter (buffer, &iter);
315 gtk_text_buffer_insert_with_tags_by_name (buffer,
321 empathy_chat_view_set_last_timestamp (view, timestamp);
324 g_string_free (str, TRUE);
328 theme_irc_append_spacing (EmpathyTheme *theme,
329 EmpathyChatView *view)
331 GtkTextBuffer *buffer;
334 g_return_if_fail (EMPATHY_IS_THEME (theme));
335 g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
337 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
339 gtk_text_buffer_get_end_iter (buffer, &iter);
340 gtk_text_buffer_insert_with_tags_by_name (buffer,