Commit 34585f45 authored by Tristan Van Berkom's avatar Tristan Van Berkom

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
parent 19a99a02
...@@ -2797,21 +2797,17 @@ glade_project_verify_project_for_ui (GladeProject *project) ...@@ -2797,21 +2797,17 @@ glade_project_verify_project_for_ui (GladeProject *project)
{ {
GList *list; GList *list;
GladeWidget *widget; GladeWidget *widget;
gchar *warning;
/* Sync displayable info here */ /* Sync displayable info here */
for (list = project->priv->objects; list; list = list->next) for (list = project->priv->objects; list; list = list->next)
{ {
widget = glade_widget_get_from_gobject (list->data); widget = glade_widget_get_from_gobject (list->data);
warning = /* Update the support warnings for widget's properties */
glade_project_verify_widget_adaptor (project, glade_widget_get_adaptor (widget), NULL);
glade_widget_set_support_warning (widget, warning);
if (warning)
g_free (warning);
glade_project_verify_properties (widget); 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) ...@@ -4679,6 +4675,8 @@ glade_project_model_get_column_type (GtkTreeModel *model, gint column)
return G_TYPE_OBJECT; return G_TYPE_OBJECT;
case GLADE_PROJECT_MODEL_COLUMN_MISC: case GLADE_PROJECT_MODEL_COLUMN_MISC:
return G_TYPE_STRING; return G_TYPE_STRING;
case GLADE_PROJECT_MODEL_COLUMN_WARNING:
return G_TYPE_STRING;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
return G_TYPE_NONE; return G_TYPE_NONE;
...@@ -4841,6 +4839,10 @@ glade_project_model_get_value (GtkTreeModel *model, ...@@ -4841,6 +4839,10 @@ glade_project_model_get_value (GtkTreeModel *model,
g_value_take_string (value, str); g_value_take_string (value, str);
break; break;
case GLADE_PROJECT_MODEL_COLUMN_WARNING:
g_value_set_string (value, glade_widget_support_warning (widget));
break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
} }
......
...@@ -52,6 +52,7 @@ typedef enum ...@@ -52,6 +52,7 @@ typedef enum
* @GLADE_PROJECT_MODEL_COLUMN_TYPE_NAME: The type name of the widget * @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_OBJECT: the GObject of the widget
* @GLADE_PROJECT_MODEL_COLUMN_MISC: the auxilary text describing a widget's role * @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 * @GLADE_PROJECT_MODEL_ICON_NAME_N_COLUMNS: Number of columns
* *
* The tree view columns provided by the GtkTreeModel implemented * The tree view columns provided by the GtkTreeModel implemented
...@@ -65,6 +66,7 @@ typedef enum ...@@ -65,6 +66,7 @@ typedef enum
GLADE_PROJECT_MODEL_COLUMN_TYPE_NAME, GLADE_PROJECT_MODEL_COLUMN_TYPE_NAME,
GLADE_PROJECT_MODEL_COLUMN_OBJECT, GLADE_PROJECT_MODEL_COLUMN_OBJECT,
GLADE_PROJECT_MODEL_COLUMN_MISC, GLADE_PROJECT_MODEL_COLUMN_MISC,
GLADE_PROJECT_MODEL_COLUMN_WARNING,
GLADE_PROJECT_MODEL_N_COLUMNS GLADE_PROJECT_MODEL_N_COLUMNS
} GladeProjectModelColumns; } GladeProjectModelColumns;
......
...@@ -274,8 +274,17 @@ glade_property_fix_state (GladeProperty * property) ...@@ -274,8 +274,17 @@ glade_property_fix_state (GladeProperty * property)
{ {
property->priv->state = GLADE_STATE_NORMAL; property->priv->state = GLADE_STATE_NORMAL;
if (!glade_property_original_default (property)) /* Properties are 'changed' state if they are not default, or if
property->priv->state = GLADE_STATE_CHANGED; * 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) if (property->priv->support_warning)
property->priv->state |= GLADE_STATE_UNSUPPORTED; property->priv->state |= GLADE_STATE_UNSUPPORTED;
...@@ -294,6 +303,7 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value) ...@@ -294,6 +303,7 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
glade_widget_get_project (property->priv->widget) : NULL; glade_widget_get_project (property->priv->widget) : NULL;
gboolean changed = FALSE; gboolean changed = FALSE;
GValue old_value = { 0, }; GValue old_value = { 0, };
gboolean warn_before, warn_after;
#if 0 #if 0
{ {
...@@ -337,7 +347,6 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value) ...@@ -337,7 +347,6 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
*/ */
changed = !glade_property_equals_value (property, value); changed = !glade_property_equals_value (property, value);
/* Add/Remove references from widget ref stacks here /* Add/Remove references from widget ref stacks here
* (before assigning the value) * (before assigning the value)
*/ */
...@@ -345,6 +354,8 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * 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_class_is_object (property->priv->klass))
glade_property_update_prop_refs (property, property->priv->value, value); 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 */ /* Make a copy of the old value */
g_value_init (&old_value, G_VALUE_TYPE (property->priv->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) ...@@ -367,6 +378,13 @@ glade_property_set_value_impl (GladeProperty * property, const GValue * value)
0, &old_value, property->priv->value); 0, &old_value, property->priv->value);
glade_project_verify_property (property); 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 */ /* Special case parentless widget properties */
...@@ -764,6 +782,7 @@ glade_property_new (GladePropertyClass * klass, ...@@ -764,6 +782,7 @@ glade_property_new (GladePropertyClass * klass,
g_value_init (property->priv->value, orig_def->g_type); g_value_init (property->priv->value, orig_def->g_type);
g_value_copy (orig_def, property->priv->value); g_value_copy (orig_def, property->priv->value);
} }
return property; return property;
} }
...@@ -1431,8 +1450,13 @@ void ...@@ -1431,8 +1450,13 @@ void
glade_property_set_support_warning (GladeProperty * property, glade_property_set_support_warning (GladeProperty * property,
gboolean disable, const gchar * reason) gboolean disable, const gchar * reason)
{ {
gboolean warn_before, warn_after;
g_return_if_fail (GLADE_IS_PROPERTY (property)); 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) if (property->priv->support_warning)
g_free (property->priv->support_warning); g_free (property->priv->support_warning);
property->priv->support_warning = g_strdup (reason); property->priv->support_warning = g_strdup (reason);
...@@ -1447,6 +1471,13 @@ glade_property_set_support_warning (GladeProperty * property, ...@@ -1447,6 +1471,13 @@ glade_property_set_support_warning (GladeProperty * property,
property->priv->support_warning); property->priv->support_warning);
glade_property_fix_state (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_CONST_RETURN gchar * G_CONST_RETURN gchar *
...@@ -1457,6 +1488,16 @@ glade_property_get_support_warning (GladeProperty *property) ...@@ -1457,6 +1488,16 @@ glade_property_get_support_warning (GladeProperty *property)
return property->priv->support_warning; 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: * glade_property_set_save_always:
...@@ -1495,14 +1536,26 @@ glade_property_get_save_always (GladeProperty * property) ...@@ -1495,14 +1536,26 @@ glade_property_get_save_always (GladeProperty * property)
void void
glade_property_set_enabled (GladeProperty * property, gboolean enabled) glade_property_set_enabled (GladeProperty * property, gboolean enabled)
{ {
gboolean warn_before, warn_after;
g_return_if_fail (GLADE_IS_PROPERTY (property)); g_return_if_fail (GLADE_IS_PROPERTY (property));
/* Check pre-changed warning state */
warn_before = glade_property_warn_usage (property);
property->priv->enabled = enabled; property->priv->enabled = enabled;
if (enabled) if (enabled)
glade_property_sync (property); glade_property_sync (property);
glade_property_fix_state (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]); g_object_notify_by_pspec (G_OBJECT (property), properties[PROP_ENABLED]);
} }
......
...@@ -133,6 +133,8 @@ void glade_property_set_support_warning (GladeProperty ...@@ -133,6 +133,8 @@ void glade_property_set_support_warning (GladeProperty
const gchar *reason); const gchar *reason);
G_CONST_RETURN gchar *glade_property_get_support_warning (GladeProperty *property); 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); gboolean glade_property_get_sensitive (GladeProperty *property);
......
...@@ -335,6 +335,9 @@ glade_widget_add_signal_handler (GladeWidget *widget, const GladeSignal *signal_ ...@@ -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); g_signal_emit (widget, glade_widget_signals[ADD_SIGNAL_HANDLER], 0, new_signal_handler);
glade_project_verify_signal (widget, 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, ...@@ -367,8 +370,12 @@ glade_widget_remove_signal_handler (GladeWidget * widget,
if (glade_signal_equal (tmp_signal_handler, signal_handler)) if (glade_signal_equal (tmp_signal_handler, signal_handler))
{ {
g_signal_emit (widget, glade_widget_signals[REMOVE_SIGNAL_HANDLER], 0, tmp_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); 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; break;
} }
} }
...@@ -937,6 +944,9 @@ glade_widget_constructor (GType type, ...@@ -937,6 +944,9 @@ glade_widget_constructor (GType type,
else if (GTK_IS_WIDGET (gwidget->priv->object) == FALSE) else if (GTK_IS_WIDGET (gwidget->priv->object) == FALSE)
gwidget->priv->visible = TRUE; gwidget->priv->visible = TRUE;
/* Verify support warnings to start off */
glade_widget_verify (gwidget);
return ret_obj; return ret_obj;
} }
...@@ -2938,7 +2948,6 @@ glade_widget_pack_property_set_sensitive (GladeWidget * widget, ...@@ -2938,7 +2948,6 @@ glade_widget_pack_property_set_sensitive (GladeWidget * widget,
return FALSE; return FALSE;
} }
/** /**
* glade_widget_property_set_enabled: * glade_widget_property_set_enabled:
* @widget: a #GladeWidget * @widget: a #GladeWidget
...@@ -4596,6 +4605,125 @@ glade_widget_generate_path_name (GladeWidget * widget) ...@@ -4596,6 +4605,125 @@ glade_widget_generate_path_name (GladeWidget * widget)
return g_string_free (string, FALSE); 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 void
glade_widget_set_support_warning (GladeWidget * widget, const gchar * warning) glade_widget_set_support_warning (GladeWidget * widget, const gchar * warning)
{ {
...@@ -4605,6 +4733,10 @@ 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); g_free (widget->priv->support_warning);
widget->priv->support_warning = g_strdup (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]); g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SUPPORT_WARNING]);
} }
......
...@@ -377,6 +377,7 @@ void glade_widget_push_superuser (void); ...@@ -377,6 +377,7 @@ void glade_widget_push_superuser (void);
void glade_widget_pop_superuser (void); void glade_widget_pop_superuser (void);
void glade_widget_verify (GladeWidget *widget);
void glade_widget_set_support_warning (GladeWidget *widget, void glade_widget_set_support_warning (GladeWidget *widget,
const gchar *warning); const gchar *warning);
G_CONST_RETURN gchar *glade_widget_support_warning (GladeWidget *widget); G_CONST_RETURN gchar *glade_widget_support_warning (GladeWidget *widget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment