From 17532f801907f1e09ea03b79aed20b26945beb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Mon, 24 May 2021 19:13:42 -0700 Subject: [PATCH 1/6] Add iCloud account --- data/gresource.xml | 6 + data/icons/icloud.svg | 325 ++++++++++++++++++++++++++++++++++++++++++ meson.build | 6 + src/MainView.vala | 10 +- src/Plug.vala | 2 + src/meson.build | 1 + 6 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 data/gresource.xml create mode 100644 data/icons/icloud.svg diff --git a/data/gresource.xml b/data/gresource.xml new file mode 100644 index 00000000..e5838572 --- /dev/null +++ b/data/gresource.xml @@ -0,0 +1,6 @@ + + + + icons/icloud.svg + + diff --git a/data/icons/icloud.svg b/data/icons/icloud.svg new file mode 100644 index 00000000..da43ef58 --- /dev/null +++ b/data/icons/icloud.svg @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/meson.build b/meson.build index ff1a770b..ec49b8fe 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,12 @@ gtk_dep = dependency('gtk+-3.0') handy_dep = dependency('libhandy-1', version: '>=1.0.0') switchboard_dep = dependency('switchboard-2.0') +gresource = gnome.compile_resources( + 'gresource', + 'data' / 'gresource.xml', + source_dir: 'data' +) + subdir('data') subdir('src') subdir('po') diff --git a/src/MainView.vala b/src/MainView.vala index 3d57b314..c2bdb2fc 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -42,11 +42,19 @@ public class OnlineAccounts.MainView : Gtk.Grid { _("Calendars and Tasks") ); + var icloud_menuitem = new AccountMenuItem ( + "onlineaccounts-icloud", + _("iCloud"), + _("Calendars and Mail") + ); + var add_acount_grid = new Gtk.Grid () { margin_top = 3, - margin_bottom = 3 + margin_bottom = 3, + orientation = Gtk.Orientation.VERTICAL }; add_acount_grid.add (caldav_menuitem); + add_acount_grid.add (icloud_menuitem); add_acount_grid.show_all (); var add_account_popover = new Gtk.Popover (null); diff --git a/src/Plug.vala b/src/Plug.vala index 816cf700..4288f48b 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -33,6 +33,8 @@ public class OnlineAccounts.Plug : Switchboard.Plug { public override Gtk.Widget get_widget () { if (main_view == null) { + Gtk.IconTheme.get_default ().add_resource_path ("/io/elementary/switchboard/onlineaccounts"); + main_view = new MainView (); } diff --git a/src/meson.build b/src/meson.build index a943dd91..dd1161fa 100644 --- a/src/meson.build +++ b/src/meson.build @@ -9,6 +9,7 @@ switchboard_plugsdir = switchboard_dep.get_pkgconfig_variable('plugsdir', define shared_module( meson.project_name(), + gresource, plug_files, dependencies: [ glib_dep, From 3420926f1f767614b10f774501d649771b0e2728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Mon, 24 May 2021 19:56:53 -0700 Subject: [PATCH 2/6] Prototype icloud login --- src/Dialogs/iCloudDialog.vala | 109 ++++++++++++++++++++++++++++++++++ src/MainView.vala | 7 +++ src/meson.build | 1 + 3 files changed, 117 insertions(+) create mode 100644 src/Dialogs/iCloudDialog.vala diff --git a/src/Dialogs/iCloudDialog.vala b/src/Dialogs/iCloudDialog.vala new file mode 100644 index 00000000..729605b5 --- /dev/null +++ b/src/Dialogs/iCloudDialog.vala @@ -0,0 +1,109 @@ +/* +* Copyright 2020-2021 elementary, Inc. (https://elementary.io) +* +* 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, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*/ + +public class OnlineAccounts.iCloudDialog : Hdy.Window { + private Granite.ValidatedEntry password_entry; + private Granite.ValidatedEntry username_entry; + private Gtk.Button login_button; + + construct { + var username_label = new Granite.HeaderLabel (_("Apple ID")); + + username_entry = new Granite.ValidatedEntry () { + hexpand = true + }; + + var password_label = new Granite.HeaderLabel (_("App-Specific Password")); + + Regex? app_password_regex = null; + try { + app_password_regex = new Regex ("^[a-zA-Z]{4}-{1}[a-zA-Z]{4}-{1}[a-zA-Z]{4}-{1}[a-zA-Z]{4}$"); + } catch (Error e) { + critical (e.message); + } + + password_entry = new Granite.ValidatedEntry.from_regex (app_password_regex) { + input_purpose = Gtk.InputPurpose.PASSWORD + }; + + var app_password_help = new Gtk.LinkButton.with_label ( + "https://support.apple.com/en-us/HT204397", + _("Create an app-specific password") + ); + app_password_help.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL); + + var cancel_button = new Gtk.Button.with_label (_("Cancel")); + + login_button = new Gtk.Button.with_label (_("Log In")) { + can_default = true, + sensitive = false + }; + login_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + + var action_area = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL) { + layout_style = Gtk.ButtonBoxStyle.END, + margin_top = 24, + spacing = 6, + valign = Gtk.Align.END, + vexpand = true + }; + action_area.add (cancel_button); + action_area.add (login_button); + + var grid = new Gtk.Grid () { + orientation = Gtk.Orientation.VERTICAL, + row_spacing = 6, + margin = 12 + }; + grid.add (username_label); + grid.add (username_entry); + grid.add (password_label); + grid.add (password_entry); + grid.add (app_password_help); + grid.add (action_area); + + var window_handle = new Hdy.WindowHandle (); + window_handle.add (grid); + + default_height = 400; + default_width = 300; + modal = true; + type_hint = Gdk.WindowTypeHint.DIALOG; + window_position = Gtk.WindowPosition.CENTER_ON_PARENT; + add (window_handle); + + login_button.has_default = true; + + cancel_button.clicked.connect (() => { + destroy (); + }); + + username_entry.changed.connect (() => { + username_entry.is_valid = username_entry.text.length >= 1; + update_login_sensitivity (); + }); + + password_entry.changed.connect (update_login_sensitivity); + } + + private void update_login_sensitivity () { + login_button.sensitive = username_entry.is_valid && password_entry.is_valid; + } +} diff --git a/src/MainView.vala b/src/MainView.vala index c2bdb2fc..4ca04a48 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -90,6 +90,13 @@ public class OnlineAccounts.MainView : Gtk.Grid { }; caldav_dialog.show_all (); }); + + icloud_menuitem.clicked.connect (() => { + var icloud_dialog = new iCloudDialog () { + transient_for = (Gtk.Window) get_toplevel () + }; + icloud_dialog.show_all (); + }); } private class AccountMenuItem : Gtk.Button { diff --git a/src/meson.build b/src/meson.build index dd1161fa..44c05af7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,5 +1,6 @@ plug_files = files( 'Dialogs/CaldavDialog.vala', + 'Dialogs/iCloudDialog.vala', 'MainView.vala', 'Plug.vala', 'Widgets/ValidationMessage.vala' From 6a2f7b8274c711f98346511151b79a12b39572d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Mon, 24 May 2021 19:58:31 -0700 Subject: [PATCH 3/6] satisfy linter --- src/Dialogs/{iCloudDialog.vala => ICloudDialog.vala} | 2 +- src/MainView.vala | 2 +- src/meson.build | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/Dialogs/{iCloudDialog.vala => ICloudDialog.vala} (98%) diff --git a/src/Dialogs/iCloudDialog.vala b/src/Dialogs/ICloudDialog.vala similarity index 98% rename from src/Dialogs/iCloudDialog.vala rename to src/Dialogs/ICloudDialog.vala index 729605b5..904277dc 100644 --- a/src/Dialogs/iCloudDialog.vala +++ b/src/Dialogs/ICloudDialog.vala @@ -18,7 +18,7 @@ * */ -public class OnlineAccounts.iCloudDialog : Hdy.Window { +public class OnlineAccounts.ICloudDialog : Hdy.Window { private Granite.ValidatedEntry password_entry; private Granite.ValidatedEntry username_entry; private Gtk.Button login_button; diff --git a/src/MainView.vala b/src/MainView.vala index 4ca04a48..1d859d14 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -92,7 +92,7 @@ public class OnlineAccounts.MainView : Gtk.Grid { }); icloud_menuitem.clicked.connect (() => { - var icloud_dialog = new iCloudDialog () { + var icloud_dialog = new ICloudDialog () { transient_for = (Gtk.Window) get_toplevel () }; icloud_dialog.show_all (); diff --git a/src/meson.build b/src/meson.build index 44c05af7..b6ca9329 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,6 @@ plug_files = files( 'Dialogs/CaldavDialog.vala', - 'Dialogs/iCloudDialog.vala', + 'Dialogs/ICloudDialog.vala', 'MainView.vala', 'Plug.vala', 'Widgets/ValidationMessage.vala' From 623a65de47dde7bbf605825e95dacfa09e6b61dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Mon, 24 May 2021 20:01:20 -0700 Subject: [PATCH 4/6] set password entry max length --- src/Dialogs/ICloudDialog.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dialogs/ICloudDialog.vala b/src/Dialogs/ICloudDialog.vala index 904277dc..f1a11597 100644 --- a/src/Dialogs/ICloudDialog.vala +++ b/src/Dialogs/ICloudDialog.vala @@ -40,7 +40,8 @@ public class OnlineAccounts.ICloudDialog : Hdy.Window { } password_entry = new Granite.ValidatedEntry.from_regex (app_password_regex) { - input_purpose = Gtk.InputPurpose.PASSWORD + input_purpose = Gtk.InputPurpose.PASSWORD, + max_length = 19 }; var app_password_help = new Gtk.LinkButton.with_label ( From 424803358c887813de0e970e456cb8a645743f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Mon, 24 May 2021 20:01:54 -0700 Subject: [PATCH 5/6] comment --- src/Dialogs/ICloudDialog.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Dialogs/ICloudDialog.vala b/src/Dialogs/ICloudDialog.vala index f1a11597..5cc9f37e 100644 --- a/src/Dialogs/ICloudDialog.vala +++ b/src/Dialogs/ICloudDialog.vala @@ -32,6 +32,7 @@ public class OnlineAccounts.ICloudDialog : Hdy.Window { var password_label = new Granite.HeaderLabel (_("App-Specific Password")); + // Apple app-passwords are in the format xxxx-xxxx-xxxx-xxxx Regex? app_password_regex = null; try { app_password_regex = new Regex ("^[a-zA-Z]{4}-{1}[a-zA-Z]{4}-{1}[a-zA-Z]{4}-{1}[a-zA-Z]{4}$"); From b41a30c8bd49b960d1274ed1bde85081c39d2c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Tue, 19 Oct 2021 12:10:41 -0700 Subject: [PATCH 6/6] add 48px icon --- data/icons/48.svg | 293 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 data/icons/48.svg diff --git a/data/icons/48.svg b/data/icons/48.svg new file mode 100644 index 00000000..87c2d12b --- /dev/null +++ b/data/icons/48.svg @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + +