Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sources in calendar chooser when source connects #742

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EventEdition/InfoPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class Maya.View.EventEdition.InfoPanel : Gtk.Grid {
// Row: title & calendar
attach (title_label, 0, 0, 1, 1);
attach (title_entry, 0, 1, 1, 1);
if (calendar_button.sources.length () > 1 && parent_dialog.can_edit) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered adding this element only once all sources were initialized but given that the registry is accessed within the CalendarChooser component, it would have led to a lot of extra code. The only downside to this approach is that a user who only has one calendar will only have one source to select from in the dropdown. I think this is a reasonably minor UX tradeoff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a fine tradeoff. From my perspective (not on the UX team) having the selector present even with only one source may be good for consistency.

My only concern is that this could lead to a state where not all the sources are available in the chooser. Depending how long that state lasts it may be worthwhile to add a spinner or something of the sort, if there's an easy way to access a state that indicates we're still loading sources. This may not be much of an issue though.

if (parent_dialog.can_edit) {
attach (calendar_label, 1, 0, 4, 1);
attach (calendar_button, 1, 1, 4, 1);
}
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/CalendarButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Maya.View.Widgets.CalendarButton : Gtk.MenuButton {

var button_grid = new Gtk.Grid ();
button_grid.column_spacing = 6;
button_grid.valign = Gtk.Align.CENTER;
button_grid.add (current_calendar_grid);
button_grid.add (new Gtk.Image.from_icon_name ("pan-down-symbolic", Gtk.IconSize.MENU));
add (button_grid);
Expand Down
39 changes: 25 additions & 14 deletions src/Widgets/CalendarChooser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid {
public GLib.List<E.Source> sources;
public E.Source current_source { get; set; }

private Calendar.EventStore calmodel;
private E.SourceRegistry registry;
private Gtk.SearchEntry search_entry;
private Gtk.ListBox list_box;

construct {
// Set up sources list
sources = new GLib.List<E.Source> ();
var calmodel = Calendar.EventStore.get_default ();
var registry = calmodel.registry;
foreach (var src in registry.list_sources (E.SOURCE_EXTENSION_CALENDAR)) {
if (src.writable == true && src.enabled == true && calmodel.calclient_is_readonly (src) == false) {
sources.append (src);
}
}

// GUI setup

calmodel = Calendar.EventStore.get_default ();
registry = calmodel.registry;
current_source = registry.default_calendar;

// GUI setup
search_entry = new Gtk.SearchEntry ();
search_entry.margin = 12;
search_entry.margin_bottom = 6;
Expand All @@ -57,7 +51,7 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid {
);
placeholder.show_all ();

var list_box = new Gtk.ListBox ();
list_box = new Gtk.ListBox ();
list_box.activate_on_single_click = true;
list_box.set_placeholder (placeholder);

Expand Down Expand Up @@ -123,7 +117,24 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid {
// TODO Should active calendar be re-selected?
});

// Populate list_box
// Parse registry list_sources and render list_box;
render_sources ();

// Re-render sources when a new source connects;
calmodel.connected.connect (() => render_sources ());
}

private void render_sources () {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted render code into a private method so it can be used both in the initial constructor and as an event handler.

// Set up sources list
sources = new GLib.List<E.Source> ();
foreach (var src in registry.list_sources (E.SOURCE_EXTENSION_CALENDAR)) {
if (src.writable == true && src.enabled == true && calmodel.calclient_is_readonly (src) == false) {
sources.append (src);
}
}

// Render sources into list_box
list_box.foreach (element => list_box.remove (element));
foreach (var source in sources) {
var calrow = new CalendarRow (source);
calrow.margin = 6;
Expand Down