[PATCH] Color values are stored as strings and not lists.

David Reveman davidr at novell.com
Fri Aug 17 12:08:53 PDT 2007


---
 settings-backend/kconfig_backend.cpp |   68 +++++++++++++++++++--------------
 1 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/settings-backend/kconfig_backend.cpp b/settings-backend/kconfig_backend.cpp
index 43d66e5..3d955f6 100644
--- a/settings-backend/kconfig_backend.cpp
+++ b/settings-backend/kconfig_backend.cpp
@@ -530,12 +530,19 @@ readSetting (CCSContext *c,
 
     case TypeColor:
 	{
-	    QValueList<int> list = cfg->readIntListEntry (key);
+	    QString str = cfg->readEntry (key);
 	    CCSSettingColorValue color;
-	    color.color.red = list[0];
-	    color.color.green = list[1];
-	    color.color.blue = list[2];
-	    color.color.alpha = list[3];
+	    int c[4];
+
+	    if (sscanf (str.ascii (), "#%2x%2x%2x%2x",
+			&c[0], &c[1], &c[2], &c[3]) == 4)
+	    {
+		color.color.red = c[0] << 8 | c[0];
+		color.color.green = c[1] << 8 | c[1];
+		color.color.blue = c[2] << 8 | c[2];
+		color.color.alpha = c[3] << 8 | c[3];
+	    }
+
 	    ccsSetColor (setting, color);
 	}
 	break;
@@ -695,11 +702,17 @@ readSetting (CCSContext *c,
 
 		    for (it = list.begin(); it != list.end(); it++)
 		    {
-			QStringList colorstr = QStringList::split (",", (*it) );
-			array[i].color.red = colorstr[0].toInt();
-			array[i].color.green = colorstr[1].toInt();
-			array[i].color.blue = colorstr[2].toInt();
-			array[i].color.alpha = colorstr[3].toInt();
+			int c[4];
+
+			if (sscanf ((*it).ascii (), "#%2x%2x%2x%2x",
+				    &c[0], &c[1], &c[2], &c[3]) == 4)
+			{
+			    array[i].color.red = c[0] << 8 | c[0];
+			    array[i].color.green = c[1] << 8 | c[1];
+			    array[i].color.blue = c[2] << 8 | c[2];
+			    array[i].color.alpha = c[3] << 8 | c[3];
+			}
+
 			i++;
 		    }
 
@@ -1058,21 +1071,18 @@ writeSetting (CCSContext *c,
     case TypeColor:
 	{
 	    CCSSettingColorValue color;
+	    char tmp[256];
 
 	    if (!ccsGetColor (setting, &color) )
 		break;
 
-	    QValueList<int> list;
-
-	    list.append (color.color.red);
-
-	    list.append (color.color.green);
-
-	    list.append (color.color.blue);
+	    snprintf (tmp, 256, "#%.2x%.2x%.2x%.2x",
+		      color.color.red / 256,
+		      color.color.green/ 256,
+		      color.color.blue / 256,
+		      color.color.alpha / 256);
 
-	    list.append (color.color.alpha);
-
-	    cfg->writeEntry (key, list);
+	    cfg->writeEntry (key, QString (tmp));
 	}
 	break;
 
@@ -1181,15 +1191,15 @@ writeSetting (CCSContext *c,
 
 		    while (l)
 		    {
-			QString str;
-			str += l->data->value.asColor.array.array[0];
-			str += ",";
-			str += l->data->value.asColor.array.array[1];
-			str += ",";
-			str += l->data->value.asColor.array.array[2];
-			str += ",";
-			str += l->data->value.asColor.array.array[3];
-			list.append (str);
+			char tmp[256];
+
+			snprintf (tmp, 256, "#%.2x%.2x%.2x%.2x",
+				  l->data->value.asColor.array.array[0] / 256,
+				  l->data->value.asColor.array.array[1] / 256,
+				  l->data->value.asColor.array.array[2] / 256,
+				  l->data->value.asColor.array.array[3] / 256);
+
+			list.append (QString (tmp));
 			l = l->next;
 		    }
 
-- 
1.5.2.4


--=-JKJEo0QaMHFoQml1BvGW--



More information about the compiz mailing list