aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2004-03-05 19:42:21 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2004-03-05 19:42:21 +0800
commitcb3ff288a6b7fe057640062be8a4b76e8cdb0f52 (patch)
treeb14f022b36cc349adf5c29f9bb262e400c6c6602
parent71ea31e21704fae22af9bf0d775c0e26c18be262 (diff)
downloadgsoc2013-evolution-cb3ff288a6b7fe057640062be8a4b76e8cdb0f52.tar.gz
gsoc2013-evolution-cb3ff288a6b7fe057640062be8a4b76e8cdb0f52.tar.zst
gsoc2013-evolution-cb3ff288a6b7fe057640062be8a4b76e8cdb0f52.zip
set a GConf listener callback to list for changes in selected calendars.
2004-03-05 Rodrigo Moya <rodrigo@ximian.com> * gui/alarm-notify/alarm-notify.c (alarm_notify_init): set a GConf listener callback to list for changes in selected calendars. (alarm_notify_finalize): remove the GConf notification listener. (conf_changed_cb): callback to react on configuration changes. Process the new selected calendars and remove the unselected ones. (process_removal_in_hash): callback to remove unselected calendars. svn path=/trunk/; revision=24973
-rw-r--r--calendar/ChangeLog9
-rw-r--r--calendar/gui/alarm-notify/alarm-notify.c92
-rw-r--r--calendar/gui/e-calendar-table.c2
3 files changed, 102 insertions, 1 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 1a364e8912..3b59f493ab 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,12 @@
+2004-03-05 Rodrigo Moya <rodrigo@ximian.com>
+
+ * gui/alarm-notify/alarm-notify.c (alarm_notify_init): set a GConf
+ listener callback to list for changes in selected calendars.
+ (alarm_notify_finalize): remove the GConf notification listener.
+ (conf_changed_cb): callback to react on configuration changes. Process
+ the new selected calendars and remove the unselected ones.
+ (process_removal_in_hash): callback to remove unselected calendars.
+
2004-03-04 Rodrigo Moya <rodrigo@ximian.com>
Fixes #50294
diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c
index fb18fdc422..cfcf446ff8 100644
--- a/calendar/gui/alarm-notify/alarm-notify.c
+++ b/calendar/gui/alarm-notify/alarm-notify.c
@@ -27,6 +27,7 @@
#include <libecal/e-cal.h>
#include "alarm-notify.h"
#include "alarm-queue.h"
+#include "config-data.h"
#include "common/authentication.h"
#include "e-util/e-url.h"
@@ -36,6 +37,9 @@
struct _AlarmNotifyPrivate {
/* Mapping from EUri's to LoadedClient structures */
GHashTable *uri_client_hash;
+
+ /* ID of GConf notification listener */
+ guint notification_id;
};
@@ -64,16 +68,101 @@ alarm_notify_class_init (AlarmNotifyClass *klass)
object_class->finalize = alarm_notify_finalize;
}
+typedef struct {
+ AlarmNotify *an;
+ GPtrArray *cals;
+} ProcessRemovalsData;
+
+static void
+process_removal_in_hash (gpointer key, gpointer value, gpointer user_data)
+{
+ int i;
+ char *uri = key;
+ ProcessRemovalsData *prd = user_data;
+
+ /* search the list of selected calendars */
+ for (i = 0; i < prd->cals->len; i++) {
+ ESource *source;
+ char *source_uri;
+ gboolean found = FALSE;
+
+ source = prd->cals->pdata[i];
+ source_uri = e_source_get_uri (source);
+ if (strcmp (source_uri, uri) == 0)
+ found = TRUE;
+
+ g_free (source_uri);
+ if (found)
+ return;
+ }
+
+ /* not found, so remove it */
+ alarm_notify_remove_calendar (prd->an, uri);
+}
+
+static void
+conf_changed_cb (GConfClient *conf_client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
+{
+ AlarmNotify *an;
+ AlarmNotifyPrivate *priv;
+ GPtrArray *cals;
+ const char *key_name;
+ int i;
+ ProcessRemovalsData prd;
+
+ an = ALARM_NOTIFY (user_data);
+ priv = an->priv;
+
+ key_name = gconf_entry_get_key (entry);
+ if (!key_name ||
+ (key_name && strcmp (key_name, "/apps/evolution/calendar/sources") != 0) ||
+ (key_name && strcmp (key_name, "/apps/evolution/tasks/sources") != 0))
+ return;
+
+ cals = config_data_get_calendars_to_load ();
+ if (!cals)
+ return;
+
+ /* process the additions */
+ for (i = 0; i < cals->len; i++) {
+ ESource *source;
+ char *uri;
+
+ source = cals->pdata[i];
+
+ uri = e_source_get_uri (source);
+ if (!g_hash_table_lookup (priv->uri_client_hash, uri))
+ alarm_notify_add_calendar (an, uri, FALSE);
+
+ g_free (uri);
+ }
+
+ /* process the removals */
+ prd.an = an;
+ prd.cals = cals;
+ g_hash_table_foreach (priv->uri_client_hash, (GHFunc) process_removal_in_hash, &prd);
+
+ g_ptr_array_free (cals, TRUE);
+}
+
/* Object initialization function for the alarm notify system */
static void
alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass)
{
AlarmNotifyPrivate *priv;
+ GConfClient *conf_client;
priv = g_new0 (AlarmNotifyPrivate, 1);
an->priv = priv;
priv->uri_client_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+ /* setup listener for getting changes in selected calendars */
+ conf_client = config_data_get_conf_client ();
+ gconf_client_add_dir (conf_client, "/apps/evolution", GCONF_CLIENT_PRELOAD_NONE, NULL);
+
+ priv->notification_id = gconf_client_notify_add (conf_client, "/apps/evolution",
+ (GConfClientNotifyFunc) conf_changed_cb, an, NULL, NULL);
}
static void
@@ -97,6 +186,9 @@ alarm_notify_finalize (GObject *object)
an = ALARM_NOTIFY (object);
priv = an->priv;
+ gconf_client_notify_remove (config_data_get_conf_client (), priv->notification_id);
+ priv->notification_id = -1;
+
g_hash_table_foreach (priv->uri_client_hash, dequeue_client, NULL);
g_hash_table_destroy (priv->uri_client_hash);
diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c
index a659057559..b64378b1b8 100644
--- a/calendar/gui/e-calendar-table.c
+++ b/calendar/gui/e-calendar-table.c
@@ -702,7 +702,7 @@ delete_selected_components (ECalendarTable *cal_table)
GError *error = NULL;
e_cal_remove_object (comp_data->client,
- icalcomponent_get_uid (comp_data->icalcomp), &error);
+ icalcomponent_get_uid (comp_data->icalcomp), &error);
delete_error_dialog (error, E_CAL_COMPONENT_TODO);
g_clear_error (&error);
}