[gnome-packagekit] Correctly use the theme colors rather than hardcoding gray



commit 4363a17af7b7aa03b0fe38275d2fcb9f4c71510d
Author: Richard Hughes <richard hughsie com>
Date:   Wed Aug 17 13:19:15 2011 +0100

    Correctly use the theme colors rather than hardcoding gray

 src/gpk-application.c    |    6 ++++-
 src/gpk-common.c         |   57 +++++++++++++++++++++++++++++++++-------------
 src/gpk-common.h         |    3 +-
 src/gpk-dbus-task.c      |    2 +-
 src/gpk-dialog.c         |    2 +-
 src/gpk-helper-chooser.c |    6 +++-
 src/gpk-helper-run.c     |    2 +-
 src/gpk-modal-dialog.c   |    3 +-
 src/gpk-update-viewer.c  |    9 +++++-
 9 files changed, 64 insertions(+), 26 deletions(-)
---
diff --git a/src/gpk-application.c b/src/gpk-application.c
index bb82be4..d43aeeb 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -1228,6 +1228,7 @@ gpk_application_add_item_to_results (PkPackage *item)
 	PkInfoEnum info;
 	gchar *package_id = NULL;
 	gchar *summary = NULL;
+	GtkWidget *widget;
 
 	/* get data */
 	g_object_get (item,
@@ -1266,7 +1267,10 @@ gpk_application_add_item_to_results (PkPackage *item)
 	checkbox = gpk_application_state_get_checkbox (state);
 
 	/* use two lines */
-	text = gpk_package_id_format_twoline (package_id, summary_markup);
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "window_manager"));
+	text = gpk_package_id_format_twoline (gtk_widget_get_style_context (widget),
+					      package_id,
+					      summary_markup);
 
 	/* can we modify this? */
 	enabled = gpk_application_get_checkbox_enable (state);
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 9cf6d57..db259c5 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -285,40 +285,65 @@ gpk_window_set_parent_xid (GtkWindow *window, guint32 xid)
  * Return value: "<b>GTK Toolkit</b>\ngtk2-2.12.2 (i386)"
  **/
 gchar *
-gpk_package_id_format_twoline (const gchar *package_id, const gchar *summary)
+gpk_package_id_format_twoline (GtkStyleContext *style,
+			       const gchar *package_id,
+			       const gchar *summary)
 {
-	gchar *summary_safe;
+	gchar *summary_safe = NULL;
 	gchar *text = NULL;
 	GString *string;
 	gchar **split = NULL;
+	gchar *color;
+	GdkRGBA inactive;
 
 	g_return_val_if_fail (package_id != NULL, NULL);
 
+	/* get style color */
+	if (style != NULL) {
+		gtk_style_context_get_color (style,
+					     GTK_STATE_FLAG_INSENSITIVE,
+					     &inactive);
+		color = g_strdup_printf ("#%02x%02x%02x",
+					 (guint) (inactive.red * 255.0f),
+					 (guint) (inactive.green * 255.0f),
+					 (guint) (inactive.blue * 255.0f));
+	} else {
+		color = g_strdup ("gray");
+	}
+
 	/* optional */
 	split = pk_package_id_split (package_id);
 	if (split == NULL) {
 		g_warning ("could not parse %s", package_id);
 		goto out;
 	}
-	if (summary == NULL || summary[PK_PACKAGE_ID_NAME] == '\0') {
+
+	/* no summary */
+	if (summary == NULL || summary[0] == '\0') {
 		string = g_string_new (split[PK_PACKAGE_ID_NAME]);
-	} else {
-		string = g_string_new ("");
-		summary_safe = g_markup_escape_text (summary, -1);
-		g_string_append_printf (string, "<b>%s</b>\n%s", summary_safe, split[PK_PACKAGE_ID_NAME]);
-		g_free (summary_safe);
+		if (split[PK_PACKAGE_ID_VERSION][0] != '\0')
+			g_string_append_printf (string, "-%s", split[PK_PACKAGE_ID_VERSION]);
+		if (split[PK_PACKAGE_ID_ARCH][0] != '\0')
+			g_string_append_printf (string, " (%s)", split[PK_PACKAGE_ID_ARCH]);
+		text = g_string_free (string, FALSE);
+		goto out;
 	}
 
-	/* some backends don't provide this */
-	g_string_append (string, "<span color=\"gray\">");
+	/* name and summary */
+	string = g_string_new ("");
+	summary_safe = g_markup_escape_text (summary, -1);
+	g_string_append_printf (string, "<b>%s</b>\n", summary_safe);
+	g_string_append_printf (string, "<span color=\"%s\">", color);
+	g_string_append (string, split[PK_PACKAGE_ID_NAME]);
 	if (split[PK_PACKAGE_ID_VERSION][0] != '\0')
 		g_string_append_printf (string, "-%s", split[PK_PACKAGE_ID_VERSION]);
 	if (split[PK_PACKAGE_ID_ARCH][0] != '\0')
 		g_string_append_printf (string, " (%s)", split[PK_PACKAGE_ID_ARCH]);
 	g_string_append (string, "</span>");
-
 	text = g_string_free (string, FALSE);
 out:
+	g_free (summary_safe);
+	g_free (color);
 	g_strfreev (split);
 	return text;
 }
@@ -878,7 +903,7 @@ gpk_common_test (gpointer data)
 	 ****************     package name text        **************
 	 ************************************************************/
 	egg_test_title (test, "package id pretty valid package id, no summary");
-	text = gpk_package_id_format_twoline ("simon;0.0.1;i386;data", NULL);
+	text = gpk_package_id_format_twoline (NULL, "simon;0.0.1;i386;data", NULL);
 	if (text != NULL && strcmp (text, "simon-0.0.1 (i386)") == 0)
 		egg_test_success (test, NULL);
 	else
@@ -887,7 +912,7 @@ gpk_common_test (gpointer data)
 
 	/************************************************************/
 	egg_test_title (test, "package id pretty valid package id, no summary 2");
-	text = gpk_package_id_format_twoline ("simon;0.0.1;;data", NULL);
+	text = gpk_package_id_format_twoline (NULL, "simon;0.0.1;;data", NULL);
 	if (text != NULL && strcmp (text, "simon-0.0.1") == 0)
 		egg_test_success (test, NULL);
 	else
@@ -896,7 +921,7 @@ gpk_common_test (gpointer data)
 
 	/************************************************************/
 	egg_test_title (test, "package id pretty valid package id, no summary 3");
-	text = gpk_package_id_format_twoline ("simon;;;data", NULL);
+	text = gpk_package_id_format_twoline (NULL, "simon;;;data", NULL);
 	if (text != NULL && strcmp (text, "simon") == 0)
 		egg_test_success (test, NULL);
 	else
@@ -905,8 +930,8 @@ gpk_common_test (gpointer data)
 
 	/************************************************************/
 	egg_test_title (test, "package id pretty valid package id, no summary 4");
-	text = gpk_package_id_format_twoline ("simon;0.0.1;;data", "dude");
-	if (text != NULL && strcmp (text, "<b>dude</b>\nsimon-0.0.1") == 0)
+	text = gpk_package_id_format_twoline (NULL, "simon;0.0.1;;data", "dude");
+	if (text != NULL && strcmp (text, "<b>dude</b>\n<span color=\"gray\">simon-0.0.1</span>") == 0)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed, got %s", text);
diff --git a/src/gpk-common.h b/src/gpk-common.h
index cd4bbdb..bbbeffd 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -77,7 +77,8 @@ void		 gpk_common_test			(gpointer	 data);
 void		 gtk_text_buffer_insert_markup		(GtkTextBuffer	*buffer,
 							 GtkTextIter	*iter,
 							 const gchar	*markup);
-gchar		*gpk_package_id_format_twoline		(const gchar 	*package_id,
+gchar		*gpk_package_id_format_twoline		(GtkStyleContext *style,
+							 const gchar 	*package_id,
 							 const gchar	*summary);
 gchar		*gpk_package_id_format_oneline		(const gchar 	*package_id,
 							 const gchar	*summary);
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index 9c9fe29..eda869e 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -802,7 +802,7 @@ gpk_dbus_task_progress_cb (PkProgress *progress, PkProgressType type, GpkDbusTas
 	} else if (type == PK_PROGRESS_TYPE_REMAINING_TIME) {
 		gpk_modal_dialog_set_remaining (dtask->priv->dialog, remaining_time);
 	} else if (type == PK_PROGRESS_TYPE_PACKAGE_ID) {
-		text = gpk_package_id_format_twoline (package_id, NULL); //TODO: need summary
+		text = gpk_package_id_format_twoline (NULL, package_id, NULL); //TODO: need summary
 		gpk_modal_dialog_set_message (dtask->priv->dialog, text);
 		g_free (text);
 	}
diff --git a/src/gpk-dialog.c b/src/gpk-dialog.c
index 975fa8d..50064c6 100644
--- a/src/gpk-dialog.c
+++ b/src/gpk-dialog.c
@@ -104,7 +104,7 @@ gpk_dialog_package_array_to_list_store (GPtrArray *array)
 			      "package-id", &package_id,
 			      "summary", &summary,
 			      NULL);
-		text = gpk_package_id_format_twoline (package_id, summary);
+		text = gpk_package_id_format_twoline (NULL, package_id, summary);
 
 		/* get the icon */
 		split = pk_package_id_split (package_id);
diff --git a/src/gpk-helper-chooser.c b/src/gpk-helper-chooser.c
index 38dc956..0960c30 100644
--- a/src/gpk-helper-chooser.c
+++ b/src/gpk-helper-chooser.c
@@ -174,6 +174,7 @@ gpk_helper_chooser_show (GpkHelperChooser *helper, GPtrArray *list)
 	g_return_val_if_fail (list != NULL, FALSE);
 
 	/* see what we've got already */
+	widget = GTK_WIDGET (gtk_builder_get_object (helper->priv->builder, "dialog_simple"));
 	for (i=0; i<list->len; i++) {
 		item = g_ptr_array_index (list, i);
 		g_object_get (item,
@@ -185,7 +186,9 @@ gpk_helper_chooser_show (GpkHelperChooser *helper, GPtrArray *list)
 
 		/* put formatted text into treeview */
 		gtk_list_store_append (helper->priv->list_store, &iter);
-		text = gpk_package_id_format_twoline (package_id, summary);
+		text = gpk_package_id_format_twoline (gtk_widget_get_style_context (widget),
+						      package_id,
+						      summary);
 
 		/* get the icon */
 		split = pk_package_id_split (package_id);
@@ -204,7 +207,6 @@ gpk_helper_chooser_show (GpkHelperChooser *helper, GPtrArray *list)
 	}
 
 	/* show window */
-	widget = GTK_WIDGET (gtk_builder_get_object (helper->priv->builder, "dialog_simple"));
 	gtk_widget_show (widget);
 
 	return TRUE;
diff --git a/src/gpk-helper-run.c b/src/gpk-helper-run.c
index 31e2d0e..793cb0a 100644
--- a/src/gpk-helper-run.c
+++ b/src/gpk-helper-run.c
@@ -295,7 +295,7 @@ gpk_helper_run_add_desktop_file (GpkHelperRun *helper, const gchar *package_id,
 	/* put formatted text into treeview */
 	gtk_list_store_append (helper->priv->list_store, &iter);
 	joint = g_strdup_printf ("%s - %s", name, summary);
-	text = gpk_package_id_format_twoline (package_id, joint);
+	text = gpk_package_id_format_twoline (NULL, package_id, joint);
 
 	gtk_list_store_set (helper->priv->list_store, &iter,
 			    GPK_CHOOSER_COLUMN_TEXT, fulltext,
diff --git a/src/gpk-modal-dialog.c b/src/gpk-modal-dialog.c
index 10e7b57..d3ac6f1 100644
--- a/src/gpk-modal-dialog.c
+++ b/src/gpk-modal-dialog.c
@@ -674,7 +674,8 @@ gpk_modal_dialog_set_package_list (GpkModalDialog *dialog, const GPtrArray *list
 			      "summary", &summary,
 			      NULL);
 
-		text = gpk_package_id_format_twoline (package_id, summary);
+		text = gpk_package_id_format_twoline (gtk_widget_get_style_context (widget),
+						      package_id, summary);
 
 		/* get the icon */
 		split = pk_package_id_split (package_id);
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index f45822c..7e908c3 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -863,7 +863,9 @@ gpk_update_viewer_progress_cb (PkProgress *progress, PkProgressType type, gpoint
 			/* find our parent */
 			ret = gpk_update_viewer_find_parent (package_id, &parent);
 
-			text = gpk_package_id_format_twoline (package_id, summary);
+			text = gpk_package_id_format_twoline (gtk_widget_get_style_context (GTK_WIDGET (treeview)),
+							      package_id,
+							      summary);
 			g_debug ("adding: id=%s, text=%s", package_id, text);
 
 			/* do we add to a parent? */
@@ -2605,6 +2607,7 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
 	sack = pk_results_get_package_sack (results);
 	pk_package_sack_sort (sack, PK_PACKAGE_SACK_SORT_TYPE_NAME);
 	array = pk_package_sack_get_array (sack);
+	widget = GTK_WIDGET(gtk_builder_get_object (builder, "treeview_updates"));
 	for (i=0; i<array->len; i++) {
 		item = g_ptr_array_index (array, i);
 
@@ -2619,7 +2622,9 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
 		ret = gpk_update_viewer_find_parent (package_id, &parent);
 
 		/* add to array store */
-		text = gpk_package_id_format_twoline (package_id, summary);
+		text = gpk_package_id_format_twoline (gtk_widget_get_style_context (widget),
+						      package_id,
+						      summary);
 		g_debug ("adding: id=%s, text=%s", package_id, text);
 		selected = (info != PK_INFO_ENUM_BLOCKED);
 



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