[gnome-control-center] background: Add function to compare 2 bg items



commit 758242bb8e43967e0a589e2cdd0597fcff2352fb
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Feb 13 02:49:03 2011 +0000

    background: Add function to compare 2 bg items

 panels/background/cc-background-item.c |   66 ++++++++++++++++++++++++++++++++
 panels/background/cc-background-item.h |    3 +
 2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/panels/background/cc-background-item.c b/panels/background/cc-background-item.c
index 476cc24..535abc7 100644
--- a/panels/background/cc-background-item.c
+++ b/panels/background/cc-background-item.c
@@ -811,3 +811,69 @@ cc_background_item_dump (CcBackgroundItem *item)
 	g_debug ("dimensions:\t\t%d x %d", priv->width, priv->height);
 	g_debug (" ");
 }
+
+static gboolean
+files_equal (const char *a,
+	     const char *b)
+{
+	GFile *file1, *file2;
+	gboolean retval;
+
+	file1 = g_file_new_for_commandline_arg (a);
+	file2 = g_file_new_for_commandline_arg (b);
+	if (g_file_equal (file1, file2) == FALSE)
+		retval = FALSE;
+	else
+		retval = TRUE;
+	g_object_unref (file1);
+	g_object_unref (file2);
+
+	return retval;
+}
+
+static gboolean
+colors_equal (const char *a,
+	      const char *b)
+{
+	GdkColor color1, color2;
+
+	gdk_color_parse (a, &color1);
+	gdk_color_parse (b, &color2);
+
+	return gdk_color_equal (&color1, &color2);
+}
+
+gboolean
+cc_background_item_compare (CcBackgroundItem *saved,
+			    CcBackgroundItem *configured)
+{
+	CcBackgroundItemFlags flags;
+
+	flags = saved->priv->flags;
+	if (flags & CC_BACKGROUND_ITEM_HAS_URI) {
+		if (files_equal (saved->priv->uri, configured->priv->uri) == FALSE)
+			return FALSE;
+	}
+	if (flags & CC_BACKGROUND_ITEM_HAS_SHADING) {
+		if (saved->priv->shading != configured->priv->shading)
+			return FALSE;
+	}
+	if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT) {
+		if (saved->priv->placement != configured->priv->placement)
+			return FALSE;
+	}
+	if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR) {
+		if (colors_equal (saved->priv->primary_color,
+				  configured->priv->primary_color) == FALSE) {
+			return FALSE;
+		}
+	}
+	if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR) {
+		if (colors_equal (saved->priv->secondary_color,
+				  configured->priv->secondary_color) == FALSE) {
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
diff --git a/panels/background/cc-background-item.h b/panels/background/cc-background-item.h
index 8180f2f..1840dd9 100644
--- a/panels/background/cc-background-item.h
+++ b/panels/background/cc-background-item.h
@@ -92,6 +92,9 @@ const char *              cc_background_item_get_scolor     (CcBackgroundItem *i
 const char *              cc_background_item_get_name       (CcBackgroundItem *item);
 const char *              cc_background_item_get_size       (CcBackgroundItem *item);
 
+gboolean                  cc_background_item_compare        (CcBackgroundItem *saved,
+							     CcBackgroundItem *configured);
+
 void                      cc_background_item_dump           (CcBackgroundItem *item);
 
 G_END_DECLS



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