aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-irc.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-12-16 17:24:35 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-12-16 17:24:35 +0800
commit109f46a8278fc797ba526f69f44335063903066c (patch)
treee65ec3672e6c2df4ede307296d81adf348c7e560 /libempathy-gtk/empathy-theme-irc.c
parent031e66bd2b0b63a6d33d3242e24392e2109a82e2 (diff)
downloadgsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.gz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.bz2
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.lz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.xz
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.tar.zst
gsoc2013-empathy-109f46a8278fc797ba526f69f44335063903066c.zip
Completely rework the theming system to make easy implementing themes based on other classes like webkit.
svn path=/trunk/; revision=1993
Diffstat (limited to 'libempathy-gtk/empathy-theme-irc.c')
-rw-r--r--libempathy-gtk/empathy-theme-irc.c293
1 files changed, 47 insertions, 246 deletions
diff --git a/libempathy-gtk/empathy-theme-irc.c b/libempathy-gtk/empathy-theme-irc.c
index da96f1ea6..4eb7329b3 100644
--- a/libempathy-gtk/empathy-theme-irc.c
+++ b/libempathy-gtk/empathy-theme-irc.c
@@ -1,6 +1,7 @@
/* -*- 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
@@ -16,6 +17,8 @@
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include "config.h"
@@ -23,201 +26,62 @@
#include <glib/gi18n-lib.h>
#include <libempathy/empathy-utils.h>
-#include "empathy-chat.h"
-#include "empathy-ui-utils.h"
#include "empathy-theme-irc.h"
+#include "empathy-ui-utils.h"
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeIrc)
typedef struct {
- gint my_prop;
+ gpointer dummy;
} EmpathyThemeIrcPriv;
-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 *theme)
-{
- EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
- EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
-
- theme->priv = priv;
-}
-
-static void
-theme_irc_finalize (GObject *object)
-{
- EmpathyThemeIrcPriv *priv;
-
- priv = GET_PRIV (object);
-
- (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,
+theme_irc_append_message (EmpathyChatTextView *view,
EmpathyMessage *message)
{
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);
if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_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),
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_message_should_highlight (message)) {
- nick_tag = "irc-nick-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);
@@ -234,115 +98,52 @@ theme_irc_append_message (EmpathyTheme *theme,
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)
+theme_irc_finalize (GObject *object)
{
- GtkTextBuffer *buffer;
- GtkTextIter iter;
- gchar *msg;
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- empathy_theme_maybe_append_date_and_time (theme, view, NULL);
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
-
- 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_OBJECT_CLASS (empathy_theme_irc_parent_class)->finalize) (object);
}
static void
-theme_irc_append_timestamp (EmpathyTheme *theme,
- EmpathyChatView *view,
- EmpathyMessage *message,
- gboolean show_date,
- gboolean show_time)
+empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
{
- GtkTextBuffer *buffer;
- time_t timestamp;
- GDate *date;
- GtkTextIter iter;
- GString *str;
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- date = empathy_message_get_date_and_time (message, &timestamp);
-
- str = g_string_new (NULL);
-
- 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);
- }
+ GObjectClass *object_class;
+ EmpathyChatTextViewClass *chat_text_view_class;
- 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);
+ object_class = G_OBJECT_CLASS (class);
+ chat_text_view_class = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
- empathy_chat_view_set_last_timestamp (view, timestamp);
- }
+ object_class->finalize = theme_irc_finalize;
+ chat_text_view_class->append_message = theme_irc_append_message;
- g_string_free (str, TRUE);
+ g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
}
static void
-theme_irc_append_spacing (EmpathyTheme *theme,
- EmpathyChatView *view)
+empathy_theme_irc_init (EmpathyThemeIrc *theme)
{
- GtkTextBuffer *buffer;
- GtkTextIter iter;
+ EmpathyThemeIrcPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
+ EMPATHY_TYPE_THEME_IRC, EmpathyThemeIrcPriv);
- g_return_if_fail (EMPATHY_IS_THEME (theme));
- g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
+ theme->priv = priv;
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ theme_irc_create_tags (theme);
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert_with_tags_by_name (buffer,
- &iter,
- "\n",
- -1,
- "cut",
- "irc-spacing",
- NULL);
+ /* Define margin */
+ g_object_set (theme,
+ "left-margin", 3,
+ "right-margin", 3,
+ NULL);
+}
+
+EmpathyThemeIrc *
+empathy_theme_irc_new (void)
+{
+ return g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
}