[Xfce4-commits] <xfce4-weather-plugin:master> Apply patch from bug 7956 (migrate to libxfce4ui) Start moving away from weather.com
Colin Leroy
noreply at xfce.org
Wed Nov 16 22:34:01 CET 2011
Updating branch refs/heads/master
to d776b317fd3b6523490ecc2159d693485d69c01c (commit)
from 938e81786dc2022eed61cfb7a65f8e14f10358a2 (commit)
commit d776b317fd3b6523490ecc2159d693485d69c01c
Author: Colin Leroy <colin at marv.colino.net>
Date: Mon Nov 14 23:10:55 2011 +0100
Apply patch from bug 7956 (migrate to libxfce4ui)
Start moving away from weather.com
configure.ac.in | 2 +-
panel-plugin/Makefile.am | 4 +-
panel-plugin/weather-config.c | 51 ++++++++++++----------
panel-plugin/weather-config.h | 3 +-
panel-plugin/weather-search.c | 95 ++++++++++++++++++++++++----------------
panel-plugin/weather-search.h | 5 +-
panel-plugin/weather-summary.c | 2 +-
panel-plugin/weather.c | 34 ++++++++++----
panel-plugin/weather.h | 3 +-
9 files changed, 120 insertions(+), 79 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index 04f466a..d1bb58e 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -59,7 +59,7 @@ dnl ***********************************
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0])
XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.6.0])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.90.2])
-XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.3.90.2])
+XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.7.0])
XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.3.99.1])
XDT_CHECK_PACKAGE([LIBXML], [libxml-2.0], [2.4.0])
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 50fc962..ed06da1 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -33,7 +33,7 @@ xfce4_weather_plugin_SOURCES = \
xfce4_weather_plugin_CFLAGS = \
$(LIBXFCE4PANEL_CFLAGS) \
- $(LIBXFCEGUI4_CFLAGS) \
+ $(LIBXFCE4UI_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBXML_CFLAGS)
@@ -41,7 +41,7 @@ xfce4_weather_plugin_CFLAGS = \
xfce4_weather_plugin_LDADD = \
$(LIBXFCE4PANEL_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
- $(LIBXFCEGUI4_LIBS) \
+ $(LIBXFCE4UI_LIBS) \
$(GTK_LIBS) \
$(LIBXML_LIBS) \
$(LIBRESOLV)
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 3023e11..e38e822 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -20,7 +20,7 @@
#endif
#include <string.h>
-#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4ui/libxfce4ui.h>
#include "weather-parsers.h"
#include "weather-data.h"
@@ -173,14 +173,20 @@ apply_options (xfceweather_dialog *dialog)
else
data->unit = METRIC;
- if (data->location_code)
- g_free (data->location_code);
+ if (data->lat)
+ g_free (data->lat);
+
+ if (data->lon)
+ g_free (data->lon);
if (data->location_name)
g_free (data->location_name);
- data->location_code =
- g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_loc_code)));
+ data->lat =
+ g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_lat)));
+
+ data->lon =
+ g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_lon)));
data->location_name =
g_strdup (gtk_label_get_text (GTK_LABEL (dialog->txt_loc_name)));
@@ -279,19 +285,21 @@ option_i (datas opt)
return -1;
}
-static void auto_locate_cb(const gchar *loc_name, const gchar *loc_code, gpointer user_data)
+static void auto_locate_cb(const gchar *loc_name, const gchar *lat, const gchar *lon, gpointer user_data)
{
xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
- if (loc_code && loc_name) {
- gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code), loc_code);
+ if (lat && lon && loc_name) {
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), lat);
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), lon);
gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), loc_name);
gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE);
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(dialog->txt_loc_name,loc_name);
#endif
} else {
- gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code), "");
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), "");
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), "");
gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), _("Unset"));
gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE);
}
@@ -317,7 +325,8 @@ cb_findlocation (GtkButton *button,
dialog->wd->proxy_port);
if (run_search_dialog (sdialog)) {
- gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code), sdialog->result);
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), sdialog->result_lat);
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), sdialog->result_lon);
gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), sdialog->result_name);
gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE);
#if GTK_CHECK_VERSION(2,12,0)
@@ -377,7 +386,8 @@ create_config_dialog (xfceweather_data *data,
label = gtk_label_new (_("Location:"));
- dialog->txt_loc_code = gtk_entry_new ();
+ dialog->txt_lat = gtk_entry_new ();
+ dialog->txt_lon = gtk_entry_new ();
dialog->txt_loc_name = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
@@ -386,28 +396,23 @@ create_config_dialog (xfceweather_data *data,
#if GTK_CHECK_VERSION(2,12,0)
gtk_label_set_ellipsize (GTK_LABEL(dialog->txt_loc_name), PANGO_ELLIPSIZE_END);
#endif
- if (dialog->wd->location_code != NULL)
- gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_code),
- dialog->wd->location_code);
+ if (dialog->wd->lat != NULL)
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat),
+ dialog->wd->lat);
+ if (dialog->wd->lon != NULL)
+ gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon),
+ dialog->wd->lon);
if (dialog->wd->location_name != NULL)
gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name),
dialog->wd->location_name);
- else if (dialog->wd->weatherdata &&
- get_data (dialog->wd->weatherdata, DNAM) != NULL &&
- strlen (get_data (dialog->wd->weatherdata, DNAM)) > 1)
- gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name),
- get_data (dialog->wd->weatherdata, DNAM));
- else
- gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name),
- dialog->wd->location_code);
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(dialog->txt_loc_name,
gtk_label_get_text(GTK_LABEL(dialog->txt_loc_name)));
#endif
- if (dialog->wd->location_code == NULL) {
+ if (dialog->wd->lat == NULL || dialog->wd->lon == NULL) {
start_auto_locate(dialog);
}
gtk_size_group_add_widget (sg, label);
diff --git a/panel-plugin/weather-config.h b/panel-plugin/weather-config.h
index 90a8318..b5b3f16 100644
--- a/panel-plugin/weather-config.h
+++ b/panel-plugin/weather-config.h
@@ -31,7 +31,8 @@ typedef struct
{
GtkWidget *dialog;
GtkWidget *opt_unit;
- GtkWidget *txt_loc_code;
+ GtkWidget *txt_lat;
+ GtkWidget *txt_lon;
GtkWidget *txt_loc_name;
GtkWidget *txt_proxy_host;
GtkWidget *txt_proxy_port;
diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c
index c43ad15..2b7398e 100644
--- a/panel-plugin/weather-search.c
+++ b/panel-plugin/weather-search.c
@@ -21,7 +21,7 @@
#include <string.h>
-#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4ui/libxfce4ui.h>
#include "weather-parsers.h"
#include "weather-data.h"
@@ -36,13 +36,14 @@
static void
append_result (GtkListStore *mdl,
- gchar *id,
+ gchar *lat,
+ gchar *lon,
gchar *city)
{
GtkTreeIter iter;
gtk_list_store_append (mdl, &iter);
- gtk_list_store_set (mdl, &iter, 0, city, 1, id, -1);
+ gtk_list_store_set (mdl, &iter, 0, city, 1, lat, lon, -1);
}
@@ -79,7 +80,7 @@ cb_searchdone (gboolean succeed,
search_dialog *dialog = (search_dialog *) user_data;
xmlDoc *doc;
xmlNode *cur_node;
- gchar *id, *city;
+ gchar *lat, *lon, *city;
gint found = 0;
GtkTreeIter iter;
GtkTreeSelection *selection;
@@ -106,24 +107,29 @@ cb_searchdone (gboolean succeed,
{
for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
{
- if (NODE_IS_TYPE (cur_node, "loc"))
+ if (NODE_IS_TYPE (cur_node, "place"))
{
- id = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "id");
-
- if (!id)
- continue;
-
- city = DATA (cur_node);
+ lat = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "lat");
+ if (!lat)
+ continue;
+ lon = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "lon");
+ if (!lon) {
+ g_free(lat);
+ continue;
+ }
+ city = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "display_name");
if (!city)
{
- g_free (id);
+ g_free (lat);
+ g_free (lon);
continue;
}
- append_result (dialog->result_mdl, id, city);
+ append_result (dialog->result_mdl, lat, lon, city);
found++;
- g_free (id);
+ g_free (lat);
+ g_free (lon);
g_free (city);
}
}
@@ -177,11 +183,11 @@ search_cb (GtkWidget *widget,
gtk_widget_set_sensitive(dialog->find_button, FALSE);
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog->dialog), GTK_RESPONSE_ACCEPT, FALSE);
- url = g_strdup_printf ("/search/search?where=%s", sane_str);
+ url = g_strdup_printf ("/search?q=%s&format=xml", sane_str);
g_free (sane_str);
gtk_tree_view_column_set_title(dialog->column, _("Searching..."));
- weather_http_receive_data ("xoap.weather.com", url,
+ weather_http_receive_data ("nominatim.openstreetmap.org", url,
dialog->proxy_host, dialog->proxy_port,
cb_searchdone, dialog);
@@ -269,7 +275,7 @@ create_search_dialog (GtkWindow *parent,
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (frame), scroll);
- dialog->result_mdl = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+ dialog->result_mdl = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
dialog->result_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (dialog->result_mdl));
dialog->column = gtk_tree_view_column_new_with_attributes (_("Results"), renderer, "text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->result_list), dialog->column);
@@ -301,7 +307,13 @@ run_search_dialog (search_dialog *dialog)
{
gtk_tree_model_get_value (GTK_TREE_MODEL (dialog->result_mdl),
&iter, 1, &value);
- dialog->result = g_strdup (g_value_get_string (&value));
+ dialog->result_lat = g_strdup (g_value_get_string (&value));
+
+ g_value_unset (&value);
+
+ gtk_tree_model_get_value (GTK_TREE_MODEL (dialog->result_mdl),
+ &iter, 2, &value);
+ dialog->result_lon = g_strdup (g_value_get_string (&value));
g_value_unset (&value);
@@ -321,7 +333,8 @@ run_search_dialog (search_dialog *dialog)
void
free_search_dialog (search_dialog * dialog)
{
- g_free (dialog->result);
+ g_free (dialog->result_lat);
+ g_free (dialog->result_lon);
g_free (dialog->result_name);
g_free (dialog->last_search);
@@ -333,7 +346,7 @@ free_search_dialog (search_dialog * dialog)
typedef struct {
const gchar *proxy_host;
gint proxy_port;
- void (*cb)(const gchar *loc_name, const gchar *loc_code, gpointer user_data);
+ void (*cb)(const gchar *loc_name, const gchar *lat, const gchar *lon, gpointer user_data);
gpointer user_data;
}
geolocation_data;
@@ -347,10 +360,10 @@ cb_geo_searchdone (gboolean succeed,
geolocation_data *data = (geolocation_data *) user_data;
xmlDoc *doc;
xmlNode *cur_node;
- gchar *id, *city;
+ gchar *lat, *lon, *city;
if (!succeed || received == NULL) {
- data->cb(NULL, NULL, data->user_data);
+ data->cb(NULL, NULL, NULL, data->user_data);
g_free(data);
return;
}
@@ -364,7 +377,7 @@ cb_geo_searchdone (gboolean succeed,
g_free (received);
if (!doc) {
- data->cb(NULL, NULL, data->user_data);
+ data->cb(NULL, NULL, NULL, data->user_data);
g_free(data);
return;
}
@@ -375,23 +388,29 @@ cb_geo_searchdone (gboolean succeed,
{
for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
{
- if (NODE_IS_TYPE (cur_node, "loc"))
+ if (NODE_IS_TYPE (cur_node, "place"))
{
- id = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "id");
+ lat = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "lat");
+ if (!lat)
+ continue;
+ lon = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "lon");
+ if (!lon) {
+ g_free(lat);
+ continue;
+ }
- if (!id)
- continue;
-
- city = DATA (cur_node);
+ city = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "display_name");
if (!city)
{
- g_free (id);
+ g_free(lat);
+ g_free(lon);
continue;
}
- data->cb(city, id, data->user_data);
- g_free (id);
+ data->cb(city, lat, lon, data->user_data);
+ g_free (lat);
+ g_free (lon);
g_free (city);
break;
}
@@ -418,7 +437,7 @@ cb_geolocation (gboolean succeed,
gchar *p;
if (!succeed || received == NULL) {
- data->cb(NULL, NULL, data->user_data);
+ data->cb(NULL, NULL, NULL, data->user_data);
g_free(data);
return;
}
@@ -439,7 +458,7 @@ cb_geolocation (gboolean succeed,
g_free (received);
if (!doc) {
- data->cb(NULL, NULL, data->user_data);
+ data->cb(NULL, NULL, NULL, data->user_data);
g_free(data);
return;
}
@@ -496,17 +515,17 @@ cb_geolocation (gboolean succeed,
gchar *url, *sane_str;
if ((sane_str = sanitize_str (full_loc)) == NULL) {
- data->cb(NULL, NULL, data->user_data);
+ data->cb(NULL, NULL, NULL, data->user_data);
g_free(data);
g_free(full_loc);
return;
}
g_free(full_loc);
- url = g_strdup_printf ("/search/search?where=%s", sane_str);
+ url = g_strdup_printf ("/search?q=%s&format=xml", sane_str);
g_free (sane_str);
- weather_http_receive_data ("xoap.weather.com", url,
+ weather_http_receive_data ("nominatim.openstreetmap.org", url,
data->proxy_host, data->proxy_port,
cb_geo_searchdone, data);
g_free(url);
@@ -517,7 +536,7 @@ cb_geolocation (gboolean succeed,
void weather_search_by_ip(
const gchar *proxy_host, gint proxy_port,
- void (*gui_cb)(const gchar *loc_name, const gchar *loc_code, gpointer user_data),
+ void (*gui_cb)(const gchar *loc_name, const gchar *lat, const gchar *lon, gpointer user_data),
gpointer user_data)
{
geolocation_data *data;
diff --git a/panel-plugin/weather-search.h b/panel-plugin/weather-search.h
index 9473e1b..83c40da 100644
--- a/panel-plugin/weather-search.h
+++ b/panel-plugin/weather-search.h
@@ -33,7 +33,8 @@ typedef struct
GtkListStore *result_mdl;
GtkTreeViewColumn *column;
- gchar *result;
+ gchar *result_lat;
+ gchar *result_lon;
gchar *result_name;
gchar *proxy_host;
@@ -48,7 +49,7 @@ search_dialog *create_search_dialog (GtkWindow *, gchar *, gint);
gboolean run_search_dialog (search_dialog * dialog);
void weather_search_by_ip(const gchar *proxy_host, gint proxy_port,
- void (*gui_cb)(const gchar *loc_name, const gchar *loc_code, gpointer user_data),
+ void (*gui_cb)(const gchar *loc_name, const gchar *lat, const gchar *lon, gpointer user_data),
gpointer user_data);
void free_search_dialog (search_dialog * dialog);
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 36eeb14..b584c7d 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -19,7 +19,7 @@
#include <config.h>
#endif
-#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4ui/libxfce4ui.h>
#include "weather-parsers.h"
#include "weather-data.h"
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index cd341aa..cc5aa24 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -23,7 +23,7 @@
#include <sys/stat.h>
#include <libxfce4util/libxfce4util.h>
-#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4ui/libxfce4ui.h>
#include "weather-parsers.h"
#include "weather-data.h"
@@ -368,7 +368,7 @@ update_weatherdata (xfceweather_data *data)
{
gchar *url;
- if (!data->location_code)
+ if (!data->lat || !data->lon)
{
gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
set_icon_error (data);
@@ -378,7 +378,7 @@ update_weatherdata (xfceweather_data *data)
/* build url */
url = g_strdup_printf ("/weather/local/%s?cc=*&dayf=%d&unit=%c&link=xoap&prod=xoap&par=%s&key=%s",
- data->location_code, XML_WEATHER_DAYF_N,
+ "FIXME", XML_WEATHER_DAYF_N,
data->unit == METRIC ? 'm' : 'i',
PARTNER_ID, LICENSE_KEY);
@@ -442,14 +442,24 @@ xfceweather_read_config (XfcePanelPlugin *plugin,
if (!rc)
return;
- value = xfce_rc_read_entry (rc, "loc_code", NULL);
+ value = xfce_rc_read_entry (rc, "lat", NULL);
if (value)
{
- if (data->location_code)
- g_free (data->location_code);
+ if (data->lat)
+ g_free (data->lat);
- data->location_code = g_strdup (value);
+ data->lat = g_strdup (value);
+ }
+
+ value = xfce_rc_read_entry (rc, "lon", NULL);
+
+ if (value)
+ {
+ if (data->lon)
+ g_free (data->lon);
+
+ data->lon = g_strdup (value);
}
value = xfce_rc_read_entry (rc, "loc_name", NULL);
@@ -547,8 +557,11 @@ xfceweather_write_config (XfcePanelPlugin *plugin,
xfce_rc_write_bool_entry (rc, "celcius", (data->unit == METRIC));
- if (data->location_code)
- xfce_rc_write_entry (rc, "loc_code", data->location_code);
+ if (data->lat)
+ xfce_rc_write_entry (rc, "lat", data->lat);
+
+ if (data->lon)
+ xfce_rc_write_entry (rc, "lon", data->lon);
if (data->location_name)
xfce_rc_write_entry (rc, "loc_name", data->location_name);
@@ -898,7 +911,8 @@ xfceweather_free (XfcePanelPlugin *plugin,
#endif
/* Free chars */
- g_free (data->location_code);
+ g_free (data->lat);
+ g_free (data->lon);
g_free (data->location_name);
g_free (data->proxy_host);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 4837208..81b666e 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -49,7 +49,8 @@ typedef struct
GtkOrientation orientation;
gint updatetimeout;
- gchar *location_code;
+ gchar *lat;
+ gchar *lon;
gchar *location_name;
units unit;
More information about the Xfce4-commits
mailing list