diff options
Diffstat (limited to 'src/gui/form/repetition.rs')
-rw-r--r-- | src/gui/form/repetition.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/gui/form/repetition.rs b/src/gui/form/repetition.rs index 87c8d84..7236016 100644 --- a/src/gui/form/repetition.rs +++ b/src/gui/form/repetition.rs @@ -126,26 +126,23 @@ fn label(text: &str) -> gtk::Label { .build() } -pub fn validate(model: &Model) -> Option<Repetition> { +pub fn validate(model: &Model) -> Result<Option<Repetition>, String> { if model.no_radio.is_active() { - None + Ok(None) } else if model.day_interval_radio.is_active() { - repetition::validate_day(&model.day_interval_entry.buffer().text()) - .map(|d| Repetition::Daily { period: d }) + let period = repetition::validate_period(&model.day_interval_entry.buffer().text())?; + Ok(Some(Repetition::Daily { period })) } else if model.monthly_radio.is_active() { - repetition::validate_day(&model.monthly_entry.buffer().text()).map(|d| { - Repetition::Monthly { - day: DayOfMonth::Day { day: d }, - } - }) + let day = repetition::validate_day(&model.monthly_entry.buffer().text())?; + Ok(Some(Repetition::Monthly { day: DayOfMonth::Day { day } })) } else if model.first_day_radio.is_active() { let weekday = WEEKDAYS[model.first_day_dropdown.selected() as usize]; - Some(Repetition::Monthly { + Ok(Some(Repetition::Monthly { day: DayOfMonth::Weekday { weekday }, - }) + })) } else if model.yearly_radio.is_active() { - Some(Repetition::Yearly) + Ok(Some(Repetition::Yearly)) } else { - None + Err("Aucune option n’a été sélectionnée".to_string()) } } |