[gnome-contacts/nielsdg/core-should-stay-core: 6/11] utils: Cleanup and remove all Gtk/Adw related methods




commit ca63c4912bd5f161b5bfc8067f40f3715fc97b88
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Sep 7 10:40:06 2022 +0200

    utils: Cleanup and remove all Gtk/Adw related methods
    
    We had quite a few functions that were no longer being used or had only
    one specific user (so we can remove it from the generic `Utils`
    namespace).
    
    Finally, by removing all UI-related functions (those using GTK or
    libadwaita) we allow moving it into the "core" library

 src/contacts-avatar-selector.vala        |  8 ++++++--
 src/contacts-contact-editor.vala         |  8 ++++++--
 src/contacts-linked-personas-dialog.vala |  4 ++++
 src/contacts-type-combo.vala             |  9 ---------
 src/contacts-utils.vala                  | 29 -----------------------------
 src/core/contacts-type-set.vala          | 17 -----------------
 6 files changed, 16 insertions(+), 59 deletions(-)
---
diff --git a/src/contacts-avatar-selector.vala b/src/contacts-avatar-selector.vala
index cfe92aaa..4660351d 100644
--- a/src/contacts-avatar-selector.vala
+++ b/src/contacts-avatar-selector.vala
@@ -232,8 +232,12 @@ public class Contacts.AvatarSelector : Gtk.Dialog {
         }
       } catch (GLib.Error e) {
         warning ("Failed to set avatar: %s", e.message);
-        Utils.show_error_dialog (_("Failed to set avatar."),
-                                 this.get_root () as Gtk.Window);
+        var dialog = new Adw.MessageDialog (get_root () as Gtk.Window,
+                                            null,
+                                            _("Failed to set avatar."));
+        dialog.add_response ("close", _("_Close"));
+        dialog.default_response = "close";
+        dialog.show();
       } finally {
         chooser.destroy ();
       }
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index e7f9fc62..5509646e 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -110,8 +110,12 @@ public class Contacts.ContactEditor : Gtk.Widget {
           avatar_selector.set_avatar_on_contact ();
         } catch (Error e) {
           warning ("Failed to set avatar: %s", e.message);
-          Utils.show_error_dialog (_("Failed to set avatar."),
-                                   get_root () as Gtk.Window);
+          var dialog = new Adw.MessageDialog (get_root () as Gtk.Window,
+                                              null,
+                                              _("Failed to set avatar."));
+          dialog.add_response ("close", _("_Close"));
+          dialog.default_response = "close";
+          dialog.show();
         }
       }
       avatar_selector.destroy ();
diff --git a/src/contacts-linked-personas-dialog.vala b/src/contacts-linked-personas-dialog.vala
index 7d870951..f0105543 100644
--- a/src/contacts-linked-personas-dialog.vala
+++ b/src/contacts-linked-personas-dialog.vala
@@ -86,4 +86,8 @@ public class Contacts.LinkedPersonasDialog : Gtk.Dialog {
 
     return row_grid;
   }
+
+  private void add_separator (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
+    row.set_header (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
+  }
 }
diff --git a/src/contacts-type-combo.vala b/src/contacts-type-combo.vala
index 2940a5e0..67d68b9e 100644
--- a/src/contacts-type-combo.vala
+++ b/src/contacts-type-combo.vala
@@ -43,15 +43,6 @@ public class Contacts.TypeComboRow : Adw.ComboRow  {
     );
   }
 
-  /**
-   * Sets the value to the type of the given {@link Folks.AbstractFieldDetails}.
-   */
-  public void set_selected_from_field_details (AbstractFieldDetails details) {
-    uint position = 0;
-    this.type_set.lookup_by_field_details (details, out position);
-    this.selected = position;
-  }
-
   /**
    * Sets the value to the type that best matches the given vcard type
    * (for example "HOME" or "WORK").
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index 7edaa7c1..ec38207b 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -17,12 +17,6 @@
 
 using Folks;
 
-namespace Contacts {
-  public void add_separator (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
-    row.set_header (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
-  }
-}
-
 namespace Contacts.Utils {
 
   public void set_primary_store (Edsf.PersonaStore e_store) {
@@ -38,15 +32,6 @@ namespace Contacts.Utils {
     return null;
   }
 
-  public void grab_entry_focus_no_select (Gtk.SearchEntry entry) {
-    int start, end;
-    if (!entry.get_selection_bounds (out start, out end)) {
-      start = end = entry.get_position ();
-    }
-    entry.grab_focus ();
-    entry.select_region (start, end);
-  }
-
   public string[] get_stock_avatars () {
     string[] files = {};
     var system_data_dirs = Environment.get_system_data_dirs ();
@@ -69,13 +54,6 @@ namespace Contacts.Utils {
     return files;
   }
 
-  public void show_error_dialog (string error, Gtk.Window toplevel) {
-    var dialog = new Adw.MessageDialog (toplevel, null, error);
-    dialog.add_response ("close", _("_Close"));
-    dialog.default_response = "close";
-    dialog.show();
-  }
-
   public bool persona_is_main (Persona persona) {
     var store = persona.store;
     if (!store.is_primary_store)
@@ -125,13 +103,6 @@ namespace Contacts.Utils {
     return !has_main_persona (self) || !has_mainable_persona (other);
   }
 
-  public ListModel fields_to_sorted (Gee.Collection<AbstractFieldDetails> fields) {
-    var res = new ListStore (typeof (AbstractFieldDetails));
-    foreach (var afd in fields)
-      res.append (afd);
-    return new Gtk.SortListModel ((owned) res, new AbstractFieldDetailsSorter ());
-  }
-
   /* We claim something is "removable" if at least one persona is removable,
   that will typically unlink the rest. */
   public bool can_remove_personas (Individual individual) {
diff --git a/src/core/contacts-type-set.vala b/src/core/contacts-type-set.vala
index 8e462996..94877db3 100644
--- a/src/core/contacts-type-set.vala
+++ b/src/core/contacts-type-set.vala
@@ -43,14 +43,6 @@ public class Contacts.TypeSet : Object, GLib.ListModel  {
     Object (category: category);
   }
 
-  /**
-   * Returns the display name for the type of the given AbstractFieldDetails.
-   */
-  public unowned string format_type (AbstractFieldDetails detail) {
-    var d = lookup_by_field_details (detail);
-    return d.display_name;
-  }
-
   /**
    * Adds the TypeDescriptor to the {@link TypeSet}'s store.
    * @param descriptor The TypeDescription to be added
@@ -137,15 +129,6 @@ public class Contacts.TypeSet : Object, GLib.ListModel  {
     return null;
   }
 
-  /**
-   * Looks up the TypeDescriptor for the given field details. If the descriptor
-   * is not found, it will be created and returned, so this never returns null.
-   */
-  public TypeDescriptor lookup_by_field_details (AbstractFieldDetails detail,
-                                                 out uint position = null) {
-    return lookup_by_parameters (detail.parameters, out position);
-  }
-
   /**
    * Looks up the TypeDescriptor for the given parameters. If the descriptor
    * is not found, it will be created and returned, so this never returns null.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]