aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-boxes.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-12-29 23:49:47 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-12-29 23:49:47 +0800
commitb8607414ea0e41c44a09d31ebcd0437a3c867a24 (patch)
tree0004eceb52b4bb3a4da1275057e46ea80e840a05 /libempathy-gtk/empathy-theme-boxes.c
parent736ff5bf9f668528f1a1db1c8c135a8165a1b044 (diff)
downloadgsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar.gz
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar.bz2
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar.lz
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar.xz
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.tar.zst
gsoc2013-empathy-b8607414ea0e41c44a09d31ebcd0437a3c867a24.zip
merge git work
svn path=/trunk/; revision=518
Diffstat (limited to 'libempathy-gtk/empathy-theme-boxes.c')
-rw-r--r--libempathy-gtk/empathy-theme-boxes.c332
1 files changed, 266 insertions, 66 deletions
diff --git a/libempathy-gtk/empathy-theme-boxes.c b/libempathy-gtk/empathy-theme-boxes.c
index 87eac87d5..2905f2bec 100644
--- a/libempathy-gtk/empathy-theme-boxes.c
+++ b/libempathy-gtk/empathy-theme-boxes.c
@@ -29,6 +29,7 @@
#include "empathy-ui-utils.h"
#include "empathy-main-window.h"
+#include "empathy-theme-utils.h"
#include "empathy-theme-boxes.h"
#define DEBUG_DOMAIN "FancyTheme"
@@ -65,20 +66,32 @@ static void theme_boxes_set_property (GObject *object,
GParamSpec *pspec);
static void theme_boxes_define_theme_tags (EmpathyTheme *theme,
EmpathyChatView *view);
-static void theme_boxes_update_view (EmpathyTheme *theme,
+static EmpathyThemeContext *
+theme_boxes_setup_with_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 {
@@ -116,7 +129,9 @@ 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->update_view = theme_boxes_update_view;
+ 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->append_message = theme_boxes_append_message;
theme_class->append_event = theme_boxes_append_event;
theme_class->append_timestamp = theme_boxes_append_timestamp;
@@ -295,9 +310,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;
@@ -307,57 +322,46 @@ 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);
@@ -369,42 +373,53 @@ static void
theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
{
EmpathyThemeBoxesPriv *priv;
- GtkTextBuffer *buffer;
- GtkTextTag *tag;
+ GtkTextBuffer *buffer;
+ GtkTextTagTable *table;
+ GtkTextTag *tag;
priv = GET_PRIV (theme);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- 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);
+ 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);
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_text_buffer_tag_set (buffer, "fancy-header-line",
- "size", 1,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "fancy-header-line");
+ g_object_set (tag,
+ "size", 1,
+ NULL);
if (priv->header_line_background) {
g_object_set (tag,
"paragraph-background", priv->header_line_background,
NULL);
}
- tag = empathy_text_buffer_tag_set (buffer, "fancy-body",
- "pixels-above-lines", 4,
- 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);
if (priv->text_background) {
g_object_set (tag,
"paragraph-background", priv->text_background,
@@ -416,11 +431,13 @@ theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
"foreground", priv->text_foreground,
NULL);
}
+ empathy_theme_utils_add_tag (table, tag);
- tag = empathy_text_buffer_tag_set (buffer, "fancy-action",
- "style", PANGO_STYLE_ITALIC,
- "pixels-above-lines", 4,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "fancy-action");
+ g_object_set (tag,
+ "style", PANGO_STYLE_ITALIC,
+ "pixels-above-lines", 4,
+ NULL);
if (priv->text_background) {
g_object_set (tag,
@@ -432,12 +449,16 @@ 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_text_buffer_tag_set (buffer, "fancy-highlight",
- "weight", PANGO_WEIGHT_BOLD,
- "pixels-above-lines", 4,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table,
+ "fancy-highlight");
+ g_object_set (tag,
+ "weight", PANGO_WEIGHT_BOLD,
+ "pixels-above-lines", 4,
+ NULL);
if (priv->text_background) {
g_object_set (tag,
"paragraph-background", priv->text_background,
@@ -450,55 +471,106 @@ theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
"foreground", priv->highlight_foreground,
NULL);
}
+ empathy_theme_utils_add_tag (table, tag);
- tag = empathy_text_buffer_tag_set (buffer, "fancy-time",
- "justification", GTK_JUSTIFY_CENTER,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "fancy-time");
+ g_object_set (tag,
+ "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_text_buffer_tag_set (buffer, "fancy-event",
- "justification", GTK_JUSTIFY_LEFT,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "fancy-event");
+ g_object_set (tag,
+ "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_text_buffer_tag_set (buffer, "invite", NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "invite");
if (priv->invite_foreground) {
g_object_set (tag,
"foreground", priv->invite_foreground,
NULL);
}
+ empathy_theme_utils_add_tag (table, tag);
- tag = empathy_text_buffer_tag_set (buffer, "fancy-link",
- "underline", PANGO_UNDERLINE_SINGLE,
- NULL);
+ tag = empathy_theme_utils_init_tag_by_name (table, "fancy-link");
+ g_object_set (tag,
+ "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_update_view (EmpathyTheme *theme, EmpathyChatView *view)
+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)
{
EmpathyThemeBoxesPriv *priv;
- g_return_if_fail (EMPATHY_IS_THEME_BOXES (theme));
- g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
+ g_return_val_if_fail (EMPATHY_IS_THEME_BOXES (theme), NULL);
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
@@ -523,6 +595,7 @@ table_size_allocate_cb (GtkWidget *view,
static void
theme_boxes_maybe_append_header (EmpathyTheme *theme,
+ EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *msg)
{
@@ -581,7 +654,7 @@ theme_boxes_maybe_append_header (EmpathyTheme *theme,
return;
}
- empathy_theme_append_spacing (theme, view);
+ empathy_theme_append_spacing (theme, context, view);
gtk_text_buffer_get_end_iter (buffer, &iter);
gtk_text_buffer_insert_with_tags_by_name (buffer,
@@ -620,8 +693,7 @@ theme_boxes_maybe_append_header (EmpathyTheme *theme,
"xalign", 0.0,
NULL);
- parse_success = priv->header_foreground &&
- gdk_color_parse (priv->header_foreground, &color);
+ parse_success = gdk_color_parse (priv->header_foreground, &color);
if (parse_success) {
gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
@@ -685,13 +757,14 @@ 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, view, message);
- theme_boxes_maybe_append_header (theme, view, message);
+ empathy_theme_maybe_append_date_and_time (theme, context, view, message);
+ theme_boxes_maybe_append_header (theme, context, view, message);
sender = empathy_message_get_sender (message);
@@ -701,10 +774,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, view, body,
+ empathy_theme_append_text (theme, context, view, body,
"fancy-action", "fancy-link");
} else {
- empathy_theme_append_text (theme, view,
+ empathy_theme_append_text (theme, context, view,
empathy_message_get_body (message),
"fancy-body", "fancy-link");
}
@@ -720,6 +793,7 @@ theme_boxes_append_message (EmpathyTheme *theme,
static void
theme_boxes_append_event (EmpathyTheme *theme,
+ EmpathyThemeContext *context,
EmpathyChatView *view,
const gchar *str)
{
@@ -729,7 +803,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, view, NULL);
+ empathy_theme_maybe_append_date_and_time (theme, context, view, NULL);
gtk_text_buffer_get_end_iter (buffer, &iter);
@@ -746,6 +820,7 @@ theme_boxes_append_event (EmpathyTheme *theme,
static void
theme_boxes_append_timestamp (EmpathyTheme *theme,
+ EmpathyThemeContext *context,
EmpathyChatView *view,
EmpathyMessage *message,
gboolean show_date,
@@ -768,7 +843,9 @@ theme_boxes_append_timestamp (EmpathyTheme *theme,
str = g_string_new (NULL);
if (show_time || show_date) {
- empathy_theme_append_spacing (theme, view);
+ empathy_theme_append_spacing (theme,
+ context,
+ view);
g_string_append (str, "- ");
}
@@ -814,6 +891,7 @@ theme_boxes_append_timestamp (EmpathyTheme *theme,
static void
theme_boxes_append_spacing (EmpathyTheme *theme,
+ EmpathyThemeContext *context,
EmpathyChatView *view)
{
GtkTextBuffer *buffer;
@@ -834,3 +912,125 @@ 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;
+}
+
+