LCOV - code coverage report
Current view: top level - src/plugins/gnome - valent-preferences-sync-page.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 48.9 % 282 138
Test Date: 2025-04-18 23:22:27 Functions: 48.0 % 25 12
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16.2 % 130 21

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-device-preferences-dialog"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <glib/gi18n-lib.h>
       9                 :             : #include <adwaita.h>
      10                 :             : #include <gtk/gtk.h>
      11                 :             : #include <valent.h>
      12                 :             : 
      13                 :             : #include "valent-preferences-sync-page.h"
      14                 :             : 
      15                 :             : 
      16                 :             : struct _ValentPreferencesSyncPage
      17                 :             : {
      18                 :             :   ValentPreferencesPage  parent_instance;
      19                 :             : 
      20                 :             :   GHashTable            *local_stores;
      21                 :             : 
      22                 :             :   /* template */
      23                 :             :   GtkSwitch             *sync_pull;
      24                 :             :   GtkSwitch             *sync_push;
      25                 :             : 
      26                 :             :   AdwExpanderRow        *local_sync;
      27                 :             :   GtkListBox            *local_list;
      28                 :             :   GtkSwitch             *remote_sync;
      29                 :             : 
      30                 :             :   AdwExpanderRow        *forward_notifications;
      31                 :             :   GtkSwitch             *forward_when_active;
      32                 :             :   AdwNavigationPage     *application_page;
      33                 :             :   GtkStack              *application_title_stack;
      34                 :             :   GtkToggleButton       *application_filter_button;
      35                 :             :   GtkSearchEntry        *application_filter_entry;
      36                 :             :   AdwActionRow          *application_row;
      37                 :             :   GtkListBox            *application_list;
      38                 :             :   char                  *application_filter;
      39                 :             :   GHashTable            *application_rows;
      40                 :             : 
      41                 :             :   GtkSwitch             *auto_mount;
      42                 :             :   AdwExpanderRow        *local_allow;
      43                 :             :   GtkAdjustment         *local_port;
      44                 :             : };
      45                 :             : 
      46   [ +  +  +  - ]:          42 : G_DEFINE_FINAL_TYPE (ValentPreferencesSyncPage, valent_preferences_sync_page, VALENT_TYPE_PREFERENCES_PAGE)
      47                 :             : 
      48                 :             : /*
      49                 :             :  * Contacts
      50                 :             :  */
      51                 :             : static void
      52                 :           0 : on_local_sync (GtkListBox            *box,
      53                 :             :                GtkListBoxRow         *row,
      54                 :             :                ValentPreferencesPage *page)
      55                 :             : {
      56                 :           0 :   GSettings *settings;
      57                 :           0 :   g_autofree char *local_uid = NULL;
      58                 :           0 :   const char *uid;
      59                 :             : 
      60   [ #  #  #  #  :           0 :   g_assert (GTK_IS_LIST_BOX (box));
             #  #  #  # ]
      61   [ #  #  #  #  :           0 :   g_assert (GTK_IS_LIST_BOX_ROW (row));
             #  #  #  # ]
      62         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_PAGE (page));
      63                 :             : 
      64                 :           0 :   settings = valent_preferences_page_get_settings (page, "contacts");
      65                 :           0 :   local_uid = g_settings_get_string (settings, "local-uid");
      66                 :           0 :   uid = gtk_widget_get_name (GTK_WIDGET (row));
      67                 :             : 
      68         [ #  # ]:           0 :   if (g_strcmp0 (local_uid, uid) == 0)
      69                 :           0 :     g_settings_reset (settings, "local-uid");
      70                 :             :   else
      71                 :           0 :     g_settings_set_string (settings, "local-uid", uid);
      72                 :             : 
      73                 :           0 :   gtk_list_box_invalidate_filter (box);
      74                 :           0 : }
      75                 :             : 
      76                 :             : static void
      77                 :           0 : on_adapter_selected (AdwActionRow          *row,
      78                 :             :                      ValentPreferencesPage *page)
      79                 :             : {
      80                 :           0 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (page);
      81                 :           0 :   GSettings *settings;
      82                 :           0 :   GHashTableIter iter;
      83                 :           0 :   ValentContactsAdapter *adapter;
      84                 :           0 :   gpointer store_row;
      85                 :             : 
      86         [ #  # ]:           0 :   g_assert (ADW_IS_ACTION_ROW (row));
      87         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_PAGE (page));
      88                 :             : 
      89                 :           0 :   settings = valent_preferences_page_get_settings (page, "contacts");
      90                 :             : 
      91                 :           0 :   g_hash_table_iter_init (&iter, self->local_stores);
      92         [ #  # ]:           0 :   while (g_hash_table_iter_next (&iter, (void **)&adapter, &store_row))
      93                 :             :     {
      94                 :           0 :       GtkWidget *check = g_object_get_data (G_OBJECT (store_row), "select");
      95                 :             : 
      96         [ #  # ]:           0 :       if (row == store_row)
      97                 :             :         {
      98                 :           0 :           const char *iri = valent_resource_get_iri (VALENT_RESOURCE (self));
      99         [ #  # ]:           0 :           g_settings_set_string (settings, "local-uid", iri != NULL ? iri : "");
     100                 :             :         }
     101                 :             : 
     102                 :           0 :       gtk_widget_set_visible (check, (row == store_row));
     103                 :             :     }
     104                 :           0 : }
     105                 :             : 
     106                 :             : static GtkWidget *
     107                 :           3 : valent_contacts_preferences_create_row_func (gpointer item,
     108                 :             :                                              gpointer user_data)
     109                 :             : {
     110                 :           3 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (user_data);
     111                 :           3 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (user_data);
     112                 :           3 :   ValentContactsAdapter *adapter = VALENT_CONTACTS_ADAPTER (item);
     113                 :           3 :   GSettings *settings;
     114                 :           3 :   GtkWidget *row;
     115                 :           3 :   GtkWidget *image;
     116                 :           3 :   const char *iri = NULL;
     117                 :           6 :   g_autofree char *local_iri = NULL;
     118                 :             : 
     119         [ +  - ]:           3 :   g_assert (VALENT_IS_CONTACTS_ADAPTER (adapter));
     120         [ -  + ]:           3 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     121                 :             : 
     122                 :           3 :   iri = valent_resource_get_iri (VALENT_RESOURCE (adapter));
     123                 :           3 :   row = g_object_new (ADW_TYPE_ACTION_ROW,
     124                 :             :                       "activatable", TRUE,
     125                 :             :                       "title",       iri,
     126                 :             :                       NULL);
     127                 :           3 :   image = g_object_new (GTK_TYPE_IMAGE,
     128                 :             :                         "icon-name", "x-office-address-book",
     129                 :             :                         "icon-size", GTK_ICON_SIZE_NORMAL,
     130                 :             :                         NULL);
     131                 :           3 :   adw_action_row_add_prefix (ADW_ACTION_ROW (row), image);
     132                 :             : 
     133                 :           3 :   g_signal_connect_object (G_OBJECT (row),
     134                 :             :                            "activated",
     135                 :             :                            G_CALLBACK (on_adapter_selected),
     136                 :             :                            self, 0);
     137                 :             : 
     138                 :           3 :   settings = valent_preferences_page_get_settings (page, "contacts");
     139                 :           3 :   local_iri = g_settings_get_string (settings, "local-uid");
     140                 :           3 :   image = g_object_new (GTK_TYPE_IMAGE,
     141                 :             :                         "icon-name", "object-select-symbolic",
     142                 :             :                         "icon-size", GTK_ICON_SIZE_NORMAL,
     143                 :           3 :                         "visible",   (g_strcmp0 (local_iri, iri) == 0),
     144                 :             :                         NULL);
     145                 :           3 :   adw_action_row_add_suffix (ADW_ACTION_ROW (row), image);
     146                 :           3 :   g_object_set_data (G_OBJECT (row), "select", image);
     147                 :             : 
     148                 :           3 :   return row;
     149                 :             : }
     150                 :             : 
     151                 :             : static GtkListBox *
     152                 :           3 : _adw_expander_row_get_list (AdwExpanderRow *row)
     153                 :             : {
     154                 :           3 :   GtkWidget *box;
     155                 :           3 :   GtkWidget *child;
     156                 :             : 
     157                 :             :   /* First child is a GtkBox */
     158                 :           3 :   box = gtk_widget_get_first_child (GTK_WIDGET (row));
     159                 :             : 
     160                 :             :   /* The GtkBox contains the primary AdwActionRow and a GtkRevealer */
     161                 :           3 :   for (child = gtk_widget_get_first_child (box);
     162         [ +  - ]:           6 :        child != NULL;
     163                 :           3 :        child = gtk_widget_get_next_sibling (child))
     164                 :             :     {
     165   [ +  -  +  +  :           6 :       if (GTK_IS_REVEALER (child))
                   +  - ]
     166                 :             :         break;
     167                 :             :     }
     168                 :             : 
     169                 :             :   /* The GtkRevealer's child is the GtkListBox */
     170   [ +  -  +  -  :           3 :   if (GTK_IS_REVEALER (child))
             -  +  -  - ]
     171                 :           3 :     return GTK_LIST_BOX (gtk_revealer_get_child (GTK_REVEALER (child)));
     172                 :             : 
     173                 :             :   return NULL;
     174                 :             : }
     175                 :             : 
     176                 :             : /*
     177                 :             :  * Notifications
     178                 :             :  */
     179                 :             : static gboolean
     180                 :           0 : application_list_filter (GtkListBoxRow *row,
     181                 :             :                          gpointer       user_data)
     182                 :             : {
     183                 :           0 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (user_data);
     184                 :           0 :   g_autofree char *haystack = NULL;
     185                 :           0 :   const char *title = NULL;
     186                 :             : 
     187         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     188                 :             : 
     189   [ #  #  #  # ]:           0 :   if (self->application_filter == NULL || *self->application_filter == '\0')
     190                 :             :     return TRUE;
     191                 :             : 
     192                 :           0 :   title = adw_preferences_row_get_title (ADW_PREFERENCES_ROW (row));
     193                 :           0 :   haystack = g_utf8_casefold (title, -1);
     194                 :             : 
     195                 :           0 :   return g_strrstr (haystack, self->application_filter) != NULL;
     196                 :             : }
     197                 :             : 
     198                 :             : static int
     199                 :           0 : application_list_sort (GtkListBoxRow *row1,
     200                 :             :                        GtkListBoxRow *row2,
     201                 :             :                        gpointer       user_data)
     202                 :             : {
     203   [ #  #  #  # ]:           0 :   if G_UNLIKELY (!ADW_IS_PREFERENCES_ROW (row1) ||
     204                 :             :                  !ADW_IS_PREFERENCES_ROW (row2))
     205                 :           0 :     return 0;
     206                 :             : 
     207                 :           0 :   return g_utf8_collate (adw_preferences_row_get_title ((AdwPreferencesRow *)row1),
     208                 :           0 :                          adw_preferences_row_get_title ((AdwPreferencesRow *)row2));
     209                 :             : }
     210                 :             : 
     211                 :             : /*
     212                 :             :  * Template Callbacks
     213                 :             :  */
     214                 :             : static void
     215                 :           0 : on_search_changed (GtkSearchEntry            *entry,
     216                 :             :                    ValentPreferencesSyncPage *self)
     217                 :             : {
     218                 :           0 :   g_autofree char *query = NULL;
     219                 :             : 
     220         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     221                 :             : 
     222                 :           0 :   query = g_utf8_casefold (gtk_editable_get_text (GTK_EDITABLE (entry)), -1);
     223                 :             : 
     224         [ #  # ]:           0 :   if (g_set_str (&self->application_filter, query))
     225                 :           0 :     gtk_list_box_invalidate_filter (self->application_list);
     226                 :           0 : }
     227                 :             : 
     228                 :             : static void
     229                 :           0 : on_search_toggled (GtkToggleButton           *button,
     230                 :             :                    GParamSpec                *pspec,
     231                 :             :                    ValentPreferencesSyncPage *self)
     232                 :             : {
     233         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     234                 :             : 
     235         [ #  # ]:           0 :   if (gtk_toggle_button_get_active (button))
     236                 :             :     {
     237                 :           0 :       gtk_stack_set_visible_child_name (self->application_title_stack, "search");
     238                 :           0 :       gtk_widget_grab_focus (GTK_WIDGET (self->application_filter_entry));
     239                 :           0 :       gtk_editable_set_position (GTK_EDITABLE (self->application_filter_entry), -1);
     240                 :             :     }
     241                 :             :   else
     242                 :             :     {
     243                 :           0 :       gtk_editable_set_text (GTK_EDITABLE (self->application_filter_entry), "");
     244                 :           0 :       gtk_stack_set_visible_child_name (self->application_title_stack, "title");
     245                 :             :     }
     246                 :           0 : }
     247                 :             : 
     248                 :             : static void
     249                 :           0 : on_search_started (GtkSearchEntry            *entry,
     250                 :             :                    ValentPreferencesSyncPage *self)
     251                 :             : {
     252         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     253                 :             : 
     254                 :           0 :   gtk_toggle_button_set_active (self->application_filter_button, TRUE);
     255                 :           0 : }
     256                 :             : 
     257                 :             : static void
     258                 :           0 : on_stop_search (GtkSearchEntry            *entry,
     259                 :             :                 ValentPreferencesSyncPage *self)
     260                 :             : {
     261         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     262                 :             : 
     263                 :           0 :   gtk_toggle_button_set_active (self->application_filter_button, FALSE);
     264                 :           0 : }
     265                 :             : 
     266                 :             : static void
     267                 :           0 : on_switch_toggled (GObject                   *object,
     268                 :             :                    GParamSpec                *pspec,
     269                 :             :                    ValentPreferencesSyncPage *self)
     270                 :             : {
     271                 :           0 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (self);
     272                 :           0 :   GSettings *settings;
     273                 :           0 :   GHashTableIter iter;
     274                 :           0 :   gpointer row;
     275                 :           0 :   GVariantBuilder builder;
     276                 :           0 :   GVariant *forward_deny;
     277                 :             : 
     278                 :           0 :   g_hash_table_iter_init (&iter, self->application_rows);
     279                 :           0 :   g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
     280                 :             : 
     281         [ #  # ]:           0 :   while (g_hash_table_iter_next (&iter, &row, NULL))
     282                 :             :     {
     283                 :           0 :       const char *name;
     284                 :             : 
     285         [ #  # ]:           0 :       if (adw_switch_row_get_active (ADW_SWITCH_ROW (row)))
     286                 :           0 :         continue;
     287                 :             : 
     288                 :           0 :       name = adw_preferences_row_get_title (ADW_PREFERENCES_ROW (row));
     289                 :           0 :       g_variant_builder_add (&builder, "s", name);
     290                 :             :     }
     291                 :             : 
     292                 :           0 :   forward_deny = g_variant_builder_end (&builder);
     293                 :           0 :   settings = valent_preferences_page_get_settings (page, "notification");
     294                 :           0 :   g_settings_set_value (settings, "forward-deny", forward_deny);
     295                 :           0 : }
     296                 :             : 
     297                 :             : static void
     298                 :           0 : add_application (ValentPreferencesSyncPage *self,
     299                 :             :                  GVariant                  *app,
     300                 :             :                  gboolean                   enabled)
     301                 :             : {
     302                 :           0 :   GtkWidget *row;
     303                 :           0 :   GtkWidget *image;
     304                 :           0 :   const char *title;
     305                 :           0 :   g_autoptr (GVariant) icon_v = NULL;
     306         [ #  # ]:           0 :   g_autoptr (GIcon) icon = NULL;
     307                 :             : 
     308         [ #  # ]:           0 :   if (!g_variant_lookup (app, "name", "&s", &title))
     309                 :           0 :     return;
     310                 :             : 
     311                 :           0 :   row = g_object_new (ADW_TYPE_SWITCH_ROW,
     312                 :             :                       "activatable", TRUE,
     313                 :             :                       "selectable",  TRUE,
     314                 :             :                       "title",       title,
     315                 :             :                       "active",      enabled,
     316                 :             :                       NULL);
     317                 :           0 :   g_signal_connect_object (row,
     318                 :             :                            "notify::active",
     319                 :             :                            G_CALLBACK (on_switch_toggled),
     320                 :             :                            self, 0);
     321                 :             : 
     322                 :             :   /* App icon */
     323         [ #  # ]:           0 :   if ((icon_v = g_variant_lookup_value (app, "icon", NULL)) != NULL)
     324                 :           0 :     icon = g_icon_deserialize (icon_v);
     325                 :             : 
     326         [ #  # ]:           0 :   if (icon == NULL)
     327                 :           0 :     icon = g_icon_new_for_string ("application-x-executable", NULL);
     328                 :             : 
     329                 :           0 :   image = g_object_new (GTK_TYPE_IMAGE,
     330                 :             :                         "gicon",     icon,
     331                 :             :                         "icon-size", GTK_ICON_SIZE_LARGE,
     332                 :             :                         NULL);
     333                 :           0 :   adw_action_row_add_prefix (ADW_ACTION_ROW (row), image);
     334                 :             : 
     335                 :           0 :   g_hash_table_add (self->application_rows, row);
     336         [ #  # ]:           0 :   gtk_list_box_insert (self->application_list, row, -1);
     337                 :             : }
     338                 :             : 
     339                 :             : static void
     340                 :           3 : populate_applications (ValentPreferencesSyncPage *self)
     341                 :             : {
     342                 :           3 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (self);
     343                 :           3 :   GSettings *settings;
     344                 :           3 :   GVariant *known;
     345                 :           6 :   g_auto (GStrv) deny = NULL;
     346                 :           3 :   GVariantIter iter;
     347                 :           3 :   const char *key;
     348                 :           3 :   GVariant *value;
     349                 :             : 
     350                 :           3 :   settings = valent_preferences_page_get_settings (page, "notification");
     351                 :           3 :   deny = g_settings_get_strv (settings, "forward-deny");
     352                 :             : 
     353                 :             :   /* Query the known applications */
     354                 :           3 :   known = valent_notifications_get_applications (NULL);
     355                 :           3 :   g_variant_iter_init (&iter, known);
     356                 :             : 
     357         [ -  + ]:           3 :   while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
     358                 :             :     {
     359                 :           0 :       gboolean enabled;
     360                 :             : 
     361                 :           0 :       enabled = !g_strv_contains ((const char * const *)deny, key);
     362                 :           0 :       add_application (self, value, enabled);
     363                 :             :     }
     364                 :           3 : }
     365                 :             : 
     366                 :             : /*
     367                 :             :  * GAction
     368                 :             :  */
     369                 :             : static void
     370                 :           0 : applications_action (GtkWidget  *widget,
     371                 :             :                      const char *action,
     372                 :             :                      GVariant   *parameter)
     373                 :             : {
     374                 :           0 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (widget);
     375                 :           0 :   GtkWidget *dialog = NULL;
     376                 :             : 
     377         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     378                 :             : 
     379                 :           0 :   dialog = gtk_widget_get_ancestor (widget, ADW_TYPE_PREFERENCES_DIALOG);
     380         [ #  # ]:           0 :   if (dialog != NULL)
     381                 :             :     {
     382                 :           0 :       adw_preferences_dialog_push_subpage (ADW_PREFERENCES_DIALOG (dialog),
     383                 :             :                                            self->application_page);
     384                 :             :     }
     385                 :           0 : }
     386                 :             : 
     387                 :             : static void
     388                 :           0 : reset_action (GtkWidget  *widget,
     389                 :             :               const char *action,
     390                 :             :               GVariant   *parameter)
     391                 :             : {
     392                 :           0 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (widget);
     393                 :           0 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (widget);
     394                 :           0 :   GSettings *settings;
     395                 :           0 :   GHashTableIter iter;
     396                 :           0 :   gpointer row_switch;
     397                 :             : 
     398         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_SYNC_PAGE (self));
     399         [ #  # ]:           0 :   g_assert (VALENT_IS_PREFERENCES_PAGE (self));
     400                 :             : 
     401                 :           0 :   g_hash_table_iter_init (&iter, self->application_rows);
     402                 :             : 
     403         [ #  # ]:           0 :   while (g_hash_table_iter_next (&iter, NULL, &row_switch))
     404                 :           0 :     gtk_switch_set_active (GTK_SWITCH (row_switch), TRUE);
     405                 :             : 
     406                 :           0 :   settings = valent_preferences_page_get_settings (page, "notification");
     407                 :           0 :   g_settings_reset (settings, "applications");
     408                 :           0 : }
     409                 :             : 
     410                 :             : /*
     411                 :             :  * SFTP
     412                 :             :  */
     413                 :             : static void
     414                 :           0 : on_toggle_row (GtkListBox    *box,
     415                 :             :                GtkListBoxRow *row,
     416                 :             :                gpointer       user_data)
     417                 :             : {
     418                 :           0 :   gboolean active;
     419                 :           0 :   GtkWidget *grid;
     420                 :           0 :   GtkWidget *toggle;
     421                 :             : 
     422   [ #  #  #  #  :           0 :   g_assert (GTK_IS_LIST_BOX (box));
             #  #  #  # ]
     423   [ #  #  #  #  :           0 :   g_assert (GTK_IS_LIST_BOX_ROW (row));
             #  #  #  # ]
     424                 :             : 
     425                 :           0 :   grid = gtk_list_box_row_get_child (row);
     426                 :           0 :   toggle = gtk_grid_get_child_at (GTK_GRID (grid), 1, 0);
     427                 :             : 
     428                 :           0 :   g_object_get (toggle, "active", &active, NULL);
     429                 :           0 :   g_object_set (toggle, "active", !active, NULL);
     430                 :           0 : }
     431                 :             : 
     432                 :             : /*
     433                 :             :  * ValentPreferencesPage
     434                 :             :  */
     435                 :             : static inline void
     436                 :           3 : valent_preferences_sync_page_bind_context (ValentPreferencesSyncPage *self)
     437                 :             : {
     438                 :           3 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (self);
     439                 :           3 :   GSettings *settings = NULL;
     440                 :             : 
     441                 :             :   /* Clipboard
     442                 :             :    */
     443                 :           3 :   settings = valent_preferences_page_get_settings (page, "clipboard");
     444                 :           3 :   g_settings_bind (settings,        "auto-pull",
     445                 :           3 :                    self->sync_pull, "active",
     446                 :             :                    G_SETTINGS_BIND_DEFAULT);
     447                 :           3 :   g_settings_bind (settings,        "auto-push",
     448                 :           3 :                    self->sync_push, "active",
     449                 :             :                    G_SETTINGS_BIND_DEFAULT);
     450                 :             : 
     451                 :             :   /* Contacts
     452                 :             :    */
     453                 :           3 :   settings = valent_preferences_page_get_settings (page, "contacts");
     454                 :           3 :   g_settings_bind (settings,          "remote-sync",
     455                 :           3 :                    self->remote_sync, "active",
     456                 :             :                    G_SETTINGS_BIND_DEFAULT);
     457                 :           3 :   g_settings_bind (settings,         "local-sync",
     458                 :           3 :                    self->local_sync, "enable-expansion",
     459                 :             :                    G_SETTINGS_BIND_DEFAULT);
     460                 :             : 
     461                 :             :   /* Notifications
     462                 :             :    */
     463                 :           3 :   settings = valent_preferences_page_get_settings (page, "notification");
     464                 :           3 :   g_settings_bind (settings,                    "forward-notifications",
     465                 :           3 :                    self->forward_notifications, "enable-expansion",
     466                 :             :                    G_SETTINGS_BIND_DEFAULT);
     467                 :           3 :   g_settings_bind (settings,                    "forward-when-active",
     468                 :           3 :                    self->forward_when_active,   "active",
     469                 :             :                    G_SETTINGS_BIND_INVERT_BOOLEAN);
     470                 :           3 :   populate_applications (self);
     471                 :             : 
     472                 :             :   /* SFTP
     473                 :             :    */
     474                 :           3 :   settings = valent_preferences_page_get_settings (page, "sftp");
     475                 :           3 :   g_settings_bind (settings,         "auto-mount",
     476                 :           3 :                    self->auto_mount, "active",
     477                 :             :                    G_SETTINGS_BIND_DEFAULT);
     478                 :           3 :   g_settings_bind (settings,          "local-allow",
     479                 :           3 :                    self->local_allow, "enable-expansion",
     480                 :             :                    G_SETTINGS_BIND_DEFAULT);
     481                 :           3 :   g_settings_bind (settings,         "local-port",
     482                 :           3 :                    self->local_port, "value",
     483                 :             :                    G_SETTINGS_BIND_DEFAULT);
     484                 :           3 : }
     485                 :             : 
     486                 :             : /*
     487                 :             :  * GObject
     488                 :             :  */
     489                 :             : static void
     490                 :           3 : valent_preferences_sync_page_dispose (GObject *object)
     491                 :             : {
     492                 :           3 :   GtkWidget *widget = GTK_WIDGET (object);
     493                 :             : 
     494                 :           3 :   gtk_widget_dispose_template (widget, VALENT_TYPE_PREFERENCES_SYNC_PAGE);
     495                 :             : 
     496                 :           3 :   G_OBJECT_CLASS (valent_preferences_sync_page_parent_class)->dispose (object);
     497                 :           3 : }
     498                 :             : 
     499                 :             : static void
     500                 :           3 : valent_preferences_sync_page_finalize (GObject *object)
     501                 :             : {
     502                 :           3 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (object);
     503                 :             : 
     504         [ -  + ]:           3 :   g_clear_pointer (&self->application_filter, g_free);
     505         [ +  - ]:           3 :   g_clear_pointer (&self->application_rows, g_hash_table_unref);
     506         [ +  - ]:           3 :   g_clear_pointer (&self->local_stores, g_hash_table_unref);
     507                 :             : 
     508                 :           3 :   G_OBJECT_CLASS (valent_preferences_sync_page_parent_class)->finalize (object);
     509                 :           3 : }
     510                 :             : 
     511                 :             : static void
     512                 :          27 : valent_preferences_sync_page_notify (GObject    *object,
     513                 :             :                                      GParamSpec *pspec)
     514                 :             : {
     515                 :          27 :   ValentPreferencesPage *page = VALENT_PREFERENCES_PAGE (object);
     516                 :          27 :   ValentPreferencesSyncPage *self = VALENT_PREFERENCES_SYNC_PAGE (object);
     517                 :             : 
     518         [ +  + ]:          27 :   if (g_strcmp0 (pspec->name, "context") == 0)
     519                 :             :     {
     520         [ +  - ]:           3 :       if (valent_preferences_page_get_context (page) != NULL)
     521                 :           3 :         valent_preferences_sync_page_bind_context (self);
     522                 :             :     }
     523                 :             : 
     524         [ -  + ]:          27 :   if (G_OBJECT_CLASS (valent_preferences_sync_page_parent_class)->notify)
     525                 :           0 :     G_OBJECT_CLASS (valent_preferences_sync_page_parent_class)->notify (object,
     526                 :             :                                                                         pspec);
     527                 :          27 : }
     528                 :             : 
     529                 :             : static void
     530                 :           2 : valent_preferences_sync_page_class_init (ValentPreferencesSyncPageClass *klass)
     531                 :             : {
     532                 :           2 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     533                 :           2 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
     534                 :             : 
     535                 :           2 :   object_class->dispose = valent_preferences_sync_page_dispose;
     536                 :           2 :   object_class->finalize = valent_preferences_sync_page_finalize;
     537                 :           2 :   object_class->notify = valent_preferences_sync_page_notify;
     538                 :             : 
     539                 :           2 :   gtk_widget_class_set_template_from_resource (widget_class, "/plugins/gnome/valent-preferences-sync-page.ui");
     540                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, sync_pull);
     541                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, sync_push);
     542                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, local_sync);
     543                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, remote_sync);
     544                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, forward_notifications);
     545                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, forward_when_active);
     546                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_page);
     547                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_title_stack);
     548                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_filter_entry);
     549                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_filter_button);
     550                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_list);
     551                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, application_row);
     552                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, auto_mount);
     553                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, local_allow);
     554                 :           2 :   gtk_widget_class_bind_template_child (widget_class, ValentPreferencesSyncPage, local_port);
     555                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_local_sync);
     556                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_search_changed);
     557                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_search_started);
     558                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_search_toggled);
     559                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_stop_search);
     560                 :           2 :   gtk_widget_class_bind_template_callback (widget_class, on_toggle_row);
     561                 :             : 
     562                 :           2 :   gtk_widget_class_install_action (widget_class, "preferences.applications", NULL, applications_action);
     563                 :           2 :   gtk_widget_class_install_action (widget_class, "preferences.reset", NULL, reset_action);
     564                 :             : 
     565                 :           2 : }
     566                 :             : 
     567                 :             : static void
     568                 :           3 : valent_preferences_sync_page_init (ValentPreferencesSyncPage *self)
     569                 :             : {
     570                 :           3 :   gtk_widget_init_template (GTK_WIDGET (self));
     571                 :             : 
     572                 :             :   /* Contacts
     573                 :             :    */
     574                 :           3 :   self->local_stores = g_hash_table_new (NULL, NULL);
     575                 :           3 :   self->local_list = _adw_expander_row_get_list (self->local_sync);
     576                 :           3 :   gtk_list_box_bind_model (self->local_list,
     577                 :           3 :                            G_LIST_MODEL (valent_contacts_get_default ()),
     578                 :             :                            valent_contacts_preferences_create_row_func,
     579                 :             :                            self, NULL);
     580                 :             : 
     581                 :             :   /* Notifications
     582                 :             :    */
     583                 :           3 :   self->application_rows = g_hash_table_new (NULL, NULL);
     584                 :           3 :   gtk_search_entry_set_key_capture_widget (self->application_filter_entry,
     585                 :           3 :                                            GTK_WIDGET (self->application_page));
     586                 :           3 :   gtk_list_box_set_filter_func (self->application_list,
     587                 :             :                                 application_list_filter,
     588                 :             :                                 self, NULL);
     589                 :           3 :   gtk_list_box_set_sort_func (self->application_list,
     590                 :             :                               application_list_sort,
     591                 :             :                               self, NULL);
     592                 :           3 : }
     593                 :             : 
        

Generated by: LCOV version 2.0-1