[gnome-calendar/gbsneto/edit-dialog-cleanup: 11/23] event-editor-dialog: Move summary to GcalSummarySection




commit 73cbe1f39c7bc0e03c4c2529f93a596d0b4c2102
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Oct 31 12:34:48 2020 -0300

    event-editor-dialog: Move summary to GcalSummarySection

 src/gui/event-editor/event-editor.gresource.xml  |   1 +
 src/gui/event-editor/gcal-event-editor-dialog.c  |  80 +++-------
 src/gui/event-editor/gcal-event-editor-dialog.ui |  54 +------
 src/gui/event-editor/gcal-summary-section.c      | 186 +++++++++++++++++++++++
 src/gui/event-editor/gcal-summary-section.h      |  30 ++++
 src/gui/event-editor/gcal-summary-section.ui     |  56 +++++++
 src/gui/event-editor/meson.build                 |   1 +
 7 files changed, 295 insertions(+), 113 deletions(-)
---
diff --git a/src/gui/event-editor/event-editor.gresource.xml b/src/gui/event-editor/event-editor.gresource.xml
index 5614d4af..1f244220 100644
--- a/src/gui/event-editor/event-editor.gresource.xml
+++ b/src/gui/event-editor/event-editor.gresource.xml
@@ -8,6 +8,7 @@
     <file compressed="true">gcal-multi-choice.ui</file>
     <file compressed="true">gcal-reminders-section.ui</file>
     <file compressed="true">gcal-schedule-section.ui</file>
+    <file compressed="true">gcal-summary-section.ui</file>
     <file compressed="true">gcal-time-selector.ui</file>
   </gresource>
 </gresources>
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.c b/src/gui/event-editor/gcal-event-editor-dialog.c
index e1c69d75..e6128bf0 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.c
+++ b/src/gui/event-editor/gcal-event-editor-dialog.c
@@ -28,6 +28,7 @@
 #include "gcal-event.h"
 #include "gcal-reminders-section.h"
 #include "gcal-schedule-section.h"
+#include "gcal-summary-section.h"
 
 #include <dazzle.h>
 #include <libecal/libecal.h>
@@ -62,6 +63,7 @@ struct _GcalEventEditorDialog
 
   GcalEventEditorSection *reminders_section;
   GcalEventEditorSection *schedule_section;
+  GcalEventEditorSection *summary_section;
 
   GtkWidget        *lock;
   GtkWidget        *source_image;
@@ -73,11 +75,10 @@ struct _GcalEventEditorDialog
   GtkWidget        *sources_button;
   GtkWidget        *sources_popover;
 
-  GtkWidget        *summary_entry;
-
-  GtkWidget        *location_entry;
   GtkWidget        *notes_text;
 
+  GBinding           *event_title_binding;
+
   /* actions */
   GMenu              *sources_menu;
   GSimpleActionGroup *action_group;
@@ -96,14 +97,6 @@ static void          on_calendar_selected_action_cb              (GSimpleAction
                                                                   GVariant           *value,
                                                                   gpointer            user_data);
 
-static void          on_summary_entry_changed_cb                 (GtkEntry              *entry,
-                                                                  GParamSpec            *pspec,
-                                                                  GcalEventEditorDialog *self);
-
-static void          on_location_entry_changed_cb                (GtkEntry              *entry,
-                                                                  GParamSpec            *pspec,
-                                                                  GcalEventEditorDialog *self);
-
 G_DEFINE_TYPE (GcalEventEditorDialog, gcal_event_editor_dialog, GTK_TYPE_DIALOG)
 
 enum
@@ -216,20 +209,6 @@ set_writable (GcalEventEditorDialog *self,
 static void
 gcal_event_editor_dialog_clear_data (GcalEventEditorDialog *self)
 {
-  /* summary */
-  g_signal_handlers_block_by_func (self->summary_entry, on_summary_entry_changed_cb, self);
-
-  gtk_entry_set_text (GTK_ENTRY (self->summary_entry), "");
-
-  g_signal_handlers_unblock_by_func (self->summary_entry, on_summary_entry_changed_cb, self);
-
-  /* location */
-  g_signal_handlers_block_by_func (self->location_entry, on_location_entry_changed_cb, self);
-
-  gtk_entry_set_text (GTK_ENTRY (self->location_entry), "");
-
-  g_signal_handlers_unblock_by_func (self->location_entry, on_location_entry_changed_cb, self);
-
   /* notes */
   gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text)), "", -1);
 }
@@ -239,9 +218,6 @@ apply_changes_to_event (GcalEventEditorDialog *self)
 {
   gchar *note_text;
 
-  /* Update summary */
-  gcal_event_set_summary (self->event, gtk_entry_get_text (GTK_ENTRY (self->summary_entry)));
-
   /* Update description */
   g_object_get (G_OBJECT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text))),
                 "text", &note_text,
@@ -252,6 +228,7 @@ apply_changes_to_event (GcalEventEditorDialog *self)
 
   gcal_event_editor_section_apply (self->reminders_section);
   gcal_event_editor_section_apply (self->schedule_section);
+  gcal_event_editor_section_apply (self->summary_section);
 }
 
 
@@ -321,22 +298,6 @@ transient_size_allocate_cb (GcalEventEditorDialog *self)
                                               MAX (400, (gint) (0.75 * alloc.height)));
 }
 
-static void
-on_location_entry_changed_cb (GtkEntry              *entry,
-                              GParamSpec            *pspec,
-                              GcalEventEditorDialog *self)
-{
-  gcal_event_set_location (self->event, gtk_entry_get_text (entry));
-}
-
-static void
-on_summary_entry_changed_cb (GtkEntry              *entry,
-                             GParamSpec            *pspec,
-                             GcalEventEditorDialog *self)
-{
-  gtk_widget_set_sensitive (self->done_button, gtk_entry_get_text_length (entry) > 0);
-}
-
 static void
 fix_reminders_label_height_cb (GtkWidget    *summary_label,
                                GdkRectangle *allocation,
@@ -520,6 +481,7 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
 
   g_type_ensure (GCAL_TYPE_REMINDERS_SECTION);
   g_type_ensure (GCAL_TYPE_SCHEDULE_SECTION);
+  g_type_ensure (GCAL_TYPE_SUMMARY_SECTION);
 
   object_class->finalize = gcal_event_editor_dialog_finalize;
   object_class->constructed = gcal_event_editor_dialog_constructed;
@@ -568,9 +530,6 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, cancel_button);
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, delete_button);
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, sources_button);
-  /* Entries */
-  gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, summary_entry);
-  gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, location_entry);
   /* Other */
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, notes_text);
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, titlebar);
@@ -582,13 +541,12 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, sources_popover);
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, reminders_section);
   gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, schedule_section);
+  gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, summary_section);
 
 
   /* callbacks */
   gtk_widget_class_bind_template_callback (widget_class, fix_reminders_label_height_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_action_button_clicked_cb);
-  gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_changed_cb);
-  gtk_widget_class_bind_template_callback (widget_class, on_location_entry_changed_cb);
 }
 
 static void
@@ -600,6 +558,7 @@ gcal_event_editor_dialog_init (GcalEventEditorDialog *self)
 
   g_object_bind_property (self, "context", self->reminders_section, "context", G_BINDING_DEFAULT);
   g_object_bind_property (self, "context", self->schedule_section, "context", G_BINDING_DEFAULT);
+  g_object_bind_property (self, "context", self->summary_section, "context", G_BINDING_DEFAULT);
 }
 
 /**
@@ -664,7 +623,6 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
   GcalEventEditorFlags flags;
   GcalCalendar *calendar;
   cairo_surface_t *surface;
-  const gchar *summary;
 
   GCAL_ENTRY;
 
@@ -692,29 +650,26 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
 
   fill_sources_menu (self);
 
-  /* Load new event data */
-  /* summary */
-  summary = gcal_event_get_summary (cloned_event);
-
-  if (g_strcmp0 (summary, "") == 0)
-    gtk_entry_set_text (GTK_ENTRY (self->summary_entry), _("Unnamed event"));
-  else
-    gtk_entry_set_text (GTK_ENTRY (self->summary_entry), summary);
-
   /* dialog titlebar's title & subtitle */
   surface = get_circle_surface_from_color (gcal_event_get_color (cloned_event), 10);
   gtk_image_set_from_surface (GTK_IMAGE (self->source_image), surface);
   g_clear_pointer (&surface, cairo_surface_destroy);
 
+  g_clear_pointer (&self->event_title_binding, g_binding_unbind);
+  self->event_title_binding = g_object_bind_property (cloned_event,
+                                                      "summary",
+                                                      self->title_label,
+                                                      "label",
+                                                      G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+  g_object_add_weak_pointer (G_OBJECT (self->event_title_binding),
+                             (gpointer*) &self->event_title_binding);
+
   gtk_label_set_label (GTK_LABEL (self->subtitle_label), gcal_calendar_get_name (calendar));
   self->selected_calendar = calendar;
 
   /* recurrence_changed */
   self->recurrence_changed = FALSE;
 
-  /* location */
-  gtk_entry_set_text (GTK_ENTRY (self->location_entry), gcal_event_get_location (cloned_event));
-
   /* notes */
   gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text)),
                             gcal_event_get_description (cloned_event),
@@ -730,6 +685,7 @@ out:
 
   gcal_event_editor_section_set_event (self->reminders_section, cloned_event, flags);
   gcal_event_editor_section_set_event (self->schedule_section, cloned_event, flags);
+  gcal_event_editor_section_set_event (self->summary_section, cloned_event, flags);
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EVENT]);
 
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.ui 
b/src/gui/event-editor/gcal-event-editor-dialog.ui
index d40d3fd5..ff435010 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.ui
+++ b/src/gui/event-editor/gcal-event-editor-dialog.ui
@@ -56,7 +56,6 @@
                         <property name="can_focus">False</property>
                         <property name="ellipsize">middle</property>
                         <property name="max_width_chars">40</property>
-                        <property name="label" bind-source="summary_entry" bind-property="text" 
bind-flags="default" />
                         <style>
                           <class name="title"/>
                         </style>
@@ -139,59 +138,12 @@
                 <property name="margin">18</property>
                 <property name="spacing">12</property>
                 <property name="orientation">vertical</property>
+
+                <!-- Summary -->
                 <child>
-                  <object class="GtkListBox">
+                  <object class="GcalSummarySection" id="summary_section">
                     <property name="visible">True</property>
-                    <property name="selection-mode">none</property>
                     <property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" 
bind-flags="default" />
-
-                    <style>
-                      <class name="frame" />
-                    </style>
-
-                    <!-- Summary -->
-                    <child>
-                      <object class="HdyActionRow">
-                        <property name="visible">True</property>
-                        <property name="title" translatable="yes">Title</property>
-                        <property name="activatable-widget">summary_entry</property>
-
-                        <child>
-                          <object class="GtkEntry" id="summary_entry">
-                            <property name="visible">True</property>
-                            <property name="valign">center</property>
-                            <property name="can_focus">True</property>
-                            <property name="editable" bind-source="GcalEventEditorDialog" 
bind-property="writable" bind-flags="default" />
-                            <property name="sensitive" bind-source="GcalEventEditorDialog" 
bind-property="writable" bind-flags="default" />
-                            <signal name="notify::text" handler="on_summary_entry_changed_cb" 
object="GcalEventEditorDialog" swapped="no"/>
-                          </object>
-                        </child>
-
-                      </object>
-                    </child>
-
-                    <!-- Location -->
-                    <child>
-                      <object class="HdyActionRow">
-                        <property name="visible">True</property>
-                        <property name="title" translatable="yes">Location</property>
-                        <property name="activatable-widget">location_entry</property>
-
-                        <child>
-                          <object class="GtkEntry" id="location_entry">
-                            <property name="visible">True</property>
-                            <property name="valign">center</property>
-                            <property name="can_focus">True</property>
-                            <property name="secondary_icon_name">find-location-symbolic</property>
-                            <property name="editable" bind-source="GcalEventEditorDialog" 
bind-property="writable" bind-flags="default" />
-                            <property name="sensitive" bind-source="GcalEventEditorDialog" 
bind-property="writable" bind-flags="default" />
-                            <signal name="notify::text" handler="on_location_entry_changed_cb" 
object="GcalEventEditorDialog" swapped="no"/>
-                          </object>
-                        </child>
-
-                      </object>
-                    </child>
-
                   </object>
                 </child>
 
diff --git a/src/gui/event-editor/gcal-summary-section.c b/src/gui/event-editor/gcal-summary-section.c
new file mode 100644
index 00000000..e987bce5
--- /dev/null
+++ b/src/gui/event-editor/gcal-summary-section.c
@@ -0,0 +1,186 @@
+/* gcal-summary-section.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "GcalSummarySection"
+
+#include "gcal-context.h"
+#include "gcal-debug.h"
+#include "gcal-event-editor-section.h"
+#include "gcal-summary-section.h"
+
+#include <glib/gi18n.h>
+
+struct _GcalSummarySection
+{
+  GtkBin              parent;
+
+  GtkEntry           *summary_entry;
+  GtkEntry           *location_entry;
+
+  GcalContext        *context;
+  GcalEvent          *event;
+};
+
+
+static void          gcal_event_editor_section_iface_init        (GcalEventEditorSectionInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GcalSummarySection, gcal_summary_section, GTK_TYPE_BIN,
+                         G_IMPLEMENT_INTERFACE (GCAL_TYPE_EVENT_EDITOR_SECTION, 
gcal_event_editor_section_iface_init))
+
+enum
+{
+  PROP_0,
+  PROP_CONTEXT,
+  N_PROPS
+};
+
+/*
+ * GcalEventEditorSection interface
+ */
+
+static void
+gcal_reminders_section_set_event (GcalEventEditorSection *section,
+                                  GcalEvent              *event,
+                                  GcalEventEditorFlags    flags)
+{
+  GcalSummarySection *self;
+  const gchar *summary;
+
+  GCAL_ENTRY;
+
+  self = GCAL_SUMMARY_SECTION (section);
+
+  g_set_object (&self->event, event);
+
+  if (!event)
+    GCAL_RETURN ();
+
+  summary = gcal_event_get_summary (event);
+
+  if (g_strcmp0 (summary, "") == 0)
+    gtk_entry_set_text (GTK_ENTRY (self->summary_entry), _("Unnamed event"));
+  else
+    gtk_entry_set_text (GTK_ENTRY (self->summary_entry), summary);
+
+  gtk_entry_set_text (self->location_entry, gcal_event_get_location (event));
+
+  GCAL_EXIT;
+}
+
+static void
+gcal_reminders_section_apply (GcalEventEditorSection *section)
+{
+  GcalSummarySection *self;
+
+  GCAL_ENTRY;
+
+  self = GCAL_SUMMARY_SECTION (section);
+
+  gcal_event_set_summary (self->event, gtk_entry_get_text (self->summary_entry));
+  gcal_event_set_location (self->event, gtk_entry_get_text (self->location_entry));
+
+  GCAL_EXIT;
+}
+
+static void
+gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
+{
+  iface->set_event = gcal_reminders_section_set_event;
+  iface->apply = gcal_reminders_section_apply;
+}
+
+
+/*
+ * GObject overrides
+ */
+
+static void
+gcal_summary_section_finalize (GObject *object)
+{
+  GcalSummarySection *self = (GcalSummarySection *)object;
+
+  g_clear_object (&self->context);
+  g_clear_object (&self->event);
+
+  G_OBJECT_CLASS (gcal_summary_section_parent_class)->finalize (object);
+}
+
+static void
+gcal_summary_section_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  GcalSummarySection *self = GCAL_SUMMARY_SECTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      g_value_set_object (value, self->context);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gcal_summary_section_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  GcalSummarySection *self = GCAL_SUMMARY_SECTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      g_assert (self->context == NULL);
+      self->context = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gcal_summary_section_class_init (GcalSummarySectionClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gcal_summary_section_finalize;
+  object_class->get_property = gcal_summary_section_get_property;
+  object_class->set_property = gcal_summary_section_set_property;
+
+  g_object_class_override_property (object_class, PROP_CONTEXT, "context");
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/calendar/ui/event-editor/gcal-summary-section.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, location_entry);
+  gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, summary_entry);
+}
+
+static void
+gcal_summary_section_init (GcalSummarySection *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/gui/event-editor/gcal-summary-section.h b/src/gui/event-editor/gcal-summary-section.h
new file mode 100644
index 00000000..6c747bcf
--- /dev/null
+++ b/src/gui/event-editor/gcal-summary-section.h
@@ -0,0 +1,30 @@
+/* gcal-summary-section.h
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_SUMMARY_SECTION (gcal_summary_section_get_type())
+G_DECLARE_FINAL_TYPE (GcalSummarySection, gcal_summary_section, GCAL, SUMMARY_SECTION, GtkBin)
+
+G_END_DECLS
diff --git a/src/gui/event-editor/gcal-summary-section.ui b/src/gui/event-editor/gcal-summary-section.ui
new file mode 100644
index 00000000..e7885778
--- /dev/null
+++ b/src/gui/event-editor/gcal-summary-section.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GcalSummarySection" parent="GtkBin">
+    <property name="can_focus">False</property>
+
+    <child>
+      <object class="GtkListBox">
+        <property name="visible">True</property>
+        <property name="selection-mode">none</property>
+
+        <style>
+          <class name="frame" />
+        </style>
+
+        <!-- Summary -->
+        <child>
+          <object class="HdyActionRow">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes">Title</property>
+            <property name="activatable-widget">summary_entry</property>
+
+            <child>
+              <object class="GtkEntry" id="summary_entry">
+                <property name="visible">True</property>
+                <property name="valign">center</property>
+                <property name="can_focus">True</property>
+              </object>
+            </child>
+
+          </object>
+        </child>
+
+        <!-- Location -->
+        <child>
+          <object class="HdyActionRow">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes">Location</property>
+            <property name="activatable-widget">location_entry</property>
+
+            <child>
+              <object class="GtkEntry" id="location_entry">
+                <property name="visible">True</property>
+                <property name="valign">center</property>
+                <property name="can_focus">True</property>
+                <property name="secondary_icon_name">find-location-symbolic</property>
+              </object>
+            </child>
+
+          </object>
+        </child>
+
+      </object>
+    </child>
+
+  </template>
+</interface>
diff --git a/src/gui/event-editor/meson.build b/src/gui/event-editor/meson.build
index 582da5c2..9f21362b 100644
--- a/src/gui/event-editor/meson.build
+++ b/src/gui/event-editor/meson.build
@@ -16,5 +16,6 @@ sources += files(
   'gcal-multi-choice.c',
   'gcal-reminders-section.c',
   'gcal-schedule-section.c',
+  'gcal-summary-section.c',
   'gcal-time-selector.c',
 )


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