summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-10-11 00:04:50 +0200
committerStefano Karapetsas <[email protected]>2012-10-11 00:04:50 +0200
commitcf41dc3d28c3daa30f04962718b468cf46830828 (patch)
treebf34cb5d73dbc4d297229b1464967ace652e7085
parent5052d39d3d10a57b2fe0e15b2e7833ef207d3a48 (diff)
downloadmate-panel-cf41dc3d28c3daa30f04962718b468cf46830828.tar.bz2
mate-panel-cf41dc3d28c3daa30f04962718b468cf46830828.tar.xz
migrate clock applet to gsettings
remove evolution code
-rw-r--r--applets/clock/Makefile.am39
-rw-r--r--applets/clock/calendar-client.c2171
-rw-r--r--applets/clock/calendar-client.h153
-rw-r--r--applets/clock/calendar-debug.h56
-rw-r--r--applets/clock/calendar-sources.c658
-rw-r--r--applets/clock/calendar-sources.h70
-rw-r--r--applets/clock/calendar-window.c1616
-rw-r--r--applets/clock/clock-face.c2
-rw-r--r--applets/clock/clock-location.c8
-rw-r--r--applets/clock/clock.c823
-rw-r--r--applets/clock/clock.h2
-rw-r--r--applets/clock/clock.schemas.in313
-rw-r--r--applets/clock/org.mate.panel.applet.clock.gschema.xml.in88
13 files changed, 307 insertions, 5692 deletions
diff --git a/applets/clock/Makefile.am b/applets/clock/Makefile.am
index afda6eb2..17dc67e4 100644
--- a/applets/clock/Makefile.am
+++ b/applets/clock/Makefile.am
@@ -14,15 +14,6 @@ libsystem_timezone_la_SOURCES = \
system-timezone.h
libsystem_timezone_la_LIBADD = $(TZ_LIBS)
-if HAVE_LIBECAL
-CALENDAR_SOURCES = \
- calendar-client.c \
- calendar-client.h \
- calendar-sources.c \
- calendar-sources.h \
- calendar-debug.h
-endif
-
CLOCK_SOURCES = \
calendar-window.c \
calendar-window.h \
@@ -42,8 +33,7 @@ CLOCK_SOURCES = \
clock-utils.h \
set-timezone.c \
set-timezone.h \
- $(BUILT_SOURCES) \
- $(CALENDAR_SOURCES)
+ $(BUILT_SOURCES)
CLOCK_CPPFLAGS = \
$(AM_CPPFLAGS) \
@@ -55,11 +45,10 @@ CLOCK_CPPFLAGS = \
-DBUILDERDIR=\""$(uidir)"\" \
-DCLOCK_MENU_UI_DIR=\""$(xmluidir)"\" \
-DICONDIR=\""$(datadir)/mate-panel/pixmaps"\" \
- -DCLOCK_EDS_ICONDIR="\"$(CLOCK_EDS_ICONDIR)\"" \
-DMATEWEATHER_I_KNOW_THIS_IS_UNSTABLE
CLOCK_LDADD = \
- ../../libmate-panel-applet/libmate-panel-applet-3.la \
+ ../../libmate-panel-applet/libmate-panel-applet-4.la \
$(CLOCK_LIBS) \
$(LIBMATE_PANEL_APPLET_LIBS) \
libsystem-timezone.la \
@@ -166,28 +155,13 @@ ui_DATA = clock.ui
xmluidir = $(datadir)/mate-panel/ui
xmlui_DATA = clock-menu.xml
-schemasdir = $(MATECONF_SCHEMA_FILE_DIR)
-schemas_in_files = clock.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
-
-@INTLTOOL_SCHEMAS_RULE@
-
-if MATECONF_SCHEMAS_INSTALL
-install-data-local:
- if test -z "$(DESTDIR)" ; then \
- for p in $(schemas_DATA) ; do \
- MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(top_builddir)/applets/clock/$$p ; \
- done \
- fi
-uninstall-local:
- for p in $(schema_DATA) ; do \
- MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-uninstall-rule $(top_builddir)/applets/clock/$$p ; \
- done
-endif
+gsettings_SCHEMAS = org.mate.panel.applet.clock.gschema.xml
+@INTLTOOL_XML_NOMERGE_RULE@
+@GSETTINGS_RULES@
EXTRA_DIST = \
org.mate.panel.ClockApplet.mate-panel-applet.in.in \
- $(schemas_in_files) \
+ $(gsettings_SCHEMAS) \
$(xmlui_DATA) \
$(ui_DATA) \
clock-marshallers.list \
@@ -198,7 +172,6 @@ CLEANFILES = \
$(applet_DATA) \
$(applet_DATA).in \
$(service_DATA) \
- $(schemas_DATA) \
$(polkit_DATA) \
$(dbus_services_DATA)
diff --git a/applets/clock/calendar-client.c b/applets/clock/calendar-client.c
deleted file mode 100644
index 8619a3b6..00000000
--- a/applets/clock/calendar-client.c
+++ /dev/null
@@ -1,2171 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Authors:
- * Mark McLoughlin <[email protected]>
- * William Jon McCann <[email protected]>
- * Martin Grimme <[email protected]>
- * Christian Kellner <[email protected]>
- */
-
-#include <config.h>
-
-#include "calendar-client.h"
-
-#include <mateconf/mateconf-client.h>
-
-#include <libintl.h>
-#include <string.h>
-#define HANDLE_LIBICAL_MEMORY
-#include <libecal/e-cal.h>
-#include <libecal/e-cal-time-util.h>
-#include <libecal/e-cal-recur.h>
-
-#include "calendar-sources.h"
-
-#undef CALENDAR_ENABLE_DEBUG
-#include "calendar-debug.h"
-
-#define CALENDAR_CONFIG_PREFIX "/apps/evolution/calendar"
-#define CALENDAR_CONFIG_TIMEZONE CALENDAR_CONFIG_PREFIX "/display/timezone"
-
-#ifndef _
-#define _(x) gettext(x)
-#endif
-
-#ifndef N_
-#define N_(x) x
-#endif
-
-#define CALENDAR_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CALENDAR_TYPE_CLIENT, CalendarClientPrivate))
-
-typedef struct _CalendarClientQuery CalendarClientQuery;
-typedef struct _CalendarClientSource CalendarClientSource;
-
-struct _CalendarClientQuery
-{
- ECalView *view;
- GHashTable *events;
-};
-
-struct _CalendarClientSource
-{
- CalendarClient *client;
- ECal *source;
-
- CalendarClientQuery completed_query;
- CalendarClientQuery in_progress_query;
-
- guint changed_signal_id;
-
- guint query_completed : 1;
- guint query_in_progress : 1;
-};
-
-struct _CalendarClientPrivate
-{
- CalendarSources *calendar_sources;
-
- GSList *appointment_sources;
- GSList *task_sources;
-
- icaltimezone *zone;
-
- guint zone_listener;
- MateConfClient *mateconf_client;
-
- guint day;
- guint month;
- guint year;
-};
-
-static void calendar_client_class_init (CalendarClientClass *klass);
-static void calendar_client_init (CalendarClient *client);
-static void calendar_client_finalize (GObject *object);
-static void calendar_client_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void calendar_client_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static GSList *calendar_client_update_sources_list (CalendarClient *client,
- GSList *sources,
- GSList *esources,
- guint changed_signal_id);
-static void calendar_client_appointment_sources_changed (CalendarClient *client);
-static void calendar_client_task_sources_changed (CalendarClient *client);
-
-static void calendar_client_stop_query (CalendarClient *client,
- CalendarClientSource *source,
- CalendarClientQuery *query);
-static void calendar_client_start_query (CalendarClient *client,
- CalendarClientSource *source,
- const char *query);
-
-static void calendar_client_source_finalize (CalendarClientSource *source);
-static void calendar_client_query_finalize (CalendarClientQuery *query);
-
-static void
-calendar_client_update_appointments (CalendarClient *client);
-static void
-calendar_client_update_tasks (CalendarClient *client);
-
-enum
-{
- PROP_O,
- PROP_DAY,
- PROP_MONTH,
- PROP_YEAR
-};
-
-enum
-{
- APPOINTMENTS_CHANGED,
- TASKS_CHANGED,
- LAST_SIGNAL
-};
-
-static GObjectClass *parent_class = NULL;
-static guint signals [LAST_SIGNAL] = { 0, };
-
-GType
-calendar_client_get_type (void)
-{
- static GType client_type = 0;
-
- if (!client_type)
- {
- static const GTypeInfo client_info =
- {
- sizeof (CalendarClientClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) calendar_client_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (CalendarClient),
- 0, /* n_preallocs */
- (GInstanceInitFunc) calendar_client_init,
- };
-
- client_type = g_type_register_static (G_TYPE_OBJECT,
- "CalendarClient",
- &client_info, 0);
- }
-
- return client_type;
-}
-
-static void
-calendar_client_class_init (CalendarClientClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass *) klass;
-
- parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->finalize = calendar_client_finalize;
- gobject_class->set_property = calendar_client_set_property;
- gobject_class->get_property = calendar_client_get_property;
-
- g_type_class_add_private (klass, sizeof (CalendarClientPrivate));
-
- g_object_class_install_property (gobject_class,
- PROP_DAY,
- g_param_spec_uint ("day",
- "Day",
- "The currently monitored day between 1 and 31 (0 denotes unset)",
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_MONTH,
- g_param_spec_uint ("month",
- "Month",
- "The currently monitored month between 0 and 11",
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_YEAR,
- g_param_spec_uint ("year",
- "Year",
- "The currently monitored year",
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- signals [APPOINTMENTS_CHANGED] =
- g_signal_new ("appointments-changed",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CalendarClientClass, tasks_changed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- signals [TASKS_CHANGED] =
- g_signal_new ("tasks-changed",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CalendarClientClass, tasks_changed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-}
-
-/* Timezone code adapted from evolution/calendar/gui/calendar-config.c */
-/* The current timezone, e.g. "Europe/London". It may be NULL, in which case
- you should assume UTC. */
-static gchar *
-calendar_client_config_get_timezone (MateConfClient *mateconf_client)
-{
- char *location;
-
- location = mateconf_client_get_string (mateconf_client,
- CALENDAR_CONFIG_TIMEZONE,
- NULL);
-
- return location;
-}
-
-static icaltimezone *
-calendar_client_config_get_icaltimezone (MateConfClient *mateconf_client)
-{
- char *location;
- icaltimezone *zone = NULL;
-
- location = calendar_client_config_get_timezone (mateconf_client);
- if (!location)
- return icaltimezone_get_utc_timezone ();
-
- zone = icaltimezone_get_builtin_timezone (location);
- g_free (location);
-
- return zone;
-}
-
-static void
-calendar_client_set_timezone (CalendarClient *client)
-{
- GSList *l;
- GSList *esources;
-
- client->priv->zone = calendar_client_config_get_icaltimezone (client->priv->mateconf_client);
-
- esources = calendar_sources_get_appointment_sources (client->priv->calendar_sources);
- for (l = esources; l; l = l->next) {
- ECal *source = l->data;
-
- e_cal_set_default_timezone (source, client->priv->zone, NULL);
- }
-}
-
-static void
-calendar_client_timezone_changed_cb (MateConfClient *mateconf_client,
- guint id,
- MateConfEntry *entry,
- CalendarClient *client)
-{
- calendar_client_set_timezone (client);
-}
-
-static void
-cal_opened_cb (ECal *ecal,
- ECalendarStatus status,
- CalendarClientSource *cl_source)
-{
- ECalSourceType s_type;
- CalendarClient *client = cl_source->client;
-
- s_type = e_cal_get_source_type (ecal);
-
- if (status == E_CALENDAR_STATUS_BUSY &&
- e_cal_get_load_state (ecal) == E_CAL_LOAD_NOT_LOADED)
- {
- e_cal_open_async (ecal, FALSE);
- return;
- }
-
- g_signal_handlers_disconnect_by_func (ecal, cal_opened_cb, cl_source);
-
- if (status != E_CALENDAR_STATUS_OK)
- {
- if (s_type == E_CAL_SOURCE_TYPE_EVENT)
- client->priv->appointment_sources = g_slist_remove (client->priv->appointment_sources,
- cl_source);
- else
- client->priv->task_sources = g_slist_remove (client->priv->task_sources,
- cl_source);
-
- calendar_client_source_finalize (cl_source);
- g_free (cl_source);
-
- return;
- }
-
- if (s_type == E_CAL_SOURCE_TYPE_EVENT)
- calendar_client_update_appointments (client);
- else
- calendar_client_update_tasks (client);
-}
-
-static void
-load_calendars (CalendarClient *client,
- CalendarEventType type)
-{
- GSList *l, *clients;
-
- switch (type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- clients = client->priv->appointment_sources;
- break;
- case CALENDAR_EVENT_TASK:
- clients = client->priv->task_sources;
- break;
- default:
- g_assert_not_reached ();
- }
-
- for (l = clients; l != NULL; l = l->next)
- {
- ECal *ecal;
- CalendarClientSource *cl_source = l->data;
-
- ecal = cl_source->source;
-
- if (e_cal_get_load_state (ecal) == E_CAL_LOAD_LOADED)
- continue;
-
- g_signal_connect (G_OBJECT (ecal), "cal_opened",
- G_CALLBACK (cal_opened_cb), cl_source);
- e_cal_open_async (ecal, TRUE);
- }
-}
-
-static void
-calendar_client_init (CalendarClient *client)
-{
- GSList *esources;
-
- client->priv = CALENDAR_CLIENT_GET_PRIVATE (client);
-
- client->priv->calendar_sources = calendar_sources_get ();
- client->priv->mateconf_client = mateconf_client_get_default ();
-
- esources = calendar_sources_get_appointment_sources (client->priv->calendar_sources);
- client->priv->appointment_sources =
- calendar_client_update_sources_list (client, NULL, esources, signals [APPOINTMENTS_CHANGED]);
-
- esources = calendar_sources_get_task_sources (client->priv->calendar_sources);
- client->priv->task_sources =
- calendar_client_update_sources_list (client, NULL, esources, signals [TASKS_CHANGED]);
-
- /* set the timezone before loading the clients */
- calendar_client_set_timezone (client);
- load_calendars (client, CALENDAR_EVENT_APPOINTMENT);
- load_calendars (client, CALENDAR_EVENT_TASK);
-
- g_signal_connect_swapped (client->priv->calendar_sources,
- "appointment-sources-changed",
- G_CALLBACK (calendar_client_appointment_sources_changed),
- client);
- g_signal_connect_swapped (client->priv->calendar_sources,
- "task-sources-changed",
- G_CALLBACK (calendar_client_task_sources_changed),
- client);
-
- mateconf_client_add_dir (client->priv->mateconf_client,
- CALENDAR_CONFIG_PREFIX,
- MATECONF_CLIENT_PRELOAD_NONE,
- NULL);
-
- client->priv->zone_listener = mateconf_client_notify_add (client->priv->mateconf_client,
- CALENDAR_CONFIG_TIMEZONE,
- (MateConfClientNotifyFunc) calendar_client_timezone_changed_cb,
- client, NULL, NULL);
-
- client->priv->day = -1;
- client->priv->month = -1;
- client->priv->year = -1;
-}
-
-static void
-calendar_client_finalize (GObject *object)
-{
- CalendarClient *client = CALENDAR_CLIENT (object);
- GSList *l;
-
- if (client->priv->zone_listener)
- {
- mateconf_client_notify_remove (client->priv->mateconf_client,
- client->priv->zone_listener);
- client->priv->zone_listener = 0;
- }
-
- mateconf_client_remove_dir (client->priv->mateconf_client,
- CALENDAR_CONFIG_PREFIX,
- NULL);
-
- if (client->priv->mateconf_client)
- g_object_unref (client->priv->mateconf_client);
- client->priv->mateconf_client = NULL;
-
- for (l = client->priv->appointment_sources; l; l = l->next)
- {
- calendar_client_source_finalize (l->data);
- g_free (l->data);
- }
- g_slist_free (client->priv->appointment_sources);
- client->priv->appointment_sources = NULL;
-
- for (l = client->priv->task_sources; l; l = l->next)
- {
- calendar_client_source_finalize (l->data);
- g_free (l->data);
- }
- g_slist_free (client->priv->task_sources);
- client->priv->task_sources = NULL;
-
- if (client->priv->calendar_sources)
- g_object_unref (client->priv->calendar_sources);
- client->priv->calendar_sources = NULL;
-
- if (G_OBJECT_CLASS (parent_class)->finalize)
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-calendar_client_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- CalendarClient *client = CALENDAR_CLIENT (object);
-
- switch (prop_id)
- {
- case PROP_DAY:
- calendar_client_select_day (client, g_value_get_uint (value));
- break;
- case PROP_MONTH:
- calendar_client_select_month (client,
- g_value_get_uint (value),
- client->priv->year);
- break;
- case PROP_YEAR:
- calendar_client_select_month (client,
- client->priv->month,
- g_value_get_uint (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-calendar_client_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- CalendarClient *client = CALENDAR_CLIENT (object);
-
- switch (prop_id)
- {
- case PROP_DAY:
- g_value_set_uint (value, client->priv->day);
- break;
- case PROP_MONTH:
- g_value_set_uint (value, client->priv->month);
- break;
- case PROP_YEAR:
- g_value_set_uint (value, client->priv->year);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-CalendarClient *
-calendar_client_new (void)
-{
- return g_object_new (CALENDAR_TYPE_CLIENT, NULL);
-}
-
-/* @day and @month can happily be out of range as
- * mktime() will normalize them correctly. From mktime(3):
- *
- * "If structure members are outside their legal interval,
- * they will be normalized (so that, e.g., 40 October is
- * changed into 9 November)."
- *
- * "What?", you say, "Something useful in libc?"
- */
-static inline time_t
-make_time_for_day_begin (int day,
- int month,
- int year)
-{
- struct tm localtime_tm = { 0, };
-
- localtime_tm.tm_mday = day;
- localtime_tm.tm_mon = month;
- localtime_tm.tm_year = year - 1900;
- localtime_tm.tm_isdst = -1;
-
- return mktime (&localtime_tm);
-}
-
-static inline char *
-make_isodate_for_day_begin (int day,
- int month,
- int year)
-{
- time_t utctime;
-
- utctime = make_time_for_day_begin (day, month, year);
-
- return utctime != -1 ? isodate_from_time_t (utctime) : NULL;
-}
-
-static time_t
-get_time_from_property (icalcomponent *ical,
- icalproperty_kind prop_kind,
- struct icaltimetype (* get_prop_func) (const icalproperty *prop),
- icaltimezone *default_zone)
-{
- icalproperty *prop;
- struct icaltimetype ical_time;
- icalparameter *param;
- icaltimezone *timezone = NULL;
-
- prop = icalcomponent_get_first_property (ical, prop_kind);
- if (!prop)
- return 0;
-
- ical_time = get_prop_func (prop);
-
- param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
- if (param)
- timezone = icaltimezone_get_builtin_timezone_from_tzid (icalparameter_get_tzid (param));
- else if (icaltime_is_utc (ical_time))
- timezone = icaltimezone_get_utc_timezone ();
- else
- timezone = default_zone;
-
- return icaltime_as_timet_with_zone (ical_time, timezone);
-}
-
-static char *
-get_ical_uid (icalcomponent *ical)
-{
- return g_strdup (icalcomponent_get_uid (ical));
-}
-
-static char *
-get_ical_rid (icalcomponent *ical)
-{
- icalproperty *prop;
- struct icaltimetype ical_time;
-
- prop = icalcomponent_get_first_property (ical, ICAL_RECURRENCEID_PROPERTY);
- if (!prop)
- return NULL;
-
- ical_time = icalproperty_get_recurrenceid (prop);
-
- return icaltime_is_valid_time (ical_time) && !icaltime_is_null_time (ical_time) ?
- g_strdup (icaltime_as_ical_string (ical_time)) : NULL;
-}
-
-static char *
-get_ical_summary (icalcomponent *ical)
-{
- icalproperty *prop;
-
- prop = icalcomponent_get_first_property (ical, ICAL_SUMMARY_PROPERTY);
- if (!prop)
- return NULL;
-
- return g_strdup (icalproperty_get_summary (prop));
-}
-
-static char *
-get_ical_description (icalcomponent *ical)
-{
- icalproperty *prop;
-
- prop = icalcomponent_get_first_property (ical, ICAL_DESCRIPTION_PROPERTY);
- if (!prop)
- return NULL;
-
- return g_strdup (icalproperty_get_description (prop));
-}
-
-static inline time_t
-get_ical_start_time (icalcomponent *ical,
- icaltimezone *default_zone)
-{
- return get_time_from_property (ical,
- ICAL_DTSTART_PROPERTY,
- icalproperty_get_dtstart,
- default_zone);
-}
-
-static inline time_t
-get_ical_end_time (icalcomponent *ical,
- icaltimezone *default_zone)
-{
- return get_time_from_property (ical,
- ICAL_DTEND_PROPERTY,
- icalproperty_get_dtend,
- default_zone);
-}
-
-static gboolean
-get_ical_is_all_day (icalcomponent *ical,
- time_t start_time,
- icaltimezone *default_zone)
-{
- icalproperty *prop;
- struct tm *start_tm;
- time_t end_time;
- struct icaldurationtype duration;
- struct icaltimetype start_icaltime;
-
- start_icaltime = icalcomponent_get_dtstart (ical);
- if (start_icaltime.is_date)
- return TRUE;
-
- start_tm = gmtime (&start_time);
- if (start_tm->tm_sec != 0 ||
- start_tm->tm_min != 0 ||
- start_tm->tm_hour != 0)
- return FALSE;
-
- if ((end_time = get_ical_end_time (ical, default_zone)))
- return (end_time - start_time) % 86400 == 0;
-
- prop = icalcomponent_get_first_property (ical, ICAL_DURATION_PROPERTY);
- if (!prop)
- return FALSE;
-
- duration = icalproperty_get_duration (prop);
-
- return icaldurationtype_as_int (duration) % 86400 == 0;
-}
-
-static inline time_t
-get_ical_due_time (icalcomponent *ical,
- icaltimezone *default_zone)
-{
- return get_time_from_property (ical,
- ICAL_DUE_PROPERTY,
- icalproperty_get_due,
- default_zone);
-}
-
-static guint
-get_ical_percent_complete (icalcomponent *ical)
-{
- icalproperty *prop;
- icalproperty_status status;
- int percent_complete;
-
- status = icalcomponent_get_status (ical);
- if (status == ICAL_STATUS_COMPLETED)
- return 100;
-
- prop = icalcomponent_get_first_property (ical, ICAL_COMPLETED_PROPERTY);
- if (prop)
- return 100;
-
- prop = icalcomponent_get_first_property (ical, ICAL_PERCENTCOMPLETE_PROPERTY);
- if (!prop)
- return 0;
-
- percent_complete = icalproperty_get_percentcomplete (prop);
-
- return CLAMP (percent_complete, 0, 100);
-}
-
-static inline time_t
-get_ical_completed_time (icalcomponent *ical,
- icaltimezone *default_zone)
-{
- return get_time_from_property (ical,
- ICAL_COMPLETED_PROPERTY,
- icalproperty_get_completed,
- default_zone);
-}
-
-static int
-get_ical_priority (icalcomponent *ical)
-{
- icalproperty *prop;
-
- prop = icalcomponent_get_first_property (ical, ICAL_PRIORITY_PROPERTY);
- if (!prop)
- return -1;
-
- return icalproperty_get_priority (prop);
-}
-
-static char *
-get_source_color (ECal *esource)
-{
- ESource *source;
-
- g_return_val_if_fail (E_IS_CAL (esource), NULL);
-
- source = e_cal_get_source (esource);
-
- return g_strdup (e_source_peek_color_spec (source));
-}
-
-static gchar *
-get_source_uri (ECal *esource)
-{
- ESource *source;
- gchar *string;
- gchar **list;
-
- g_return_val_if_fail (E_IS_CAL (esource), NULL);
-
- source = e_cal_get_source (esource);
- string = g_strdup (e_source_get_uri (source));
- if (string) {
- list = g_strsplit (string, ":", 2);
- g_free (string);
-
- if (list[0]) {
- string = g_strdup (list[0]);
- g_strfreev (list);
- return string;
- }
- g_strfreev (list);
- }
- return NULL;
-}
-
-static inline int
-null_safe_strcmp (const char *a,
- const char *b)
-{
- return (!a && !b) ? 0 : (a && !b) || (!a && b) ? 1 : strcmp (a, b);
-}
-
-static inline gboolean
-calendar_appointment_equal (CalendarAppointment *a,
- CalendarAppointment *b)
-{
- GSList *la, *lb;
-
- if (g_slist_length (a->occurrences) != g_slist_length (b->occurrences))
- return FALSE;
-
- for (la = a->occurrences, lb = b->occurrences; la && lb; la = la->next, lb = lb->next)
- {
- CalendarOccurrence *oa = la->data;
- CalendarOccurrence *ob = lb->data;
-
- if (oa->start_time != ob->start_time ||
- oa->end_time != ob->end_time)
- return FALSE;
- }
-
- return
- null_safe_strcmp (a->uid, b->uid) == 0 &&
- null_safe_strcmp (a->uri, b->uri) == 0 &&
- null_safe_strcmp (a->summary, b->summary) == 0 &&
- null_safe_strcmp (a->description, b->description) == 0 &&
- null_safe_strcmp (a->color_string, b->color_string) == 0 &&
- a->start_time == b->start_time &&
- a->end_time == b->end_time &&
- a->is_all_day == b->is_all_day;
-}
-
-static void
-calendar_appointment_copy (CalendarAppointment *appointment,
- CalendarAppointment *appointment_copy)
-{
- GSList *l;
-
- g_assert (appointment != NULL);
- g_assert (appointment_copy != NULL);
-
- appointment_copy->occurrences = g_slist_copy (appointment->occurrences);
- for (l = appointment_copy->occurrences; l; l = l->next)
- {
- CalendarOccurrence *occurrence = l->data;
- CalendarOccurrence *occurrence_copy;
-
- occurrence_copy = g_new0 (CalendarOccurrence, 1);
- occurrence_copy->start_time = occurrence->start_time;
- occurrence_copy->end_time = occurrence->end_time;
-
- l->data = occurrence_copy;
- }
-
- appointment_copy->uid = g_strdup (appointment->uid);
- appointment_copy->uri = g_strdup (appointment->uri);
- appointment_copy->summary = g_strdup (appointment->summary);
- appointment_copy->description = g_strdup (appointment->description);
- appointment_copy->color_string = g_strdup (appointment->color_string);
- appointment_copy->start_time = appointment->start_time;
- appointment_copy->end_time = appointment->end_time;
- appointment_copy->is_all_day = appointment->is_all_day;
-}
-
-static void
-calendar_appointment_finalize (CalendarAppointment *appointment)
-{
- GSList *l;
-
- for (l = appointment->occurrences; l; l = l->next)
- g_free (l->data);
- g_slist_free (appointment->occurrences);
- appointment->occurrences = NULL;
-
- g_free (appointment->uid);
- appointment->uid = NULL;
-
- g_free (appointment->rid);
- appointment->rid = NULL;
-
- g_free (appointment->uri);
- appointment->uri = NULL;
-
- g_free (appointment->summary);
- appointment->summary = NULL;
-
- g_free (appointment->description);
- appointment->description = NULL;
-
- g_free (appointment->color_string);
- appointment->color_string = NULL;
-
- appointment->start_time = 0;
- appointment->is_all_day = FALSE;
-}
-
-static void
-calendar_appointment_init (CalendarAppointment *appointment,
- icalcomponent *ical,
- CalendarClientSource *source,
- icaltimezone *default_zone)
-{
- appointment->uid = get_ical_uid (ical);
- appointment->rid = get_ical_rid (ical);
- appointment->uri = get_source_uri (source->source);
- appointment->summary = get_ical_summary (ical);
- appointment->description = get_ical_description (ical);
- appointment->color_string = get_source_color (source->source);
- appointment->start_time = get_ical_start_time (ical, default_zone);
- appointment->end_time = get_ical_end_time (ical, default_zone);
- appointment->is_all_day = get_ical_is_all_day (ical,
- appointment->start_time,
- default_zone);
-}
-
-static icaltimezone *
-resolve_timezone_id (const char *tzid,
- ECal *source)
-{
- icaltimezone *retval;
-
- retval = icaltimezone_get_builtin_timezone_from_tzid (tzid);
- if (!retval)
- {
- e_cal_get_timezone (source, tzid, &retval, NULL);
- }
-
- return retval;
-}
-
-static gboolean
-calendar_appointment_collect_occurrence (ECalComponent *component,
- time_t occurrence_start,
- time_t occurrence_end,
- gpointer data)
-{
- CalendarOccurrence *occurrence;
- GSList **collect_loc = data;
-
- occurrence = g_new0 (CalendarOccurrence, 1);
- occurrence->start_time = occurrence_start;
- occurrence->end_time = occurrence_end;
-
- *collect_loc = g_slist_prepend (*collect_loc, occurrence);
-
- return TRUE;
-}
-
-static void
-calendar_appointment_generate_ocurrences (CalendarAppointment *appointment,
- icalcomponent *ical,
- ECal *source,
- time_t start,
- time_t end,
- icaltimezone *default_zone)
-{
- ECalComponent *ecal;
-
- g_assert (appointment->occurrences == NULL);
-
- ecal = e_cal_component_new ();
- e_cal_component_set_icalcomponent (ecal,
- icalcomponent_new_clone (ical));
-
- e_cal_recur_generate_instances (ecal,
- start,
- end,
- calendar_appointment_collect_occurrence,
- &appointment->occurrences,
- (ECalRecurResolveTimezoneFn) resolve_timezone_id,
- source,
- default_zone);
-
- g_object_unref (ecal);
-
- appointment->occurrences = g_slist_reverse (appointment->occurrences);
-}
-
-static inline gboolean
-calendar_task_equal (CalendarTask *a,
- CalendarTask *b)
-{
- return
- null_safe_strcmp (a->uid, b->uid) == 0 &&
- null_safe_strcmp (a->summary, b->summary) == 0 &&
- null_safe_strcmp (a->description, b->description) == 0 &&
- null_safe_strcmp (a->color_string, b->color_string) == 0 &&
- a->start_time == b->start_time &&
- a->due_time == b->due_time &&
- a->percent_complete == b->percent_complete &&
- a->completed_time == b->completed_time &&
- a->priority == b->priority;
-}
-
-static void
-calendar_task_copy (CalendarTask *task,
- CalendarTask *task_copy)
-{
- g_assert (task != NULL);
- g_assert (task_copy != NULL);
-
- task_copy->uid = g_strdup (task->uid);
- task_copy->summary = g_strdup (task->summary);
- task_copy->description = g_strdup (task->description);
- task_copy->color_string = g_strdup (task->color_string);
- task_copy->start_time = task->start_time;
- task_copy->due_time = task->due_time;
- task_copy->percent_complete = task->percent_complete;
- task_copy->completed_time = task->completed_time;
- task_copy->priority = task->priority;
-}
-
-static void
-calendar_task_finalize (CalendarTask *task)
-{
- g_free (task->uid);
- task->uid = NULL;
-
- g_free (task->summary);
- task->summary = NULL;
-
- g_free (task->description);
- task->description = NULL;
-
- g_free (task->color_string);
- task->color_string = NULL;
-
- task->percent_complete = 0;
-}
-
-static void
-calendar_task_init (CalendarTask *task,
- icalcomponent *ical,
- CalendarClientSource *source,
- icaltimezone *default_zone)
-{
- task->uid = get_ical_uid (ical);
- task->summary = get_ical_summary (ical);
- task->description = get_ical_description (ical);
- task->color_string = get_source_color (source->source);
- task->start_time = get_ical_start_time (ical, default_zone);
- task->due_time = get_ical_due_time (ical, default_zone);
- task->percent_complete = get_ical_percent_complete (ical);
- task->completed_time = get_ical_completed_time (ical, default_zone);
- task->priority = get_ical_priority (ical);
-}
-
-void
-calendar_event_free (CalendarEvent *event)
-{
- switch (event->type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- calendar_appointment_finalize (CALENDAR_APPOINTMENT (event));
- break;
- case CALENDAR_EVENT_TASK:
- calendar_task_finalize (CALENDAR_TASK (event));
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- g_free (event);
-}
-
-static CalendarEvent *
-calendar_event_new (icalcomponent *ical,
- CalendarClientSource *source,
- icaltimezone *default_zone)
-{
- CalendarEvent *event;
-
- event = g_new0 (CalendarEvent, 1);
-
- switch (icalcomponent_isa (ical))
- {
- case ICAL_VEVENT_COMPONENT:
- event->type = CALENDAR_EVENT_APPOINTMENT;
- calendar_appointment_init (CALENDAR_APPOINTMENT (event),
- ical,
- source,
- default_zone);
- break;
- case ICAL_VTODO_COMPONENT:
- event->type = CALENDAR_EVENT_TASK;
- calendar_task_init (CALENDAR_TASK (event),
- ical,
- source,
- default_zone);
- break;
- default:
- g_warning ("Unknown calendar component type: %d\n",
- icalcomponent_isa (ical));
- g_free (event);
- return NULL;
- }
-
- return event;
-}
-
-static CalendarEvent *
-calendar_event_copy (CalendarEvent *event)
-{
- CalendarEvent *retval;
-
- if (!event)
- return NULL;
-
- retval = g_new0 (CalendarEvent, 1);
-
- retval->type = event->type;
-
- switch (event->type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- calendar_appointment_copy (CALENDAR_APPOINTMENT (event),
- CALENDAR_APPOINTMENT (retval));
- break;
- case CALENDAR_EVENT_TASK:
- calendar_task_copy (CALENDAR_TASK (event),
- CALENDAR_TASK (retval));
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- return retval;
-}
-
-static char *
-calendar_event_get_uid (CalendarEvent *event)
-{
- switch (event->type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- return g_strdup_printf ("%s%s", CALENDAR_APPOINTMENT (event)->uid, CALENDAR_APPOINTMENT (event)->rid ? CALENDAR_APPOINTMENT (event)->rid : "");
- break;
- case CALENDAR_EVENT_TASK:
- return g_strdup (CALENDAR_TASK (event)->uid);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- return NULL;
-}
-
-static gboolean
-calendar_event_equal (CalendarEvent *a,
- CalendarEvent *b)
-{
- if (!a && !b)
- return TRUE;
-
- if ((a && !b) || (!a && b))
- return FALSE;
-
- if (a->type != b->type)
- return FALSE;
-
- switch (a->type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- return calendar_appointment_equal (CALENDAR_APPOINTMENT (a),
- CALENDAR_APPOINTMENT (b));
- case CALENDAR_EVENT_TASK:
- return calendar_task_equal (CALENDAR_TASK (a),
- CALENDAR_TASK (b));
- default:
- break;
- }
-
- g_assert_not_reached ();
-
- return FALSE;
-}
-
-static void
-calendar_event_generate_ocurrences (CalendarEvent *event,
- icalcomponent *ical,
- ECal *source,
- time_t start,
- time_t end,
- icaltimezone *default_zone)
-{
- if (event->type != CALENDAR_EVENT_APPOINTMENT)
- return;
-
- calendar_appointment_generate_ocurrences (CALENDAR_APPOINTMENT (event),
- ical,
- source,
- start,
- end,
- default_zone);
-}
-
-static inline void
-calendar_event_debug_dump (CalendarEvent *event)
-{
-#ifdef CALENDAR_ENABLE_DEBUG
- switch (event->type)
- {
- case CALENDAR_EVENT_APPOINTMENT:
- {
- char *start_str;
- char *end_str;
- GSList *l;
-
- start_str = CALENDAR_APPOINTMENT (event)->start_time ?
- isodate_from_time_t (CALENDAR_APPOINTMENT (event)->start_time) :
- g_strdup ("(undefined)");
- end_str = CALENDAR_APPOINTMENT (event)->end_time ?
- isodate_from_time_t (CALENDAR_APPOINTMENT (event)->end_time) :
- g_strdup ("(undefined)");
-
- dprintf ("Appointment: uid '%s', summary '%s', description '%s', "
- "start_time '%s', end_time '%s', is_all_day %s\n",
- CALENDAR_APPOINTMENT (event)->uid,
- CALENDAR_APPOINTMENT (event)->summary,
- CALENDAR_APPOINTMENT (event)->description,
- start_str,
- end_str,
- CALENDAR_APPOINTMENT (event)->is_all_day ? "(true)" : "(false)");
-
- g_free (start_str);
- g_free (end_str);
-
- dprintf (" Occurrences:\n");
- for (l = CALENDAR_APPOINTMENT (event)->occurrences; l; l = l->next)
- {
- CalendarOccurrence *occurrence = l->data;
-
- start_str = occurrence->start_time ?
- isodate_from_time_t (occurrence->start_time) :
- g_strdup ("(undefined)");
-
- end_str = occurrence->end_time ?
- isodate_from_time_t (occurrence->end_time) :
- g_strdup ("(undefined)");
-
- dprintf (" start_time '%s', end_time '%s'\n",
- start_str, end_str);
-
- g_free (start_str);
- g_free (end_str);
- }
- }
- break;
- case CALENDAR_EVENT_TASK:
- {
- char *start_str;
- char *due_str;
- char *completed_str;
-
- start_str = CALENDAR_TASK (event)->start_time ?
- isodate_from_time_t (CALENDAR_TASK (event)->start_time) :
- g_strdup ("(undefined)");
- due_str = CALENDAR_TASK (event)->due_time ?
- isodate_from_time_t (CALENDAR_TASK (event)->due_time) :
- g_strdup ("(undefined)");
- completed_str = CALENDAR_TASK (event)->completed_time ?
- isodate_from_time_t (CALENDAR_TASK (event)->completed_time) :
- g_strdup ("(undefined)");
-
- dprintf ("Task: uid '%s', summary '%s', description '%s', "
- "start_time '%s', due_time '%s', percent_complete %d, completed_time '%s'\n",
- CALENDAR_TASK (event)->uid,
- CALENDAR_TASK (event)->summary,
- CALENDAR_TASK (event)->description,
- start_str,
- due_str,
- CALENDAR_TASK (event)->percent_complete,
- completed_str);
-
- g_free (completed_str);
- }
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-#endif
-}
-
-static inline CalendarClientQuery *
-goddamn_this_is_crack (CalendarClientSource *source,
- ECalView *view,
- gboolean *emit_signal)
-{
- g_assert (view != NULL);
-
- if (source->completed_query.view == view)
- {
- if (emit_signal)
- *emit_signal = TRUE;
- return &source->completed_query;
- }
- else if (source->in_progress_query.view == view)
- {
- if (emit_signal)
- *emit_signal = FALSE;
- return &source->in_progress_query;
- }
-
- g_assert_not_reached ();
-
- return NULL;
-}
-
-static void
-calendar_client_handle_query_completed (CalendarClientSource *source,
- ECalendarStatus status,
- ECalView *view)
-{
- CalendarClientQuery *query;
-
- query = goddamn_this_is_crack (source, view, NULL);
-
- dprintf ("Query %p completed: %s\n", query, e_cal_get_error_message (status));
-
- if (status != E_CALENDAR_STATUS_OK)
- {
- g_warning ("Calendar query failed: %s\n",
- e_cal_get_error_message (status));
- calendar_client_stop_query (source->client, source, query);
- return;
- }
-
- g_assert (source->query_in_progress != FALSE);
- g_assert (query == &source->in_progress_query);
-
- calendar_client_query_finalize (&source->completed_query);
-
- source->completed_query = source->in_progress_query;
- source->query_completed = TRUE;
-
- source->query_in_progress = FALSE;
- source->in_progress_query.view = NULL;
- source->in_progress_query.events = NULL;
-
- g_signal_emit (source->client, source->changed_signal_id, 0);
-}
-
-static void
-calendar_client_handle_query_result (CalendarClientSource *source,
- GList *objects,
- ECalView *view)
-{
- CalendarClientQuery *query;
- CalendarClient *client;
- gboolean emit_signal;
- gboolean events_changed;
- GList *l;
- time_t month_begin;
- time_t month_end;
-
- client = source->client;
-
- query = goddamn_this_is_crack (source, view, &emit_signal);
-
- dprintf ("Query %p result: %d objects:\n",
- query, g_list_length (objects));
-
- month_begin = make_time_for_day_begin (1,
- client->priv->month,
- client->priv->year);
-
- month_end = make_time_for_day_begin (1,
- client->priv->month + 1,
- client->priv->year);
-
- events_changed = FALSE;
- for (l = objects; l; l = l->next)
- {
- CalendarEvent *event;
- CalendarEvent *old_event;
- icalcomponent *ical = l->data;
- char *uid;
-
- event = calendar_event_new (ical, source, client->priv->zone);
- if (!event)
- continue;
-
- calendar_event_generate_ocurrences (event,
- ical,
- source->source,
- month_begin,
- month_end,
- client->priv->zone);
-
- uid = calendar_event_get_uid (event);
-
- old_event = g_hash_table_lookup (query->events, uid);
-
- if (!calendar_event_equal (event, old_event))
- {
- dprintf ("Event %s: ", old_event ? "modified" : "added");
-
- calendar_event_debug_dump (event);
-
- g_hash_table_replace (query->events, uid, event);
-
- events_changed = TRUE;
- }
- else
- {
- g_free (uid);
- }
- }
-
- if (emit_signal && events_changed)
- {
- g_signal_emit (source->client, source->changed_signal_id, 0);
- }
-}
-
-static gboolean
-check_object_remove (gpointer key,
- gpointer value,
- gpointer data)
-{
- char *uid = data;
- ssize_t len;
-
- len = strlen (uid);
-
- if (len <= strlen (key) && strncmp (uid, key, len) == 0)
- {
- dprintf ("Event removed: ");
-
- calendar_event_debug_dump (value);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-calendar_client_handle_objects_removed (CalendarClientSource *source,
- GList *ids,
- ECalView *view)
-{
- CalendarClientQuery *query;
- gboolean emit_signal;
- gboolean events_changed;
- GList *l;
-
- query = goddamn_this_is_crack (source, view, &emit_signal);
-
- events_changed = FALSE;
- for (l = ids; l; l = l->next)
- {
- CalendarEvent *event;
- ECalComponentId *id = l->data;
- char *uid = g_strdup_printf ("%s%s", id->uid, id->rid ? id->rid : "");
-
- if (!id->rid || !(*id->rid))
- {
- int size = g_hash_table_size (query->events);
-
- g_hash_table_foreach_remove (query->events, check_object_remove, id->uid);
-
- if (size != g_hash_table_size (query->events))
- events_changed = TRUE;
- }
- else if ((event = g_hash_table_lookup (query->events, uid)))
- {
- dprintf ("Event removed: ");
-
- calendar_event_debug_dump (event);
-
- g_assert (g_hash_table_remove (query->events, uid));
-
- events_changed = TRUE;
- }
- g_free (uid);
- }
-
- if (emit_signal && events_changed)
- {
- g_signal_emit (source->client, source->changed_signal_id, 0);
- }
-}
-
-static void
-calendar_client_query_finalize (CalendarClientQuery *query)
-{
- if (query->view)
- g_object_unref (query->view);
- query->view = NULL;
-
- if (query->events)
- g_hash_table_destroy (query->events);
- query->events = NULL;
-}
-
-static void
-calendar_client_stop_query (CalendarClient *client,
- CalendarClientSource *source,
- CalendarClientQuery *query)
-{
- if (query == &source->in_progress_query)
- {
- dprintf ("Stopping in progress query %p\n", query);
-
- g_assert (source->query_in_progress != FALSE);
-
- source->query_in_progress = FALSE;
- }
- else if (query == &source->completed_query)
- {
- dprintf ("Stopping completed query %p\n", query);
-
- g_assert (source->query_completed != FALSE);
-
- source->query_completed = FALSE;
- }
- else
- g_assert_not_reached ();
-
- calendar_client_query_finalize (query);
-}
-
-static void
-calendar_client_start_query (CalendarClient *client,
- CalendarClientSource *source,
- const char *query)
-{
- ECalView *view = NULL;
- GError *error = NULL;
-
- if (!e_cal_get_query (source->source, query, &view, &error))
- {
- g_warning ("Error preparing the query: '%s': %s\n",
- query, error->message);
- g_error_free (error);
- return;
- }
-
- g_assert (view != NULL);
-
- if (source->query_in_progress)
- calendar_client_stop_query (client, source, &source->in_progress_query);
-
- dprintf ("Starting query %p: '%s'\n", &source->in_progress_query, query);
-
- source->query_in_progress = TRUE;
- source->in_progress_query.view = view;
- source->in_progress_query.events =
- g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify) calendar_event_free);
-
- g_signal_connect_swapped (view, "objects-added",
- G_CALLBACK (calendar_client_handle_query_result),
- source);
- g_signal_connect_swapped (view, "objects-modified",
- G_CALLBACK (calendar_client_handle_query_result),
- source);
- g_signal_connect_swapped (view, "objects-removed",
- G_CALLBACK (calendar_client_handle_objects_removed),
- source);
- g_signal_connect_swapped (view, "view-done",
- G_CALLBACK (calendar_client_handle_query_completed),
- source);
-
- e_cal_view_start (view);
-}
-
-static void
-calendar_client_update_appointments (CalendarClient *client)
-{
- GSList *l;
- char *query;
- char *month_begin;
- char *month_end;
-
- if (client->priv->month == -1 ||
- client->priv->year == -1)
- return;
-
- month_begin = make_isodate_for_day_begin (1,
- client->priv->month,
- client->priv->year);
-
- month_end = make_isodate_for_day_begin (1,
- client->priv->month + 1,
- client->priv->year);
-
- query = g_strdup_printf ("occur-in-time-range? (make-time \"%s\") "
- "(make-time \"%s\")",
- month_begin, month_end);
-
- for (l = client->priv->appointment_sources; l; l = l->next)
- {
- CalendarClientSource *cs = l->data;
-
- if (e_cal_get_load_state (cs->source) != E_CAL_LOAD_LOADED)
- continue;
-
- calendar_client_start_query (client, cs, query);
- }
-
- g_free (month_begin);
- g_free (month_end);
- g_free (query);
-}
-
-/* FIXME:
- * perhaps we should use evo's "hide_completed_tasks" pref?
- */
-static void
-calendar_client_update_tasks (CalendarClient *client)
-{
- GSList *l;
- char *query;
-
-#ifdef FIX_BROKEN_TASKS_QUERY
- /* FIXME: this doesn't work for tasks without a start or
- * due date
- * Look at filter_task() to see the behaviour we
- * want.
- */
-
- char *day_begin;
- char *day_end;
-
- if (client->priv->day == -1 ||
- client->priv->month == -1 ||
- client->priv->year == -1)
- return;
-
- day_begin = make_isodate_for_day_begin (client->priv->day,
- client->priv->month,
- client->priv->year);
-
- day_end = make_isodate_for_day_begin (client->priv->day + 1,
- client->priv->month,
- client->priv->year);
- if (!day_begin || !day_end)
- {
- g_warning ("Cannot run query with invalid date: %dd %dy %dm\n",
- client->priv->day,
- client->priv->month,
- client->priv->year);
- g_free (day_begin);
- g_free (day_end);
- return;
- }
-
- query = g_strdup_printf ("(and (occur-in-time-range? (make-time \"%s\") "
- "(make-time \"%s\")) "
- "(or (not is-completed?) "
- "(and (is-completed?) "
- "(not (completed-before? (make-time \"%s\"))))))",
- day_begin, day_end, day_begin);
-#else
- query = g_strdup ("#t");
-#endif /* FIX_BROKEN_TASKS_QUERY */
-
- for (l = client->priv->task_sources; l; l = l->next)
- {
- CalendarClientSource *cs = l->data;
-
- if (e_cal_get_load_state (cs->source) != E_CAL_LOAD_LOADED)
- continue;
-
- calendar_client_start_query (client, cs, query);
- }
-
-#ifdef FIX_BROKEN_TASKS_QUERY
- g_free (day_begin);
- g_free (day_end);
-#endif
- g_free (query);
-}
-
-static void
-calendar_client_source_finalize (CalendarClientSource *source)
-{
- source->client = NULL;
-
- if (source->source) {
- g_signal_handlers_disconnect_by_func (source->source,
- cal_opened_cb, source);
- g_object_unref (source->source);
- }
- source->source = NULL;
-
- calendar_client_query_finalize (&source->completed_query);
- calendar_client_query_finalize (&source->in_progress_query);
-
- source->query_completed = FALSE;
- source->query_in_progress = FALSE;
-}
-
-static int
-compare_calendar_sources (CalendarClientSource *s1,
- CalendarClientSource *s2)
-{
- return (s1->source == s2->source) ? 0 : 1;
-}
-
-static GSList *
-calendar_client_update_sources_list (CalendarClient *client,
- GSList *sources,
- GSList *esources,
- guint changed_signal_id)
-{
- GSList *retval, *l;
-
- retval = NULL;
-
- for (l = esources; l; l = l->next)
- {
- CalendarClientSource dummy_source;
- CalendarClientSource *new_source;
- GSList *s;
- ECal *esource = l->data;
-
- dummy_source.source = esource;
-
- dprintf ("update_sources_list: adding client %s: ",
- e_source_peek_uid (e_cal_get_source (esource)));
-
- if ((s = g_slist_find_custom (sources,
- &dummy_source,
- (GCompareFunc) compare_calendar_sources)))
- {
- dprintf ("already on list\n");
- new_source = s->data;
- sources = g_slist_delete_link (sources, s);
- }
- else
- {
- dprintf ("added\n");
- new_source = g_new0 (CalendarClientSource, 1);
- new_source->client = client;
- new_source->source = g_object_ref (esource);
- new_source->changed_signal_id = changed_signal_id;
- }
-
- retval = g_slist_prepend (retval, new_source);
- }
-
- for (l = sources; l; l = l->next)
- {
- CalendarClientSource *source = l->data;
-
- dprintf ("Removing client %s from list\n",
- e_source_peek_uid (e_cal_get_source (source->source)));
-
- calendar_client_source_finalize (source);
- g_free (source);
- }
- g_slist_free (sources);
-
- return retval;
-}
-
-static void
-calendar_client_appointment_sources_changed (CalendarClient *client)
-{
- GSList *esources;
-
- dprintf ("appointment_sources_changed: updating ...\n");
-
- esources = calendar_sources_get_appointment_sources (client->priv->calendar_sources);
-
- client->priv->appointment_sources =
- calendar_client_update_sources_list (client,
- client->priv->appointment_sources,
- esources,
- signals [APPOINTMENTS_CHANGED]);
-
- load_calendars (client, CALENDAR_EVENT_APPOINTMENT);
- calendar_client_update_appointments (client);
-}
-
-static void
-calendar_client_task_sources_changed (CalendarClient *client)
-{
- GSList *esources;
-
- dprintf ("task_sources_changed: updating ...\n");
-
- esources = calendar_sources_get_task_sources (client->priv->calendar_sources);
-
- client->priv->task_sources =
- calendar_client_update_sources_list (client,
- client->priv->task_sources,
- esources,
- signals [TASKS_CHANGED]);
-
- load_calendars (client, CALENDAR_EVENT_TASK);
- calendar_client_update_tasks (client);
-}
-
-void
-calendar_client_get_date (CalendarClient *client,
- guint *year,
- guint *month,
- guint *day)
-{
- g_return_if_fail (CALENDAR_IS_CLIENT (client));
-
- if (year)
- *year = client->priv->year;
-
- if (month)
- *month = client->priv->month;
-
- if (day)
- *day = client->priv->day;
-}
-
-void
-calendar_client_select_month (CalendarClient *client,
- guint month,
- guint year)
-{
- g_return_if_fail (CALENDAR_IS_CLIENT (client));
- g_return_if_fail (month <= 11);
-
- if (client->priv->year != year || client->priv->month != month)
- {
- client->priv->month = month;
- client->priv->year = year;
-
- calendar_client_update_appointments (client);
- calendar_client_update_tasks (client);
-
- g_object_freeze_notify (G_OBJECT (client));
- g_object_notify (G_OBJECT (client), "month");
- g_object_notify (G_OBJECT (client), "year");
- g_object_thaw_notify (G_OBJECT (client));
- }
-}
-
-void
-calendar_client_select_day (CalendarClient *client,
- guint day)
-{
- g_return_if_fail (CALENDAR_IS_CLIENT (client));
- g_return_if_fail (day <= 31);
-
- if (client->priv->day != day)
- {
- client->priv->day = day;
-
- /* don't need to update appointments unless
- * the selected month changes
- */
-#ifdef FIX_BROKEN_TASKS_QUERY
- calendar_client_update_tasks (client);
-#endif
-
- g_object_notify (G_OBJECT (client), "day");
- }
-}
-
-typedef struct
-{
- CalendarClient *client;
- GSList *events;
- time_t start_time;
- time_t end_time;
-} FilterData;
-
-typedef void (* CalendarEventFilterFunc) (const char *uid,
- CalendarEvent *event,
- FilterData *filter_data);
-
-static void
-filter_appointment (const char *uid,
- CalendarEvent *event,
- FilterData *filter_data)
-{
- GSList *occurrences, *l;
-
- if (event->type != CALENDAR_EVENT_APPOINTMENT)
- return;
-
- occurrences = CALENDAR_APPOINTMENT (event)->occurrences;
- CALENDAR_APPOINTMENT (event)->occurrences = NULL;
-
- for (l = occurrences; l; l = l->next)
- {
- CalendarOccurrence *occurrence = l->data;
- time_t start_time = occurrence->start_time;
- time_t end_time = occurrence->end_time;
-
- if ((start_time >= filter_data->start_time &&
- start_time < filter_data->end_time) ||
- (start_time <= filter_data->start_time &&
- (end_time - 1) > filter_data->start_time))
- {
- CalendarEvent *new_event;
-
- new_event = calendar_event_copy (event);
-
- CALENDAR_APPOINTMENT (new_event)->start_time = occurrence->start_time;
- CALENDAR_APPOINTMENT (new_event)->end_time = occurrence->end_time;
-
- filter_data->events = g_slist_prepend (filter_data->events, new_event);
- }
- }
-
- CALENDAR_APPOINTMENT (event)->occurrences = occurrences;
-}
-
-static void
-filter_task (const char *uid,
- CalendarEvent *event,
- FilterData *filter_data)
-{
-#ifdef FIX_BROKEN_TASKS_QUERY
- CalendarTask *task;
-#endif
-
- if (event->type != CALENDAR_EVENT_TASK)
- return;
-
-#ifdef FIX_BROKEN_TASKS_QUERY
- task = CALENDAR_TASK (event);
-
- if (task->start_time && task->start_time > filter_data->start_time)
- return;
-
- if (task->completed_time &&
- (task->completed_time < filter_data->start_time ||
- task->completed_time > filter_data->end_time))
- return;
-#endif /* FIX_BROKEN_TASKS_QUERY */
-
- filter_data->events = g_slist_prepend (filter_data->events,
- calendar_event_copy (event));
-}
-
-static GSList *
-calendar_client_filter_events (CalendarClient *client,
- GSList *sources,
- CalendarEventFilterFunc filter_func,
- time_t start_time,
- time_t end_time)
-{
- FilterData filter_data;
- GSList *l;
- GSList *retval;
-
- if (!sources)
- return NULL;
-
- filter_data.client = client;
- filter_data.events = NULL;
- filter_data.start_time = start_time;
- filter_data.end_time = end_time;
-
- retval = NULL;
- for (l = sources; l; l = l->next)
- {
- CalendarClientSource *source = l->data;
-
- if (source->query_completed)
- {
- filter_data.events = NULL;
- g_hash_table_foreach (source->completed_query.events,
- (GHFunc) filter_func,
- &filter_data);
-
- filter_data.events = g_slist_reverse (filter_data.events);
-
- retval = g_slist_concat (retval, filter_data.events);
- }
- }
-
- return retval;
-}
-
-GSList *
-calendar_client_get_events (CalendarClient *client,
- CalendarEventType event_mask)
-{
- GSList *appointments;
- GSList *tasks;
- time_t day_begin;
- time_t day_end;
-
- g_return_val_if_fail (CALENDAR_IS_CLIENT (client), NULL);
- g_return_val_if_fail (client->priv->day != -1 &&
- client->priv->month != -1 &&
- client->priv->year != -1, NULL);
-
- day_begin = make_time_for_day_begin (client->priv->day,
- client->priv->month,
- client->priv->year);
- day_end = make_time_for_day_begin (client->priv->day + 1,
- client->priv->month,
- client->priv->year);
-
- appointments = NULL;
- if (event_mask & CALENDAR_EVENT_APPOINTMENT)
- {
- appointments = calendar_client_filter_events (client,
- client->priv->appointment_sources,
- filter_appointment,
- day_begin,
- day_end);
- }
-
- tasks = NULL;
- if (event_mask & CALENDAR_EVENT_TASK)
- {
- tasks = calendar_client_filter_events (client,
- client->priv->task_sources,
- filter_task,
- day_begin,
- day_end);
- }
-
- return g_slist_concat (appointments, tasks);
-}
-
-static inline int
-day_from_time_t (time_t t)
-{
- struct tm *tm = localtime (&t);
-
- g_assert (tm == NULL || (tm->tm_mday >=1 && tm->tm_mday <= 31));
-
- return tm ? tm->tm_mday : 0;
-}
-
-void
-calendar_client_foreach_appointment_day (CalendarClient *client,
- CalendarDayIter iter_func,
- gpointer user_data)
-{
- GSList *appointments, *l;
- gboolean marked_days [32] = { FALSE, };
- time_t month_begin;
- time_t month_end;
- int i;
-
- g_return_if_fail (CALENDAR_IS_CLIENT (client));
- g_return_if_fail (iter_func != NULL);
- g_return_if_fail (client->priv->month != -1 &&
- client->priv->year != -1);
-
- month_begin = make_time_for_day_begin (1,
- client->priv->month,
- client->priv->year);
- month_end = make_time_for_day_begin (1,
- client->priv->month + 1,
- client->priv->year);
-
- appointments = calendar_client_filter_events (client,
- client->priv->appointment_sources,
- filter_appointment,
- month_begin,
- month_end);
- for (l = appointments; l; l = l->next)
- {
- CalendarAppointment *appointment = l->data;
-
- if (appointment->start_time)
- {
- time_t day_time = appointment->start_time;
-
- if (day_time >= month_begin)
- marked_days [day_from_time_t (day_time)] = TRUE;
-
- if (appointment->end_time)
- {
- int day_offset;
- int duration = appointment->end_time - appointment->start_time;
- /* mark the days for the appointment, no need to add an extra one when duration is a multiple of 86400 */
- for (day_offset = 1; day_offset <= duration / 86400 && duration != day_offset * 86400; day_offset++)
- {
- time_t day_tm = appointment->start_time + day_offset * 86400;
-
- if (day_tm > month_end)
- break;
- if (day_tm >= month_begin)
- marked_days [day_from_time_t (day_tm)] = TRUE;
- }
- }
- }
- calendar_event_free (CALENDAR_EVENT (appointment));
- }
-
- g_slist_free (appointments);
-
- for (i = 1; i < 32; i++)
- {
- if (marked_days [i])
- iter_func (client, i, user_data);
- }
-}
-
-void
-calendar_client_set_task_completed (CalendarClient *client,
- char *task_uid,
- gboolean task_completed,
- guint percent_complete)
-{
- GSList *l;
- ECal *esource;
- icalcomponent *ical;
- icalproperty *prop;
- icalproperty_status status;
-
- g_return_if_fail (CALENDAR_IS_CLIENT (client));
- g_return_if_fail (task_uid != NULL);
- g_return_if_fail (task_completed == FALSE || percent_complete == 100);
-
- ical = NULL;
- esource = NULL;
- for (l = client->priv->task_sources; l; l = l->next)
- {
- CalendarClientSource *source = l->data;
-
- esource = source->source;
- e_cal_get_object (esource, task_uid, NULL, &ical, NULL);
- if (ical)
- break;
- }
-
- if (!ical)
- {
- g_warning ("Cannot locate task with uid = '%s'\n", task_uid);
- return;
- }
-
- g_assert (esource != NULL);
-
- /* Completed time */
- prop = icalcomponent_get_first_property (ical,
- ICAL_COMPLETED_PROPERTY);
- if (task_completed)
- {
- struct icaltimetype completed_time;
-
- completed_time = icaltime_current_time_with_zone (client->priv->zone);
- if (!prop)
- {
- icalcomponent_add_property (ical,
- icalproperty_new_completed (completed_time));
- }
- else
- {
- icalproperty_set_completed (prop, completed_time);
- }
- }
- else if (prop)
- {
- icalcomponent_remove_property (ical, prop);
- }
-
- /* Percent complete */
- prop = icalcomponent_get_first_property (ical,
- ICAL_PERCENTCOMPLETE_PROPERTY);
- if (!prop)
- {
- icalcomponent_add_property (ical,
- icalproperty_new_percentcomplete (percent_complete));
- }
- else
- {
- icalproperty_set_percentcomplete (prop, percent_complete);
- }
-
- /* Status */
- status = task_completed ? ICAL_STATUS_COMPLETED : ICAL_STATUS_NEEDSACTION;
- prop = icalcomponent_get_first_property (ical, ICAL_STATUS_PROPERTY);
- if (prop)
- {
- icalproperty_set_status (prop, status);
- }
- else
- {
- icalcomponent_add_property (ical,
- icalproperty_new_status (status));
- }
-
- e_cal_modify_object (esource, ical, CALOBJ_MOD_ALL, NULL);
-}
diff --git a/applets/clock/calendar-client.h b/applets/clock/calendar-client.h
deleted file mode 100644
index 9d502ba0..00000000
--- a/applets/clock/calendar-client.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Authors:
- * Mark McLoughlin <[email protected]>
- * William Jon McCann <[email protected]>
- * Martin Grimme <[email protected]>
- * Christian Kellner <[email protected]>
- */
-
-#ifndef __CALENDAR_CLIENT_H__
-#define __CALENDAR_CLIENT_H__
-
-#include <glib-object.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum
-{
- CALENDAR_EVENT_APPOINTMENT = 1 << 0,
- CALENDAR_EVENT_TASK = 1 << 1,
- CALENDAR_EVENT_ALL = (1 << 2) - 1
-} CalendarEventType;
-
-#define CALENDAR_TYPE_CLIENT (calendar_client_get_type ())
-#define CALENDAR_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CALENDAR_TYPE_CLIENT, CalendarClient))
-#define CALENDAR_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CALENDAR_TYPE_CLIENT, CalendarClientClass))
-#define CALENDAR_IS_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CALENDAR_TYPE_CLIENT))
-#define CALENDAR_IS_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CALENDAR_TYPE_CLIENT))
-#define CALENDAR_CLIENT_GET_CLASS(o)(G_TYPE_INSTANCE_GET_CLASS ((o), CALENDAR_TYPE_CLIENT, CalendarClientClass))
-
-typedef struct _CalendarClient CalendarClient;
-typedef struct _CalendarClientClass CalendarClientClass;
-typedef struct _CalendarClientPrivate CalendarClientPrivate;
-
-struct _CalendarClient
-{
- GObject parent;
- CalendarClientPrivate *priv;
-};
-
-struct _CalendarClientClass
-{
- GObjectClass parent_class;
-
- void (* appointments_changed) (CalendarClient *client);
- void (* tasks_changed) (CalendarClient *client);
-};
-
-
-typedef struct
-{
- time_t start_time;
- time_t end_time;
-} CalendarOccurrence;
-
-typedef struct
-{
- char *uid;
- char *rid;
- char *uri;
- char *summary;
- char *description;
- char *color_string;
- time_t start_time;
- time_t end_time;
- guint is_all_day : 1;
-
- /* Only used internally */
- GSList *occurrences;
-} CalendarAppointment;
-
-typedef struct
-{
- char *uid;
- char *summary;
- char *description;
- char *color_string;
- char *url;
- time_t start_time;
- time_t due_time;
- guint percent_complete;
- time_t completed_time;
- int priority;
-} CalendarTask;
-
-typedef struct
-{
- union
- {
- CalendarAppointment appointment;
- CalendarTask task;
- } event;
- CalendarEventType type;
-} CalendarEvent;
-
-#define CALENDAR_EVENT(e) ((CalendarEvent *)(e))
-#define CALENDAR_APPOINTMENT(e) ((CalendarAppointment *)(e))
-#define CALENDAR_TASK(e) ((CalendarTask *)(e))
-
-typedef void (* CalendarDayIter) (CalendarClient *client,
- guint day,
- gpointer user_data);
-
-
-GType calendar_client_get_type (void) G_GNUC_CONST;
-CalendarClient *calendar_client_new (void);
-
-void calendar_client_get_date (CalendarClient *client,
- guint *year,
- guint *month,
- guint *day);
-void calendar_client_select_month (CalendarClient *client,
- guint month,
- guint year);
-void calendar_client_select_day (CalendarClient *client,
- guint day);
-
-GSList *calendar_client_get_events (CalendarClient *client,
- CalendarEventType event_mask);
-void calendar_client_foreach_appointment_day (CalendarClient *client,
- CalendarDayIter iter_func,
- gpointer user_data);
-
-void calendar_client_set_task_completed (CalendarClient *client,
- char *task_uid,
- gboolean task_completed,
- guint percent_complete);
-
-void calendar_event_free (CalendarEvent *event);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CALENDAR_CLIENT_H__ */
diff --git a/applets/clock/calendar-debug.h b/applets/clock/calendar-debug.h
deleted file mode 100644
index a7ea2a79..00000000
--- a/applets/clock/calendar-debug.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Authors:
- * Mark McLoughlin <[email protected]>
- */
-
-#ifndef __CALENDAR_DEBUG_H__
-#define __CALENDAR_DEBUG_H__
-
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef CALENDAR_ENABLE_DEBUG
-
-#include <stdio.h>
-
-#ifdef G_HAVE_ISO_VARARGS
-# define dprintf(...) fprintf (stderr, __VA_ARGS__);
-#elif defined(G_HAVE_GNUC_VARARGS)
-# define dprintf(args...) fprintf (stderr, args);
-#endif
-
-#else /* if !defined (CALENDAR_DEBUG) */
-
-#ifdef G_HAVE_ISO_VARARGS
-# define dprintf(...)
-#elif defined(G_HAVE_GNUC_VARARGS)
-# define dprintf(args...)
-#endif
-
-#endif /* CALENDAR_ENABLE_DEBUG */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CALENDAR_DEBUG_H__ */
diff --git a/applets/clock/calendar-sources.c b/applets/clock/calendar-sources.c
deleted file mode 100644
index 721ff062..00000000
--- a/applets/clock/calendar-sources.c
+++ /dev/null
@@ -1,658 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Authors:
- * Mark McLoughlin <[email protected]>
- * William Jon McCann <[email protected]>
- * Martin Grimme <[email protected]>
- * Christian Kellner <[email protected]>
- */
-
-#include <config.h>
-
-#include "calendar-sources.h"
-
-#include <libintl.h>
-#include <string.h>
-#include <mateconf/mateconf-client.h>
-#define HANDLE_LIBICAL_MEMORY
-#include <libecal/e-cal.h>
-#include <libedataserver/e-source-list.h>
-#include <libedataserverui/e-passwords.h>
-
-#undef CALENDAR_ENABLE_DEBUG
-#include "calendar-debug.h"
-
-#ifndef _
-#define _(x) gettext(x)
-#endif
-
-#ifndef N_
-#define N_(x) x
-#endif
-
-#define CALENDAR_SOURCES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CALENDAR_TYPE_SOURCES, CalendarSourcesPrivate))
-
-#define CALENDAR_SOURCES_EVO_DIR "/apps/evolution"
-#define CALENDAR_SOURCES_APPOINTMENT_SOURCES_KEY CALENDAR_SOURCES_EVO_DIR "/calendar/sources"
-#define CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_DIR CALENDAR_SOURCES_EVO_DIR "/calendar/display"
-#define CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_KEY CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_DIR "/selected_calendars"
-#define CALENDAR_SOURCES_TASK_SOURCES_KEY CALENDAR_SOURCES_EVO_DIR "/tasks/sources"
-#define CALENDAR_SOURCES_SELECTED_TASK_SOURCES_DIR CALENDAR_SOURCES_EVO_DIR "/calendar/tasks"
-#define CALENDAR_SOURCES_SELECTED_TASK_SOURCES_KEY CALENDAR_SOURCES_SELECTED_TASK_SOURCES_DIR "/selected_tasks"
-
-typedef struct _CalendarSourceData CalendarSourceData;
-
-struct _CalendarSourceData
-{
- ECalSourceType source_type;
- CalendarSources *sources;
- guint changed_signal;
-
- GSList *clients;
- GSList *selected_sources;
- ESourceList *esource_list;
-
- guint selected_sources_listener;
- char *selected_sources_dir;
-
- guint timeout_id;
-
- guint loaded : 1;
-};
-
-struct _CalendarSourcesPrivate
-{
- CalendarSourceData appointment_sources;
- CalendarSourceData task_sources;
-
- MateConfClient *mateconf_client;
-};
-
-static void calendar_sources_class_init (CalendarSourcesClass *klass);
-static void calendar_sources_init (CalendarSources *sources);
-static void calendar_sources_finalize (GObject *object);
-
-static void backend_died_cb (ECal *client, CalendarSourceData *source_data);
-static void calendar_sources_esource_list_changed (ESourceList *source_list,
- CalendarSourceData *source_data);
-
-enum
-{
- APPOINTMENT_SOURCES_CHANGED,
- TASK_SOURCES_CHANGED,
- LAST_SIGNAL
-};
-static guint signals [LAST_SIGNAL] = { 0, };
-
-static GObjectClass *parent_class = NULL;
-static CalendarSources *calendar_sources_singleton = NULL;
-
-GType
-calendar_sources_get_type (void)
-{
- static GType sources_type = 0;
-
- if (!sources_type)
- {
- static const GTypeInfo sources_info =
- {
- sizeof (CalendarSourcesClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) calendar_sources_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (CalendarSources),
- 0, /* n_preallocs */
- (GInstanceInitFunc) calendar_sources_init,
- };
-
- sources_type = g_type_register_static (G_TYPE_OBJECT,
- "CalendarSources",
- &sources_info, 0);
- }
-
- return sources_type;
-}
-
-static void
-calendar_sources_class_init (CalendarSourcesClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass *) klass;
-
- parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->finalize = calendar_sources_finalize;
-
- g_type_class_add_private (klass, sizeof (CalendarSourcesPrivate));
-
- signals [APPOINTMENT_SOURCES_CHANGED] =
- g_signal_new ("appointment-sources-changed",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CalendarSourcesClass,
- appointment_sources_changed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- signals [TASK_SOURCES_CHANGED] =
- g_signal_new ("task-sources-changed",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CalendarSourcesClass,
- task_sources_changed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-}
-
-static void
-calendar_sources_init (CalendarSources *sources)
-{
- sources->priv = CALENDAR_SOURCES_GET_PRIVATE (sources);
-
- sources->priv->appointment_sources.source_type = E_CAL_SOURCE_TYPE_EVENT;
- sources->priv->appointment_sources.sources = sources;
- sources->priv->appointment_sources.changed_signal = signals [APPOINTMENT_SOURCES_CHANGED];
- sources->priv->appointment_sources.timeout_id = 0;
-
- sources->priv->task_sources.source_type = E_CAL_SOURCE_TYPE_TODO;
- sources->priv->task_sources.sources = sources;
- sources->priv->task_sources.changed_signal = signals [TASK_SOURCES_CHANGED];
- sources->priv->task_sources.timeout_id = 0;
-
- sources->priv->mateconf_client = mateconf_client_get_default ();
-}
-
-static void
-calendar_sources_finalize_source_data (CalendarSources *sources,
- CalendarSourceData *source_data)
-{
- if (source_data->loaded)
- {
- GSList *l;
-
- if (source_data->selected_sources_dir)
- {
- mateconf_client_remove_dir (sources->priv->mateconf_client,
- source_data->selected_sources_dir,
- NULL);
-
- g_free (source_data->selected_sources_dir);
- source_data->selected_sources_dir = NULL;
- }
-
- if (source_data->selected_sources_listener)
- {
- mateconf_client_notify_remove (sources->priv->mateconf_client,
- source_data->selected_sources_listener);
- source_data->selected_sources_listener = 0;
- }
-
- for (l = source_data->clients; l; l = l->next)
- {
- g_signal_handlers_disconnect_by_func (G_OBJECT (l->data),
- G_CALLBACK (backend_died_cb),
- source_data);
- g_object_unref (l->data);
- }
- g_slist_free (source_data->clients);
- source_data->clients = NULL;
-
- if (source_data->esource_list)
- {
- g_signal_handlers_disconnect_by_func (source_data->esource_list,
- G_CALLBACK (calendar_sources_esource_list_changed),
- source_data);
- g_object_unref (source_data->esource_list);
- }
- source_data->esource_list = NULL;
-
- for (l = source_data->selected_sources; l; l = l->next)
- g_free (l->data);
- g_slist_free (source_data->selected_sources);
- source_data->selected_sources = NULL;
-
- if (source_data->timeout_id != 0)
- {
- g_source_remove (source_data->timeout_id);
- source_data->timeout_id = 0;
- }
-
- source_data->loaded = FALSE;
- }
-}
-
-static void
-calendar_sources_finalize (GObject *object)
-{
- CalendarSources *sources = CALENDAR_SOURCES (object);
-
- calendar_sources_finalize_source_data (sources, &sources->priv->appointment_sources);
- calendar_sources_finalize_source_data (sources, &sources->priv->task_sources);
-
- if (sources->priv->mateconf_client)
- g_object_unref (sources->priv->mateconf_client);
- sources->priv->mateconf_client = NULL;
-
- if (G_OBJECT_CLASS (parent_class)->finalize)
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-CalendarSources *
-calendar_sources_get (void)
-{
- gpointer singleton_location = &calendar_sources_singleton;
-
- if (calendar_sources_singleton)
- return g_object_ref (calendar_sources_singleton);
-
- calendar_sources_singleton = g_object_new (CALENDAR_TYPE_SOURCES, NULL);
- g_object_add_weak_pointer (G_OBJECT (calendar_sources_singleton),
- singleton_location);
-
- return calendar_sources_singleton;
-}
-
-static gboolean
-is_source_selected (ESource *esource,
- GSList *selected_sources)
-{
- const char *uid;
- GSList *l;
-
- uid = e_source_peek_uid (esource);
-
- for (l = selected_sources; l; l = l->next)
- {
- const char *source = l->data;
-
- if (!strcmp (source, uid))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static char *
-auth_func_cb (ECal *ecal,
- const char *prompt,
- const char *key,
- gpointer user_data)
-{
- ESource *source;
- const gchar *auth_domain;
- const gchar *component_name;
-
- source = e_cal_get_source (ecal);
- auth_domain = e_source_get_property (source, "auth-domain");
- component_name = auth_domain ? auth_domain : "Calendar";
-
- return e_passwords_get_password (component_name, key);
-}
-
-/* The clients are just created here but not loaded */
-static ECal *
-get_ecal_from_source (ESource *esource,
- ECalSourceType source_type,
- GSList *existing_clients)
-{
- ECal *retval;
-
- if (existing_clients)
- {
- GSList *l;
-
- for (l = existing_clients; l; l = l->next)
- {
- ECal *client = E_CAL (l->data);
-
- if (e_source_equal (esource, e_cal_get_source (client)))
- {
- dprintf (" load_esource: found existing source ... returning that\n");
-
- return g_object_ref (client);
- }
- }
- }
-
- retval = e_cal_new (esource, source_type);
- if (!retval)
- {
- g_warning ("Could not load source '%s' from '%s'\n",
- e_source_peek_name (esource),
- e_source_peek_relative_uri (esource));
- return NULL;
- }
-
- e_cal_set_auth_func (retval, auth_func_cb, NULL);
-
- return retval;
-}
-
-/* - Order doesn't matter
- * - Can just compare object pointers since we
- * re-use client connections
- */
-static gboolean
-compare_ecal_lists (GSList *a,
- GSList *b)
-{
- GSList *l;
-
- if (g_slist_length (a) != g_slist_length (b))
- return FALSE;
-
- for (l = a; l; l = l->next)
- {
- if (!g_slist_find (b, l->data))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static inline void
-debug_dump_selected_sources (GSList *selected_sources)
-{
-#ifdef CALENDAR_ENABLE_DEBUG
- GSList *l;
-
- dprintf ("Selected sources:\n");
- for (l = selected_sources; l; l = l->next)
- {
- char *source = l->data;
-
- dprintf (" %s\n", source);
- }
- dprintf ("\n");
-#endif
-}
-
-static inline void
-debug_dump_ecal_list (GSList *ecal_list)
-{
-#ifdef CALENDAR_ENABLE_DEBUG
- GSList *l;
-
- dprintf ("Loaded clients:\n");
- for (l = ecal_list; l; l = l->next)
- {
- ECal *client = l->data;
- ESource *source = e_cal_get_source (client);
-
- dprintf (" %s %s %s\n",
- e_source_peek_uid (source),
- e_source_peek_name (source),
- e_cal_get_uri (client));
- }
-#endif
-}
-
-static void
-calendar_sources_load_esource_list (CalendarSourceData *source_data);
-
-static gboolean
-backend_restart (gpointer data)
-{
- CalendarSourceData *source_data = data;
-
- calendar_sources_load_esource_list (source_data);
-
- source_data->timeout_id = 0;
-
- return FALSE;
-}
-
-static void
-backend_died_cb (ECal *client, CalendarSourceData *source_data)
-{
- const char *uristr;
-
- source_data->clients = g_slist_remove (source_data->clients, client);
- if (g_slist_length (source_data->clients) < 1)
- {
- g_slist_free (source_data->clients);
- source_data->clients = NULL;
- }
- uristr = e_cal_get_uri (client);
- g_warning ("The calendar backend for %s has crashed.", uristr);
-
- if (source_data->timeout_id != 0)
- {
- g_source_remove (source_data->timeout_id);
- source_data->timeout_id = 0;
- }
-
- source_data->timeout_id = g_timeout_add_seconds (2, backend_restart,
- source_data);
-}
-
-static void
-calendar_sources_load_esource_list (CalendarSourceData *source_data)
-{
- GSList *clients = NULL;
- GSList *groups, *l;
- gboolean emit_signal = FALSE;
-
- g_return_if_fail (source_data->esource_list != NULL);
-
- debug_dump_selected_sources (source_data->selected_sources);
-
- dprintf ("Source groups:\n");
- groups = e_source_list_peek_groups (source_data->esource_list);
- for (l = groups; l; l = l->next)
- {
- GSList *esources, *s;
-
- dprintf (" %s\n", e_source_group_peek_uid (l->data));
- dprintf (" sources:\n");
-
- esources = e_source_group_peek_sources (l->data);
- for (s = esources; s; s = s->next)
- {
- ESource *esource = E_SOURCE (s->data);
- ECal *client;
-
- dprintf (" type = '%s' uid = '%s', name = '%s', relative uri = '%s': \n",
- source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task",
- e_source_peek_uid (esource),
- e_source_peek_name (esource),
- e_source_peek_relative_uri (esource));
-
- if (is_source_selected (esource, source_data->selected_sources) &&
- (client = get_ecal_from_source (esource, source_data->source_type, source_data->clients)))
- {
- clients = g_slist_prepend (clients, client);
- }
- }
- }
- dprintf ("\n");
-
- if (source_data->loaded &&
- !compare_ecal_lists (source_data->clients, clients))
- emit_signal = TRUE;
-
- for (l = source_data->clients; l; l = l->next)
- {
- g_signal_handlers_disconnect_by_func (G_OBJECT (l->data),
- G_CALLBACK (backend_died_cb),
- source_data);
-
- g_object_unref (l->data);
- }
- g_slist_free (source_data->clients);
- source_data->clients = g_slist_reverse (clients);
-
- /* connect to backend_died after we disconnected the previous signal
- * handlers. If we do it before, we'll lose some handlers (for clients that
- * were already there before) */
- for (l = source_data->clients; l; l = l->next)
- {
- g_signal_connect (G_OBJECT (l->data), "backend_died",
- G_CALLBACK (backend_died_cb), source_data);
- }
-
- if (emit_signal)
- {
- dprintf ("Emitting %s-sources-changed signal\n",
- source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task");
- g_signal_emit (source_data->sources, source_data->changed_signal, 0);
- }
-
- debug_dump_ecal_list (source_data->clients);
-}
-
-static void
-calendar_sources_esource_list_changed (ESourceList *source_list,
- CalendarSourceData *source_data)
-
-{
- dprintf ("ESourceList changed, reloading\n");
-
- calendar_sources_load_esource_list (source_data);
-}
-
-static void
-calendar_sources_selected_sources_notify (MateConfClient *client,
- guint cnx_id,
- MateConfEntry *entry,
- CalendarSourceData *source_data)
-{
- GSList *l;
-
- if (!entry->value ||
- entry->value->type != MATECONF_VALUE_LIST ||
- mateconf_value_get_list_type (entry->value) != MATECONF_VALUE_STRING)
- return;
-
- dprintf ("Selected sources key (%s) changed, reloading\n", entry->key);
-
- for (l = source_data->selected_sources; l; l = l->next)
- g_free (l->data);
- source_data->selected_sources = NULL;
-
- for (l = mateconf_value_get_list (entry->value); l; l = l->next)
- {
- const char *source = mateconf_value_get_string (l->data);
-
- source_data->selected_sources =
- g_slist_prepend (source_data->selected_sources,
- g_strdup (source));
- }
- source_data->selected_sources =
- g_slist_reverse (source_data->selected_sources);
-
- calendar_sources_load_esource_list (source_data);
-}
-
-static void
-calendar_sources_load_sources (CalendarSources *sources,
- CalendarSourceData *source_data,
- const char *sources_key,
- const char *selected_sources_key,
- const char *selected_sources_dir)
-{
- MateConfClient *mateconf_client;
- GError *error;
-
- dprintf ("---------------------------\n");
- dprintf ("Loading sources:\n");
- dprintf (" sources_key: %s\n", sources_key);
- dprintf (" selected_sources_key: %s\n", selected_sources_key);
- dprintf (" selected_sources_dir: %s\n", selected_sources_dir);
-
- mateconf_client = sources->priv->mateconf_client;
-
- error = NULL;
- source_data->selected_sources = mateconf_client_get_list (mateconf_client,
- selected_sources_key,
- MATECONF_VALUE_STRING,
- &error);
- if (error)
- {
- g_warning ("Failed to get selected sources from '%s': %s\n",
- selected_sources_key,
- error->message);
- g_error_free (error);
- return;
- }
-
- mateconf_client_add_dir (mateconf_client,
- selected_sources_dir,
- MATECONF_CLIENT_PRELOAD_NONE,
- NULL);
- source_data->selected_sources_dir = g_strdup (selected_sources_dir);
-
- source_data->selected_sources_listener =
- mateconf_client_notify_add (mateconf_client,
- selected_sources_dir,
- (MateConfClientNotifyFunc) calendar_sources_selected_sources_notify,
- source_data, NULL, NULL);
-
- source_data->esource_list = e_source_list_new_for_mateconf (mateconf_client, sources_key);
- g_signal_connect (source_data->esource_list, "changed",
- G_CALLBACK (calendar_sources_esource_list_changed),
- source_data);
-
- calendar_sources_load_esource_list (source_data);
-
- source_data->loaded = TRUE;
-
- dprintf ("---------------------------\n");
-}
-
-GSList *
-calendar_sources_get_appointment_sources (CalendarSources *sources)
-{
- g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
-
- if (!sources->priv->appointment_sources.loaded)
- {
- calendar_sources_load_sources (sources,
- &sources->priv->appointment_sources,
- CALENDAR_SOURCES_APPOINTMENT_SOURCES_KEY,
- CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_KEY,
- CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_DIR);
- }
-
- return sources->priv->appointment_sources.clients;
-}
-
-GSList *
-calendar_sources_get_task_sources (CalendarSources *sources)
-{
- g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
-
- if (!sources->priv->task_sources.loaded)
- {
- calendar_sources_load_sources (sources,
- &sources->priv->task_sources,
- CALENDAR_SOURCES_TASK_SOURCES_KEY,
- CALENDAR_SOURCES_SELECTED_TASK_SOURCES_KEY,
- CALENDAR_SOURCES_SELECTED_TASK_SOURCES_DIR);
- }
-
- return sources->priv->task_sources.clients;
-}
diff --git a/applets/clock/calendar-sources.h b/applets/clock/calendar-sources.h
deleted file mode 100644
index 3f080c55..00000000
--- a/applets/clock/calendar-sources.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Authors:
- * Mark McLoughlin <[email protected]>
- * William Jon McCann <[email protected]>
- * Martin Grimme <[email protected]>
- * Christian Kellner <[email protected]>
- */
-
-#ifndef __CALENDAR_SOURCES_H__
-#define __CALENDAR_SOURCES_H__
-
-#include <glib-object.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define CALENDAR_TYPE_SOURCES (calendar_sources_get_type ())
-#define CALENDAR_SOURCES(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CALENDAR_TYPE_SOURCES, CalendarSources))
-#define CALENDAR_SOURCES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CALENDAR_TYPE_SOURCES, CalendarSourcesClass))
-#define CALENDAR_IS_SOURCES(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CALENDAR_TYPE_SOURCES))
-#define CALENDAR_IS_SOURCES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CALENDAR_TYPE_SOURCES))
-#define CALENDAR_SOURCES_GET_CLASS(o)(G_TYPE_INSTANCE_GET_CLASS ((o), CALENDAR_TYPE_SOURCES, CalendarSourcesClass))
-
-typedef struct _CalendarSources CalendarSources;
-typedef struct _CalendarSourcesClass CalendarSourcesClass;
-typedef struct _CalendarSourcesPrivate CalendarSourcesPrivate;
-
-struct _CalendarSources
-{
- GObject parent;
- CalendarSourcesPrivate *priv;
-};
-
-struct _CalendarSourcesClass
-{
- GObjectClass parent_class;
-
- void (* appointment_sources_changed) (CalendarSources *sources);
- void (* task_sources_changed) (CalendarSources *sources);
-};
-
-
-GType calendar_sources_get_type (void) G_GNUC_CONST;
-CalendarSources *calendar_sources_get (void);
-GSList *calendar_sources_get_appointment_sources (CalendarSources *sources);
-GSList *calendar_sources_get_task_sources (CalendarSources *sources);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CALENDAR_SOURCES_H__ */
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c
index 062e4d7e..c2a723d4 100644
--- a/applets/clock/calendar-window.c
+++ b/applets/clock/calendar-window.c
@@ -25,22 +25,12 @@
* Most of the original code comes from clock.c
*/
- /*
- * Evolution calendar integration TODO:
- * + Fix treeview scrolling and sizing
- * + Tooltips for tasks/appointments
- * + Do everything backwards if the clock is on the bottom
- * + Double clicking appointments/tasks should open them in evo
- * + Consider using different colours for different sources
- * + Consider doing a GtkMenu tearoff type thing
- */
-
#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
-#include <mateconf/mateconf-client.h>
+#include <gio/gio.h>
#define MATE_DESKTOP_USE_UNSTABLE_API
#include <libmate/mate-desktop-utils.h>
@@ -50,30 +40,14 @@
#include "clock.h"
#include "clock-utils.h"
#include "clock-typebuiltins.h"
-#ifdef HAVE_LIBECAL
-#include "calendar-client.h"
-#endif
#define CALENDAR_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CALENDAR_TYPE_WINDOW, CalendarWindowPrivate))
-#define KEY_LOCATIONS_EXPANDED "expand_locations"
-#ifdef HAVE_LIBECAL
-/* For the following value, take into account the KEY_* that are not inside this #ifdef! */
-# define N_CALENDAR_WINDOW_MATECONF_PREFS 5
-# define KEY_APPOINTMENTS_EXPANDED "expand_appointments"
-# define KEY_BIRTHDAYS_EXPANDED "expand_birthdays"
-# define KEY_TASKS_EXPANDED "expand_tasks"
-# define KEY_WEATHER_EXPANDED "expand_weather"
-
-# define KEY_CALENDAR_APP "/desktop/mate/applications/calendar"
-# define KEY_TASKS_APP "/desktop/mate/applications/tasks"
-#else
-# define N_CALENDAR_WINDOW_MATECONF_PREFS 1
-#endif
+#define KEY_LOCATIONS_EXPANDED "expand-locations"
enum {
- EDIT_LOCATIONS,
- LAST_SIGNAL
+EDIT_LOCATIONS,
+LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -81,7 +55,7 @@ static guint signals[LAST_SIGNAL];
struct _CalendarWindowPrivate {
GtkWidget *calendar;
- char *prefs_dir;
+ char *prefs_path;
gboolean invert_order;
gboolean show_weeks;
@@ -89,28 +63,7 @@ struct _CalendarWindowPrivate {
GtkWidget *locations_list;
-#ifdef HAVE_LIBECAL
- ClockFormat time_format;
-
- CalendarClient *client;
-
- GtkWidget *appointment_list;
- GtkWidget *birthday_list;
- GtkWidget *weather_list;
- GtkWidget *task_list;
-
- GtkListStore *appointments_model;
- GtkListStore *tasks_model;
-
- GtkTreeSelection *previous_selection;
-
- GtkTreeModelFilter *appointments_filter;
- GtkTreeModelFilter *birthdays_filter;
- GtkTreeModelFilter *tasks_filter;
- GtkTreeModelFilter *weather_filter;
-#endif /* HAVE_LIBECAL */
-
- MateConfClient *mateconfclient;
+ GSettings *settings;
};
G_DEFINE_TYPE (CalendarWindow, calendar_window, GTK_TYPE_WINDOW)
@@ -119,1409 +72,22 @@ enum {
PROP_0,
PROP_INVERTORDER,
PROP_SHOWWEEKS,
-#ifdef HAVE_LIBECAL
- PROP_TIMEFORMAT,
-#endif
PROP_CURRENTTIMEP,
- PROP_PREFSDIR
+ PROP_PREFSPATH
};
static time_t *calendar_window_get_current_time_p (CalendarWindow *calwin);
static void calendar_window_set_current_time_p (CalendarWindow *calwin,
time_t *current_time);
-static const char *calendar_window_get_prefs_dir (CalendarWindow *calwin);
-static void calendar_window_set_prefs_dir (CalendarWindow *calwin,
- const char *prefs_dir);
+static const char *calendar_window_get_prefs_path (CalendarWindow *calwin);
+static void calendar_window_set_prefs_path (CalendarWindow *calwin,
+ const char *prefs_path);
static GtkWidget * create_hig_frame (CalendarWindow *calwin,
const char *title,
const char *button_label,
const char *key,
GCallback callback);
-#ifdef HAVE_LIBECAL
-
-static void
-clock_launch_calendar_tasks_app (CalendarWindow *calwin,
- const char *key_program,
- const char *argument)
-{
- char **argv;
- int argc;
- char *key;
- char *program;
- gboolean terminal;
- char *command_line;
- GdkScreen *screen;
- GError *error;
- gboolean result;
-
- key = g_strdup_printf ("%s%s", key_program, "/exec");
- program = mateconf_client_get_string (calwin->priv->mateconfclient,
- key, NULL);
- g_free (key);
-
- key = g_strdup_printf ("%s%s", key_program, "/needs_term");
- terminal = mateconf_client_get_bool (calwin->priv->mateconfclient,
- key, NULL);
- g_free (key);
-
- if (program == NULL) {
- g_printerr ("Cannot launch calendar/tasks application: key not set\n");
- return;
- }
-
- command_line = g_find_program_in_path (program);
- if (command_line == NULL) {
- g_printerr ("Cannot launch calendar/tasks application: %s in path\n", program);
- g_free (program);
- return;
- }
- g_free (command_line);
-
- if (argument) {
- argc = 2;
- argv = g_new0 (char *, 3);
- argv[1] = g_strdup (argument);
- } else {
- argc = 1;
- argv = g_new0 (char *, 2);
- }
- argv[0] = program; /* no strdup, and it will get freed for free */
-
- screen = gtk_widget_get_screen (calwin->priv->calendar);
- error = NULL;
-
- if (terminal)
- mate_desktop_prepend_terminal_to_vector (&argc, &argv);
-
- result = gdk_spawn_on_screen (screen,
- NULL, /* working directory */
- argv,
- NULL, /* envp */
- G_SPAWN_SEARCH_PATH,
- NULL, /* child setup func */
- NULL, /* user data */
- NULL, /* child pid */
- &error);
-
- if (!result) {
- g_printerr ("Cannot launch calendar/tasks application: %s\n",
- error->message);
- g_error_free (error);
- }
-
- g_strfreev (argv);
-}
-
-static void
-clock_launch_calendar_app (CalendarWindow *calwin,
- const char *argument)
-{
- clock_launch_calendar_tasks_app (calwin, KEY_CALENDAR_APP, argument);
-}
-
-static void
-clock_launch_tasks_app (CalendarWindow *calwin,
- const char *argument)
-{
- clock_launch_calendar_tasks_app (calwin, KEY_TASKS_APP, argument);
-}
-
-static void
-update_frame_visibility (GtkWidget *frame,
- GtkTreeModel *model)
-{
- GtkTreeIter iter;
- gboolean model_empty;
-
- if (!frame)
- return;
-
- model_empty = !gtk_tree_model_get_iter_first (model, &iter);
-
- if (model_empty)
- gtk_widget_hide (frame);
- else
- gtk_widget_show (frame);
-}
-
-enum {
- APPOINTMENT_COLUMN_UID,
- APPOINTMENT_COLUMN_URI,
- APPOINTMENT_COLUMN_SUMMARY,
- APPOINTMENT_COLUMN_DESCRIPTION,
- APPOINTMENT_COLUMN_START_TIME,
- APPOINTMENT_COLUMN_START_TEXT,
- APPOINTMENT_COLUMN_END_TIME,
- APPOINTMENT_COLUMN_ALL_DAY,
- APPOINTMENT_COLUMN_PIXBUF,
- N_APPOINTMENT_COLUMNS
-};
-
-enum {
- TASK_COLUMN_UID,
- TASK_COLUMN_SUMMARY,
- TASK_COLUMN_DESCRIPTION,
- TASK_COLUMN_START_TIME,
- TASK_COLUMN_DUE_TIME,
- TASK_COLUMN_PERCENT_COMPLETE,
- TASK_COLUMN_PERCENT_COMPLETE_TEXT,
- TASK_COLUMN_COMPLETED,
- TASK_COLUMN_COMPLETED_TIME,
- TASK_COLUMN_OVERDUE_ATTR,
- TASK_COLUMN_COLOR,
- TASK_COLUMN_PRIORITY,
- N_TASK_COLUMNS
-};
-
-static char *
-format_time (ClockFormat format,
- time_t t,
- guint year,
- guint month,
- guint day)
-{
- struct tm *tm;
- char *time_format;
- char result [256] = { 0, };
-
- if (!t)
- return NULL;
-
- tm = localtime (&t);
- if (!tm)
- return NULL;
-
- if (year == (tm->tm_year + 1900) &&
- month == tm->tm_mon &&
- day == tm->tm_mday) {
- if (format == CLOCK_FORMAT_12)
- /* Translators: This is a strftime format string.
- * It is used to display the time in 12-hours format
- * (eg, like in the US: 8:10 am). The %p expands to
- * am/pm. */
- time_format = g_locale_from_utf8 (_("%l:%M %p"), -1, NULL, NULL, NULL);
- else
- /* Translators: This is a strftime format string.
- * It is used to display the time in 24-hours format
- * (eg, like in France: 20:10). */
- time_format = g_locale_from_utf8 (_("%H:%M"), -1, NULL, NULL, NULL);
- }
- else {
- /* Translators: This is a strftime format string.
- * It is used to display the start date of an appointment, in
- * the most abbreviated way possible. */
- time_format = g_locale_from_utf8 (_("%b %d"), -1, NULL, NULL, NULL);
- }
-
- strftime (result, sizeof (result), time_format, tm);
- g_free (time_format);
-
- return g_locale_to_utf8 (result, -1, NULL, NULL, NULL);
-}
-
-static void
-handle_tasks_changed (CalendarWindow *calwin)
-{
- GSList *events, *l;
-
- gtk_list_store_clear (calwin->priv->tasks_model);
-
- events = calendar_client_get_events (calwin->priv->client,
- CALENDAR_EVENT_TASK);
- for (l = events; l; l = l->next) {
- CalendarTask *task = l->data;
- GtkTreeIter iter;
- char *percent_complete_text;
-
- g_assert (CALENDAR_EVENT (task)->type == CALENDAR_EVENT_TASK);
-
- /* FIXME: should this format be locale specific ? */
- percent_complete_text = g_strdup_printf ("%d%%", task->percent_complete);
-
- gtk_list_store_append (calwin->priv->tasks_model, &iter);
- gtk_list_store_set (calwin->priv->tasks_model, &iter,
- TASK_COLUMN_UID, task->uid,
- TASK_COLUMN_SUMMARY, task->summary,
- TASK_COLUMN_DESCRIPTION, task->description,
- TASK_COLUMN_START_TIME, (gint64)task->start_time,
- TASK_COLUMN_DUE_TIME, (gint64)task->due_time,
- TASK_COLUMN_PERCENT_COMPLETE, task->percent_complete,
- TASK_COLUMN_PERCENT_COMPLETE_TEXT, percent_complete_text,
- TASK_COLUMN_COMPLETED, task->percent_complete == 100,
- TASK_COLUMN_COMPLETED_TIME, (gint64)task->completed_time,
- TASK_COLUMN_COLOR, task->color_string,
- TASK_COLUMN_PRIORITY, task->priority,
- -1);
-
- g_free (percent_complete_text);
- calendar_event_free (CALENDAR_EVENT (task));
- }
- g_slist_free (events);
-
- update_frame_visibility (calwin->priv->task_list,
- GTK_TREE_MODEL (calwin->priv->tasks_filter));
-}
-
-static void
-handle_task_completed_toggled (CalendarWindow *calwin,
- const char *path_str,
- GtkCellRendererToggle *cell)
-{
- GtkTreePath *child_path, *path;
- GtkTreeIter iter;
- char *uid;
- gboolean task_completed;
- guint percent_complete;
-
- path = gtk_tree_path_new_from_string (path_str);
- child_path = gtk_tree_model_filter_convert_path_to_child_path (calwin->priv->tasks_filter, path);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter, child_path);
- gtk_tree_model_get (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter,
- TASK_COLUMN_UID, &uid,
- TASK_COLUMN_COMPLETED, &task_completed,
- TASK_COLUMN_PERCENT_COMPLETE, &percent_complete,
- -1);
-
- task_completed = !task_completed;
- percent_complete = task_completed ? 100 : 0;
-
- calendar_client_set_task_completed (calwin->priv->client,
- uid,
- task_completed,
- percent_complete);
-
- g_free (uid);
- gtk_tree_path_free (path);
- gtk_tree_path_free (child_path);
-}
-
-static void
-handle_task_percent_complete_edited (CalendarWindow *calwin,
- const char *path_str,
- const char *text,
- GtkCellRendererText *cell)
-{
- GtkTreePath *child_path, *path;
- GtkTreeIter iter;
- char *uid;
- int percent_complete;
- char *error = NULL, *text_copy;
-
- path = gtk_tree_path_new_from_string (path_str);
- child_path = gtk_tree_model_filter_convert_path_to_child_path (calwin->priv->tasks_filter, path);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter, child_path);
- gtk_tree_model_get (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter, TASK_COLUMN_UID, &uid,
- -1);
-
- text_copy = g_strdup (text);
- text_copy = g_strdelimit (text_copy, "%", ' ');
- text_copy = g_strstrip (text_copy);
- percent_complete = (int) g_strtod (text_copy, &error);
- if (!error || !error [0]) {
- gboolean task_completed;
-
- percent_complete = CLAMP (percent_complete, 0, 100);
- task_completed = (percent_complete == 100);
-
- calendar_client_set_task_completed (calwin->priv->client,
- uid,
- task_completed,
- percent_complete);
- }
-
- g_free (uid);
- g_free (text_copy);
- gtk_tree_path_free (path);
- gtk_tree_path_free (child_path);
-}
-
-static gboolean
-is_appointment (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- gchar *uri;
-
- gtk_tree_model_get (model, iter, APPOINTMENT_COLUMN_URI, &uri, -1);
- if (uri)
- return (g_ascii_strcasecmp (uri, "file") == 0 ||
- g_ascii_strcasecmp (uri, "webcal") == 0 ||
- g_ascii_strcasecmp (uri, "caldav") == 0 ||
- g_ascii_strcasecmp (uri, "exchange") == 0 ||
- g_ascii_strcasecmp (uri, "groupwise") == 0 ||
- g_ascii_strcasecmp (uri, "google") == 0);
- return FALSE;
-}
-
-static gboolean
-is_birthday (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- gchar *uri;
-
- gtk_tree_model_get (model, iter, APPOINTMENT_COLUMN_URI, &uri, -1);
- if (uri)
- return (g_ascii_strcasecmp (uri, "contacts") == 0);
- return FALSE;
-}
-
-static gboolean
-is_weather (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- gchar *uri;
-
- gtk_tree_model_get (model, iter, APPOINTMENT_COLUMN_URI, &uri, -1);
- if (uri)
- return (g_ascii_strcasecmp (uri, "weather") == 0);
- return FALSE;
-}
-
-static gboolean
-filter_out_tasks (GtkTreeModel *model,
- GtkTreeIter *iter,
- CalendarWindow *calwin)
-{
- gint64 start_time64;
- gint64 completed_time64;
- time_t start_time;
- time_t completed_time;
- time_t one_day_ago;
- gboolean visible;
-
- gtk_tree_model_get (model, iter,
- TASK_COLUMN_START_TIME, &start_time64,
- TASK_COLUMN_COMPLETED_TIME, &completed_time64,
- -1);
- start_time = start_time64;
- completed_time = completed_time64;
-
- one_day_ago = *(calwin->priv->current_time) - (24 * 60 * 60);
-
- visible = !start_time || start_time <= *(calwin->priv->current_time);
- if (visible)
- visible = !completed_time || completed_time >= one_day_ago;
-
- return visible;
-}
-
-static void
-modify_task_text_attributes (GtkTreeModel *model,
- GtkTreeIter *iter,
- GValue *value,
- gint column,
- CalendarWindow *calwin)
-{
- gint64 due_time64;
- time_t due_time;
- PangoAttrList *attr_list;
- PangoAttribute *attr;
- GtkTreeIter child_iter;
-
- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
- &child_iter,
- iter);
-
- if (column != TASK_COLUMN_OVERDUE_ATTR) {
- memset (value, 0, sizeof (GValue));
- gtk_tree_model_get_value (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &child_iter, column, value);
-
- return;
- }
-
- gtk_tree_model_get (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &child_iter, TASK_COLUMN_DUE_TIME, &due_time64,
- -1);
- due_time = due_time64;
-
- if (due_time && due_time > *(calwin->priv->current_time))
- return;
-
- attr_list = pango_attr_list_new ();
-
- attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
- attr->start_index = 0;
- attr->end_index = G_MAXINT;
- pango_attr_list_insert (attr_list, attr);
-
- g_value_take_boxed (value, attr_list);
-}
-
-static gboolean
-task_activated_cb (GtkTreeView *view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- CalendarWindow *calwin)
-{
- GtkTreeIter iter;
- GtkTreePath *child_path;
- char *uid;
- char *argument;
-
- child_path = gtk_tree_model_filter_convert_path_to_child_path (calwin->priv->tasks_filter,
- path);
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter, child_path);
- gtk_tree_model_get (GTK_TREE_MODEL (calwin->priv->tasks_model),
- &iter, TASK_COLUMN_UID, &uid, -1);
-
- argument = g_strdup_printf ("task:%s", uid);
-
- clock_launch_tasks_app (calwin, argument);
-
- g_free (argument);
- g_free (uid);
- gtk_tree_path_free (child_path);
-
- return TRUE;
-}
-
-static void
-set_renderer_pixbuf_color_by_column (GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gint column_number)
-{
- char *color_string;
- GdkPixbuf *pixbuf = NULL;
- GdkColor color;
-
- gtk_tree_model_get (model, iter, column_number, &color_string, -1);
-
- if (color_string && gdk_color_parse (color_string, &color)) {
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 16, 16);
- /* GdkColor has 16 bits per color, gdk_pixbuf only uses 8 bits
- * per color. So just drop the least significant parts */
- gdk_pixbuf_fill (pixbuf,
- (color.red & 0xff00) << 16 |
- (color.green & 0xff00) << 8 |
- (color.blue & 0xff00));
-
- g_object_set (renderer, "visible", pixbuf != NULL, "pixbuf", pixbuf, NULL);
-
- if (pixbuf)
- g_object_unref (pixbuf);
-
- g_free (color_string);
- }
-}
-
-static void
-set_renderer_pixbuf_pixmap (GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- const char *iconpath)
-{
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
-
- if (!g_file_test (iconpath, G_FILE_TEST_IS_REGULAR)) {
- g_printerr ("File '%s' does not exist.\n", iconpath);
- return;
- }
-
- pixbuf = gdk_pixbuf_new_from_file (iconpath, &error);
- if (error) {
- g_printerr ("Cannot load '%s': %s\n",
- iconpath, error->message);
- g_error_free (error);
- return;
- }
-
- g_object_set (renderer,
- "visible", pixbuf != NULL,
- "pixbuf", pixbuf,
- NULL);
-
- if (pixbuf)
- g_object_unref (pixbuf);
-}
-
-static void
-set_renderer_pixbuf_pixmap_for_bday (GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gint data_column)
-{
- const gchar *path = NULL;
- gchar *type = NULL;
-
- gtk_tree_model_get (model, iter, data_column, &type, -1);
- if (!type)
- return;
-
- /* type should be in format like this:
- * pas-id-4121A93E00000001-anniversary
- * pas-id-41112AF900000003-birthday
- * ...
- */
- if (g_strrstr (type, "birthday") != NULL)
- path = CLOCK_EDS_ICONDIR G_DIR_SEPARATOR_S "category_birthday_16.png";
- else if (g_strrstr (type, "anniversary") != NULL)
- path = CLOCK_EDS_ICONDIR G_DIR_SEPARATOR_S "category_gifts_16.png";
- else
- path = CLOCK_EDS_ICONDIR G_DIR_SEPARATOR_S "category_miscellaneous_16.png";
-
- g_free (type);
-
- set_renderer_pixbuf_pixmap (renderer, model, iter, path);
-}
-
-static void
-set_renderer_pixbuf_pixmap_for_weather (GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter)
-{
- set_renderer_pixbuf_pixmap (renderer, model, iter,
- CLOCK_EDS_ICONDIR G_DIR_SEPARATOR_S "category_holiday_16.png");
-}
-
-static void
-task_pixbuf_cell_data_func (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- set_renderer_pixbuf_color_by_column (renderer,
- model,
- iter,
- TASK_COLUMN_COLOR);
-}
-
-static void
-appointment_pixbuf_cell_data_func (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- set_renderer_pixbuf_color_by_column (renderer,
- model,
- iter,
- APPOINTMENT_COLUMN_PIXBUF);
-}
-static void
-birthday_pixbuf_cell_data_func (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
-
- /* APPOINTMENT_COLUMN_UID contains data to select between
- * anniversary or birthday
- */
- set_renderer_pixbuf_pixmap_for_bday (renderer,
- model,
- iter,
- APPOINTMENT_COLUMN_UID);
-}
-static void
-weather_pixbuf_cell_data_func (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
-
- set_renderer_pixbuf_pixmap_for_weather (renderer,
- model,
- iter);
-}
-
-static int
-compare_tasks (GtkTreeModel *model,
- GtkTreeIter *a,
- GtkTreeIter *b,
- gpointer user_data)
-{
- gboolean done_a, done_b;
- int priority_a, priority_b;
-
- gtk_tree_model_get (model, a,
- TASK_COLUMN_COMPLETED, &done_a,
- TASK_COLUMN_PRIORITY, &priority_a,
- -1);
- gtk_tree_model_get (model, b,
- TASK_COLUMN_COMPLETED, &done_b,
- TASK_COLUMN_PRIORITY, &priority_b,
- -1);
-
- /* Always sort completed tasks last */
- if (done_a != done_b)
- return done_a ? -1 : 1;
-
- /* We change undefined priorities so they appear as "Normal" */
- if (priority_a <= 0)
- priority_a = 5;
- if (priority_b <= 0)
- priority_b = 5;
-
- /* We'll just use the ordering of the priority values. */
- if (priority_a < priority_b)
- return -1;
- else if (priority_a > priority_b)
- return 1;
- else {
- gint64 due_time_a64, due_time_b64;
- time_t due_time_a, due_time_b;
-
- gtk_tree_model_get (model, a,
- TASK_COLUMN_DUE_TIME, &due_time_a64, -1);
- gtk_tree_model_get (model, b,
- TASK_COLUMN_DUE_TIME, &due_time_b64, -1);
- due_time_a = due_time_a64;
- due_time_b = due_time_b64;
-
- if (due_time_a < due_time_b)
- return -1;
- else if (due_time_a > due_time_b)
- return 1;
- else {
- char *summary_a, *summary_b;
- int res;
-
- gtk_tree_model_get (model, a, TASK_COLUMN_SUMMARY, &summary_a, -1);
- gtk_tree_model_get (model, b, TASK_COLUMN_SUMMARY, &summary_b, -1);
-
- res = g_utf8_collate (summary_a ? summary_a: "",
- summary_b ? summary_b: "");
-
- g_free (summary_a);
- g_free (summary_b);
-
- return res;
- }
- }
-}
-
-static void
-calendar_window_tree_selection_changed (GtkTreeSelection *selection,
- CalendarWindow *calwin)
-{
- if (selection == calwin->priv->previous_selection)
- return;
-
- if (calwin->priv->previous_selection) {
- g_signal_handlers_block_by_func (calwin->priv->previous_selection,
- calendar_window_tree_selection_changed,
- calwin);
- gtk_tree_selection_unselect_all (calwin->priv->previous_selection);
- g_signal_handlers_unblock_by_func (calwin->priv->previous_selection,
- calendar_window_tree_selection_changed,
- calwin);
- }
-
- calwin->priv->previous_selection = selection;
-}
-
-static void
-edit_tasks (CalendarWindow *calwin)
-{
- clock_launch_tasks_app (calwin, NULL);
-}
-
-static GtkWidget *
-create_task_list (CalendarWindow *calwin,
- GtkWidget **tree_view,
- GtkWidget **scrolled_window)
-{
- GtkWidget *list;
- GtkWidget *view;
- GtkWidget *scrolled;
- GtkCellRenderer *cell;
- GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
-
- list = create_hig_frame (calwin,
- _("Tasks"), _("Edit"),
- KEY_TASKS_EXPANDED,
- G_CALLBACK (edit_tasks));
-
- *scrolled_window = scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
- /* we show the widget before adding to the container, since adding to
- * the container changes the visibility depending on the state of the
- * expander */
- gtk_widget_show (scrolled);
- gtk_container_add (GTK_CONTAINER (list), scrolled);
-
- g_assert (calwin->priv->tasks_model != NULL);
-
- *tree_view = view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (calwin->priv->tasks_filter));
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
-
- g_signal_connect (view, "row-activated",
- G_CALLBACK (task_activated_cb), calwin);
-
- /* Source color */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_set_cell_data_func (column, cell,
- (GtkTreeCellDataFunc) task_pixbuf_cell_data_func,
- NULL, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- /* Completed toggle */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_toggle_new ();
- g_object_set (cell,
- "activatable", TRUE,
- NULL);
- g_signal_connect_swapped (cell, "toggled",
- G_CALLBACK (handle_task_completed_toggled),
- calwin);
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_add_attribute (column, cell,
- "active", TASK_COLUMN_COMPLETED);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- /* Percent complete */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell,
- "editable", TRUE,
- NULL);
- g_signal_connect_swapped (cell, "edited",
- G_CALLBACK (handle_task_percent_complete_edited),
- calwin);
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_add_attribute (column, cell,
- "text", TASK_COLUMN_PERCENT_COMPLETE_TEXT);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- /* Summary */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_set_attributes (column, cell,
- "text", TASK_COLUMN_SUMMARY,
- "strikethrough", TASK_COLUMN_COMPLETED,
- "attributes", TASK_COLUMN_OVERDUE_ATTR,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- g_signal_connect (selection, "changed",
- G_CALLBACK (calendar_window_tree_selection_changed),
- calwin);
-
- gtk_container_add (GTK_CONTAINER (scrolled), view);
-
- gtk_widget_show (view);
-
- return list;
-}
-
-static void
-mark_day_on_calendar (CalendarClient *client,
- guint day,
- CalendarWindow *calwin)
-{
- gtk_calendar_mark_day (GTK_CALENDAR (calwin->priv->calendar), day);
-}
-
-static void
-handle_appointments_changed (CalendarWindow *calwin)
-{
- GSList *events, *l;
- guint year, month, day;
-
- if (calwin->priv->calendar) {
- gtk_calendar_clear_marks (GTK_CALENDAR (calwin->priv->calendar));
-
- calendar_client_foreach_appointment_day (calwin->priv->client,
- (CalendarDayIter) mark_day_on_calendar,
- calwin);
- }
-
- gtk_list_store_clear (calwin->priv->appointments_model);
-
- calendar_client_get_date (calwin->priv->client, &year, &month, &day);
-
- events = calendar_client_get_events (calwin->priv->client,
- CALENDAR_EVENT_APPOINTMENT);
- for (l = events; l; l = l->next) {
- CalendarAppointment *appointment = l->data;
- GtkTreeIter iter;
- char *start_text;
-
- g_assert (CALENDAR_EVENT (appointment)->type == CALENDAR_EVENT_APPOINTMENT);
-
- if (appointment->is_all_day)
- start_text = g_strdup (_("All Day"));
- else
- start_text = format_time (calwin->priv->time_format,
- appointment->start_time,
- year, month, day);
-
-
- gtk_list_store_append (calwin->priv->appointments_model,
- &iter);
- gtk_list_store_set (calwin->priv->appointments_model, &iter,
- APPOINTMENT_COLUMN_UID, appointment->uid,
- APPOINTMENT_COLUMN_URI, appointment->uri,
- APPOINTMENT_COLUMN_SUMMARY, appointment->summary,
- APPOINTMENT_COLUMN_DESCRIPTION, appointment->description,
- APPOINTMENT_COLUMN_START_TIME, (gint64)appointment->start_time,
- APPOINTMENT_COLUMN_START_TEXT, start_text,
- APPOINTMENT_COLUMN_END_TIME, (gint64)appointment->end_time,
- APPOINTMENT_COLUMN_ALL_DAY, appointment->is_all_day,
- APPOINTMENT_COLUMN_PIXBUF, appointment->color_string,
- -1);
-
- g_free (start_text);
- calendar_event_free (CALENDAR_EVENT (appointment));
- }
- g_slist_free (events);
-
- update_frame_visibility (calwin->priv->appointment_list,
- GTK_TREE_MODEL (calwin->priv->appointments_filter));
- update_frame_visibility (calwin->priv->birthday_list,
- GTK_TREE_MODEL (calwin->priv->birthdays_filter));
- update_frame_visibility (calwin->priv->weather_list,
- GTK_TREE_MODEL (calwin->priv->weather_filter));
-}
-
-static GtkWidget *
-create_list_for_appointment_model (CalendarWindow *calwin,
- const char *label,
- GtkTreeModelFilter **filter,
- GtkTreeModelFilterVisibleFunc is_for_filter,
- GtkTreeCellDataFunc set_pixbuf_cell,
- gboolean show_start,
- GtkWidget **tree_view,
- GtkWidget **scrolled_window,
- const char *key,
- GCallback callback)
-{
- GtkWidget *list;
- GtkWidget *view;
- GtkWidget *scrolled;
- GtkCellRenderer *cell;
- GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
-
-
- list = create_hig_frame (calwin, label, _("Edit"), key, callback);
-
- *scrolled_window = scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
- /* we show the widget before adding to the container, since adding to
- * the container changes the visibility depending on the state of the
- * expander */
- gtk_widget_show (scrolled);
- gtk_container_add (GTK_CONTAINER (list), scrolled);
-
- g_assert (calwin->priv->appointments_model != NULL);
-
- if (!*filter) {
- *filter =
- GTK_TREE_MODEL_FILTER (
- gtk_tree_model_filter_new (GTK_TREE_MODEL (calwin->priv->appointments_model),
- NULL));
- gtk_tree_model_filter_set_visible_func (
- *filter,
- (GtkTreeModelFilterVisibleFunc) is_for_filter,
- calwin,
- NULL);
- }
-
- *tree_view = view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (*filter));
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
-
- /* Icon */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_set_cell_data_func (column, cell,
- (GtkTreeCellDataFunc) set_pixbuf_cell,
- NULL, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- if (show_start) {
- /* Start time */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_add_attribute (column, cell,
- "text", APPOINTMENT_COLUMN_START_TEXT);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
- }
-
- /* Summary */
- column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_add_attribute (column, cell,
- "text", APPOINTMENT_COLUMN_SUMMARY);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- g_signal_connect (selection, "changed",
- G_CALLBACK (calendar_window_tree_selection_changed),
- calwin);
-
- gtk_container_add (GTK_CONTAINER (scrolled), view);
-
- gtk_widget_show (view);
-
- return list;
-}
-
-static void
-edit_appointments (CalendarWindow *calwin)
-{
- clock_launch_calendar_app (calwin, NULL);
-}
-
-static GtkWidget *
-create_appointment_list (CalendarWindow *calwin,
- GtkWidget **tree_view,
- GtkWidget **scrolled_window)
-{
- return create_list_for_appointment_model (
- calwin,
- _("Appointments"),
- &calwin->priv->appointments_filter,
- is_appointment,
- appointment_pixbuf_cell_data_func,
- TRUE,
- tree_view,
- scrolled_window,
- KEY_APPOINTMENTS_EXPANDED,
- G_CALLBACK (edit_appointments));
-}
-
-static void
-edit_birthdays (CalendarWindow *calwin)
-{
- clock_launch_calendar_app (calwin, NULL);
-}
-
-static GtkWidget *
-create_birthday_list (CalendarWindow *calwin,
- GtkWidget **tree_view,
- GtkWidget **scrolled_window)
-{
- /* FIXME: Figure out how to get rid of useless localized message in front of the summary */
- return create_list_for_appointment_model (
- calwin,
- _("Birthdays and Anniversaries"),
- &calwin->priv->birthdays_filter,
- is_birthday,
- birthday_pixbuf_cell_data_func,
- FALSE,
- tree_view,
- scrolled_window,
- KEY_BIRTHDAYS_EXPANDED,
- G_CALLBACK (edit_birthdays));
-}
-
-static void
-edit_weather (CalendarWindow *calwin)
-{
- clock_launch_calendar_app (calwin, NULL);
-}
-
-
-static GtkWidget *
-create_weather_list (CalendarWindow *calwin,
- GtkWidget **tree_view,
- GtkWidget **scrolled_window)
-{
- return create_list_for_appointment_model (
- calwin,
- _("Weather Information"),
- &calwin->priv->weather_filter,
- is_weather,
- weather_pixbuf_cell_data_func,
- FALSE,
- tree_view,
- scrolled_window,
- KEY_WEATHER_EXPANDED,
- G_CALLBACK (edit_weather));
-}
-
-static void
-calendar_window_create_tasks_model (CalendarWindow *calwin)
-{
- GType column_types [N_TASK_COLUMNS] = {
- G_TYPE_STRING, /* uid */
- G_TYPE_STRING, /* summary */
- G_TYPE_STRING, /* description */
- G_TYPE_INT64, /* start time */
- G_TYPE_INT64, /* due time */
- G_TYPE_UINT, /* percent complete */
- G_TYPE_STRING, /* percent complete text */
- G_TYPE_BOOLEAN, /* completed */
- G_TYPE_INT64, /* completed time */
- PANGO_TYPE_ATTR_LIST, /* summary text attributes */
- G_TYPE_STRING, /* color */
- G_TYPE_INT /* priority */
- };
-
- calwin->priv->tasks_model = gtk_list_store_newv (N_TASK_COLUMNS,
- column_types);
-
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (calwin->priv->tasks_model),
- TASK_COLUMN_PRIORITY,
- compare_tasks,
- NULL, NULL);
-
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (calwin->priv->tasks_model),
- TASK_COLUMN_PRIORITY,
- GTK_SORT_ASCENDING);
-
- calwin->priv->tasks_filter = GTK_TREE_MODEL_FILTER (
- gtk_tree_model_filter_new (GTK_TREE_MODEL (calwin->priv->tasks_model),
- NULL));
- gtk_tree_model_filter_set_visible_func (
- calwin->priv->tasks_filter,
- (GtkTreeModelFilterVisibleFunc) filter_out_tasks,
- calwin,
- NULL);
- gtk_tree_model_filter_set_modify_func (
- calwin->priv->tasks_filter,
- N_TASK_COLUMNS,
- column_types,
- (GtkTreeModelFilterModifyFunc) modify_task_text_attributes,
- calwin,
- NULL);
-}
-
-static void
-calendar_window_create_appointments_model (CalendarWindow *calwin)
-{
- calwin->priv->appointments_model =
- gtk_list_store_new (N_APPOINTMENT_COLUMNS,
- G_TYPE_STRING, /* uid */
- G_TYPE_STRING, /* uri */
- G_TYPE_STRING, /* summary */
- G_TYPE_STRING, /* description */
- G_TYPE_INT64, /* start time */
- G_TYPE_STRING, /* start time text */
- G_TYPE_INT64, /* end time */
- G_TYPE_BOOLEAN, /* all day */
- G_TYPE_STRING); /* color */
-
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (calwin->priv->appointments_model),
- APPOINTMENT_COLUMN_START_TIME,
- GTK_SORT_ASCENDING);
-}
-
-static void
-calendar_day_activated (GtkCalendar *calendar,
- CalendarWindow *calwin)
-{
- unsigned int day;
- unsigned int month;
- unsigned int year;
- time_t date;
- struct tm utc_date_tm;
- struct tm local_date_tm = { 0, };
- char *argument;
-
- gtk_calendar_get_date (calendar, &year, &month, &day);
-
- local_date_tm.tm_mday = (int) day;
- local_date_tm.tm_mon = (int) month;
- local_date_tm.tm_year = (int) year - 1900;
- local_date_tm.tm_isdst = -1;
-
- /* convert the local date picked in the calendar to broken-down UTC */
- date = mktime (&local_date_tm);
- gmtime_r (&date, &utc_date_tm);
-
- /* FIXME: once bug 409200 is fixed, we'll have to make this hh:mm:ss
- * instead of hhmmss */
- argument = g_strdup_printf ("calendar:///?startdate="
- "%.4d%.2d%.2dT%.2d%.2d%.2dZ",
- utc_date_tm.tm_year + 1900,
- utc_date_tm.tm_mon + 1,
- utc_date_tm.tm_mday,
- utc_date_tm.tm_hour,
- utc_date_tm.tm_min,
- 0);
-
- clock_launch_calendar_app (calwin, argument);
-
- g_free (argument);
-}
-
-static void
-calendar_day_selected (GtkCalendar *calendar,
- CalendarWindow *calwin)
-{
- guint day;
-
- gtk_calendar_get_date (calendar, NULL, NULL, &day);
-
- calendar_client_select_day (calwin->priv->client, day);
-
- handle_appointments_changed (calwin);
- handle_tasks_changed (calwin);
-}
-
-static void
-calendar_month_selected (GtkCalendar *calendar,
- CalendarWindow *calwin)
-{
- guint year, month;
-
- gtk_calendar_get_date (calendar, &year, &month, NULL);
-
- calendar_client_select_month (calwin->priv->client, month, year);
-
- handle_appointments_changed (calwin);
- handle_tasks_changed (calwin);
-}
-
-typedef struct
-{
- GtkWidget *calendar;
- GtkWidget *tree;
-} ConstraintData;
-
-static void
-constrain_list_size (GtkWidget *widget,
- GtkRequisition *requisition,
- ConstraintData *constraint)
-{
- GtkRequisition req;
- int screen_h;
- int max_height;
-
- /* constrain width to the calendar width */
- gtk_widget_size_request (constraint->calendar, &req);
- requisition->width = MIN (requisition->width, req.width);
-
- screen_h = gdk_screen_get_height (gtk_widget_get_screen (widget));
- /* constrain height to be the tree height up to a max */
- max_height = (screen_h - req.height) / 3;
- gtk_widget_size_request (constraint->tree, &req);
-
- requisition->height = MIN (req.height, max_height);
- requisition->height += 2 * gtk_widget_get_style (widget)->ythickness;
-}
-
-static void
-setup_list_size_constraint (GtkWidget *widget,
- GtkWidget *calendar,
- GtkWidget *tree)
-{
- ConstraintData *constraint;
-
- constraint = g_new0 (ConstraintData, 1);
- constraint->calendar = calendar;
- constraint->tree = tree;
-
- g_signal_connect_data (widget, "size-request",
- G_CALLBACK (constrain_list_size), constraint,
- (GClosureNotify) g_free, 0);
-}
-#endif /* HAVE_LIBECAL */
-
-static void
-expander_activated (GtkExpander *expander,
- CalendarWindow *calwin)
-{
- const char *key;
-
- key = (const gchar*)g_object_get_data (G_OBJECT (expander), "mateconf-key");
-
- if (mateconf_client_key_is_writable (calwin->priv->mateconfclient,
- key, NULL)) {
- mateconf_client_set_bool (calwin->priv->mateconfclient, key,
- gtk_expander_get_expanded (expander),
- NULL);
- }
-}
-
-static void
-expanded_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
- GtkExpander *expander)
-{
- gboolean value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_BOOL)
- return;
-
- value = mateconf_value_get_bool (entry->value);
-
- gtk_expander_set_expanded (expander, value);
-}
-
-static void
-remove_listener (gpointer data)
-{
- MateConfClient *client;
-
- client = mateconf_client_get_default ();
- mateconf_client_notify_remove (client, GPOINTER_TO_UINT (data));
- g_object_unref (client);
-}
-
-static void
-connect_expander_with_mateconf (CalendarWindow *calwin,
- GtkWidget *expander,
- const char *relative_key)
-{
- char *key;
- gboolean expanded;
- guint listener;
-
- key = g_strdup_printf ("%s/%s",
- calwin->priv->prefs_dir, relative_key);
-
- g_object_set_data_full (G_OBJECT (expander), "mateconf-key", (gpointer)key, g_free);
-
- expanded = mateconf_client_get_bool (calwin->priv->mateconfclient, key,
- NULL);
- gtk_expander_set_expanded (GTK_EXPANDER (expander), expanded);
-
- g_signal_connect_after (expander, "activate",
- G_CALLBACK (expander_activated),
- calwin);
-
- listener = mateconf_client_notify_add (
- calwin->priv->mateconfclient, key,
- (MateConfClientNotifyFunc) expanded_changed,
- expander, NULL, NULL);
-
- g_object_set_data_full (G_OBJECT (expander), "listener-id",
- GUINT_TO_POINTER (listener), remove_listener);
-}
-
-static void
-calendar_window_pack_pim (CalendarWindow *calwin,
- GtkWidget *vbox)
-{
-#ifdef HAVE_LIBECAL
- GtkWidget *list;
- GtkWidget *tree_view;
- GtkWidget *scrolled_window;
- guint year, month, day;
-
- calendar_window_create_tasks_model (calwin);
- calendar_window_create_appointments_model (calwin);
-
- list = create_task_list (calwin, &tree_view, &scrolled_window);
- setup_list_size_constraint (scrolled_window,
- calwin->priv->calendar, tree_view);
- update_frame_visibility (list,
- GTK_TREE_MODEL (calwin->priv->tasks_model));
- calwin->priv->task_list = list;
-
- list = create_birthday_list (calwin, &tree_view, &scrolled_window);
- setup_list_size_constraint (scrolled_window,
- calwin->priv->calendar, tree_view);
- update_frame_visibility (list,
- GTK_TREE_MODEL (calwin->priv->birthdays_filter));
- calwin->priv->birthday_list = list;
-
- list = create_weather_list (calwin, &tree_view, &scrolled_window);
- setup_list_size_constraint (scrolled_window,
- calwin->priv->calendar, tree_view);
- update_frame_visibility (list,
- GTK_TREE_MODEL (calwin->priv->weather_filter));
- calwin->priv->weather_list = list;
-
- list = create_appointment_list (calwin, &tree_view, &scrolled_window);
- setup_list_size_constraint (scrolled_window,
- calwin->priv->calendar, tree_view);
- update_frame_visibility (list,
- GTK_TREE_MODEL (calwin->priv->appointments_filter));
- calwin->priv->appointment_list = list;
-
- if (!calwin->priv->invert_order) {
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->task_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->appointment_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->birthday_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->weather_list,
- TRUE, TRUE, 0);
- } else {
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->weather_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->birthday_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->appointment_list,
- TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox),
- calwin->priv->task_list,
- TRUE, TRUE, 0);
- }
-
- if (!calwin->priv->client) {
- calwin->priv->client = calendar_client_new ();
-
- g_signal_connect_swapped (calwin->priv->client,
- "tasks-changed",
- G_CALLBACK (handle_tasks_changed),
- calwin);
- g_signal_connect_swapped (calwin->priv->client,
- "appointments-changed",
- G_CALLBACK (handle_appointments_changed),
- calwin);
- }
-
- gtk_calendar_get_date (GTK_CALENDAR (calwin->priv->calendar),
- &year, &month, &day);
-
- calendar_client_select_day (calwin->priv->client, day);
- calendar_client_select_month (calwin->priv->client, month, year);
-
- handle_tasks_changed (calwin);
- handle_appointments_changed (calwin);
-
- g_signal_connect (calwin->priv->calendar,
- "day-selected-double-click",
- G_CALLBACK (calendar_day_activated),
- calwin);
- g_signal_connect (calwin->priv->calendar,
- "day-selected",
- G_CALLBACK (calendar_day_selected),
- calwin);
- g_signal_connect (calwin->priv->calendar,
- "month-changed",
- G_CALLBACK (calendar_month_selected),
- calwin);
-#endif /* HAVE_LIBECAL */
-}
-
static GtkWidget *
calendar_window_create_calendar (CalendarWindow *calwin)
{
@@ -1635,7 +201,8 @@ create_hig_frame (CalendarWindow *calwin,
g_signal_connect_swapped (button, "clicked", callback, calwin);
}
- connect_expander_with_mateconf (calwin, expander, key);
+ g_settings_bind (calwin->priv->settings, key, expander, "expanded",
+ G_SETTINGS_BIND_DEFAULT);
return vbox;
}
@@ -1685,11 +252,9 @@ calendar_window_fill (CalendarWindow *calwin)
if (!calwin->priv->invert_order) {
gtk_box_pack_start (GTK_BOX (vbox),
calwin->priv->calendar, TRUE, FALSE, 0);
- calendar_window_pack_pim (calwin, vbox);
calendar_window_pack_locations (calwin, vbox);
} else {
calendar_window_pack_locations (calwin, vbox);
- calendar_window_pack_pim (calwin, vbox);
gtk_box_pack_start (GTK_BOX (vbox),
calwin->priv->calendar, TRUE, FALSE, 0);
}
@@ -1716,7 +281,7 @@ calendar_window_constructor (GType type,
calwin = CALENDAR_WINDOW (obj);
g_assert (calwin->priv->current_time != NULL);
- g_assert (calwin->priv->prefs_dir != NULL);
+ g_assert (calwin->priv->prefs_path != NULL);
calendar_window_fill (calwin);
@@ -1744,19 +309,13 @@ calendar_window_get_property (GObject *object,
g_value_set_boolean (value,
calendar_window_get_show_weeks (calwin));
break;
-#ifdef HAVE_LIBECAL
- case PROP_TIMEFORMAT:
- g_value_set_enum (value,
- calendar_window_get_time_format (calwin));
- break;
-#endif
case PROP_CURRENTTIMEP:
g_value_set_pointer (value,
calendar_window_get_current_time_p (calwin));
break;
- case PROP_PREFSDIR:
+ case PROP_PREFSPATH:
g_value_set_string (value,
- calendar_window_get_prefs_dir (calwin));
+ calendar_window_get_prefs_path (calwin));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1785,19 +344,13 @@ calendar_window_set_property (GObject *object,
calendar_window_set_show_weeks (calwin,
g_value_get_boolean (value));
break;
-#ifdef HAVE_LIBECAL
- case PROP_TIMEFORMAT:
- calendar_window_set_time_format (calwin,
- g_value_get_enum (value));
- break;
-#endif
case PROP_CURRENTTIMEP:
calendar_window_set_current_time_p (calwin,
g_value_get_pointer (value));
break;
- case PROP_PREFSDIR:
- calendar_window_set_prefs_dir (calwin,
- g_value_get_string (value));
+ case PROP_PREFSPATH:
+ calendar_window_set_prefs_path (calwin,
+ g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1812,39 +365,9 @@ calendar_window_destroy (GtkObject *object)
calwin = CALENDAR_WINDOW (object);
-#ifdef HAVE_LIBECAL
- if (calwin->priv->client)
- g_object_unref (calwin->priv->client);
- calwin->priv->client = NULL;
-
- if (calwin->priv->appointments_model)
- g_object_unref (calwin->priv->appointments_model);
- calwin->priv->appointments_model = NULL;
-
- if (calwin->priv->tasks_model)
- g_object_unref (calwin->priv->tasks_model);
- calwin->priv->tasks_model = NULL;
-
- if (calwin->priv->appointments_filter)
- g_object_unref (calwin->priv->appointments_filter);
- calwin->priv->appointments_filter = NULL;
-
- if (calwin->priv->birthdays_filter)
- g_object_unref (calwin->priv->birthdays_filter);
- calwin->priv->birthdays_filter = NULL;
-
- if (calwin->priv->tasks_filter)
- g_object_unref (calwin->priv->tasks_filter);
- calwin->priv->tasks_filter = NULL;
-
- if (calwin->priv->weather_filter)
- g_object_unref (calwin->priv->weather_filter);
- calwin->priv->weather_filter = NULL;
-#endif /* HAVE_LIBECAL */
-
- if (calwin->priv->mateconfclient)
- g_object_unref (calwin->priv->mateconfclient);
- calwin->priv->mateconfclient = NULL;
+ if (calwin->priv->settings)
+ g_object_unref (calwin->priv->settings);
+ calwin->priv->settings = NULL;
GTK_OBJECT_CLASS (calendar_window_parent_class)->destroy (object);
}
@@ -1890,18 +413,6 @@ calendar_window_class_init (CalendarWindowClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-#ifdef HAVE_LIBECAL
- g_object_class_install_property (
- gobject_class,
- PROP_TIMEFORMAT,
- g_param_spec_enum ("time-format",
- "Time Format",
- "Time format used to display time",
- CLOCK_TYPE_FORMAT,
- clock_locale_format (),
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-#endif
-
g_object_class_install_property (
gobject_class,
PROP_CURRENTTIMEP,
@@ -1912,10 +423,10 @@ calendar_window_class_init (CalendarWindowClass *klass)
g_object_class_install_property (
gobject_class,
- PROP_PREFSDIR,
- g_param_spec_string ("prefs-dir",
- "Preferences Directory",
- "Preferences directory in MateConf",
+ PROP_PREFSPATH,
+ g_param_spec_string ("prefs-path",
+ "Preferences Path",
+ "Preferences path in GSettings",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
@@ -1934,16 +445,11 @@ calendar_window_init (CalendarWindow *calwin)
gtk_window_stick (window);
gtk_window_set_title (window, _("Calendar"));
gtk_window_set_icon_name (window, CLOCK_ICON);
-
-#ifdef HAVE_LIBECAL
- calwin->priv->previous_selection = NULL;
-#endif
- calwin->priv->mateconfclient = mateconf_client_get_default ();
}
GtkWidget *
calendar_window_new (time_t *static_current_time,
- const char *prefs_dir,
+ const char *prefs_path,
gboolean invert_order)
{
CalendarWindow *calwin;
@@ -1952,7 +458,7 @@ calendar_window_new (time_t *static_current_time,
"type", GTK_WINDOW_TOPLEVEL,
"current-time", static_current_time,
"invert-order", invert_order,
- "prefs-dir", prefs_dir,
+ "prefs-path", prefs_path,
NULL);
return GTK_WIDGET (calwin);
@@ -1962,17 +468,6 @@ void
calendar_window_refresh (CalendarWindow *calwin)
{
g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
-
-#ifdef HAVE_LIBECAL
- if (calwin->priv->appointments_filter && calwin->priv->appointment_list)
- gtk_tree_model_filter_refilter (calwin->priv->appointments_filter);
- if (calwin->priv->birthdays_filter && calwin->priv->birthday_list)
- gtk_tree_model_filter_refilter (calwin->priv->birthdays_filter);
- if (calwin->priv->tasks_filter && calwin->priv->task_list)
- gtk_tree_model_filter_refilter (calwin->priv->tasks_filter);
- if (calwin->priv->weather_filter && calwin->priv->weather_list)
- gtk_tree_model_filter_refilter (calwin->priv->weather_filter);
-#endif
}
gboolean
@@ -2040,33 +535,7 @@ calendar_window_get_time_format (CalendarWindow *calwin)
g_return_val_if_fail (CALENDAR_IS_WINDOW (calwin),
CLOCK_FORMAT_INVALID);
-#ifdef HAVE_LIBECAL
- return calwin->priv->time_format;
-#else
return CLOCK_FORMAT_INVALID;
-#endif
-}
-
-void
-calendar_window_set_time_format (CalendarWindow *calwin,
- ClockFormat time_format)
-{
- g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
-
-#ifdef HAVE_LIBECAL
- if (time_format != CLOCK_FORMAT_12 && time_format != CLOCK_FORMAT_24)
- time_format = clock_locale_format ();
-
- if (time_format == calwin->priv->time_format)
- return;
-
- calwin->priv->time_format = time_format;
- /* Time to display for appointments has changed */
- if (calwin->priv->appointments_model)
- handle_appointments_changed (calwin);
-
- g_object_notify (G_OBJECT (calwin), "time-format");
-#endif
}
static time_t *
@@ -2092,32 +561,37 @@ calendar_window_set_current_time_p (CalendarWindow *calwin,
}
static const char *
-calendar_window_get_prefs_dir (CalendarWindow *calwin)
+calendar_window_get_prefs_path (CalendarWindow *calwin)
{
g_return_val_if_fail (CALENDAR_IS_WINDOW (calwin), NULL);
- return calwin->priv->prefs_dir;
+ return calwin->priv->prefs_path;
}
static void
-calendar_window_set_prefs_dir (CalendarWindow *calwin,
- const char *prefs_dir)
+calendar_window_set_prefs_path (CalendarWindow *calwin,
+ const char *prefs_path)
{
g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
- if (!calwin->priv->prefs_dir && (!prefs_dir || !prefs_dir [0]))
+ if (!calwin->priv->prefs_path && (!prefs_path || !prefs_path [0]))
return;
- if (calwin->priv->prefs_dir && prefs_dir && prefs_dir [0] &&
- !strcmp (calwin->priv->prefs_dir, prefs_dir))
+ if (calwin->priv->prefs_path && prefs_path && prefs_path [0] &&
+ !strcmp (calwin->priv->prefs_path, prefs_path))
return;
- if (calwin->priv->prefs_dir)
- g_free (calwin->priv->prefs_dir);
- calwin->priv->prefs_dir = NULL;
+ if (calwin->priv->prefs_path)
+ g_free (calwin->priv->prefs_path);
+ calwin->priv->prefs_path = NULL;
+
+ if (prefs_path && prefs_path [0])
+ calwin->priv->prefs_path = g_strdup (prefs_path);
+
+ g_object_notify (G_OBJECT (calwin), "prefs-path");
- if (prefs_dir && prefs_dir [0])
- calwin->priv->prefs_dir = g_strdup (prefs_dir);
+ if (calwin->priv->settings)
+ g_object_unref (calwin->priv->settings);
- g_object_notify (G_OBJECT (calwin), "prefs-dir");
+ calwin->priv->settings = g_settings_new_with_path (CLOCK_SCHEMA, calwin->priv->prefs_path);
}
diff --git a/applets/clock/clock-face.c b/applets/clock/clock-face.c
index 53f0e4f4..143eef12 100644
--- a/applets/clock/clock-face.c
+++ b/applets/clock/clock-face.c
@@ -289,7 +289,7 @@ update_time_and_face (ClockFace *this,
localtime_r (&timet, &priv->time);
}
- /* FIXME this should be a mateconf setting
+ /* FIXME this should be a pref in gsetting
* Or we could use some code from clock-sun.c?
* currently we hardcode
* morning 7-9
diff --git a/applets/clock/clock-location.c b/applets/clock/clock-location.c
index 1b81c517..efbc5939 100644
--- a/applets/clock/clock-location.c
+++ b/applets/clock/clock-location.c
@@ -676,8 +676,12 @@ update_weather_info (gpointer data)
DISTANCE_UNIT_KM
};
- prefs.temperature_unit = priv->temperature_unit;
- prefs.speed_unit = priv->speed_unit;
+ // set temperature and speed units only if different from
+ // invalid/default
+ if (priv->temperature_unit > TEMP_UNIT_DEFAULT)
+ prefs.temperature_unit = priv->temperature_unit;
+ if (priv->speed_unit > SPEED_UNIT_DEFAULT)
+ prefs.speed_unit = priv->speed_unit;
weather_info_abort (priv->weather_info);
weather_info_update (priv->weather_info,
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index d728354e..f86722b6 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -27,6 +27,7 @@
* George Lebl
* Gediminas Paulauskas
* Mark McLoughlin
+ * Stefano Karapetsas
*/
#include "config.h"
@@ -42,24 +43,20 @@
#include <locale.h>
#include <mate-panel-applet.h>
-#include <mate-panel-applet-mateconf.h>
+#include <mate-panel-applet-gsettings.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
-#include <mateconf/mateconf-client.h>
+#include <gio/gio.h>
#include <libmateweather/mateweather-prefs.h>
#include <libmateweather/mateweather-xml.h>
#include <libmateweather/location-entry.h>
#include <libmateweather/timezone-menu.h>
-#ifdef HAVE_LIBECAL
-#include <libedataserverui/e-passwords.h>
-#endif
-
#include "clock.h"
#include "calendar-window.h"
@@ -75,26 +72,16 @@
#define NEVER_SENSITIVE "never_sensitive"
-#define N_MATECONF_PREFS 11 /* Keep this in sync with the number of keys below! */
#define KEY_FORMAT "format"
-#define KEY_SHOW_SECONDS "show_seconds"
-#define KEY_SHOW_DATE "show_date"
-#define KEY_SHOW_WEATHER "show_weather"
-#define KEY_SHOW_TEMPERATURE "show_temperature"
-#define KEY_CUSTOM_FORMAT "custom_format"
-#define KEY_SHOW_WEEK "show_week_numbers"
+#define KEY_SHOW_SECONDS "show-seconds"
+#define KEY_SHOW_DATE "show-date"
+#define KEY_SHOW_WEATHER "show-weather"
+#define KEY_SHOW_TEMPERATURE "show-temperature"
+#define KEY_CUSTOM_FORMAT "custom-format"
+#define KEY_SHOW_WEEK "show-week-numbers"
#define KEY_CITIES "cities"
-#define KEY_TEMPERATURE_UNIT "temperature_unit"
-#define KEY_SPEED_UNIT "speed_unit"
-
-static MateConfEnumStringPair format_type_enum_map [] = {
- { CLOCK_FORMAT_12, "12-hour" },
- { CLOCK_FORMAT_24, "24-hour" },
- { CLOCK_FORMAT_UNIX, "unix" },
- { CLOCK_FORMAT_INTERNET, "internet" },
- { CLOCK_FORMAT_CUSTOM, "custom" },
- { 0, NULL }
-};
+#define KEY_TEMPERATURE_UNIT "temperature-unit"
+#define KEY_SPEED_UNIT "speed-unit"
enum {
COL_CITY_NAME = 0,
@@ -163,8 +150,6 @@ struct _ClockData {
gboolean show_weather;
gboolean show_temperature;
- gboolean use_temperature_default;
- gboolean use_speed_default;
TempUnit temperature_unit;
SpeedUnit speed_unit;
@@ -194,7 +179,7 @@ struct _ClockData {
gboolean can_handle_format_12;
- guint listeners [N_MATECONF_PREFS];
+ GSettings *settings;
};
/* Used to count the number of clock instances. It's there to know when we
@@ -489,7 +474,8 @@ get_updated_timeformat (ClockData *cd)
static void
update_timeformat (ClockData *cd)
{
- g_free (cd->timeformat);
+ if (cd->timeformat)
+ g_free (cd->timeformat);
cd->timeformat = get_updated_timeformat (cd);
}
@@ -671,21 +657,12 @@ update_tooltip (ClockData * cd)
g_free (utf8);
g_free (tip);
} else {
-#ifdef HAVE_LIBECAL
- if (cd->calendar_popup)
- gtk_widget_set_tooltip_text (cd->panel_button,
- _("Click to hide your appointments and tasks"));
- else
- gtk_widget_set_tooltip_text (cd->panel_button,
- _("Click to view your appointments and tasks"));
-#else
if (cd->calendar_popup)
gtk_widget_set_tooltip_text (cd->panel_button,
_("Click to hide month calendar"));
else
gtk_widget_set_tooltip_text (cd->panel_button,
_("Click to view month calendar"));
-#endif
}
}
@@ -726,28 +703,23 @@ refresh_click_timeout_time_only (ClockData *cd)
static void
free_locations (ClockData *cd)
{
- GList *l;
+ if (cd->locations != NULL) {
+ GList *l;
- for (l = cd->locations; l; l = l->next)
- g_object_unref (l->data);
+ for (l = cd->locations; l; l = l->next)
+ g_object_unref (l->data);
- g_list_free (cd->locations);
+ g_list_free (cd->locations);
+ }
cd->locations = NULL;
}
static void
destroy_clock (GtkWidget * widget, ClockData *cd)
{
- MateConfClient *client;
- int i;
-
- client = mateconf_client_get_default ();
-
- for (i = 0; i < N_MATECONF_PREFS; i++)
- mateconf_client_notify_remove (
- client, cd->listeners [i]);
-
- g_object_unref (G_OBJECT (client));
+ if (cd->settings)
+ g_object_unref (cd->settings);
+ cd->settings = NULL;
if (cd->timeout)
g_source_remove (cd->timeout);
@@ -766,7 +738,8 @@ destroy_clock (GtkWidget * widget, ClockData *cd)
free_locations (cd);
- g_list_free (cd->location_tiles);
+ if (cd->location_tiles)
+ g_list_free (cd->location_tiles);
cd->location_tiles = NULL;
if (cd->systz) {
@@ -785,13 +758,6 @@ destroy_clock (GtkWidget * widget, ClockData *cd)
}
g_free (cd);
-
-#ifdef HAVE_LIBECAL
- if (clock_numbers > 0) {
- e_passwords_shutdown ();
- clock_numbers--;
- }
-#endif
}
static gboolean
@@ -830,18 +796,16 @@ static GtkWidget *
create_calendar (ClockData *cd)
{
GtkWidget *window;
- char *prefs_dir;
+ char *prefs_path;
- prefs_dir = mate_panel_applet_get_preferences_key (MATE_PANEL_APPLET (cd->applet));
+ prefs_path = mate_panel_applet_get_preferences_path (MATE_PANEL_APPLET (cd->applet));
window = calendar_window_new (&cd->current_time,
- prefs_dir,
+ prefs_path,
cd->orient == MATE_PANEL_APPLET_ORIENT_UP);
- g_free (prefs_dir);
+ g_free (prefs_path);
calendar_window_set_show_weeks (CALENDAR_WINDOW (window),
cd->showweek);
- calendar_window_set_time_format (CALENDAR_WINDOW (window),
- cd->format);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (cd->applet));
@@ -1116,7 +1080,8 @@ create_cities_section (ClockData *cd)
cd->cities_section = NULL;
}
- g_list_free (cd->location_tiles);
+ if (cd->location_tiles)
+ g_list_free (cd->location_tiles);
cd->location_tiles = NULL;
cd->cities_section = gtk_vbox_new (FALSE, 6);
@@ -1209,7 +1174,8 @@ update_calendar_popup (ClockData *cd)
cd->map_widget = NULL;
cd->clock_vbox = NULL;
- g_list_free (cd->location_tiles);
+ if (cd->location_tiles)
+ g_list_free (cd->location_tiles);
cd->location_tiles = NULL;
}
update_tooltip (cd);
@@ -1370,11 +1336,6 @@ weather_tooltip (GtkWidget *widget,
static void
create_clock_widget (ClockData *cd)
{
-#ifdef HAVE_LIBECAL
- clock_numbers++;
- e_passwords_init ();
-#endif
-
/* Main toggle button */
cd->panel_button = create_main_clock_button ();
g_signal_connect (cd->panel_button, "button_press_event",
@@ -1882,20 +1843,12 @@ static const GtkActionEntry clock_menu_actions [] = {
};
static void
-format_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+format_changed (GSettings *settings,
+ gchar *key,
ClockData *clock)
{
- const char *value;
int new_format;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
- return;
-
- value = mateconf_value_get_string (entry->value);
- if (!mateconf_string_to_enum (format_type_enum_map, value, &new_format))
- return;
+ new_format = g_settings_get_enum (settings, key);
if (!clock->can_handle_format_12 && new_format == CLOCK_FORMAT_12)
new_format = CLOCK_FORMAT_24;
@@ -1907,43 +1860,26 @@ format_changed (MateConfClient *client,
refresh_clock_timeout (clock);
if (clock->calendar_popup != NULL) {
- calendar_window_set_time_format (CALENDAR_WINDOW (clock->calendar_popup), clock->format);
position_calendar_popup (clock);
}
}
static void
-show_seconds_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
- ClockData *clock)
+show_seconds_changed (GSettings *settings,
+ gchar *key,
+ ClockData *clock)
{
- gboolean value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_BOOL)
- return;
-
- value = mateconf_value_get_bool (entry->value);
-
- clock->showseconds = (value != 0);
+ clock->showseconds = g_settings_get_boolean (settings, key);
refresh_clock_timeout (clock);
}
static void
-show_date_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+show_date_changed (GSettings *settings,
+ gchar *key,
ClockData *clock)
{
- gboolean value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_BOOL)
- return;
-
- value = mateconf_value_get_bool (entry->value);
-
- clock->showdate = (value != 0);
+ clock->showdate = g_settings_get_boolean (settings, key);
update_timeformat (clock);
refresh_clock (clock);
}
@@ -1971,16 +1907,13 @@ update_panel_weather (ClockData *cd)
}
static void
-update_weather_bool_value_and_toggle_from_mateconf (ClockData *cd, MateConfEntry *entry,
+update_weather_bool_value_and_toggle_from_gsettings (ClockData *cd, gchar *key,
gboolean *value_loc, const char *widget_name)
{
GtkWidget *widget;
gboolean value;
- if (!entry->value || entry->value->type != MATECONF_VALUE_BOOL)
- return;
-
- value = mateconf_value_get_bool (entry->value);
+ value = g_settings_get_boolean (cd->settings, key);
*value_loc = (value != 0);
@@ -1993,21 +1926,19 @@ update_weather_bool_value_and_toggle_from_mateconf (ClockData *cd, MateConfEntry
}
static void
-show_weather_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+show_weather_changed (GSettings *settings,
+ gchar *key,
ClockData *cd)
{
- update_weather_bool_value_and_toggle_from_mateconf (cd, entry, &cd->show_weather, "weather_check");
+ update_weather_bool_value_and_toggle_from_gsettings (cd, key, &cd->show_weather, "weather_check");
}
static void
-show_temperature_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+show_temperature_changed (GSettings *settings,
+ gchar *key,
ClockData *cd)
{
- update_weather_bool_value_and_toggle_from_mateconf (cd, entry, &cd->show_temperature, "temperature_check");
+ update_weather_bool_value_and_toggle_from_gsettings (cd, key, &cd->show_temperature, "temperature_check");
}
static void
@@ -2110,7 +2041,7 @@ typedef struct {
ClockData *cd;
} LocationParserData;
-/* Parser for our serialized locations in mateconf */
+/* Parser for our serialized locations in gsettings */
static void
location_start_element (GMarkupParseContext *context,
const gchar *element_name,
@@ -2194,13 +2125,11 @@ static GMarkupParser location_parser = {
};
static void
-cities_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+cities_changed (GSettings *settings,
+ gchar *key,
ClockData *cd)
{
LocationParserData data;
-
GSList *cur = NULL;
GMarkupParseContext *context;
@@ -2208,17 +2137,13 @@ cities_changed (MateConfClient *client,
data.cities = NULL;
data.cd = cd;
- if (!entry->value || entry->value->type != MATECONF_VALUE_LIST)
- return;
-
context = g_markup_parse_context_new (&location_parser, 0, &data, NULL);
- cur = mateconf_value_get_list (entry->value);
+ cur = mate_panel_applet_settings_get_gslist (settings, key);
while (cur) {
- const char *str = mateconf_value_get_string (cur->data);
+ const char *str = cur->data;
g_markup_parse_context_parse (context, str, strlen (str), NULL);
-
cur = cur->next;
}
@@ -2229,22 +2154,6 @@ cities_changed (MateConfClient *client,
}
static void
-update_temperature_combo (ClockData *cd)
-{
- GtkWidget *widget;
- int active_index;
-
- widget = _clock_get_widget (cd, "temperature_combo");
-
- if (cd->use_temperature_default)
- active_index = 0;
- else
- active_index = cd->temperature_unit - 1;
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active_index);
-}
-
-static void
update_weather_locations (ClockData *cd)
{
GList *locations, *l;
@@ -2269,43 +2178,6 @@ update_weather_locations (ClockData *cd)
}
static void
-clock_migrate_to_26 (ClockData *clock)
-{
- gboolean unixtime;
- gboolean internettime;
- int hourformat;
-
- internettime = mate_panel_applet_mateconf_get_bool (MATE_PANEL_APPLET (clock->applet),
- "internet_time",
- NULL);
- unixtime = mate_panel_applet_mateconf_get_bool (MATE_PANEL_APPLET (clock->applet),
- "unix_time",
- NULL);
- hourformat = mate_panel_applet_mateconf_get_int (MATE_PANEL_APPLET (clock->applet),
- "hour_format",
- NULL);
-
- if (unixtime)
- clock->format = CLOCK_FORMAT_UNIX;
- else if (internettime)
- clock->format = CLOCK_FORMAT_INTERNET;
- else if (hourformat == 12)
- clock->format = CLOCK_FORMAT_12;
- else if (hourformat == 24)
- clock->format = CLOCK_FORMAT_24;
-
- /* It's still possible that we have none of the old keys, in which case
- * we're not migrating from 2.6, but the config is simply wrong. So
- * don't set the format key in this case. */
- if (clock->format != CLOCK_FORMAT_INVALID)
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (clock->applet),
- KEY_FORMAT,
- mateconf_enum_to_string (format_type_enum_map,
- clock->format),
- NULL);
-}
-
-static void
clock_timezone_changed (SystemTimezone *systz,
const char *new_tz,
ClockData *cd)
@@ -2317,111 +2189,65 @@ clock_timezone_changed (SystemTimezone *systz,
}
static void
-parse_and_set_temperature_string (const char *str, ClockData *cd)
-{
- gint value = 0;
- gboolean use_default = FALSE;
-
- value = mateweather_prefs_parse_temperature (str, &use_default);
-
- cd->use_temperature_default = use_default;
- cd->temperature_unit = value;
-}
-
-static void
-parse_and_set_speed_string (const char *str, ClockData *cd)
-{
- gint value = 0;
- gboolean use_default = FALSE;
-
- value = mateweather_prefs_parse_speed (str, &use_default);
-
- cd->use_speed_default = use_default;
- cd->speed_unit = value;
-}
-
-static void
-temperature_unit_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+temperature_unit_changed (GSettings *settings,
+ gchar *key,
ClockData *cd)
{
- const gchar *value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
- return;
-
- value = mateconf_value_get_string (entry->value);
- parse_and_set_temperature_string (value, cd);
- update_temperature_combo (cd);
+ cd->temperature_unit = g_settings_get_enum (settings, key);
+ if (cd->temperature_unit > 0)
+ {
+ GtkWidget *widget;
+ gint oldvalue;
+ widget = _clock_get_widget (cd, "temperature_combo");
+ oldvalue = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) + 1;
+ if (oldvalue != cd->speed_unit)
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), cd->temperature_unit -1);
+ }
update_weather_locations (cd);
}
static void
-update_speed_combo (ClockData *cd)
-{
- GtkWidget *widget;
- int active_index;
-
- widget = _clock_get_widget (cd, "wind_speed_combo");
-
- if (cd->use_speed_default)
- active_index = 0;
- else
- active_index = cd->speed_unit - 1;
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active_index);
-}
-
-static void
-speed_unit_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+speed_unit_changed (GSettings *settings,
+ gchar *key,
ClockData *cd)
{
- const gchar *value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
- return;
-
- value = mateconf_value_get_string (entry->value);
- parse_and_set_speed_string (value, cd);
- update_speed_combo (cd);
+ cd->speed_unit = g_settings_get_enum (settings, key);
+ if (cd->speed_unit > 0)
+ {
+ GtkWidget *widget;
+ gint oldvalue;
+ widget = _clock_get_widget (cd, "wind_speed_combo");
+ oldvalue = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) + 1;
+ if (oldvalue != cd->speed_unit)
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), cd->speed_unit -1);
+ }
update_weather_locations (cd);
}
static void
-custom_format_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+custom_format_changed (GSettings *settings,
+ gchar *key,
ClockData *clock)
{
- const char *value;
-
- if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
- return;
-
- value = mateconf_value_get_string (entry->value);
+ gchar *value;
+ value = g_settings_get_string (settings, key);
g_free (clock->custom_format);
clock->custom_format = g_strdup (value);
if (clock->format == CLOCK_FORMAT_CUSTOM)
refresh_clock (clock);
+ g_free (value);
}
static void
-show_week_changed (MateConfClient *client,
- guint cnxn_id,
- MateConfEntry *entry,
+show_week_changed (GSettings *settings,
+ gchar *key,
ClockData *clock)
{
gboolean value;
- if (!entry->value || entry->value->type != MATECONF_VALUE_BOOL)
- return;
-
- value = mateconf_value_get_bool (entry->value);
+ value = g_settings_get_boolean (settings, key);
if (clock->showweek == (value != 0))
return;
@@ -2434,71 +2260,39 @@ show_week_changed (MateConfClient *client,
}
}
-static guint
-setup_mateconf_preference (ClockData *cd, MateConfClient *client, const char *key_name, MateConfClientNotifyFunc callback)
-{
- char *key;
- guint id;
-
- key = mate_panel_applet_mateconf_get_full_key (MATE_PANEL_APPLET (cd->applet),
- key_name);
- id = mateconf_client_notify_add (client, key,
- callback,
- cd, NULL, NULL);
- g_free (key);
-
- return id;
-}
-
static void
-setup_mateconf (ClockData *cd)
+setup_gsettings (ClockData *cd)
{
- struct {
- const char *key_name;
- MateConfClientNotifyFunc callback;
- } prefs[] = {
- { KEY_FORMAT, (MateConfClientNotifyFunc) format_changed },
- { KEY_SHOW_SECONDS, (MateConfClientNotifyFunc) show_seconds_changed },
- { KEY_SHOW_DATE, (MateConfClientNotifyFunc) show_date_changed },
- { KEY_SHOW_WEATHER, (MateConfClientNotifyFunc) show_weather_changed },
- { KEY_SHOW_TEMPERATURE, (MateConfClientNotifyFunc) show_temperature_changed },
- { KEY_CUSTOM_FORMAT, (MateConfClientNotifyFunc) custom_format_changed },
- { KEY_SHOW_WEEK, (MateConfClientNotifyFunc) show_week_changed },
- { KEY_CITIES, (MateConfClientNotifyFunc) cities_changed },
- { KEY_TEMPERATURE_UNIT, (MateConfClientNotifyFunc) temperature_unit_changed },
- { KEY_SPEED_UNIT, (MateConfClientNotifyFunc) speed_unit_changed },
- };
-
- MateConfClient *client;
- int i;
-
- client = mateconf_client_get_default ();
-
- for (i = 0; i < G_N_ELEMENTS (prefs); i++)
- cd->listeners[i] = setup_mateconf_preference (cd, client, prefs[i].key_name, prefs[i].callback);
-
- g_object_unref (G_OBJECT (client));
+ cd->settings = mate_panel_applet_settings_new (MATE_PANEL_APPLET (cd->applet), CLOCK_SCHEMA);
+ g_signal_connect (cd->settings, "changed::" KEY_FORMAT, G_CALLBACK (format_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SHOW_SECONDS, G_CALLBACK (show_seconds_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SHOW_DATE, G_CALLBACK (show_date_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SHOW_WEATHER, G_CALLBACK (show_weather_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SHOW_TEMPERATURE, G_CALLBACK (show_temperature_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_CUSTOM_FORMAT, G_CALLBACK (custom_format_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SHOW_WEEK, G_CALLBACK (show_week_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_CITIES, G_CALLBACK (cities_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_TEMPERATURE_UNIT, G_CALLBACK (temperature_unit_changed), cd);
+ g_signal_connect (cd->settings, "changed::" KEY_SPEED_UNIT, G_CALLBACK (speed_unit_changed), cd);
}
static GList *
-parse_mateconf_cities (ClockData *cd, GSList *values)
+parse_gsettings_cities (ClockData *cd, gchar **values)
{
- GSList *cur = values;
+ gint i;
LocationParserData data;
GMarkupParseContext *context;
data.cities = NULL;
data.cd = cd;
- context =
- g_markup_parse_context_new (&location_parser, 0, &data, NULL);
-
- while (cur) {
- const char *str = (char *)cur->data;
- g_markup_parse_context_parse (context, str, strlen(str), NULL);
+ context = g_markup_parse_context_new (&location_parser, 0, &data, NULL);
- cur = cur->next;
- }
+ if (values) {
+ for (i = 0; values[i]; i++) {
+ g_markup_parse_context_parse (context, values[i], strlen(values[i]), NULL);
+ }
+ }
g_markup_parse_context_free (context);
@@ -2506,70 +2300,37 @@ parse_mateconf_cities (ClockData *cd, GSList *values)
}
static void
-load_mateconf_settings (ClockData *cd)
+load_gsettings (ClockData *cd)
{
- MatePanelApplet *applet;
- int format;
- char *format_str;
- char *value;
- GError *error;
- GSList *values = NULL;
+ gchar **values;
GList *cities = NULL;
- applet = MATE_PANEL_APPLET (cd->applet);
-
- cd->format = CLOCK_FORMAT_INVALID;
-
- format_str = mate_panel_applet_mateconf_get_string (applet, KEY_FORMAT, NULL);
- if (format_str &&
- mateconf_string_to_enum (format_type_enum_map, format_str, &format))
- cd->format = format;
- else
- clock_migrate_to_26 (cd);
-
- g_free (format_str);
+ cd->format = g_settings_get_enum (cd->settings, KEY_FORMAT);
if (cd->format == CLOCK_FORMAT_INVALID)
cd->format = clock_locale_format ();
- cd->custom_format = mate_panel_applet_mateconf_get_string (applet, KEY_CUSTOM_FORMAT, NULL);
- cd->showseconds = mate_panel_applet_mateconf_get_bool (applet, KEY_SHOW_SECONDS, NULL);
-
- error = NULL;
- cd->showdate = mate_panel_applet_mateconf_get_bool (applet, KEY_SHOW_DATE, &error);
- if (error) {
- g_error_free (error);
- /* if on a small screen don't show date by default */
- if (gdk_screen_width () <= 800)
- cd->showdate = FALSE;
- else
- cd->showdate = TRUE;
- }
-
- cd->show_weather = mate_panel_applet_mateconf_get_bool (applet, KEY_SHOW_WEATHER, NULL);
- cd->show_temperature = mate_panel_applet_mateconf_get_bool (applet, KEY_SHOW_TEMPERATURE, NULL);
- cd->showweek = mate_panel_applet_mateconf_get_bool (applet, KEY_SHOW_WEEK, NULL);
+ cd->custom_format = g_settings_get_string (cd->settings, KEY_CUSTOM_FORMAT);
+ cd->showseconds = g_settings_get_boolean (cd->settings, KEY_SHOW_SECONDS);
+ cd->showdate = g_settings_get_boolean (cd->settings, KEY_SHOW_DATE);
+ cd->show_weather = g_settings_get_boolean (cd->settings, KEY_SHOW_WEATHER);
+ cd->show_temperature = g_settings_get_boolean (cd->settings, KEY_SHOW_TEMPERATURE);
+ cd->showweek = g_settings_get_boolean (cd->settings, KEY_SHOW_WEEK);
cd->timeformat = NULL;
cd->can_handle_format_12 = (clock_locale_format () == CLOCK_FORMAT_12);
if (!cd->can_handle_format_12 && cd->format == CLOCK_FORMAT_12)
cd->format = CLOCK_FORMAT_24;
- value = mate_panel_applet_mateconf_get_string (applet, KEY_TEMPERATURE_UNIT, NULL);
- parse_and_set_temperature_string (value, cd);
- g_free (value);
-
- value = mate_panel_applet_mateconf_get_string (applet, KEY_SPEED_UNIT, NULL);
- parse_and_set_speed_string (value, cd);
- g_free (value);
+ cd->temperature_unit = g_settings_get_enum (cd->settings, KEY_TEMPERATURE_UNIT);
+ cd->speed_unit = g_settings_get_enum (cd->settings, KEY_SPEED_UNIT);
- values = mate_panel_applet_mateconf_get_list (MATE_PANEL_APPLET (cd->applet), KEY_CITIES,
- MATECONF_VALUE_STRING, NULL);
+ values = g_settings_get_strv (cd->settings, KEY_CITIES);
- if (g_slist_length (values) == 0) {
+ if (!values || (g_strv_length (values) == 0)) {
cities = NULL;
} else {
- cities = parse_mateconf_cities (cd, values);
+ cities = parse_gsettings_cities (cd, values);
}
set_locations (cd, cities);
@@ -2585,7 +2346,6 @@ fill_clock_applet (MatePanelApplet *applet)
char *filename;
GError *error;
- mate_panel_applet_add_preferences (applet, CLOCK_SCHEMA_DIR, NULL);
mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR);
cd = g_new0 (ClockData, 1);
@@ -2594,8 +2354,8 @@ fill_clock_applet (MatePanelApplet *applet)
cd->applet = GTK_WIDGET (applet);
- setup_mateconf (cd);
- load_mateconf_settings (cd);
+ setup_gsettings (cd);
+ load_gsettings (cd);
cd->builder = gtk_builder_new ();
gtk_builder_set_translation_domain (cd->builder, GETTEXT_PACKAGE);
@@ -2665,181 +2425,6 @@ fill_clock_applet (MatePanelApplet *applet)
return TRUE;
}
-/* FIXME old clock applet */
-#if 0
-static void
-setup_writability_sensitivity (ClockData *clock, GtkWidget *w, GtkWidget *label, const char *key)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- char *fullkey;
- MateConfClient *client;
-
- client = mateconf_client_get_default ();
-
- fullkey = mate_panel_applet_mateconf_get_full_key
- (MATE_PANEL_APPLET (clock->applet), key);
-
- if ( ! mateconf_client_key_is_writable (client, fullkey, NULL)) {
- g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE,
- GINT_TO_POINTER (1));
- gtk_widget_set_sensitive (w, FALSE);
- if (label != NULL) {
- g_object_set_data (G_OBJECT (label), NEVER_SENSITIVE,
- GINT_TO_POINTER (1));
- gtk_widget_set_sensitive (label, FALSE);
- }
- }
-
- g_free (fullkey);
-
- g_object_unref (G_OBJECT (client));
-}
-
-static void
-update_properties_for_format (ClockData *cd,
- GtkComboBox *combo,
- ClockFormat format)
-{
-
- /* show the custom format things the first time we actually
- * have a custom format set in MateConf, but after that don't
- * unshow it if the format changes
- */
- if (!cd->custom_format_shown &&
- (cd->format == CLOCK_FORMAT_CUSTOM ||
- (cd->custom_format && cd->custom_format [0]))) {
- gtk_widget_show (cd->custom_hbox);
- gtk_widget_show (cd->custom_label);
- gtk_widget_show (cd->custom_entry);
-
- gtk_combo_box_append_text (combo, _("Custom format"));
-
- cd->custom_format_shown = TRUE;
- }
-
- /* Some combinations of options do not make sense */
- switch (format) {
- case CLOCK_FORMAT_12:
- case CLOCK_FORMAT_24:
- gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
- gtk_widget_set_sensitive (cd->showdate_check, TRUE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_UNIX:
- gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_INTERNET:
- gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_CUSTOM:
- gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, TRUE);
- gtk_widget_set_sensitive (cd->custom_label, TRUE);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-}
-
-static void
-set_format_cb (GtkComboBox *combo,
- ClockData *cd)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- ClockFormat format;
-
- /* valid values begin from 1 */
- if (cd->can_handle_format_12)
- format = gtk_combo_box_get_active (combo) + 1;
- else
- format = gtk_combo_box_get_active (combo) + 2;
-
- update_properties_for_format (cd, combo, format);
-
- if (cd->format != format)
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (cd->applet),
- KEY_FORMAT,
- mateconf_enum_to_string (format_type_enum_map, format),
- NULL);
-}
-#endif
-
-static void
-set_show_seconds_cb (GtkWidget *w,
- ClockData *clock)
-{
- mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (clock->applet),
- KEY_SHOW_SECONDS,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_date_cb (GtkWidget *w,
- ClockData *clock)
-{
- mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (clock->applet),
- KEY_SHOW_DATE,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_weather_cb (GtkWidget *w,
- ClockData *clock)
-{
- mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (clock->applet),
- KEY_SHOW_WEATHER,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_temperature_cb (GtkWidget *w,
- ClockData *clock)
-{
- mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (clock->applet),
- KEY_SHOW_TEMPERATURE,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-#if 0
-static void
-set_show_zones_cb (GtkWidget *w,
- ClockData *clock)
-{
- mate_panel_applet_mateconf_set_bool (MATE_PANEL_APPLET (clock->applet),
- KEY_SHOW_ZONES,
- GTK_TOGGLE_BUTTON (w)->active,
- NULL);
-}
-#endif
-
-/* FIXME old clock applet */
-#if 0
-static void
-set_custom_format_cb (GtkEntry *entry,
- ClockData *cd)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- const char *custom_format;
-
- custom_format = gtk_entry_get_text (entry);
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (cd->applet),
- KEY_CUSTOM_FORMAT, custom_format, NULL);
-}
-#endif
-
static void
prefs_locations_changed (GtkTreeSelection *selection, ClockData *cd)
{
@@ -2882,28 +2467,26 @@ save_cities_store (ClockData *cd)
{
ClockLocation *loc;
GList *node = cd->locations;
-
- GSList *root = NULL;
- GSList *list = NULL;
+ gint len = g_list_length(cd->locations);
+ gchar **array[len + 1];
+ gchar **array_reverse[len + 1];
+ gint i = 0;
while (node) {
loc = CLOCK_LOCATION (node->data);
- list = g_slist_prepend (list, loc_to_string (loc));
+ array[i] = loc_to_string (loc);
+ i++;
node = node->next;
}
+ array[i] = NULL;
- list = g_slist_reverse (list);
- mate_panel_applet_mateconf_set_list (MATE_PANEL_APPLET (cd->applet),
- KEY_CITIES, MATECONF_VALUE_STRING, list, NULL);
-
- root = list;
-
- while (list) {
- g_free (list->data);
- list = g_slist_next (list);
+ for (i = 0; i <= (len - 1); i++) {
+ array_reverse [len - i - 1] = g_strdup (array [i]);
}
+ array_reverse[i] = NULL;
- g_slist_free (root);
+ g_settings_set_strv (cd->settings, KEY_CITIES, (const gchar **) array_reverse);
+ /* FIXME free arrays */
}
static void
@@ -2980,7 +2563,7 @@ run_prefs_edit_save (GtkButton *button, ClockData *cd)
g_free (city);
/* This will update everything related to locations to take into
- * account the new location (via the mateconf notification) */
+ * account the new location (via the gsettings changed signal) */
save_cities_store (cd);
edit_hide (edit_window, cd);
@@ -3179,7 +2762,7 @@ remove_tree_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpoi
g_object_unref (loc);
/* This will update everything related to locations to take into
- * account the removed location (via the mateconf notification) */
+ * account the removed location (via the gsettings changed signal) */
save_cities_store (cd);
}
@@ -3293,7 +2876,6 @@ run_prefs_locations_edit (GtkButton *unused, ClockData *cd)
static void
set_12hr_format_radio_cb (GtkWidget *widget, ClockData *cd)
{
- const gchar *val;
ClockFormat format;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
@@ -3301,10 +2883,7 @@ set_12hr_format_radio_cb (GtkWidget *widget, ClockData *cd)
else
format = CLOCK_FORMAT_24;
- val = mateconf_enum_to_string (format_type_enum_map, format);
-
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (cd->applet),
- KEY_FORMAT, val, NULL);
+ g_settings_set_enum (cd->settings, KEY_FORMAT, format);
}
static void
@@ -3315,19 +2894,12 @@ temperature_combo_changed (GtkComboBox *combo, ClockData *cd)
const gchar *str;
value = gtk_combo_box_get_active (combo) + 1;
-
- if (cd->use_temperature_default)
- old_value = TEMP_UNIT_DEFAULT;
- else
- old_value = cd->temperature_unit;
+ old_value = cd->temperature_unit;
if (value == old_value)
return;
- str = mateweather_prefs_temp_enum_to_string (value);
-
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (cd->applet),
- KEY_TEMPERATURE_UNIT, str, NULL);
+ g_settings_set_enum (cd->settings, KEY_TEMPERATURE_UNIT, value);
}
static void
@@ -3338,21 +2910,15 @@ speed_combo_changed (GtkComboBox *combo, ClockData *cd)
const gchar *str;
value = gtk_combo_box_get_active (combo) + 1;
-
- if (cd->use_speed_default)
- old_value = SPEED_UNIT_DEFAULT;
- else
- old_value = cd->speed_unit;
+ old_value = cd->speed_unit;
if (value == old_value)
return;
- str = mateweather_prefs_speed_enum_to_string (value);
-
- mate_panel_applet_mateconf_set_string (MATE_PANEL_APPLET (cd->applet),
- KEY_SPEED_UNIT, str, NULL);
+ g_settings_set_enum (cd->settings, KEY_SPEED_UNIT, value);
}
+
static void
fill_prefs_window (ClockData *cd)
{
@@ -3398,27 +2964,23 @@ fill_prefs_window (ClockData *cd)
/* Set the "Show Date" checkbox */
widget = _clock_get_widget (cd, "date_check");
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_date_cb), cd);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->showdate);
+ g_settings_bind (cd->settings, KEY_SHOW_DATE, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show Seconds" checkbox */
widget = _clock_get_widget (cd, "seconds_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->showseconds);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_seconds_cb), cd);
+ g_settings_bind (cd->settings, KEY_SHOW_SECONDS, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show weather" checkbox */
widget = _clock_get_widget (cd, "weather_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->show_weather);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_weather_cb), cd);
+ g_settings_bind (cd->settings, KEY_SHOW_WEATHER, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show temperature" checkbox */
widget = _clock_get_widget (cd, "temperature_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->show_temperature);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_temperature_cb), cd);
+ g_settings_bind (cd->settings, KEY_SHOW_TEMPERATURE, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Fill the Cities list */
widget = _clock_get_widget (cd, "cities_list");
@@ -3448,10 +3010,12 @@ fill_prefs_window (ClockData *cd)
for (i = 0; temperatures[i] != -1; i++)
gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
mateweather_prefs_get_temp_display_name (temperatures[i]));
-
- update_temperature_combo (cd);
+
+ if (cd->temperature_unit > 0)
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
+ cd->temperature_unit - 1);
g_signal_connect (widget, "changed",
- G_CALLBACK (temperature_combo_changed), cd);
+ G_CALLBACK (temperature_combo_changed), cd);
/* Wind speed combo */
widget = _clock_get_widget (cd, "wind_speed_combo");
@@ -3465,7 +3029,9 @@ fill_prefs_window (ClockData *cd)
gtk_combo_box_append_text (GTK_COMBO_BOX (widget),
mateweather_prefs_get_speed_display_name (speeds[i]));
- update_speed_combo (cd);
+ if (cd->speed_unit > 0)
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
+ cd->speed_unit - 1);
g_signal_connect (widget, "changed",
G_CALLBACK (speed_combo_changed), cd);
}
@@ -3603,75 +3169,6 @@ display_properties_dialog (ClockData *cd, gboolean start_in_locations_page)
gtk_window_present (GTK_WINDOW (cd->prefs_window));
refresh_click_timeout_time_only (cd);
-
- /* FMQ: cd->props was the old preferences window; remove references to it */
- /* FMQ: connect to the Help button by hand; look at properties_response_cb() for the help code */
-#if 0
- /* FMQ: check the code below; replace the proper parts */
- GtkWidget *hbox;
- GtkWidget *vbox;
- GtkWidget *combo;
- GtkWidget *label;
-
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("24 hour"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("UNIX time"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Internet time"));
-
- gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
- gtk_widget_show (combo);
-
- cd->custom_hbox = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox), cd->custom_hbox, TRUE, TRUE, 0);
-
- cd->custom_label = gtk_label_new_with_mnemonic (_("Custom _format:"));
- gtk_label_set_use_markup (GTK_LABEL (cd->custom_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (cd->custom_label),
- GTK_JUSTIFY_LEFT);
- gtk_misc_set_alignment (GTK_MISC (cd->custom_label), 0, 0.5);
- gtk_box_pack_start (GTK_BOX (cd->custom_hbox),
- cd->custom_label,
- FALSE, FALSE, 0);
-
- cd->custom_entry = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (cd->custom_hbox),
- cd->custom_entry,
- FALSE, FALSE, 0);
- gtk_entry_set_text (GTK_ENTRY (cd->custom_entry),
- cd->custom_format);
- g_signal_connect (cd->custom_entry, "changed",
- G_CALLBACK (set_custom_format_cb),
- cd);
-
- g_signal_connect (cd->props, "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &cd->props);
- g_signal_connect (cd->props, "response",
- G_CALLBACK (properties_response_cb),
- cd);
-
- cd->custom_format_shown = FALSE;
- update_properties_for_format (cd, GTK_COMBO_BOX (combo), cd->format);
-
- /* valid values begin from 1 */
- if (cd->can_handle_format_12)
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo),
- cd->format - 1);
- else
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo),
- cd->format - 2);
-
- g_signal_connect (combo, "changed",
- G_CALLBACK (set_format_cb), cd);
-
- /* Now set up the sensitivity based on mateconf key writability */
- setup_writability_sensitivity (cd, combo, label, KEY_FORMAT);
- setup_writability_sensitivity (cd, cd->custom_entry, cd->custom_label,
- KEY_CUSTOM_FORMAT);
- setup_writability_sensitivity (cd, cd->showseconds_check, NULL, KEY_SHOW_SECONDS);
- setup_writability_sensitivity (cd, cd->showdate_check, NULL, KEY_SHOW_DATE);
-
- gtk_widget_show (cd->props);
-#endif
}
static void
diff --git a/applets/clock/clock.h b/applets/clock/clock.h
index f2347f68..190c29b5 100644
--- a/applets/clock/clock.h
+++ b/applets/clock/clock.h
@@ -32,7 +32,7 @@ extern "C" {
#endif
#define CLOCK_ICON "mate-panel-clock"
-#define CLOCK_SCHEMA_DIR "/schemas/apps/clock_applet/prefs"
+#define CLOCK_SCHEMA "org.mate.panel.applet.clock"
#ifdef __cplusplus
}
diff --git a/applets/clock/clock.schemas.in b/applets/clock/clock.schemas.in
deleted file mode 100644
index badec94e..00000000
--- a/applets/clock/clock.schemas.in
+++ /dev/null
@@ -1,313 +0,0 @@
-<?xml version="1.0"?>
-<mateconfschemafile>
- <schemalist>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/format</key>
- <owner>clock-applet</owner>
- <type>string</type>
- <locale name="C">
- <default>
- <!-- Translators:
- This controls whether the MATE panel clock should display time in 24 hour mode
- or 12 hour mode by default. The only valid values for this are "24-hour" and
- "12-hour". If your locale uses 24 hour time notation, translate this to "24-hour".
- If your locale uses 12 hour time notation with am/pm, translate this to "12-hour".
-
- Do NOT translate this into anything else than "24-hour" or "12-hour". For example,
- if you translate this to "24 sata" or anything else that isn't "24-hour" or
- "12-hour", things will not work.
- -->
- 24-hour
- </default>
- <short>Hour format</short>
- <long>
- This key specifies the hour format used by the clock applet.
- Possible values are "12-hour", "24-hour", "internet", "unix" and
- "custom".
- If set to "internet", the clock will display Internet time.
- The Internet time system divides the day into 1000 ".beats". There
- are no time zones in this system, so time is the same all over the
- world.
- If set to "unix", the clock will display time in seconds since
- Epoch, i.e. 1970-01-01.
- If set to "custom", the clock will display time according to the
- format specified in the custom_format key.
- </long>
- </locale>
- <locale name="en_US">
- <default>12-hour</default>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/custom_format</key>
- <owner>clock-applet</owner>
- <type>string</type>
- <default></default>
- <locale name="C">
- <short>Custom format of the clock</short>
- <long>
- This key specifies the format used by the clock applet when the
- format key is set to "custom". You can use conversion specifiers
- understood by strftime() to obtain a specific format. See the
- strftime() manual for more information.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_seconds</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Show time with seconds</short>
- <long>If true, display seconds in time.</long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_date</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Show date in clock</short>
- <long>If true, display date in the clock, in addition to time.</long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_tooltip</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Show date in tooltip</short>
- <long>
- If true, show date in a tooltip when the pointer is over the clock.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_weather</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Show weather in clock</short>
- <long>If true, display a weather icon.</long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_temperature</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Show temperature in clock</short>
- <long>If true, show the temperature next to the weather icon.</long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/gmt_time</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Use UTC</short>
- <long>
- The use of this key was deprecated in MATE 2.28 in favour of the
- use of timezones. The schema is retained for compatibility with
- older versions.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/config_tool</key>
- <owner>clock-applet</owner>
- <type>string</type>
- <default> </default>
- <locale name="C">
- <short>Time configuration tool</short>
- <long>
- The use of this key was deprecated in MATE 2.22 with the use
- of an internal time configuration tool. The schema is retained for
- compatibility with older versions.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/show_week_numbers</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>true</default>
- <locale name="C">
- <short>Show week numbers in calendar</short>
- <long>
- If true, show week numbers in the calendar.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/expand_appointments</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Expand list of appointments</short>
- <long>
- If true, expand the list of appointments in the calendar window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/expand_birthdays</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Expand list of birthdays</short>
- <long>
- If true, expand the list of birthdays in the calendar window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/expand_tasks</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Expand list of tasks</short>
- <long>
- If true, expand the list of tasks in the calendar window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/expand_weather</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Expand list of weather information</short>
- <long>
- If true, expand the list of weather information in the calendar
- window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/expand_locations</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Expand list of locations</short>
- <long>
- If true, expand the list of locations in the calendar
- window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/hour_format</key>
- <owner>clock-applet</owner>
- <type>int</type>
- <default>12</default>
- <locale name="C">
- <short>Hour format</short>
- <long>
- The use of this key was deprecated in MATE 2.6 in favour of the
- 'format' key. The schema is retained for compatibility with older
- versions.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/unix_time</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Use UNIX time</short>
- <long>
- The use of this key was deprecated in MATE 2.6 in favour of the
- 'format' key. The schema is retained for compatibility with older
- versions.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/internet_time</key>
- <owner>clock-applet</owner>
- <type>bool</type>
- <default>false</default>
- <locale name="C">
- <short>Use Internet time</short>
- <long>
- The use of this key was deprecated in MATE 2.6 in favour of the
- 'format' key. The schema is retained for compatibility with older
- versions.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/cities</key>
- <owner>clock-applet</owner>
- <type>list</type>
- <list_type>string</list_type>
- <default>[]</default>
- <locale name="C">
- <short>List of locations</short>
- <long>
- A list of locations to display in the calendar window.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/temperature_unit</key>
- <owner>clock-applet</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Temperature unit</short>
- <long>
- The unit to use when showing temperatures.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/clock_applet/prefs/speed_unit</key>
- <owner>clock-applet</owner>
- <type>string</type>
- <default>Default</default>
- <locale name="C">
- <short>Speed unit</short>
- <long>
- The unit to use when showing wind speed.
- </long>
- </locale>
- </schema>
-
- </schemalist>
-
-</mateconfschemafile>
diff --git a/applets/clock/org.mate.panel.applet.clock.gschema.xml.in b/applets/clock/org.mate.panel.applet.clock.gschema.xml.in
new file mode 100644
index 00000000..d2f7daca
--- /dev/null
+++ b/applets/clock/org.mate.panel.applet.clock.gschema.xml.in
@@ -0,0 +1,88 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+ <enum id="org.mate.panel.applet.clock.ClockFormat">
+ <value nick="invalid" value="0"/>
+ <value nick="12-hour" value="1"/>
+ <value nick="24-hour" value="2"/>
+ <value nick="unix" value="3"/>
+ <value nick="internet" value="4"/>
+ <value nick="custom" value="5"/>
+ </enum>
+ <enum id="org.mate.panel.applet.clock.TemperatureUnit">
+ <value nick="Invalid" value="0"/>
+ <value nick="Default" value="1"/>
+ <value nick="Kelvin" value="2"/>
+ <value nick="Centigrade" value="3"/>
+ <value nick="Fahrenheit" value="4"/>
+ </enum>
+ <enum id="org.mate.panel.applet.clock.SpeedUnit">
+ <value nick="Invalid" value="0"/>
+ <value nick="Default" value="1"/>
+ <value nick="m/s" value="2"/>
+ <value nick="km/h" value="3"/>
+ <value nick="mph" value="4"/>
+ <value nick="knots" value="5"/>
+ <value nick="Beaufort scale" value="6"/>
+ </enum>
+ <schema id="org.mate.panel.applet.clock">
+ <key name="format" enum="org.mate.panel.applet.clock.ClockFormat">
+ <default>'24-hour'</default>
+ <summary>Hour format</summary>
+ <description>This key specifies the hour format used by the clock applet. Possible values are "12-hour", "24-hour", "internet", "unix" and "custom". If set to "internet", the clock will display Internet time. The Internet time system divides the day into 1000 ".beats". There are no time zones in this system, so time is the same all over the world. If set to "unix", the clock will display time in seconds since Epoch, i.e. 1970-01-01. If set to "custom", the clock will display time according to the format specified in the custom_format key.</description>
+ </key>
+ <key name="custom-format" type="s">
+ <default>''</default>
+ <summary>Custom format of the clock</summary>
+ <description>This key specifies the format used by the clock applet when the format key is set to "custom". You can use conversion specifiers understood by strftime() to obtain a specific format. See the strftime() manual for more information.</description>
+ </key>
+ <key name="show-seconds" type="b">
+ <default>false</default>
+ <summary>Show time with seconds</summary>
+ <description>If true, display seconds in time.</description>
+ </key>
+ <key name="show-date" type="b">
+ <default>true</default>
+ <summary>Show date in clock</summary>
+ <description>If true, display date in the clock, in addition to time.</description>
+ </key>
+ <key name="show-tooltip" type="b">
+ <default>true</default>
+ <summary>Show date in tooltip</summary>
+ <description>If true, show date in a tooltip when the pointer is over the clock.</description>
+ </key>
+ <key name="show-weather" type="b">
+ <default>true</default>
+ <summary>Show weather in clock</summary>
+ <description>If true, display a weather icon.</description>
+ </key>
+ <key name="show-temperature" type="b">
+ <default>true</default>
+ <summary>Show temperature in clock</summary>
+ <description>If true, show the temperature next to the weather icon.</description>
+ </key>
+ <key name="show-week-numbers" type="b">
+ <default>true</default>
+ <summary>Show week numbers in calendar</summary>
+ <description>If true, show week numbers in the calendar.</description>
+ </key>
+ <key name="expand-locations" type="b">
+ <default>false</default>
+ <summary>Expand list of locations</summary>
+ <description>If true, expand the list of locations in the calendar window.</description>
+ </key>
+ <key name="cities" type="as">
+ <default>[]</default>
+ <summary>List of locations</summary>
+ <description>A list of locations to display in the calendar window.</description>
+ </key>
+ <key name="temperature-unit" enum="org.mate.panel.applet.clock.TemperatureUnit">
+ <default>'Default'</default>
+ <summary>Temperature unit</summary>
+ <description>The unit to use when showing temperatures.</description>
+ </key>
+ <key name="speed-unit" enum="org.mate.panel.applet.clock.SpeedUnit">
+ <default>'Default'</default>
+ <summary>Speed unit</summary>
+ <description>The unit to use when showing wind speed.</description>
+ </key>
+ </schema>
+</schemalist>