diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c index a94f4fb6..e4376328 100644 --- a/src/gcal-edit-dialog.c +++ b/src/gcal-edit-dialog.c @@ -58,6 +58,8 @@ typedef struct ESource *source; /* weak reference */ ECalComponent *component; + /* flags */ + gboolean event_is_new; gboolean setting_event; } GcalEditDialogPrivate; @@ -490,6 +492,9 @@ gcal_edit_dialog_finalize (GObject *object) if (priv->event_uid != NULL) g_free (priv->event_uid); + if (priv->source != NULL) + g_object_unref (priv->source); + if (priv->component != NULL) g_object_unref (priv->component); @@ -588,11 +593,19 @@ static void gcal_edit_dialog_action_button_clicked (GtkWidget *widget, gpointer user_data) { + GcalEditDialogPrivate *priv; gint response; + priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); response = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "response")); + if (response == GCAL_RESPONSE_SAVE_EVENT && + priv->event_is_new) + { + response = GCAL_RESPONSE_CREATE_EVENT; + } + gtk_dialog_response (GTK_DIALOG (user_data), response); } @@ -625,6 +638,16 @@ gcal_edit_dialog_new (void) return dialog; } +void +gcal_edit_dialog_set_event_is_new (GcalEditDialog *dialog, + gboolean event_is_new) +{ + GcalEditDialogPrivate *priv; + + priv = gcal_edit_dialog_get_instance_private (dialog); + priv->event_is_new = event_is_new; +} + void gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, GcalEventData *data) @@ -648,7 +671,10 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, priv->setting_event = TRUE; - priv->source = data->source; + if (priv->source != NULL) + g_clear_object (&(priv->source)); + priv->source = g_object_ref (data->source); + if (priv->component != NULL) g_object_unref (priv->component); priv->component = e_cal_component_clone (data->event_component); @@ -922,4 +948,3 @@ gcal_edit_dialog_get_end_date (GcalEditDialog *dialog) return date; } - diff --git a/src/gcal-edit-dialog.h b/src/gcal-edit-dialog.h index ca30ff3d..4e43274d 100644 --- a/src/gcal-edit-dialog.h +++ b/src/gcal-edit-dialog.h @@ -28,6 +28,7 @@ G_BEGIN_DECLS #define GCAL_RESPONSE_DELETE_EVENT 2 #define GCAL_RESPONSE_SAVE_EVENT 4 +#define GCAL_RESPONSE_CREATE_EVENT 6 #define GCAL_TYPE_EDIT_DIALOG (gcal_edit_dialog_get_type ()) @@ -55,6 +56,9 @@ GType gcal_edit_dialog_get_type (void); GtkWidget* gcal_edit_dialog_new (void); +void gcal_edit_dialog_set_event_is_new (GcalEditDialog *dialog, + gboolean event_is_new); + void gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, GcalEventData *data); diff --git a/src/gcal-window.c b/src/gcal-window.c index 84138721..055ee7d1 100644 --- a/src/gcal-window.c +++ b/src/gcal-window.c @@ -655,25 +655,44 @@ create_event (gpointer user_data, GcalWindowPrivate *priv; ESource *source; + ECalComponent *comp; priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data)); - priv->open_edit_dialog = (widget == priv->new_event_details_button); - - source = gcal_manager_get_default_source (priv->manager); - - /* create the event */ - gcal_manager_create_event ( - priv->manager, - e_source_get_uid (source), - gtk_entry_get_text (GTK_ENTRY (priv->new_event_what_entry)), - priv->event_creation_data->start_date, - priv->event_creation_data->end_date); - - g_object_unref (source); - /* reset and hide */ set_new_event_mode (GCAL_WINDOW (user_data), FALSE); + + source = gcal_manager_get_default_source (priv->manager); + comp = build_component_from_details (gtk_entry_get_text (GTK_ENTRY (priv->new_event_what_entry)), + priv->event_creation_data->start_date, + priv->event_creation_data->end_date); + if (widget == priv->new_event_details_button) + { + GcalEventData *edata; + + edata = g_new0 (GcalEventData, 1); + edata->source = source; + edata->event_component = comp; + + if (priv->edit_dialog == NULL) + init_edit_dialog (GCAL_WINDOW (user_data)); + + gcal_edit_dialog_set_event_is_new (GCAL_EDIT_DIALOG (priv->edit_dialog), + TRUE); + gcal_edit_dialog_set_event_data (GCAL_EDIT_DIALOG (priv->edit_dialog), + edata); + g_object_unref (comp); + g_free (edata); + + gtk_dialog_run (GTK_DIALOG (priv->edit_dialog)); + } + else + { + /* create the event */ + gcal_manager_create_event (priv->manager, source, comp); + } + + g_object_unref (source); } static void @@ -738,6 +757,14 @@ edit_dialog_closed (GtkDialog *dialog, switch (response) { + case GCAL_RESPONSE_CREATE_EVENT: + /* retrieve the component from the dialog*/ + gcal_manager_create_event (priv->manager, + gcal_edit_dialog_get_source (edit_dialog), + gcal_edit_dialog_get_component (edit_dialog)); + + break; + case GCAL_RESPONSE_SAVE_EVENT: /* retrieve the component from the dialog*/ component = gcal_edit_dialog_get_component (edit_dialog);