diff --git a/src/EventEdition/EventDialog.vala b/src/EventEdition/EventDialog.vala index 49b27a387..85e578d05 100644 --- a/src/EventEdition/EventDialog.vala +++ b/src/EventEdition/EventDialog.vala @@ -63,7 +63,7 @@ public class EventDialog : Granite.Dialog { event_type = EventType.EDIT; } - guests_panel = new EventEdition.GuestsPanel (this); + guests_panel = new EventEdition.GuestsPanel (ecal.get_icalcomponent ()); info_panel = new EventEdition.InfoPanel (this); location_panel = new EventEdition.LocationPanel (this); reminder_panel = new EventEdition.ReminderPanel (this); diff --git a/src/EventEdition/GuestGrid.vala b/src/EventEdition/GuestGrid.vala index 023116a1b..d5794fa24 100644 --- a/src/EventEdition/GuestGrid.vala +++ b/src/EventEdition/GuestGrid.vala @@ -47,7 +47,10 @@ public class Maya.View.EventEdition.GuestGrid : Gtk.Grid { avatar = new Hdy.Avatar (ICON_SIZE, name_label.label, true); column_spacing = 12; - margin = 6; + margin_top = 6; + margin_end = 6; + margin_bottom = 6; + margin_start = 6; attach (avatar, 0, 0, 1, 4); attach (name_label, 1, 1); attach (mail_label, 1, 2); diff --git a/src/EventEdition/GuestsPanel.vala b/src/EventEdition/GuestsPanel.vala index 24d167106..88fb1d960 100644 --- a/src/EventEdition/GuestsPanel.vala +++ b/src/EventEdition/GuestsPanel.vala @@ -1,25 +1,13 @@ -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- -/*- - * Copyright (c) 2011-2015 Maya Developers (http://launchpad.net/maya) - * - * 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 . +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2011-2026 elementary, Inc. (https://elementary.io) * * Authored by: Jaap Broekhuizen */ -public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { - private EventDialog parent_dialog; +public class Maya.View.EventEdition.GuestsPanel : Gtk.Box { + public ICal.Component component { get; construct; } + private Gtk.Entry guest_entry; private Gtk.EntryCompletion guest_completion; private Gtk.ListBox guest_list; @@ -38,36 +26,35 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { N_COLUMNS; } - public GuestsPanel (EventDialog parent_dialog) { - this.parent_dialog = parent_dialog; - attendees = new Gee.ArrayList (); - - margin_start = 12; - margin_end = 12; - row_spacing = 6; - orientation = Gtk.Orientation.VERTICAL; + public GuestsPanel (ICal.Component component) { + Object (component: component); + } + construct { + attendees = new Gee.ArrayList (); guest_store = new Gtk.ListStore (2, typeof (string), typeof (string)); - var guest_label = new Granite.HeaderLabel (_("Invitees")); - load_contacts.begin (); var no_guests_label = new Gtk.Label (_("No Invitees")); + no_guests_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + no_guests_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); no_guests_label.show (); - unowned Gtk.StyleContext no_guests_context = no_guests_label.get_style_context (); - no_guests_context.add_class (Granite.STYLE_CLASS_H3_LABEL); - no_guests_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL); - - guest_list = new Gtk.ListBox (); - guest_list.set_selection_mode (Gtk.SelectionMode.NONE); + guest_list = new Gtk.ListBox () { + hexpand = true, + vexpand = true, + selection_mode = NONE + }; guest_list.set_placeholder (no_guests_label); + var guest_label = new Granite.HeaderLabel (_("Invitees")) { + mnemonic_widget = guest_list + }; + var guest_scrolledwindow = new Gtk.ScrolledWindow (null, null) { child = guest_list }; - guest_scrolledwindow.expand = true; var frame = new Gtk.Frame (null) { child = guest_scrolledwindow @@ -93,34 +80,33 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { return false; }); - guest_entry = new Gtk.SearchEntry (); - guest_entry.placeholder_text = _("Invite"); - guest_entry.hexpand = true; + guest_entry = new Gtk.SearchEntry () { + hexpand = true, + placeholder_text = _("Invite") + }; guest_entry.set_completion (guest_completion); guest_entry.activate.connect (() => { - var attendee = new ICal.Property (ICal.PropertyKind.ATTENDEE_PROPERTY); + var attendee = new ICal.Property (ATTENDEE_PROPERTY); attendee.set_attendee (guest_entry.text); add_guest ((owned)attendee); guest_entry.delete_text (0, -1); }); + margin_start = 12; + margin_end = 12; + spacing = 6; + orientation = VERTICAL; add (guest_label); add (guest_entry); add (frame); - if (parent_dialog.ecal != null) { - unowned ICal.Component comp = parent_dialog.ecal.get_icalcomponent (); - // Load the guests - int count = comp.count_properties (ICal.PropertyKind.ATTENDEE_PROPERTY); - - ICal.Property property; - property = comp.get_first_property (ICal.PropertyKind.ATTENDEE_PROPERTY); - for (int i = 0; i < count; i++) { - if (property.get_attendee () != null) - add_guest (property); - - property = comp.get_next_property (ICal.PropertyKind.ATTENDEE_PROPERTY); + var property = component.get_first_property (ATTENDEE_PROPERTY); + for (int i = 0; i < component.count_properties (ATTENDEE_PROPERTY); i++) { + if (property.get_attendee () != null) { + add_guest (property); } + + property = component.get_next_property (ATTENDEE_PROPERTY); } show_all (); @@ -144,17 +130,13 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { * Save the values in the dialog into the component. */ public void save () { - unowned ICal.Component comp = parent_dialog.ecal.get_icalcomponent (); - // Save the guests // First, clear the guests - int count = comp.count_properties (ICal.PropertyKind.ATTENDEE_PROPERTY); - - for (int i = 0; i < count; i++) { + for (int i = 0; i < component.count_properties (ATTENDEE_PROPERTY); i++) { ICal.Property remove_prop; if (i == 0) { - remove_prop = comp.get_first_property (ICal.PropertyKind.ATTENDEE_PROPERTY); + remove_prop = component.get_first_property (ATTENDEE_PROPERTY); } else { - remove_prop = comp.get_next_property (ICal.PropertyKind.ATTENDEE_PROPERTY); + remove_prop = component.get_next_property (ATTENDEE_PROPERTY); } ICal.Property found_prop = remove_prop; @@ -167,7 +149,7 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { } if (can_remove == true) { - comp.remove_property (remove_prop); + component.remove_property (remove_prop); } else if (found_prop != remove_prop) { attendees.remove (found_prop); } @@ -175,26 +157,29 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid { // Add the new guests foreach (unowned ICal.Property attendee in attendees) { - comp.add_property (attendee.clone ()); + component.add_property (attendee.clone ()); } } private void add_guest (ICal.Property attendee) { - var row = new Gtk.ListBoxRow (); var guest_element = new GuestGrid (attendee); - row.add (guest_element); + + var row = new Gtk.ListBoxRow () { + child = guest_element + }; + row.show_all (); + guest_list.add (row); attendees.add (guest_element.attendee); + guest_element.removed.connect (() => { attendees.remove (guest_element.attendee); }); - - row.show_all (); } private bool suggestion_selected (Gtk.TreeModel model, Gtk.TreeIter iter) { - var attendee = new ICal.Property (ICal.PropertyKind.ATTENDEE_PROPERTY); + var attendee = new ICal.Property (ATTENDEE_PROPERTY); Value selected_value; model.get_value (iter, 1, out selected_value);