[gnome-calendar/mcatanzaro/one-at-a-time: 17/18] new-calendar-page: don't add local calendar if remote address is given
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/mcatanzaro/one-at-a-time: 17/18] new-calendar-page: don't add local calendar if remote address is given
- Date: Tue, 14 Apr 2020 20:31:02 +0000 (UTC)
commit 28496c99739bdd85ed82c6f6cfdfb160e3e8f78b
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Thu Apr 2 19:06:57 2020 -0500
new-calendar-page: don't add local calendar if remote address is given
If the user has entered a remote address, then adding a new empty local
calendar is definitely not desired. So stop doing it. Create the
local_source only if the user has clicked the Add button and no remote
sources are available. Rename the relevant widgets accordingly, and
update the add button's sensitivity check to account for the fact that
self->local_source no longer exists.
See #566, but note this does not solve #566 as there is an
additional bug somewhere else causing multiple remote calendars to be
added at the same time when only a single ical file is used as the data
source. This dialog does support adding multiple calendars (ESources)
from a single URL, but that shouldn't be happening when the URL points
to a single ical file. That bug appears to be in a different level of
the code, not GcalNewCalendarPage.
Also note that we require further changes to the strings on this dialog
to conform to this new behavior, in a future commit. This commit is
designed to not break string freeze.
.../calendar-management/gcal-new-calendar-page.c | 123 +++++++++++----------
.../calendar-management/gcal-new-calendar-page.ui | 5 +-
2 files changed, 68 insertions(+), 60 deletions(-)
---
diff --git a/src/gui/calendar-management/gcal-new-calendar-page.c
b/src/gui/calendar-management/gcal-new-calendar-page.c
index ee784fff..71f993ab 100644
--- a/src/gui/calendar-management/gcal-new-calendar-page.c
+++ b/src/gui/calendar-management/gcal-new-calendar-page.c
@@ -54,8 +54,8 @@ struct _GcalNewCalendarPage
GtkEntry *credentials_password_entry;
GtkPopover *credentials_popover;
GtkEntry *credentials_user_entry;
- GtkColorChooser *local_calendar_color_button;
- GtkEntry *local_calendar_name_entry;
+ GtkColorChooser *calendar_color_button;
+ GtkEntry *calendar_name_entry;
GtkWidget *web_sources_listbox;
GtkWidget *web_sources_revealer;
@@ -65,8 +65,6 @@ struct _GcalNewCalendarPage
GCancellable *cancellable;
- ESource *local_source;
-
GcalContext *context;
};
@@ -134,53 +132,40 @@ calendar_path_to_name_suggestion (GFile *file)
return g_steal_pointer (&basename);
}
-static void
-update_add_button (GcalNewCalendarPage *self)
+static gchar *
+get_calendar_name (GcalNewCalendarPage *self)
{
- gboolean valid;
+ g_autofree gchar *name = NULL;
- valid = (self->local_source != NULL || self->remote_sources != NULL) &&
- self->calendar_address_entry_state != ENTRY_STATE_VALIDATING &&
- self->calendar_address_entry_state != ENTRY_STATE_INVALID;
+ name = g_strdup (gtk_entry_get_text (self->calendar_name_entry));
+ if (!name)
+ return NULL;
- gtk_widget_set_sensitive (self->add_button, valid);
+ name = g_strstrip (name);
+ if (g_utf8_strlen (name, -1) == 0)
+ return NULL;
+
+ return g_steal_pointer (&name);
}
-static void
-update_local_source (GcalNewCalendarPage *self)
+static gboolean
+has_calendar_name (GcalNewCalendarPage *self)
{
- g_autofree gchar *calendar_name = NULL;
-
- g_clear_object (&self->local_source);
-
- calendar_name = g_strdup (gtk_entry_get_text (self->local_calendar_name_entry));
- calendar_name = g_strstrip (calendar_name);
-
- if (calendar_name && g_utf8_strlen (calendar_name, -1) > 0)
- {
- g_autofree gchar *color_string = NULL;
- ESourceExtension *ext;
- ESource *source;
- GdkRGBA color;
-
- gtk_color_chooser_get_rgba (self->local_calendar_color_button, &color);
- color_string = gdk_rgba_to_string (&color);
+ g_autofree gchar *name = get_calendar_name (self);
- /* Create the new source and add the needed extensions */
- source = e_source_new (NULL, NULL, NULL);
- e_source_set_parent (source, "local-stub");
- e_source_set_display_name (source, calendar_name);
-
- ext = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
- e_source_backend_set_backend_name (E_SOURCE_BACKEND (ext), "local");
- e_source_selectable_set_color (E_SOURCE_SELECTABLE (ext), color_string);
+ return name != NULL;
+}
- e_source_backend_set_backend_name (E_SOURCE_BACKEND (ext), "local");
+static void
+update_add_button (GcalNewCalendarPage *self)
+{
+ gboolean has_remote_calendar;
+ gboolean has_local_calendar;
- self->local_source = source;
- }
+ has_remote_calendar = self->calendar_address_entry_state == ENTRY_STATE_VALID;
+ has_local_calendar = self->calendar_address_entry_state == ENTRY_STATE_EMPTY && has_calendar_name (self);
- update_add_button (self);
+ gtk_widget_set_sensitive (self->add_button, has_local_calendar || has_remote_calendar);
}
static void
@@ -336,6 +321,7 @@ sources_discovered_cb (GObject *source_object,
g_debug ("Found %u sources", sources->len);
+ g_clear_pointer (&self->remote_sources, g_ptr_array_unref);
self->remote_sources = g_steal_pointer (&sources);
update_url_entry_state (self, ENTRY_STATE_VALID);
@@ -372,23 +358,56 @@ on_add_button_clicked_cb (GtkWidget *button,
GcalNewCalendarPage *self)
{
GcalManager *manager;
+ g_autofree gchar *calendar_name = NULL;
+ g_autofree gchar *color_string = NULL;
+ ESourceExtension *ext;
+ ESource *source;
+ GdkRGBA color;
manager = gcal_context_get_manager (self->context);
- /* Commit the new source */
- if (self->local_source)
- gcal_manager_save_source (manager, self->local_source);
+ calendar_name = get_calendar_name (self);
+
+ gtk_color_chooser_get_rgba (self->calendar_color_button, &color);
+ color_string = gdk_rgba_to_string (&color);
/* Commit each new remote source */
if (self->remote_sources)
{
guint i;
+ /* Apply the selected name and color to the first calendar source.
+ *
+ * FIXME: This might not be a reasonable thing to do when there are multiple sources.
+ */
+ source = g_ptr_array_index (self->remote_sources, 0);
+ if (calendar_name)
+ e_source_set_display_name (source, calendar_name);
+ ext = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
+ e_source_selectable_set_color (E_SOURCE_SELECTABLE (ext), color_string);
+
for (i = 0; i < self->remote_sources->len; i++)
gcal_manager_save_source (manager, g_ptr_array_index (self->remote_sources, i));
g_clear_pointer (&self->remote_sources, g_ptr_array_unref);
}
+ else
+ {
+ g_assert (calendar_name);
+
+ /* Create the new source and add the needed extensions */
+ source = e_source_new (NULL, NULL, NULL);
+ e_source_set_parent (source, "local-stub");
+ e_source_set_display_name (source, calendar_name);
+
+ ext = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
+ e_source_backend_set_backend_name (E_SOURCE_BACKEND (ext), "local");
+ e_source_selectable_set_color (E_SOURCE_SELECTABLE (ext), color_string);
+
+ e_source_backend_set_backend_name (E_SOURCE_BACKEND (ext), "local");
+
+ gcal_manager_save_source (manager, source);
+ }
gcal_calendar_management_page_switch_page (GCAL_CALENDAR_MANAGEMENT_PAGE (self),
"calendars",
@@ -470,14 +489,6 @@ on_cancel_button_clicked_cb (GtkWidget *button,
gcal_calendar_management_page_switch_page (page, "calendars", NULL);
}
-static void
-on_local_calendar_name_entry_text_changed_cb (GtkEntry *entry,
- GParamSpec *pspec,
- GcalNewCalendarPage *self)
-{
- update_local_source (self);
-}
-
static void
on_web_description_label_link_activated_cb (GtkLabel *label,
gchar *uri,
@@ -538,11 +549,10 @@ gcal_new_calendar_page_deactivate (GcalCalendarManagementPage *page)
gtk_container_remove (GTK_CONTAINER (headerbar), self->add_button);
gtk_header_bar_set_show_close_button (headerbar, TRUE);
- g_clear_object (&self->local_source);
g_clear_pointer (&self->remote_sources, g_ptr_array_unref);
update_add_button (self);
- gtk_entry_set_text (self->local_calendar_name_entry, "");
+ gtk_entry_set_text (self->calendar_name_entry, "");
gtk_entry_set_text (self->calendar_address_entry, "");
toggle_url_entry_pulsing (self, FALSE);
@@ -641,8 +651,8 @@ gcal_new_calendar_page_class_init (GcalNewCalendarPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_password_entry);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_popover);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_user_entry);
- gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, local_calendar_color_button);
- gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, local_calendar_name_entry);
+ gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_color_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_name_entry);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, web_sources_listbox);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, web_sources_revealer);
@@ -652,7 +662,6 @@ gcal_new_calendar_page_class_init (GcalNewCalendarPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_credential_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, on_credential_entry_activate_cb);
gtk_widget_class_bind_template_callback (widget_class, on_file_chooser_button_file_set_cb);
- gtk_widget_class_bind_template_callback (widget_class, on_local_calendar_name_entry_text_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_url_entry_text_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_web_description_label_link_activated_cb);
}
diff --git a/src/gui/calendar-management/gcal-new-calendar-page.ui
b/src/gui/calendar-management/gcal-new-calendar-page.ui
index fae3a5d5..e8366b5a 100644
--- a/src/gui/calendar-management/gcal-new-calendar-page.ui
+++ b/src/gui/calendar-management/gcal-new-calendar-page.ui
@@ -36,10 +36,9 @@
</child>
<child>
- <object class="GtkEntry" id="local_calendar_name_entry">
+ <object class="GtkEntry" id="calendar_name_entry">
<property name="visible">True</property>
<property name="placeholder-text" translatable="yes">Calendar Name</property>
- <signal name="notify::text" handler="on_local_calendar_name_entry_text_changed_cb"
object="GcalNewCalendarPage" swapped="no" />
</object>
</child>
@@ -68,7 +67,7 @@
</child>
<child>
- <object class="GtkColorButton" id="local_calendar_color_button">
+ <object class="GtkColorButton" id="calendar_color_button">
<property name="visible">True</property>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]