Merge branch 'trivia'
[empathy-mirror.git] / libempathy-gtk / empathy-theme-irc.c
blobafd59523e125f043df7c5d007ff90d11f22f2d24
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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>
24 #include "config.h"
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)
33 typedef struct {
34 gpointer dummy;
35 } EmpathyThemeIrcPriv;
37 G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_CHAT_TEXT_VIEW);
39 static void
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);
51 static void
52 theme_irc_append_message (EmpathyChatTextView *view,
53 EmpathyMessage *message)
55 GtkTextBuffer *buffer;
56 const gchar *name;
57 const gchar *nick_tag;
58 GtkTextIter iter;
59 gchar *tmp;
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_alias (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_alias (contact),
70 empathy_message_get_body (message));
71 empathy_chat_text_view_append_body (view, tmp,
72 EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION);
73 g_free (tmp);
74 return;
77 if (empathy_contact_is_user (contact)) {
78 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_SELF;
79 } else {
80 if (empathy_message_should_highlight (message)) {
81 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT;
82 } else {
83 nick_tag = EMPATHY_THEME_IRC_TAG_NICK_OTHER;
87 gtk_text_buffer_get_end_iter (buffer, &iter);
89 /* The nickname. */
90 tmp = g_strdup_printf ("%s: ", name);
91 gtk_text_buffer_insert_with_tags_by_name (buffer,
92 &iter,
93 tmp,
94 -1,
95 "cut",
96 nick_tag,
97 NULL);
98 g_free (tmp);
100 /* The text body. */
101 empathy_chat_text_view_append_body (view,
102 empathy_message_get_body (message),
103 EMPATHY_CHAT_TEXT_VIEW_TAG_BODY);
106 static void
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));
120 static void
121 empathy_theme_irc_init (EmpathyThemeIrc *theme)
123 EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
124 EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
126 theme->priv = priv;
128 theme_irc_create_tags (theme);
130 /* Define margin */
131 g_object_set (theme,
132 "left-margin", 3,
133 "right-margin", 3,
134 NULL);
137 EmpathyThemeIrc *
138 empathy_theme_irc_new (void)
140 return g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);