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: Maxwell Barvian
196 * Corentin Noël <corentin@elementaryos.org>
@@ -32,26 +19,24 @@ public class Maya.View.CalendarView : Gtk.Box {
3219 private const string ACTION_GROUP_PREFIX = " calendar" ;
3320 private const string ACTION_PREFIX = ACTION_GROUP_PREFIX + " ." ;
3421
35- public Gtk . SearchEntry search_bar;
36- private Calendar . Widgets . DateSwitcher month_switcher;
37- private Calendar . Widgets . DateSwitcher year_switcher;
38-
39- public Hdy . HeaderBar header_bar { get ; private set ; }
4022 public DateTime ? selected_date { get ; private set ; }
23+ public Gtk . SearchEntry search_bar { get ; private set ; }
24+ public Hdy . HeaderBar header_bar { get ; private set ; }
4125
26+ private Calendar . Widgets . DateSwitcher month_switcher;
27+ private Calendar . Widgets . DateSwitcher year_switcher;
28+ private Grid days_grid;
4229 private Gtk . EventControllerScroll scroll_controller;
43- private WeekLabels weeks { get ; private set ; }
44- private Header header { get ; private set ; }
45- private Grid days_grid { get ; private set ; }
46- private Gtk . Stack stack { get ; private set ; }
47- private Gtk . Label spacer { get ; private set ; }
48- private static GLib . Settings show_weeks;
30+ private Gtk . Stack stack;
31+ private WeekLabels weeks;
32+
33+ private static GLib . Settings settings;
4934
5035 static construct {
5136 if (Application . wingpanel_settings != null ) {
52- show_weeks = Application . wingpanel_settings;
37+ settings = Application . wingpanel_settings;
5338 } else {
54- show_weeks = Application . saved_state;
39+ settings = Application . saved_state;
5540 }
5641 }
5742
@@ -135,14 +120,14 @@ public class Maya.View.CalendarView : Gtk.Box {
135120 };
136121
137122 var calmodel = Calendar . EventStore . get_default ();
138- set_switcher_date (calmodel. month_start);
139123
140124 var spinner = new Maya .View .Widgets .DynamicSpinner ();
141125
142126 var contractor = new Gtk .MenuButton () {
143127 image = new Gtk .Image .from_icon_name (" document-export" , LARGE_TOOLBAR ),
144- popup = new Gtk .Menu .from_model (contractor_menu),
145- tooltip_text = _ ("Export or Share the default Calendar ")
128+ menu_model = contractor_menu,
129+ tooltip_text = _ ("Export or Share the default Calendar "),
130+ use_popover = false
146131 };
147132
148133 var source_popover = new Calendar .Widgets .SourcePopover ();
@@ -165,8 +150,10 @@ public class Maya.View.CalendarView : Gtk.Box {
165150
166151 header_bar.get_style_context ().add_class (Gtk .STYLE_CLASS_FLAT );
167152
168- stack = new Gtk .Stack ();
169- stack. expand = true ;
153+ stack = new Gtk .Stack () {
154+ hexpand = true ,
155+ vexpand = true
156+ };
170157
171158 sync_with_model (); // Populate stack with a grid
172159
@@ -187,8 +174,8 @@ public class Maya.View.CalendarView : Gtk.Box {
187174 }
188175 });
189176
190- show_weeks .changed["show-weeks"].connect (on_show_weeks_changed );
191- show_weeks .get_value ("show -weeks ");
177+ settings .changed["show-weeks"].connect (on_show_weeks_changed );
178+ settings .get_value ("show -weeks ");
192179
193180 events |= Gdk . EventMask . BUTTON_PRESS_MASK ;
194181 events |= Gdk . EventMask . KEY_PRESS_MASK ;
@@ -216,6 +203,8 @@ public class Maya.View.CalendarView : Gtk.Box {
216203 month_switcher.right_clicked.connect (() => Calendar.EventStore.get_default ().change_month (1 ));
217204 year_switcher.left_clicked.connect (() => Calendar.EventStore.get_default ().change_year (-1 ));
218205 year_switcher.right_clicked.connect (() => Calendar.EventStore.get_default ().change_year (1 ));
206+
207+ set_switcher_date (calmodel .month_start );
219208 calmodel.parameters_changed.connect (() => {
220209 set_switcher_date (calmodel. month_start);
221210 });
@@ -264,35 +253,24 @@ public class Maya.View.CalendarView : Gtk.Box {
264253 year_switcher. text = date. format (" %Y " );
265254 }
266255
267- // --- Public Methods ---//
268-
269256 public void today () {
270257 var today = Calendar . Util . datetime_strip_time (new DateTime .now_local ());
271258 var calmodel = Calendar . EventStore . get_default ();
272259 var start = Calendar . Util . datetime_get_start_of_month (today);
273- if (! start. equal (calmodel. month_start))
260+ if (! start. equal (calmodel. month_start)) {
274261 calmodel. month_start = start;
262+ }
263+
275264 sync_with_model ();
276265 days_grid. focus_date (today);
277266 }
278267
279- // --- Signal Handlers ---//
280-
281- void on_show_weeks_changed () {
268+ private void on_show_weeks_changed () {
282269 var model = Calendar . EventStore . get_default ();
283270 weeks. update (model. data_range. first_dt, model. num_weeks);
284- update_spacer_visible ();
285- }
286-
287- private void update_spacer_visible () {
288- if (show_weeks. get_boolean (" show-weeks" )) {
289- spacer. show ();
290- } else {
291- spacer. hide ();
292- }
293271 }
294272
295- void on_events_added (E .Source source , Gee .Collection<ECal . Component > events ) {
273+ private void on_events_added (E .Source source , Gee .Collection<ECal . Component > events ) {
296274 Idle . add ( () = > {
297275 foreach (var event in events) {
298276 add_event (source, event);
@@ -302,7 +280,7 @@ public class Maya.View.CalendarView : Gtk.Box {
302280 });
303281 }
304282
305- void on_events_updated (E .Source source , Gee .Collection<ECal . Component > events ) {
283+ private void on_events_updated (E .Source source , Gee .Collection<ECal . Component > events ) {
306284 Idle . add ( () = > {
307285 foreach (var event in events) {
308286 update_event (source, event);
@@ -312,7 +290,7 @@ public class Maya.View.CalendarView : Gtk.Box {
312290 });
313291 }
314292
315- void on_events_removed (E .Source source , Gee .Collection<ECal . Component > events ) {
293+ private void on_events_removed (E .Source source , Gee .Collection<ECal . Component > events ) {
316294 Idle . add ( () = > {
317295 foreach (var event in events)
318296 remove_event (source, event);
@@ -322,7 +300,7 @@ public class Maya.View.CalendarView : Gtk.Box {
322300 }
323301
324302 /* Indicates the month has changed */
325- void on_model_parameters_changed () {
303+ private void on_model_parameters_changed () {
326304 var model = Calendar . EventStore . get_default ();
327305 if (days_grid. grid_range != null && model. data_range. equals (days_grid. grid_range))
328306 return ; // nothing to do
@@ -334,15 +312,32 @@ public class Maya.View.CalendarView : Gtk.Box {
334312 });
335313 }
336314
337- // --- Helper Methods ---//
338- Gtk .Grid create_big_grid () {
339- spacer = new Gtk .Label (" " );
340- spacer. no_show_all = true ;
315+ /* Sets the calendar widgets to the date range of the model */
316+ private void sync_with_model () {
317+ var model = Calendar . EventStore . get_default ();
318+ DateTime previous_first = null ;
319+ if (days_grid != null ) {
320+ if (days_grid. grid_range != null && (model. data_range. equals (days_grid. grid_range) || days_grid. grid_range. first_dt. compare (model. data_range. first_dt) == 0 )) {
321+ return ; // nothing to do
322+ }
323+
324+ if (days_grid. grid_range != null ) {
325+ previous_first = days_grid. grid_range. first_dt;
326+ }
327+ }
328+
329+ var spacer = new Gtk .Label (" " );
341330 spacer. get_style_context (). add_class (" weeks" );
342331
332+ var spacer_revealer = new Gtk .Revealer () {
333+ child = spacer,
334+ transition_type = CROSSFADE
335+ };
336+
343337 weeks = new WeekLabels ();
344338
345- header = new Header ();
339+ var header = new Header ();
340+
346341 days_grid = new Grid ();
347342 days_grid. focus_date (selected_date);
348343 days_grid. on_event_add. connect ((date) = > on_event_add (date));
@@ -351,32 +346,18 @@ public class Maya.View.CalendarView : Gtk.Box {
351346 selection_changed (date);
352347 });
353348
354- // Grid properties
355- var new_big_grid = new Gtk .Grid ();
356- new_big_grid. attach (spacer, 0 , 0 , 1 , 1 );
357- new_big_grid. attach (header, 1 , 0 , 1 , 1 );
358- new_big_grid. attach (days_grid, 1 , 1 , 1 , 1 );
359- new_big_grid. attach (weeks, 0 , 1 , 1 , 1 );
360- new_big_grid. show_all ();
361- new_big_grid. expand = true ;
362-
363- update_spacer_visible ();
364-
365- return new_big_grid;
366- }
349+ var big_grid = new Gtk .Grid () {
350+ hexpand = true ,
351+ vexpand = true
352+ };
353+ big_grid. attach (spacer_revealer, 0 , 0 );
354+ big_grid. attach (header, 1 , 0 );
355+ big_grid. attach (days_grid, 1 , 1 );
356+ big_grid. attach (weeks, 0 , 1 );
357+ big_grid. show_all ();
367358
368- /* Sets the calendar widgets to the date range of the model */
369- void sync_with_model () {
370- var model = Calendar . EventStore . get_default ();
371- DateTime previous_first = null ;
372- if (days_grid != null ) {
373- if (days_grid. grid_range != null && (model. data_range. equals (days_grid. grid_range) || days_grid. grid_range. first_dt. compare (model. data_range. first_dt) == 0 ))
374- return ; // nothing to do
375- if (days_grid. grid_range != null )
376- previous_first = days_grid. grid_range. first_dt;
377- }
359+ settings. bind (" show-weeks" , spacer_revealer, " reveal-child" , SettingsBindFlags . GET );
378360
379- var big_grid = create_big_grid ();
380361 stack. add (big_grid);
381362
382363 header. update_columns (model. week_starts_on);
@@ -391,35 +372,35 @@ public class Maya.View.CalendarView : Gtk.Box {
391372
392373 if (previous_first != null ) {
393374 if (previous_first. compare (days_grid. grid_range. first_dt) == - 1 ) {
394- stack. transition_type = Gtk . StackTransitionType . SLIDE_LEFT ;
375+ stack. transition_type = SLIDE_LEFT ;
395376 } else {
396- stack. transition_type = Gtk . StackTransitionType . SLIDE_RIGHT ;
377+ stack. transition_type = SLIDE_RIGHT ;
397378 }
398379 }
399380
400381 stack. set_visible_child (big_grid);
401382 }
402383
403384 /* Render new event on the grid */
404- void add_event (E .Source source , ECal .Component event ) {
385+ private void add_event (E .Source source , ECal .Component event ) {
405386 /* The "source" data is added to events by the Calendar.EventStore. The grid must only show events that have
406387 been added to the model first */
407388 assert (event. get_data< E . Source > (" source" ) != null );
408389 days_grid. add_event (event);
409390 }
410391
411392 /* Update the event on the grid */
412- void update_event (E .Source source , ECal .Component event ) {
393+ private void update_event (E .Source source , ECal .Component event ) {
413394 days_grid. update_event (event);
414395 }
415396
416397 /* Remove event from the grid */
417- void remove_event (E .Source source , ECal .Component event ) {
398+ private void remove_event (E .Source source , ECal .Component event ) {
418399 days_grid. remove_event (event);
419400 }
420401
421402 /* Remove all events from the grid */
422- void remove_all_events () {
403+ private void remove_all_events () {
423404 days_grid. remove_all_events ();
424405 }
425406}
0 commit comments