Guifications - The notification plugin to end all notification plugins! Copyright (C) 2003 Gary Kramlich 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. /**********************************************************************/ gf_resize(GtkWidget *window, GtkWidget *box) { gtk_window_resize(GTK_WINDOW(window), get_window_width(box), get_window_height(box)); gtk_window_move(GTK_WINDOW(window), get_window_x(window), get_window_y(window)); /**********************************************************************/ get_window_x(GtkWidget *window) { gtk_widget_size_request(window, &req); switch(gaim_prefs_get_int(GF_PREF_BEHAVIOR_WINDOW_POS)) { return gdk_screen_width() - req.width; /**********************************************************************/ get_window_y(GtkWidget *window) { gtk_widget_size_request(window, &req); switch(gaim_prefs_get_int(GF_PREF_BEHAVIOR_WINDOW_POS)) { return gdk_screen_height() - req.height; /**********************************************************************/ get_window_width(GtkWidget *box) { children = gtk_container_get_children(GTK_CONTAINER(box)); if (gaim_prefs_get_bool(GF_PREF_BEHAVIOR_WINDOW_VERTICAL)) { gtk_widget_size_request(child, &req); children = children->next; gtk_widget_size_request(child, &req); /**********************************************************************/ get_window_height(GtkWidget *box) { children = gtk_container_get_children(GTK_CONTAINER(box)); if (gaim_prefs_get_bool(GF_PREF_BEHAVIOR_WINDOW_VERTICAL)) { children = children->next; gtk_widget_size_request(child, &req); gtk_widget_size_request(child, &req); /**********************************************************************/ get_image_size(dimensions *image_size) { if (gaim_prefs_get_bool(GF_PREF_APPEARANCE_IMAGE)) { image = gdk_pixbuf_new_from_file(gaim_prefs_get_string(GF_PREF_APPEARANCE_IMAGE_FILE), NULL); gaim_prefs_set_bool(GF_PREF_APPEARANCE_IMAGE, FALSE); gaim_prefs_set_string(GF_PREF_APPEARANCE_IMAGE_FILE, ""); image_size->height = 120; image_size->width = gdk_pixbuf_get_width(image); image_size->height = gdk_pixbuf_get_height(image); image_size->height = 120; /**********************************************************************/ get_zoom_size(dimensions image_size, dimensions *zoom_size) { gfloat width = 0, height = 0; gfloat owidth = image_size.width, oheight = image_size.height; switch(gaim_prefs_get_int(GF_PREF_BEHAVIOR_ZOOM)) { height = oheight * 1.75f; height = oheight * 1.25f; height = oheight * 0.75f; height = oheight * 0.25f; zoom_size->width = width; zoom_size->height = height; /**********************************************************************/ clip_layout(PangoLayout **layout, gboolean use_color, const gchar *text_x, const gchar *text_color) { PangoLayout *lay = (*layout), *elipse = NULL; const gchar *text = NULL; gchar *new_text = NULL, *left_text = NULL, *right_text = NULL; gint width = 0, ewidth = 0, offset = 0, mid = 0; offset = gaim_prefs_get_int(text_x); elipse = pango_layout_copy(lay); pango_layout_set_text(elipse, "...", -1); pango_layout_get_pixel_size(elipse, &ewidth, NULL); pango_layout_get_pixel_size(lay, &width, NULL); if ((width + offset) > dim.width) { switch (gaim_prefs_get_int(GF_PREF_APPEARANCE_TEXT_CLIPPING)) { case text_clipping_truncate: pango_layout_get_pixel_size(lay, &width, NULL); if ((width + offset) <= dim.width) text = pango_layout_get_text(lay); new_text = g_strndup(text, strlen(text) - 1); pango_layout_set_text(lay, new_text, -1); case text_clipping_elipse_start: pango_layout_get_pixel_size(lay, &width, NULL); if ((width + offset + ewidth) <= dim.width) text = pango_layout_get_text(lay); new_text = g_strrndup(text, strlen(text) - 1); pango_layout_set_text(lay, new_text, -1); text = pango_layout_get_text(lay); new_text = g_strdup_printf("...%s", text); pango_layout_set_text(lay, new_text, -1); case text_clipping_elipse_middle: pango_layout_get_pixel_size(lay, &width, NULL); if ((width + offset + ewidth) <= dim.width) text = pango_layout_get_text(lay); if (is_even(strlen(text))) { left_text = g_strndup(text, mid); right_text = g_strrndup(text, mid - 1); left_text = g_strndup(text, mid); right_text = g_strrndup(text, mid); new_text = g_strdup_printf("%s%s", left_text, right_text); pango_layout_set_text(lay, new_text, -1); new_text = g_strdup_printf("%s...%s", left_text, right_text); pango_layout_set_text(lay, new_text, -1); case text_clipping_elipse_end: pango_layout_get_pixel_size(lay, &width, NULL); if ((width + offset + ewidth) <= dim.width) text = pango_layout_get_text(lay); new_text = g_strndup(text, strlen(text) - 1); pango_layout_set_text(lay, new_text, -1); text = pango_layout_get_text(lay); new_text = g_strdup_printf("%s...", text); pango_layout_set_text(lay, new_text, -1); text = pango_layout_get_text(lay); new_text = g_markup_escape_text(text, -1); pango_layout_set_text(lay, new_text, -1); set_color(&lay, use_color, text_color); /**********************************************************************/ g_strrndup(const gchar *src, gint n) { gchar *dest = g_malloc(strlen(src)); for (i = strlen(src) - n; i < strlen(src); i++) { /**********************************************************************/ set_color(PangoLayout **layout, gboolean custom_color, const gchar *pref) { PangoLayout *lay = (*layout); text = pango_layout_get_text(lay); pango_layout_set_markup(lay, set_text_color(text, pref), -1); pango_layout_set_markup(lay, g_strdup_printf("<span foreground=\"%s\">%s</span>", "#000000000000", text), -1); /**********************************************************************/ set_text_color(const gchar *text, const gchar *pref) { ret = g_strdup_printf("<span foreground=\"%s\">%s</span>", gaim_prefs_get_string(pref), text); /**********************************************************************/ switch (gaim_prefs_get_int(GF_PREF_APPEARANCE_PROT_SIZE)) { case icon_size_tiny: return 16; break; case icon_size_small: return 24; break; case icon_size_normal: return 48; break; case icon_size_large: return 96; break; case icon_size_huge: return 144; break; /**********************************************************************/ get_text_pos(gint *x, gint *y, gboolean line, PangoLayout *layout) { gint north, east, south, west, lat, lon; pango_layout_get_pixel_size(layout, &width, &height); ox = gaim_prefs_get_int(GF_PREF_APPEARANCE_TEXT_X); oy = gaim_prefs_get_int(GF_PREF_APPEARANCE_TEXT_Y); north = line ? oy: height + oy; east = dim.width - (width + ox); south = line ? dim.height - (height * 2 + oy): dim.height - (height + oy); lat = line ? dhh - (height + ohy): dhh + ohy; /* y */ lon = dhw - (hw + ohx); /* x */ switch (gaim_prefs_get_int(GF_PREF_APPEARANCE_TEXT_POS)) { case item_position_nw: (*x) = west; (*y) = north; break; case item_position_n: (*x) = lon; (*y) = north; break; case item_position_ne: (*x) = east; (*y) = north; break; case item_position_w: (*x) = west; (*y) = lat; break; case item_position_c: (*x) = lon; (*y) = lat; break; case item_position_e: (*x) = east; (*y) = lat; break; case item_position_sw: (*x) = west; (*y) = south; break; case item_position_s: (*x) = lon; (*y) = south; break; case item_position_se: (*x) = east; (*y) = south; break; /**********************************************************************/ get_icon_pos(gint *x, gint *y) { gint north, east, south, west, lat, lon; width = height = get_proto_icon_size(); ox = gaim_prefs_get_int(GF_PREF_APPEARANCE_PROT_X); oy = gaim_prefs_get_int(GF_PREF_APPEARANCE_PROT_Y); east = dim.width - (width + ox); south = dim.height - (height + oy); lat = dhh - (hh + ohy); /* y */ lon = dhw - (hw + ohx); /* x */ switch (gaim_prefs_get_int(GF_PREF_APPEARANCE_PROT_POS)) { case item_position_nw: (*x) = west; (*y) = north; break; case item_position_n: (*x) = lon; (*y) = north; break; case item_position_ne: (*x) = east; (*y) = north; break; case item_position_w: (*x) = west; (*y) = lat; break; case item_position_c: (*x) = lon; (*y) = lat; break; case item_position_e: (*x) = east; (*y) = lat; break; case item_position_sw: (*x) = west; (*y) = south; break; case item_position_s: (*x) = lon; (*y) = south; break; case item_position_se: (*x) = east; (*y) = south; break; /**********************************************************************/ get_proto_icon(GaimBuddy *buddy) { GaimPluginProtocolInfo *prplinfo = NULL; GdkPixbuf *src = NULL, *ret = NULL; gint height = 0, width = 0; prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol(buddy->account))); proto = g_strdup_printf("%s.png", prplinfo->list_icon(buddy->account, buddy)); file = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", proto, NULL); src = gdk_pixbuf_new_from_file(file, NULL); width = height = get_proto_icon_size(); ret = gdk_pixbuf_scale_simple(src, width, height, GDK_INTERP_BILINEAR); /**********************************************************************/ /**********************************************************************/