diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-01-30 12:10:32 -0200 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-01-30 12:10:32 -0200 |
commit | b8f56f39d018172ef70fb7b8aa4dcabb226c688f (patch) | |
tree | d7529c6974844ce0fae12e37ccc75add138585d4 /search-provider | |
parent | e227bb8aff228db27062773b5c58ecfa4c9c7f8f (diff) | |
download | gnome-control-center-b8f56f39d018172ef70fb7b8aa4dcabb226c688f.tar.gz |
search-provider: Simplify code by using g_auto*
Diffstat (limited to 'search-provider')
-rw-r--r-- | search-provider/cc-search-provider.c | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/search-provider/cc-search-provider.c b/search-provider/cc-search-provider.c index e6a1ef890..49df7f48f 100644 --- a/search-provider/cc-search-provider.c +++ b/search-provider/cc-search-provider.c @@ -97,11 +97,11 @@ get_model (void) static gchar ** get_results (gchar **terms) { + g_auto(GStrv) casefolded_terms = NULL; GtkTreeModel *model = get_model (); GtkTreeIter iter; GPtrArray *results; gboolean ok; - gchar **casefolded_terms; casefolded_terms = get_casefolded_terms (terms); results = g_ptr_array_new (); @@ -122,7 +122,6 @@ get_results (gchar **terms) } g_ptr_array_add (results, NULL); - g_strfreev (casefolded_terms); return (char**) g_ptr_array_free (results, FALSE); } @@ -133,11 +132,10 @@ handle_get_initial_result_set (CcShellSearchProvider2 *skeleton, char **terms, CcSearchProvider *self) { - gchar **results = get_results (terms); + g_auto(GStrv) results = get_results (terms); cc_shell_search_provider2_complete_get_initial_result_set (skeleton, invocation, (const char* const*) results); - g_strfreev (results); return TRUE; } @@ -155,11 +153,10 @@ handle_get_subsearch_result_set (CcShellSearchProvider2 *skeleton, * in the model is always small enough that we don't need to worry * about this taking too long. */ - gchar **results = get_results (terms); + g_auto(GStrv) results = get_results (terms); cc_shell_search_provider2_complete_get_subsearch_result_set (skeleton, invocation, (const char* const*) results); - g_strfreev (results); return TRUE; } @@ -207,15 +204,18 @@ handle_get_result_metas (CcShellSearchProvider2 *skeleton, GtkTreeIter *iter; int i; GVariantBuilder builder; - GAppInfo *app; const char *id; - char *name, *description, *escaped_description; - GIcon *icon; g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}")); for (i = 0; results[i]; i++) { + g_autofree gchar *escaped_description = NULL; + g_autofree gchar *description = NULL; + g_autofree gchar *name = NULL; + g_autoptr(GAppInfo) app = NULL; + g_autoptr(GIcon) icon = NULL; + iter = get_iter_for_result (self, results[i]); if (!iter) continue; @@ -239,12 +239,6 @@ handle_get_result_metas (CcShellSearchProvider2 *skeleton, g_variant_builder_add (&builder, "{sv}", "description", g_variant_new_string (escaped_description)); g_variant_builder_close (&builder); - - g_free (name); - g_free (description); - g_free (escaped_description); - g_object_unref (app); - g_object_unref (icon); } cc_shell_search_provider2_complete_get_result_metas (skeleton, @@ -262,24 +256,19 @@ handle_activate_result (CcShellSearchProvider2 *skeleton, CcSearchProvider *self) { GdkAppLaunchContext *launch_context; + g_autoptr(GError) error = NULL; GAppInfo *app; - GError *error; launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ()); gdk_app_launch_context_set_timestamp (launch_context, timestamp); app = G_APP_INFO (g_desktop_app_info_new (identifier)); - error = NULL; if (!g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) - { - g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); - } + g_dbus_method_invocation_return_gerror (invocation, error); else - { - cc_shell_search_provider2_complete_activate_result (skeleton, invocation); - } + cc_shell_search_provider2_complete_activate_result (skeleton, invocation); + return TRUE; } @@ -291,36 +280,30 @@ handle_launch_search (CcShellSearchProvider2 *skeleton, CcSearchProvider *self) { GdkAppLaunchContext *launch_context; + g_autoptr(GError) error = NULL; char *joined_terms, *command_line; GAppInfo *app; - GError *error; launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ()); gdk_app_launch_context_set_timestamp (launch_context, timestamp); joined_terms = g_strjoinv (" ", terms); command_line = g_strdup_printf ("gnome-control-center -s '%s'", joined_terms); - - error = NULL; app = g_app_info_create_from_commandline (command_line, "gnome-control-center.desktop", G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION, &error); - if (!app) { + if (!app) + { g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); return TRUE; - } + } if (!g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) - { - g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); - } + g_dbus_method_invocation_return_gerror (invocation, error); else - { - cc_shell_search_provider2_complete_launch_search (skeleton, invocation); - } + cc_shell_search_provider2_complete_launch_search (skeleton, invocation); + return TRUE; } |