[recipes/welcome-dialog: 1/3] Add a function to get release info
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/welcome-dialog: 1/3] Add a function to get release info
- Date: Sun, 7 May 2017 19:26:16 +0000 (UTC)
commit 3b3af25bee051c29e66ce9bfa131360adefd4a05
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 25 20:22:34 2017 -0500
Add a function to get release info
This works by parsing our own appdata.
configure.ac | 2 +-
src/Makefile.am | 10 ++++-
src/gr-appdata.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gr-appdata.h | 36 ++++++++++++++++
src/meson.build | 1 +
5 files changed, 169 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 365b67f..6e7e080 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,11 +139,11 @@ dnl ***********************************************************************
PKG_CHECK_MODULES(RECIPES, [gmodule-2.0
gio-2.0 >= 2.42
gtk+-3.0 >= 3.22
+ appstream-glib
$AUTOAR_DEP
$GSPELL_DEP
$CANBERRA_DEP])
-
LIBGD_INIT([tagged-entry static])
dnl ***********************************************************************
diff --git a/src/Makefile.am b/src/Makefile.am
index cb7c17c..520bd6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ gnome_recipes_CFLAGS = \
$(RECIPES_CFLAGS) \
-DPACKAGE_NAME=\"$(PACKAGE_NAME)\" \
-DPKGDATADIR=\"$(pkgdatadir)\" \
+ -DDATADIR=\"$(datadir)\" \
-DLOCALEDIR=\"$(localedir)\" \
-DCOMMIT_ID=\"$(commitid)\" \
-DLIBGD_INFO=\"$(libgd_info)\" \
@@ -31,6 +32,8 @@ gnome_recipes_SOURCES = \
gr-account.c \
gr-app.h \
gr-app.c \
+ gr-appdata.h \
+ gr-appdata.c \
gr-category-tile.h \
gr-category-tile.c \
gr-chef.h \
@@ -149,7 +152,9 @@ BUILT_SOURCES = \
DISTCLEANFILES = \
ingredients.inc \
no-ingredients.inc \
- segments.inc
+ segments.inc \
+ cuisine.css \
+ news
MAINTAINERCLEANFILES = \
resources-ui.c \
@@ -207,6 +212,9 @@ gr-shell-search-provider-dbus.h gr-shell-search-provider-dbus.c: Makefile.am $(s
cuisine.css: cuisine.css.in
$(AM_V_GEN) sed -e "s|\@pkgdatadir\@|$(pkgdatadir)|" $< > $@
+news:
+ $(AM_V_GEN) $(top_builddir)/tools/get-news
$(top_srcdir)/data/appdata/org.gnome.Recipes.appdata.xml.in $(PACKAGE_VERSION) > $@
+
EXTRA_DIST = \
shell-search-provider-dbus-interfaces.xml \
recipes-ui.gresource.xml \
diff --git a/src/gr-appdata.c b/src/gr-appdata.c
new file mode 100644
index 0000000..3f9df1b
--- /dev/null
+++ b/src/gr-appdata.c
@@ -0,0 +1,122 @@
+/* gr-appdata.c:
+ *
+ * Copyright (C) 2017 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <appstream-glib.h>
+#include <gr-appdata.h>
+
+static void
+release_info_free (gpointer data)
+{
+ ReleaseInfo *ri = data;
+
+ g_free (ri->version);
+ g_date_time_unref (ri->date);
+ g_free (ri->news);
+ g_free (ri);
+}
+
+static int
+version_compare (const char *v1,
+ const char *v2)
+{
+ const char *p1, *p2;
+ char *q;
+ int a1, a2;
+ int i;
+
+ p1 = v1;
+ p2 = v2;
+ for (i = 0; i < 3; i++) {
+ a1 = (int)g_ascii_strtoll (p1, &q, 10);
+ if (q) {
+ if (*q == '.') q++;
+ p1 = (const char *)q;
+ }
+ a2 = (int)g_ascii_strtoll (p2, &q, 10);
+ if (q) {
+ if (*q == '.') q++;
+ p2 = (const char *)q;
+ }
+
+ if (a1 < a2) return -1;
+ if (a1 > a2) return 1;
+ }
+
+ return 0;
+}
+
+static gboolean
+version_between (const char *v,
+ const char *lower,
+ const char *upper)
+{
+ return version_compare (lower, v) <= 0 && version_compare (v, upper) <= 0;
+}
+
+GPtrArray *
+get_release_info (const char *new_version,
+ const char *old_version)
+{
+ GPtrArray *news;
+ g_autoptr(AsApp) app = NULL;
+ GPtrArray *releases = NULL;
+ unsigned int i;
+ g_autofree char *file = NULL;
+ g_autoptr(GError) error = NULL;
+
+ file = g_build_filename (DATADIR, "appdata", "org.gnome.Recipes.appdata.xml", NULL);
+
+ news = g_ptr_array_new_with_free_func (release_info_free);
+
+ app = as_app_new ();
+ if (!as_app_parse_file (app, file, 0, &error)) {
+ g_warning ("Failed to parse %s: %s", file, error->message);
+ return news;
+ }
+
+ releases = as_app_get_releases (app);
+ for (i = 0; i < releases->len; i++) {
+ AsRelease *rel = g_ptr_array_index (releases, i);
+ ReleaseInfo *ri;
+ const char *tmp;
+
+ if (!version_between (as_release_get_version (rel), old_version, new_version))
+ continue;
+
+ ri = g_new0 (ReleaseInfo, 1);
+ g_ptr_array_insert (news, -1, ri);
+
+ ri->version = g_strdup (as_release_get_version (rel));
+
+ if (as_release_get_timestamp (rel) > 0)
+ ri->date = g_date_time_new_from_unix_utc ((gint64) as_release_get_timestamp (rel));
+
+ tmp = as_release_get_description (rel, NULL);
+ if (tmp != NULL)
+ ri->news = as_markup_convert (tmp, AS_MARKUP_CONVERT_FORMAT_SIMPLE, NULL);
+ else {
+ g_warning ("Failed to convert markup in %s", file);
+ }
+ }
+
+ return news;
+}
diff --git a/src/gr-appdata.h b/src/gr-appdata.h
new file mode 100644
index 0000000..c05f04a
--- /dev/null
+++ b/src/gr-appdata.h
@@ -0,0 +1,36 @@
+/* gr-appdata.h:
+ *
+ * Copyright (C) 2017 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+ char *version;
+ GDateTime *date;
+ char *news;
+} ReleaseInfo;
+
+GPtrArray *get_release_info (const char *new_version,
+ const char *old_version);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index af3108a..cd6b4bb 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -57,6 +57,7 @@ src += ['main.c',
'gr-about-dialog.c',
'gr-account.c',
'gr-app.c',
+ 'gr-appdata.c',
'gr-category-tile.c',
'gr-chef.c',
'gr-chef-dialog.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]