Mercurial > pidgin.yaz
changeset 23482:d17d6e83f428
Added layout capabilities to blist themes
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Tue, 22 Jul 2008 03:08:59 +0000 |
parents | fc3600ba68f1 |
children | 748308865dbf |
files | pidgin/gtkblist-loader.c pidgin/gtkblist-theme.h pidgin/gtkblist.c |
diffstat | 3 files changed, 205 insertions(+), 167 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkblist-loader.c Fri Jul 18 22:31:28 2008 +0000 +++ b/pidgin/gtkblist-loader.c Tue Jul 22 03:08:59 2008 +0000 @@ -31,6 +31,7 @@ /****************************************************************************** * Globals *****************************************************************************/ +#define DEFAULT_TEXT_COLOR "black" /***************************************************************************** * Buddy List Theme Builder *****************************************************************************/ @@ -43,9 +44,10 @@ const gchar *icon_theme = NULL, *tmp; gboolean sucess = TRUE; GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *buddy_bgcolor1, *buddy_bgcolor2; + GdkColor color; FontColorPair *expanded, *collapsed, *online, *away, *offline, *message, *status; gdouble transparency; - PidginBlistLayout *layout = g_new0(PidginBlistLayout, 1); + PidginBlistLayout *layout; GDir *gdir; PidginBlistTheme *theme; @@ -67,28 +69,22 @@ root_node = xmlnode_from_file(dir, filename, "blist themes", "blist-loader"); g_return_val_if_fail(root_node != NULL, NULL); - /* colors */ + /* init all structs and colors */ bgcolor = g_new0(GdkColor, 1); expanded_bgcolor = g_new0(GdkColor, 1); collapsed_bgcolor = g_new0(GdkColor, 1); buddy_bgcolor1 = g_new0(GdkColor, 1); buddy_bgcolor2 = g_new0(GdkColor, 1); - - /* font color pairs */ + + layout = g_new0(PidginBlistLayout, 1); + expanded = g_new0(FontColorPair, 1); - expanded->color = g_new0(GdkColor, 1); collapsed = g_new0(FontColorPair, 1); - collapsed->color = g_new0(GdkColor, 1); online = g_new0(FontColorPair, 1); - online->color = g_new0(GdkColor, 1); away = g_new0(FontColorPair, 1); - away->color = g_new0(GdkColor, 1); offline = g_new0(FontColorPair, 1); - offline->color = g_new0(GdkColor, 1); - message = g_new0(FontColorPair, 1); - message->color = g_new0(GdkColor, 1); + message = g_new0(FontColorPair, 1); status = g_new0(FontColorPair, 1); - status->color = g_new0(GdkColor, 1); /* Parse the tree */ sub_node = xmlnode_get_child(root_node, "description"); @@ -116,12 +112,9 @@ expanded->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if ((tmp = xmlnode_get_attrib(sub_sub_node, "color")) != NULL && gdk_color_parse(tmp, expanded->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), expanded->color, FALSE, TRUE); - else { - g_free(expanded->color); - expanded->color = NULL; - } + if ((tmp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(tmp, &color)) + expanded->color = g_strdup(tmp); + else expanded->color = DEFAULT_TEXT_COLOR; if ((tmp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(tmp, expanded_bgcolor)) @@ -135,12 +128,10 @@ if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { collapsed->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if((tmp = xmlnode_get_attrib(sub_sub_node, "color")) != NULL && gdk_color_parse(tmp, collapsed->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), collapsed->color, FALSE, TRUE); - else { - g_free(collapsed->color); - collapsed->color = NULL; - } + if((tmp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(tmp, &color)) + collapsed->color = g_strdup(tmp); + else collapsed->color = DEFAULT_TEXT_COLOR; + if ((tmp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(tmp, collapsed_bgcolor)) gdk_colormap_alloc_color(gdk_colormap_get_system(), collapsed_bgcolor, FALSE, TRUE); else { @@ -153,11 +144,11 @@ if ((sucess = sucess && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) { - layout->buddy_icon = atoi(xmlnode_get_attrib(sub_sub_node, "status_icon")); + layout->status_icon = atoi(xmlnode_get_attrib(sub_sub_node, "status_icon")); layout->text = atoi(xmlnode_get_attrib(sub_sub_node, "name")); - layout->buddy_icon = atoi(xmlnode_get_attrib(sub_sub_node, "buddy_icon")); + layout->emblem = atoi(xmlnode_get_attrib(sub_sub_node, "emblem")); layout->protocol_icon = atoi(xmlnode_get_attrib(sub_sub_node, "protocol_icon")); - layout->emblem = atoi(xmlnode_get_attrib(sub_sub_node, "emblem")); + layout->buddy_icon = atoi(xmlnode_get_attrib(sub_sub_node, "buddy_icon")); layout->show_status = atoi(xmlnode_get_attrib(sub_sub_node, "status_icon")) != 0; } @@ -180,52 +171,37 @@ if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "online_text")) != NULL)) { online->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), online->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), online->color, FALSE, TRUE); - else { - g_free(online->color); - online->color = NULL; - } + if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &color)) + online->color = g_strdup(tmp); + else online->color = DEFAULT_TEXT_COLOR; } if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "away_text")) != NULL)) { away->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), away->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), away->color, FALSE, TRUE); - else { - g_free(away->color); - away->color = NULL; - } + if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &color)) + away->color = g_strdup(tmp); + else away->color = DEFAULT_TEXT_COLOR; } if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "offline_text")) != NULL)) { offline->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), offline->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), offline->color, FALSE, TRUE); - else { - g_free(offline->color); - online->color = NULL; - } + if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &color)) + online->color = g_strdup(tmp); + else online->color = DEFAULT_TEXT_COLOR; } if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "message_text")) != NULL)) { message->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), message->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), message->color, FALSE, TRUE); - else { - g_free(message->color); - message->color = NULL; - } + if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &color)) + message->color = g_strdup(tmp); + else message->color = DEFAULT_TEXT_COLOR; } if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "status_text")) != NULL)) { status->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), status->color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), status->color, FALSE, TRUE); - else { - g_free(status->color); - status->color = NULL; - } + if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &color)) + status->color = g_strdup(tmp); + else status->color = DEFAULT_TEXT_COLOR; } /* name is required for theme manager */
--- a/pidgin/gtkblist-theme.h Fri Jul 18 22:31:28 2008 +0000 +++ b/pidgin/gtkblist-theme.h Tue Jul 22 03:08:59 2008 +0000 @@ -63,17 +63,17 @@ typedef struct { gchar *font; - GdkColor *color; + gchar *color; } FontColorPair; typedef struct { - gint buddy_icon; + gint status_icon; gint text; - gint status_icon; + gint emblem; gint protocol_icon; - gint emblem; + gint buddy_icon; gboolean show_status; } PidginBlistLayout;
--- a/pidgin/gtkblist.c Fri Jul 18 22:31:28 2008 +0000 +++ b/pidgin/gtkblist.c Tue Jul 22 03:08:59 2008 +0000 @@ -127,6 +127,7 @@ PidginMiniDialog *signed_on_elsewhere; PidginBlistTheme *current_theme; + } PidginBuddyListPrivate; #define PIDGIN_BUDDY_LIST_GET_PRIVATE(list) \ @@ -5231,11 +5232,148 @@ } #endif +/* builds the blist layout according to to the current theme */ +static void +pidgin_blist_build_layout(PurpleBuddyList *list) +{ + GtkTreeViewColumn *column; + PidginBlistLayout *layout; + PidginBlistTheme *theme; + GtkCellRenderer *rend; + gint i; + + column = gtkblist->text_column; + + if ((theme = pidgin_blist_get_theme()) != NULL) + layout = pidgin_blist_theme_get_layout(theme); + else { + /* Default Layout */ + layout = g_new0(PidginBlistLayout, 1); + + layout->status_icon = 0; + layout->text = 1; + layout->emblem = 2; + layout->protocol_icon = 3; + layout->buddy_icon = 4; + layout->show_status = 5; + } + + gtk_tree_view_column_clear(column); + + /* group */ + rend = pidgin_cell_renderer_expander_new(); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, + "visible", GROUP_EXPANDER_VISIBLE_COLUMN, + "expander-visible", GROUP_EXPANDER_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "sensitive", GROUP_EXPANDER_COLUMN, + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + NULL); + + /* contact */ + rend = pidgin_cell_renderer_expander_new(); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, + "expander-visible", CONTACT_EXPANDER_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "sensitive", CONTACT_EXPANDER_COLUMN, + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + "visible", CONTACT_EXPANDER_VISIBLE_COLUMN, + NULL); + + for (i = 0; i < 5; i++) { + + if (layout->status_icon == i) { + /* status icons */ + rend = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, + "pixbuf", STATUS_ICON_COLUMN, + "visible", STATUS_ICON_VISIBLE_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + NULL); + g_object_set(rend, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL); + + } else if (layout->text == i) { + /* name */ + gtkblist->text_rend = rend = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start (column, rend, TRUE); + gtk_tree_view_column_set_attributes(column, rend, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + "markup", NAME_COLUMN, + NULL); +#if GTK_CHECK_VERSION(2,6,0) + g_signal_connect(G_OBJECT(rend), "editing-started", G_CALLBACK(gtk_blist_renderer_editing_started_cb), NULL); + g_signal_connect(G_OBJECT(rend), "editing-canceled", G_CALLBACK(gtk_blist_renderer_editing_cancelled_cb), list); +#endif + g_signal_connect(G_OBJECT(rend), "edited", G_CALLBACK(gtk_blist_renderer_edited_cb), list); + g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); +#if GTK_CHECK_VERSION(2,6,0) + g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); +#endif + + /* idle */ + rend = gtk_cell_renderer_text_new(); + g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, + "markup", IDLE_COLUMN, + "visible", IDLE_VISIBLE_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + NULL); + } else if (layout->emblem == i) { + /* emblem */ + rend = gtk_cell_renderer_pixbuf_new(); + g_object_set(rend, "xalign", 1.0, "yalign", 0.5, "ypad", 0, "xpad", 3, NULL); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, "pixbuf", EMBLEM_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + "visible", EMBLEM_VISIBLE_COLUMN, NULL); + + } else if (layout->protocol_icon == i) { + /* protocol icon */ + rend = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, + "pixbuf", PROTOCOL_ICON_COLUMN, + "visible", PROTOCOL_ICON_VISIBLE_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + NULL); + g_object_set(rend, "xalign", 0.0, "xpad", 3, "ypad", 0, NULL); + + } else if (layout->buddy_icon == i) { + /* buddy icon */ + rend = gtk_cell_renderer_pixbuf_new(); + g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); + gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_set_attributes(column, rend, "pixbuf", BUDDY_ICON_COLUMN, +#if GTK_CHECK_VERSION(2,6,0) + "cell-background-gdk", BGCOLOR_COLUMN, +#endif + "visible", BUDDY_ICON_VISIBLE_COLUMN, + NULL); + } + + }/* end for loop */ +} + static void pidgin_blist_show(PurpleBuddyList *list) { PidginBuddyListPrivate *priv; void *handle; - GtkCellRenderer *rend; GtkTreeViewColumn *column; GtkWidget *menu; GtkWidget *ebox; @@ -5446,114 +5584,16 @@ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); - /* columns */ + /* expander columns */ column = gtk_tree_view_column_new(); gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); gtk_tree_view_column_set_visible(column, FALSE); gtk_tree_view_set_expander_column(GTK_TREE_VIEW(gtkblist->treeview), column); - /* group */ - gtkblist->text_column = column = gtk_tree_view_column_new (); - rend = pidgin_cell_renderer_expander_new(); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, - "visible", GROUP_EXPANDER_VISIBLE_COLUMN, - "expander-visible", GROUP_EXPANDER_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "sensitive", GROUP_EXPANDER_COLUMN, - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - NULL); - - /* contact */ - rend = pidgin_cell_renderer_expander_new(); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, - "expander-visible", CONTACT_EXPANDER_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "sensitive", CONTACT_EXPANDER_COLUMN, - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - "visible", CONTACT_EXPANDER_VISIBLE_COLUMN, - NULL); - - /* status icons */ - rend = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, - "pixbuf", STATUS_ICON_COLUMN, - "visible", STATUS_ICON_VISIBLE_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - NULL); - g_object_set(rend, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL); - - /* name */ - gtkblist->text_rend = rend = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start (column, rend, TRUE); - gtk_tree_view_column_set_attributes(column, rend, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - "markup", NAME_COLUMN, - NULL); -#if GTK_CHECK_VERSION(2,6,0) - g_signal_connect(G_OBJECT(rend), "editing-started", G_CALLBACK(gtk_blist_renderer_editing_started_cb), NULL); - g_signal_connect(G_OBJECT(rend), "editing-canceled", G_CALLBACK(gtk_blist_renderer_editing_cancelled_cb), list); -#endif - g_signal_connect(G_OBJECT(rend), "edited", G_CALLBACK(gtk_blist_renderer_edited_cb), list); - g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); -#if GTK_CHECK_VERSION(2,6,0) - g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); -#endif - gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); - - /* idle */ - rend = gtk_cell_renderer_text_new(); - g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, - "markup", IDLE_COLUMN, - "visible", IDLE_VISIBLE_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - NULL); - - /* emblem */ - rend = gtk_cell_renderer_pixbuf_new(); - g_object_set(rend, "xalign", 1.0, "yalign", 0.5, "ypad", 0, "xpad", 3, NULL); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, "pixbuf", EMBLEM_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - "visible", EMBLEM_VISIBLE_COLUMN, NULL); - - /* protocol icon */ - rend = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, - "pixbuf", PROTOCOL_ICON_COLUMN, - "visible", PROTOCOL_ICON_VISIBLE_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - NULL); - g_object_set(rend, "xalign", 0.0, "xpad", 3, "ypad", 0, NULL); - - /* buddy icon */ - rend = gtk_cell_renderer_pixbuf_new(); - g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); - gtk_tree_view_column_pack_start(column, rend, FALSE); - gtk_tree_view_column_set_attributes(column, rend, "pixbuf", BUDDY_ICON_COLUMN, -#if GTK_CHECK_VERSION(2,6,0) - "cell-background-gdk", BGCOLOR_COLUMN, -#endif - "visible", BUDDY_ICON_VISIBLE_COLUMN, - NULL); - + /* everything else column */ + gtkblist->text_column = gtk_tree_view_column_new (); + gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->text_column); + pidgin_blist_build_layout(list); g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); @@ -6034,6 +6074,9 @@ char *mark, *esc; PurpleBlistNode *selected_node = NULL; GtkTreeIter iter; + FontColorPair *pair; + PidginBlistTheme *theme; + const gchar *text_color, *text_font; group = (PurpleGroup*)gnode; @@ -6048,9 +6091,25 @@ purple_blist_get_group_online_count(group), purple_blist_get_group_size(group, FALSE)); } + + theme = pidgin_blist_get_theme(); + if (theme == NULL) { + text_color = "black"; + text_font = ""; + } else if (expanded) { + pair = pidgin_blist_theme_get_expanded_text_info(theme); + text_color = pair->color; + text_font = pair->font; + }else { + pair = pidgin_blist_theme_get_collapsed_text_info(theme); + text_color = pair->color; + text_font = pair->font; + } + esc = g_markup_escape_text(group->name, -1); - mark = g_strdup_printf("<span weight='bold'>%s</span>%s", esc ? esc : "", group_count); + mark = g_strdup_printf("<span foreground='%s' font_desc='%s'><span weight='bold'>%s</span>%s</span>", + text_color, text_font, esc ? esc : "", group_count); g_free(esc); return mark; @@ -7187,6 +7246,7 @@ pidgin_blist_set_theme(PidginBlistTheme *theme) { PidginBuddyListPrivate *priv = PIDGIN_BUDDY_LIST_GET_PRIVATE(gtkblist); + PurpleBuddyList *list = purple_get_blist(); if (theme != NULL) purple_prefs_set_string(PIDGIN_PREFS_ROOT "/blist/theme", @@ -7195,7 +7255,9 @@ priv->current_theme = theme; - pidgin_blist_refresh(purple_get_blist()); + pidgin_blist_build_layout(list); + + pidgin_blist_refresh(list); }