changeset 15737:20225df32b7e

Change some old, busted status icon stuff to use the new hotness
author Sean Egan <seanegan@gmail.com>
date Mon, 26 Feb 2007 09:41:38 +0000
parents dad514810a45
children 1d0dc6ecfa0d 51dd9ae01585
files pidgin/gtkblist.c pidgin/gtkdocklet.c pidgin/gtksavedstatuses.c pidgin/gtkutils.c pidgin/gtkutils.h
diffstat 5 files changed, 43 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkblist.c	Mon Feb 26 07:50:01 2007 +0000
+++ b/pidgin/gtkblist.c	Mon Feb 26 09:41:38 2007 +0000
@@ -3919,7 +3919,7 @@
 	/* Create the icon */
 	if ((status_type = gaim_account_get_status_type_with_primitive(account,
 							GAIM_STATUS_OFFLINE))) {
-		pixbuf = pidgin_create_prpl_icon_with_status(account, status_type, 0.5);
+		pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
 		if (pixbuf != NULL) {
 			image = gtk_image_new_from_pixbuf(pixbuf);
 			g_object_unref(pixbuf);
@@ -6347,7 +6347,6 @@
 		GtkWidget *image = NULL;
 		GaimConnection *gc = NULL;
 		GaimAccount *account = NULL;
-		GaimStatus *status = NULL;
 		GdkPixbuf *pixbuf = NULL;
 
 		account = accounts->data;
@@ -6359,8 +6358,7 @@
 			menuitem = gtk_image_menu_item_new_with_label(buf);
 			accel_path_buf = g_strconcat(N_("<GaimMain>/Accounts/"), buf, NULL);
 			g_free(buf);
-			status = gaim_account_get_active_status(account);
-			pixbuf = pidgin_create_prpl_icon_with_status(account, gaim_status_get_type(status), 0.5);
+			pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
 			if (pixbuf != NULL)
 			{
 				if (!gaim_account_is_connected(account))
--- a/pidgin/gtkdocklet.c	Mon Feb 26 07:50:01 2007 +0000
+++ b/pidgin/gtkdocklet.c	Mon Feb 26 09:41:38 2007 +0000
@@ -423,7 +423,7 @@
 	if (sf)
 		g_signal_connect(G_OBJECT(menuitem), "activate", sf, data);
 
-	pixbuf = pidgin_create_gaim_icon_with_status(primitive, 0.5);
+	pixbuf = pidgin_create_status_icon(primitive, menu, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
 	image = gtk_image_new_from_pixbuf(pixbuf);
 	g_object_unref(pixbuf);
 	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
--- a/pidgin/gtksavedstatuses.c	Mon Feb 26 07:50:01 2007 +0000
+++ b/pidgin/gtksavedstatuses.c	Mon Feb 26 09:41:38 2007 +0000
@@ -1538,7 +1538,7 @@
 			continue;
 
 		id = gaim_status_type_get_id(status_type);
-		pixbuf = pidgin_create_prpl_icon_with_status(account, status_type, PIDGIN_PRPL_ICON_MEDIUM);
+		pixbuf = pidgin_create_status_icon(gaim_status_type_get_primitive(status_type), combo, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
 		name = gaim_status_type_get_name(status_type);
 
 		gtk_list_store_append(dialog->model, &iter);
@@ -1633,12 +1633,12 @@
 				  gaim_savedstatus_get_title(saved_status_b));
 }
 
-static gboolean pidgin_status_menu_add_primitive(GtkListStore *model, GaimStatusPrimitive primitive,
+static gboolean pidgin_status_menu_add_primitive(GtkListStore *model, GtkWidget *w, GaimStatusPrimitive primitive,
 	GaimSavedStatus *current_status)
 {
 	GtkTreeIter iter;
 	gboolean currently_selected = FALSE;
-	GdkPixbuf *pixbuf = pidgin_create_gaim_icon_with_status(primitive, 0.5);
+	GdkPixbuf *pixbuf = pidgin_create_status_icon(primitive, w, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
 
 	gtk_list_store_append(model, &iter);
 	gtk_list_store_set(model, &iter,
@@ -1672,19 +1672,19 @@
 
 	combobox = gtk_combo_box_new();
 
-	if (pidgin_status_menu_add_primitive(model, GAIM_STATUS_AVAILABLE, current_status))
+	if (pidgin_status_menu_add_primitive(model, combobox, GAIM_STATUS_AVAILABLE, current_status))
 		index = i;
 	i++;
 
-	if (pidgin_status_menu_add_primitive(model, GAIM_STATUS_AWAY, current_status))
+	if (pidgin_status_menu_add_primitive(model, combobox, GAIM_STATUS_AWAY, current_status))
 		index = i;
 	i++;
 
-	if (pidgin_status_menu_add_primitive(model, GAIM_STATUS_INVISIBLE, current_status))
+	if (pidgin_status_menu_add_primitive(model, combobox, GAIM_STATUS_INVISIBLE, current_status))
 		index = i;
 	i++;
 
-	if (pidgin_status_menu_add_primitive(model, GAIM_STATUS_OFFLINE, current_status))
+	if (pidgin_status_menu_add_primitive(model, combobox, GAIM_STATUS_OFFLINE, current_status))
 		index = i;
 	i++;
 
@@ -1696,8 +1696,8 @@
 		if (!gaim_savedstatus_is_transient(status))
 		{
 			/* Get an appropriate status icon */
-			pixbuf = pidgin_create_gaim_icon_with_status(
-					gaim_savedstatus_get_type(status), 0.5);
+			pixbuf = pidgin_create_status_icon(gaim_savedstatus_get_type(status),
+							combobox, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
 
 			/* Overlay a disk in the bottom left corner */
 			emblem = gtk_widget_render_icon(GTK_WIDGET(combobox),
--- a/pidgin/gtkutils.c	Mon Feb 26 07:50:01 2007 +0000
+++ b/pidgin/gtkutils.c	Mon Feb 26 09:41:38 2007 +0000
@@ -1552,6 +1552,31 @@
 		*height = 100;
 }
 
+GdkPixbuf * pidgin_create_status_icon(GaimStatusPrimitive prim, GtkWidget *w, const char *size)
+{
+	GtkIconSize icon_size = gtk_icon_size_from_name(size);
+	GdkPixbuf *pixbuf = NULL;
+
+	if (prim == GAIM_STATUS_UNAVAILABLE)
+        	pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_BUSY,
+                                                 icon_size, "GtkWidget");
+        else if (prim == GAIM_STATUS_AWAY)
+                pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_AWAY,
+                                                 icon_size, "GtkWidget");
+        else if (prim == GAIM_STATUS_EXTENDED_AWAY)
+                pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_XA,
+                                                 icon_size, "GtkWidget");
+        else if (prim == GAIM_STATUS_OFFLINE)
+                pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_OFFLINE,
+                                                 icon_size, "GtkWidget");
+        else
+                pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_AVAILABLE,
+                                                 icon_size, "GtkWidget");
+	return pixbuf;
+
+}
+
+
 GdkPixbuf *
 pidgin_create_prpl_icon(GaimAccount *account, PidginPrplIconSize size)
 {
@@ -1592,94 +1617,6 @@
 	return pixbuf;
 }
 
-static GdkPixbuf *
-overlay_status_onto_icon(GdkPixbuf *pixbuf, GaimStatusPrimitive primitive)
-{
-	const char *type_name;
-	char basename[256];
-	char *filename;
-	GdkPixbuf *emblem;
-
-	type_name = gaim_primitive_get_id_from_type(primitive);
-
-	g_snprintf(basename, sizeof(basename), "%s.png", type_name);
-	filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
-								"default", basename, NULL);
-	emblem = gdk_pixbuf_new_from_file(filename, NULL);
-	g_free(filename);
-
-	if (emblem != NULL) {
-		int width, height, emblem_width, emblem_height;
-		int new_emblem_width, new_emblem_height;
-
-		width = gdk_pixbuf_get_width(pixbuf);
-		height = gdk_pixbuf_get_height(pixbuf);
-		emblem_width = gdk_pixbuf_get_width(emblem);
-		emblem_height = gdk_pixbuf_get_height(emblem);
-
-		/*
-		 * Figure out how big to make the emblem.  Normally the emblem
-		 * will have half the width of the pixbuf.  But we don't make
-		 * an emblem any smaller than 10 pixels because it becomes
-		 * unrecognizable, unless the width of the pixbuf is less than
-		 * 10 pixels, in which case we make the emblem width the same
-		 * as the pixbuf width.
-		 */
-		new_emblem_width = MAX(width / 2, MIN(width, 10));
-		new_emblem_height = MAX(height / 2, MIN(height, 10));
-
-		/* Overlay emblem onto the bottom right corner of pixbuf */
-		gdk_pixbuf_composite(emblem, pixbuf,
-				width - new_emblem_width, height - new_emblem_height,
-				new_emblem_width, new_emblem_height,
-				width - new_emblem_width, height - new_emblem_height,
-				(double)new_emblem_width / (double)emblem_width,
-				(double)new_emblem_height / (double)emblem_height,
-				GDK_INTERP_BILINEAR,
-				255);
-		g_object_unref(emblem);
-	}
-
-	return pixbuf;
-}
-
-GdkPixbuf *
-pidgin_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor)
-{
-	GdkPixbuf *pixbuf;
-
-	pixbuf = pidgin_create_prpl_icon(account, scale_factor);
-	if (pixbuf == NULL)
-		return NULL;
-
-	/*
-	 * TODO: Let the prpl pick the emblem on a per status basis,
-	 *       and only use the primitive as a fallback?
-	 */
-
-	return overlay_status_onto_icon(pixbuf,
-				gaim_status_type_get_primitive(status_type));
-}
-
-GdkPixbuf *
-pidgin_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor)
-{
-	gchar *filename;
-	GdkPixbuf *orig, *pixbuf;
-
-	filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL);
-	orig = gdk_pixbuf_new_from_file(filename, NULL);
-	g_free(filename);
-	if (orig == NULL)
-		return NULL;
-
-	pixbuf = gdk_pixbuf_scale_simple(orig, 32*scale_factor,
-					32*scale_factor, GDK_INTERP_BILINEAR);
-	g_object_unref(G_OBJECT(orig));
-
-	return overlay_status_onto_icon(pixbuf, primitive);
-}
-
 static void
 menu_action_cb(GtkMenuItem *item, gpointer object)
 {
--- a/pidgin/gtkutils.h	Mon Feb 26 07:50:01 2007 +0000
+++ b/pidgin/gtkutils.h	Mon Feb 26 09:41:38 2007 +0000
@@ -388,45 +388,14 @@
 GdkPixbuf *pidgin_create_prpl_icon(GaimAccount *account, PidginPrplIconSize size);
 
 /**
- * Create a protocol icon with the status emblem overlayed in
- * the lower right corner.
+ * Creates a status icon for a given primitve
  *
- * @param account      The account.
- * @param status_type  The status type of the emblem to overlay.
- * @param scale_factor The amount to scale to the original image.
- *                     The default size is 32x32 pixels.  A scale
- *                     factor of 1 means no scaling will be done.
- *                     A scale factor of 0.5 means the length
- *                     and width will be 16 pixels each.
- *
- * @return A newly-created pixbuf with a reference count of 1,
- *         or NULL if any of several error conditions occurred:
- *         the file could not be opened, there was no loader
- *         for the file's format, there was not enough memory
- *         to allocate the image buffer, or the image file
- *         contained invalid data.
+ * @param primitive  The status primitive
+ * @param w          The widget to render this
+ * @param size       The icon size to render at
+ * @retrun A GdkPixbuf, created from stock
  */
-GdkPixbuf *pidgin_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor);
-
-/**
- * Create a Pidgin running-man icon with the status emblem overlayed
- * in the lower right corner.
- *
- * @param primitive    The status type to set the emblem for.
- * @param scale_factor The amount to scale to the original image.
- *                     The default size is 32x32 pixels.  A scale
- *                     factor of 1 means no scaling will be done.
- *                     A scale factor of 0.5 means the length
- *                     and width will be 16 pixels each.
- *
- * @return A newly-created pixbuf with a reference count of 1,
- *         or NULL if any of several error conditions occurred:
- *         the file could not be opened, there was no loader for
- *         the file's format, there was not enough memory to
- *         allocate the image buffer, or the image file contained
- *         invalid data.
- */
-GdkPixbuf *pidgin_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor);
+GdkPixbuf * pidgin_create_status_icon(GaimStatusPrimitive primitive, GtkWidget *w, const char *size);
 
 
 /**