calendar-management/new: Switch to a GtkDialog

The implementation of the credentials popover has relied on a hack,
and sadly this hack doesn't work anymore.

It's too late for a redesign, so for now, just put it into a dialog
and show it on top of the calendar management dialog.
This commit is contained in:
Georges Basile Stavracas Neto
2023-03-03 19:50:30 -03:00
parent 4f9d7de032
commit 0e8332b07b
2 changed files with 45 additions and 33 deletions
@@ -52,8 +52,8 @@ struct _GcalNewCalendarPage
GtkWidget *cancel_button; GtkWidget *cancel_button;
GtkWidget *credentials_cancel_button; GtkWidget *credentials_cancel_button;
GtkWidget *credentials_connect_button; GtkWidget *credentials_connect_button;
GtkWindow *credentials_dialog;
GtkEntry *credentials_password_entry; GtkEntry *credentials_password_entry;
GtkWidget *credentials_popover;
GtkEntry *credentials_user_entry; GtkEntry *credentials_user_entry;
GtkColorChooser *local_calendar_color_button; GtkColorChooser *local_calendar_color_button;
GtkEntry *local_calendar_name_entry; GtkEntry *local_calendar_name_entry;
@@ -238,12 +238,12 @@ discover_sources (GcalNewCalendarPage *self)
} }
static void static void
popdown_credentials_popover (GcalNewCalendarPage *self) hide_credentials_dialog (GcalNewCalendarPage *self)
{ {
gtk_editable_set_text (GTK_EDITABLE (self->credentials_user_entry), ""); gtk_editable_set_text (GTK_EDITABLE (self->credentials_user_entry), "");
gtk_editable_set_text (GTK_EDITABLE (self->credentials_password_entry), ""); gtk_editable_set_text (GTK_EDITABLE (self->credentials_password_entry), "");
gtk_popover_popdown (GTK_POPOVER (self->credentials_popover)); gtk_window_close (self->credentials_dialog);
} }
/* /*
@@ -322,8 +322,13 @@ sources_discovered_cb (GObject *source_object,
GCAL_SOURCE_DISCOVERER_ERROR, GCAL_SOURCE_DISCOVERER_ERROR,
GCAL_SOURCE_DISCOVERER_ERROR_UNAUTHORIZED)) GCAL_SOURCE_DISCOVERER_ERROR_UNAUTHORIZED))
{ {
GtkRoot *root;
g_debug ("Unauthorized, asking for credentials..."); g_debug ("Unauthorized, asking for credentials...");
gtk_popover_popup (GTK_POPOVER (self->credentials_popover));
root = gtk_widget_get_root (GTK_WIDGET (self));
gtk_window_set_transient_for (self->credentials_dialog, GTK_WINDOW (root));
gtk_window_present (self->credentials_dialog);
} }
else else
{ {
@@ -410,7 +415,7 @@ on_credential_button_clicked_cb (GtkWidget *button,
else else
update_url_entry_state (self, ENTRY_STATE_INVALID); update_url_entry_state (self, ENTRY_STATE_INVALID);
popdown_credentials_popover (self); hide_credentials_dialog (self);
} }
static void static void
@@ -418,7 +423,7 @@ on_credential_entry_activate_cb (GtkEntry *entry,
GcalNewCalendarPage *self) GcalNewCalendarPage *self)
{ {
discover_sources (self); discover_sources (self);
popdown_credentials_popover (self); hide_credentials_dialog (self);
} }
static void static void
@@ -658,8 +663,8 @@ gcal_new_calendar_page_class_init (GcalNewCalendarPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, cancel_button); gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, cancel_button);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_cancel_button); gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_cancel_button);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_connect_button); gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_connect_button);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_dialog);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_password_entry); 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, 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_color_button);
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, local_calendar_name_entry); gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, local_calendar_name_entry);
@@ -691,6 +696,4 @@ gcal_new_calendar_page_init (GcalNewCalendarPage *self)
chooser = gcal_file_chooser_button_get_filechooser (self->calendar_file_chooser_button); chooser = gcal_file_chooser_button_get_filechooser (self->calendar_file_chooser_button);
gtk_file_chooser_add_filter (chooser, self->calendar_file_filter); gtk_file_chooser_add_filter (chooser, self->calendar_file_filter);
gtk_widget_set_parent (self->credentials_popover, GTK_WIDGET (self->calendar_address_entry));
} }
@@ -171,8 +171,39 @@
</template> </template>
<!-- Credentials popover --> <!-- Credentials popover -->
<object class="GtkPopover" id="credentials_popover"> <object class="GtkWindow" id="credentials_dialog">
<property name="position">top</property> <property name="title" translatable="yes">Credentials</property>
<property name="modal">True</property>
<property name="hide-on-close">True</property>
<property name="default-width">350</property>
<property name="default-height">150</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">False</property>
<child type="start">
<object class="GtkButton" id="credentials_cancel_button">
<property name="hexpand">True</property>
<property name="label" translatable="yes">Cancel</property>
<signal name="clicked" handler="on_credential_button_clicked_cb" object="GcalNewCalendarPage" swapped="no" />
</object>
</child>
<child type="end">
<object class="GtkButton" id="credentials_connect_button">
<property name="hexpand">True</property>
<property name="label" translatable="yes">Connect</property>
<signal name="clicked" handler="on_credential_button_clicked_cb" object="GcalNewCalendarPage" swapped="no" />
<style>
<class name="suggested-action" />
</style>
</object>
</child>
</object>
</child>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
@@ -239,28 +270,6 @@
</object> </object>
</child> </child>
<child>
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkButton" id="credentials_cancel_button">
<property name="hexpand">True</property>
<property name="label" translatable="yes">Cancel</property>
<signal name="clicked" handler="on_credential_button_clicked_cb" object="GcalNewCalendarPage" swapped="no" />
</object>
</child>
<child>
<object class="GtkButton" id="credentials_connect_button">
<property name="hexpand">True</property>
<property name="label" translatable="yes">Connect</property>
<signal name="clicked" handler="on_credential_button_clicked_cb" object="GcalNewCalendarPage" swapped="no" />
<style>
<class name="suggested-action" />
</style>
</object>
</child>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>