changeset 26726:18543445e929

Reduce code duplication.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 23 Apr 2009 05:30:36 +0000
parents 0011cd06990a
children dbe2731f0a35
files pidgin/gtksavedstatuses.c pidgin/gtkstatusbox.c pidgin/gtkutils.c
diffstat 3 files changed, 6 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtksavedstatuses.c	Thu Apr 23 05:08:06 2009 +0000
+++ b/pidgin/gtksavedstatuses.c	Thu Apr 23 05:30:36 2009 +0000
@@ -398,23 +398,7 @@
 static const gchar *
 get_stock_icon_from_primitive(PurpleStatusPrimitive type)
 {
-	switch (type) {
-		case PURPLE_STATUS_AVAILABLE:
-			return PIDGIN_STOCK_STATUS_AVAILABLE;
-		case PURPLE_STATUS_AWAY:
-			return PIDGIN_STOCK_STATUS_AWAY;
-		case PURPLE_STATUS_EXTENDED_AWAY:
-			return PIDGIN_STOCK_STATUS_XA;
-		case PURPLE_STATUS_INVISIBLE:
-			return PIDGIN_STOCK_STATUS_INVISIBLE;
-		case PURPLE_STATUS_OFFLINE:
-			return PIDGIN_STOCK_STATUS_OFFLINE;
-		case PURPLE_STATUS_UNAVAILABLE:
-			return PIDGIN_STOCK_STATUS_BUSY;
-		default:
-			/* this shouldn't happen */
-			return NULL;
-	}
+	return pidgin_stock_id_from_status_primitive(type);
 }
 
 static void
--- a/pidgin/gtkstatusbox.c	Thu Apr 23 05:08:06 2009 +0000
+++ b/pidgin/gtkstatusbox.c	Thu Apr 23 05:30:36 2009 +0000
@@ -2145,29 +2145,7 @@
 			}
 		}
 
-		switch (prim) {
-			case PURPLE_STATUS_UNSET:
-				stock = NULL;
-				break;
-			case PURPLE_STATUS_UNAVAILABLE:
-				stock = PIDGIN_STOCK_STATUS_BUSY;
-				break;
-			case PURPLE_STATUS_AWAY:
-				stock = PIDGIN_STOCK_STATUS_AWAY;
-				break;
-			case PURPLE_STATUS_EXTENDED_AWAY:
-				stock = PIDGIN_STOCK_STATUS_XA;
-				break;
-			case PURPLE_STATUS_INVISIBLE:
-				stock = PIDGIN_STOCK_STATUS_INVISIBLE;
-				break;
-			case PURPLE_STATUS_OFFLINE:
-				stock = PIDGIN_STOCK_STATUS_OFFLINE;
-				break;
-			default:
-				stock = PIDGIN_STOCK_STATUS_AVAILABLE;
-				break;
-		}
+		stock = pidgin_stock_id_from_status_primitive(prim);
 	}
 
 	gtk_list_store_append(status_box->dropdown_store, &iter);
--- a/pidgin/gtkutils.c	Thu Apr 23 05:08:06 2009 +0000
+++ b/pidgin/gtkutils.c	Thu Apr 23 05:30:36 2009 +0000
@@ -1715,27 +1715,11 @@
 {
 	GtkIconSize icon_size = gtk_icon_size_from_name(size);
 	GdkPixbuf *pixbuf = NULL;
-
-	if (prim == PURPLE_STATUS_UNAVAILABLE)
-		pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_BUSY,
-				icon_size, "GtkWidget");
-	else if (prim == PURPLE_STATUS_AWAY)
-		pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_AWAY,
-				icon_size, "GtkWidget");
-	else if (prim == PURPLE_STATUS_EXTENDED_AWAY)
-		pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_XA,
-				icon_size, "GtkWidget");
-	else if (prim == PURPLE_STATUS_INVISIBLE)
-		pixbuf = gtk_widget_render_icon (w, PIDGIN_STOCK_STATUS_INVISIBLE,
-				icon_size, "GtkWidget");
-	else if (prim == PURPLE_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");
+	const char *stock = pidgin_stock_id_from_status_primitive(prim);
+
+	pixbuf = gtk_widget_render_icon (w, stock ? stock : PIDGIN_STOCK_STATUS_AVAILABLE,
+			icon_size, "GtkWidget");
 	return pixbuf;
-
 }
 
 const char *