[glade] GladeWidget: Enhanced support warnings
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] GladeWidget: Enhanced support warnings
- Date: Wed, 10 Apr 2013 16:06:46 +0000 (UTC)
commit 34585f45158e8126f1f5c14830a371c6ecf32ce6
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Thu Apr 11 00:06:12 2013 +0900
GladeWidget: Enhanced support warnings
o Now GladeWidget support warnings include warnings about any used
properties or signals which have warnings
o GladeWidget support warnings update appropriately when signals
are added/removed or when properties are changed/enabled
o GladeProject now also has a column with the widget warning text
which gets updated any time a widget's warning changes
gladeui/glade-project.c | 18 ++++---
gladeui/glade-project.h | 2 +
gladeui/glade-property.c | 59 +++++++++++++++++++-
gladeui/glade-property.h | 2 +
gladeui/glade-widget.c | 136 +++++++++++++++++++++++++++++++++++++++++++++-
gladeui/glade-widget.h | 1 +
6 files changed, 205 insertions(+), 13 deletions(-)
---
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 896feee..1a77bb7 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -2797,21 +2797,17 @@ glade_project_verify_project_for_ui (GladeProject *project)
{
GList *list;
GladeWidget *widget;
- gchar *warning;
/* Sync displayable info here */
for (list = project->priv->objects; list; list = list->next)
{
widget = glade_widget_get_from_gobject (list->data);
- warning =
- glade_project_verify_widget_adaptor (project, glade_widget_get_adaptor (widget), NULL);
- glade_widget_set_support_warning (widget, warning);
-
- if (warning)
- g_free (warning);
-
+ /* Update the support warnings for widget's properties */
glade_project_verify_properties (widget);
+
+ /* Update the support warning for widget */
+ glade_widget_verify (widget);
}
}
@@ -4679,6 +4675,8 @@ glade_project_model_get_column_type (GtkTreeModel *model, gint column)
return G_TYPE_OBJECT;
case GLADE_PROJECT_MODEL_COLUMN_MISC:
return G_TYPE_STRING;
+ case GLADE_PROJECT_MODEL_COLUMN_WARNING:
+ return G_TYPE_STRING;
default:
g_assert_not_reached ();
return G_TYPE_NONE;
@@ -4841,6 +4839,10 @@ glade_project_model_get_value (GtkTreeModel *model,
g_value_take_string (value, str);
break;
+ case GLADE_PROJECT_MODEL_COLUMN_WARNING:
+ g_value_set_string (value, glade_widget_support_warning (widget));
+ break;
+
default:
g_assert_not_reached ();
}
diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h
index c243eec..dd7dc34 100644
--- a/gladeui/glade-project.h
+++ b/gladeui/glade-project.h
@@ -52,6 +52,7 @@ typedef enum
* @GLADE_PROJECT_MODEL_COLUMN_TYPE_NAME: The type name of the widget
* @GLADE_PROJECT_MODEL_COLUMN_OBJECT: the GObject of the widget
* @GLADE_PROJECT_MODEL_COLUMN_MISC: the auxilary text describing a widget's role
+ * @GLADE_PROJECT_MODEL_COLUMN_WARNING: the support warning text for this widget
* @GLADE_PROJECT_MODEL_ICON_NAME_N_COLUMNS: Number of columns
*
* The tree view columns provided by the GtkTreeModel implemented
@@ -65,6 +66,7 @@ typedef enum
GLADE_PROJECT_MODEL_COLUMN_TYPE_NAME,
GLADE_PROJECT_MODEL_COLUMN_OBJECT,
GLADE_PROJECT_MODEL_COLUMN_MISC,
+ GLADE_PROJECT_MODEL_COLUMN_WARNING,
GLADE_PROJECT_MODEL_N_COLUMNS
} GladeProjectModelColumns;
diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c
index fcbb5cd..2b3d6d9 100644
--- a/gladeui/glade-property.c
+++ b/gladeui/glade-property.c
@@ -274,8 +274,17 @@ glade_property_fix_state (GladeProperty * property)
{
property->priv->state = GLADE_STATE_NORMAL;
- if (!glade_property_original_default (property))
- property->priv->state = GLADE_STATE_CHANGED;
+ /* Properties are 'changed' state if they are not default, or if
+ * they are optional and enabled, optional enabled properties
+ * are saved regardless of default value
+ */
+ if (glade_property_class_optional (property->priv->klass))
+ {
+ if (glade_property_get_enabled (property))
+ property->priv->state |= GLADE_STATE_CHANGED;
+ }
+ else if (!glade_property_original_default (property))
+ property->priv->state |= GLADE_STATE_CHANGED;
if (property->priv->support_warning)
property->priv->state |= GLADE_STATE_UNSUPPORTED;
@@ -294,6 +303,7 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
glade_widget_get_project (property->priv->widget) : NULL;
gboolean changed = FALSE;
GValue old_value = { 0, };
+ gboolean warn_before, warn_after;
#if 0
{
@@ -337,7 +347,6 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
*/
changed = !glade_property_equals_value (property, value);
-
/* Add/Remove references from widget ref stacks here
* (before assigning the value)
*/
@@ -345,6 +354,8 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
glade_property_class_is_object (property->priv->klass))
glade_property_update_prop_refs (property, property->priv->value, value);
+ /* Check pre-changed warning state */
+ warn_before = glade_property_warn_usage (property);
/* Make a copy of the old value */
g_value_init (&old_value, G_VALUE_TYPE (property->priv->value));
@@ -367,6 +378,13 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
0, &old_value, property->priv->value);
glade_project_verify_property (property);
+
+ /* Check post change warning state */
+ warn_after = glade_property_warn_usage (property);
+
+ /* Update owning widget's warning state if need be */
+ if (property->priv->widget != NULL && warn_before != warn_after)
+ glade_widget_verify (property->priv->widget);
}
/* Special case parentless widget properties */
@@ -764,6 +782,7 @@ glade_property_new (GladePropertyClass * klass,
g_value_init (property->priv->value, orig_def->g_type);
g_value_copy (orig_def, property->priv->value);
}
+
return property;
}
@@ -1431,8 +1450,13 @@ void
glade_property_set_support_warning (GladeProperty * property,
gboolean disable, const gchar * reason)
{
+ gboolean warn_before, warn_after;
+
g_return_if_fail (GLADE_IS_PROPERTY (property));
+ /* Check pre-changed warning state */
+ warn_before = glade_property_warn_usage (property);
+
if (property->priv->support_warning)
g_free (property->priv->support_warning);
property->priv->support_warning = g_strdup (reason);
@@ -1447,6 +1471,13 @@ glade_property_set_support_warning (GladeProperty * property,
property->priv->support_warning);
glade_property_fix_state (property);
+
+ /* Check post-changed warning state */
+ warn_after = glade_property_warn_usage (property);
+
+ /* Update owning widget's warning state if need be */
+ if (property->priv->widget != NULL && warn_before != warn_after)
+ glade_widget_verify (property->priv->widget);
}
G_CONST_RETURN gchar *
@@ -1457,6 +1488,16 @@ glade_property_get_support_warning (GladeProperty *property)
return property->priv->support_warning;
}
+gboolean
+glade_property_warn_usage (GladeProperty *property)
+{
+ g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE);
+
+ if (!property->priv->support_warning)
+ return FALSE;
+
+ return ((property->priv->state & GLADE_STATE_CHANGED) != 0);
+}
/**
* glade_property_set_save_always:
@@ -1495,14 +1536,26 @@ glade_property_get_save_always (GladeProperty * property)
void
glade_property_set_enabled (GladeProperty * property, gboolean enabled)
{
+ gboolean warn_before, warn_after;
+
g_return_if_fail (GLADE_IS_PROPERTY (property));
+ /* Check pre-changed warning state */
+ warn_before = glade_property_warn_usage (property);
+
property->priv->enabled = enabled;
if (enabled)
glade_property_sync (property);
glade_property_fix_state (property);
+ /* Check post-changed warning state */
+ warn_after = glade_property_warn_usage (property);
+
+ /* Update owning widget's warning state if need be */
+ if (property->priv->widget != NULL && warn_before != warn_after)
+ glade_widget_verify (property->priv->widget);
+
g_object_notify_by_pspec (G_OBJECT (property), properties[PROP_ENABLED]);
}
diff --git a/gladeui/glade-property.h b/gladeui/glade-property.h
index b69c248..84eab22 100644
--- a/gladeui/glade-property.h
+++ b/gladeui/glade-property.h
@@ -133,6 +133,8 @@ void glade_property_set_support_warning (GladeProperty
const gchar *reason);
G_CONST_RETURN gchar *glade_property_get_support_warning (GladeProperty *property);
+gboolean glade_property_warn_usage (GladeProperty *property);
+
gboolean glade_property_get_sensitive (GladeProperty *property);
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 777a86e..15da3f1 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -335,6 +335,9 @@ glade_widget_add_signal_handler (GladeWidget *widget, const GladeSignal *signal_
g_signal_emit (widget, glade_widget_signals[ADD_SIGNAL_HANDLER], 0, new_signal_handler);
glade_project_verify_signal (widget, new_signal_handler);
+
+ if (glade_signal_get_support_warning (new_signal_handler))
+ glade_widget_verify (widget);
}
/**
@@ -367,8 +370,12 @@ glade_widget_remove_signal_handler (GladeWidget * widget,
if (glade_signal_equal (tmp_signal_handler, signal_handler))
{
g_signal_emit (widget, glade_widget_signals[REMOVE_SIGNAL_HANDLER], 0, tmp_signal_handler);
- g_object_unref (tmp_signal_handler);
g_ptr_array_remove_index (signals, i);
+
+ if (glade_signal_get_support_warning (tmp_signal_handler))
+ glade_widget_verify (widget);
+
+ g_object_unref (tmp_signal_handler);
break;
}
}
@@ -937,6 +944,9 @@ glade_widget_constructor (GType type,
else if (GTK_IS_WIDGET (gwidget->priv->object) == FALSE)
gwidget->priv->visible = TRUE;
+ /* Verify support warnings to start off */
+ glade_widget_verify (gwidget);
+
return ret_obj;
}
@@ -2938,7 +2948,6 @@ glade_widget_pack_property_set_sensitive (GladeWidget * widget,
return FALSE;
}
-
/**
* glade_widget_property_set_enabled:
* @widget: a #GladeWidget
@@ -4596,6 +4605,125 @@ glade_widget_generate_path_name (GladeWidget * widget)
return g_string_free (string, FALSE);
}
+/**
+ * glade_widget_verify:
+ * @widget: A #GladeWidget
+ *
+ * Verify this widget for deprecation and versioning warnings.
+ *
+ * This function will update the widget's support warning.
+ */
+void
+glade_widget_verify (GladeWidget *widget)
+{
+ gchar *warning;
+ GList *warn_properties = NULL;
+ GList *warn_signals = NULL;
+
+ g_return_if_fail (GLADE_IS_WIDGET (widget));
+
+ if (widget->priv->project == NULL)
+ return;
+
+ warning = glade_project_verify_widget_adaptor (widget->priv->project,
+ widget->priv->adaptor,
+ NULL);
+
+ /* If there is already support issues with the adaptor, skip signals
+ * and properties
+ */
+ if (!warning)
+ {
+ GHashTableIter iter;
+ gpointer key, value;
+ GList *l;
+ GString *string = NULL;
+
+ /* Collect signals with warnings on them */
+ g_hash_table_iter_init (&iter, widget->priv->signals);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ GPtrArray *signals = (GPtrArray *)value;
+ gint i;
+
+ for (i = 0; i < signals->len; i++)
+ {
+ GladeSignal *signal = g_ptr_array_index (signals, i);
+
+ if (glade_signal_get_support_warning (signal))
+ warn_signals = g_list_prepend (warn_signals, signal);
+ }
+ }
+
+ /* Collect properties with warnings on them */
+ for (l = widget->priv->properties; l; l = l->next)
+ {
+ GladeProperty *property = l->data;
+
+ if (glade_property_warn_usage (property))
+ warn_properties = g_list_prepend (warn_properties, property);
+ }
+
+ for (l = widget->priv->packing_properties; l; l = l->next)
+ {
+ GladeProperty *property = l->data;
+
+ if (glade_property_warn_usage (property))
+ warn_properties = g_list_prepend (warn_properties, property);
+ }
+
+ if (warn_signals || warn_properties)
+ string = g_string_new (NULL);
+
+ /* Print out property warnings */
+ for (l = warn_properties; l; l = l->next)
+ {
+ GladeProperty *property = l->data;
+ GladePropertyClass *pclass = glade_property_get_class (property);
+
+ if (l->prev == NULL)
+ {
+ if (l->next == NULL)
+ g_string_append (string, _("Property has versioning problems: "));
+ else
+ g_string_append (string, _("Some properties have versioning problems: "));
+ }
+ else
+ g_string_append (string, ", ");
+
+ g_string_append (string, glade_property_class_get_name (pclass));
+ }
+
+ /* New line if printing both */
+ if (warn_signals && warn_properties)
+ g_string_append (string, "\n");
+
+ /* Print out signal warnings */
+ for (l = warn_signals; l; l = l->next)
+ {
+ GladeSignal *signal = l->data;
+
+ if (l->prev == NULL)
+ {
+ if (l->next == NULL)
+ g_string_append (string, _("Signal has versioning problems: "));
+ else
+ g_string_append (string, _("Some signals have versioning problems: "));
+ }
+ else
+ g_string_append (string, ", ");
+
+ g_string_append (string, glade_signal_get_name (signal));
+ }
+
+ if (string)
+ warning = g_string_free (string, FALSE);
+ }
+
+ glade_widget_set_support_warning (widget, warning);
+ g_free (warning);
+}
+
void
glade_widget_set_support_warning (GladeWidget * widget, const gchar * warning)
{
@@ -4605,6 +4733,10 @@ glade_widget_set_support_warning (GladeWidget * widget, const gchar * warning)
g_free (widget->priv->support_warning);
widget->priv->support_warning = g_strdup (warning);
+ if (widget->priv->project &&
+ glade_project_has_object (widget->priv->project, widget->priv->object))
+ glade_project_widget_changed (widget->priv->project, widget);
+
g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SUPPORT_WARNING]);
}
diff --git a/gladeui/glade-widget.h b/gladeui/glade-widget.h
index e44bb5e..44834d4 100644
--- a/gladeui/glade-widget.h
+++ b/gladeui/glade-widget.h
@@ -377,6 +377,7 @@ void glade_widget_push_superuser (void);
void glade_widget_pop_superuser (void);
+void glade_widget_verify (GladeWidget *widget);
void glade_widget_set_support_warning (GladeWidget *widget,
const gchar *warning);
G_CONST_RETURN gchar *glade_widget_support_warning (GladeWidget *widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]