window: Simplify CSS recalculation code
This commit is contained in:
+6
-12
@@ -276,25 +276,20 @@ update_active_date (GcalWindow *window,
|
||||
static void
|
||||
recalculate_calendar_colors_css (GcalWindow *self)
|
||||
{
|
||||
g_autoptr (GString) css_colors = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autoptr (GList) calendars = NULL;
|
||||
g_autofree gchar *new_css_data = NULL;
|
||||
g_auto (GStrv) new_css_snippets = NULL;
|
||||
GcalManager *manager;
|
||||
GQuark color_id;
|
||||
GList *l;
|
||||
gint arr_length;
|
||||
gint i = 0;
|
||||
|
||||
css_colors = g_string_new (NULL);
|
||||
manager = gcal_context_get_manager (self->context);
|
||||
calendars = gcal_manager_get_calendars (manager);
|
||||
arr_length = g_list_length (calendars);
|
||||
new_css_snippets = g_new0 (gchar*, arr_length + 2);
|
||||
for (l = calendars; l; l = l->next, i++)
|
||||
for (GList *l = calendars; l; l = l->next)
|
||||
{
|
||||
g_autofree gchar* color_str = NULL;
|
||||
const GdkRGBA *color;
|
||||
GcalCalendar *calendar;
|
||||
GQuark color_id;
|
||||
|
||||
calendar = GCAL_CALENDAR (l->data);
|
||||
|
||||
@@ -302,11 +297,10 @@ recalculate_calendar_colors_css (GcalWindow *self)
|
||||
color_str = gdk_rgba_to_string (color);
|
||||
color_id = g_quark_from_string (color_str);
|
||||
|
||||
new_css_snippets[i] = g_strdup_printf (".color-%u { --event-bg-color: %s; }", color_id, color_str);
|
||||
g_string_append_printf (css_colors, ".color-%u { --event-bg-color: %s; }\n", color_id, color_str);
|
||||
}
|
||||
|
||||
new_css_data = g_strjoinv ("\n", new_css_snippets);
|
||||
gtk_css_provider_load_from_string (self->colors_provider, new_css_data);
|
||||
gtk_css_provider_load_from_string (self->colors_provider, css_colors->str);
|
||||
|
||||
if (error)
|
||||
g_warning ("Error creating custom stylesheet. %s", error->message);
|
||||
|
||||
Reference in New Issue
Block a user