aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/gnome-cal.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-06-01 08:48:01 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-06-01 08:48:01 +0800
commit19150e7c7b614544188f93dbffd748a2846d2a1b (patch)
tree038bed0dd7a7d6921d19cc0a992910ea5c1144fa /calendar/gui/gnome-cal.c
parentebdac7989a6fcb20ddd3ecf7b875d7c16b75cabb (diff)
downloadgsoc2013-evolution-19150e7c7b614544188f93dbffd748a2846d2a1b.tar.gz
gsoc2013-evolution-19150e7c7b614544188f93dbffd748a2846d2a1b.tar.zst
gsoc2013-evolution-19150e7c7b614544188f93dbffd748a2846d2a1b.zip
Added a hash table to map calendar objects to their respective event
2000-05-31 Federico Mena Quintero <federico@helixcode.com> * gui/gnome-cal.h (GnomeCalendar): Added a hash table to map calendar objects to their respective event editors. * gui/gnome-cal.c (gnome_calendar_init): Create the object_editor_hash. (gnome_calendar_destroy): Free the object_editor_hash. (gnome_calendar_edit_object): New function to centralize the launching of event editors; if one already exists for a particular calendar object, we just raise its window. (edit): Use gnome_calendar_edit_object(). * gui/calendar-commands.c (display_objedit): Use gnome_calendar_edit_object(). (display_objedit_today): Likewise. * gui/e-day-view.c (e_day_view_on_new_appointment): Likewise. (e_day_view_on_edit_appointment): Likewise. * gui/e-week-view.c (e_week_view_on_new_appointment): Likewise. (e_week_view_on_edit_appointment): Likewise. * gui/event-editor.c (event_editor_new): Do not take in an iCalObject; rather provide an event_editor_set_ical_object() function. We need this because a single editor may be switched between different calendar objects. Also, do not show the event editor; leave it up to the client code. (event_editor_construct): Likewise. (clear_widgets): New function to clear the widgets to default values. (fill_widgets): New function to fill in the widgets from the iCalObject. We don't do this in init_widgets() anymore. (free_exception_clist_data): New function to free the exceptions clist data. We were leaking the row data. (init_widgets): Hook to the destroy signal of the exceptions clist. (event_editor_set_ical_object): New function. Now it also makes a copy of the calendar object for the event editor; clients do not need to copy it anymore. (event_editor_destroy): Unref the UI handler as well. (event_editor_class_init): New "ical_object_released" signal to notify the parent that we are no longer editing the calendar object. (make_title_from_ico): Handle NULL objects. * gui/event-editor.h (EventEditor): Removed fields that are no longer used. svn path=/trunk/; revision=3317
Diffstat (limited to 'calendar/gui/gnome-cal.c')
-rw-r--r--calendar/gui/gnome-cal.c89
1 files changed, 78 insertions, 11 deletions
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index b6d035c201..e1e366885f 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -24,7 +24,7 @@
#include "alarm.h"
#include "e-day-view.h"
#include "e-week-view.h"
-#include "eventedit.h"
+#include "event-editor.h"
#include "gncal-todo.h"
#include "gnome-cal.h"
#include "calendar-commands.h"
@@ -99,6 +99,7 @@ gnome_calendar_class_init (GnomeCalendarClass *class)
static void
gnome_calendar_init (GnomeCalendar *gcal)
{
+ gcal->object_editor_hash = g_hash_table_new (g_str_hash, g_str_equal);
gcal->alarms = g_hash_table_new (g_str_hash, g_str_equal);
}
@@ -121,6 +122,16 @@ free_object_alarms (gpointer key, gpointer value, gpointer data)
g_free (oa);
}
+/* Used from g_hash_table_foreach(); frees an UID string */
+static void
+free_uid (gpointer key, gpointer value, gpointer data)
+{
+ char *uid;
+
+ uid = key;
+ g_free (uid);
+}
+
static void
gnome_calendar_destroy (GtkObject *object)
{
@@ -137,6 +148,10 @@ gnome_calendar_destroy (GtkObject *object)
g_hash_table_destroy (gcal->alarms);
gcal->alarms = NULL;
+ g_hash_table_foreach (gcal->object_editor_hash, free_uid, NULL);
+ g_hash_table_destroy (gcal->object_editor_hash);
+ gcal->object_editor_hash = NULL;
+
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
@@ -525,16 +540,7 @@ snooze (GnomeCalendar *gcal, iCalObject *ico, time_t occur, int snooze_mins, gbo
static void
edit (GnomeCalendar *gcal, iCalObject *ico)
{
- iCalObject *new_ico;
- GtkWidget *event_editor;
-
- /* We must duplicate the iCalObject, since the event editor will change
- * the fields.
- */
- new_ico = ical_object_duplicate (ico);
-
- event_editor = event_editor_new (gcal, new_ico);
- gtk_widget_show (event_editor);
+ gnome_calendar_edit_object (gcal, ico);
}
struct alarm_notify_closure {
@@ -1301,6 +1307,67 @@ gnome_calendar_set_selected_time_range (GnomeCalendar *gcal,
gnome_calendar_update_gtk_calendar (gcal);
}
+/* Brings attention to a window by raising it and giving it focus */
+static void
+raise_and_focus (GtkWidget *widget)
+{
+ g_assert (GTK_WIDGET_REALIZED (widget));
+ gdk_window_show (widget->window);
+ gtk_widget_grab_focus (widget);
+}
+
+/* Callback used when an event editor finishes editing an object */
+static void
+ical_object_released_cb (EventEditor *ee, const char *uid, gpointer data)
+{
+ GnomeCalendar *gcal;
+ gboolean result;
+ gpointer orig_key;
+ char *orig_uid;
+
+ gcal = GNOME_CALENDAR (data);
+
+ result = g_hash_table_lookup_extended (gcal->object_editor_hash, uid, &orig_key, NULL);
+ g_assert (result != FALSE);
+
+ orig_uid = orig_key;
+
+ g_hash_table_remove (gcal->object_editor_hash, orig_uid);
+ g_free (orig_uid);
+}
+
+void
+gnome_calendar_edit_object (GnomeCalendar *gcal, iCalObject *ico)
+{
+ GtkWidget *ee;
+
+ g_return_if_fail (gcal != NULL);
+ g_return_if_fail (GNOME_IS_CALENDAR (gcal));
+ g_return_if_fail (ico != NULL);
+ g_return_if_fail (ico->uid != NULL);
+
+ ee = g_hash_table_lookup (gcal->object_editor_hash, ico->uid);
+ if (!ee) {
+ ee = event_editor_new (gcal);
+ if (!ee) {
+ g_message ("gnome_calendar_edit_object(): Could not create the event editor");
+ return;
+ }
+
+ /* FIXME: what to do when an event editor wants to switch
+ * objects? We would need to know about it as well.
+ */
+
+ g_hash_table_insert (gcal->object_editor_hash, g_strdup (ico->uid), ee);
+ gtk_signal_connect (GTK_OBJECT (ee), "ical_object_released",
+ GTK_SIGNAL_FUNC (ical_object_released_cb), gcal);
+
+ event_editor_set_ical_object (EVENT_EDITOR (ee), ico);
+ }
+
+ gtk_widget_show_now (ee);
+ raise_and_focus (ee);
+}
/* Returns the selected time range for the current view. Note that this may be
different from the fields in the GnomeCalendar, since the view may clip