manager: use EDS selectable property to track disabled agendas

This way, we can keep GNOME Calendar and Evolution synchronized.
And we can save some code too.
This commit is contained in:
Georges Basile Stavracas Neto
2017-03-17 21:25:23 -03:00
parent 95e293beed
commit 2544773645
8 changed files with 52 additions and 97 deletions
-5
View File
@@ -21,10 +21,5 @@
<_summary>Type of the active view</_summary> <_summary>Type of the active view</_summary>
<_description>Type of the active window view, default value is: monthly view</_description> <_description>Type of the active window view, default value is: monthly view</_description>
</key> </key>
<key name="disabled-sources" type="as">
<default>[]</default>
<_summary>List of the disabled sources</_summary>
<_description>Sources disabled last time Calendar ran</_description>
</key>
</schema> </schema>
</schemalist> </schemalist>
+22 -79
View File
@@ -44,8 +44,6 @@ typedef struct
typedef struct typedef struct
{ {
ECalClient *client; ECalClient *client;
gboolean enabled;
gboolean connected; gboolean connected;
} GcalManagerUnit; } GcalManagerUnit;
@@ -84,7 +82,6 @@ struct _GcalManager
/* state flags */ /* state flags */
gboolean goa_client_ready; gboolean goa_client_ready;
gchar **disabled_sources;
gint sources_at_launch; gint sources_at_launch;
/* timezone */ /* timezone */
@@ -299,7 +296,7 @@ on_client_readonly_changed (EClient *client,
source = e_client_get_source (client); source = e_client_get_source (client);
unit = g_hash_table_lookup (manager->clients, source); unit = g_hash_table_lookup (manager->clients, source);
if (unit && unit->enabled) if (unit && is_source_enabled (source))
source_changed (manager, source); source_changed (manager, source);
GCAL_EXIT; GCAL_EXIT;
@@ -340,11 +337,13 @@ on_client_connected (GObject *source_object,
ECalClient *client; ECalClient *client;
ESource *source; ESource *source;
GError *error; GError *error;
gboolean enabled;
GCAL_ENTRY; GCAL_ENTRY;
manager = GCAL_MANAGER (user_data); manager = GCAL_MANAGER (user_data);
source = e_client_get_source (E_CLIENT (source_object)); source = e_client_get_source (E_CLIENT (source_object));
enabled = is_source_enabled (source);
manager->sources_at_launch--; manager->sources_at_launch--;
@@ -380,14 +379,8 @@ on_client_connected (GObject *source_object,
/* notify the readonly property */ /* notify the readonly property */
g_signal_connect (client, "notify::readonly", G_CALLBACK (on_client_readonly_changed), user_data); g_signal_connect (client, "notify::readonly", G_CALLBACK (on_client_readonly_changed), user_data);
if (g_strv_contains ((const gchar * const *) manager->disabled_sources, e_source_get_uid (source))) if (enabled)
{ {
unit->enabled = FALSE;
}
else
{
unit->enabled = TRUE;
e_cal_data_model_add_client (manager->e_data_model, client); e_cal_data_model_add_client (manager->e_data_model, client);
e_cal_data_model_add_client (manager->search_data_model, client); e_cal_data_model_add_client (manager->search_data_model, client);
if (manager->shell_search_data_model != NULL) if (manager->shell_search_data_model != NULL)
@@ -395,10 +388,8 @@ on_client_connected (GObject *source_object,
} }
/* refresh client when it's added */ /* refresh client when it's added */
if (unit->enabled && e_client_check_refresh_supported (E_CLIENT (client))) if (enabled && e_client_check_refresh_supported (E_CLIENT (client)))
{
e_client_refresh (E_CLIENT (client), NULL, on_client_refreshed, user_data); e_client_refresh (E_CLIENT (client), NULL, on_client_refreshed, user_data);
}
/* Cache all the online calendars, so the user can see them offline */ /* Cache all the online calendars, so the user can see them offline */
offline_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_OFFLINE); offline_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_OFFLINE);
@@ -410,7 +401,7 @@ on_client_connected (GObject *source_object,
NULL, NULL,
NULL); NULL);
g_signal_emit (GCAL_MANAGER (user_data), signals[SOURCE_ADDED], 0, source, unit->enabled); g_signal_emit (GCAL_MANAGER (user_data), signals[SOURCE_ADDED], 0, source, enabled);
g_clear_object (&client); g_clear_object (&client);
@@ -776,8 +767,6 @@ gcal_manager_constructed (GObject *object)
G_OBJECT_CLASS (gcal_manager_parent_class)->constructed (object); G_OBJECT_CLASS (gcal_manager_parent_class)->constructed (object);
manager = GCAL_MANAGER (object); manager = GCAL_MANAGER (object);
manager->disabled_sources = g_settings_get_strv (manager->settings, "disabled-sources");
manager->system_timezone = e_cal_util_get_system_timezone (); manager->system_timezone = e_cal_util_get_system_timezone ();
manager->clients = g_hash_table_new_full ((GHashFunc) e_source_hash, (GEqualFunc) e_source_equal, manager->clients = g_hash_table_new_full ((GHashFunc) e_source_hash, (GEqualFunc) e_source_equal,
@@ -905,8 +894,6 @@ gcal_manager_finalize (GObject *object)
g_clear_object (&manager->search_data_model); g_clear_object (&manager->search_data_model);
g_clear_object (&manager->shell_search_data_model); g_clear_object (&manager->shell_search_data_model);
g_strfreev (manager->disabled_sources);
if (manager->search_view_data != NULL) if (manager->search_view_data != NULL)
{ {
g_free (manager->search_view_data->query); g_free (manager->search_view_data->query);
@@ -1143,7 +1130,7 @@ gcal_manager_get_sources (GcalManager *manager)
{ {
GcalManagerUnit *unit = value; GcalManagerUnit *unit = value;
if (!unit->enabled) if (!is_source_enabled (key))
continue; continue;
aux = g_list_append (aux, key); aux = g_list_append (aux, key);
@@ -1235,7 +1222,7 @@ gcal_manager_set_shell_search_query (GcalManager *manager,
manager->search_view_data->passed_start = FALSE; manager->search_view_data->passed_start = FALSE;
manager->search_view_data->search_done = FALSE; manager->search_view_data->search_done = FALSE;
manager->search_view_data->sources_left = g_hash_table_size (manager->clients) - g_strv_length (manager->disabled_sources); manager->search_view_data->sources_left = g_hash_table_size (manager->clients);
if (manager->search_view_data->query != NULL) if (manager->search_view_data->query != NULL)
g_free (manager->search_view_data->query); g_free (manager->search_view_data->query);
@@ -1435,48 +1422,32 @@ void
gcal_manager_enable_source (GcalManager *manager, gcal_manager_enable_source (GcalManager *manager,
ESource *source) ESource *source)
{ {
ESourceSelectable *selectable;
GcalManagerUnit *unit; GcalManagerUnit *unit;
gchar **new_disabled_sources;
guint i;
GCAL_ENTRY; GCAL_ENTRY;
unit = g_hash_table_lookup (manager->clients, source); unit = g_hash_table_lookup (manager->clients, source);
selectable = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
if (unit->enabled) if (is_source_enabled (source))
{ {
g_debug ("Source '%s' already enabled", e_source_get_uid (source)); g_debug ("Source '%s' already enabled", e_source_get_uid (source));
GCAL_EXIT; GCAL_EXIT;
return; return;
} }
unit->enabled = TRUE;
e_cal_data_model_add_client (manager->e_data_model, unit->client); e_cal_data_model_add_client (manager->e_data_model, unit->client);
e_cal_data_model_add_client (manager->search_data_model, unit->client); e_cal_data_model_add_client (manager->search_data_model, unit->client);
if (manager->shell_search_data_model != NULL)
if (manager->shell_search_data_model)
e_cal_data_model_add_client (manager->shell_search_data_model, unit->client); e_cal_data_model_add_client (manager->shell_search_data_model, unit->client);
/* remove source's uid from disabled_sources array */
new_disabled_sources = g_new0 (gchar*, g_strv_length (manager->disabled_sources));
for (i = 0; i < g_strv_length (manager->disabled_sources); i++)
{
if (g_strcmp0 (manager->disabled_sources[i], e_source_get_uid (source)) == 0)
continue;
new_disabled_sources[i] = g_strdup (manager->disabled_sources[i]);
}
g_strfreev (manager->disabled_sources);
manager->disabled_sources = new_disabled_sources;
g_signal_emit (manager, signals[SOURCE_ENABLED], 0, source, TRUE); g_signal_emit (manager, signals[SOURCE_ENABLED], 0, source, TRUE);
/* sync settings value */ /* Save the source */
g_settings_set_strv (manager->settings, e_source_selectable_set_selected (selectable, TRUE);
"disabled-sources", gcal_manager_save_source (manager, source);
(const gchar * const *) manager->disabled_sources);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -1492,16 +1463,16 @@ void
gcal_manager_disable_source (GcalManager *manager, gcal_manager_disable_source (GcalManager *manager,
ESource *source) ESource *source)
{ {
ESourceSelectable *selectable;
GcalManagerUnit *unit; GcalManagerUnit *unit;
gchar **new_disabled_sources;
guint i;
const gchar *source_uid; const gchar *source_uid;
GCAL_ENTRY; GCAL_ENTRY;
unit = g_hash_table_lookup (manager->clients, source); unit = g_hash_table_lookup (manager->clients, source);
selectable = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
if (!unit->enabled) if (!is_source_enabled (source))
{ {
g_debug ("Source '%s' already disabled", e_source_get_uid (source)); g_debug ("Source '%s' already disabled", e_source_get_uid (source));
GCAL_EXIT; GCAL_EXIT;
@@ -1510,29 +1481,17 @@ gcal_manager_disable_source (GcalManager *manager,
source_uid = e_source_get_uid (source); source_uid = e_source_get_uid (source);
unit->enabled = FALSE;
e_cal_data_model_remove_client (manager->e_data_model, source_uid); e_cal_data_model_remove_client (manager->e_data_model, source_uid);
e_cal_data_model_remove_client (manager->search_data_model, source_uid); e_cal_data_model_remove_client (manager->search_data_model, source_uid);
if (manager->shell_search_data_model != NULL) if (manager->shell_search_data_model != NULL)
e_cal_data_model_remove_client (manager->shell_search_data_model, source_uid); e_cal_data_model_remove_client (manager->shell_search_data_model, source_uid);
/* add source's uid from disabled_sources array */
new_disabled_sources = g_new0 (gchar*, g_strv_length (manager->disabled_sources) + 2);
for (i = 0; i < g_strv_length (manager->disabled_sources); i++)
new_disabled_sources[i] = g_strdup (manager->disabled_sources[i]);
new_disabled_sources[g_strv_length (manager->disabled_sources)] = g_strdup (source_uid);
g_strfreev (manager->disabled_sources);
manager->disabled_sources = new_disabled_sources;
g_signal_emit (manager, signals[SOURCE_ENABLED], 0, source, FALSE); g_signal_emit (manager, signals[SOURCE_ENABLED], 0, source, FALSE);
/* sync settings value */ /* Save the source */
g_settings_set_strv (manager->settings, "disabled-sources", (const gchar * const *) manager->disabled_sources); e_source_selectable_set_selected (selectable, FALSE);
gcal_manager_save_source (manager, source);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -1564,22 +1523,6 @@ gcal_manager_save_source (GcalManager *manager,
GCAL_EXIT; GCAL_EXIT;
} }
gboolean
gcal_manager_source_enabled (GcalManager *manager,
ESource *source)
{
GcalManagerUnit *unit;
GCAL_ENTRY;
unit = g_hash_table_lookup (manager->clients, source);
if (!unit)
GCAL_RETURN (FALSE);
GCAL_RETURN (unit->enabled);
}
void void
gcal_manager_refresh (GcalManager *manager) gcal_manager_refresh (GcalManager *manager)
{ {
-3
View File
@@ -97,9 +97,6 @@ void gcal_manager_disable_source (GcalManager
void gcal_manager_save_source (GcalManager *manager, void gcal_manager_save_source (GcalManager *manager,
ESource *source); ESource *source);
gboolean gcal_manager_source_enabled (GcalManager *manager,
ESource *source);
GList* gcal_manager_get_events (GcalManager *manager, GList* gcal_manager_get_events (GcalManager *manager,
icaltimetype *range_start, icaltimetype *range_start,
icaltimetype *range_end); icaltimetype *range_end);
+1 -1
View File
@@ -364,7 +364,7 @@ on_source_changed (GcalManager *manager,
{ {
on_source_added (self->manager, on_source_added (self->manager,
source, source,
gcal_manager_source_enabled (self->manager, source), is_source_enabled (source),
self); self);
row = get_row_for_source (self, source); row = get_row_for_source (self, source);
+10 -6
View File
@@ -942,7 +942,7 @@ stack_visible_child_name_changed (GObject *object,
// enabled check // enabled check
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->calendar_visible_check), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->calendar_visible_check),
gcal_manager_source_enabled (self->manager, self->source)); is_source_enabled (self->source));
/* default source check button */ /* default source check button */
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->default_check), (self->source == default_source)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->default_check), (self->source == default_source));
@@ -1684,8 +1684,10 @@ notification_child_revealed_changed (GtkWidget *notification,
{ {
g_warning ("[source-dialog] Error removing source: %s", error->message); g_warning ("[source-dialog] Error removing source: %s", error->message);
add_source (self->manager, self->removed_source, add_source (self->manager,
gcal_manager_source_enabled (self->manager, self->removed_source), user_data); self->removed_source,
is_source_enabled (self->removed_source),
user_data);
gcal_manager_enable_source (self->manager, self->removed_source); gcal_manager_enable_source (self->manager, self->removed_source);
@@ -1713,8 +1715,10 @@ undo_remove_action (GtkButton *button,
// Enable the source before adding it again // Enable the source before adding it again
gcal_manager_enable_source (self->manager, self->removed_source); gcal_manager_enable_source (self->manager, self->removed_source);
add_source (self->manager, self->removed_source, add_source (self->manager,
gcal_manager_source_enabled (self->manager, self->removed_source), user_data); self->removed_source,
is_source_enabled (self->removed_source),
user_data);
/* /*
* Don't clear the pointer, since we don't * Don't clear the pointer, since we don't
@@ -2200,7 +2204,7 @@ gcal_source_dialog_set_manager (GcalSourceDialog *dialog,
sources = gcal_manager_get_sources_connected (dialog->manager); sources = gcal_manager_get_sources_connected (dialog->manager);
for (l = sources; l != NULL; l = l->next) for (l = sources; l != NULL; l = l->next)
add_source (dialog->manager, l->data, gcal_manager_source_enabled (dialog->manager, l->data), dialog); add_source (dialog->manager, l->data, is_source_enabled (l->data), dialog);
} }
else else
{ {
+12
View File
@@ -924,3 +924,15 @@ should_change_date_for_scroll (gdouble *scroll_value,
return FALSE; return FALSE;
} }
gboolean
is_source_enabled (ESource *source)
{
ESourceSelectable *selectable;
g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
selectable = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR);
return e_source_selectable_get_selected (selectable);
}
+2
View File
@@ -138,4 +138,6 @@ gint get_alarm_trigger_minutes (GcalEvent
gboolean should_change_date_for_scroll (gdouble *scroll_value, gboolean should_change_date_for_scroll (gdouble *scroll_value,
GdkEventScroll *scroll_event); GdkEventScroll *scroll_event);
gboolean is_source_enabled (ESource *source);
#endif // __GCAL_UTILS_H__ #endif // __GCAL_UTILS_H__
+5 -3
View File
@@ -806,7 +806,7 @@ make_row_from_source (GcalWindow *window,
/* checkbox */ /* checkbox */
checkbox = gtk_check_button_new (); checkbox = gtk_check_button_new ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), gcal_manager_source_enabled (window->manager, source)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), is_source_enabled (source));
g_signal_connect (checkbox, "notify::active", G_CALLBACK (on_calendar_toggled), window); g_signal_connect (checkbox, "notify::active", G_CALLBACK (on_calendar_toggled), window);
gtk_container_add (GTK_CONTAINER (box), icon); gtk_container_add (GTK_CONTAINER (box), icon);
@@ -926,7 +926,7 @@ source_changed (GcalWindow *window,
if (child_source != NULL && child_source == source) if (child_source != NULL && child_source == source)
{ {
gtk_widget_destroy (aux->data); gtk_widget_destroy (aux->data);
add_source (window->manager, source, gcal_manager_source_enabled (window->manager, source), window); add_source (window->manager, source, is_source_enabled (source), window);
break; break;
} }
} }
@@ -1256,9 +1256,11 @@ gcal_window_constructed (GObject *object)
if (!gcal_manager_get_loading (window->manager)) if (!gcal_manager_get_loading (window->manager))
{ {
GList *sources, *l; GList *sources, *l;
sources = gcal_manager_get_sources_connected (window->manager); sources = gcal_manager_get_sources_connected (window->manager);
for (l = sources; l != NULL; l = g_list_next (l)) for (l = sources; l != NULL; l = g_list_next (l))
add_source (window->manager, l->data, gcal_manager_source_enabled (window->manager, l->data), object); add_source (window->manager, l->data, is_source_enabled (l->data), object);
g_list_free (sources); g_list_free (sources);
} }