diff --git a/panels/search/cc-search-locations-dialog.c b/panels/search/cc-search-locations-page.c similarity index 90% rename from panels/search/cc-search-locations-dialog.c rename to panels/search/cc-search-locations-page.c index ab73aca2574723dcc4ee2c0c2ce0abdeb41b877c..5bc8d616802cac44b4ffbf18f3b03892d1a2f856 100644 --- a/panels/search/cc-search-locations-dialog.c +++ b/panels/search/cc-search-locations-page.c @@ -18,7 +18,7 @@ * Author: Cosimo Cecchi */ -#include "cc-search-locations-dialog.h" +#include "cc-search-locations-page.h" #include @@ -34,7 +34,7 @@ typedef enum { } PlaceType; typedef struct { - CcSearchLocationsDialog *dialog; + CcSearchLocationsPage *page; GFile *location; gchar *display_name; PlaceType place_type; @@ -42,8 +42,8 @@ typedef struct { const gchar *settings_key; } Place; -struct _CcSearchLocationsDialog { - AdwWindow parent; +struct _CcSearchLocationsPage { + AdwNavigationPage parent; GSettings *tracker_preferences; @@ -55,16 +55,12 @@ struct _CcSearchLocationsDialog { GtkWidget *locations_add; }; -struct _CcSearchLocationsDialogClass { - AdwPreferencesWindowClass parent_class; -}; - -G_DEFINE_TYPE (CcSearchLocationsDialog, cc_search_locations_dialog, ADW_TYPE_WINDOW) +G_DEFINE_TYPE (CcSearchLocationsPage, cc_search_locations_page, ADW_TYPE_NAVIGATION_PAGE) static const gchar *path_from_tracker_dir (const gchar *value); static gboolean -keynav_failed_cb (CcSearchLocationsDialog *self, +keynav_failed_cb (CcSearchLocationsPage *self, GtkDirectionType direction) { GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self))); @@ -80,19 +76,47 @@ keynav_failed_cb (CcSearchLocationsDialog *self, } static void -cc_search_locations_dialog_finalize (GObject *object) +cc_search_locations_page_finalize (GObject *object) { - CcSearchLocationsDialog *self = CC_SEARCH_LOCATIONS_DIALOG (object); + CcSearchLocationsPage *self = CC_SEARCH_LOCATIONS_PAGE (object); g_clear_object (&self->tracker_preferences); - G_OBJECT_CLASS (cc_search_locations_dialog_parent_class)->finalize (object); + G_OBJECT_CLASS (cc_search_locations_page_parent_class)->finalize (object); } +static void other_places_refresh (CcSearchLocationsPage *self); +static void populate_list_boxes (CcSearchLocationsPage *self); +static gint place_compare_func (gconstpointer a, gconstpointer b, gpointer user_data); + static void -cc_search_locations_dialog_init (CcSearchLocationsDialog *self) +cc_search_locations_page_init (CcSearchLocationsPage *self) { + GSettingsSchemaSource *source; + g_autoptr(GSettingsSchema) schema = NULL; + gtk_widget_init_template (GTK_WIDGET (self)); + + source = g_settings_schema_source_get_default (); + schema = g_settings_schema_source_lookup (source, TRACKER3_SCHEMA, TRUE); + if (schema) + self->tracker_preferences = g_settings_new (TRACKER3_SCHEMA); + else + self->tracker_preferences = g_settings_new (TRACKER_SCHEMA); + + populate_list_boxes (self); + + gtk_list_box_set_sort_func (GTK_LIST_BOX (self->places_list), + (GtkListBoxSortFunc) place_compare_func, NULL, NULL); + gtk_list_box_set_sort_func (GTK_LIST_BOX (self->bookmarks_list), + (GtkListBoxSortFunc) place_compare_func, NULL, NULL); + gtk_list_box_set_sort_func (GTK_LIST_BOX (self->others_list), + (GtkListBoxSortFunc) place_compare_func, NULL, NULL); + + g_signal_connect_swapped (self->tracker_preferences, "changed::" TRACKER_KEY_RECURSIVE_DIRECTORIES, + G_CALLBACK (other_places_refresh), self); + g_signal_connect_swapped (self->tracker_preferences, "changed::" TRACKER_KEY_SINGLE_DIRECTORIES, + G_CALLBACK (other_places_refresh), self); } static gboolean @@ -120,7 +144,7 @@ location_in_path_strv (GFile *location, } static Place * -place_new (CcSearchLocationsDialog *dialog, +place_new (CcSearchLocationsPage *page, GFile *location, gchar *display_name, PlaceType place_type) @@ -130,12 +154,12 @@ place_new (CcSearchLocationsDialog *dialog, g_autofree const char **single_dir_default = NULL; g_auto(GStrv) single_dir = NULL; - single_dir_default_var = g_settings_get_default_value (dialog->tracker_preferences, + single_dir_default_var = g_settings_get_default_value (page->tracker_preferences, TRACKER_KEY_SINGLE_DIRECTORIES); single_dir_default = g_variant_get_strv (single_dir_default_var, NULL); - single_dir = g_settings_get_strv (dialog->tracker_preferences, TRACKER_KEY_SINGLE_DIRECTORIES); + single_dir = g_settings_get_strv (page->tracker_preferences, TRACKER_KEY_SINGLE_DIRECTORIES); - new_place->dialog = dialog; + new_place->page = page; new_place->location = location; if (display_name != NULL) new_place->display_name = display_name; @@ -167,7 +191,7 @@ place_free (Place * p) G_DEFINE_AUTOPTR_CLEANUP_FUNC (Place, place_free) static GList * -get_bookmarks (CcSearchLocationsDialog *self) +get_bookmarks (CcSearchLocationsPage *self) { g_autoptr(GFile) file = NULL; g_autofree gchar *contents = NULL; @@ -227,7 +251,7 @@ get_user_special_dir_if_not_home (GUserDirectory idx) } static GList * -get_xdg_dirs (CcSearchLocationsDialog *self) +get_xdg_dirs (CcSearchLocationsPage *self) { GList *xdg_dirs = NULL; gint idx; @@ -315,7 +339,7 @@ path_from_tracker_dir (const gchar *value) } static GPtrArray * -place_get_new_settings_values (CcSearchLocationsDialog *self, +place_get_new_settings_values (CcSearchLocationsPage *self, Place *place, gboolean remove) { @@ -356,7 +380,7 @@ place_get_new_settings_values (CcSearchLocationsDialog *self, static GList * -get_tracker_locations (CcSearchLocationsDialog *self) +get_tracker_locations (CcSearchLocationsPage *self) { g_auto(GStrv) locations_single = NULL; g_auto(GStrv) locations = NULL; @@ -394,7 +418,7 @@ get_tracker_locations (CcSearchLocationsDialog *self) } static GList * -get_places_list (CcSearchLocationsDialog *self) +get_places_list (CcSearchLocationsPage *self) { g_autoptr(GList) xdg_list = NULL; g_autoptr(GList) tracker_list = NULL; @@ -487,7 +511,7 @@ switch_tracker_set_mapping (const GValue *value, gboolean remove; remove = !g_value_get_boolean (value); - new_values = place_get_new_settings_values (place->dialog, place, remove); + new_values = place_get_new_settings_values (place->page, place, remove); return g_variant_new_strv ((const gchar **) new_values->pdata, -1); } @@ -511,7 +535,7 @@ place_query_info_ready (GObject *source, } static void -remove_button_clicked (CcSearchLocationsDialog *self, +remove_button_clicked (CcSearchLocationsPage *self, GtkWidget *button) { g_autoptr(GPtrArray) new_values = NULL; @@ -550,7 +574,7 @@ place_compare_func (gconstpointer a, } static GtkWidget * -create_row_for_place (CcSearchLocationsDialog *self, Place *place) +create_row_for_place (CcSearchLocationsPage *self, Place *place) { AdwActionRow *row; GtkWidget *index_switch, *remove_button; @@ -586,7 +610,7 @@ create_row_for_place (CcSearchLocationsDialog *self, Place *place) adw_action_row_add_suffix (row, index_switch); adw_action_row_set_activatable_widget (row, index_switch); - g_settings_bind_with_mapping (place->dialog->tracker_preferences, place->settings_key, + g_settings_bind_with_mapping (place->page->tracker_preferences, place->settings_key, index_switch, "active", G_SETTINGS_BIND_DEFAULT, switch_tracker_get_mapping, @@ -603,7 +627,7 @@ create_row_for_place (CcSearchLocationsDialog *self, Place *place) } static void -update_list_visibility (CcSearchLocationsDialog *self) +update_list_visibility (CcSearchLocationsPage *self) { gtk_widget_set_visible (self->places_group, gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->places_list), 0) @@ -614,7 +638,7 @@ update_list_visibility (CcSearchLocationsDialog *self) } static void -populate_list_boxes (CcSearchLocationsDialog *self) +populate_list_boxes (CcSearchLocationsPage *self) { g_autoptr(GList) places = NULL; GList *l; @@ -651,7 +675,7 @@ add_file_chooser_response (GObject *source, GAsyncResult *res, gpointer user_data) { - CcSearchLocationsDialog *self = CC_SEARCH_LOCATIONS_DIALOG (user_data); + CcSearchLocationsPage *self = CC_SEARCH_LOCATIONS_PAGE (user_data); GtkFileDialog *file_dialog = GTK_FILE_DIALOG (source); g_autoptr(Place) place = NULL; g_autoptr(GPtrArray) new_values = NULL; @@ -675,22 +699,23 @@ add_file_chooser_response (GObject *source, } static void -add_button_clicked (CcSearchLocationsDialog *self) +add_button_clicked (CcSearchLocationsPage *self) { GtkFileDialog *file_dialog; + GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self))); file_dialog = gtk_file_dialog_new (); gtk_file_dialog_set_title (file_dialog, _("Select Location")); gtk_file_dialog_set_modal (file_dialog, TRUE); - gtk_file_dialog_select_folder (file_dialog, GTK_WINDOW (self), + gtk_file_dialog_select_folder (file_dialog, GTK_WINDOW (toplevel), NULL, add_file_chooser_response, self); } static void -other_places_refresh (CcSearchLocationsDialog *self) +other_places_refresh (CcSearchLocationsPage *self) { g_autoptr(GList) places = NULL; GList *l; @@ -716,41 +741,8 @@ other_places_refresh (CcSearchLocationsDialog *self) update_list_visibility (self); } -CcSearchLocationsDialog * -cc_search_locations_dialog_new (void) -{ - CcSearchLocationsDialog *self; - GSettingsSchemaSource *source; - g_autoptr(GSettingsSchema) schema = NULL; - - self = g_object_new (CC_SEARCH_LOCATIONS_DIALOG_TYPE, NULL); - - source = g_settings_schema_source_get_default (); - schema = g_settings_schema_source_lookup (source, TRACKER3_SCHEMA, TRUE); - if (schema) - self->tracker_preferences = g_settings_new (TRACKER3_SCHEMA); - else - self->tracker_preferences = g_settings_new (TRACKER_SCHEMA); - - populate_list_boxes (self); - - gtk_list_box_set_sort_func (GTK_LIST_BOX (self->places_list), - (GtkListBoxSortFunc) place_compare_func, NULL, NULL); - gtk_list_box_set_sort_func (GTK_LIST_BOX (self->bookmarks_list), - (GtkListBoxSortFunc) place_compare_func, NULL, NULL); - gtk_list_box_set_sort_func (GTK_LIST_BOX (self->others_list), - (GtkListBoxSortFunc) place_compare_func, NULL, NULL); - - g_signal_connect_swapped (self->tracker_preferences, "changed::" TRACKER_KEY_RECURSIVE_DIRECTORIES, - G_CALLBACK (other_places_refresh), self); - g_signal_connect_swapped (self->tracker_preferences, "changed::" TRACKER_KEY_SINGLE_DIRECTORIES, - G_CALLBACK (other_places_refresh), self); - - return self; -} - gboolean -cc_search_locations_dialog_is_available (void) +cc_search_locations_page_is_available (void) { GSettingsSchemaSource *source; g_autoptr(GSettingsSchema) schema = NULL; @@ -771,25 +763,23 @@ cc_search_locations_dialog_is_available (void) } static void -cc_search_locations_dialog_class_init (CcSearchLocationsDialogClass *klass) +cc_search_locations_page_class_init (CcSearchLocationsPageClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = cc_search_locations_dialog_finalize; + object_class->finalize = cc_search_locations_page_finalize; gtk_widget_class_set_template_from_resource (widget_class, - "/org/gnome/control-center/search/cc-search-locations-dialog.ui"); + "/org/gnome/control-center/search/cc-search-locations-page.ui"); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, places_group); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, places_list); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, bookmarks_group); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, bookmarks_list); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, others_list); - gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsDialog, locations_add); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, places_group); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, places_list); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, bookmarks_group); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, bookmarks_list); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, others_list); + gtk_widget_class_bind_template_child (widget_class, CcSearchLocationsPage, locations_add); gtk_widget_class_bind_template_callback (widget_class, add_button_clicked); gtk_widget_class_bind_template_callback (widget_class, keynav_failed_cb); - - gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL); } diff --git a/panels/search/cc-search-locations-dialog.h b/panels/search/cc-search-locations-page.h similarity index 72% rename from panels/search/cc-search-locations-dialog.h rename to panels/search/cc-search-locations-page.h index 9f47514ad22f60980564e48bdb0389fccede0bc3..6339028bb35b52f99a98c1aa8e49e052183c2e6f 100644 --- a/panels/search/cc-search-locations-dialog.h +++ b/panels/search/cc-search-locations-page.h @@ -22,9 +22,7 @@ #include -#define CC_SEARCH_LOCATIONS_DIALOG_TYPE (cc_search_locations_dialog_get_type ()) -G_DECLARE_FINAL_TYPE (CcSearchLocationsDialog, cc_search_locations_dialog, CC, SEARCH_LOCATIONS_DIALOG, AdwWindow) +#define CC_TYPE_SEARCH_LOCATIONS_PAGE (cc_search_locations_page_get_type ()) +G_DECLARE_FINAL_TYPE (CcSearchLocationsPage, cc_search_locations_page, CC, SEARCH_LOCATIONS_PAGE, AdwNavigationPage) -CcSearchLocationsDialog *cc_search_locations_dialog_new (void); - -gboolean cc_search_locations_dialog_is_available (void); +gboolean cc_search_locations_page_is_available (void); diff --git a/panels/search/cc-search-locations-dialog.ui b/panels/search/cc-search-locations-page.ui similarity index 86% rename from panels/search/cc-search-locations-dialog.ui rename to panels/search/cc-search-locations-page.ui index 143bfec796c8c047cdc85ab8cd8a70b574381334..ff391664159018fca80f63f0cf37e41f1fc6db09 100644 --- a/panels/search/cc-search-locations-dialog.ui +++ b/panels/search/cc-search-locations-page.ui @@ -1,15 +1,9 @@ - -