[gnome-calendar/ui-rewrite] app: active More details button from new event popover



commit 8d313b7113adc63f4dacbd7265ad340f7985d46d
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Thu Dec 4 16:25:59 2014 -0500

    app: active More details button from new event popover
    
    GcalWindow got connected to GcalManager, and pass just created component
    to GcalEditDialog
    GcalEditDialog gained support to handle component not committed to
    manager singleton instance yet.

 src/gcal-edit-dialog.c |   29 ++++++++++++++++++++++++++-
 src/gcal-edit-dialog.h |    4 +++
 src/gcal-window.c      |   49 +++++++++++++++++++++++++++++++++++++----------
 3 files changed, 69 insertions(+), 13 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index a94f4fb..e437632 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);
 }
 
@@ -626,6 +639,16 @@ gcal_edit_dialog_new (void)
 }
 
 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 ca30ff3..4e43274 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 8413872..055ee7d 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);
+  /* 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;
 
-  /* 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);
+      edata = g_new0 (GcalEventData, 1);
+      edata->source = source;
+      edata->event_component = comp;
 
-  g_object_unref (source);
+      if (priv->edit_dialog == NULL)
+        init_edit_dialog (GCAL_WINDOW (user_data));
 
-  /* reset and hide */
-  set_new_event_mode (GCAL_WINDOW (user_data), FALSE);
+      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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]