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>
24 #include <libempathy/empathy-debug.h>
26 #include "empathy-chat.h"
27 #include "empathy-ui-utils.h"
28 #include "empathy-theme-irc.h"
30 #define DEBUG_DOMAIN "Theme"
32 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv))
34 typedef struct _EmpathyThemeIrcPriv EmpathyThemeIrcPriv;
36 struct _EmpathyThemeIrcPriv {
40 static void theme_irc_finalize (GObject *object);
41 static void theme_irc_update_view (EmpathyTheme *theme,
42 EmpathyChatView *view);
43 static void theme_irc_append_message (EmpathyTheme *theme,
44 EmpathyChatView *view,
45 EmpathyMessage *message);
46 static void theme_irc_append_event (EmpathyTheme *theme,
47 EmpathyChatView *view,
49 static void theme_irc_append_timestamp (EmpathyTheme *theme,
50 EmpathyChatView *view,
51 EmpathyMessage *message,
54 static void theme_irc_append_spacing (EmpathyTheme *theme,
55 EmpathyChatView *view);
63 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_THEME);
66 empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
68 GObjectClass *object_class;
69 EmpathyThemeClass *theme_class;
71 object_class = G_OBJECT_CLASS (class);
72 theme_class = EMPATHY_THEME_CLASS (class);
74 object_class->finalize = theme_irc_finalize;
76 theme_class->update_view = theme_irc_update_view;
77 theme_class->append_message = theme_irc_append_message;
78 theme_class->append_event = theme_irc_append_event;
79 theme_class->append_timestamp = theme_irc_append_timestamp;
80 theme_class->append_spacing = theme_irc_append_spacing;
82 g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
86 empathy_theme_irc_init (EmpathyThemeIrc *presence)
88 EmpathyThemeIrcPriv *priv;
90 priv = GET_PRIV (presence);
94 theme_irc_finalize (GObject *object)
96 EmpathyThemeIrcPriv *priv;
98 priv = GET_PRIV (object);
100 (G_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
104 theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
106 EmpathyThemeIrcPriv *priv;
107 GtkTextBuffer *buffer;
109 priv = GET_PRIV (theme);
111 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
113 empathy_text_buffer_tag_set (buffer, "irc-spacing",
117 empathy_text_buffer_tag_set (buffer, "irc-nick-self",
118 "foreground", "sea green",
121 empathy_text_buffer_tag_set (buffer, "irc-body-self",
122 /* To get the default theme color: */
123 "foreground-set", FALSE,
126 empathy_text_buffer_tag_set (buffer, "irc-action-self",
127 "foreground", "brown4",
128 "style", PANGO_STYLE_ITALIC,
131 empathy_text_buffer_tag_set (buffer, "irc-nick-highlight",
132 "foreground", "indian red",
133 "weight", PANGO_WEIGHT_BOLD,
136 empathy_text_buffer_tag_set (buffer, "irc-nick-other",
137 "foreground", "skyblue4",
140 empathy_text_buffer_tag_set (buffer, "irc-body-other",
141 /* To get the default theme color: */
142 "foreground-set", FALSE,
145 empathy_text_buffer_tag_set (buffer, "irc-action-other",
146 "foreground", "brown4",
147 "style", PANGO_STYLE_ITALIC,
150 empathy_text_buffer_tag_set (buffer, "irc-time",
151 "foreground", "darkgrey",
152 "justification", GTK_JUSTIFY_CENTER,
155 empathy_text_buffer_tag_set (buffer, "irc-event",
156 "foreground", "PeachPuff4",
157 "justification", GTK_JUSTIFY_LEFT,
160 empathy_text_buffer_tag_set (buffer, "invite",
161 "foreground", "sienna",
164 empathy_text_buffer_tag_set (buffer, "irc-link",
165 "foreground", "steelblue",
166 "underline", PANGO_UNDERLINE_SINGLE,
172 theme_irc_update_view (EmpathyTheme *theme, EmpathyChatView *view)
174 theme_irc_apply_theme_classic (theme, view);
175 empathy_chat_view_set_margin (view, 3);
179 theme_irc_append_message (EmpathyTheme *theme,
180 EmpathyChatView *view,
181 EmpathyMessage *message)
183 GtkTextBuffer *buffer;
185 const gchar *nick_tag;
186 const gchar *body_tag;
189 EmpathyContact *contact;
191 empathy_theme_maybe_append_date_and_time (theme, view, message);
193 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
195 contact = empathy_message_get_sender (message);
196 name = empathy_contact_get_name (contact);
198 if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
199 if (empathy_contact_is_user (contact)) {
200 body_tag = "irc-action-self";
202 body_tag = "irc-action-other";
205 tmp = g_strdup_printf (" * %s %s",
206 empathy_contact_get_name (contact),
207 empathy_message_get_body (message));
208 empathy_theme_append_text (theme, view, tmp,
209 body_tag, "irc-link");
214 if (empathy_contact_is_user (contact)) {
215 nick_tag = "irc-nick-self";
216 body_tag = "irc-body-self";
218 if (empathy_chat_should_highlight_nick (message)) {
219 nick_tag = "irc-nick-highlight";
221 nick_tag = "irc-nick-other";
224 body_tag = "irc-body-other";
227 gtk_text_buffer_get_end_iter (buffer, &iter);
230 tmp = g_strdup_printf ("%s: ", name);
231 gtk_text_buffer_insert_with_tags_by_name (buffer,
241 empathy_theme_append_text (theme, view,
242 empathy_message_get_body (message),
243 body_tag, "irc-link");
247 theme_irc_append_event (EmpathyTheme *theme,
248 EmpathyChatView *view,
251 GtkTextBuffer *buffer;
255 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
257 empathy_theme_maybe_append_date_and_time (theme, view, NULL);
259 gtk_text_buffer_get_end_iter (buffer, &iter);
261 msg = g_strdup_printf (" - %s\n", str);
262 gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
270 theme_irc_append_timestamp (EmpathyTheme *theme,
271 EmpathyChatView *view,
272 EmpathyMessage *message,
276 GtkTextBuffer *buffer;
282 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
284 date = empathy_message_get_date_and_time (message, ×tamp);
286 str = g_string_new (NULL);
288 if (show_time || show_date) {
289 empathy_theme_append_spacing (theme, view);
291 g_string_append (str, "- ");
297 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
298 g_string_append (str, buf);
301 g_string_append (str, ", ");
310 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
311 g_string_append (str, tmp);
315 if (show_time || show_date) {
316 g_string_append (str, " -\n");
318 gtk_text_buffer_get_end_iter (buffer, &iter);
319 gtk_text_buffer_insert_with_tags_by_name (buffer,
325 empathy_chat_view_set_last_timestamp (view, timestamp);
328 g_string_free (str, TRUE);
332 theme_irc_append_spacing (EmpathyTheme *theme,
333 EmpathyChatView *view)
335 GtkTextBuffer *buffer;
338 g_return_if_fail (EMPATHY_IS_THEME (theme));
339 g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
341 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
343 gtk_text_buffer_get_end_iter (buffer, &iter);
344 gtk_text_buffer_insert_with_tags_by_name (buffer,