* Buddy List Themes for Pidgin * Pidgin is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "gtkblist-theme.h" /****************************************************************************** *****************************************************************************/ * A pidgin buddy list theme. * This is an object for Purple to represent a buddy list theme. * PidginBlistTheme is a PurpleTheme Object. PidginBlistLayout *layout; PidginThemeFont *expanded; GdkRGBA *collapsed_color; PidginThemeFont *collapsed; PidginThemeFont *contact; PidginThemeFont *offline; PidginThemeFont *message; PidginThemeFont *message_nick_said; } PidginBlistThemePrivate; /****************************************************************************** *****************************************************************************/ /****************************************************************************** *****************************************************************************/ static GParamSpec *properties[PROP_LAST]; G_DEFINE_TYPE_WITH_PRIVATE(PidginBlistTheme, pidgin_blist_theme, /****************************************************************************** *****************************************************************************/ pidgin_theme_font_new(const gchar *face, GdkRGBA *color) PidginThemeFont *font = g_new0(PidginThemeFont, 1); font->font = g_strdup(face); pidgin_theme_font_set_color(font, color); pidgin_theme_font_free(PidginThemeFont *pair) gdk_rgba_free(pair->gdkcolor); copy_font_and_color(const PidginThemeFont *pair) copy = g_new0(PidginThemeFont, 1); copy->font = g_strdup(pair->font); strncpy(copy->color, pair->color, sizeof(copy->color) - 1); copy->gdkcolor = gdk_rgba_copy(pair->gdkcolor); pidgin_theme_font_set_font_face(PidginThemeFont *font, const gchar *face) font->font = g_strdup(face); pidgin_theme_font_set_color(PidginThemeFont *font, const GdkRGBA *color) gdk_rgba_free(font->gdkcolor); font->gdkcolor = color ? gdk_rgba_copy(color) : NULL; g_snprintf(font->color, sizeof(font->color), (unsigned int)(color->red * 255), (unsigned int)(color->green * 255), (unsigned int)(color->blue * 255)); pidgin_theme_font_get_font_face(PidginThemeFont *font) g_return_val_if_fail(font, NULL); pidgin_theme_font_get_color(PidginThemeFont *font) g_return_val_if_fail(font, NULL); pidgin_theme_font_get_color_describe(PidginThemeFont *font) g_return_val_if_fail(font, NULL); return font->color[0] ? font->color : NULL; /****************************************************************************** *****************************************************************************/ pidgin_blist_theme_get_property(GObject *obj, guint param_id, GValue *value, PidginBlistTheme *theme = PIDGIN_BLIST_THEME(obj); case PROP_BACKGROUND_COLOR: g_value_set_boxed(value, pidgin_blist_theme_get_background_color(theme)); g_value_set_double(value, pidgin_blist_theme_get_opacity(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_layout(theme)); case PROP_EXPANDED_COLOR: g_value_set_boxed(value, pidgin_blist_theme_get_expanded_background_color(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_expanded_text_info(theme)); case PROP_COLLAPSED_COLOR: g_value_set_boxed(value, pidgin_blist_theme_get_collapsed_background_color(theme)); case PROP_COLLAPSED_TEXT: g_value_set_pointer(value, pidgin_blist_theme_get_collapsed_text_info(theme)); g_value_set_boxed(value, pidgin_blist_theme_get_contact_color(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_contact_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_online_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_away_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_offline_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_idle_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_unread_message_text_info(theme)); case PROP_MESSAGE_NICK_SAID: g_value_set_pointer(value, pidgin_blist_theme_get_unread_message_nick_said_text_info(theme)); g_value_set_pointer(value, pidgin_blist_theme_get_status_text_info(theme)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec); pidgin_blist_theme_set_property(GObject *obj, guint param_id, const GValue *value, PidginBlistTheme *theme = PIDGIN_BLIST_THEME(obj); case PROP_BACKGROUND_COLOR: pidgin_blist_theme_set_background_color(theme, g_value_get_boxed(value)); pidgin_blist_theme_set_opacity(theme, g_value_get_double(value)); pidgin_blist_theme_set_layout(theme, g_value_get_pointer(value)); case PROP_EXPANDED_COLOR: pidgin_blist_theme_set_expanded_background_color(theme, g_value_get_boxed(value)); pidgin_blist_theme_set_expanded_text_info(theme, g_value_get_pointer(value)); case PROP_COLLAPSED_COLOR: pidgin_blist_theme_set_collapsed_background_color(theme, g_value_get_boxed(value)); case PROP_COLLAPSED_TEXT: pidgin_blist_theme_set_collapsed_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_contact_color(theme, g_value_get_boxed(value)); pidgin_blist_theme_set_contact_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_online_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_away_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_offline_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_idle_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_unread_message_text_info(theme, g_value_get_pointer(value)); case PROP_MESSAGE_NICK_SAID: pidgin_blist_theme_set_unread_message_nick_said_text_info(theme, g_value_get_pointer(value)); pidgin_blist_theme_set_status_text_info(theme, g_value_get_pointer(value)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec); pidgin_blist_theme_finalize(GObject *obj) PidginBlistThemePrivate *priv; priv = pidgin_blist_theme_get_instance_private( PIDGIN_BLIST_THEME(obj)); gdk_rgba_free(priv->bgcolor); if (priv->expanded_color) gdk_rgba_free(priv->expanded_color); pidgin_theme_font_free(priv->expanded); if (priv->collapsed_color) gdk_rgba_free(priv->collapsed_color); pidgin_theme_font_free(priv->collapsed); gdk_rgba_free(priv->contact_color); pidgin_theme_font_free(priv->contact); pidgin_theme_font_free(priv->online); pidgin_theme_font_free(priv->away); pidgin_theme_font_free(priv->offline); pidgin_theme_font_free(priv->idle); pidgin_theme_font_free(priv->message); pidgin_theme_font_free(priv->message_nick_said); pidgin_theme_font_free(priv->status); G_OBJECT_CLASS(pidgin_blist_theme_parent_class)->finalize (obj); pidgin_blist_theme_init(PidginBlistTheme *theme) PidginBlistThemePrivate *priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_class_init(PidginBlistThemeClass *klass) GObjectClass *obj_class = G_OBJECT_CLASS(klass); obj_class->get_property = pidgin_blist_theme_get_property; obj_class->set_property = pidgin_blist_theme_set_property; obj_class->finalize = pidgin_blist_theme_finalize; properties[PROP_BACKGROUND_COLOR] = g_param_spec_boxed("background-color", "The background color for the buddy list", GDK_TYPE_RGBA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_OPACITY] = g_param_spec_double("opacity", "Opacity", "The opacity of the buddy list", 0.0, 1.0, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_LAYOUT] = g_param_spec_pointer("layout", "Layout", "The layout of icons, name, and status of the buddy list", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_EXPANDED_COLOR] = g_param_spec_boxed("expanded-color", "Expanded Background Color", "The background color of an expanded group", GDK_TYPE_RGBA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_EXPANDED_TEXT] = g_param_spec_pointer("expanded-text", "The text information for when a group is expanded", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_COLLAPSED_COLOR] = g_param_spec_boxed("collapsed-color", "Collapsed Background Color", "The background color of a collapsed group", GDK_TYPE_RGBA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_COLLAPSED_TEXT] = g_param_spec_pointer("collapsed-text", "The text information for when a group is collapsed", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_CONTACT_COLOR] = g_param_spec_boxed("contact-color", "Contact/Chat Background Color", "The background color of a contact or chat", GDK_TYPE_RGBA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_CONTACT] = g_param_spec_pointer("contact", "The text information for when a contact is expanded", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_ONLINE] = g_param_spec_pointer("online", "The text information for when a buddy is online", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_AWAY] = g_param_spec_pointer("away", "The text information for when a buddy is away", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_OFFLINE] = g_param_spec_pointer("offline", "The text information for when a buddy is offline", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_IDLE] = g_param_spec_pointer("idle", "The text information for when a buddy is idle", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_MESSAGE] = g_param_spec_pointer("message", "The text information for when a buddy has an unread message", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_MESSAGE_NICK_SAID] = g_param_spec_pointer("message-nick-said", "Message (Nick Said) Text", "The text information for when a chat has an unread message that mentions your nickname", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_STATUS] = g_param_spec_pointer("status", "The text information for a buddy's status", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties(obj_class, PROP_LAST, properties); /************************************************************************** **************************************************************************/ pidgin_theme_font_copy(PidginThemeFont *font) g_return_val_if_fail(font != NULL, NULL); return pidgin_theme_font_new(font->font, font->gdkcolor); pidgin_theme_font_get_type(void) type = g_boxed_type_register_static("PidginThemeFont", (GBoxedCopyFunc)pidgin_theme_font_copy, (GBoxedFreeFunc)pidgin_theme_font_free); static PidginBlistLayout * pidgin_blist_layout_copy(const PidginBlistLayout *layout) g_return_val_if_fail(layout != NULL, NULL); return g_memdup(layout, sizeof(PidginBlistLayout)); pidgin_blist_layout_get_type(void) type = g_boxed_type_register_static("PidginBlistLayout", (GBoxedCopyFunc)pidgin_blist_layout_copy, /***************************************************************************** *****************************************************************************/ pidgin_blist_theme_get_background_color(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_opacity(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), 1.0); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_layout(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_expanded_background_color(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); return priv->expanded_color; pidgin_blist_theme_get_expanded_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_collapsed_background_color(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); return priv->collapsed_color; pidgin_blist_theme_get_collapsed_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_contact_color(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); return priv->contact_color; pidgin_blist_theme_get_contact_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_online_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_away_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_offline_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_idle_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_unread_message_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_get_unread_message_nick_said_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); return priv->message_nick_said; pidgin_blist_theme_get_status_text_info(PidginBlistTheme *theme) PidginBlistThemePrivate *priv; g_return_val_if_fail(PIDGIN_IS_BLIST_THEME(theme), NULL); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_blist_theme_set_background_color(PidginBlistTheme *theme, const GdkRGBA *color) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); gdk_rgba_free(priv->bgcolor); priv->bgcolor = color ? gdk_rgba_copy(color) : NULL; g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_BACKGROUND_COLOR]); pidgin_blist_theme_set_opacity(PidginBlistTheme *theme, gdouble opacity) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme) || opacity < 0.0 || opacity > 1.0); priv = pidgin_blist_theme_get_instance_private(theme); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_OPACITY]); pidgin_blist_theme_set_layout(PidginBlistTheme *theme, const PidginBlistLayout *layout) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); priv->layout = pidgin_blist_layout_copy(layout); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_LAYOUT]); pidgin_blist_theme_set_expanded_background_color(PidginBlistTheme *theme, const GdkRGBA *color) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); if (priv->expanded_color) gdk_rgba_free(priv->expanded_color); priv->expanded_color = color ? gdk_rgba_copy(color) : NULL; g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_EXPANDED_COLOR]); pidgin_blist_theme_set_expanded_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->expanded); priv->expanded = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_EXPANDED_TEXT]); pidgin_blist_theme_set_collapsed_background_color(PidginBlistTheme *theme, const GdkRGBA *color) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); if (priv->collapsed_color) gdk_rgba_free(priv->collapsed_color); priv->collapsed_color = color ? gdk_rgba_copy(color) : NULL; g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_COLLAPSED_COLOR]); pidgin_blist_theme_set_collapsed_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->collapsed); priv->collapsed = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_COLLAPSED_TEXT]); pidgin_blist_theme_set_contact_color(PidginBlistTheme *theme, const GdkRGBA *color) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); gdk_rgba_free(priv->contact_color); priv->contact_color = color ? gdk_rgba_copy(color) : NULL; g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_CONTACT_COLOR]); pidgin_blist_theme_set_contact_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->contact); priv->contact = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_CONTACT]); pidgin_blist_theme_set_online_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->online); priv->online = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_ONLINE]); pidgin_blist_theme_set_away_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->away); priv->away = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_AWAY]); pidgin_blist_theme_set_offline_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->offline); priv->offline = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_OFFLINE]); pidgin_blist_theme_set_idle_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->idle); priv->idle = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_IDLE]); pidgin_blist_theme_set_unread_message_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->message); priv->message = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_MESSAGE]); pidgin_blist_theme_set_unread_message_nick_said_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->message_nick_said); priv->message_nick_said = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_MESSAGE_NICK_SAID]); pidgin_blist_theme_set_status_text_info(PidginBlistTheme *theme, const PidginThemeFont *pair) PidginBlistThemePrivate *priv; g_return_if_fail(PIDGIN_IS_BLIST_THEME(theme)); priv = pidgin_blist_theme_get_instance_private(theme); pidgin_theme_font_free(priv->status); priv->status = copy_font_and_color(pair); g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_STATUS]);