|
| 1 | +using GLib; |
| 2 | + |
| 3 | +namespace SwayNotificationCenter.Widgets { |
| 4 | + public class Calendar : BaseWidget { |
| 5 | + public override string widget_name { |
| 6 | + get { |
| 7 | + return "calendar"; |
| 8 | + } |
| 9 | + } |
| 10 | + |
| 11 | + Gtk.Calendar calendar; |
| 12 | + Gtk.Label date_label; |
| 13 | + Gtk.Label day_label; |
| 14 | + |
| 15 | + public Calendar (string suffix) { |
| 16 | + base (suffix); |
| 17 | + |
| 18 | + Json.Object ?config = get_config (this); |
| 19 | + |
| 20 | + var container = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); |
| 21 | + container.set_margin_start (12); |
| 22 | + container.set_margin_end (12); |
| 23 | + container.set_margin_top (12); |
| 24 | + container.set_margin_bottom (12); |
| 25 | + container.set_hexpand (true); |
| 26 | + |
| 27 | + day_label = new Gtk.Label (""); |
| 28 | + day_label.add_css_class ("day-label"); |
| 29 | + day_label.set_halign (Gtk.Align.START); |
| 30 | + |
| 31 | + date_label = new Gtk.Label (""); |
| 32 | + date_label.add_css_class ("date-label"); |
| 33 | + date_label.set_halign (Gtk.Align.START); |
| 34 | + |
| 35 | + calendar = new Gtk.Calendar (); |
| 36 | + calendar.set_hexpand (true); |
| 37 | + calendar.add_css_class ("calendar-widget"); |
| 38 | + |
| 39 | + if (config != null) { |
| 40 | + bool ?show_day_label = get_prop<bool> (config, "show-day-label", null); |
| 41 | + if (show_day_label == false) { |
| 42 | + day_label.hide (); |
| 43 | + } |
| 44 | + |
| 45 | + bool ?show_date_label = get_prop<bool> (config, "show-date-label", null); |
| 46 | + if (show_date_label == false) { |
| 47 | + date_label.hide (); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + container.append (day_label); |
| 52 | + container.append (date_label); |
| 53 | + container.append (calendar); |
| 54 | + append (container); |
| 55 | + |
| 56 | + calendar.day_selected.connect (update_labels); |
| 57 | + update_labels (); |
| 58 | + } |
| 59 | + |
| 60 | + void update_labels () { |
| 61 | + var now = new GLib.DateTime.now_local (); |
| 62 | + day_label.set_label (now.format ("%A")); |
| 63 | + date_label.set_label (now.format ("%B %-d, %Y")); |
| 64 | + } |
| 65 | + |
| 66 | + public override void on_cc_visibility_change (bool value) { |
| 67 | + if (value) { |
| 68 | + update_labels (); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments