[gnome-panel/features/merge-gnome-applets: 2/3] Update applets which uses libgweather 1. Update clock applet. 2. Fix gweather applet building. 3. Re



commit 5077c13bfc8bf4e9896b7e5ab8ea495bedc1c5ee
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun May 25 21:04:20 2014 +0300

    Update applets which uses libgweather
    1. Update clock applet.
    2. Fix gweather applet building.
    3. Require libgweather 3.9.5 or newer.

 applets/clock/clock-location.c   |    4 -
 applets/clock/clock.c            |    2 +-
 applets/gweather/Makefile.am     |    1 +
 applets/gweather/gweather-pref.c |    2 +-
 applets/gweather/gweather-xml.c  |  164 ++++++++++++++++++++++++++++++++++++++
 applets/gweather/gweather-xml.h  |   39 +++++++++
 configure.ac                     |    9 +--
 7 files changed, 208 insertions(+), 13 deletions(-)
---
diff --git a/applets/clock/clock-location.c b/applets/clock/clock-location.c
index 9e263b4..d2d0e58 100644
--- a/applets/clock/clock-location.c
+++ b/applets/clock/clock-location.c
@@ -541,11 +541,7 @@ setup_weather_updates (ClockLocation *loc)
                priv->weather_timeout = 0;
        }
 
-#ifdef HAVE_GWEATHER_3_9_2_OR_NEWER
        priv->weather_info = gweather_info_new (priv->loc, GWEATHER_FORECAST_LIST);
-#else
-       priv->weather_info = gweather_info_new_for_world (priv->world, priv->loc, GWEATHER_FORECAST_LIST);
-#endif
 
        g_signal_connect (priv->weather_info, "updated",
                          G_CALLBACK (weather_info_updated), loc);
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index d027916..89ae892 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -1325,7 +1325,7 @@ fill_clock_applet (PanelApplet *applet)
 
        cd->applet = GTK_WIDGET (applet);
 
-        cd->world = gweather_location_new_world (FALSE);
+        cd->world = gweather_location_get_world ();
         load_cities (cd);
         locations_changed (NULL, NULL, cd);
 
diff --git a/applets/gweather/Makefile.am b/applets/gweather/Makefile.am
index de5cd31..91643c2 100644
--- a/applets/gweather/Makefile.am
+++ b/applets/gweather/Makefile.am
@@ -21,6 +21,7 @@ libexec_PROGRAMS = gweather-applet-2
 gweather_applet_2_SOURCES = \
        gweather.h \
        main.c \
+       gweather-xml.c gweather-xml.h \
        gweather-about.c gweather-about.h \
        gweather-pref.c gweather-pref.h \
        gweather-dialog.c gweather-dialog.h \
diff --git a/applets/gweather/gweather-pref.c b/applets/gweather/gweather-pref.c
index 23dd571..738d3b2 100644
--- a/applets/gweather/gweather-pref.c
+++ b/applets/gweather/gweather-pref.c
@@ -29,7 +29,7 @@
 
 #define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
 
-#include <libgweather/gweather-xml.h>
+#include "gweather-xml.h"
 #include "gweather.h"
 #include "gweather-pref.h"
 #include "gweather-applet.h"
diff --git a/applets/gweather/gweather-xml.c b/applets/gweather/gweather-xml.c
new file mode 100644
index 0000000..a429e8c
--- /dev/null
+++ b/applets/gweather/gweather-xml.c
@@ -0,0 +1,164 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* gweather-xml.c - Locations.xml parsing code
+ *
+ * Copyright (C) 2005 Ryan Lortie, 2004 Gareth Owen
+ *
+ * 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 2 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <math.h>
+#include <locale.h>
+#include <gtk/gtk.h>
+#include <libxml/xmlreader.h>
+
+#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
+#include "gweather-xml.h"
+
+
+/**
+ * SECTION:gweather-xml
+ * @Title: gweather-xml
+ */
+
+
+static gboolean
+gweather_xml_parse_node (GWeatherLocation *gloc,
+                        GtkTreeStore *store, GtkTreeIter *parent)
+{
+    GtkTreeIter iter, *self = &iter;
+    GWeatherLocation **children, *parent_loc;
+    GWeatherLocationLevel level;
+    const char *name;
+    int i;
+
+    name = gweather_location_get_name (gloc);
+    children = gweather_location_get_children (gloc);
+    level = gweather_location_get_level (gloc);
+
+    if (!children[0] && level < GWEATHER_LOCATION_WEATHER_STATION) {
+       return TRUE;
+    }
+
+    switch (gweather_location_get_level (gloc)) {
+    case GWEATHER_LOCATION_WORLD:
+    case GWEATHER_LOCATION_ADM2:
+       self = parent;
+       break;
+
+    case GWEATHER_LOCATION_REGION:
+    case GWEATHER_LOCATION_COUNTRY:
+    case GWEATHER_LOCATION_ADM1:
+       /* Create a row with a name but no WeatherLocation */
+       gtk_tree_store_append (store, &iter, parent);
+       gtk_tree_store_set (store, &iter,
+                           GWEATHER_XML_COL_LOCATION_NAME, name,
+                           -1);
+       break;
+
+    case GWEATHER_LOCATION_CITY:
+       /* If multiple children, treat this like a
+        * region/country/adm1. If a single child, merge with that
+        * location.
+        */
+       gtk_tree_store_append (store, &iter, parent);
+       gtk_tree_store_set (store, &iter,
+                           GWEATHER_XML_COL_LOCATION_NAME, name,
+                           -1);
+       if (children[0] && !children[1]) {
+               const char *code = NULL;
+               gboolean has_coords = FALSE;
+               double latitude = 0;
+               double longitude = 0;
+               
+               code = gweather_location_get_code (children[0]);
+               has_coords = gweather_location_has_coords (children[0]);
+               if (has_coords) {
+                       gweather_location_get_coords (children[0], &latitude, &longitude);
+               }
+
+               gtk_tree_store_set (store, &iter,
+                                   GWEATHER_XML_COL_METAR_CODE, code,
+                                   GWEATHER_XML_COL_LATLON_VALID, has_coords,
+                                   GWEATHER_XML_COL_LATITUDE, latitude,
+                                   GWEATHER_XML_COL_LONGITUDE, longitude,
+                                   -1);
+       }
+       break;
+
+    case GWEATHER_LOCATION_WEATHER_STATION:
+       gtk_tree_store_append (store, &iter, parent);
+       gtk_tree_store_set (store, &iter,
+                           GWEATHER_XML_COL_LOCATION_NAME, name,
+                           -1);
+
+       parent_loc = gweather_location_get_parent (gloc);
+       if (parent_loc && gweather_location_get_level (parent_loc) == GWEATHER_LOCATION_CITY)
+           name = gweather_location_get_name (parent_loc);
+       
+       const char *code = NULL;
+       gboolean has_coords = FALSE;
+       double latitude = 0;
+       double longitude = 0;
+       
+       code = gweather_location_get_code (gloc);
+       has_coords = gweather_location_has_coords (gloc);
+       if (has_coords) {
+               gweather_location_get_coords (gloc, &latitude, &longitude);
+       }
+
+       gtk_tree_store_set (store, &iter,
+                           GWEATHER_XML_COL_METAR_CODE, code,
+                           GWEATHER_XML_COL_LATLON_VALID, has_coords,
+                           GWEATHER_XML_COL_LATITUDE, latitude,
+                           GWEATHER_XML_COL_LONGITUDE, longitude,
+                           -1);
+       break;
+    }
+
+    for (i = 0; children[i]; i++) {
+       if (!gweather_xml_parse_node (children[i], store, self)) {
+           return FALSE;
+       }
+    }
+
+    return TRUE;
+}
+
+GtkTreeModel *
+gweather_xml_load_locations (void)
+{
+    GWeatherLocation *world;
+    GtkTreeStore *store;
+
+    world = gweather_location_get_world ();
+    if (!world)
+       return NULL;
+
+    store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_DOUBLE, 
G_TYPE_DOUBLE);
+
+    if (!gweather_xml_parse_node (world, store, NULL)) {
+       g_object_unref (store);
+       store = NULL;
+    }
+
+    gweather_location_unref (world);
+
+    return (GtkTreeModel *)store;
+}
diff --git a/applets/gweather/gweather-xml.h b/applets/gweather/gweather-xml.h
new file mode 100644
index 0000000..b5679c4
--- /dev/null
+++ b/applets/gweather/gweather-xml.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* gweather-xml.h
+ *
+ * Copyright (C) 2004 Gareth Owen
+ *
+ * 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 2 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/>.
+ */
+
+#ifndef __GWEATHER_XML_H__
+#define __GWEATHER_XML_H__
+
+#include <gtk/gtk.h>
+#include <libgweather/gweather-weather.h>
+
+enum
+{
+    GWEATHER_XML_COL_LOCATION_NAME = 0,
+    GWEATHER_XML_COL_METAR_CODE,
+    GWEATHER_XML_COL_LATLON_VALID,
+    GWEATHER_XML_COL_LATITUDE,
+    GWEATHER_XML_COL_LONGITUDE,
+    GWEATHER_XML_NUM_COLUMNS
+};
+
+GtkTreeModel *gweather_xml_load_locations (void);
+
+#endif /* __GWEATHER_XML_H__ */
diff --git a/configure.ac b/configure.ac
index 025c8a0..b4f614b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,7 +118,7 @@ TELEPATHY_GLIB_REQUIRED=0.14.0
 LIBECAL_REQUIRED=3.5.3
 LIBEDATASERVER_REQUIRED=3.5.3
 CAIRO_REQUIRED=1.0.0
-GWEATHER_REQUIRED=3.5.1
+GWEATHER_REQUIRED=3.9.5
 DBUS_GLIB_REQUIRED=0.80
 DCONF_REQUIRED=0.13.4
 LIBRSVG_REQUIRED=2.36.2
@@ -192,11 +192,6 @@ PKG_CHECK_MODULES(CLOCK, pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib
 AC_SUBST(CLOCK_CFLAGS)
 AC_SUBST(CLOCK_LIBS)
 
-PKG_CHECK_MODULES(GWEATHER, gweather-3.0 >= 3.9.2, HAVE_GWEATHER_3_9_2_OR_NEWER=yes, 
HAVE_GWEATHER_3_9_2_OR_NEWER=no)
-if test "x$HAVE_GWEATHER_3_9_2_OR_NEWER" = "xyes" ; then
-    AC_DEFINE(HAVE_GWEATHER_3_9_2_OR_NEWER, 1, [Defined if Gweather version is 3.9.2 or newer])
-fi
-
 # Check whether to enable e-d-s support for clock applet
 AC_MSG_CHECKING([whether to enable evolution-data-server support])
 AC_ARG_ENABLE([eds],
@@ -461,7 +456,7 @@ AC_SUBST(XML2_LIBS)
 
  dnl -- check for libgweather (required for gweather applet) ------------------
 build_libgweather_applets=false
-PKG_CHECK_MODULES(LIBGWEATHER, gweather-3.0 >= $GWEATHER_REQUIRED gweather-3.0 <= 3.7,
+PKG_CHECK_MODULES(LIBGWEATHER, gweather-3.0 >= $GWEATHER_REQUIRED,
                  build_libgweather_applets=true,
                  AC_MSG_WARN([libgweather not found. Not building the weather applet.]))
 AC_SUBST(LIBGWEATHER_CFLAGS)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]