gnome-system-monitor r2283 - trunk/src



Author: bdejean
Date: Mon Jan 21 18:37:33 2008
New Revision: 2283
URL: http://svn.gnome.org/viewvc/gnome-system-monitor?rev=2283&view=rev

Log:
New function fill_image_buffer_from_file.
Merged duplicated code and added error handling.
Patch by Jared Moore <cornflake pirate gmail com>
Bug #510558.


Modified:
   trunk/src/gsm_color_button.c

Modified: trunk/src/gsm_color_button.c
==============================================================================
--- trunk/src/gsm_color_button.c	(original)
+++ trunk/src/gsm_color_button.c	Mon Jan 21 18:37:33 2008
@@ -226,6 +226,36 @@
   g_type_class_add_private (gobject_class, sizeof (GSMColorButtonPrivate));
 }
 
+
+static cairo_surface_t *
+fill_image_buffer_from_file (cairo_t *cr, const char *filePath)
+{
+  GError *error = NULL;
+  RsvgHandle *handle;
+  cairo_surface_t *tmp_surface;
+  cairo_t *tmp_cr;
+
+  handle = rsvg_handle_new_from_file (filePath, &error);
+
+  if (handle == NULL) {
+    g_warning("rsvg_handle_new_from_file(\"%s\") failed: %s",
+	      filePath, (error ? error->message : "unknown error"));
+    if (error)
+      g_error_free(error);
+    return NULL;
+  }
+
+  tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
+					      CAIRO_CONTENT_COLOR_ALPHA,
+					      32, 32);
+  tmp_cr = cairo_create (tmp_surface);
+  rsvg_handle_render_cairo (handle, tmp_cr);
+  cairo_destroy (tmp_cr);
+  rsvg_handle_free (handle);
+  return tmp_surface;
+}
+
+
 static void
 render (GtkWidget * widget)
 {
@@ -236,8 +266,6 @@
   cairo_path_t *path = NULL;
   gint width, height;
   gdouble radius, arc_start, arc_end;
-  RsvgHandle *handle;
-  GError *error = NULL;
   gint highlight_factor;
 
   if (color_button->priv->highlight > 0) {
@@ -338,21 +366,9 @@
 
       break;
     case GSMCP_TYPE_NETWORK_IN:
-      /* Fill the image buffer */
       if (color_button->priv->image_buffer == NULL)
-	{
-	  handle = rsvg_handle_new_from_file (DATADIR "/pixmaps/gnome-system-monitor/download.svg", &error);
-	  cairo_surface_t *tmp_surface;
-	  cairo_t *tmp_cr;
-	  tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
-						      CAIRO_CONTENT_COLOR_ALPHA,
-						      32, 32);
-	  tmp_cr = cairo_create (tmp_surface);
-	  rsvg_handle_render_cairo (handle, tmp_cr);
-	  cairo_destroy (tmp_cr);
-	  rsvg_handle_free (handle);
-	  color_button->priv->image_buffer = tmp_surface;
-	}
+	color_button->priv->image_buffer =
+	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/gnome-system-monitor/download.svg");
       gtk_widget_set_size_request (widget, 32, 32);
       cairo_move_to (cr, 8.5, 1.5);
       cairo_line_to (cr, 23.5, 1.5);
@@ -381,21 +397,9 @@
 
       break;
     case GSMCP_TYPE_NETWORK_OUT:
-      /* Fill the image buffer */
       if (color_button->priv->image_buffer == NULL)
-	{
-	  handle = rsvg_handle_new_from_file (DATADIR "/pixmaps/gnome-system-monitor/upload.svg", &error);
-	  cairo_surface_t *tmp_surface;
-	  cairo_t *tmp_cr;
-	  tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
-						      CAIRO_CONTENT_COLOR_ALPHA,
-						      32, 32);
-	  tmp_cr = cairo_create (tmp_surface);
-	  rsvg_handle_render_cairo (handle, tmp_cr);
-	  cairo_destroy (tmp_cr);
-	  rsvg_handle_free (handle);
-	  color_button->priv->image_buffer = tmp_surface;
-	}
+	color_button->priv->image_buffer =
+	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/gnome-system-monitor/upload.svg");
       gtk_widget_set_size_request (widget, 32, 32);
       cairo_move_to (cr, 16.5, 1.5);
       cairo_line_to (cr, 29.5, 17.5);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]