manager: avoid deep nesting
Use an early return rather than deep nesting to improve the code legibility. https://bugzilla.gnome.org/show_bug.cgi?id=764623
This commit is contained in:
+15
-19
@@ -340,13 +340,11 @@ on_client_connected (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalManagerUnit *unit;
|
||||
GcalManager *manager;
|
||||
ECalClient *client;
|
||||
GError *error;
|
||||
|
||||
ESource *source;
|
||||
|
||||
GcalManagerUnit *unit;
|
||||
GError *error;
|
||||
|
||||
manager = GCAL_MANAGER (user_data);
|
||||
source = e_client_get_source (E_CLIENT (source_object));
|
||||
@@ -357,8 +355,20 @@ on_client_connected (GObject *source_object,
|
||||
|
||||
error = NULL;
|
||||
client = E_CAL_CLIENT (e_cal_client_connect_finish (result, &error));
|
||||
if (error == NULL)
|
||||
|
||||
if (error)
|
||||
{
|
||||
remove_source (GCAL_MANAGER (user_data), source);
|
||||
g_warning ("%s: Failed to open/connect '%s': %s",
|
||||
G_STRFUNC,
|
||||
e_source_get_display_name (source),
|
||||
error->message);
|
||||
|
||||
g_object_unref (source);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
unit = g_new0 (GcalManagerUnit, 1);
|
||||
unit->connected = TRUE;
|
||||
unit->client = g_object_ref (client);
|
||||
@@ -395,20 +405,6 @@ on_client_connected (GObject *source_object,
|
||||
g_signal_emit (GCAL_MANAGER (user_data), signals[SOURCE_ADDED], 0, source, unit->enabled);
|
||||
|
||||
g_clear_object (&client);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* in any other case, remove it*/
|
||||
remove_source (GCAL_MANAGER (user_data), source);
|
||||
g_warning ("%s: Failed to open/connect '%s': %s",
|
||||
G_STRFUNC,
|
||||
e_source_get_display_name (source),
|
||||
error->message);
|
||||
|
||||
g_object_unref (source);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user