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
,
54 gboolean should_highlight
)
56 GtkTextBuffer
*buffer
;
58 const gchar
*nick_tag
;
61 EmpathyContact
*contact
;
63 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (view
));
65 contact
= empathy_message_get_sender (message
);
66 name
= empathy_contact_get_logged_alias (contact
);
68 if (empathy_message_get_tptype (message
) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION
) {
69 tmp
= g_strdup_printf (" * %s %s",
70 empathy_contact_get_logged_alias (contact
),
71 empathy_message_get_body (message
));
72 empathy_chat_text_view_append_body (view
, tmp
,
73 EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION
);
78 if (empathy_contact_is_user (contact
)) {
79 nick_tag
= EMPATHY_THEME_IRC_TAG_NICK_SELF
;
81 if (should_highlight
) {
82 nick_tag
= EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT
;
84 nick_tag
= EMPATHY_THEME_IRC_TAG_NICK_OTHER
;
88 gtk_text_buffer_get_end_iter (buffer
, &iter
);
91 tmp
= g_strdup_printf ("%s: ", name
);
92 gtk_text_buffer_insert_with_tags_by_name (buffer
,
102 empathy_chat_text_view_append_body (view
,
103 empathy_message_get_body (message
),
104 EMPATHY_CHAT_TEXT_VIEW_TAG_BODY
);
108 empathy_theme_irc_class_init (EmpathyThemeIrcClass
*class)
110 GObjectClass
*object_class
;
111 EmpathyChatTextViewClass
*chat_text_view_class
;
113 object_class
= G_OBJECT_CLASS (class);
114 chat_text_view_class
= EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
116 chat_text_view_class
->append_message
= theme_irc_append_message
;
118 g_type_class_add_private (object_class
, sizeof (EmpathyThemeIrcPriv
));
122 empathy_theme_irc_init (EmpathyThemeIrc
*theme
)
124 EmpathyThemeIrcPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (theme
,
125 EMPATHY_TYPE_THEME_IRC
, EmpathyThemeIrcPriv
);
129 theme_irc_create_tags (theme
);
139 empathy_theme_irc_new (void)
141 return g_object_new (EMPATHY_TYPE_THEME_IRC
, NULL
);