diff options
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | modules/Makefile.am | 5 | ||||
-rw-r--r-- | modules/cal-config-weather/Makefile.am | 28 | ||||
-rw-r--r-- | modules/cal-config-weather/e-source-weather.c | 252 | ||||
-rw-r--r-- | modules/cal-config-weather/e-source-weather.h | 83 | ||||
-rw-r--r-- | modules/cal-config-weather/evolution-cal-config-weather.c | 309 | ||||
-rw-r--r-- | plugins/calendar-weather/Makefile.am | 34 | ||||
-rw-r--r-- | plugins/calendar-weather/calendar-weather.c | 520 | ||||
-rw-r--r-- | plugins/calendar-weather/org-gnome-calendar-weather.eplug.xml | 34 |
9 files changed, 682 insertions, 594 deletions
diff --git a/configure.ac b/configure.ac index 6424e769f9..148b6895dd 100644 --- a/configure.ac +++ b/configure.ac @@ -1301,7 +1301,7 @@ dnl Add any new plugins here plugins_base_always="calendar-http itip-formatter default-source mark-all-read publish-calendar imap-features" plugins_base="$plugins_base_always" -dist_plugins_base="$plugins_base_always calendar-weather" +dist_plugins_base="$plugins_base_always" plugins_standard_always="bbdb save-calendar mail-to-task mailing-list-actions prefer-plain mail-notification attachment-reminder email-custom-header face templates vcard-inline dbx-import external-editor" @@ -1352,10 +1352,8 @@ if test "x$enable_weather" != "xno"; then AC_SUBST(GWEATHER_CFLAGS) AC_SUBST(GWEATHER_LIBS) - if test "x$have_weather" = "xyes"; then - plugins_base="$plugins_base calendar-weather" - else - AC_MSG_ERROR([gweather-3.0 >= gweather_minimum_version is required for configuring weather calendars. Use --disable-weather to disable this features.]) + if test "x$have_weather" = "xno"; then + AC_MSG_ERROR([gweather-3.0 >= gweather_minimum_version is required for configuring weather calendars. Use --disable-weather to disable this feature.]) fi dnl gweather-3.5 introduces API changes we do not yet support. @@ -1363,6 +1361,7 @@ if test "x$enable_weather" != "xno"; then AC_MSG_ERROR([gweather-3.5 is not yet supported. Install gweather-3.4 or specify --disable-weather as a configure option to exclude the calendar-weather plugin.]) fi fi +AM_CONDITIONAL(ENABLE_WEATHER, [test "x$enable_weather" != "xno"]) dnl ******************************************************************** dnl maps in contacts preview requires champlain-gtk, geoclue and clutter @@ -1641,6 +1640,7 @@ modules/cal-config-caldav/Makefile modules/cal-config-contacts/Makefile modules/cal-config-google/Makefile modules/cal-config-local/Makefile +modules/cal-config-weather/Makefile modules/composer-autosave/Makefile modules/mailto-handler/Makefile modules/mdn/Makefile @@ -1658,7 +1658,6 @@ plugins/attachment-reminder/Makefile plugins/audio-inline/Makefile plugins/bbdb/Makefile plugins/calendar-http/Makefile -plugins/calendar-weather/Makefile plugins/dbx-import/Makefile plugins/default-source/Makefile plugins/email-custom-header/Makefile diff --git a/modules/Makefile.am b/modules/Makefile.am index 00754d8491..0f1f6b5a93 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -2,6 +2,10 @@ if ENABLE_LDAP CONFIG_LDAP_DIR = book-config-ldap endif +if ENABLE_WEATHER +CONFIG_WEATHER_DIR = cal-config-weather +endif + if ENABLE_MONO MONO_DIR = plugin-mono endif @@ -28,6 +32,7 @@ SUBDIRS = \ cal-config-contacts \ cal-config-google \ cal-config-local \ + $(CONFIG_WEATHER_DIR) \ composer-autosave \ mailto-handler \ mdn \ diff --git a/modules/cal-config-weather/Makefile.am b/modules/cal-config-weather/Makefile.am new file mode 100644 index 0000000000..54b6d1e0e0 --- /dev/null +++ b/modules/cal-config-weather/Makefile.am @@ -0,0 +1,28 @@ +module_LTLIBRARIES = module-cal-config-weather.la + +module_cal_config_weather_la_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/widgets \ + -DG_LOG_DOMAIN=\"evolution-cal-config-weather\" \ + $(EVOLUTION_DATA_SERVER_CFLAGS) \ + $(GNOME_PLATFORM_CFLAGS) \ + $(GWEATHER_CFLAGS) + +module_cal_config_weather_la_SOURCES = \ + evolution-cal-config-weather.c \ + e-source-weather.c \ + e-source-weather.h + +module_cal_config_weather_la_LIBADD = \ + $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/widgets/misc/libemiscwidgets.la \ + $(top_builddir)/calendar/gui/libevolution-calendar.la \ + $(EVOLUTION_DATA_SERVER_LIBS) \ + $(GNOME_PLATFORM_LIBS) \ + $(GWEATHER_LIBS) + +module_cal_config_weather_la_LDFLAGS = \ + -module -avoid-version $(NO_UNDEFINED) + +-include $(top_srcdir)/git.mk diff --git a/modules/cal-config-weather/e-source-weather.c b/modules/cal-config-weather/e-source-weather.c new file mode 100644 index 0000000000..0f7e581ce8 --- /dev/null +++ b/modules/cal-config-weather/e-source-weather.c @@ -0,0 +1,252 @@ +/* + * e-source-weather.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <webcal://www.gnu.org/licenses/> + * + */ + +#include "e-source-weather.h" + +#include <libedataserver/e-data-server-util.h> + +#define E_SOURCE_WEATHER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_SOURCE_WEATHER, ESourceWeatherPrivate)) + +struct _ESourceWeatherPrivate { + GMutex *property_lock; + ESourceWeatherUnits units; + gchar *location; +}; + +enum { + PROP_0, + PROP_LOCATION, + PROP_UNITS +}; + +static GType e_source_weather_units_type = G_TYPE_INVALID; + +G_DEFINE_DYNAMIC_TYPE ( + ESourceWeather, + e_source_weather, + E_TYPE_SOURCE_EXTENSION) + +static void +source_weather_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_LOCATION: + e_source_weather_set_location ( + E_SOURCE_WEATHER (object), + g_value_get_string (value)); + return; + + case PROP_UNITS: + e_source_weather_set_units ( + E_SOURCE_WEATHER (object), + g_value_get_enum (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +source_weather_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_LOCATION: + g_value_take_string ( + value, + e_source_weather_dup_location ( + E_SOURCE_WEATHER (object))); + return; + + case PROP_UNITS: + g_value_set_enum ( + value, + e_source_weather_get_units ( + E_SOURCE_WEATHER (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +source_weather_finalize (GObject *object) +{ + ESourceWeatherPrivate *priv; + + priv = E_SOURCE_WEATHER_GET_PRIVATE (object); + + g_mutex_free (priv->property_lock); + + g_free (priv->location); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (e_source_weather_parent_class)->finalize (object); +} + +static void +e_source_weather_class_init (ESourceWeatherClass *class) +{ + GObjectClass *object_class; + ESourceExtensionClass *extension_class; + + g_type_class_add_private (class, sizeof (ESourceWeatherPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = source_weather_set_property; + object_class->get_property = source_weather_get_property; + object_class->finalize = source_weather_finalize; + + extension_class = E_SOURCE_EXTENSION_CLASS (class); + extension_class->name = E_SOURCE_EXTENSION_WEATHER_BACKEND; + + g_object_class_install_property ( + object_class, + PROP_LOCATION, + g_param_spec_string ( + "location", + "Location", + "Weather location code", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + E_SOURCE_PARAM_SETTING)); + + g_object_class_install_property ( + object_class, + PROP_UNITS, + g_param_spec_enum ( + "units", + "Units", + "Metric or imperial units", + E_TYPE_SOURCE_WEATHER_UNITS, + E_SOURCE_WEATHER_UNITS_METRIC, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + E_SOURCE_PARAM_SETTING)); +} + +static void +e_source_weather_class_finalize (ESourceWeatherClass *class) +{ +} + +static void +e_source_weather_init (ESourceWeather *extension) +{ + extension->priv = E_SOURCE_WEATHER_GET_PRIVATE (extension); + extension->priv->property_lock = g_mutex_new (); +} + +void +e_source_weather_type_register (GTypeModule *type_module) +{ + static const GEnumValue e_source_weather_units_values[] = { + { E_SOURCE_WEATHER_UNITS_METRIC, + "E_SOURCE_WEATHER_UNITS_METRIC", + "metric" }, + { E_SOURCE_WEATHER_UNITS_IMPERIAL, + "E_SOURCE_WEATHER_UNITS_IMPERIAL", + "imperial" }, + { 0, NULL, NULL } + }; + + e_source_weather_units_type = + g_type_module_register_enum ( + type_module, "ESourceWeatherUnits", + e_source_weather_units_values); + + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_source_weather_register_type (type_module); +} + +const gchar * +e_source_weather_get_location (ESourceWeather *extension) +{ + g_return_val_if_fail (E_IS_SOURCE_WEATHER (extension), NULL); + + return extension->priv->location; +} + +gchar * +e_source_weather_dup_location (ESourceWeather *extension) +{ + const gchar *protected; + gchar *duplicate; + + g_return_val_if_fail (E_IS_SOURCE_WEATHER (extension), NULL); + + g_mutex_lock (extension->priv->property_lock); + + protected = e_source_weather_get_location (extension); + duplicate = g_strdup (protected); + + g_mutex_unlock (extension->priv->property_lock); + + return duplicate; +} + +void +e_source_weather_set_location (ESourceWeather *extension, + const gchar *location) +{ + g_return_if_fail (E_IS_SOURCE_WEATHER (extension)); + + g_mutex_lock (extension->priv->property_lock); + + g_free (extension->priv->location); + extension->priv->location = e_util_strdup_strip (location); + + g_mutex_unlock (extension->priv->property_lock); + + g_object_notify (G_OBJECT (extension), "location"); +} + +ESourceWeatherUnits +e_source_weather_get_units (ESourceWeather *extension) +{ + g_return_val_if_fail (E_IS_SOURCE_WEATHER (extension), 0); + + return extension->priv->units; +} + +void +e_source_weather_set_units (ESourceWeather *extension, + ESourceWeatherUnits units) +{ + g_return_if_fail (E_IS_SOURCE_WEATHER (extension)); + + extension->priv->units = units; + + g_object_notify (G_OBJECT (extension), "units"); +} + +ESourceWeatherUnits +e_source_weather_units_get_type (void) +{ + return e_source_weather_units_type; +} diff --git a/modules/cal-config-weather/e-source-weather.h b/modules/cal-config-weather/e-source-weather.h new file mode 100644 index 0000000000..85ad991f64 --- /dev/null +++ b/modules/cal-config-weather/e-source-weather.h @@ -0,0 +1,83 @@ +/* + * e-source-weather.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <webcal://www.gnu.org/licenses/> + * + */ + +#ifndef E_SOURCE_WEATHER_H +#define E_SOURCE_WEATHER_H + +#include <libedataserver/e-source-extension.h> + +/* Standard GObject macros */ +#define E_TYPE_SOURCE_WEATHER \ + (e_source_weather_get_type ()) +#define E_SOURCE_WEATHER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_SOURCE_WEATHER, ESourceWeather)) +#define E_SOURCE_WEATHER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_SOURCE_WEATHER, ESourceWeatherClass)) +#define E_IS_SOURCE_WEATHER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_SOURCE_WEATHER)) +#define E_IS_SOURCE_WEATHER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_SOURCE_WEATHER)) +#define E_SOURCE_WEATHER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_SOURCE_WEATHER, ESourceWeatherClass)) + +#define E_TYPE_SOURCE_WEATHER_UNITS \ + (e_source_weather_units_get_type ()) + +#define E_SOURCE_EXTENSION_WEATHER_BACKEND "Weather Backend" + +G_BEGIN_DECLS + +typedef struct _ESourceWeather ESourceWeather; +typedef struct _ESourceWeatherClass ESourceWeatherClass; +typedef struct _ESourceWeatherPrivate ESourceWeatherPrivate; + +struct _ESourceWeather { + ESourceExtension parent; + ESourceWeatherPrivate *priv; +}; + +struct _ESourceWeatherClass { + ESourceExtensionClass parent_class; +}; + +typedef enum { + E_SOURCE_WEATHER_UNITS_METRIC, + E_SOURCE_WEATHER_UNITS_IMPERIAL +} ESourceWeatherUnits; + +GType e_source_weather_get_type (void); +void e_source_weather_type_register (GTypeModule *type_module); +const gchar * e_source_weather_get_location (ESourceWeather *extension); +gchar * e_source_weather_dup_location (ESourceWeather *extension); +void e_source_weather_set_location (ESourceWeather *extension, + const gchar *location); +ESourceWeatherUnits + e_source_weather_get_units (ESourceWeather *extension); +void e_source_weather_set_units (ESourceWeather *extension, + ESourceWeatherUnits units); + +GType e_source_weather_units_get_type (void); + +G_END_DECLS + +#endif /* E_SOURCE_WEATHER_H */ diff --git a/modules/cal-config-weather/evolution-cal-config-weather.c b/modules/cal-config-weather/evolution-cal-config-weather.c new file mode 100644 index 0000000000..c6e8c47d08 --- /dev/null +++ b/modules/cal-config-weather/evolution-cal-config-weather.c @@ -0,0 +1,309 @@ +/* + * evolution-cal-config-weather.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include <config.h> +#include <glib/gi18n-lib.h> + +#include <libebackend/e-extension.h> + +#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE +#include <libgweather/location-entry.h> +#undef GWEATHER_I_KNOW_THIS_IS_UNSTABLE + +#include <misc/e-source-config-backend.h> +#include <calendar/gui/e-cal-source-config.h> + +#include "e-source-weather.h" + +typedef ESourceConfigBackend ECalConfigWeather; +typedef ESourceConfigBackendClass ECalConfigWeatherClass; + +/* Module Entry Points */ +void e_module_load (GTypeModule *type_module); +void e_module_unload (GTypeModule *type_module); + +typedef struct _Context Context; + +struct _Context { + GtkWidget *location_entry; + GtkWidget *units_combo; +}; + +/* Forward Declarations */ +GType e_cal_config_weather_get_type (void); + +G_DEFINE_DYNAMIC_TYPE ( + ECalConfigWeather, + e_cal_config_weather, + E_TYPE_SOURCE_CONFIG_BACKEND) + +static void +cal_config_weather_context_free (Context *context) +{ + g_object_unref (context->location_entry); + g_object_unref (context->units_combo); + + g_slice_free (Context, context); +} + +static gboolean +cal_config_weather_location_to_string (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + GWeatherLocation *location; + gchar *string = NULL; + + location = g_value_get_pointer (source_value); + + if (location != NULL) { + const gchar *code; + gchar *city_name; + + code = gweather_location_get_code (location); + city_name = gweather_location_get_city_name (location); + string = g_strdup_printf ("%s/%s", code, city_name); + g_free (city_name); + } + + g_value_take_string (target_value, string); + + return TRUE; +} + +/* XXX This is a private libgweather constant. + * The value may change at any time. */ +#define GWEATHER_LOCATION_ENTRY_COL_LOCATION 1 + +static gboolean +cal_config_weather_string_to_location (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + GObject *target; + GWeatherLocation *match = NULL; + GtkEntryCompletion *completion; + GtkTreeModel *model; + GtkTreeIter iter; + const gchar *string; + const gchar *city_name; + const gchar *code; + gchar **tokens; + + /* XXX This is a bit convoluted because libgweather lacks a + * GWeatherLocation lookup function. The algorithm is + * copied from gweather_location_entry_set_city(). */ + + string = g_value_get_string (source_value); + + if (string == NULL) + return FALSE; + + /* String is: STATION-CODE '/' CITY-NAME */ + tokens = g_strsplit (string, "/", 2); + + if (g_strv_length (tokens) != 2) { + g_strfreev (tokens); + return FALSE; + } + + code = tokens[0]; + city_name = tokens[1]; + + target = g_binding_get_target (binding); + completion = gtk_entry_get_completion (GTK_ENTRY (target)); + model = gtk_entry_completion_get_model (completion); + + gtk_tree_model_get_iter_first (model, &iter); + + do { + GWeatherLocation *location; + const gchar *cmp_code; + gchar *cmp_city_name; + + gtk_tree_model_get ( + model, &iter, + GWEATHER_LOCATION_ENTRY_COL_LOCATION, + &location, -1); + + /* Does the station code match? */ + cmp_code = gweather_location_get_code (location); + if (g_strcmp0 (code, cmp_code) != 0) + continue; + + /* Does the city name match? */ + cmp_city_name = gweather_location_get_city_name (location); + if (g_strcmp0 (city_name, cmp_city_name) != 0) { + g_free (cmp_city_name); + continue; + } + g_free (cmp_city_name); + + /* We found a match! */ + match = location; + break; + + } while (gtk_tree_model_iter_next (model, &iter)); + + g_value_set_pointer (target_value, match); + + g_strfreev (tokens); + + return TRUE; +} + +static gboolean +cal_config_weather_allow_creation (ESourceConfigBackend *backend) +{ + ESourceConfig *config; + ECalSourceConfig *cal_config; + ECalClientSourceType source_type; + + /* No such thing as weather task lists or weather memo lists. */ + + config = e_source_config_backend_get_config (backend); + + cal_config = E_CAL_SOURCE_CONFIG (config); + source_type = e_cal_source_config_get_source_type (cal_config); + + return (source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS); +} + +static void +cal_config_weather_insert_widgets (ESourceConfigBackend *backend, + ESource *scratch_source) +{ + ESourceConfig *config; + ESourceExtension *extension; + GWeatherLocation *world; + GtkWidget *widget; + Context *context; + const gchar *extension_name; + const gchar *uid; + + context = g_slice_new (Context); + uid = e_source_get_uid (scratch_source); + config = e_source_config_backend_get_config (backend); + + g_object_set_data_full ( + G_OBJECT (backend), uid, context, + (GDestroyNotify) cal_config_weather_context_free); + + world = gweather_location_new_world (TRUE); + + e_cal_source_config_add_offline_toggle ( + E_CAL_SOURCE_CONFIG (config), scratch_source); + + widget = gweather_location_entry_new (world); + e_source_config_insert_widget ( + config, scratch_source, _("Location:"), widget); + context->location_entry = g_object_ref (widget); + gtk_widget_show (widget); + + /* This must follow the order of ESourceWeatherUnits. */ + widget = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text ( + GTK_COMBO_BOX_TEXT (widget), + _("Metric (Celsius, cm, etc)")); + gtk_combo_box_text_append_text ( + GTK_COMBO_BOX_TEXT (widget), + _("Imperial (Fahrenheit, inches, etc)")); + e_source_config_insert_widget ( + config, scratch_source, _("Units:"), widget); + context->units_combo = g_object_ref (widget); + gtk_widget_show (widget); + + e_source_config_add_refresh_interval (config, scratch_source); + + gweather_location_unref (world); + + extension_name = E_SOURCE_EXTENSION_WEATHER_BACKEND; + extension = e_source_get_extension (scratch_source, extension_name); + + g_object_bind_property_full ( + extension, "location", + context->location_entry, "location", + G_BINDING_BIDIRECTIONAL | + G_BINDING_SYNC_CREATE, + cal_config_weather_string_to_location, + cal_config_weather_location_to_string, + NULL, (GDestroyNotify) NULL); + + g_object_bind_property ( + extension, "units", + context->units_combo, "active", + G_BINDING_BIDIRECTIONAL | + G_BINDING_SYNC_CREATE); +} + +static gboolean +cal_config_weather_check_complete (ESourceConfigBackend *backend, + ESource *scratch_source) +{ + ESourceWeather *extension; + const gchar *extension_name; + const gchar *location; + + extension_name = E_SOURCE_EXTENSION_WEATHER_BACKEND; + extension = e_source_get_extension (scratch_source, extension_name); + + location = e_source_weather_get_location (extension); + + g_debug ("Location: [%s]", location); + + return (location != NULL) && (*location != '\0'); +} + +static void +e_cal_config_weather_class_init (ESourceConfigBackendClass *class) +{ + EExtensionClass *extension_class; + + extension_class = E_EXTENSION_CLASS (class); + extension_class->extensible_type = E_TYPE_CAL_SOURCE_CONFIG; + + class->parent_uid = "weather-stub"; + class->backend_name = "weather"; + class->allow_creation = cal_config_weather_allow_creation; + class->insert_widgets = cal_config_weather_insert_widgets; + class->check_complete = cal_config_weather_check_complete; +} + +static void +e_cal_config_weather_class_finalize (ESourceConfigBackendClass *class) +{ +} + +static void +e_cal_config_weather_init (ESourceConfigBackend *backend) +{ +} + +G_MODULE_EXPORT void +e_module_load (GTypeModule *type_module) +{ + e_source_weather_type_register (type_module); + e_cal_config_weather_register_type (type_module); +} + +G_MODULE_EXPORT void +e_module_unload (GTypeModule *type_module) +{ +} diff --git a/plugins/calendar-weather/Makefile.am b/plugins/calendar-weather/Makefile.am deleted file mode 100644 index 4283318ffb..0000000000 --- a/plugins/calendar-weather/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -eds_datadir = `pkg-config --variable=privdatadir evolution-data-server-1.2` - -@EVO_PLUGIN_RULE@ - -plugin_DATA = org-gnome-calendar-weather.eplug -plugin_LTLIBRARIES = liborg-gnome-calendar-weather.la - -liborg_gnome_calendar_weather_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - -DWEATHER_DATADIR=\""$(weatherdatadir)"\" \ - -DWEATHER_EDS_DATADIR=\""$(eds_datadir)/weather"\" \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) \ - $(GWEATHER_CFLAGS) - -liborg_gnome_calendar_weather_la_SOURCES = calendar-weather.c -liborg_gnome_calendar_weather_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) -liborg_gnome_calendar_weather_la_LIBADD = \ - $(top_builddir)/calendar/gui/libevolution-calendar.la \ - $(top_builddir)/e-util/libeutil.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) \ - $(GWEATHER_LIBS) - -EXTRA_DIST = \ - org-gnome-calendar-weather.eplug.xml \ - $(weatherdata_DATA) - -BUILT_SOURCES = $(plugin_DATA) -CLEANFILES = $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugins/calendar-weather/calendar-weather.c b/plugins/calendar-weather/calendar-weather.c deleted file mode 100644 index 93f1c0ae50..0000000000 --- a/plugins/calendar-weather/calendar-weather.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Authors: David Trowbridge <trowbrds@cs.colorado.edu> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <e-util/e-config.h> -#include <e-util/e-icon-factory.h> -#include <e-util/e-plugin-util.h> -#include <calendar/gui/e-cal-config.h> -#include <calendar/gui/e-cal-event.h> -#include <libedataserver/e-source.h> -#include <libedataserver/e-categories.h> -#include <glib/gi18n.h> -#include <libxml/parser.h> -#include <libxml/tree.h> -#include <string.h> - -#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE -#include <libgweather/weather.h> -#include <libgweather/gweather-xml.h> -#undef GWEATHER_I_KNOW_THIS_IS_UNSTABLE - -GtkWidget *e_calendar_weather_location (EPlugin *epl, EConfigHookItemFactoryData *data); -GtkWidget *e_calendar_weather_refresh (EPlugin *epl, EConfigHookItemFactoryData *data); -GtkWidget *e_calendar_weather_units (EPlugin *epl, EConfigHookItemFactoryData *data); -gboolean e_calendar_weather_check (EPlugin *epl, EConfigHookPageCheckData *data); -void e_calendar_weather_migrate (EPlugin *epl, ECalEventTargetBackend *data); -gint e_plugin_lib_enable (EPlugin *epl, gint enable); - -#define WEATHER_BASE_URI "weather://" - -gint -e_plugin_lib_enable (EPlugin *epl, - gint enable) -{ - GList *l, *saved_cats; - const gchar *tmp; - gint ii; - - static struct { - const gchar *description; - const gchar *icon_name; - } categories[] = { - { N_("Weather: Fog"), "weather-fog" }, - { N_("Weather: Cloudy"), "weather-few-clouds" }, - { N_("Weather: Cloudy Night"), "weather-few-clouds-night" }, - { N_("Weather: Overcast"), "weather-overcast" }, - { N_("Weather: Showers"), "weather-showers" }, - { N_("Weather: Snow"), "weather-snow" }, - { N_("Weather: Sunny"), "weather-clear" }, - { N_("Weather: Clear Night"), "weather-clear-night" }, - { N_("Weather: Thunderstorms"), "weather-storm" }, - { NULL, NULL } - }; - - tmp = _(categories[0].description); - - saved_cats = e_categories_get_list (); - - /* Add the categories icons if we don't have them. */ - for (l = saved_cats; l; l = g_list_next (l)) { - if (!strcmp ((const gchar *) l->data, tmp)) - goto exit; - } - - for (ii = 0; categories[ii].description; ii++) { - gchar *filename; - - filename = e_icon_factory_get_icon_filename ( - categories[ii].icon_name, GTK_ICON_SIZE_MENU); - e_categories_add ( - _(categories[ii].description), NULL, filename, FALSE); - g_free (filename); - } - -exit: - g_list_free (saved_cats); - - return 0; -} - -void -e_calendar_weather_migrate (EPlugin *epl, - ECalEventTargetBackend *data) -{ - /* Perform a migration step here. This allows us to keep the weather calendar completely - * separate from evolution. If the plugin isn't built, the weather source group won't - * show up in the user's evolution. If it is, this will create it if it doesn't exist */ - ESourceGroup *group; - GSList *groups; - ESourceGroup *weather = NULL; - - groups = e_source_list_peek_groups (data->source_list); - if (groups) { - /* groups are already there, we need to search */ - GSList *g; - - for (g = groups; g; g = g_slist_next (g)) { - group = E_SOURCE_GROUP (g->data); - if (!weather && !strcmp (WEATHER_BASE_URI, e_source_group_peek_base_uri (group))) - weather = g_object_ref (group); - } - } - - if (!weather) { - group = e_source_group_new (_("Weather"), WEATHER_BASE_URI); - e_source_list_add_group (data->source_list, group, -1); - - weather = group; - } - - if (weather) - g_object_unref (weather); - - e_source_list_sync (data->source_list, NULL); -} - -static void -selection_changed (GtkTreeSelection *selection, - GtkDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - WeatherLocation *loc = NULL; - gtk_tree_model_get (model, &iter, GWEATHER_XML_COL_POINTER, &loc, -1); - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, loc != NULL); - } else { - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); - } -} - -static struct -{ - gboolean is_old; - gchar **ids; - GtkTreeIter *result; -} find_data; - -static gboolean -find_location_func (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *node, - gpointer data) -{ - WeatherLocation *wl = NULL; - - gtk_tree_model_get (model, node, GWEATHER_XML_COL_POINTER, &wl, -1); - if (!wl || !wl->name || !wl->code) - return FALSE; - if (((!strcmp (wl->code, find_data.ids[0])) || (find_data.is_old && !strcmp (wl->code + 1, find_data.ids[0]))) && - (!strcmp (wl->name, find_data.ids[1]))) { - find_data.result = gtk_tree_iter_copy (node); - return TRUE; - } - return FALSE; -} - -static GtkTreeIter * -find_location (GtkTreeModel *model, - gchar *relative_url) -{ - /* old URL uses type/code/name, but new uses only code/name */ - if (strncmp (relative_url, "ccf/", 4) == 0) { - relative_url = relative_url + 4; - find_data.is_old = TRUE; - } else - find_data.is_old = FALSE; - - find_data.ids = g_strsplit (relative_url, "/", -1); - find_data.result = NULL; - gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) find_location_func, NULL); - - g_strfreev (find_data.ids); - return find_data.result; -} - -static gboolean -treeview_clicked (GtkTreeView *treeview, - GdkEventButton *event, - GtkDialog *dialog) -{ - if (event->type == GDK_2BUTTON_PRESS) { - GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); - GtkTreeModel *model; - GtkTreeIter iter; - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - WeatherLocation *wl = NULL; - gtk_tree_model_get (model, &iter, GWEATHER_XML_COL_POINTER, &wl, -1); - if (wl != NULL && wl->code != NULL && wl->name != NULL) { - gtk_dialog_response (dialog, GTK_RESPONSE_OK); - return TRUE; - } - } - } - return FALSE; -} - -static GtkTreeModel *store = NULL; - -static GtkDialog * -create_source_selector (ESource *source) -{ - GtkWidget *dialog, *treeview, *scrolledwindow; - GtkWidget *content_area; - GtkCellRenderer *text; - GtkTreeSelection *selection; - gchar *uri_text; - SoupURI *suri; - - /* FIXME - should show an error here if it fails*/ - if (store == NULL) - return NULL; - - dialog = gtk_dialog_new_with_buttons ( - _("Select a location"), - NULL, GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); - - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_widget_show (scrolledwindow); - treeview = gtk_tree_view_new_with_model (store); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); - gtk_widget_show (treeview); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), treeview); - gtk_widget_add_events (treeview, GDK_BUTTON_PRESS); - g_signal_connect ( - treeview, "button-press-event", - G_CALLBACK (treeview_clicked), dialog); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - - uri_text = e_source_get_uri (source); - suri = soup_uri_new (uri_text); - if (suri && suri->path && *suri->path) { - GtkTreeIter *iter = find_location (store, uri_text + 10); - GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (treeview), path); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); - } - g_free (uri_text); - if (suri) - soup_uri_free (suri); - - g_signal_connect ( - selection, "changed", - G_CALLBACK (selection_changed), dialog); - g_object_set_data (G_OBJECT (dialog), "treeview", treeview); - - text = gtk_cell_renderer_text_new (); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "location", text, "text", 0, NULL); - - content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); - gtk_box_pack_start (GTK_BOX (content_area), scrolledwindow, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow), 6); - gtk_box_set_spacing (GTK_BOX (content_area), 6); - - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); - gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 340); - - return GTK_DIALOG (dialog); -} - -static gchar * -build_location_path (GtkTreeIter *iter) -{ - GtkTreeIter parent; - gchar *path, *temp1, *temp2; - - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, GWEATHER_XML_COL_LOC, &temp1, -1); - path = g_strdup (temp1); - - while (gtk_tree_model_iter_parent (GTK_TREE_MODEL (store), &parent, iter)) { - gtk_tree_model_get (GTK_TREE_MODEL (store), &parent, GWEATHER_XML_COL_LOC, &temp1, -1); - temp2 = g_strdup_printf ("%s : %s", temp1, path); - g_free (path); - path = temp2; - iter = gtk_tree_iter_copy (&parent); - } - return path; -} - -static void -location_clicked (GtkButton *button, - ESource *source) -{ - GtkDialog *dialog = create_source_selector (source); - gint response; - - if (dialog == NULL) - return; - - response = gtk_dialog_run (dialog); - - if (response == GTK_RESPONSE_OK) { - GtkTreeView *view = GTK_TREE_VIEW (g_object_get_data (G_OBJECT (dialog), "treeview")); - GtkTreeSelection *selection = gtk_tree_view_get_selection (view); - GtkTreeModel *model; - GtkTreeIter iter; - GtkWidget *label; - WeatherLocation *wl = NULL; - gchar *path, *uri; - - gtk_tree_selection_get_selected (selection, &model, &iter); - gtk_tree_model_get (model, &iter, GWEATHER_XML_COL_POINTER, &wl, -1); - path = build_location_path (&iter); - - label = gtk_bin_get_child (GTK_BIN (button)); - gtk_label_set_text (GTK_LABEL (label), path); - - uri = g_strdup_printf ("%s/%s", wl->code, wl->name); - /* FIXME - url_encode (&uri); */ - e_source_set_relative_uri (source, uri); - g_free (uri); - } else { - GtkWidget *label; - const gchar *text; - - label = GTK_WIDGET (gtk_bin_get_child (GTK_BIN (button))); - text = gtk_label_get_text (GTK_LABEL (label)); - /* Translators: "None" location for a weather calendar */ - if (strcmp ((const gchar *)text, C_("weather-cal-location", "None")) == 0) - e_source_set_relative_uri (source, ""); - } - - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -GtkWidget * -e_calendar_weather_location (EPlugin *epl, - EConfigHookItemFactoryData *data) -{ - GtkWidget *button, *parent, *text, *label; - guint row; - ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; - ESource *source = t->source; - SoupURI *suri; - gchar *uri_text; - - if (!e_plugin_util_is_source_proto (t->source, "weather")) - return NULL; - - if (store == NULL) - store = gweather_xml_load_locations (); - - uri_text = e_source_get_uri (t->source); - suri = soup_uri_new (uri_text); - - parent = data->parent; - - g_object_get (parent, "n-rows", &row, NULL); - - label = gtk_label_new_with_mnemonic (_("_Location:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (parent), label, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0); - - button = gtk_button_new (); - g_signal_connect ( - button, "clicked", - G_CALLBACK (location_clicked), source); - gtk_widget_show (button); - - if (suri && suri->path && *suri->path) { - GtkTreeIter *iter = find_location (store, uri_text + 10); - gchar *location = build_location_path (iter); - text = gtk_label_new (location); - g_free (location); - } else { - text = gtk_label_new (C_("weather-cal-location", "None")); - } - gtk_widget_show (text); - gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ELLIPSIZE_START); - gtk_container_add (GTK_CONTAINER (button), text); - if (suri) - soup_uri_free (suri); - g_free (uri_text); - - gtk_table_attach (GTK_TABLE (parent), button, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - - return button; -} - -GtkWidget * -e_calendar_weather_refresh (EPlugin *epl, - EConfigHookItemFactoryData *data) -{ - ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; - - if (!e_plugin_util_is_source_proto (t->source, "weather")) - return NULL; - - return e_plugin_util_add_refresh (data->parent, _("Re_fresh:"), t->source, "refresh"); -} - -static void -set_units (ESource *source, - GtkWidget *combobox) -{ - const gchar *format = e_source_get_property (source, "units"); - if (format == NULL) { - format = e_source_get_property (source, "temperature"); - if (format == NULL) { - e_source_set_property (source, "units", "metric"); - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); - } else if (strcmp ((const gchar *)format, "fahrenheit") == 0) { - /* old format, convert */ - e_source_set_property (source, "units", "imperial"); - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 1); - } else { - e_source_set_property (source, "units", "metric"); - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); - } - } else { - if (strcmp ((const gchar *)format, "metric") == 0) - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); - else - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 1); - } -} - -static void -units_changed (GtkComboBox *combobox, - ECalConfigTargetSource *t) -{ - gint choice = gtk_combo_box_get_active (GTK_COMBO_BOX (combobox)); - if (choice == 0) - e_source_set_property (t->source, "units", "metric"); - else - e_source_set_property (t->source, "units", "imperial"); -} - -GtkWidget * -e_calendar_weather_units (EPlugin *epl, - EConfigHookItemFactoryData *data) -{ - GtkWidget *combobox, *parent, *label; - guint row; - ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; - ESource *source = t->source; - - if (!e_plugin_util_is_source_proto (t->source, "weather")) - return NULL; - - parent = data->parent; - - g_object_get (parent, "n-rows", &row, NULL); - - label = gtk_label_new_with_mnemonic (_("_Units:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (parent), label, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0); - - combobox = gtk_combo_box_text_new (); - gtk_widget_show (combobox); - gtk_combo_box_text_append_text ( - GTK_COMBO_BOX_TEXT (combobox), - _("Metric (Celsius, cm, etc)")); - gtk_combo_box_text_append_text ( - GTK_COMBO_BOX_TEXT (combobox), - _("Imperial (Fahrenheit, inches, etc)")); - set_units (source, combobox); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox); - g_signal_connect ( - combobox, "changed", - G_CALLBACK (units_changed), t); - gtk_table_attach (GTK_TABLE (parent), combobox, 1, 2, row, row + 1, GTK_FILL, 0, 0, 0); - - return combobox; -} - -gboolean -e_calendar_weather_check (EPlugin *epl, - EConfigHookPageCheckData *data) -{ - /* FIXME - check pageid */ - ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target; - SoupURI *suri; - gboolean ok = FALSE; - - /* always return TRUE if this isn't a weather source */ - if (!e_plugin_util_is_group_proto (e_source_peek_group (t->source), "weather")) - return TRUE; - - suri = soup_uri_new (e_source_get_uri (t->source)); - /* make sure that the protocol is weather:// and that the path isn't empty */ - ok = suri && suri->path && *suri->path; - if (suri) - soup_uri_free (suri); - - return ok; -} diff --git a/plugins/calendar-weather/org-gnome-calendar-weather.eplug.xml b/plugins/calendar-weather/org-gnome-calendar-weather.eplug.xml deleted file mode 100644 index 17ba087058..0000000000 --- a/plugins/calendar-weather/org-gnome-calendar-weather.eplug.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0"?> -<e-plugin-list> - <e-plugin - type="shlib" - location="@PLUGINDIR@/liborg-gnome-calendar-weather@SOEXT@" - id="org.gnome.evolution.calendar.weather" - _name="Weather Calendars" - system_plugin="true"> - <_description>Add weather calendars to Evolution.</_description> - <author name="David Trowbridge" email="trowbrds@cs.colorado.edu"/> - <hook class="org.gnome.evolution.calendar.config:1.0"> - <group - target="source" - id="org.gnome.evolution.calendar.calendarProperties" - check="e_calendar_weather_check"> - <item - type="item_table" - path="00.general/00.source/40.location" - factory="e_calendar_weather_location"/> - <item - type="item_table" - path="00.general/00.source/50.units" - factory="e_calendar_weather_units"/> - <item - type="item_table" - path="00.general/00.source/60.refresh" - factory="e_calendar_weather_refresh"/> - </group> - </hook> - <hook class="org.gnome.evolution.calendar.events:1.0"> - <event target="module" id="module.migration" handle="e_calendar_weather_migrate"/> - </hook> - </e-plugin> -</e-plugin-list> |