/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2007 Imendio AB
+ * Copyright (C) 2008 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include "config.h"
-#include <glib/gi18n.h>
-#include <libempathy/empathy-debug.h>
+#include <glib/gi18n-lib.h>
-#include "empathy-chat.h"
-#include "empathy-ui-utils.h"
+#include <libempathy/empathy-utils.h>
#include "empathy-theme-irc.h"
+#include "empathy-ui-utils.h"
-#define DEBUG_DOMAIN "Theme"
-
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv))
-
-typedef struct _EmpathyThemeIrcPriv EmpathyThemeIrcPriv;
-
-struct _EmpathyThemeIrcPriv {
- gint my_prop;
-};
-
-static void theme_irc_finalize (GObject *object);
-static void theme_irc_update_view (EmpathyTheme *theme,
- EmpathyChatView *view);
-static void theme_irc_append_message (EmpathyTheme *theme,
- EmpathyChatView *view,
- EmpathyMessage *message);
-static void theme_irc_append_event (EmpathyTheme *theme,
- EmpathyChatView *view,
- const gchar *str);
-static void theme_irc_append_timestamp (EmpathyTheme *theme,
- EmpathyChatView *view,
- EmpathyMessage *message,
- gboolean show_date,
- gboolean show_time);
-static void theme_irc_append_spacing (EmpathyTheme *theme,
- EmpathyChatView *view);
-
-
-enum {
- PROP_0,
- PROP_MY_PROP
-};
-
-G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_THEME);
-
-static void
-empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
-{
- GObjectClass *object_class;
- EmpathyThemeClass *theme_class;
-
- object_class = G_OBJECT_CLASS (class);
- theme_class = EMPATHY_THEME_CLASS (class);
-
- object_class->finalize = theme_irc_finalize;
-
- theme_class->update_view = theme_irc_update_view;
- theme_class->append_message = theme_irc_append_message;
- theme_class->append_event = theme_irc_append_event;
- theme_class->append_timestamp = theme_irc_append_timestamp;
- theme_class->append_spacing = theme_irc_append_spacing;
-
- g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
-}
-
-static void
-empathy_theme_irc_init (EmpathyThemeIrc *presence)
-{
- EmpathyThemeIrcPriv *priv;
-
- priv = GET_PRIV (presence);
-}
-
-static void
-theme_irc_finalize (GObject *object)
-{
- EmpathyThemeIrcPriv *priv;
-
- priv = GET_PRIV (object);
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeIrc)
+typedef struct {
+ gpointer dummy;
+} EmpathyThemeIrcPriv;
- (G_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
-}
+G_DEFINE_TYPE (EmpathyThemeIrc, empathy_theme_irc, EMPATHY_TYPE_CHAT_TEXT_VIEW);
static void
-theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
+theme_irc_create_tags (EmpathyThemeIrc *theme)
{
- EmpathyThemeIrcPriv *priv;
- GtkTextBuffer *buffer;
-
- priv = GET_PRIV (theme);
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- empathy_text_buffer_tag_set (buffer, "irc-spacing",
- "size", 2000,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-nick-self",
- "foreground", "sea green",
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-body-self",
- /* To get the default theme color: */
- "foreground-set", FALSE,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-action-self",
- "foreground", "brown4",
- "style", PANGO_STYLE_ITALIC,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-nick-highlight",
- "foreground", "indian red",
- "weight", PANGO_WEIGHT_BOLD,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-nick-other",
- "foreground", "skyblue4",
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-body-other",
- /* To get the default theme color: */
- "foreground-set", FALSE,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-action-other",
- "foreground", "brown4",
- "style", PANGO_STYLE_ITALIC,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-time",
- "foreground", "darkgrey",
- "justification", GTK_JUSTIFY_CENTER,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-event",
- "foreground", "PeachPuff4",
- "justification", GTK_JUSTIFY_LEFT,
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "invite",
- "foreground", "sienna",
- NULL);
-
- empathy_text_buffer_tag_set (buffer, "irc-link",
- "foreground", "steelblue",
- "underline", PANGO_UNDERLINE_SINGLE,
- NULL);
-}
+ GtkTextBuffer *buffer;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
-static void
-theme_irc_update_view (EmpathyTheme *theme, EmpathyChatView *view)
-{
- theme_irc_apply_theme_classic (theme, view);
- empathy_chat_view_set_margin (view, 3);
+ gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_SELF, NULL);
+ gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_OTHER, NULL);
+ gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT, NULL);
}
static void
-theme_irc_append_message (EmpathyTheme *theme,
- EmpathyChatView *view,
- EmpathyMessage *message)
+theme_irc_append_message (EmpathyChatTextView *view,
+ EmpathyMessage *message,
+ gboolean should_highlight)
{
GtkTextBuffer *buffer;
const gchar *name;
const gchar *nick_tag;
- const gchar *body_tag;
GtkTextIter iter;
gchar *tmp;
EmpathyContact *contact;
- empathy_theme_maybe_append_date_and_time (theme, view, message);
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
contact = empathy_message_get_sender (message);
- name = empathy_contact_get_name (contact);
+ name = empathy_contact_get_logged_alias (contact);
- if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
- if (empathy_contact_is_user (contact)) {
- body_tag = "irc-action-self";
- } else {
- body_tag = "irc-action-other";
- }
-
- tmp = g_strdup_printf (" * %s %s",
- empathy_contact_get_name (contact),
+ if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
+ tmp = g_strdup_printf (" * %s %s",
+ empathy_contact_get_logged_alias (contact),
empathy_message_get_body (message));
- empathy_theme_append_text (theme, view, tmp,
- body_tag, "irc-link");
+ empathy_chat_text_view_append_body (view, tmp,
+ EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION);
g_free (tmp);
return;
}
if (empathy_contact_is_user (contact)) {
- nick_tag = "irc-nick-self";
- body_tag = "irc-body-self";
+ nick_tag = EMPATHY_THEME_IRC_TAG_NICK_SELF;
} else {
- if (empathy_chat_should_highlight_nick (message)) {
- nick_tag = "irc-nick-highlight";
+ if (should_highlight) {
+ nick_tag = EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT;
} else {
- nick_tag = "irc-nick-other";
+ nick_tag = EMPATHY_THEME_IRC_TAG_NICK_OTHER;
}
-
- body_tag = "irc-body-other";
}
-
+
gtk_text_buffer_get_end_iter (buffer, &iter);
/* The nickname. */
g_free (tmp);
/* The text body. */
- empathy_theme_append_text (theme, view,
- empathy_message_get_body (message),
- body_tag, "irc-link");
+ empathy_chat_text_view_append_body (view,
+ empathy_message_get_body (message),
+ EMPATHY_CHAT_TEXT_VIEW_TAG_BODY);
}
static void
-theme_irc_append_event (EmpathyTheme *theme,
- EmpathyChatView *view,
- const gchar *str)
+empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
{
- GtkTextBuffer *buffer;
- GtkTextIter iter;
- gchar *msg;
+ GObjectClass *object_class;
+ EmpathyChatTextViewClass *chat_text_view_class;
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- empathy_theme_maybe_append_date_and_time (theme, view, NULL);
+ object_class = G_OBJECT_CLASS (class);
+ chat_text_view_class = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
- gtk_text_buffer_get_end_iter (buffer, &iter);
+ chat_text_view_class->append_message = theme_irc_append_message;
- msg = g_strdup_printf (" - %s\n", str);
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- msg, -1,
- "irc-event",
- NULL);
- g_free (msg);
+ g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
}
static void
-theme_irc_append_timestamp (EmpathyTheme *theme,
- EmpathyChatView *view,
- EmpathyMessage *message,
- gboolean show_date,
- gboolean show_time)
+empathy_theme_irc_init (EmpathyThemeIrc *theme)
{
- GtkTextBuffer *buffer;
- time_t timestamp;
- GDate *date;
- GtkTextIter iter;
- GString *str;
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
+ EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
- date = empathy_message_get_date_and_time (message, ×tamp);
+ theme->priv = priv;
- str = g_string_new (NULL);
+ theme_irc_create_tags (theme);
- if (show_time || show_date) {
- empathy_theme_append_spacing (theme, view);
-
- g_string_append (str, "- ");
- }
-
- if (show_date) {
- gchar buf[256];
-
- g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
- g_string_append (str, buf);
-
- if (show_time) {
- g_string_append (str, ", ");
- }
- }
-
- g_date_free (date);
-
- if (show_time) {
- gchar *tmp;
-
- tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
- g_string_append (str, tmp);
- g_free (tmp);
- }
-
- if (show_time || show_date) {
- g_string_append (str, " -\n");
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert_with_tags_by_name (buffer,
- &iter,
- str->str, -1,
- "irc-time",
- NULL);
-
- empathy_chat_view_set_last_timestamp (view, timestamp);
- }
-
- g_string_free (str, TRUE);
+ /* Define margin */
+ g_object_set (theme,
+ "left-margin", 3,
+ "right-margin", 3,
+ NULL);
}
-static void
-theme_irc_append_spacing (EmpathyTheme *theme,
- EmpathyChatView *view)
+EmpathyThemeIrc *
+empathy_theme_irc_new (void)
{
- GtkTextBuffer *buffer;
- GtkTextIter iter;
-
- g_return_if_fail (EMPATHY_IS_THEME (theme));
- g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert_with_tags_by_name (buffer,
- &iter,
- "\n",
- -1,
- "cut",
- "irc-spacing",
- NULL);
+ return g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
}