aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-12-29 23:49:21 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-12-29 23:49:21 +0800
commit98d76879d49bbe8acddaa0b3f056ea556bda6b70 (patch)
treed3a4656697bfc1aed894dc89011a3e5f1e91f899
parent9c0af71c275a1e1a1fcbec99b90ab62acfecf67a (diff)
downloadgsoc2013-empathy-98d76879d49bbe8acddaa0b3f056ea556bda6b70.tar.gz
gsoc2013-empathy-98d76879d49bbe8acddaa0b3f056ea556bda6b70.tar.zst
gsoc2013-empathy-98d76879d49bbe8acddaa0b3f056ea556bda6b70.zip
Simplify chat theme system
svn path=/trunk/; revision=507
-rw-r--r--libempathy-gtk/Makefile.am10
-rw-r--r--libempathy-gtk/empathy-chat-view.c54
-rw-r--r--libempathy-gtk/empathy-theme-boxes.c332
-rw-r--r--libempathy-gtk/empathy-theme-boxes.h4
-rw-r--r--libempathy-gtk/empathy-theme-irc.c270
-rw-r--r--libempathy-gtk/empathy-theme-manager.c146
-rw-r--r--libempathy-gtk/empathy-theme-utils.c90
-rw-r--r--libempathy-gtk/empathy-theme-utils.h40
-rw-r--r--libempathy-gtk/empathy-theme.c87
-rw-r--r--libempathy-gtk/empathy-theme.h119
-rw-r--r--libempathy-gtk/empathy-ui-utils.c48
-rw-r--r--libempathy-gtk/empathy-ui-utils.h7
12 files changed, 405 insertions, 802 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index 494e3c4ce..07336f55c 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -32,11 +32,10 @@ libempathy_gtk_la_SOURCES = \
empathy-contact-list-store.c \
empathy-contact-list-view.c \
empathy-preferences.c \
- empathy-theme.c \
+ empathy-theme.c \
empathy-theme-boxes.c \
- empathy-theme-irc.c \
+ empathy-theme-irc.c \
empathy-theme-manager.c \
- empathy-theme-utils.c \
empathy-smiley-manager.c \
empathy-chat-window.c \
empathy-chat.c \
@@ -89,11 +88,10 @@ libempathy_gtk_headers = \
empathy-contact-list-store.h \
empathy-contact-list-view.h \
empathy-preferences.h \
- empathy-theme.h \
+ empathy-theme.h \
empathy-theme-boxes.h \
- empathy-theme-irc.h \
+ empathy-theme-irc.h \
empathy-theme-manager.h \
- empathy-theme-utils.h \
empathy-smiley-manager.h \
empathy-chat-window.h \
empathy-chat.h \
diff --git a/libempathy-gtk/empathy-chat-view.c b/libempathy-gtk/empathy-chat-view.c
index 947281590..c7428e9df 100644
--- a/libempathy-gtk/empathy-chat-view.c
+++ b/libempathy-gtk/empathy-chat-view.c
@@ -68,7 +68,6 @@ struct _EmpathyChatViewPriv {
GtkTextBuffer *buffer;
EmpathyTheme *theme;
- gpointer theme_context;
time_t last_timestamp;
BlockType last_block_type;
@@ -130,7 +129,8 @@ static void chat_view_clear_view_cb (GtkMenuItem *
static gboolean chat_view_is_scrolled_down (EmpathyChatView *view);
static void chat_view_theme_changed_cb (EmpathyThemeManager *manager,
EmpathyChatView *view);
-static void chat_view_theme_updated_cb (EmpathyTheme *theme,
+static void chat_view_theme_notify_cb (EmpathyTheme *theme,
+ GParamSpec *param,
EmpathyChatView *view);
G_DEFINE_TYPE (EmpathyChatView, empathy_chat_view, GTK_TYPE_TEXT_VIEW);
@@ -233,12 +233,8 @@ chat_view_finalize (GObject *object)
if (priv->theme) {
g_signal_handlers_disconnect_by_func (priv->theme,
- chat_view_theme_updated_cb,
+ chat_view_theme_notify_cb,
view);
-
- empathy_theme_detach_from_view (priv->theme, priv->theme_context,
- view);
-
g_object_unref (priv->theme);
}
@@ -796,8 +792,7 @@ empathy_chat_view_append_message (EmpathyChatView *view,
chat_view_maybe_trim_buffer (view);
- empathy_theme_append_message (priv->theme, priv->theme_context,
- view, msg);
+ empathy_theme_append_message (priv->theme, view, msg);
if (bottom) {
empathy_chat_view_scroll_down (view);
@@ -820,9 +815,7 @@ empathy_chat_view_append_event (EmpathyChatView *view,
chat_view_maybe_trim_buffer (view);
- empathy_theme_append_event (priv->theme,
- priv->theme_context,
- view, str);
+ empathy_theme_append_event (priv->theme, view, str);
if (bottom) {
empathy_chat_view_scroll_down (view);
@@ -852,13 +845,10 @@ empathy_chat_view_append_button (EmpathyChatView *view,
bottom = chat_view_is_scrolled_down (view);
- empathy_theme_append_timestamp (priv->theme, priv->theme_context,
- view, NULL,
- TRUE, TRUE);
+ empathy_theme_append_timestamp (priv->theme, view, NULL, TRUE, TRUE);
if (message) {
- empathy_theme_append_text (priv->theme, priv->theme_context,
- view, message, tag, NULL);
+ empathy_theme_append_text (priv->theme, view, message, tag, NULL);
}
gtk_text_buffer_get_end_iter (priv->buffer, &iter);
@@ -1006,8 +996,6 @@ empathy_chat_view_clear (EmpathyChatView *view)
*/
priv = GET_PRIV (view);
- empathy_theme_view_cleared (priv->theme, priv->theme_context, view);
-
priv->last_block_type = BLOCK_TYPE_NONE;
priv->last_timestamp = 0;
}
@@ -1370,16 +1358,11 @@ empathy_chat_view_get_theme (EmpathyChatView *view)
}
static void
-chat_view_theme_updated_cb (EmpathyTheme *theme, EmpathyChatView *view)
+chat_view_theme_notify_cb (EmpathyTheme *theme,
+ GParamSpec *param,
+ EmpathyChatView *view)
{
- EmpathyChatViewPriv *priv;
-
- priv = GET_PRIV (view);
-
- empathy_theme_detach_from_view (priv->theme, priv->theme_context,
- view);
-
- priv->theme_context = empathy_theme_setup_with_view (theme, view);
+ empathy_theme_update_view (theme, view);
}
void
@@ -1394,24 +1377,19 @@ empathy_chat_view_set_theme (EmpathyChatView *view, EmpathyTheme *theme)
if (priv->theme) {
g_signal_handlers_disconnect_by_func (priv->theme,
- chat_view_theme_updated_cb,
+ chat_view_theme_notify_cb,
view);
- empathy_theme_detach_from_view (priv->theme, priv->theme_context,
- view);
-
g_object_unref (priv->theme);
}
priv->theme = g_object_ref (theme);
- g_signal_connect (priv->theme,
- "updated",
- G_CALLBACK (chat_view_theme_updated_cb),
+ empathy_theme_update_view (theme, view);
+ g_signal_connect (priv->theme, "notify",
+ G_CALLBACK (chat_view_theme_notify_cb),
view);
- priv->theme_context = empathy_theme_setup_with_view (theme, view);
-
- /* FIXME: Possibly redraw the function and make it a property */
+ /* FIXME: Redraw all messages using the new theme */
}
void
diff --git a/libempathy-gtk/empathy-theme-boxes.c b/libempathy-gtk/empathy-theme-boxes.c
index 2905f2bec..87eac87d5 100644
--- a/libempathy-gtk/empathy-theme-boxes.c
+++ b/libempathy-gtk/empathy-theme-boxes.c
@@ -29,7 +29,6 @@
#include "empathy-ui-utils.h"
#include "empathy-main-window.h"
-#include "empathy-theme-utils.h"
#include "empathy-theme-boxes.h"
#define DEBUG_DOMAIN "FancyTheme"
@@ -66,32 +65,20 @@ static void theme_boxes_set_property (GObject *object,
GParamSpec *pspec);
static void theme_boxes_define_theme_tags (EmpathyTheme *theme,
EmpathyChatView *view);
-static EmpathyThemeContext *
-theme_boxes_setup_with_view (EmpathyTheme *theme,
+static void theme_boxes_update_view (EmpathyTheme *theme,
EmpathyChatView *view);
-static void theme_boxes_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
-static void theme_boxes_view_cleared (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
-
static void theme_boxes_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message);
static void theme_boxes_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str);
static void theme_boxes_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
gboolean show_time);
static void theme_boxes_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view);
enum {
@@ -129,9 +116,7 @@ empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
object_class->get_property = theme_boxes_get_property;
object_class->set_property = theme_boxes_set_property;
- theme_class->setup_with_view = theme_boxes_setup_with_view;
- theme_class->detach_from_view = theme_boxes_detach_from_view;
- theme_class->view_cleared = theme_boxes_view_cleared;
+ theme_class->update_view = theme_boxes_update_view;
theme_class->append_message = theme_boxes_append_message;
theme_class->append_event = theme_boxes_append_event;
theme_class->append_timestamp = theme_boxes_append_timestamp;
@@ -310,9 +295,9 @@ theme_boxes_get_property (GObject *object,
}
static void
theme_boxes_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
EmpathyThemeBoxesPriv *priv;
@@ -322,46 +307,57 @@ theme_boxes_set_property (GObject *object,
case PROP_HEADER_FOREGROUND:
g_free (priv->header_foreground);
priv->header_foreground = g_value_dup_string (value);
+ g_object_notify (object, "header-foreground");
break;
case PROP_HEADER_BACKGROUND:
g_free (priv->header_background);
priv->header_background = g_value_dup_string (value);
+ g_object_notify (object, "header-background");
break;
case PROP_HEADER_LINE_BACKGROUND:
g_free (priv->header_line_background);
priv->header_line_background = g_value_dup_string (value);
+ g_object_notify (object, "header-line_background");
break;
case PROP_TEXT_FOREGROUND:
g_free (priv->text_foreground);
priv->text_foreground = g_value_dup_string (value);
+ g_object_notify (object, "text-foreground");
break;
case PROP_TEXT_BACKGROUND:
g_free (priv->text_background);
priv->text_background = g_value_dup_string (value);
+ g_object_notify (object, "text-background");
break;
case PROP_ACTION_FOREGROUND:
g_free (priv->action_foreground);
priv->action_foreground = g_value_dup_string (value);
+ g_object_notify (object, "action-foreground");
break;
case PROP_HIGHLIGHT_FOREGROUND:
g_free (priv->highlight_foreground);
priv->highlight_foreground = g_value_dup_string (value);
+ g_object_notify (object, "highlight-foreground");
break;
case PROP_TIME_FOREGROUND:
g_free (priv->time_foreground);
priv->time_foreground = g_value_dup_string (value);
+ g_object_notify (object, "time-foreground");
break;
case PROP_EVENT_FOREGROUND:
g_free (priv->event_foreground);
priv->event_foreground = g_value_dup_string (value);
+ g_object_notify (object, "event-foreground");
break;
case PROP_INVITE_FOREGROUND:
g_free (priv->invite_foreground);
priv->invite_foreground = g_value_dup_string (value);
+ g_object_notify (object, "invite-foreground");
break;
case PROP_LINK_FOREGROUND:
g_free (priv->link_foreground);
priv->link_foreground = g_value_dup_string (value);
+ g_object_notify (object, "link-foreground");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -373,53 +369,42 @@ static void
theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
{
EmpathyThemeBoxesPriv *priv;
- GtkTextBuffer *buffer;
- GtkTextTagTable *table;
- GtkTextTag *tag;
+ GtkTextBuffer *buffer;
+ GtkTextTag *tag;
priv = GET_PRIV (theme);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- table = gtk_text_buffer_get_tag_table (buffer);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-spacing");
- g_object_set (tag,
- "size", 3000,
- "pixels-above-lines", 8,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table,
- "fancy-header");
- g_object_set (tag,
- "weight", PANGO_WEIGHT_BOLD,
- "pixels-above-lines", HEADER_PADDING,
- "pixels-below-lines", HEADER_PADDING,
- NULL);
+
+ empathy_text_buffer_tag_set (buffer, "fancy-spacing",
+ "size", 3000,
+ "pixels-above-lines", 8,
+ NULL);
+
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-header",
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", HEADER_PADDING,
+ "pixels-below-lines", HEADER_PADDING,
+ NULL);
if (priv->header_foreground) {
g_object_set (tag,
"foreground", priv->header_foreground,
"paragraph-background", priv->header_background,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-header-line");
- g_object_set (tag,
- "size", 1,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-header-line",
+ "size", 1,
+ NULL);
if (priv->header_line_background) {
g_object_set (tag,
"paragraph-background", priv->header_line_background,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-body");
- g_object_set (tag,
- "pixels-above-lines", 4,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-body",
+ "pixels-above-lines", 4,
+ NULL);
if (priv->text_background) {
g_object_set (tag,
"paragraph-background", priv->text_background,
@@ -431,13 +416,11 @@ theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
"foreground", priv->text_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-action");
- g_object_set (tag,
- "style", PANGO_STYLE_ITALIC,
- "pixels-above-lines", 4,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-action",
+ "style", PANGO_STYLE_ITALIC,
+ "pixels-above-lines", 4,
+ NULL);
if (priv->text_background) {
g_object_set (tag,
@@ -449,16 +432,12 @@ theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
g_object_set (tag,
"foreground", priv->action_foreground,
NULL);
- }
-
- empathy_theme_utils_add_tag (table, tag);
+ }
- tag = empathy_theme_utils_init_tag_by_name (table,
- "fancy-highlight");
- g_object_set (tag,
- "weight", PANGO_WEIGHT_BOLD,
- "pixels-above-lines", 4,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-highlight",
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", 4,
+ NULL);
if (priv->text_background) {
g_object_set (tag,
"paragraph-background", priv->text_background,
@@ -471,106 +450,55 @@ theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
"foreground", priv->highlight_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-time");
- g_object_set (tag,
- "justification", GTK_JUSTIFY_CENTER,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-time",
+ "justification", GTK_JUSTIFY_CENTER,
+ NULL);
if (priv->time_foreground) {
g_object_set (tag,
"foreground", priv->time_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-event");
- g_object_set (tag,
- "justification", GTK_JUSTIFY_LEFT,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-event",
+ "justification", GTK_JUSTIFY_LEFT,
+ NULL);
if (priv->event_foreground) {
g_object_set (tag,
"foreground", priv->event_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "invite");
+ tag = empathy_text_buffer_tag_set (buffer, "invite", NULL);
if (priv->invite_foreground) {
g_object_set (tag,
"foreground", priv->invite_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
- tag = empathy_theme_utils_init_tag_by_name (table, "fancy-link");
- g_object_set (tag,
- "underline", PANGO_UNDERLINE_SINGLE,
- NULL);
+ tag = empathy_text_buffer_tag_set (buffer, "fancy-link",
+ "underline", PANGO_UNDERLINE_SINGLE,
+ NULL);
if (priv->link_foreground) {
g_object_set (tag,
"foreground", priv->link_foreground,
NULL);
}
- empathy_theme_utils_add_tag (table, tag);
}
static void
-theme_boxes_fixup_tag_table (EmpathyTheme *theme, EmpathyChatView *view)
-{
- GtkTextBuffer *buffer;
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- /* "Fancy" style tags. */
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-header");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-header-line");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-body");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-action");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-highlight");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-spacing");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-time");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-event");
- empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-link");
-}
-
-typedef struct {
- BlockType last_block_type;
- time_t last_timestamp;
-} FancyContext;
-
-static EmpathyThemeContext *
-theme_boxes_setup_with_view (EmpathyTheme *theme, EmpathyChatView *view)
+theme_boxes_update_view (EmpathyTheme *theme, EmpathyChatView *view)
{
EmpathyThemeBoxesPriv *priv;
- g_return_val_if_fail (EMPATHY_IS_THEME_BOXES (theme), NULL);
+ g_return_if_fail (EMPATHY_IS_THEME_BOXES (theme));
+ g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
priv = GET_PRIV (theme);
- theme_boxes_fixup_tag_table (theme, view);
-
theme_boxes_define_theme_tags (theme, view);
empathy_chat_view_set_margin (view, MARGIN);
-
- return NULL;
-}
-
-static void
-theme_boxes_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view)
-{
- /* FIXME: Free the context */
-}
-
-static void
-theme_boxes_view_cleared (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view)
-{
- /* FIXME: clear the context data */
}
static void
@@ -595,7 +523,6 @@ table_size_allocate_cb (GtkWidget *view,
static void
theme_boxes_maybe_append_header (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *msg)
{
@@ -654,7 +581,7 @@ theme_boxes_maybe_append_header (EmpathyTheme *theme,
return;
}
- empathy_theme_append_spacing (theme, context, view);
+ empathy_theme_append_spacing (theme, view);
gtk_text_buffer_get_end_iter (buffer, &iter);
gtk_text_buffer_insert_with_tags_by_name (buffer,
@@ -693,7 +620,8 @@ theme_boxes_maybe_append_header (EmpathyTheme *theme,
"xalign", 0.0,
NULL);
- parse_success = gdk_color_parse (priv->header_foreground, &color);
+ parse_success = priv->header_foreground &&
+ gdk_color_parse (priv->header_foreground, &color);
if (parse_success) {
gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
@@ -757,14 +685,13 @@ theme_boxes_maybe_append_header (EmpathyTheme *theme,
static void
theme_boxes_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message)
{
EmpathyContact *sender;
- empathy_theme_maybe_append_date_and_time (theme, context, view, message);
- theme_boxes_maybe_append_header (theme, context, view, message);
+ empathy_theme_maybe_append_date_and_time (theme, view, message);
+ theme_boxes_maybe_append_header (theme, view, message);
sender = empathy_message_get_sender (message);
@@ -774,10 +701,10 @@ theme_boxes_append_message (EmpathyTheme *theme,
body = g_strdup_printf (" * %s %s",
empathy_contact_get_name (sender),
empathy_message_get_body (message));
- empathy_theme_append_text (theme, context, view, body,
+ empathy_theme_append_text (theme, view, body,
"fancy-action", "fancy-link");
} else {
- empathy_theme_append_text (theme, context, view,
+ empathy_theme_append_text (theme, view,
empathy_message_get_body (message),
"fancy-body", "fancy-link");
}
@@ -793,7 +720,6 @@ theme_boxes_append_message (EmpathyTheme *theme,
static void
theme_boxes_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str)
{
@@ -803,7 +729,7 @@ theme_boxes_append_event (EmpathyTheme *theme,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- empathy_theme_maybe_append_date_and_time (theme, context, view, NULL);
+ empathy_theme_maybe_append_date_and_time (theme, view, NULL);
gtk_text_buffer_get_end_iter (buffer, &iter);
@@ -820,7 +746,6 @@ theme_boxes_append_event (EmpathyTheme *theme,
static void
theme_boxes_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
@@ -843,9 +768,7 @@ theme_boxes_append_timestamp (EmpathyTheme *theme,
str = g_string_new (NULL);
if (show_time || show_date) {
- empathy_theme_append_spacing (theme,
- context,
- view);
+ empathy_theme_append_spacing (theme, view);
g_string_append (str, "- ");
}
@@ -891,7 +814,6 @@ theme_boxes_append_timestamp (EmpathyTheme *theme,
static void
theme_boxes_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view)
{
GtkTextBuffer *buffer;
@@ -912,125 +834,3 @@ theme_boxes_append_spacing (EmpathyTheme *theme,
NULL);
}
-static void
-theme_boxes_setup_clean (EmpathyTheme *theme)
-{
- g_object_set (theme,
- "header-foreground", "black",
- "header-background", "#efefdf",
- "header_line_background", "#e3e3d3",
- "action_foreground", "brown4",
- "time_foreground", "darkgrey",
- "event_foreground", "darkgrey",
- "invite_foreground", "sienna",
- "link_foreground","#49789e",
- NULL);
-}
-
-static void
-theme_boxes_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
-{
- g_snprintf (str_color, 10,
- "#%02x%02x%02x",
- gdk_color->red >> 8,
- gdk_color->green >> 8,
- gdk_color->blue >> 8);
-}
-
-static void
-theme_boxes_setup_themed (EmpathyTheme *theme)
-{
- EmpathyThemeBoxesPriv *priv;
- GtkWidget *widget;
- GtkStyle *style;
- gchar color[10];
-
- priv = GET_PRIV (theme);
-
- widget = gtk_entry_new ();
- style = gtk_widget_get_style (widget);
- gtk_widget_destroy (widget);
-
- theme_boxes_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
-
- g_object_set (theme,
- "action-foreground", color,
- "link-foreground", color,
- NULL);
-
- theme_boxes_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
-
- g_object_set (theme,
- "header-background", color,
- NULL);
-
- theme_boxes_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
-
- g_object_set (theme,
- "header_line-background", color,
- NULL);
-
- theme_boxes_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
-
- g_object_set (theme,
- "header-foreground", color,
- NULL);
-}
-
-static void
-theme_boxes_theme_changed_cb (GtkWidget *widget,
- GtkStyle *previous_style,
- gpointer user_data)
-{
- theme_boxes_setup_themed (EMPATHY_THEME (user_data));
-
- g_signal_emit_by_name (G_OBJECT (user_data), "updated");
-}
-
-static void
-theme_boxes_setup_blue (EmpathyTheme *theme)
-{
- g_object_set (theme,
- "header_foreground", "black",
- "header_background", "#88a2b4",
- "header_line_background", "#7f96a4",
- "text_foreground", "black",
- "text_background", "#adbdc8",
- "highlight_foreground", "black",
- "action_foreground", "brown4",
- "time_foreground", "darkgrey",
- "event_foreground", "#7f96a4",
- "invite_foreground", "sienna",
- "link_foreground", "#49789e",
- NULL);
-}
-
-EmpathyTheme *
-empathy_theme_boxes_new (const gchar *name)
-{
- EmpathyTheme *theme;
- EmpathyThemeBoxesPriv *priv;
-
- theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
- priv = GET_PRIV (theme);
-
- if (strcmp (name, "clean") == 0) {
- theme_boxes_setup_clean (theme);
- }
- else if (strcmp (name, "simple") == 0) {
- /* FIXME: Make an actual accessor function */
- g_signal_connect (empathy_main_window_show (),
- "style-set",
- G_CALLBACK (theme_boxes_theme_changed_cb),
- theme);
-
- theme_boxes_setup_themed (theme);
- }
- else if (strcmp (name, "blue") == 0) {
- theme_boxes_setup_blue (theme);
- }
-
- return theme;
-}
-
-
diff --git a/libempathy-gtk/empathy-theme-boxes.h b/libempathy-gtk/empathy-theme-boxes.h
index a54283693..b1f0033f3 100644
--- a/libempathy-gtk/empathy-theme-boxes.h
+++ b/libempathy-gtk/empathy-theme-boxes.h
@@ -45,9 +45,7 @@ struct _EmpathyThemeBoxesClass {
EmpathyThemeClass parent_class;
};
-GType empathy_theme_boxes_get_type (void) G_GNUC_CONST;
-
-EmpathyTheme * empathy_theme_boxes_new (const gchar *name);
+GType empathy_theme_boxes_get_type (void) G_GNUC_CONST;
G_END_DECLS
diff --git a/libempathy-gtk/empathy-theme-irc.c b/libempathy-gtk/empathy-theme-irc.c
index afe71e5ea..7cd9588bb 100644
--- a/libempathy-gtk/empathy-theme-irc.c
+++ b/libempathy-gtk/empathy-theme-irc.c
@@ -24,7 +24,7 @@
#include <libempathy/empathy-debug.h>
#include "empathy-chat.h"
-#include "empathy-theme-utils.h"
+#include "empathy-ui-utils.h"
#include "empathy-theme-irc.h"
#define DEBUG_DOMAIN "Theme"
@@ -37,37 +37,21 @@ struct _EmpathyThemeIrcPriv {
gint my_prop;
};
-static void theme_irc_finalize (GObject *object);
-static void theme_irc_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void theme_irc_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static EmpathyThemeContext *
-theme_irc_setup_with_view (EmpathyTheme *theme,
+static void theme_irc_finalize (GObject *object);
+static void theme_irc_update_view (EmpathyTheme *theme,
EmpathyChatView *view);
-static void theme_irc_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
static void theme_irc_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message);
static void theme_irc_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str);
static void theme_irc_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
gboolean show_time);
static void theme_irc_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view);
@@ -88,25 +72,13 @@ empathy_theme_irc_class_init (EmpathyThemeIrcClass *class)
theme_class = EMPATHY_THEME_CLASS (class);
object_class->finalize = theme_irc_finalize;
- object_class->get_property = theme_irc_get_property;
- object_class->set_property = theme_irc_set_property;
- theme_class->setup_with_view = theme_irc_setup_with_view;
- theme_class->detach_from_view = theme_irc_detach_from_view;
+ 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_object_class_install_property (object_class,
- PROP_MY_PROP,
- g_param_spec_int ("my-prop",
- "",
- "",
- 0, 1,
- 1,
- G_PARAM_READWRITE));
-
g_type_class_add_private (object_class, sizeof (EmpathyThemeIrcPriv));
}
@@ -129,183 +101,82 @@ theme_irc_finalize (GObject *object)
}
static void
-theme_irc_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
-{
- EmpathyThemeIrcPriv *priv;
-
- priv = GET_PRIV (object);
-
- switch (param_id) {
- case PROP_MY_PROP:
- g_value_set_int (value, priv->my_prop);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
-}
-static void
-theme_irc_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EmpathyThemeIrcPriv *priv;
-
- priv = GET_PRIV (object);
-
- switch (param_id) {
- case PROP_MY_PROP:
- priv->my_prop = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
-}
-
-static void
-theme_irc_fixup_tag_table (EmpathyTheme *theme, EmpathyChatView *view)
-{
- GtkTextBuffer *buffer;
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- /* IRC style tags. */
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-self");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-body-self");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-action-self");
-
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-other");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-body-other");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-action-other");
-
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-nick-highlight");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-spacing");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-time");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-event");
- empathy_theme_utils_ensure_tag_by_name (buffer, "irc-link");
-}
-
-static void
theme_irc_apply_theme_classic (EmpathyTheme *theme, EmpathyChatView *view)
{
EmpathyThemeIrcPriv *priv;
- GtkTextBuffer *buffer;
- GtkTextTagTable *table;
- GtkTextTag *tag;
+ GtkTextBuffer *buffer;
priv = GET_PRIV (theme);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- table = gtk_text_buffer_get_tag_table (buffer);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-spacing");
- g_object_set (tag,
- "size", 2000,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-self");
- g_object_set (tag,
- "foreground", "sea green",
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-body-self");
- g_object_set (tag,
- /* To get the default theme color: */
- "foreground-set", FALSE,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-action-self");
- g_object_set (tag,
- "foreground", "brown4",
- "style", PANGO_STYLE_ITALIC,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-highlight");
- g_object_set (tag,
- "foreground", "indian red",
- "weight", PANGO_WEIGHT_BOLD,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-nick-other");
- g_object_set (tag,
- "foreground", "skyblue4",
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-body-other");
- g_object_set (tag,
- /* To get the default theme color: */
- "foreground-set", FALSE,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-action-other");
- g_object_set (tag,
- "foreground", "brown4",
- "style", PANGO_STYLE_ITALIC,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-time");
- g_object_set (tag,
- "foreground", "darkgrey",
- "justification", GTK_JUSTIFY_CENTER,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-event");
- g_object_set (tag,
- "foreground", "PeachPuff4",
- "justification", GTK_JUSTIFY_LEFT,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "invite");
- g_object_set (tag,
- "foreground", "sienna",
- NULL);
- empathy_theme_utils_add_tag (table, tag);
-
- tag = empathy_theme_utils_init_tag_by_name (table, "irc-link");
- g_object_set (tag,
- "foreground", "steelblue",
- "underline", PANGO_UNDERLINE_SINGLE,
- NULL);
- empathy_theme_utils_add_tag (table, tag);
+
+ 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);
}
-static EmpathyThemeContext *
-theme_irc_setup_with_view (EmpathyTheme *theme, EmpathyChatView *view)
+static void
+theme_irc_update_view (EmpathyTheme *theme, EmpathyChatView *view)
{
- theme_irc_fixup_tag_table (theme, view);
theme_irc_apply_theme_classic (theme, view);
empathy_chat_view_set_margin (view, 3);
-
- return NULL;
-}
-
-static void
-theme_irc_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view)
-{
- /* Free the context */
}
static void
theme_irc_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message)
{
@@ -317,7 +188,7 @@ theme_irc_append_message (EmpathyTheme *theme,
gchar *tmp;
EmpathyContact *contact;
- empathy_theme_maybe_append_date_and_time (theme, context, view, message);
+ empathy_theme_maybe_append_date_and_time (theme, view, message);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -334,7 +205,7 @@ theme_irc_append_message (EmpathyTheme *theme,
tmp = g_strdup_printf (" * %s %s",
empathy_contact_get_name (contact),
empathy_message_get_body (message));
- empathy_theme_append_text (theme, context, view, tmp,
+ empathy_theme_append_text (theme, view, tmp,
body_tag, "irc-link");
g_free (tmp);
return;
@@ -367,14 +238,13 @@ theme_irc_append_message (EmpathyTheme *theme,
g_free (tmp);
/* The text body. */
- empathy_theme_append_text (theme, context, view,
+ empathy_theme_append_text (theme, view,
empathy_message_get_body (message),
body_tag, "irc-link");
}
static void
theme_irc_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str)
{
@@ -384,7 +254,7 @@ theme_irc_append_event (EmpathyTheme *theme,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- empathy_theme_maybe_append_date_and_time (theme, context, view, NULL);
+ empathy_theme_maybe_append_date_and_time (theme, view, NULL);
gtk_text_buffer_get_end_iter (buffer, &iter);
@@ -398,7 +268,6 @@ theme_irc_append_event (EmpathyTheme *theme,
static void
theme_irc_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
@@ -417,9 +286,7 @@ theme_irc_append_timestamp (EmpathyTheme *theme,
str = g_string_new (NULL);
if (show_time || show_date) {
- empathy_theme_append_spacing (theme,
- context,
- view);
+ empathy_theme_append_spacing (theme, view);
g_string_append (str, "- ");
}
@@ -463,7 +330,6 @@ theme_irc_append_timestamp (EmpathyTheme *theme,
static void
theme_irc_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view)
{
GtkTextBuffer *buffer;
diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c
index 6feea2fc4..6bece7506 100644
--- a/libempathy-gtk/empathy-theme-manager.c
+++ b/libempathy-gtk/empathy-theme-manager.c
@@ -50,7 +50,7 @@ typedef struct {
EmpathyTheme *blue_theme;
EmpathyTheme *classic_theme;
- gboolean irc_style;
+ GtkSettings *settings;
} EmpathyThemeManagerPriv;
static void theme_manager_finalize (GObject *object);
@@ -85,6 +85,114 @@ static const gchar *themes[] = {
G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
static void
+theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
+{
+ g_snprintf (str_color, 10,
+ "#%02x%02x%02x",
+ gdk_color->red >> 8,
+ gdk_color->green >> 8,
+ gdk_color->blue >> 8);
+}
+
+ static void
+theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
+{
+ EmpathyThemeManagerPriv *priv;
+ GtkStyle *style;
+ gchar color[10];
+
+ priv = GET_PRIV (manager);
+
+ style = gtk_widget_get_default_style ();
+
+ g_object_freeze_notify (G_OBJECT (priv->simple_theme));
+
+ theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
+ g_object_set (priv->simple_theme,
+ "action-foreground", color,
+ "link-foreground", color,
+ NULL);
+
+ theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
+ g_object_set (priv->simple_theme,
+ "header-background", color,
+ NULL);
+
+ theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
+ g_object_set (priv->simple_theme,
+ "header-line-background", color,
+ NULL);
+
+ theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
+ g_object_set (priv->simple_theme,
+ "header-foreground", color,
+ NULL);
+
+ g_object_thaw_notify (G_OBJECT (priv->simple_theme));
+
+#if 0
+
+FIXME: Make that work, it should update color when theme changes but it
+ doesnt seems to work with all themes.
+
+ g_object_get (priv->settings,
+ "color-hash", &color_hash,
+ NULL);
+
+ /*
+ * base_color: #ffffffffffff
+ * fg_color: #000000000000
+ * bg_color: #e6e6e7e7e8e8
+ * text_color: #000000000000
+ * selected_bg_color: #58589a9adbdb
+ * selected_fg_color: #ffffffffffff
+ */
+
+ color = g_hash_table_lookup (color_hash, "base_color");
+ if (color) {
+ theme_manager_gdk_color_to_hex (color, color_str);
+ g_object_set (priv->simple_theme,
+ "action-foreground", color_str,
+ "link-foreground", color_str,
+ NULL);
+ }
+
+ color = g_hash_table_lookup (color_hash, "selected_bg_color");
+ if (color) {
+ theme_manager_gdk_color_to_hex (color, color_str);
+ g_object_set (priv->simple_theme,
+ "header-background", color_str,
+ NULL);
+ }
+
+ color = g_hash_table_lookup (color_hash, "bg_color");
+ if (color) {
+ GdkColor tmp;
+
+ tmp = *color;
+ tmp.red /= 2;
+ tmp.green /= 2;
+ tmp.blue /= 2;
+ theme_manager_gdk_color_to_hex (&tmp, color_str);
+ g_object_set (priv->simple_theme,
+ "header-line-background", color_str,
+ NULL);
+ }
+
+ color = g_hash_table_lookup (color_hash, "selected_fg_color");
+ if (color) {
+ theme_manager_gdk_color_to_hex (color, color_str);
+ g_object_set (priv->simple_theme,
+ "header-foreground", color_str,
+ NULL);
+ }
+
+ g_hash_table_unref (color_hash);
+
+#endif
+}
+
+static void
empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -138,9 +246,39 @@ empathy_theme_manager_init (EmpathyThemeManager *manager)
EMPATHY_PREFS_UI_SHOW_AVATARS,
&priv->show_avatars);
- priv->clean_theme = empathy_theme_boxes_new ("clean");
- priv->simple_theme = empathy_theme_boxes_new ("simple");
- priv->blue_theme = empathy_theme_boxes_new ("blue");
+ priv->settings = gtk_settings_get_default ();
+ g_signal_connect_swapped (priv->settings, "notify::color-hash",
+ G_CALLBACK (theme_manager_color_hash_notify_cb),
+ manager);
+
+ priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
+ theme_manager_color_hash_notify_cb (manager);
+
+ priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
+ "header-foreground", "black",
+ "header-background", "#efefdf",
+ "header_line_background", "#e3e3d3",
+ "action_foreground", "brown4",
+ "time_foreground", "darkgrey",
+ "event_foreground", "darkgrey",
+ "invite_foreground", "sienna",
+ "link_foreground","#49789e",
+ NULL);
+
+ priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
+ "header_foreground", "black",
+ "header_background", "#88a2b4",
+ "header_line_background", "#7f96a4",
+ "text_foreground", "black",
+ "text_background", "#adbdc8",
+ "highlight_foreground", "black",
+ "action_foreground", "brown4",
+ "time_foreground", "darkgrey",
+ "event_foreground", "#7f96a4",
+ "invite_foreground", "sienna",
+ "link_foreground", "#49789e",
+ NULL);
+
priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
}
diff --git a/libempathy-gtk/empathy-theme-utils.c b/libempathy-gtk/empathy-theme-utils.c
deleted file mode 100644
index 56b758e2a..000000000
--- a/libempathy-gtk/empathy-theme-utils.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2007 Imendio AB
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * 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.
- */
-
-#include <config.h>
-
-#include <gtk/gtktexttag.h>
-
-#include "empathy-theme-utils.h"
-
-void
-empathy_theme_utils_ensure_tag_by_name (GtkTextBuffer *buffer, const gchar *name)
-{
- GtkTextTagTable *table;
- GtkTextTag *tag;
-
- table = gtk_text_buffer_get_tag_table (buffer);
- tag = gtk_text_tag_table_lookup (table, name);
-
- if (!tag) {
- gtk_text_buffer_create_tag (buffer,
- name,
- NULL);
- }
-}
-
-GtkTextTag *
-empathy_theme_utils_init_tag_by_name (GtkTextTagTable *table, const gchar *name)
-{
- GtkTextTag *tag;
-
- tag = gtk_text_tag_table_lookup (table, name);
-
- if (!tag) {
- return gtk_text_tag_new (name);
- }
-
- /* Clear the old values so that we don't affect the new theme. */
- g_object_set (tag,
- "background-set", FALSE,
- "foreground-set", FALSE,
- "invisible-set", FALSE,
- "justification-set", FALSE,
- "paragraph-background-set", FALSE,
- "pixels-above-lines-set", FALSE,
- "pixels-below-lines-set", FALSE,
- "rise-set", FALSE,
- "scale-set", FALSE,
- "size-set", FALSE,
- "style-set", FALSE,
- "weight-set", FALSE,
- NULL);
-
- return tag;
-}
-
-void
-empathy_theme_utils_add_tag (GtkTextTagTable *table, GtkTextTag *tag)
-{
- gchar *name;
- GtkTextTag *check_tag;
-
- g_object_get (tag, "name", &name, NULL);
- check_tag = gtk_text_tag_table_lookup (table, name);
- g_free (name);
- if (check_tag) {
- return;
- }
-
- gtk_text_tag_table_add (table, tag);
-
- g_object_unref (tag);
-}
-
diff --git a/libempathy-gtk/empathy-theme-utils.h b/libempathy-gtk/empathy-theme-utils.h
deleted file mode 100644
index af970775f..000000000
--- a/libempathy-gtk/empathy-theme-utils.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2007 Imendio AB
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * 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.
- */
-
-#ifndef __EMPATHY_THEME_UTILS_H__
-#define __EMPATHY_THEME_UTILS_H__
-
-#include <gtk/gtktextbuffer.h>
-#include <gtk/gtktexttag.h>
-
-G_BEGIN_DECLS
-
-void empathy_theme_utils_ensure_tag_by_name (GtkTextBuffer *buffer,
- const gchar *name);
-GtkTextTag * empathy_theme_utils_init_tag_by_name (GtkTextTagTable *table,
- const gchar *name);
-void empathy_theme_utils_add_tag (GtkTextTagTable *table,
- GtkTextTag *tag);
-
-G_END_DECLS
-
-#endif /* __EMPATHY_THEME_UTILS_H__ */
-
-
diff --git a/libempathy-gtk/empathy-theme.c b/libempathy-gtk/empathy-theme.c
index c465ae69a..1895b8ccb 100644
--- a/libempathy-gtk/empathy-theme.c
+++ b/libempathy-gtk/empathy-theme.c
@@ -31,7 +31,6 @@
#include "empathy-chat.h"
#include "empathy-preferences.h"
-#include "empathy-theme-utils.h"
#include "empathy-theme.h"
#include "empathy-smiley-manager.h"
@@ -67,13 +66,6 @@ enum {
PROP_SHOW_AVATARS
};
-enum {
- UPDATED,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
static void
empathy_theme_class_init (EmpathyThemeClass *class)
{
@@ -85,8 +77,7 @@ empathy_theme_class_init (EmpathyThemeClass *class)
object_class->get_property = theme_get_property;
object_class->set_property = theme_set_property;
- class->setup_with_view = NULL;
- class->view_cleared = NULL;
+ class->update_view = NULL;
class->append_message = NULL;
class->append_event = NULL;
class->append_timestamp = NULL;
@@ -99,16 +90,6 @@ empathy_theme_class_init (EmpathyThemeClass *class)
TRUE,
G_PARAM_READWRITE));
- signals[UPDATED] =
- g_signal_new ("updated",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- empathy_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
g_type_class_add_private (object_class, sizeof (EmpathyThemePriv));
}
@@ -168,7 +149,8 @@ theme_set_property (GObject *object,
switch (param_id) {
case PROP_SHOW_AVATARS:
- priv->show_avatars = g_value_get_boolean (value);
+ empathy_theme_set_show_avatars (EMPATHY_THEME (object),
+ g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -178,7 +160,6 @@ theme_set_property (GObject *object,
void
empathy_theme_maybe_append_date_and_time (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message)
{
@@ -207,61 +188,24 @@ empathy_theme_maybe_append_date_and_time (EmpathyTheme *theme,
}
if (append_time || append_date) {
- empathy_theme_append_timestamp (theme, context,
- view, message,
+ empathy_theme_append_timestamp (theme, view, message,
append_date, append_time);
}
}
-EmpathyTheme *
-empathy_theme_new (void)
-{
- EmpathyTheme *theme;
-
- theme = g_object_new (EMPATHY_TYPE_THEME, NULL);
-
- return theme;
-}
-
-EmpathyThemeContext *
-empathy_theme_setup_with_view (EmpathyTheme *theme,
- EmpathyChatView *view)
-{
- if (!EMPATHY_THEME_GET_CLASS(theme)->setup_with_view) {
- g_error ("Theme must override setup_with_view");
- }
-
- return EMPATHY_THEME_GET_CLASS(theme)->setup_with_view (theme, view);
-}
-
void
-empathy_theme_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view)
+empathy_theme_update_view (EmpathyTheme *theme,
+ EmpathyChatView *view)
{
- if (!EMPATHY_THEME_GET_CLASS(theme)->detach_from_view) {
- g_error ("Theme must override detach_from_view");
- }
-
- return EMPATHY_THEME_GET_CLASS(theme)->detach_from_view (theme, context,
- view);
-}
-
-void
-empathy_theme_view_cleared (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view)
-{
- if (!EMPATHY_THEME_GET_CLASS(theme)->view_cleared) {
- return;
+ if (!EMPATHY_THEME_GET_CLASS(theme)->update_view) {
+ g_error ("Theme must override update_view");
}
- EMPATHY_THEME_GET_CLASS(theme)->view_cleared (theme, context, view);
+ return EMPATHY_THEME_GET_CLASS(theme)->update_view (theme, view);
}
void
empathy_theme_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message)
{
@@ -270,8 +214,7 @@ empathy_theme_append_message (EmpathyTheme *theme,
return;
}
- EMPATHY_THEME_GET_CLASS(theme)->append_message (theme, context, view,
- message);
+ EMPATHY_THEME_GET_CLASS(theme)->append_message (theme, view, message);
}
static void
@@ -309,7 +252,6 @@ theme_insert_text_with_emoticons (GtkTextBuffer *buf,
void
empathy_theme_append_text (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *body,
const gchar *tag,
@@ -410,7 +352,6 @@ empathy_theme_append_text (EmpathyTheme *theme,
void
empathy_theme_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str)
{
@@ -418,25 +359,23 @@ empathy_theme_append_event (EmpathyTheme *theme,
return;
}
- EMPATHY_THEME_GET_CLASS(theme)->append_event (theme, context, view, str);
+ EMPATHY_THEME_GET_CLASS(theme)->append_event (theme, view, str);
}
void
empathy_theme_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view)
{
if (!EMPATHY_THEME_GET_CLASS(theme)->append_spacing) {
return;
}
- EMPATHY_THEME_GET_CLASS(theme)->append_spacing (theme, context, view);
+ EMPATHY_THEME_GET_CLASS(theme)->append_spacing (theme, view);
}
void
empathy_theme_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
@@ -446,7 +385,7 @@ empathy_theme_append_timestamp (EmpathyTheme *theme,
return;
}
- EMPATHY_THEME_GET_CLASS(theme)->append_timestamp (theme, context, view,
+ EMPATHY_THEME_GET_CLASS(theme)->append_timestamp (theme, view,
message, show_date,
show_time);
}
diff --git a/libempathy-gtk/empathy-theme.h b/libempathy-gtk/empathy-theme.h
index b05342aa7..34875bcb4 100644
--- a/libempathy-gtk/empathy-theme.h
+++ b/libempathy-gtk/empathy-theme.h
@@ -42,89 +42,54 @@ struct _EmpathyTheme {
GObject parent;
};
-typedef void EmpathyThemeContext;
-
struct _EmpathyThemeClass {
GObjectClass parent_class;
/* <vtable> */
- EmpathyThemeContext * (*setup_with_view) (EmpathyTheme *theme,
- EmpathyChatView *view);
- void (*detach_from_view) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
- void (*view_cleared) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
- void (*append_message) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- EmpathyMessage *message);
- void (*append_event) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- const gchar *str);
- void (*append_timestamp) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- EmpathyMessage *message,
- gboolean show_date,
- gboolean show_time);
- void (*append_spacing) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
- void (*update_show_avatars) (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- gboolean show);
+ void (*update_view) (EmpathyTheme *theme,
+ EmpathyChatView *view);
+ void (*append_message) (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ EmpathyMessage *message);
+ void (*append_event) (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ const gchar *str);
+ void (*append_timestamp) (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ EmpathyMessage *message,
+ gboolean show_date,
+ gboolean show_time);
+ void (*append_spacing) (EmpathyTheme *theme,
+ EmpathyChatView *view);
};
-GType empathy_theme_get_type (void) G_GNUC_CONST;
-
-EmpathyTheme * empathy_theme_new (void);
-
-EmpathyThemeContext *
-empathy_theme_setup_with_view (EmpathyTheme *theme,
- EmpathyChatView *view);
-void empathy_theme_detach_from_view (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
-void empathy_theme_view_cleared (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
-
-void empathy_theme_append_message (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- EmpathyMessage *msg);
-void empathy_theme_append_text (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- const gchar *body,
- const gchar *tag,
- const gchar *link_tag);
-void empathy_theme_append_spacing (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view);
-void empathy_theme_append_event (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- const gchar *str);
-void empathy_theme_append_timestamp (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- EmpathyMessage *message,
- gboolean show_date,
- gboolean show_time);
-
-void
-empathy_theme_maybe_append_date_and_time (EmpathyTheme *theme,
- EmpathyThemeContext *context,
- EmpathyChatView *view,
- EmpathyMessage *message);
-gboolean empathy_theme_get_show_avatars (EmpathyTheme *theme);
-void empathy_theme_set_show_avatars (EmpathyTheme *theme,
- gboolean show);
+GType empathy_theme_get_type (void) G_GNUC_CONST;
+void empathy_theme_update_view (EmpathyTheme *theme,
+ EmpathyChatView *view);
+void empathy_theme_append_message (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ EmpathyMessage *msg);
+void empathy_theme_append_text (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ const gchar *body,
+ const gchar *tag,
+ const gchar *link_tag);
+void empathy_theme_append_spacing (EmpathyTheme *theme,
+ EmpathyChatView *view);
+void empathy_theme_append_event (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ const gchar *str);
+void empathy_theme_append_timestamp (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ EmpathyMessage *message,
+ gboolean show_date,
+ gboolean show_time);
+void empathy_theme_maybe_append_date_and_time (EmpathyTheme *theme,
+ EmpathyChatView *view,
+ EmpathyMessage *message);
+gboolean empathy_theme_get_show_avatars (EmpathyTheme *theme);
+void empathy_theme_set_show_avatars (EmpathyTheme *theme,
+ gboolean show);
G_END_DECLS
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 6f1b5a857..2989ce2ac 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1376,3 +1376,51 @@ empathy_toggle_button_set_state_quietly (GtkWidget *widget,
g_signal_handlers_unblock_by_func (widget, callback, user_data);
}
+GtkTextTag *
+empathy_text_buffer_tag_set (GtkTextBuffer *buffer,
+ const gchar *tag_name,
+ const gchar *first_property_name,
+ ...)
+{
+ GtkTextTagTable *table;
+ GtkTextTag *tag;
+
+ g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
+ g_return_val_if_fail (tag_name != NULL, NULL);
+
+ table = gtk_text_buffer_get_tag_table (buffer);
+ tag = gtk_text_tag_table_lookup (table, tag_name);
+
+ if (!tag) {
+ tag = gtk_text_tag_new (tag_name);
+ gtk_text_tag_table_add (table, tag);
+ g_object_unref (tag);
+ } else {
+ /* Clear the old values so that we don't affect the new theme. */
+ g_object_set (tag,
+ "background-set", FALSE,
+ "foreground-set", FALSE,
+ "invisible-set", FALSE,
+ "justification-set", FALSE,
+ "paragraph-background-set", FALSE,
+ "pixels-above-lines-set", FALSE,
+ "pixels-below-lines-set", FALSE,
+ "rise-set", FALSE,
+ "scale-set", FALSE,
+ "size-set", FALSE,
+ "style-set", FALSE,
+ "weight-set", FALSE,
+ NULL);
+ }
+
+ if (first_property_name) {
+ va_list list;
+
+ va_start (list, first_property_name);
+ g_object_set_valist (G_OBJECT (tag), first_property_name, list);
+ va_end (list);
+ }
+
+ return tag;
+}
+
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index eb189545a..fd1f7c633 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -106,9 +106,12 @@ void empathy_toggle_button_set_state_quietly (GtkWidget *widge
GCallback callback,
gpointer user_data,
gboolean active);
-GtkWidget *empathy_link_button_new (const gchar *url,
+GtkWidget * empathy_link_button_new (const gchar *url,
const gchar *title);
-
+GtkTextTag *empathy_text_buffer_tag_set (GtkTextBuffer *buffer,
+ const gchar *tag_name,
+ const gchar *first_property_name,
+ ...);
G_END_DECLS