calendar-management: Introduce GcalEditCalendarPage

This is the second of the three original pages we used to have.
This one edits calendars.
parent db4613ae
......@@ -8,6 +8,7 @@
<file alias="calendars-page.ui" compressed="true">ui/calendars-page.ui</file>
<file alias="date-chooser.ui" compressed="true">ui/date-chooser.ui</file>
<file alias="date-selector.ui" compressed="true">ui/date-selector.ui</file>
<file alias="edit-calendar-page.ui" compressed="true">ui/edit-calendar-page.ui</file>
<file alias="edit-dialog.ui" compressed="true">ui/edit-dialog.ui</file>
<file alias="event-widget.ui" compressed="true">ui/event-widget.ui</file>
<file alias="month-cell.ui" compressed="true">ui/month-cell.ui</file>
......
......@@ -89,6 +89,7 @@ resource_data = files(
'ui/date-chooser.ui',
'ui/date-selector.ui',
'ui/edit-dialog.ui',
'ui/edit-calendar-page.ui',
'ui/help-overlay.ui',
'ui/menus.ui',
'ui/month-cell.ui',
......
......@@ -28,204 +28,6 @@
<property name="vhomogeneous">False</property>
<property name="transition_type">crossfade</property>
<signal name="notify::visible-child-name" handler="stack_visible_child_name_changed" object="GcalCalendarManagementDialog" swapped="no"/>
<child>
<object class="GtkGrid" id="edit_grid">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="row_spacing">12</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkCheckButton" id="default_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>
<signal name="notify::active" handler="default_check_toggled" object="GcalCalendarManagementDialog" swapped="no"/>
<child>
<object class="GtkLabel" id="default_check_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Add new events to this calendar by default</property>
<property name="xalign">0</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="remove_button">
<property name="label" translatable="yes">Remove Calendar</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</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="remove_button_clicked" object="GcalCalendarManagementDialog" swapped="no"/>
<style>
<class name="destructive-action"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="calendar_visible_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>
<signal name="notify::active" handler="calendar_visible_check_toggled" object="GcalCalendarManagementDialog" swapped="no"/>
<child>
<object class="GtkLabel" id="display_calendar_check_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Display calendar</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="calendar_color_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<signal name="color-set" handler="color_set" object="GcalCalendarManagementDialog" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<signal name="notify::text" handler="name_entry_text_changed" object="GcalCalendarManagementDialog" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="calendar_dim_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Calendar name</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="color_dim_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Color</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="account_dim_label">
<property name="visible" bind-source="account_box" bind-property="visible" bind-flags="default|sync-create"/>
<property name="label" translatable="yes">Account</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="location_dim_label">
<property name="visible" bind-source="calendar_url_button" bind-property="visible" bind-flags="default|sync-create"/>
<property name="label" translatable="yes">Location</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="account_box">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="account_label">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkButton" id="settings_button">
<property name="label" translatable="yes">Settings</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="settings_button_clicked" object="GcalCalendarManagementDialog" swapped="no"/>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLinkButton" id="calendar_url_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">edit</property>
<property name="title" translatable="yes">Edit Calendar</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="web_source_grid">
<property name="visible">True</property>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalEditCalendarPage" parent="GtkBox">
<property name="visible">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="row_spacing">12</property>
<property name="column_spacing">12</property>
<!-- Online Accounts -->
<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>
<style>
<class name="dim-label" />
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="account_box">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="account_label">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkButton" id="settings_button">
<property name="label" translatable="yes">Settings</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_settings_button_clicked_cb" object="GcalEditCalendarPage" swapped="no" />
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="top_attach">0</property>
<property name="left_attach">1</property>
</packing>
</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>
<style>
<class name="dim-label" />
</style>
</object>
<packing>
<property name="top_attach">1</property>
<property name="left_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLinkButton" id="calendar_url_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="left_attach">1</property>
</packing>
</child>
<!-- Calendar name -->
<child>
<object class="GtkLabel" id="calendar_dim_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Calendar name</property>
<property name="xalign">1</property>
<style>
<class name="dim-label" />
</style>
</object>
<packing>
<property name="top_attach">2</property>
<property name="left_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="left_attach">1</property>
</packing>
</child>
<!-- Color -->
<child>
<object class="GtkLabel" id="color_dim_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Color</property>
<property name="xalign">1</property>
<style>
<class name="dim-label" />
</style>
</object>
<packing>
<property name="top_attach">3</property>
<property name="left_attach">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="calendar_color_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="left_attach">1</property>
</packing>
</child>
<!-- Calendar visibility -->
<child>
<object class="GtkCheckButton" id="calendar_visible_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>
<child>
<object class="GtkLabel" id="display_calendar_check_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Display calendar</property>
</object>
</child>
</object>
<packing>
<property name="top_attach">4</property>
<property name="left_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<!-- Default calendar -->
<child>
<object class="GtkCheckButton" id="default_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>
<child>
<object class="GtkLabel" id="default_check_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Add new events to this calendar by default</property>
<property name="xalign">0</property>
</object>
</child>
</object>
<packing>
<property name="top_attach">5</property>
<property name="left_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<!-- Remove button -->
<child>
<object class="GtkButton" id="remove_button">
<property name="label" translatable="yes">Remove Calendar</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</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" />
<style>
<class name="destructive-action" />
</style>
</object>
<packing>
<property name="top_attach">6</property>
<property name="left_attach">0</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
/* gcal-edit-calendar-page.c
*
* Copyright 2019 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 "GcalEditCalendarPage"
#include "gcal-context.h"
#include "gcal-calendar-management-page.h"
#include "gcal-debug.h"
#include "gcal-edit-calendar-page.h"
#include "gcal-utils.h"
struct _GcalEditCalendarPage
{
GtkBox parent;
GtkWidget *account_box;
GtkLabel *account_label;
GtkWidget *account_dim_label;
GtkColorChooser *calendar_color_button;
GtkToggleButton *calendar_visible_check;
GtkWidget *calendar_url_button;
GtkToggleButton *default_check;
GtkWidget *location_dim_label;
GtkEntry *name_entry;
GtkWidget *remove_button;
GcalCalendar *calendar;
GcalContext *context;
};
static void gcal_calendar_management_page_iface_init (GcalCalendarManagementPageInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GcalEditCalendarPage, gcal_edit_calendar_page, GTK_TYPE_BOX,
G_IMPLEMENT_INTERFACE (GCAL_TYPE_CALENDAR_MANAGEMENT_PAGE,
gcal_calendar_management_page_iface_init))
enum
{
PROP_0,
PROP_CONTEXT,
N_PROPS
};
/*
* Auxiliary methods
*/
static gboolean
is_goa_calendar (GcalEditCalendarPage *self,
GcalCalendar *calendar)
{
g_autoptr (ESource) parent = NULL;
GcalManager *manager;
ESource *source;
g_assert (calendar && GCAL_IS_CALENDAR (calendar));
manager = gcal_context_get_manager (self->context);
source = gcal_calendar_get_source (calendar);
parent = gcal_manager_get_source (manager, e_source_get_parent (source));
return e_source_has_extension (parent, E_SOURCE_EXTENSION_GOA);
}
static gboolean
is_remote_source (ESource *source)
{
gboolean has_webdav, has_auth;
g_assert (E_IS_SOURCE (source));
has_webdav = e_source_has_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
has_auth = e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
if (!has_webdav || !has_auth)
return FALSE;
if (has_auth)
{
ESourceAuthentication *auth;
auth = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
/* No host is set, it's not a remote source */
if (!e_source_authentication_get_host (auth))
return FALSE;
}
if (has_webdav)
{
ESourceWebdav *webdav;
webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
/* No resource path specified, not a remote source */
if (!e_source_webdav_get_resource_path (webdav))
return FALSE;
}
return TRUE;
}
static void
setup_calendar (GcalEditCalendarPage *self,
GcalCalendar *calendar)
{
g_autofree gchar *parent_name = NULL;
GcalCalendar *default_calendar;
GcalManager *manager;
ESource *default_source;
ESource *source;
gboolean is_remote;
gboolean is_file;
gboolean is_goa;
self->calendar = g_object_ref (calendar);
manager = gcal_context_get_manager (self->context);
default_calendar = gcal_manager_get_default_calendar (manager);
default_source = gcal_calendar_get_source (default_calendar);
is_goa = is_goa_calendar (self, calendar);
source = gcal_calendar_get_source (calendar);
is_file = e_source_has_extension (source, E_SOURCE_EXTENSION_LOCAL_BACKEND);
is_remote = is_remote_source (source);
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));
/* If it's a file, set the file path */
if (is_file)
{
g_autofree gchar *uri = NULL;
ESourceLocal *local;
GFile *file;
local = e_source_get_extension (source, E_SOURCE_EXTENSION_LOCAL_BACKEND);
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);
}
/* If it's remote, build the uri */
if (is_remote)
{
ESourceAuthentication *auth;
g_autoptr (SoupURI) soup = NULL;
g_autofree gchar *uri = NULL;
ESourceWebdav *webdav;
auth = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
soup = e_source_webdav_dup_soup_uri (webdav);
uri = g_strdup_printf ("%s://%s:%d%s",
soup_uri_get_scheme (soup),
e_source_authentication_get_host (auth),
e_source_authentication_get_port (auth),
e_source_webdav_get_resource_path (webdav));
gtk_link_button_set_uri (GTK_LINK_BUTTON (self->calendar_url_button), uri);
gtk_button_set_label (GTK_BUTTON (self->calendar_url_button), uri);
}
if (is_goa)
{
g_autofree gchar *name = NULL;
get_source_parent_name_color (manager, source, &name, NULL);
gtk_label_set_label (self->account_label, name);
}
gtk_color_chooser_set_rgba (self->calendar_color_button, gcal_calendar_get_color (calendar));
gtk_entry_set_text (self->name_entry, gcal_calendar_get_name (calendar));
gtk_toggle_button_set_active (self->calendar_visible_check, gcal_calendar_get_visible (calendar));
gtk_toggle_button_set_active (self->default_check, source == default_source);
gtk_widget_set_visible (GTK_WIDGET (self->default_check), !gcal_calendar_is_read_only (calendar));
gtk_widget_set_visible (self->remove_button, e_source_get_removable (source));
}
static void
update_calendar (GcalEditCalendarPage *self)
{
GcalManager *manager;
GdkRGBA color;
GCAL_ENTRY;
g_assert (self->calendar != NULL);
manager = gcal_context_get_manager (self->context);
gtk_color_chooser_get_rgba (self->calendar_color_button, &color);
gcal_calendar_set_name (self->calendar, gtk_entry_get_text (self->name_entry));
gcal_calendar_set_color (self->calendar, &color);
if (gtk_toggle_button_get_active (self->default_check))
gcal_manager_set_default_calendar (manager, self->calendar);
GCAL_EXIT;
}
/*
* Callbacks
*/
static void
on_remove_button_clicked_cb (GtkButton *button,
GcalEditCalendarPage *self)
{
GcalCalendarManagementPage *page;
GCAL_ENTRY;
page = GCAL_CALENDAR_MANAGEMENT_PAGE (self);
gcal_calendar_management_page_switch_page (page, "calendars", self->calendar);
GCAL_EXIT;
}
static void
on_settings_button_clicked_cb (GtkWidget *button,
GcalEditCalendarPage *self)
{
g_autoptr (ESource) parent = NULL;
GApplication *app;
GcalManager *manager;
ESourceGoa *goa;
ESource *source;
GCAL_ENTRY;
manager = gcal_context_get_manager (self->context);
source = gcal_calendar_get_source (self->calendar);
parent = gcal_manager_get_source (manager, e_source_get_parent (source));
g_assert (e_source_has_extension (parent, E_SOURCE_EXTENSION_GOA));
goa = e_source_get_extension (parent, E_SOURCE_EXTENSION_GOA);
app = g_application_get_default ();
gcal_utils_launch_online_accounts_panel (g_application_get_dbus_connection (app),
e_source_goa_get_account_id (goa),
NULL);
GCAL_EXIT;
}
/*
* GcalCalendarManagementPage iface
*/
static const gchar*
gcal_edit_calendar_page_get_name (GcalCalendarManagementPage *page)
</