1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Imendio AB
4 * Copyright (C) 2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <glib/gi18n-lib.h>
28 #include <libempathy/empathy-utils.h>
29 #include "empathy-theme-irc.h"
30 #include "empathy-ui-utils.h"
32 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeIrc)
35 } EmpathyThemeIrcPriv;
37 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_CHAT_TEXT_VIEW);
40 theme_irc_create_tags (EmpathyThemeIrc *theme)
42 GtkTextBuffer *buffer;
44 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
46 gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_SELF, NULL);
47 gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_OTHER, NULL);
48 gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT, NULL);
52 theme_irc_append_message (EmpathyChatTextView *view,
53 EmpathyMessage *message)
55 GtkTextBuffer *buffer;
57 const gchar *nick_tag;
60 EmpathyContact *contact;
62 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
64 contact = empathy_message_get_sender (message);
65 name = empathy_contact_get_name (contact);
67 if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
68 tmp = g_strdup_printf (" * %s %s",
69 empathy_contact_get_name (contact),
70 empathy_message_get_body (message));
71 empathy_chat_text_view_append_body (view, tmp,
72 EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION);
77 if (empathy_contact_is_user (contact)) {
78 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_SELF;
80 if (empathy_message_should_highlight (message)) {
81 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT;
83 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_OTHER;
87 gtk_text_buffer_get_end_iter (buffer, &iter);
90 tmp = g_strdup_printf ("%s: ", name);
91 gtk_text_buffer_insert_with_tags_by_name (buffer,
101 empathy_chat_text_view_append_body (view,
102 empathy_message_get_body (message),
103 EMPATHY_CHAT_TEXT_VIEW_TAG_BODY);
107 empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
109 GObjectClass *object_class;
110 EmpathyChatTextViewClass *chat_text_view_class;
112 object_class = G_OBJECT_CLASS (class);
113 chat_text_view_class = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
115 chat_text_view_class->append_message = theme_irc_append_message;
117 g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
121 empathy_theme_irc_init (EmpathyThemeIrc *theme)
123 EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
124 EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
128 theme_irc_create_tags (theme);
138 empathy_theme_irc_new (void)
140 return g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);