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-theme-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_get_property (GObject *object,
45 static void theme_irc_set_property (GObject *object,
49 static EmpathyThemeContext *
50 theme_irc_setup_with_view (EmpathyTheme *theme,
51 EmpathyChatView *view);
52 static void theme_irc_detach_from_view (EmpathyTheme *theme,
53 EmpathyThemeContext *context,
54 EmpathyChatView *view);
55 static void theme_irc_append_message (EmpathyTheme *theme,
56 EmpathyThemeContext *context,
57 EmpathyChatView *view,
58 EmpathyMessage *message);
59 static void theme_irc_append_event (EmpathyTheme *theme,
60 EmpathyThemeContext *context,
61 EmpathyChatView *view,
63 static void theme_irc_append_timestamp (EmpathyTheme *theme,
64 EmpathyThemeContext *context,
65 EmpathyChatView *view,
66 EmpathyMessage *message,
69 static void theme_irc_append_spacing (EmpathyTheme *theme,
70 EmpathyThemeContext *context,
71 EmpathyChatView *view);
79 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_THEME);
82 empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
84 GObjectClass *object_class;
85 EmpathyThemeClass *theme_class;
87 object_class = G_OBJECT_CLASS (class);
88 theme_class = EMPATHY_THEME_CLASS (class);
90 object_class->finalize = theme_irc_finalize;
91 object_class->get_property = theme_irc_get_property;
92 object_class->set_property = theme_irc_set_property;
94 theme_class->setup_with_view = theme_irc_setup_with_view;
95 theme_class->detach_from_view = theme_irc_detach_from_view;
96 theme_class->append_message = theme_irc_append_message;
97 theme_class->append_event = theme_irc_append_event;
98 theme_class->append_timestamp = theme_irc_append_timestamp;
99 theme_class->append_spacing = theme_irc_append_spacing;
101 g_object_class_install_property (object_class,
103 g_param_spec_int ("my-prop",
110 g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
114 empathy_theme_irc_init (EmpathyThemeIrc *presence)
116 EmpathyThemeIrcPriv *priv;
118 priv = GET_PRIV (presence);
122 theme_irc_finalize (GObject *object)
124 EmpathyThemeIrcPriv *priv;
126 priv = GET_PRIV (object);
128 (G_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
132 theme_irc_get_property (GObject *object,
137 EmpathyThemeIrcPriv *priv;
139 priv = GET_PRIV (object);
143 g_value_set_int (value, priv->my_prop);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
151 theme_irc_set_property (GObject *object,
156 EmpathyThemeIrcPriv *priv;
158 priv = GET_PRIV (object);
162 priv->my_prop = g_value_get_int (value);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
171 theme_irc_fixup_tag_table (EmpathyTheme *theme, EmpathyChatView *view)
173 GtkTextBuffer *buffer;
175 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
177 /* IRC style tags. */
178 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-self");
179 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-body-self");
180 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-action-self");
182 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-other");
183 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-body-other");
184 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-action-other");
186 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-highlight");
187 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-spacing");
188 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-time");
189 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-event");
190 empathy_theme_utils_ensure_tag_by_name (buffer, "irc-link");
194 theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
196 EmpathyThemeIrcPriv *priv;
197 GtkTextBuffer *buffer;
198 GtkTextTagTable *table;
201 priv = GET_PRIV (theme);
203 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
204 table = gtk_text_buffer_get_tag_table (buffer);
206 tag = empathy_theme_utils_init_tag_by_name (table, "irc-spacing");
210 empathy_theme_utils_add_tag (table, tag);
212 tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-self");
214 "foreground", "sea green",
216 empathy_theme_utils_add_tag (table, tag);
218 tag = empathy_theme_utils_init_tag_by_name (table, "irc-body-self");
220 /* To get the default theme color: */
221 "foreground-set", FALSE,
223 empathy_theme_utils_add_tag (table, tag);
225 tag = empathy_theme_utils_init_tag_by_name (table, "irc-action-self");
227 "foreground", "brown4",
228 "style", PANGO_STYLE_ITALIC,
230 empathy_theme_utils_add_tag (table, tag);
232 tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-highlight");
234 "foreground", "indian red",
235 "weight", PANGO_WEIGHT_BOLD,
237 empathy_theme_utils_add_tag (table, tag);
239 tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-other");
241 "foreground", "skyblue4",
243 empathy_theme_utils_add_tag (table, tag);
245 tag = empathy_theme_utils_init_tag_by_name (table, "irc-body-other");
247 /* To get the default theme color: */
248 "foreground-set", FALSE,
250 empathy_theme_utils_add_tag (table, tag);
252 tag = empathy_theme_utils_init_tag_by_name (table, "irc-action-other");
254 "foreground", "brown4",
255 "style", PANGO_STYLE_ITALIC,
257 empathy_theme_utils_add_tag (table, tag);
259 tag = empathy_theme_utils_init_tag_by_name (table, "irc-time");
261 "foreground", "darkgrey",
262 "justification", GTK_JUSTIFY_CENTER,
264 empathy_theme_utils_add_tag (table, tag);
266 tag = empathy_theme_utils_init_tag_by_name (table, "irc-event");
268 "foreground", "PeachPuff4",
269 "justification", GTK_JUSTIFY_LEFT,
271 empathy_theme_utils_add_tag (table, tag);
273 tag = empathy_theme_utils_init_tag_by_name (table, "invite");
275 "foreground", "sienna",
277 empathy_theme_utils_add_tag (table, tag);
279 tag = empathy_theme_utils_init_tag_by_name (table, "irc-link");
281 "foreground", "steelblue",
282 "underline", PANGO_UNDERLINE_SINGLE,
284 empathy_theme_utils_add_tag (table, tag);
288 static EmpathyThemeContext *
289 theme_irc_setup_with_view (EmpathyTheme *theme, EmpathyChatView *view)
291 theme_irc_fixup_tag_table (theme, view);
292 theme_irc_apply_theme_classic (theme, view);
293 empathy_chat_view_set_margin (view, 3);
299 theme_irc_detach_from_view (EmpathyTheme *theme,
300 EmpathyThemeContext *context,
301 EmpathyChatView *view)
303 /* Free the context */
307 theme_irc_append_message (EmpathyTheme *theme,
308 EmpathyThemeContext *context,
309 EmpathyChatView *view,
310 EmpathyMessage *message)
312 GtkTextBuffer *buffer;
314 const gchar *nick_tag;
315 const gchar *body_tag;
318 EmpathyContact *contact;
320 empathy_theme_maybe_append_date_and_time (theme, context, view, message);
322 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
324 contact = empathy_message_get_sender (message);
325 name = empathy_contact_get_name (contact);
327 if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
328 if (empathy_contact_is_user (contact)) {
329 body_tag = "irc-action-self";
331 body_tag = "irc-action-other";
334 tmp = g_strdup_printf (" * %s %s",
335 empathy_contact_get_name (contact),
336 empathy_message_get_body (message));
337 empathy_theme_append_text (theme, context, view, tmp,
338 body_tag, "irc-link");
343 if (empathy_contact_is_user (contact)) {
344 nick_tag = "irc-nick-self";
345 body_tag = "irc-body-self";
347 if (empathy_chat_should_highlight_nick (message)) {
348 nick_tag = "irc-nick-highlight";
350 nick_tag = "irc-nick-other";
353 body_tag = "irc-body-other";
356 gtk_text_buffer_get_end_iter (buffer, &iter);
359 tmp = g_strdup_printf ("%s: ", name);
360 gtk_text_buffer_insert_with_tags_by_name (buffer,
370 empathy_theme_append_text (theme, context, view,
371 empathy_message_get_body (message),
372 body_tag, "irc-link");
376 theme_irc_append_event (EmpathyTheme *theme,
377 EmpathyThemeContext *context,
378 EmpathyChatView *view,
381 GtkTextBuffer *buffer;
385 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
387 empathy_theme_maybe_append_date_and_time (theme, context, view, NULL);
389 gtk_text_buffer_get_end_iter (buffer, &iter);
391 msg = g_strdup_printf (" - %s\n", str);
392 gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
400 theme_irc_append_timestamp (EmpathyTheme *theme,
401 EmpathyThemeContext *context,
402 EmpathyChatView *view,
403 EmpathyMessage *message,
407 GtkTextBuffer *buffer;
413 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
415 date = empathy_message_get_date_and_time (message, ×tamp);
417 str = g_string_new (NULL);
419 if (show_time || show_date) {
420 empathy_theme_append_spacing (theme,
424 g_string_append (str, "- ");
430 g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
431 g_string_append (str, buf);
434 g_string_append (str, ", ");
443 tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
444 g_string_append (str, tmp);
448 if (show_time || show_date) {
449 g_string_append (str, " -\n");
451 gtk_text_buffer_get_end_iter (buffer, &iter);
452 gtk_text_buffer_insert_with_tags_by_name (buffer,
458 empathy_chat_view_set_last_timestamp (view, timestamp);
461 g_string_free (str, TRUE);
465 theme_irc_append_spacing (EmpathyTheme *theme,
466 EmpathyThemeContext *context,
467 EmpathyChatView *view)
469 GtkTextBuffer *buffer;
472 g_return_if_fail (EMPATHY_IS_THEME (theme));
473 g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
475 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
477 gtk_text_buffer_get_end_iter (buffer, &iter);
478 gtk_text_buffer_insert_with_tags_by_name (buffer,