app: use GcalManager:load-completed signal
Use this signal to load the CSS code for the widgets just one time instead of recreating the complete CSS code once for each source connected
This commit is contained in:
+73
-60
@@ -43,17 +43,13 @@ struct _GcalApplicationPrivate
|
|||||||
GcalShellSearchProvider *search_provider;
|
GcalShellSearchProvider *search_provider;
|
||||||
|
|
||||||
GtkCssProvider *provider;
|
GtkCssProvider *provider;
|
||||||
|
|
||||||
gchar **css_code_snippets;
|
|
||||||
GtkCssProvider *colors_provider;
|
GtkCssProvider *colors_provider;
|
||||||
|
|
||||||
icaltimetype *initial_date;
|
icaltimetype *initial_date;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void source_added_cb (GcalManager *manager,
|
static void load_completed_cb (GcalApplication *application,
|
||||||
ESource *source,
|
GcalManager *manager);
|
||||||
gboolean enabled,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void gcal_application_finalize (GObject *object);
|
static void gcal_application_finalize (GObject *object);
|
||||||
|
|
||||||
@@ -123,77 +119,78 @@ static const GActionEntry gcal_app_entries[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
source_added_cb (GcalManager *manager,
|
process_sources (GcalApplication *application)
|
||||||
ESource *source,
|
|
||||||
gboolean enabled,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
GcalApplicationPrivate *priv;
|
GcalApplicationPrivate *priv;
|
||||||
|
|
||||||
gint i, arr_length = 0;
|
GList *sources, *l;
|
||||||
|
ESource *source;
|
||||||
|
|
||||||
|
gint arr_length, i = 0;
|
||||||
ESourceSelectable *extension;
|
ESourceSelectable *extension;
|
||||||
GQuark color_id;
|
GQuark color_id;
|
||||||
const gchar* color_str;
|
const gchar* color_str;
|
||||||
|
|
||||||
gchar *css_snippet, *bkg_color, *slanted_edge_both_ltr, *slanted_edge_both_rtl;
|
gchar *bkg_color, *slanted_edge_both_ltr, *slanted_edge_both_rtl;
|
||||||
gchar *slanted_edge_start_ltr, *slanted_edge_start_rtl, *slanted_edge_end_ltr, *slanted_edge_end_rtl;
|
gchar *slanted_edge_start_ltr, *slanted_edge_start_rtl, *slanted_edge_end_ltr, *slanted_edge_end_rtl;
|
||||||
gchar **new_css_snippets;
|
gchar **new_css_snippets;
|
||||||
gchar *new_css_data;
|
gchar *new_css_data;
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
priv = GCAL_APPLICATION (user_data)->priv;
|
priv = application->priv;
|
||||||
|
|
||||||
extension = E_SOURCE_SELECTABLE (e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR));
|
|
||||||
color_id = g_quark_from_string (e_source_selectable_get_color (extension));
|
|
||||||
color_str = e_source_selectable_get_color (extension);
|
|
||||||
|
|
||||||
if (priv->css_code_snippets != NULL)
|
|
||||||
arr_length = g_strv_length (priv->css_code_snippets);
|
|
||||||
|
|
||||||
|
sources = gcal_manager_get_sources_connected (priv->manager);
|
||||||
|
arr_length = g_list_length (sources);
|
||||||
new_css_snippets = g_new0 (gchar*, arr_length + 2);
|
new_css_snippets = g_new0 (gchar*, arr_length + 2);
|
||||||
|
for (l = sources; l != NULL; l = g_list_next (l), i++)
|
||||||
|
{
|
||||||
|
source = l->data;
|
||||||
|
|
||||||
for (i = 0; i < arr_length; i++)
|
extension = E_SOURCE_SELECTABLE (e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR));
|
||||||
new_css_snippets[i] = priv->css_code_snippets[i];
|
color_id = g_quark_from_string (e_source_selectable_get_color (extension));
|
||||||
|
color_str = e_source_selectable_get_color (extension);
|
||||||
|
|
||||||
bkg_color = g_strdup_printf (CSS_TEMPLATE, color_id, color_str);
|
bkg_color = g_strdup_printf (CSS_TEMPLATE, color_id, color_str);
|
||||||
slanted_edge_both_ltr =
|
slanted_edge_both_ltr =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE_BOTH, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE_BOTH, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str,
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
slanted_edge_both_rtl =
|
slanted_edge_both_rtl =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE_BOTH_RTL, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE_BOTH_RTL, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str,
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
slanted_edge_end_ltr =
|
slanted_edge_end_ltr =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
slanted_edge_start_ltr =
|
slanted_edge_start_ltr =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE_START, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE_START, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
slanted_edge_end_rtl =
|
slanted_edge_end_rtl =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE_RTL, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE_RTL, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
slanted_edge_start_rtl =
|
slanted_edge_start_rtl =
|
||||||
g_strdup_printf (CSS_TEMPLATE_EDGE_START_RTL, color_id,
|
g_strdup_printf (CSS_TEMPLATE_EDGE_START_RTL, color_id,
|
||||||
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
color_str, color_str, color_str, color_str, color_str, color_str, color_str, color_str);
|
||||||
css_snippet = g_strconcat (bkg_color, slanted_edge_both_ltr, slanted_edge_both_rtl,
|
|
||||||
slanted_edge_end_ltr, slanted_edge_start_ltr,
|
|
||||||
slanted_edge_end_rtl, slanted_edge_start_rtl, NULL);
|
|
||||||
new_css_snippets[arr_length] = css_snippet;
|
|
||||||
g_free (bkg_color);
|
|
||||||
g_free (slanted_edge_both_ltr);
|
|
||||||
g_free (slanted_edge_both_rtl);
|
|
||||||
g_free (slanted_edge_end_ltr);
|
|
||||||
g_free (slanted_edge_start_ltr);
|
|
||||||
g_free (slanted_edge_start_rtl);
|
|
||||||
g_free (slanted_edge_end_rtl);
|
|
||||||
|
|
||||||
if (priv->css_code_snippets != NULL)
|
new_css_snippets[i] = g_strconcat (bkg_color, slanted_edge_both_ltr, slanted_edge_both_rtl,
|
||||||
g_free (priv->css_code_snippets); /* shallow free, cause I'm just moving the pointers */
|
slanted_edge_end_ltr, slanted_edge_start_ltr,
|
||||||
priv->css_code_snippets = new_css_snippets;
|
slanted_edge_end_rtl, slanted_edge_start_rtl, NULL);
|
||||||
|
|
||||||
|
g_free (bkg_color);
|
||||||
|
g_free (slanted_edge_both_ltr);
|
||||||
|
g_free (slanted_edge_both_rtl);
|
||||||
|
g_free (slanted_edge_end_ltr);
|
||||||
|
g_free (slanted_edge_start_ltr);
|
||||||
|
g_free (slanted_edge_start_rtl);
|
||||||
|
g_free (slanted_edge_end_rtl);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_free (sources);
|
||||||
|
|
||||||
new_css_data = g_strjoinv ("\n", new_css_snippets);
|
new_css_data = g_strjoinv ("\n", new_css_snippets);
|
||||||
|
g_strfreev (new_css_snippets);
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
gtk_css_provider_load_from_data (priv->colors_provider, new_css_data, -1, &error);
|
gtk_css_provider_load_from_data (priv->colors_provider, new_css_data, -1, &error);
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
@@ -202,6 +199,25 @@ source_added_cb (GcalManager *manager,
|
|||||||
g_free (new_css_data);
|
g_free (new_css_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sources_added_cb (GcalApplication *application,
|
||||||
|
ESource *source,
|
||||||
|
gboolean enabled,
|
||||||
|
GcalManager *manager)
|
||||||
|
{
|
||||||
|
process_sources (application);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_completed_cb (GcalApplication *application,
|
||||||
|
GcalManager *manager)
|
||||||
|
{
|
||||||
|
process_sources (application);
|
||||||
|
|
||||||
|
/* listen for other sources */
|
||||||
|
g_signal_connect_swapped (manager, "source-added", G_CALLBACK (sources_added_cb), application);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_application_class_init (GcalApplicationClass *klass)
|
gcal_application_class_init (GcalApplicationClass *klass)
|
||||||
{
|
{
|
||||||
@@ -240,9 +256,6 @@ gcal_application_finalize (GObject *object)
|
|||||||
if (priv->initial_date != NULL)
|
if (priv->initial_date != NULL)
|
||||||
g_free (priv->initial_date);
|
g_free (priv->initial_date);
|
||||||
|
|
||||||
if (priv->css_code_snippets != NULL)
|
|
||||||
g_strfreev (priv->css_code_snippets);
|
|
||||||
|
|
||||||
if (priv->provider != NULL)
|
if (priv->provider != NULL)
|
||||||
{
|
{
|
||||||
gtk_style_context_remove_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (priv->colors_provider));
|
gtk_style_context_remove_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (priv->colors_provider));
|
||||||
|
|||||||
Reference in New Issue
Block a user