search: Use g_auto for variables
This commit is contained in:
parent
d2959e4fe7
commit
58a64323c4
2 changed files with 89 additions and 167 deletions
|
@ -87,35 +87,24 @@ place_free (Place * p)
|
||||||
g_slice_free (Place, p);
|
g_slice_free (Place, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Place, place_free)
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
get_bookmarks (void)
|
get_bookmarks (void)
|
||||||
{
|
{
|
||||||
GFile *file;
|
g_autoptr(GFile) file = NULL;
|
||||||
gchar *contents;
|
g_autofree gchar *contents = NULL;
|
||||||
gchar *path;
|
g_autofree gchar *path = NULL;
|
||||||
gchar **lines;
|
GList *bookmarks = NULL;
|
||||||
GList *bookmarks;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
path = g_build_filename (g_get_user_config_dir (), "gtk-3.0",
|
path = g_build_filename (g_get_user_config_dir (), "gtk-3.0",
|
||||||
"bookmarks", NULL);
|
"bookmarks", NULL);
|
||||||
file = g_file_new_for_path (path);
|
file = g_file_new_for_path (path);
|
||||||
g_free (path);
|
if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
|
||||||
|
|
||||||
contents = NULL;
|
|
||||||
g_file_load_contents (file, NULL, &contents, NULL, NULL, &error);
|
|
||||||
g_object_unref (file);
|
|
||||||
|
|
||||||
bookmarks = NULL;
|
|
||||||
lines = NULL;
|
|
||||||
|
|
||||||
if (error != NULL)
|
|
||||||
{
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
gint idx;
|
gint idx;
|
||||||
|
g_auto(GStrv) lines = NULL;
|
||||||
|
|
||||||
lines = g_strsplit (contents, "\n", -1);
|
lines = g_strsplit (contents, "\n", -1);
|
||||||
for (idx = 0; lines[idx]; idx++)
|
for (idx = 0; lines[idx]; idx++)
|
||||||
|
@ -151,9 +140,6 @@ get_bookmarks (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (lines);
|
|
||||||
g_free (contents);
|
|
||||||
|
|
||||||
return g_list_reverse (bookmarks);
|
return g_list_reverse (bookmarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +245,7 @@ path_from_tracker_dir (const gchar *value)
|
||||||
static GList *
|
static GList *
|
||||||
get_tracker_locations (void)
|
get_tracker_locations (void)
|
||||||
{
|
{
|
||||||
gchar **locations;
|
g_auto(GStrv) locations = NULL;
|
||||||
GList *list;
|
GList *list;
|
||||||
gint idx;
|
gint idx;
|
||||||
Place *location;
|
Place *location;
|
||||||
|
@ -280,16 +266,17 @@ get_tracker_locations (void)
|
||||||
list = g_list_prepend (list, location);
|
list = g_list_prepend (list, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (locations);
|
|
||||||
|
|
||||||
return g_list_reverse (list);
|
return g_list_reverse (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
get_places_list (void)
|
get_places_list (void)
|
||||||
{
|
{
|
||||||
GList *list, *l;
|
g_autoptr(GList) xdg_list = NULL;
|
||||||
GHashTable *places;
|
g_autoptr(GList) tracker_list = NULL;
|
||||||
|
g_autoptr(GList) bookmark_list = NULL;
|
||||||
|
GList *l;
|
||||||
|
g_autoptr(GHashTable) places = NULL;
|
||||||
Place *place, *old_place;
|
Place *place, *old_place;
|
||||||
GList *places_list;
|
GList *places_list;
|
||||||
|
|
||||||
|
@ -303,53 +290,45 @@ get_places_list (void)
|
||||||
g_hash_table_insert (places, place->location, place);
|
g_hash_table_insert (places, place->location, place);
|
||||||
|
|
||||||
/* first, load the XDG dirs */
|
/* first, load the XDG dirs */
|
||||||
list = get_xdg_dirs ();
|
xdg_list = get_xdg_dirs ();
|
||||||
for (l = list; l != NULL; l = l->next)
|
for (l = xdg_list; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
place = l->data;
|
place = l->data;
|
||||||
g_hash_table_insert (places, place->location, place);
|
g_hash_table_insert (places, place->location, place);
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
/* then, insert all the tracker locations that are not XDG dirs */
|
/* then, insert all the tracker locations that are not XDG dirs */
|
||||||
list = get_tracker_locations ();
|
tracker_list = get_tracker_locations ();
|
||||||
for (l = list; l != NULL; l = l->next)
|
for (l = tracker_list; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
place = l->data;
|
g_autoptr(Place) p = l->data;
|
||||||
old_place = g_hash_table_lookup (places, place->location);
|
old_place = g_hash_table_lookup (places, p->location);
|
||||||
if (old_place == NULL)
|
if (old_place == NULL)
|
||||||
g_hash_table_insert (places, place->location, place);
|
g_hash_table_insert (places, p->location, g_steal_pointer (&p));
|
||||||
else
|
|
||||||
place_free (place);
|
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
/* finally, load bookmarks, and possibly update attributes */
|
/* finally, load bookmarks, and possibly update attributes */
|
||||||
list = get_bookmarks ();
|
bookmark_list = get_bookmarks ();
|
||||||
for (l = list; l != NULL; l = l->next)
|
for (l = bookmark_list; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
place = l->data;
|
g_autoptr(Place) p = l->data;
|
||||||
old_place = g_hash_table_lookup (places, place->location);
|
old_place = g_hash_table_lookup (places, p->location);
|
||||||
if (old_place == NULL)
|
if (old_place == NULL)
|
||||||
{
|
{
|
||||||
g_hash_table_insert (places, place->location, place);
|
g_hash_table_insert (places, p->location, g_steal_pointer (&p));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_free (old_place->display_name);
|
g_free (old_place->display_name);
|
||||||
old_place->display_name = g_strdup (place->display_name);
|
old_place->display_name = g_strdup (p->display_name);
|
||||||
|
|
||||||
if (old_place->place_type == PLACE_OTHER)
|
if (old_place->place_type == PLACE_OTHER)
|
||||||
old_place->place_type = PLACE_BOOKMARKS;
|
old_place->place_type = PLACE_BOOKMARKS;
|
||||||
|
|
||||||
place_free (place);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
places_list = g_hash_table_get_values (places);
|
places_list = g_hash_table_get_values (places);
|
||||||
g_hash_table_steal_all (places);
|
g_hash_table_steal_all (places);
|
||||||
g_hash_table_unref (places);
|
|
||||||
|
|
||||||
return places_list;
|
return places_list;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +339,7 @@ switch_tracker_get_mapping (GValue *value,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
Place *place = user_data;
|
Place *place = user_data;
|
||||||
const gchar **locations;
|
g_autofree const gchar **locations = NULL;
|
||||||
GFile *location;
|
GFile *location;
|
||||||
gint idx;
|
gint idx;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
@ -377,8 +356,6 @@ switch_tracker_get_mapping (GValue *value,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (locations);
|
|
||||||
|
|
||||||
g_value_set_boolean (value, found);
|
g_value_set_boolean (value, found);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -387,8 +364,8 @@ static GPtrArray *
|
||||||
place_get_new_settings_values (Place *place,
|
place_get_new_settings_values (Place *place,
|
||||||
gboolean remove)
|
gboolean remove)
|
||||||
{
|
{
|
||||||
gchar **values;
|
g_auto(GStrv) values = NULL;
|
||||||
gchar *path;
|
g_autofree gchar *path = NULL;
|
||||||
GPtrArray *new_values;
|
GPtrArray *new_values;
|
||||||
const gchar *tracker_dir;
|
const gchar *tracker_dir;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
@ -419,9 +396,6 @@ place_get_new_settings_values (Place *place,
|
||||||
|
|
||||||
g_ptr_array_add (new_values, NULL);
|
g_ptr_array_add (new_values, NULL);
|
||||||
|
|
||||||
g_strfreev (values);
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
return new_values;
|
return new_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,17 +405,12 @@ switch_tracker_set_mapping (const GValue *value,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
Place *place = user_data;
|
Place *place = user_data;
|
||||||
GPtrArray *new_values;
|
g_autoptr(GPtrArray) new_values = NULL;
|
||||||
gboolean remove;
|
gboolean remove;
|
||||||
GVariant *variant;
|
|
||||||
|
|
||||||
remove = !g_value_get_boolean (value);
|
remove = !g_value_get_boolean (value);
|
||||||
new_values = place_get_new_settings_values (place, remove);
|
new_values = place_get_new_settings_values (place, remove);
|
||||||
variant = g_variant_new_strv ((const gchar **) new_values->pdata, -1);
|
return g_variant_new_strv ((const gchar **) new_values->pdata, -1);
|
||||||
|
|
||||||
g_ptr_array_unref (new_values);
|
|
||||||
|
|
||||||
return variant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -451,8 +420,8 @@ place_query_info_ready (GObject *source,
|
||||||
{
|
{
|
||||||
GtkWidget *row, *box, *w;
|
GtkWidget *row, *box, *w;
|
||||||
Place *place;
|
Place *place;
|
||||||
GFileInfo *info;
|
g_autoptr(GFileInfo) info = NULL;
|
||||||
gchar *path;
|
g_autofree gchar *path = NULL;
|
||||||
|
|
||||||
info = g_file_query_info_finish (G_FILE (source), res, NULL);
|
info = g_file_query_info_finish (G_FILE (source), res, NULL);
|
||||||
if (!info)
|
if (!info)
|
||||||
|
@ -470,8 +439,6 @@ place_query_info_ready (GObject *source,
|
||||||
else
|
else
|
||||||
place->settings_key = TRACKER_KEY_RECURSIVE_DIRECTORIES;
|
place->settings_key = TRACKER_KEY_RECURSIVE_DIRECTORIES;
|
||||||
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
w = gtk_label_new (place->display_name);
|
w = gtk_label_new (place->display_name);
|
||||||
gtk_container_add (GTK_CONTAINER (box), w);
|
gtk_container_add (GTK_CONTAINER (box), w);
|
||||||
|
|
||||||
|
@ -486,7 +453,6 @@ place_query_info_ready (GObject *source,
|
||||||
place, NULL);
|
place, NULL);
|
||||||
|
|
||||||
gtk_widget_show_all (row);
|
gtk_widget_show_all (row);
|
||||||
g_object_unref (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -494,14 +460,12 @@ remove_button_clicked (GtkWidget *widget,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkWidget *row = user_data;
|
GtkWidget *row = user_data;
|
||||||
GPtrArray *new_values;
|
g_autoptr(GPtrArray) new_values = NULL;
|
||||||
Place *place;
|
Place *place;
|
||||||
|
|
||||||
place = g_object_get_data (G_OBJECT (row), "place");
|
place = g_object_get_data (G_OBJECT (row), "place");
|
||||||
new_values = place_get_new_settings_values (place, TRUE);
|
new_values = place_get_new_settings_values (place, TRUE);
|
||||||
g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);
|
g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);
|
||||||
|
|
||||||
g_ptr_array_unref (new_values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -511,7 +475,7 @@ place_compare_func (gconstpointer a,
|
||||||
{
|
{
|
||||||
GtkWidget *child_a, *child_b;
|
GtkWidget *child_a, *child_b;
|
||||||
Place *place_a, *place_b;
|
Place *place_a, *place_b;
|
||||||
gchar *path;
|
g_autofree gchar *path = NULL;
|
||||||
gboolean is_home;
|
gboolean is_home;
|
||||||
|
|
||||||
child_a = GTK_WIDGET (a);
|
child_a = GTK_WIDGET (a);
|
||||||
|
@ -522,7 +486,6 @@ place_compare_func (gconstpointer a,
|
||||||
|
|
||||||
path = g_file_get_path (place_a->location);
|
path = g_file_get_path (place_a->location);
|
||||||
is_home = (g_strcmp0 (path, g_get_home_dir ()) == 0);
|
is_home = (g_strcmp0 (path, g_get_home_dir ()) == 0);
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
if (is_home)
|
if (is_home)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -573,7 +536,8 @@ create_row_for_place (Place *place)
|
||||||
static void
|
static void
|
||||||
populate_list_boxes (CcSearchLocationsDialog *self)
|
populate_list_boxes (CcSearchLocationsDialog *self)
|
||||||
{
|
{
|
||||||
GList *places, *l;
|
g_autoptr(GList) places = NULL;
|
||||||
|
GList *l;
|
||||||
Place *place;
|
Place *place;
|
||||||
GtkWidget *row;
|
GtkWidget *row;
|
||||||
|
|
||||||
|
@ -598,8 +562,6 @@ populate_list_boxes (CcSearchLocationsDialog *self)
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (places);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -607,8 +569,8 @@ add_file_chooser_response (GtkDialog *widget,
|
||||||
GtkResponseType response,
|
GtkResponseType response,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
Place *place;
|
g_autoptr(Place) place = NULL;
|
||||||
GPtrArray *new_values;
|
g_autoptr(GPtrArray) new_values = NULL;
|
||||||
|
|
||||||
if (response != GTK_RESPONSE_OK)
|
if (response != GTK_RESPONSE_OK)
|
||||||
{
|
{
|
||||||
|
@ -624,9 +586,7 @@ add_file_chooser_response (GtkDialog *widget,
|
||||||
new_values = place_get_new_settings_values (place, FALSE);
|
new_values = place_get_new_settings_values (place, FALSE);
|
||||||
g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);
|
g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);
|
||||||
|
|
||||||
g_ptr_array_unref (new_values);
|
|
||||||
gtk_widget_destroy (GTK_WIDGET (widget));
|
gtk_widget_destroy (GTK_WIDGET (widget));
|
||||||
place_free (place);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -651,7 +611,8 @@ add_button_clicked (GtkWidget *widget,
|
||||||
static void
|
static void
|
||||||
other_places_refresh (CcSearchLocationsDialog *self)
|
other_places_refresh (CcSearchLocationsDialog *self)
|
||||||
{
|
{
|
||||||
GList *places, *l;
|
g_autoptr(GList) places = NULL;
|
||||||
|
GList *l;
|
||||||
Place *place;
|
Place *place;
|
||||||
GtkWidget *row;
|
GtkWidget *row;
|
||||||
|
|
||||||
|
@ -667,8 +628,6 @@ other_places_refresh (CcSearchLocationsDialog *self)
|
||||||
row = create_row_for_place (place);
|
row = create_row_for_place (place);
|
||||||
gtk_container_add (GTK_CONTAINER (self->others_list), row);
|
gtk_container_add (GTK_CONTAINER (self->others_list), row);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (places);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CcSearchLocationsDialog *
|
CcSearchLocationsDialog *
|
||||||
|
@ -701,18 +660,14 @@ gboolean
|
||||||
cc_search_locations_dialog_is_available (void)
|
cc_search_locations_dialog_is_available (void)
|
||||||
{
|
{
|
||||||
GSettingsSchemaSource *source;
|
GSettingsSchemaSource *source;
|
||||||
GSettingsSchema *schema;
|
g_autoptr(GSettingsSchema) schema = NULL;
|
||||||
|
|
||||||
source = g_settings_schema_source_get_default ();
|
source = g_settings_schema_source_get_default ();
|
||||||
if (!source)
|
if (!source)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
schema = g_settings_schema_source_lookup (source, TRACKER_SCHEMA, TRUE);
|
schema = g_settings_schema_source_lookup (source, TRACKER_SCHEMA, TRUE);
|
||||||
if (!schema)
|
return schema != NULL;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
g_settings_schema_unref (schema);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -96,7 +96,7 @@ list_sort_func (gconstpointer a,
|
||||||
static void
|
static void
|
||||||
search_panel_invalidate_button_state (CcSearchPanel *self)
|
search_panel_invalidate_button_state (CcSearchPanel *self)
|
||||||
{
|
{
|
||||||
GList *children;
|
g_autoptr(GList) children = NULL;
|
||||||
gboolean is_first, is_last;
|
gboolean is_first, is_last;
|
||||||
GtkListBoxRow *row;
|
GtkListBoxRow *row;
|
||||||
|
|
||||||
|
@ -111,14 +111,12 @@ search_panel_invalidate_button_state (CcSearchPanel *self)
|
||||||
|
|
||||||
gtk_widget_set_sensitive (self->up_button, !is_first);
|
gtk_widget_set_sensitive (self->up_button, !is_first);
|
||||||
gtk_widget_set_sensitive (self->down_button, !is_last);
|
gtk_widget_set_sensitive (self->down_button, !is_last);
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
search_panel_invalidate_sort_order (CcSearchPanel *self)
|
search_panel_invalidate_sort_order (CcSearchPanel *self)
|
||||||
{
|
{
|
||||||
gchar **sort_order;
|
g_auto(GStrv) sort_order = NULL;
|
||||||
gint idx;
|
gint idx;
|
||||||
|
|
||||||
g_hash_table_remove_all (self->sort_order);
|
g_hash_table_remove_all (self->sort_order);
|
||||||
|
@ -128,7 +126,6 @@ search_panel_invalidate_sort_order (CcSearchPanel *self)
|
||||||
g_hash_table_insert (self->sort_order, g_strdup (sort_order[idx]), GINT_TO_POINTER (idx + 1));
|
g_hash_table_insert (self->sort_order, g_strdup (sort_order[idx]), GINT_TO_POINTER (idx + 1));
|
||||||
|
|
||||||
gtk_list_box_invalidate_sort (GTK_LIST_BOX (self->list_box));
|
gtk_list_box_invalidate_sort (GTK_LIST_BOX (self->list_box));
|
||||||
g_strfreev (sort_order);
|
|
||||||
|
|
||||||
search_panel_invalidate_button_state (self);
|
search_panel_invalidate_button_state (self);
|
||||||
}
|
}
|
||||||
|
@ -151,8 +148,9 @@ propagate_compare_func (gconstpointer a,
|
||||||
static void
|
static void
|
||||||
search_panel_propagate_sort_order (CcSearchPanel *self)
|
search_panel_propagate_sort_order (CcSearchPanel *self)
|
||||||
{
|
{
|
||||||
GList *keys, *l;
|
g_autoptr(GList) keys = NULL;
|
||||||
GPtrArray *sort_order;
|
GList *l;
|
||||||
|
g_autoptr(GPtrArray) sort_order = NULL;
|
||||||
|
|
||||||
sort_order = g_ptr_array_new ();
|
sort_order = g_ptr_array_new ();
|
||||||
keys = g_hash_table_get_keys (self->sort_order);
|
keys = g_hash_table_get_keys (self->sort_order);
|
||||||
|
@ -164,9 +162,6 @@ search_panel_propagate_sort_order (CcSearchPanel *self)
|
||||||
g_ptr_array_add (sort_order, NULL);
|
g_ptr_array_add (sort_order, NULL);
|
||||||
g_settings_set_strv (self->search_settings, "sort-order",
|
g_settings_set_strv (self->search_settings, "sort-order",
|
||||||
(const gchar **) sort_order->pdata);
|
(const gchar **) sort_order->pdata);
|
||||||
|
|
||||||
g_ptr_array_unref (sort_order);
|
|
||||||
g_list_free (keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -194,7 +189,8 @@ search_panel_move_selected (CcSearchPanel *self,
|
||||||
gint idx, other_idx;
|
gint idx, other_idx;
|
||||||
gpointer idx_ptr;
|
gpointer idx_ptr;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
GList *children, *l, *other;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l, *other;
|
||||||
|
|
||||||
row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->list_box));
|
row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->list_box));
|
||||||
app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
||||||
|
@ -288,8 +284,6 @@ search_panel_move_selected (CcSearchPanel *self,
|
||||||
g_hash_table_replace (self->sort_order, g_strdup (app_id), GINT_TO_POINTER (idx));
|
g_hash_table_replace (self->sort_order, g_strdup (app_id), GINT_TO_POINTER (idx));
|
||||||
|
|
||||||
search_panel_propagate_sort_order (self);
|
search_panel_propagate_sort_order (self);
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -330,11 +324,10 @@ switch_settings_mapping_set_generic (const GValue *value,
|
||||||
{
|
{
|
||||||
CcSearchPanel *self = g_object_get_data (G_OBJECT (row), "self");
|
CcSearchPanel *self = g_object_get_data (G_OBJECT (row), "self");
|
||||||
GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
||||||
gchar **apps;
|
g_auto(GStrv) apps = NULL;
|
||||||
GPtrArray *new_apps;
|
g_autoptr(GPtrArray) new_apps = NULL;
|
||||||
gint idx;
|
gint idx;
|
||||||
gboolean remove, found;
|
gboolean remove, found;
|
||||||
GVariant *variant;
|
|
||||||
|
|
||||||
remove = !!g_value_get_boolean (value) == !!default_enabled;
|
remove = !!g_value_get_boolean (value) == !!default_enabled;
|
||||||
found = FALSE;
|
found = FALSE;
|
||||||
|
@ -360,11 +353,7 @@ switch_settings_mapping_set_generic (const GValue *value,
|
||||||
|
|
||||||
g_ptr_array_add (new_apps, NULL);
|
g_ptr_array_add (new_apps, NULL);
|
||||||
|
|
||||||
variant = g_variant_new_strv ((const gchar **) new_apps->pdata, -1);
|
return g_variant_new_strv ((const gchar **) new_apps->pdata, -1);
|
||||||
g_ptr_array_unref (new_apps);
|
|
||||||
g_strfreev (apps);
|
|
||||||
|
|
||||||
return variant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GVariant *
|
static GVariant *
|
||||||
|
@ -392,7 +381,7 @@ switch_settings_mapping_get_generic (GValue *value,
|
||||||
gboolean default_enabled)
|
gboolean default_enabled)
|
||||||
{
|
{
|
||||||
GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info");
|
||||||
const gchar **apps;
|
g_autofree const gchar **apps = NULL;
|
||||||
gint idx;
|
gint idx;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
|
||||||
|
@ -408,7 +397,6 @@ switch_settings_mapping_get_generic (GValue *value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (apps);
|
|
||||||
g_value_set_boolean (value, !!default_enabled != !!found);
|
g_value_set_boolean (value, !!default_enabled != !!found);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -438,7 +426,7 @@ search_panel_add_one_app_info (CcSearchPanel *self,
|
||||||
gboolean default_enabled)
|
gboolean default_enabled)
|
||||||
{
|
{
|
||||||
GtkWidget *row, *box, *w;
|
GtkWidget *row, *box, *w;
|
||||||
GIcon *icon;
|
g_autoptr(GIcon) icon = NULL;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
|
|
||||||
/* gnome-control-center is special cased in the shell,
|
/* gnome-control-center is special cased in the shell,
|
||||||
|
@ -470,7 +458,6 @@ search_panel_add_one_app_info (CcSearchPanel *self,
|
||||||
gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &width, &height);
|
gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &width, &height);
|
||||||
gtk_image_set_pixel_size (GTK_IMAGE (w), MAX (width, height));
|
gtk_image_set_pixel_size (GTK_IMAGE (w), MAX (width, height));
|
||||||
gtk_container_add (GTK_CONTAINER (box), w);
|
gtk_container_add (GTK_CONTAINER (box), w);
|
||||||
g_object_unref (icon);
|
|
||||||
|
|
||||||
w = gtk_label_new (g_app_info_get_name (app_info));
|
w = gtk_label_new (g_app_info_get_name (app_info));
|
||||||
gtk_container_add (GTK_CONTAINER (box), w);
|
gtk_container_add (GTK_CONTAINER (box), w);
|
||||||
|
@ -505,10 +492,11 @@ static void
|
||||||
search_panel_add_one_provider (CcSearchPanel *self,
|
search_panel_add_one_provider (CcSearchPanel *self,
|
||||||
GFile *provider)
|
GFile *provider)
|
||||||
{
|
{
|
||||||
gchar *path, *desktop_id;
|
g_autofree gchar *path = NULL;
|
||||||
GKeyFile *keyfile;
|
g_autofree gchar *desktop_id = NULL;
|
||||||
GAppInfo *app_info;
|
g_autoptr(GKeyFile) keyfile = NULL;
|
||||||
GError *error = NULL;
|
g_autoptr(GAppInfo) app_info = NULL;
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
gboolean default_disabled;
|
gboolean default_disabled;
|
||||||
|
|
||||||
path = g_file_get_path (provider);
|
path = g_file_get_path (provider);
|
||||||
|
@ -519,13 +507,13 @@ search_panel_add_one_provider (CcSearchPanel *self,
|
||||||
{
|
{
|
||||||
g_warning ("Error loading %s: %s - search provider will be ignored",
|
g_warning ("Error loading %s: %s - search provider will be ignored",
|
||||||
path, error->message);
|
path, error->message);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_key_file_has_group (keyfile, SHELL_PROVIDER_GROUP))
|
if (!g_key_file_has_group (keyfile, SHELL_PROVIDER_GROUP))
|
||||||
{
|
{
|
||||||
g_debug ("Shell search provider group missing from '%s', ignoring", path);
|
g_debug ("Shell search provider group missing from '%s', ignoring", path);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_id = g_key_file_get_string (keyfile, SHELL_PROVIDER_GROUP,
|
desktop_id = g_key_file_get_string (keyfile, SHELL_PROVIDER_GROUP,
|
||||||
|
@ -535,7 +523,7 @@ search_panel_add_one_provider (CcSearchPanel *self,
|
||||||
{
|
{
|
||||||
g_warning ("Unable to read desktop ID from %s: %s - search provider will be ignored",
|
g_warning ("Unable to read desktop ID from %s: %s - search provider will be ignored",
|
||||||
path, error->message);
|
path, error->message);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_info = G_APP_INFO (g_desktop_app_info_new (desktop_id));
|
app_info = G_APP_INFO (g_desktop_app_info_new (desktop_id));
|
||||||
|
@ -544,20 +532,12 @@ search_panel_add_one_provider (CcSearchPanel *self,
|
||||||
{
|
{
|
||||||
g_debug ("Could not find application with desktop ID '%s' referenced in '%s', ignoring",
|
g_debug ("Could not find application with desktop ID '%s' referenced in '%s', ignoring",
|
||||||
desktop_id, path);
|
desktop_id, path);
|
||||||
g_free (desktop_id);
|
return;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (desktop_id);
|
|
||||||
default_disabled = g_key_file_get_boolean (keyfile, SHELL_PROVIDER_GROUP,
|
default_disabled = g_key_file_get_boolean (keyfile, SHELL_PROVIDER_GROUP,
|
||||||
"DefaultDisabled", NULL);
|
"DefaultDisabled", NULL);
|
||||||
search_panel_add_one_app_info (self, app_info, !default_disabled);
|
search_panel_add_one_app_info (self, app_info, !default_disabled);
|
||||||
g_object_unref (app_info);
|
|
||||||
|
|
||||||
out:
|
|
||||||
g_free (path);
|
|
||||||
g_clear_error (&error);
|
|
||||||
g_key_file_unref (keyfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -565,18 +545,15 @@ search_providers_discover_ready (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GList *providers, *l;
|
g_autoptr(GList) providers = NULL;
|
||||||
GFile *provider;
|
GList *l;
|
||||||
CcSearchPanel *self = CC_SEARCH_PANEL (source);
|
CcSearchPanel *self = CC_SEARCH_PANEL (source);
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
providers = g_task_propagate_pointer (G_TASK (result), &error);
|
providers = g_task_propagate_pointer (G_TASK (result), &error);
|
||||||
|
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
{
|
return;
|
||||||
g_error_free (error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_clear_object (&self->load_cancellable);
|
g_clear_object (&self->load_cancellable);
|
||||||
|
|
||||||
|
@ -588,16 +565,14 @@ search_providers_discover_ready (GObject *source,
|
||||||
|
|
||||||
for (l = providers; l != NULL; l = l->next)
|
for (l = providers; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
provider = l->data;
|
g_autoptr(GFile) provider = l->data;
|
||||||
search_panel_add_one_provider (self, provider);
|
search_panel_add_one_provider (self, provider);
|
||||||
g_object_unref (provider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* propagate a write to GSettings, to make sure we always have
|
/* propagate a write to GSettings, to make sure we always have
|
||||||
* all the providers in the list.
|
* all the providers in the list.
|
||||||
*/
|
*/
|
||||||
search_panel_propagate_sort_order (self);
|
search_panel_propagate_sort_order (self);
|
||||||
g_list_free (providers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
|
@ -605,11 +580,10 @@ search_providers_discover_one_directory (const gchar *system_dir,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
GList *providers = NULL;
|
GList *providers = NULL;
|
||||||
gchar *providers_path;
|
g_autofree gchar *providers_path = NULL;
|
||||||
GFile *providers_location, *provider;
|
g_autoptr(GFile) providers_location = NULL;
|
||||||
GFileInfo *info;
|
g_autoptr(GFileEnumerator) enumerator = NULL;
|
||||||
GFileEnumerator *enumerator;
|
g_autoptr(GError) error = NULL;
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
providers_path = g_build_filename (system_dir, "gnome-shell", "search-providers", NULL);
|
providers_path = g_build_filename (system_dir, "gnome-shell", "search-providers", NULL);
|
||||||
providers_location = g_file_new_for_path (providers_path);
|
providers_location = g_file_new_for_path (providers_path);
|
||||||
|
@ -625,32 +599,26 @@ search_providers_discover_one_directory (const gchar *system_dir,
|
||||||
!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
g_warning ("Error opening %s: %s - search provider configuration won't be possible",
|
g_warning ("Error opening %s: %s - search provider configuration won't be possible",
|
||||||
providers_path, error->message);
|
providers_path, error->message);
|
||||||
g_clear_error (&error);
|
|
||||||
|
|
||||||
goto out;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((info = g_file_enumerator_next_file (enumerator, cancellable, &error)) != NULL)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
|
g_autoptr(GFileInfo) info = NULL;
|
||||||
|
GFile *provider;
|
||||||
|
|
||||||
|
info = g_file_enumerator_next_file (enumerator, cancellable, &error);
|
||||||
|
if (info == NULL)
|
||||||
|
{
|
||||||
|
if (error != NULL && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
|
g_warning ("Error reading from %s: %s - search providers might be missing from the panel",
|
||||||
|
providers_path, error->message);
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
provider = g_file_get_child (providers_location, g_file_info_get_name (info));
|
provider = g_file_get_child (providers_location, g_file_info_get_name (info));
|
||||||
providers = g_list_prepend (providers, provider);
|
providers = g_list_prepend (providers, provider);
|
||||||
g_object_unref (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != NULL)
|
|
||||||
{
|
|
||||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
||||||
g_warning ("Error reading from %s: %s - search providers might be missing from the panel",
|
|
||||||
providers_path, error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
g_clear_object (&enumerator);
|
|
||||||
g_clear_object (&providers_location);
|
|
||||||
g_free (providers_path);
|
|
||||||
|
|
||||||
return providers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -682,13 +650,12 @@ search_providers_discover_thread (GTask *task,
|
||||||
static void
|
static void
|
||||||
populate_search_providers (CcSearchPanel *self)
|
populate_search_providers (CcSearchPanel *self)
|
||||||
{
|
{
|
||||||
GTask *task;
|
g_autoptr(GTask) task = NULL;
|
||||||
|
|
||||||
self->load_cancellable = g_cancellable_new ();
|
self->load_cancellable = g_cancellable_new ();
|
||||||
task = g_task_new (self, self->load_cancellable,
|
task = g_task_new (self, self->load_cancellable,
|
||||||
search_providers_discover_ready, self);
|
search_providers_discover_ready, self);
|
||||||
g_task_run_in_thread (task, search_providers_discover_thread);
|
g_task_run_in_thread (task, search_providers_discover_thread);
|
||||||
g_object_unref (task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue