[gnome-initial-setup/youre-welcome: 3/10] Read GNOME version from the official location
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/youre-welcome: 3/10] Read GNOME version from the official location
- Date: Thu, 6 Aug 2020 13:24:14 +0000 (UTC)
commit d5fba0c31bf23d158972e61da06e4c0b88d88e05
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Aug 5 21:12:45 2020 -0400
Read GNOME version from the official location
Read /usr/share/gnome/gnome-version.xml to find the
version number.
.../pages/welcome/gis-welcome-page.c | 141 +++++++++++++++++++++
.../pages/welcome/gis-welcome-page.ui | 10 +-
meson.build | 1 +
3 files changed, 147 insertions(+), 5 deletions(-)
---
diff --git a/gnome-initial-setup/pages/welcome/gis-welcome-page.c
b/gnome-initial-setup/pages/welcome/gis-welcome-page.c
index 540249ef..519b9397 100644
--- a/gnome-initial-setup/pages/welcome/gis-welcome-page.c
+++ b/gnome-initial-setup/pages/welcome/gis-welcome-page.c
@@ -31,6 +31,7 @@
struct _GisWelcomePagePrivate
{
GtkWidget *header;
+ GtkWidget *title;
};
typedef struct _GisWelcomePagePrivate GisWelcomePagePrivate;
@@ -48,6 +49,144 @@ update_welcome_header (GisWelcomePage *page)
g_object_unref (pixbuf);
}
+typedef struct
+{
+ char *major;
+ char *minor;
+ char *micro;
+ char *distributor;
+ char *date;
+ char **current;
+} VersionData;
+
+static void
+version_data_free (VersionData *data)
+{
+ g_free (data->major);
+ g_free (data->minor);
+ g_free (data->micro);
+ g_free (data->distributor);
+ g_free (data->date);
+ g_free (data);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (VersionData, version_data_free);
+
+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)
+ {
+ g_autofree char *stripped = NULL;
+
+ stripped = g_strstrip (g_strdup (text));
+ g_free (*data->current);
+ *data->current = g_strdup (stripped);
+ }
+}
+
+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,
+ };
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GMarkupParseContext) ctx = NULL;
+ g_autofree char *contents = NULL;
+ gsize length;
+ g_autoptr(VersionData) data = 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)
+ {
+ if (strcmp (data->micro, "0") == 0)
+ *version = g_strdup_printf ("%s.%s", data->major, data->minor);
+ else
+ *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);
+
+ return TRUE;
+ }
+
+ return FALSE;
+};
+
+static void
+update_welcome_title (GisWelcomePage *page)
+{
+ GisWelcomePagePrivate *priv = gis_welcome_page_get_instance_private (page);
+ g_autofree char *version = NULL;
+ g_autofree char *text = NULL;
+
+ load_gnome_version (&version, NULL, NULL);
+ text = g_strdup_printf (_("Welcome to GNOME %s !"), version);
+
+ gtk_label_set_label (GTK_LABEL (priv->title), text);
+}
+
static void
gis_welcome_page_constructed (GObject *object)
{
@@ -56,6 +195,7 @@ gis_welcome_page_constructed (GObject *object)
G_OBJECT_CLASS (gis_welcome_page_parent_class)->constructed (object);
update_welcome_header (page);
+ update_welcome_title (page);
gis_page_set_complete (GIS_PAGE (page), TRUE);
gtk_widget_show (GTK_WIDGET (page));
@@ -80,6 +220,7 @@ gis_welcome_page_class_init (GisWelcomePageClass *klass)
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/org/gnome/initial-setup/gis-welcome-page.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisWelcomePage, header);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisWelcomePage, title);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), start_setup);
page_class->page_id = PAGE_ID;
diff --git a/gnome-initial-setup/pages/welcome/gis-welcome-page.ui
b/gnome-initial-setup/pages/welcome/gis-welcome-page.ui
index 3a4a6ee8..2df449f3 100644
--- a/gnome-initial-setup/pages/welcome/gis-welcome-page.ui
+++ b/gnome-initial-setup/pages/welcome/gis-welcome-page.ui
@@ -28,12 +28,12 @@
<property name="valign">center</property>
<property name="spacing">20</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkLabel" id="title">
<property name="visible">True</property>
- <property name="label" translatable="yes">Welcome to GNOME 3.38!</property>
- <attributes>
- <attribute name="scale" value="1.6"/>
- </attributes>
+ <property name="label">Welcome to the latest GNOME!</property>
+ <style>
+ <class name="title-1"/>
+ </style>
</object>
</child>
<child>
diff --git a/meson.build b/meson.build
index 506707d4..9838aa2f 100644
--- a/meson.build
+++ b/meson.build
@@ -23,6 +23,7 @@ conf = configuration_data()
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
conf.set_quoted('GNOMELOCALEDIR', locale_dir)
conf.set_quoted('PKGDATADIR', pkgdata_dir)
+conf.set_quoted('DATADIR', data_dir)
conf.set_quoted('PKGSYSCONFDIR', pkgsysconf_dir)
conf.set('SECRET_API_SUBJECT_TO_CHANGE', true)
conf.set_quoted('G_LOG_DOMAIN', 'InitialSetup')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]