[gnome-color-manager] Linkify the copyright and manufacturer strings in the profile dialog
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Linkify the copyright and manufacturer strings in the profile dialog
- Date: Wed, 30 Dec 2009 16:05:15 +0000 (UTC)
commit 58f544107ba1f81061b61f7ed9265bb484864418
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 30 13:24:05 2009 +0000
Linkify the copyright and manufacturer strings in the profile dialog
src/gcm-prefs.c | 9 ++++++-
src/gcm-utils.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/gcm-utils.h | 1 +
3 files changed, 65 insertions(+), 3 deletions(-)
---
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 33525e9..08d3199 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -1545,6 +1545,7 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
gchar *profile_manufacturer = NULL;
gchar *profile_model = NULL;
gchar *profile_datetime = NULL;
+ gchar *temp;
gchar *filename = NULL;
gchar *basename = NULL;
gchar *size_text = NULL;
@@ -1658,7 +1659,9 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
} else {
gtk_widget_show (widget);
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_copyright"));
- gtk_label_set_label (GTK_LABEL(widget), profile_copyright);
+ temp = gcm_utils_linkify (profile_copyright);
+ gtk_label_set_label (GTK_LABEL (widget), temp);
+ g_free (temp);
}
/* set new manufacturer */
@@ -1668,7 +1671,9 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection, gpointer us
} else {
gtk_widget_show (widget);
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_profile_manufacturer"));
- gtk_label_set_label (GTK_LABEL(widget), profile_manufacturer);
+ temp = gcm_utils_linkify (profile_manufacturer);
+ gtk_label_set_label (GTK_LABEL (widget), temp);
+ g_free (temp);
}
/* set new model */
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 1e578d1..ac589e9 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -37,7 +37,52 @@
#include "egg-debug.h"
/**
- * gcm_utils_install_package:
+ * gcm_utils_linkify:
+ **/
+gchar *
+gcm_utils_linkify (const gchar *text)
+{
+ guint i;
+ guint j = 0;
+ gboolean ret;
+ GString *string;
+
+ /* find and replace links */
+ string = g_string_new ("");
+ for (i=0;; i++) {
+
+ /* find the start of a link */
+ ret = g_str_has_prefix (&text[i], "http://");
+ if (ret) {
+ egg_debug ("dump from %i to %i", j, i);
+ g_string_append_len (string, text+j, i-j);
+ for (j=i;; j++) {
+ /* find the end of the link, or the end of the string */
+ if (text[j] == '\0' ||
+ text[j] == ' ') {
+ egg_debug ("link is from %i to %i", i, j);
+ g_string_append (string, "<a href=\"");
+ g_string_append_len (string, text+i, j-i);
+ g_string_append (string, "\">");
+ g_string_append_len (string, text+i, j-i);
+ g_string_append (string, "</a>");
+ break;
+ }
+ }
+ }
+
+ /* end of the string, dump what's left */
+ if (text[i] == '\0') {
+ egg_debug ("dump from %i to %i", j, i);
+ g_string_append_len (string, text+j, i-j);
+ break;
+ }
+ }
+ return g_string_free (string, FALSE);
+}
+
+/**
+ * gcm_utils_is_icc_profile:
**/
gboolean
gcm_utils_is_icc_profile (const gchar *filename)
@@ -859,6 +904,17 @@ gcm_utils_test (EggTest *test)
return;
/************************************************************/
+ egg_test_title (test, "Linkify text");
+ text = gcm_utils_linkify ("http://www.dave.org is text http://www.hughsie.com that needs to be linked to http://www.bbc.co.uk really");
+ if (g_strcmp0 (text, "<a href=\"http://www.dave.org\">http://www.dave.org</a> is text "
+ "<a href=\"http://www.hughsie.com\">http://www.hughsie.com</a> that needs to be linked to "
+ "<a href=\"http://www.bbc.co.uk\">http://www.bbc.co.uk</a> really") == 0)
+ egg_test_success (test, NULL);
+ else
+ egg_test_failed (test, "failed to linkify text: %s", text);
+ g_free (text);
+
+ /************************************************************/
egg_test_title (test, "get profile filenames");
array = gcm_utils_get_profile_filenames ();
egg_test_assert (test, array->len > 1);
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index a802bf5..10884cf 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -59,6 +59,7 @@ void gcm_utils_ensure_sane_length (gchar *text,
guint max_length);
void gcm_utils_ensure_printable (gchar *text);
gboolean gcm_utils_is_icc_profile (const gchar *filename);
+gchar *gcm_utils_linkify (const gchar *text);
#endif /* __GCM_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]