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

#270: Add button for adding event #299

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions src/Widgets/calendar/CalendarView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid {
box_buttons.add (center_button);
box_buttons.add (right_button);

var new_event_button = new Gtk.Button.from_icon_name ("appointment-new-symbolic");
new_event_button.tooltip_text = _("New event");

events_model = CalendarModel.get_default (ECal.ClientSourceType.EVENTS);
tasks_model = CalendarModel.get_default (ECal.ClientSourceType.TASKS);
start_month = Util.get_start_of_month ();
Expand Down Expand Up @@ -111,7 +114,8 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid {
margin_start = margin_end = 10;
attach (label, 0, 0);
attach (box_buttons, 1, 0);
attach (carousel, 0, 1, 2);
attach (new_event_button, 2, 0);
attach (carousel, 0, 1, 3);

left_button.clicked.connect (() => {
carousel.switch_child ((int) carousel.get_position () - 1, carousel.get_animation_duration ());
Expand All @@ -125,6 +129,10 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid {
show_today ();
});

new_event_button.clicked.connect (() => {
open_maya_with_options (selected_date, true);
});

carousel.page_changed.connect ((index) => {
events_model.change_month (-rel_postion);
tasks_model.change_month (-rel_postion);
Expand Down Expand Up @@ -244,8 +252,11 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid {
}

// TODO: As far as maya supports it use the Dbus Activation feature to run the calendar-app.
public void show_date_in_maya (GLib.DateTime date) {
var command = "io.elementary.calendar --show-day %s".printf (date.format ("%F"));
private void open_maya_with_options (GLib.DateTime? day_to_show, bool add_event = false) {
Copy link
Author

Choose a reason for hiding this comment

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

Expanded the previous show_date_in_maya method to also allow for displaying the new event dialog. Public API remains the same and available.

day_to_show = day_to_show ?? new GLib.DateTime.now_local ();
var command = "io.elementary.calendar";
command += add_event ? " --add-event" : "";
command += " --show-day %s".printf (day_to_show.format ("%F"));

try {
var appinfo = AppInfo.create_from_commandline (command, null, AppInfoCreateFlags.NONE);
Expand All @@ -262,6 +273,10 @@ public class DateTime.Widgets.CalendarView : Gtk.Grid {
}
}

public void show_date_in_maya (GLib.DateTime date) {
open_maya_with_options (date);
}

public void refresh () {
show_today (true);
}
Expand Down