The Client class provides a nice, high-level async API for client-server communication.
122 lines
3.3 KiB
Vala
122 lines
3.3 KiB
Vala
namespace StudySystemClient {
|
|
public class ActivitiesView : Gtk.Box {
|
|
public ActivitiesView(Client client) {
|
|
margin_top = margin_bottom = margin_start = margin_end = 0;
|
|
|
|
var scrolled_window = new Gtk.ScrolledWindow();
|
|
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
|
scrolled_window.vexpand = true;
|
|
|
|
var card_container = new Gtk.FlowBox();
|
|
card_container.homogeneous = true;
|
|
card_container.min_children_per_line = 1;
|
|
card_container.max_children_per_line = 1;
|
|
card_container.selection_mode = Gtk.SelectionMode.NONE;
|
|
card_container.valign = Gtk.Align.START;
|
|
scrolled_window.add_css_class("card-container");
|
|
|
|
var activities = new Activity[] {
|
|
{ 2, "Linguistics", ActivityType.EXERCISES },
|
|
{ 1, "Cybernetics", ActivityType.EXERCISES },
|
|
{ 2, "Linguistics", ActivityType.READING },
|
|
{ 0, "Physics", ActivityType.READING },
|
|
{ 1, "Cybernetics", ActivityType.READING },
|
|
{ 0, "Physics", ActivityType.EXERCISES },
|
|
};
|
|
foreach (var activity in activities) {
|
|
var card = new ActivityCard(client, activity);
|
|
card_container.append(card);
|
|
}
|
|
|
|
scrolled_window.set_child(card_container);
|
|
this.append(scrolled_window);
|
|
}
|
|
}
|
|
|
|
private class ActivityCard : Gtk.Frame {
|
|
public ActivityCard(Client client, Activity activity) {
|
|
add_css_class("card");
|
|
|
|
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
|
|
|
|
var text = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
|
|
text.hexpand = true;
|
|
|
|
var subject = new Gtk.Label(activity.subject_name);
|
|
subject.halign = Gtk.Align.START;
|
|
subject.add_css_class("activity-subject");
|
|
text.append(subject);
|
|
|
|
var type = new Gtk.Label(activity.type.to_string());
|
|
type.halign = Gtk.Align.START;
|
|
text.append(type);
|
|
|
|
content.append(text);
|
|
|
|
var button
|
|
= new Gtk.Button.from_icon_name("appointment-new-symbolic");
|
|
button.vexpand = false;
|
|
button.valign = Gtk.Align.CENTER;
|
|
button.set_tooltip_text("Log session");
|
|
button.add_css_class("log-session-button");
|
|
content.append(button);
|
|
|
|
set_child(content);
|
|
|
|
var log_session_popover = new LogSessionPopover(client);
|
|
log_session_popover.set_parent(button);
|
|
button.clicked.connect(() => log_session_popover.popup());
|
|
}
|
|
}
|
|
|
|
private class LogSessionPopover : Gtk.Popover {
|
|
private const int DEFAULT_LENGTH = 30;
|
|
|
|
private Gtk.SpinButton input;
|
|
private Client client;
|
|
|
|
public LogSessionPopover(Client client) {
|
|
this.client = client;
|
|
|
|
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
|
|
|
|
var label = new Gtk.Label("Minutes");
|
|
label.halign = Gtk.Align.START;
|
|
content.append(label);
|
|
|
|
var adjustment
|
|
= new Gtk.Adjustment(DEFAULT_LENGTH, 10, 480, 10, 10, 0);
|
|
input = new Gtk.SpinButton(adjustment, 1, 0);
|
|
input.numeric = true;
|
|
content.append(input);
|
|
|
|
var button = new Gtk.Button.from_icon_name("emblem-ok-symbolic");
|
|
button.halign = Gtk.Align.END;
|
|
button.set_tooltip_text("Submit");
|
|
button.add_css_class("suggested-action");
|
|
button.clicked.connect(submit);
|
|
content.append(button);
|
|
|
|
set_child(content);
|
|
|
|
closed.connect(reset);
|
|
}
|
|
|
|
private async void submit() {
|
|
reset();
|
|
popdown();
|
|
|
|
try {
|
|
yield client.ping();
|
|
stderr.printf("Successfully pinged server\n");
|
|
} catch (ClientError e) {
|
|
stderr.printf("Error pinging server: %s\n", e.message);
|
|
}
|
|
}
|
|
|
|
private void reset() {
|
|
input.value = DEFAULT_LENGTH;
|
|
}
|
|
}
|
|
}
|