event-editor/summary-section: Write to event directly
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/711>
This commit is contained in:
@@ -4,10 +4,11 @@ using Adw 1;
|
|||||||
template $GcalSummarySection: Adw.PreferencesGroup {
|
template $GcalSummarySection: Adw.PreferencesGroup {
|
||||||
Adw.EntryRow summary_entry {
|
Adw.EntryRow summary_entry {
|
||||||
title: _("Title");
|
title: _("Title");
|
||||||
changed => $on_summary_entry_text_changed_cb(template) not-swapped;
|
notify::text => $on_summary_entry_text_changed_cb(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
Adw.EntryRow location_entry {
|
Adw.EntryRow location_entry {
|
||||||
title: _("Location");
|
title: _("Location");
|
||||||
|
notify::text => $on_location_entry_changed_cb(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#define G_LOG_DOMAIN "GcalSummarySection"
|
#define G_LOG_DOMAIN "GcalSummarySection"
|
||||||
|
|
||||||
#include "gcal-debug.h"
|
#include "gcal-debug.h"
|
||||||
|
#include "gcal-event-editor-dialog.h"
|
||||||
#include "gcal-event-editor-section.h"
|
#include "gcal-event-editor-section.h"
|
||||||
#include "gcal-summary-section.h"
|
#include "gcal-summary-section.h"
|
||||||
#include "gcal-utils.h"
|
#include "gcal-utils.h"
|
||||||
@@ -35,6 +36,7 @@ struct _GcalSummarySection
|
|||||||
AdwEntryRow *location_entry;
|
AdwEntryRow *location_entry;
|
||||||
|
|
||||||
GcalEvent *event;
|
GcalEvent *event;
|
||||||
|
GcalEvent *cloned_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +45,48 @@ static void gcal_event_editor_section_iface_init (GcalEventEdito
|
|||||||
G_DEFINE_TYPE_WITH_CODE (GcalSummarySection, gcal_summary_section, ADW_TYPE_PREFERENCES_GROUP,
|
G_DEFINE_TYPE_WITH_CODE (GcalSummarySection, gcal_summary_section, ADW_TYPE_PREFERENCES_GROUP,
|
||||||
G_IMPLEMENT_INTERFACE (GCAL_TYPE_EVENT_EDITOR_SECTION, gcal_event_editor_section_iface_init))
|
G_IMPLEMENT_INTERFACE (GCAL_TYPE_EVENT_EDITOR_SECTION, gcal_event_editor_section_iface_init))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callbacks
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_summary_entry_text_changed_cb (GcalSummarySection *self)
|
||||||
|
{
|
||||||
|
const char *text = gtk_editable_get_text (GTK_EDITABLE (self->summary_entry));
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GcalEvent *event;
|
||||||
|
|
||||||
|
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||||
|
|
||||||
|
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
if (gcal_is_valid_event_name (text))
|
||||||
|
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||||
|
else
|
||||||
|
gtk_widget_add_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||||
|
|
||||||
|
gcal_event_set_summary (event, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_location_entry_changed_cb (GcalSummarySection *self)
|
||||||
|
{
|
||||||
|
const char *text = gtk_editable_get_text (GTK_EDITABLE (self->location_entry));
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GcalEvent *event;
|
||||||
|
|
||||||
|
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||||
|
|
||||||
|
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
gcal_event_set_location (event, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GcalEventEditorSection interface
|
* GcalEventEditorSection interface
|
||||||
*/
|
*/
|
||||||
@@ -58,28 +102,29 @@ gcal_reminders_section_set_event (GcalEventEditorSection *section,
|
|||||||
|
|
||||||
self = GCAL_SUMMARY_SECTION (section);
|
self = GCAL_SUMMARY_SECTION (section);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->cloned_event, g_object_unref);
|
||||||
|
|
||||||
g_set_object (&self->event, event);
|
g_set_object (&self->event, event);
|
||||||
|
|
||||||
if (!event)
|
if (!event)
|
||||||
GCAL_RETURN ();
|
GCAL_RETURN ();
|
||||||
|
|
||||||
|
g_set_object (&self->cloned_event, g_object_ref (gcal_event_new_from_event (self->event)));
|
||||||
|
|
||||||
|
g_signal_handlers_block_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_block_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), gcal_event_get_summary (event));
|
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), gcal_event_get_summary (event));
|
||||||
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), gcal_event_get_location (event));
|
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), gcal_event_get_location (event));
|
||||||
|
|
||||||
|
g_signal_handlers_unblock_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_unblock_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||||
|
|
||||||
GCAL_EXIT;
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
on_summary_entry_text_changed_cb (AdwEntryRow *entry_row)
|
|
||||||
{
|
|
||||||
if (gcal_is_valid_event_name (gtk_editable_get_text (GTK_EDITABLE (entry_row))))
|
|
||||||
gtk_widget_remove_css_class (GTK_WIDGET (entry_row), "error");
|
|
||||||
else
|
|
||||||
gtk_widget_add_css_class (GTK_WIDGET (entry_row), "error");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_reminders_section_apply (GcalEventEditorSection *section)
|
gcal_reminders_section_apply (GcalEventEditorSection *section)
|
||||||
{
|
{
|
||||||
@@ -105,8 +150,8 @@ gcal_reminders_section_changed (GcalEventEditorSection *section)
|
|||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
self = GCAL_SUMMARY_SECTION (section);
|
self = GCAL_SUMMARY_SECTION (section);
|
||||||
event_summary = gcal_event_get_summary (self->event);
|
event_summary = gcal_event_get_summary (self->cloned_event);
|
||||||
event_location = gcal_event_get_location (self->event);
|
event_location = gcal_event_get_location (self->cloned_event);
|
||||||
|
|
||||||
GCAL_RETURN (g_strcmp0 (event_summary, gtk_editable_get_text (GTK_EDITABLE (self->summary_entry))) != 0 ||
|
GCAL_RETURN (g_strcmp0 (event_summary, gtk_editable_get_text (GTK_EDITABLE (self->summary_entry))) != 0 ||
|
||||||
g_strcmp0 (event_location, gtk_editable_get_text (GTK_EDITABLE (self->location_entry))) != 0);
|
g_strcmp0 (event_location, gtk_editable_get_text (GTK_EDITABLE (self->location_entry))) != 0);
|
||||||
@@ -133,6 +178,52 @@ gcal_summary_section_grab_focus (GtkWidget *widget)
|
|||||||
return gtk_widget_grab_focus (GTK_WIDGET (self->summary_entry));
|
return gtk_widget_grab_focus (GTK_WIDGET (self->summary_entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gcal_summary_section_map (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GcalSummarySection *self = GCAL_SUMMARY_SECTION (widget);
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GcalEvent *event;
|
||||||
|
|
||||||
|
dialog = gtk_widget_get_ancestor (widget, GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
||||||
|
|
||||||
|
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
||||||
|
|
||||||
|
g_signal_handlers_block_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_block_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
|
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), gcal_event_get_summary (event));
|
||||||
|
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), gcal_event_get_location (event));
|
||||||
|
|
||||||
|
g_signal_handlers_unblock_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_unblock_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
|
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (gcal_summary_section_parent_class)->map (widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gcal_summary_section_unmap (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GcalSummarySection *self = GCAL_SUMMARY_SECTION (widget);
|
||||||
|
|
||||||
|
g_signal_handlers_block_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_block_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
|
gtk_editable_delete_text (GTK_EDITABLE (self->summary_entry), 0, -1);
|
||||||
|
gtk_editable_delete_text (GTK_EDITABLE (self->location_entry), 0, -1);
|
||||||
|
|
||||||
|
g_signal_handlers_unblock_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
|
||||||
|
g_signal_handlers_unblock_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||||
|
|
||||||
|
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (gcal_summary_section_parent_class)->unmap (widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GObject overrides
|
* GObject overrides
|
||||||
@@ -145,6 +236,8 @@ gcal_summary_section_finalize (GObject *object)
|
|||||||
|
|
||||||
g_clear_object (&self->event);
|
g_clear_object (&self->event);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->cloned_event, g_object_unref);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gcal_summary_section_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gcal_summary_section_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +250,8 @@ gcal_summary_section_class_init (GcalSummarySectionClass *klass)
|
|||||||
object_class->finalize = gcal_summary_section_finalize;
|
object_class->finalize = gcal_summary_section_finalize;
|
||||||
|
|
||||||
widget_class->grab_focus = gcal_summary_section_grab_focus;
|
widget_class->grab_focus = gcal_summary_section_grab_focus;
|
||||||
|
widget_class->map = gcal_summary_section_map;
|
||||||
|
widget_class->unmap = gcal_summary_section_unmap;
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-summary-section.ui");
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-summary-section.ui");
|
||||||
|
|
||||||
@@ -164,6 +259,7 @@ gcal_summary_section_class_init (GcalSummarySectionClass *klass)
|
|||||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, summary_entry);
|
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, summary_entry);
|
||||||
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_text_changed_cb);
|
gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_text_changed_cb);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, on_location_entry_changed_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user