Commit f3a2a088 authored by William Jon McCann's avatar William Jon McCann

info: read version info from gnome-version.xml

parent 19eae111
......@@ -4,6 +4,7 @@ INCLUDES = \
-DGNOMECC_UI_DIR="\"$(uidir)\"" \
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
-DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
-DDATADIR="\"$(datadir)\"" \
$(NULL)
ccpanelsdir = $(PANELS_DIR)
......
......@@ -31,14 +31,130 @@ G_DEFINE_DYNAMIC_TYPE (CcInfoPanel, cc_info_panel, CC_TYPE_PANEL)
struct _CcInfoPanelPrivate
{
GtkBuilder *builder;
char *gnome_version;
char *gnome_distributor;
char *gnome_date;
};
typedef struct
{
char *major;
char *minor;
char *micro;
char *distributor;
char *date;
char **current;
} VersionData;
static void
version_start_element_handler (GMarkupParseContext *ctx,
const char *element_name,
const char **attr_names,
const char **attr_values,
gpointer user_data,
GError **error)
{
VersionData *data = user_data;
if (g_str_equal (element_name, "platform"))
data->current = &data->major;
else if (g_str_equal (element_name, "minor"))
data->current = &data->minor;
else if (g_str_equal (element_name, "micro"))
data->current = &data->micro;
else if (g_str_equal (element_name, "distributor"))
data->current = &data->distributor;
else if (g_str_equal (element_name, "date"))
data->current = &data->date;
else
data->current = NULL;
}
static void
version_end_element_handler (GMarkupParseContext *ctx,
const char *element_name,
gpointer user_data,
GError **error)
{
VersionData *data = user_data;
data->current = NULL;
}
static void
version_text_handler (GMarkupParseContext *ctx,
const char *text,
gsize text_len,
gpointer user_data,
GError **error)
{
VersionData *data = user_data;
if (data->current != NULL)
*data->current = g_strstrip (g_strdup (text));
}
static gboolean
load_gnome_version (char **version,
char **distributor,
char **date)
{
GMarkupParser version_parser = {
version_start_element_handler,
version_end_element_handler,
version_text_handler,
NULL,
NULL,
};
GError *error;
GMarkupParseContext *ctx;
char *contents;
gsize length;
VersionData *data;
gboolean ret;
ret = FALSE;
error = NULL;
if (!g_file_get_contents (DATADIR "/gnome/gnome-version.xml",
&contents,
&length,
&error))
return FALSE;
data = g_new0 (VersionData, 1);
ctx = g_markup_parse_context_new (&version_parser, 0, data, NULL);
if (!g_markup_parse_context_parse (ctx, contents, length, &error))
{
g_warning ("Invalid version file: '%s'", error->message);
}
else
{
if (version != NULL)
*version = g_strdup_printf ("%s.%s.%s", data->major, data->minor, data->micro);
if (distributor != NULL)
*distributor = g_strdup (data->distributor);
if (date != NULL)
*date = g_strdup (data->date);
ret = TRUE;
}
g_markup_parse_context_free (ctx);
g_free (data->major);
g_free (data->minor);
g_free (data->micro);
g_free (data->distributor);
g_free (data->date);
g_free (data);
g_free (contents);
return ret;
};
static void
cc_info_panel_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
......@@ -49,9 +165,9 @@ cc_info_panel_get_property (GObject *object,
static void
cc_info_panel_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
......@@ -77,6 +193,11 @@ cc_info_panel_dispose (GObject *object)
static void
cc_info_panel_finalize (GObject *object)
{
CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv;
g_free (priv->gnome_version);
g_free (priv->gnome_date);
g_free (priv->gnome_distributor);
G_OBJECT_CLASS (cc_info_panel_parent_class)->finalize (object);
}
......@@ -104,6 +225,7 @@ cc_info_panel_init (CcInfoPanel *self)
{
GError *error;
GtkWidget *widget;
gboolean res;
self->priv = INFO_PANEL_PRIVATE (self);
......@@ -121,7 +243,17 @@ cc_info_panel_init (CcInfoPanel *self)
return;
}
res = load_gnome_version (&self->priv->gnome_version,
&self->priv->gnome_distributor,
&self->priv->gnome_date);
if (res)
{
char *text;
widget = WID (self->priv->builder, "version_label");
text = g_strdup_printf ("Version %s", self->priv->gnome_version);
gtk_label_set_text (GTK_LABEL (widget), text);
g_free (text);
}
widget = WID (self->priv->builder, "info_vbox");
gtk_widget_reparent (widget, (GtkWidget *) self);
......
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