edit-calendar: Port to libadwaita

Co-authored-by: Jamie Murphy <hello@itsjamie.dev>
This commit is contained in:
Hari Rana
2023-06-17 22:13:41 +00:00
committed by Georges Basile Stavracas Neto
co-authored by Jamie Murphy
parent 9a9cfb5468
commit 7b1752bc19
4 changed files with 121 additions and 186 deletions
@@ -30,16 +30,13 @@ struct _GcalEditCalendarPage
{
GtkBox parent;
GtkWidget *account_box;
GtkLabel *account_label;
GtkWidget *account_dim_label;
AdwActionRow *account_row;
GtkWidget *back_button;
GtkColorDialogButton *calendar_color_button;
GtkCheckButton *calendar_visible_check;
GtkWidget *calendar_url_button;
GtkCheckButton *default_check;
GtkWidget *location_dim_label;
GtkEntry *name_entry;
AdwSwitchRow *calendar_visible_row;
AdwActionRow *calendar_url_row;
AdwSwitchRow *default_row;
AdwEntryRow *name_entry;
GtkWidget *remove_button;
GcalCalendar *calendar;
@@ -145,12 +142,13 @@ setup_calendar (GcalEditCalendarPage *self,
get_source_parent_name_color (manager, source, &parent_name, NULL);
gtk_widget_set_visible (self->account_box, is_goa);
gtk_widget_set_visible (self->calendar_url_button, !is_goa && (is_file || is_remote));
gtk_widget_set_visible (GTK_WIDGET (self->account_row), is_goa);
gtk_widget_set_visible (GTK_WIDGET (self->calendar_url_row), !is_goa && (is_file || is_remote));
/* If it's a file, set the file path */
if (is_file)
{
g_autofree gchar *text = NULL;
g_autofree gchar *uri = NULL;
ESourceLocal *local;
GFile *file;
@@ -159,14 +157,15 @@ setup_calendar (GcalEditCalendarPage *self,
file = e_source_local_get_custom_file (local);
uri = g_file_get_uri (file);
gtk_link_button_set_uri (GTK_LINK_BUTTON (self->calendar_url_button), uri);
gtk_button_set_label (GTK_BUTTON (self->calendar_url_button), uri);
text = g_strdup_printf ("<a href=\"%s\">%s</a>", uri, uri);
adw_action_row_set_subtitle (self->calendar_url_row, text);
}
/* If it's remote, build the uri */
if (is_remote)
{
g_autoptr (GUri) guri = NULL;
g_autofree gchar *text = NULL;
g_autofree gchar *uri = NULL;
ESourceWebdav *webdav;
@@ -174,8 +173,8 @@ setup_calendar (GcalEditCalendarPage *self,
guri = e_source_webdav_dup_uri (webdav);
uri = g_uri_to_string_partial (guri, G_URI_HIDE_PASSWORD);
gtk_link_button_set_uri (GTK_LINK_BUTTON (self->calendar_url_button), uri);
gtk_button_set_label (GTK_BUTTON (self->calendar_url_button), uri);
text = g_strdup_printf ("<a href=\"%s\">%s</a>", uri, uri);
adw_action_row_set_subtitle (self->calendar_url_row, text);
}
if (is_goa)
@@ -183,15 +182,15 @@ setup_calendar (GcalEditCalendarPage *self,
g_autofree gchar *name = NULL;
get_source_parent_name_color (manager, source, &name, NULL);
gtk_label_set_label (self->account_label, name);
adw_action_row_set_subtitle (self->account_row, name);
}
gtk_color_dialog_button_set_rgba (self->calendar_color_button, gcal_calendar_get_color (calendar));
gtk_editable_set_text (GTK_EDITABLE (self->name_entry), gcal_calendar_get_name (calendar));
gtk_check_button_set_active (self->calendar_visible_check, gcal_calendar_get_visible (calendar));
adw_switch_row_set_active (self->calendar_visible_row, gcal_calendar_get_visible (calendar));
gtk_check_button_set_active (self->default_check, source == default_source);
gtk_widget_set_visible (GTK_WIDGET (self->default_check), !gcal_calendar_is_read_only (calendar));
adw_switch_row_set_active (self->default_row, source == default_source);
gtk_widget_set_visible (GTK_WIDGET (self->default_row), !gcal_calendar_is_read_only (calendar));
gtk_widget_set_visible (self->remove_button, e_source_get_removable (source));
}
@@ -211,7 +210,7 @@ update_calendar (GcalEditCalendarPage *self)
gcal_calendar_set_name (self->calendar, gtk_editable_get_text (GTK_EDITABLE (self->name_entry)));
gcal_calendar_set_color (self->calendar, color);
if (gtk_check_button_get_active (self->default_check))
if (adw_switch_row_get_active (self->default_row))
gcal_manager_set_default_calendar (manager, self->calendar);
GCAL_EXIT;
@@ -411,14 +410,12 @@ gcal_edit_calendar_page_class_init (GcalEditCalendarPageClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/gui/calendar-management/gcal-edit-calendar-page.ui");
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, account_box);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, account_label);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, account_row);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, back_button);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, calendar_color_button);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, calendar_url_button);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, calendar_visible_check);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, default_check);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, location_dim_label);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, calendar_url_row);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, calendar_visible_row);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, default_row);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, name_entry);
gtk_widget_class_bind_template_child (widget_class, GcalEditCalendarPage, remove_button);
@@ -1,181 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalEditCalendarPage" parent="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="margin-top">18</property>
<property name="margin-bottom">18</property>
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<property name="row_spacing">12</property>
<property name="column_spacing">12</property>
<!-- Online Accounts -->
<object class="AdwPreferencesPage">
<child>
<object class="GtkLabel" id="account_dim_label">
<property name="visible" bind-source="account_box" bind-property="visible" bind-flags="default" />
<property name="label" translatable="yes">Account</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<object class="AdwPreferencesGroup">
<child>
<object class="GtkBox" id="account_box">
<property name="spacing">12</property>
<layout>
<property name="row">0</property>
<property name="column">1</property>
</layout>
<!-- Online Accounts -->
<child>
<object class="GtkLabel" id="account_label">
<property name="hexpand">True</property>
<property name="xalign">0</property>
<object class="AdwActionRow" id="account_row">
<property name="title" translatable="yes">Account</property>
<property name="activatable-widget">settings_button</property>
<style>
<class name="property"/>
</style>
<child>
<object class="GtkButton" id="settings_button">
<property name="tooltip-text" translatable="yes">Open in Settings</property>
<property name="valign">center</property>
<signal name="clicked" handler="on_settings_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
<style>
<class name="flat"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-name">settings-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Location (URL, file path) -->
<child>
<object class="GtkButton" id="settings_button">
<property name="label" translatable="yes">Settings</property>
<signal name="clicked" handler="on_settings_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
<object class="AdwActionRow" id="calendar_url_row">
<property name="title" translatable="yes">Location</property>
<property name="visible" bind-source="calendar_url_row" bind-property="visible" bind-flags="default" />
<style>
<class name="property"/>
</style>
</object>
</child>
</object>
</child>
<!-- Location (URL, file path) -->
<child>
<object class="GtkLabel" id="location_dim_label">
<property name="visible" bind-source="calendar_url_button" bind-property="visible" bind-flags="default" />
<property name="label" translatable="yes">Location</property>
<property name="xalign">1</property>
<layout>
<property name="row">1</property>
<property name="column">0</property>
</layout>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<child>
<object class="GtkLinkButton" id="calendar_url_button">
<layout>
<property name="row">1</property>
<property name="column">1</property>
</layout>
<style>
<class name="flat" />
</style>
</object>
</child>
<!-- Calendar name -->
<child>
<object class="GtkLabel" id="calendar_dim_label">
<property name="label" translatable="yes">Calendar name</property>
<property name="xalign">1</property>
<layout>
<property name="row">2</property>
<property name="column">0</property>
</layout>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="name_entry">
<property name="hexpand">True</property>
<layout>
<property name="row">2</property>
<property name="column">1</property>
</layout>
</object>
</child>
<!-- Color -->
<child>
<object class="GtkLabel" id="color_dim_label">
<property name="label" translatable="yes">Color</property>
<property name="xalign">1</property>
<layout>
<property name="row">3</property>
<property name="column">0</property>
</layout>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<child>
<object class="GtkColorDialogButton" id="calendar_color_button">
<property name="halign">start</property>
<property name="dialog">
<object class="GtkColorDialog">
<property name="modal">True</property>
<property name="with-alpha">False</property>
<!-- Calendar name -->
<child>
<object class="AdwEntryRow" id="name_entry">
<property name="title" translatable="yes">Calendar Name</property>
</object>
</property>
<layout>
<property name="row">3</property>
<property name="column">1</property>
</layout>
</object>
</child>
</child>
<!-- Calendar visibility -->
<child>
<object class="GtkCheckButton" id="calendar_visible_check">
<property name="label" translatable="yes">Display calendar</property>
<layout>
<property name="row">4</property>
<property name="column">0</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<!-- Color -->
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Color</property>
<property name="activatable-widget">calendar_color_button</property>
<!-- Default calendar -->
<child>
<object class="GtkCheckButton" id="default_check">
<property name="label" translatable="yes">Add new events to this calendar by default</property>
<layout>
<property name="row">5</property>
<property name="column">0</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkColorDialogButton" id="calendar_color_button">
<property name="valign">center</property>
<property name="dialog">
<object class="GtkColorDialog">
<property name="modal">True</property>
<property name="with-alpha">False</property>
</object>
</property>
</object>
</child>
</object>
</child>
<!-- Calendar visibility -->
<child>
<object class="AdwSwitchRow" id="calendar_visible_row">
<property name="title" translatable="yes">_Display Calendar</property>
<property name="use-underline">true</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="default_row">
<property name="title" translatable="yes">Default _Calendar</property>
<property name="subtitle" translatable="yes">Add new events to this calendar by default.</property>
<property name="use-underline">true</property>
</object>
</child>
<!-- Remove button -->
<child>
<object class="GtkButton" id="remove_button">
<property name="label" translatable="yes">_Remove Calendar</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin-top">24</property>
<property name="use-underline">true</property>
<signal name="clicked" handler="on_remove_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
<style>
<class name="destructive-action" />
<class name="pill"/>
</style>
</object>
</child>
<!-- Remove button -->
<child>
<object class="GtkButton" id="remove_button">
<property name="label" translatable="yes">Remove Calendar</property>
<property name="halign">end</property>
<property name="valign">end</property>
<property name="margin_top">6</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<signal name="clicked" handler="on_remove_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
<layout>
<property name="row">6</property>
<property name="column">0</property>
<property name="column-span">2</property>
</layout>
<style>
<class name="destructive-action" />
</style>
</object>
</child>
@@ -186,6 +120,7 @@
<!-- Headerbar buttons -->
<object class="GtkButton" id="back_button">
<property name="icon-name">go-previous-symbolic</property>
<property name="tooltip-text" translatable="yes">Back</property>
<signal name="clicked" handler="on_back_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
</object>
</interface>
+1
View File
@@ -4,5 +4,6 @@
<file compressed="true">calendar-month-symbolic.svg</file>
<file compressed="true">calendar-week-symbolic.svg</file>
<file compressed="true">calendar-today-symbolic.svg</file>
<file compressed="true">settings-symbolic.svg</file>
</gresource>
</gresources>
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 0 16 16" width="16px"><path d="m 7.5 1.019531 c -0.550781 0 -0.996094 0.445313 -0.996094 0.996094 v 0.453125 c -0.472656 0.128906 -0.929687 0.320312 -1.355468 0.566406 l -0.324219 -0.324218 c -0.390625 -0.390626 -1.019531 -0.390626 -1.410157 0 l -0.703124 0.707031 c -0.390626 0.390625 -0.390626 1.019531 0 1.410156 l 0.320312 0.320313 c -0.246094 0.425781 -0.433594 0.882812 -0.5625 1.355468 h -0.453125 c -0.550781 0 -0.996094 0.445313 -0.996094 0.996094 v 1 c 0 0.550781 0.445313 0.996094 0.996094 0.996094 h 0.449219 c 0.132812 0.472656 0.320312 0.929687 0.566406 1.355468 l -0.320312 0.320313 c -0.390626 0.390625 -0.390626 1.019531 0 1.410156 l 0.703124 0.707031 c 0.390626 0.390626 1.019532 0.390626 1.410157 0 l 0.320312 -0.320312 c 0.429688 0.242188 0.882813 0.433594 1.359375 0.558594 v 0.457031 c 0 0.550781 0.445313 0.996094 0.996094 0.996094 h 0.996094 c 0.554687 0 1 -0.445313 1 -0.996094 v -0.453125 c 0.472656 -0.128906 0.929687 -0.320312 1.355468 -0.566406 l 0.320313 0.324218 c 0.390625 0.390626 1.019531 0.390626 1.410156 0 l 0.707031 -0.707031 c 0.390626 -0.390625 0.390626 -1.019531 0 -1.410156 l -0.320312 -0.320313 c 0.242188 -0.425781 0.433594 -0.882812 0.558594 -1.355468 h 0.453125 c 0.554687 0 1 -0.445313 1 -0.996094 v -1 c 0 -0.550781 -0.445313 -0.996094 -1 -0.996094 h -0.449219 c -0.128906 -0.472656 -0.320312 -0.929687 -0.566406 -1.355468 l 0.324218 -0.320313 c 0.390626 -0.390625 0.390626 -1.019531 0 -1.410156 l -0.707031 -0.707031 c -0.390625 -0.390626 -1.019531 -0.390626 -1.410156 0 l -0.320313 0.320312 c -0.425781 -0.242188 -0.882812 -0.429688 -1.355468 -0.558594 v -0.457031 c 0 -0.550781 -0.445313 -0.996094 -1 -0.996094 z m 0.515625 3.976563 c 1.660156 0 3 1.34375 3 3 s -1.339844 3 -3 3 c -1.65625 0 -3 -1.34375 -3 -3 s 1.34375 -3 3 -3 z m 0 0"/></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB