| 1 |
/* DateRow.vala |
| 2 |
* |
| 3 |
* Copyright 2023 Diego Iván <[email protected]> |
| 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/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
[GtkTemplate (ui = "/io/github/diegoivan/pdf_metadata_editor/gtk/date-row.ui")] |
| 22 |
public class PaperClip.DateRow : Adw.ActionRow { |
| 23 |
[GtkChild] |
| 24 |
private unowned Gtk.Calendar calendar; |
| 25 |
|
| 26 |
private DateTime? _date; |
| 27 |
public DateTime? date { |
| 28 |
get { |
| 29 |
return _date; |
| 30 |
} |
| 31 |
set { |
| 32 |
_date = value; |
| 33 |
if (date == null) { |
| 34 |
subtitle = _("No date set"); |
| 35 |
} else { |
| 36 |
subtitle = date.format ("%x"); |
| 37 |
datetime_to_calendar (date); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
[GtkCallback] |
| 43 |
private void on_clear_button_clicked () { |
| 44 |
date = null; |
| 45 |
} |
| 46 |
|
| 47 |
[GtkCallback] |
| 48 |
private void on_day_selected () { |
| 49 |
date = calendar.get_date (); |
| 50 |
} |
| 51 |
|
| 52 |
[GtkCallback] |
| 53 |
private void on_today_button_clicked () { |
| 54 |
var today_time = new DateTime.now_local (); |
| 55 |
|
| 56 |
datetime_to_calendar (today_time); |
| 57 |
date = today_time; |
| 58 |
} |
| 59 |
|
| 60 |
[GtkCallback] |
| 61 |
private void on_tomorrow_button_clicked () { |
| 62 |
var tomorrow_time = new DateTime.now_local (); |
| 63 |
tomorrow_time = tomorrow_time.add_days (1); |
| 64 |
|
| 65 |
datetime_to_calendar (tomorrow_time); |
| 66 |
date = tomorrow_time; |
| 67 |
} |
| 68 |
|
| 69 |
private void datetime_to_calendar (DateTime date_time) { |
| 70 |
int year, month, day; |
| 71 |
date_time.get_ymd (out year, out month, out day); |
| 72 |
|
| 73 |
calendar.year = year; |
| 74 |
calendar.month = month - 1; |
| 75 |
calendar.day = day; |
| 76 |
} |
| 77 |
} |