[gnome-color-manager] Add GcmCellRendererProfile to automatically render a profile to a cell
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add GcmCellRendererProfile to automatically render a profile to a cell
- Date: Wed, 26 May 2010 16:33:05 +0000 (UTC)
commit 2ade3b4d99c480dfc01d909bac8e8f8002784085
Author: Richard Hughes <richard hughsie com>
Date: Wed May 26 11:04:27 2010 +0100
Add GcmCellRendererProfile to automatically render a profile to a cell
src/Makefile.am | 2 +
src/gcm-cell-renderer-profile.c | 164 +++++++++++++++++++++++++++++++++++++++
src/gcm-cell-renderer-profile.h | 61 ++++++++++++++
src/gcm-prefs.c | 11 +--
4 files changed, 232 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9dea212..9fd520e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -243,6 +243,8 @@ gcm_import_CFLAGS = \
$(WARNINGFLAGS_C)
gcm_prefs_SOURCES = \
+ gcm-cell-renderer-profile.c \
+ gcm-cell-renderer-profile.h \
gcm-prefs.c
gcm_prefs_LDADD = \
diff --git a/src/gcm-cell-renderer-profile.c b/src/gcm-cell-renderer-profile.c
new file mode 100644
index 0000000..bcaf690
--- /dev/null
+++ b/src/gcm-cell-renderer-profile.c
@@ -0,0 +1,164 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "egg-debug.h"
+
+#include "gcm-cell-renderer-profile.h"
+
+enum {
+ PROP_0,
+ PROP_PROFILE,
+ PROP_IS_DEFAULT,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmCellRendererProfile, gcm_cell_renderer_profile, GTK_TYPE_CELL_RENDERER_TEXT)
+
+static gpointer parent_class = NULL;
+
+static void
+gcm_cell_renderer_profile_get_property (GObject *object, guint param_id,
+ GValue *value, GParamSpec *pspec)
+{
+ GcmCellRendererProfile *renderer = GCM_CELL_RENDERER_PROFILE (object);
+
+ switch (param_id) {
+ case PROP_PROFILE:
+ g_value_set_object (value, renderer->profile);
+ break;
+ case PROP_IS_DEFAULT:
+ g_value_set_boolean (value, renderer->is_default);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+gcm_cell_renderer_set_markup (GcmCellRendererProfile *renderer)
+{
+ GString *string;
+ const gchar *description;
+
+ /* not yet set */
+ if (renderer->profile == NULL)
+ return;
+
+ /* add profile description */
+ description = gcm_profile_get_description (renderer->profile);
+ if (description == NULL)
+ description = gcm_profile_get_filename (renderer->profile);
+ string = g_string_new (description);
+
+ /* TRANSLATORS: this is the default profile */
+ if (renderer->is_default)
+ g_string_append_printf (string, " [%s]", _("Default"));
+
+ /* assign */
+ g_free (renderer->markup);
+ renderer->markup = g_string_free (string, FALSE);
+ g_object_set (renderer, "markup", renderer->markup, NULL);
+}
+
+static void
+gcm_cell_renderer_profile_set_property (GObject *object, guint param_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ GcmCellRendererProfile *renderer = GCM_CELL_RENDERER_PROFILE (object);
+
+ switch (param_id) {
+ case PROP_PROFILE:
+ if (renderer->profile != NULL)
+ g_object_unref (renderer->profile);
+ renderer->profile = g_value_dup_object (value);
+ gcm_cell_renderer_set_markup (renderer);
+ break;
+ case PROP_IS_DEFAULT:
+ renderer->is_default = g_value_get_boolean (value);
+ gcm_cell_renderer_set_markup (renderer);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gcm_cell_renderer_finalize:
+ * @object: The object to finalize
+ **/
+static void
+gcm_cell_renderer_finalize (GObject *object)
+{
+ GcmCellRendererProfile *renderer;
+ renderer = GCM_CELL_RENDERER_PROFILE (object);
+ g_free (renderer->markup);
+ if (renderer->profile != NULL)
+ g_object_unref (renderer->profile);
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gcm_cell_renderer_profile_class_init (GcmCellRendererProfileClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ object_class->finalize = gcm_cell_renderer_finalize;
+
+ parent_class = g_type_class_peek_parent (class);
+
+ object_class->get_property = gcm_cell_renderer_profile_get_property;
+ object_class->set_property = gcm_cell_renderer_profile_set_property;
+
+ g_object_class_install_property (object_class, PROP_PROFILE,
+ g_param_spec_object ("profile", "PROFILE",
+ "PROFILE", GCM_TYPE_PROFILE, G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_IS_DEFAULT,
+ g_param_spec_boolean ("is-default", "IS_DEFAULT",
+ "IS_DEFAULT", FALSE, G_PARAM_READWRITE));
+}
+
+/**
+ * gcm_cell_renderer_profile_init:
+ **/
+static void
+gcm_cell_renderer_profile_init (GcmCellRendererProfile *renderer)
+{
+ renderer->is_default = FALSE;
+ renderer->profile = NULL;
+ renderer->markup = NULL;
+}
+
+/**
+ * gcm_cell_renderer_profile_new:
+ **/
+GtkCellRenderer *
+gcm_cell_renderer_profile_new (void)
+{
+ return g_object_new (GCM_TYPE_CELL_RENDERER_PROFILE, NULL);
+}
+
diff --git a/src/gcm-cell-renderer-profile.h b/src/gcm-cell-renderer-profile.h
new file mode 100644
index 0000000..7c37735
--- /dev/null
+++ b/src/gcm-cell-renderer-profile.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GCM_CELL_RENDERER_PROFILE_H
+#define GCM_CELL_RENDERER_PROFILE_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include "gcm-profile.h"
+
+#define GCM_TYPE_CELL_RENDERER_PROFILE (gcm_cell_renderer_profile_get_type())
+#define GCM_CELL_RENDERER_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCM_TYPE_CELL_RENDERER_PROFILE, GcmCellRendererProfile))
+#define GCM_CELL_RENDERER_PROFILE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), GCM_TYPE_CELL_RENDERER_PROFILE, GcmCellRendererProfileClass))
+#define GCM_IS_CELL_RENDERER_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCM_TYPE_CELL_RENDERER_PROFILE))
+#define GCM_IS_CELL_RENDERER_PROFILE_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), GCM_TYPE_CELL_RENDERER_PROFILE))
+#define GCM_CELL_RENDERER_PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCM_TYPE_CELL_RENDERER_PROFILE, GcmCellRendererProfileClass))
+
+G_BEGIN_DECLS
+
+typedef struct _GcmCellRendererProfile GcmCellRendererProfile;
+typedef struct _GcmCellRendererProfileClass GcmCellRendererProfileClass;
+
+struct _GcmCellRendererProfile
+{
+ GtkCellRendererText parent;
+ GcmProfile *profile;
+ gboolean is_default;
+ gchar *markup;
+};
+
+struct _GcmCellRendererProfileClass
+{
+ GtkCellRendererTextClass parent_class;
+};
+
+GType gcm_cell_renderer_profile_get_type (void);
+GtkCellRenderer *gcm_cell_renderer_profile_new (void);
+
+G_END_DECLS
+
+#endif /* GCM_CELL_RENDERER_PROFILE_H */
+
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 8c9b9a0..b741902 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -33,6 +33,7 @@
#include "egg-debug.h"
+#include "gcm-cell-renderer-profile.h"
#include "gcm-calibrate-argyll.h"
#include "gcm-cie-widget.h"
#include "gcm-client.h"
@@ -73,7 +74,6 @@ enum {
GCM_PROFILES_COLUMN_ID,
GCM_PROFILES_COLUMN_SORT,
GCM_PROFILES_COLUMN_ICON,
- GCM_PROFILES_COLUMN_TITLE,
GCM_PROFILES_COLUMN_PROFILE,
GCM_PROFILES_COLUMN_LAST
};
@@ -436,7 +436,6 @@ gcm_prefs_update_profile_list (void)
gtk_list_store_set (list_store_profiles, &iter,
GCM_PROFILES_COLUMN_ID, filename,
GCM_PROFILES_COLUMN_SORT, sort,
- GCM_PROFILES_COLUMN_TITLE, description,
GCM_PROFILES_COLUMN_ICON, icon_name,
GCM_PROFILES_COLUMN_PROFILE, profile,
-1);
@@ -1204,13 +1203,13 @@ gcm_prefs_add_profiles_columns (GtkTreeView *treeview)
gtk_widget_set_size_request (GTK_WIDGET (treeview), GCM_PREFS_TREEVIEW_WIDTH, -1);
/* column for text */
- renderer = gtk_cell_renderer_text_new ();
+ renderer = gcm_cell_renderer_profile_new ();
g_object_set (renderer,
"wrap-mode", PANGO_WRAP_WORD,
"wrap-width", GCM_PREFS_TREEVIEW_WIDTH - 62,
NULL);
column = gtk_tree_view_column_new_with_attributes ("", renderer,
- "markup", GCM_PROFILES_COLUMN_TITLE, NULL);
+ "profile", GCM_PROFILES_COLUMN_PROFILE, NULL);
gtk_tree_view_column_set_sort_column_id (column, GCM_PROFILES_COLUMN_SORT);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store_profiles), GCM_PROFILES_COLUMN_SORT, GTK_SORT_ASCENDING);
gtk_tree_view_append_column (treeview, column);
@@ -2866,8 +2865,8 @@ main (int argc, char **argv)
/* create list stores */
list_store_devices = gtk_list_store_new (GCM_DEVICES_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
- list_store_profiles = gtk_list_store_new (GCM_PROFILES_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
+ list_store_profiles = gtk_list_store_new (GCM_PROFILES_COLUMN_LAST, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING, GCM_TYPE_PROFILE);
/* create device tree view */
widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]