LibGUI+TaskBar: Make Calendar::formatted_date() return ErrorOr<String>

This commit introduces no error propagation.
This commit is contained in:
Karol Kosek 2023-02-11 21:19:00 +01:00 committed by Linus Groh
parent f802920a3a
commit b5cb9a9ebb
Notes: sideshowbarker 2024-07-17 06:39:26 +09:00
4 changed files with 23 additions and 23 deletions

View file

@ -7,6 +7,7 @@
*/
#include <AK/DateConstants.h>
#include <AK/String.h>
#include <LibConfig/Client.h>
#include <LibCore/DateTime.h>
#include <LibGUI/Calendar.h>
@ -332,20 +333,19 @@ void Calendar::update_tiles(unsigned view_year, unsigned view_month)
update();
}
DeprecatedString Calendar::formatted_date(Format format)
ErrorOr<String> Calendar::formatted_date(Format format)
{
switch (format) {
case ShortMonthYear:
return DeprecatedString::formatted("{} {}", short_month_names[view_month() - 1], view_year());
return String::formatted("{} {}", short_month_names[view_month() - 1], view_year());
case LongMonthYear:
return DeprecatedString::formatted("{} {}", long_month_names[view_month() - 1], view_year());
return String::formatted("{} {}", long_month_names[view_month() - 1], view_year());
case MonthOnly:
return DeprecatedString::formatted("{}", long_month_names[view_month() - 1]);
return String::formatted("{}", long_month_names[view_month() - 1]);
case YearOnly:
return DeprecatedString::number(view_year());
default:
VERIFY_NOT_REACHED();
return String::number(view_year());
}
VERIFY_NOT_REACHED();
}
void Calendar::paint_event(GUI::PaintEvent& event)
@ -376,7 +376,7 @@ void Calendar::paint_event(GUI::PaintEvent& event)
22);
y_offset += year_only_rect.height();
painter.fill_rect(year_only_rect, palette().hover_highlight());
painter.draw_text(year_only_rect, formatted_date(YearOnly), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
painter.draw_text(year_only_rect, formatted_date(YearOnly).release_value_but_fixme_should_propagate_errors(), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
painter.draw_line({ 0, y_offset }, { frame_inner_rect().width(), y_offset }, (!m_show_month_tiles ? palette().threed_shadow1() : palette().threed_shadow2()), 1);
y_offset += 1;
if (!m_show_month_tiles) {
@ -391,9 +391,9 @@ void Calendar::paint_event(GUI::PaintEvent& event)
22);
painter.fill_rect(month_year_rect, palette().hover_highlight());
month_year_rect.set_width(frame_inner_rect().width() / 2);
painter.draw_text(month_year_rect, formatted_date(MonthOnly), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
painter.draw_text(month_year_rect, formatted_date(MonthOnly).release_value_but_fixme_should_propagate_errors(), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
month_year_rect.set_x(month_year_rect.width() + (frame_inner_rect().width() % 2 ? 1 : 0));
painter.draw_text(month_year_rect, formatted_date(YearOnly), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
painter.draw_text(month_year_rect, formatted_date(YearOnly).release_value_but_fixme_should_propagate_errors(), medium_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text());
y_offset += 22;
painter.draw_line({ 0, y_offset }, { frame_inner_rect().width(), y_offset }, palette().threed_shadow1(), 1);
y_offset += 1;

View file

@ -45,7 +45,7 @@ public:
unsigned view_year() const { return m_view_year; }
unsigned view_month() const { return m_view_month; }
DeprecatedString formatted_date(Format format = LongMonthYear);
ErrorOr<String> formatted_date(Format format = LongMonthYear);
Mode mode() const { return m_mode; }
void toggle_mode();

View file

@ -86,7 +86,7 @@ void Statusbar::update_segment(size_t index)
if (!text(i).is_empty())
m_segments[i].set_visible(true);
}
segment.set_text_deprecated(segment.restored_text());
segment.set_text(String::from_utf8(segment.restored_text()).release_value_but_fixme_should_propagate_errors());
segment.set_frame_shape(Gfx::FrameShape::Panel);
if (segment.mode() != Segment::Mode::Proportional)
segment.set_fixed_width(segment.restored_width());
@ -95,7 +95,7 @@ void Statusbar::update_segment(size_t index)
if (!m_segments[i].is_clickable())
m_segments[i].set_visible(false);
}
segment.set_text_deprecated(segment.override_text());
segment.set_text(String::from_utf8(segment.override_text()).release_value_but_fixme_should_propagate_errors());
segment.set_frame_shape(Gfx::FrameShape::NoFrame);
if (segment.mode() != Segment::Mode::Proportional)
segment.set_fixed_width(SpecialDimension::Grow);

View file

@ -71,9 +71,9 @@ ClockWidget::ClockWidget()
}
m_calendar->update_tiles(view_year, view_month);
if (m_calendar->mode() == GUI::Calendar::Year)
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date(GUI::Calendar::YearOnly));
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
else
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
};
m_selected_calendar_button = navigation_container.add<GUI::Button>();
@ -82,9 +82,9 @@ ClockWidget::ClockWidget()
m_selected_calendar_button->on_click = [&](auto) {
m_calendar->toggle_mode();
if (m_calendar->mode() == GUI::Calendar::Year)
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date(GUI::Calendar::YearOnly));
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
else
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
};
m_next_date = navigation_container.add<GUI::Button>();
@ -105,9 +105,9 @@ ClockWidget::ClockWidget()
}
m_calendar->update_tiles(view_year, view_month);
if (m_calendar->mode() == GUI::Calendar::Year)
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date(GUI::Calendar::YearOnly));
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
else
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
};
auto& separator1 = root_container->add<GUI::HorizontalSeparator>();
@ -118,14 +118,14 @@ ClockWidget::ClockWidget()
calendar_container.layout()->set_margins({ 2 });
m_calendar = calendar_container.add<GUI::Calendar>();
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
m_calendar->on_tile_click = [&] {
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
};
m_calendar->on_month_click = [&] {
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
};
auto& separator2 = root_container->add<GUI::HorizontalSeparator>();
@ -238,7 +238,7 @@ void ClockWidget::jump_to_current_date()
m_calendar->toggle_mode();
m_calendar->set_selected_date(Core::DateTime::now());
m_calendar->update_tiles(Core::DateTime::now().year(), Core::DateTime::now().month());
m_selected_calendar_button->set_text_deprecated(m_calendar->formatted_date());
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
}
}