Skip to content

Commit 9df346c

Browse files
authored
GuestsPanel: GObject style, cleanup (#926)
1 parent 7a49b92 commit 9df346c

3 files changed

Lines changed: 55 additions & 67 deletions

File tree

src/EventEdition/EventDialog.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class EventDialog : Granite.Dialog {
6363
event_type = EventType.EDIT;
6464
}
6565

66-
guests_panel = new EventEdition.GuestsPanel (this);
66+
guests_panel = new EventEdition.GuestsPanel (ecal.get_icalcomponent ());
6767
info_panel = new EventEdition.InfoPanel (this);
6868
location_panel = new EventEdition.LocationPanel (this);
6969
reminder_panel = new EventEdition.ReminderPanel (this);

src/EventEdition/GuestGrid.vala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public class Maya.View.EventEdition.GuestGrid : Gtk.Grid {
4747
avatar = new Hdy.Avatar (ICON_SIZE, name_label.label, true);
4848

4949
column_spacing = 12;
50-
margin = 6;
50+
margin_top = 6;
51+
margin_end = 6;
52+
margin_bottom = 6;
53+
margin_start = 6;
5154
attach (avatar, 0, 0, 1, 4);
5255
attach (name_label, 1, 1);
5356
attach (mail_label, 1, 2);

src/EventEdition/GuestsPanel.vala

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2-
/*-
3-
* Copyright (c) 2011-2015 Maya Developers (http://launchpad.net/maya)
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2011-2026 elementary, Inc. (https://elementary.io)
174
*
185
* Authored by: Jaap Broekhuizen
196
*/
207

21-
public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid {
22-
private EventDialog parent_dialog;
8+
public class Maya.View.EventEdition.GuestsPanel : Gtk.Box {
9+
public ICal.Component component { get; construct; }
10+
2311
private Gtk.Entry guest_entry;
2412
private Gtk.EntryCompletion guest_completion;
2513
private Gtk.ListBox guest_list;
@@ -38,36 +26,35 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid {
3826
N_COLUMNS;
3927
}
4028

41-
public GuestsPanel (EventDialog parent_dialog) {
42-
this.parent_dialog = parent_dialog;
43-
attendees = new Gee.ArrayList<unowned ICal.Property> ();
44-
45-
margin_start = 12;
46-
margin_end = 12;
47-
row_spacing = 6;
48-
orientation = Gtk.Orientation.VERTICAL;
29+
public GuestsPanel (ICal.Component component) {
30+
Object (component: component);
31+
}
4932

33+
construct {
34+
attendees = new Gee.ArrayList<unowned ICal.Property> ();
5035
guest_store = new Gtk.ListStore (2, typeof (string), typeof (string));
5136

52-
var guest_label = new Granite.HeaderLabel (_("Invitees"));
53-
5437
load_contacts.begin ();
5538

5639
var no_guests_label = new Gtk.Label (_("No Invitees"));
40+
no_guests_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
41+
no_guests_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
5742
no_guests_label.show ();
5843

59-
unowned Gtk.StyleContext no_guests_context = no_guests_label.get_style_context ();
60-
no_guests_context.add_class (Granite.STYLE_CLASS_H3_LABEL);
61-
no_guests_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);
62-
63-
guest_list = new Gtk.ListBox ();
64-
guest_list.set_selection_mode (Gtk.SelectionMode.NONE);
44+
guest_list = new Gtk.ListBox () {
45+
hexpand = true,
46+
vexpand = true,
47+
selection_mode = NONE
48+
};
6549
guest_list.set_placeholder (no_guests_label);
6650

51+
var guest_label = new Granite.HeaderLabel (_("Invitees")) {
52+
mnemonic_widget = guest_list
53+
};
54+
6755
var guest_scrolledwindow = new Gtk.ScrolledWindow (null, null) {
6856
child = guest_list
6957
};
70-
guest_scrolledwindow.expand = true;
7158

7259
var frame = new Gtk.Frame (null) {
7360
child = guest_scrolledwindow
@@ -93,34 +80,33 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid {
9380
return false;
9481
});
9582

96-
guest_entry = new Gtk.SearchEntry ();
97-
guest_entry.placeholder_text = _("Invite");
98-
guest_entry.hexpand = true;
83+
guest_entry = new Gtk.SearchEntry () {
84+
hexpand = true,
85+
placeholder_text = _("Invite")
86+
};
9987
guest_entry.set_completion (guest_completion);
10088
guest_entry.activate.connect (() => {
101-
var attendee = new ICal.Property (ICal.PropertyKind.ATTENDEE_PROPERTY);
89+
var attendee = new ICal.Property (ATTENDEE_PROPERTY);
10290
attendee.set_attendee (guest_entry.text);
10391
add_guest ((owned)attendee);
10492
guest_entry.delete_text (0, -1);
10593
});
10694

95+
margin_start = 12;
96+
margin_end = 12;
97+
spacing = 6;
98+
orientation = VERTICAL;
10799
add (guest_label);
108100
add (guest_entry);
109101
add (frame);
110102

111-
if (parent_dialog.ecal != null) {
112-
unowned ICal.Component comp = parent_dialog.ecal.get_icalcomponent ();
113-
// Load the guests
114-
int count = comp.count_properties (ICal.PropertyKind.ATTENDEE_PROPERTY);
115-
116-
ICal.Property property;
117-
property = comp.get_first_property (ICal.PropertyKind.ATTENDEE_PROPERTY);
118-
for (int i = 0; i < count; i++) {
119-
if (property.get_attendee () != null)
120-
add_guest (property);
121-
122-
property = comp.get_next_property (ICal.PropertyKind.ATTENDEE_PROPERTY);
103+
var property = component.get_first_property (ATTENDEE_PROPERTY);
104+
for (int i = 0; i < component.count_properties (ATTENDEE_PROPERTY); i++) {
105+
if (property.get_attendee () != null) {
106+
add_guest (property);
123107
}
108+
109+
property = component.get_next_property (ATTENDEE_PROPERTY);
124110
}
125111

126112
show_all ();
@@ -144,17 +130,13 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid {
144130
* Save the values in the dialog into the component.
145131
*/
146132
public void save () {
147-
unowned ICal.Component comp = parent_dialog.ecal.get_icalcomponent ();
148-
// Save the guests
149133
// First, clear the guests
150-
int count = comp.count_properties (ICal.PropertyKind.ATTENDEE_PROPERTY);
151-
152-
for (int i = 0; i < count; i++) {
134+
for (int i = 0; i < component.count_properties (ATTENDEE_PROPERTY); i++) {
153135
ICal.Property remove_prop;
154136
if (i == 0) {
155-
remove_prop = comp.get_first_property (ICal.PropertyKind.ATTENDEE_PROPERTY);
137+
remove_prop = component.get_first_property (ATTENDEE_PROPERTY);
156138
} else {
157-
remove_prop = comp.get_next_property (ICal.PropertyKind.ATTENDEE_PROPERTY);
139+
remove_prop = component.get_next_property (ATTENDEE_PROPERTY);
158140
}
159141

160142
ICal.Property found_prop = remove_prop;
@@ -167,34 +149,37 @@ public class Maya.View.EventEdition.GuestsPanel : Gtk.Grid {
167149
}
168150

169151
if (can_remove == true) {
170-
comp.remove_property (remove_prop);
152+
component.remove_property (remove_prop);
171153
} else if (found_prop != remove_prop) {
172154
attendees.remove (found_prop);
173155
}
174156
}
175157

176158
// Add the new guests
177159
foreach (unowned ICal.Property attendee in attendees) {
178-
comp.add_property (attendee.clone ());
160+
component.add_property (attendee.clone ());
179161
}
180162
}
181163

182164
private void add_guest (ICal.Property attendee) {
183-
var row = new Gtk.ListBoxRow ();
184165
var guest_element = new GuestGrid (attendee);
185-
row.add (guest_element);
166+
167+
var row = new Gtk.ListBoxRow () {
168+
child = guest_element
169+
};
170+
row.show_all ();
171+
186172
guest_list.add (row);
187173

188174
attendees.add (guest_element.attendee);
175+
189176
guest_element.removed.connect (() => {
190177
attendees.remove (guest_element.attendee);
191178
});
192-
193-
row.show_all ();
194179
}
195180

196181
private bool suggestion_selected (Gtk.TreeModel model, Gtk.TreeIter iter) {
197-
var attendee = new ICal.Property (ICal.PropertyKind.ATTENDEE_PROPERTY);
182+
var attendee = new ICal.Property (ATTENDEE_PROPERTY);
198183
Value selected_value;
199184

200185
model.get_value (iter, 1, out selected_value);

0 commit comments

Comments
 (0)