|
| 1 | +/* |
| 2 | + * Copyright © 2025 Alain M. (https://github.com/alainm23/planify) |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU General Public |
| 6 | + * License as published by the Free Software Foundation; either |
| 7 | + * version 3 of the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | + * General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public |
| 15 | + * License along with this program; if not, write to the |
| 16 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | + * Boston, MA 02110-1301 USA |
| 18 | + * |
| 19 | + * Authored by: nijakow (https://github.com/nijakow) |
| 20 | + */ |
| 21 | + |
| 22 | +public class Widgets.BypassResolveSwitchRow : Adw.ActionRow { |
| 23 | + private Gtk.Switch toggle; |
| 24 | + |
| 25 | + public bool active { |
| 26 | + get { return toggle.active; } |
| 27 | + set { toggle.active = value; } |
| 28 | + } |
| 29 | + |
| 30 | + public BypassResolveSwitchRow () { |
| 31 | + title = _("Bypass Location Resolve"); |
| 32 | + subtitle = _("Workaround for CalDAV connection issues with connections using non-default ports"); |
| 33 | + |
| 34 | + toggle = new Gtk.Switch () { |
| 35 | + valign = Gtk.Align.CENTER, |
| 36 | + halign = Gtk.Align.END |
| 37 | + }; |
| 38 | + |
| 39 | + add_suffix (toggle); |
| 40 | + activatable_widget = toggle; |
| 41 | + |
| 42 | + toggle.state_set.connect ((state) => { |
| 43 | + if (state) { |
| 44 | + var dialog = new Adw.AlertDialog ( |
| 45 | + _("Warning"), |
| 46 | + _("This will disable the CalDAV resolve process.\nProceed at your own risk") |
| 47 | + ); |
| 48 | + dialog.add_response ("cancel", _("Cancel")); |
| 49 | + dialog.add_response ("accept", _("Continue Anyway")); |
| 50 | + dialog.set_response_appearance ("accept", Adw.ResponseAppearance.DESTRUCTIVE); |
| 51 | + |
| 52 | + dialog.response.connect ((response) => { |
| 53 | + if (response == "accept") { |
| 54 | + toggle.state = true; |
| 55 | + toggle.active = true; |
| 56 | + } else { |
| 57 | + toggle.state = false; |
| 58 | + toggle.active = false; |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + dialog.present (Planify._instance.main_window); |
| 63 | + return true; // prevent immediate state change |
| 64 | + } |
| 65 | + return false; |
| 66 | + }); |
| 67 | + |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | + |
0 commit comments