[geary/wip/135-contact-popovers: 14/26] Update ContactPopover depending on if the contact is from the desktop



commit 258b68b7e73fe3c839641dde4d92d946d4246978
Author: Michael Gratton <mike vee net>
Date:   Sat Mar 16 17:48:24 2019 +1100

    Update ContactPopover depending on if the contact is from the desktop
    
    Show the appropriate menu and star/unstar buttons.

 src/client/application/application-contact.vala           | 14 ++++++++++++++
 .../conversation-viewer/conversation-contact-popover.vala | 15 +++++++++++++++
 src/client/conversation-viewer/conversation-message.vala  |  7 ++++++-
 ui/conversation-contact-popover.ui                        |  8 +++++++-
 4 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/src/client/application/application-contact.vala b/src/client/application/application-contact.vala
index 5ff5d3fa..c0f58345 100644
--- a/src/client/application/application-contact.vala
+++ b/src/client/application/application-contact.vala
@@ -25,6 +25,11 @@ public class Application.Contact : Geary.BaseObject {
     /** Determines if this contact was loaded from Folks. */
     public bool is_desktop_contact { get; private set; default = false; }
 
+    /**
+     * Determines if this contact has been marked as a favourite.
+     */
+    public bool is_favourite { get; private set; default = false; }
+
     /**
      * Determines if email from this contact should load remote resources.
      *
@@ -100,6 +105,13 @@ public class Application.Contact : Geary.BaseObject {
         changed();
     }
 
+    /** Sets remote resource loading for this contact. */
+    public async void set_favourite(bool is_favourite,
+                                    GLib.Cancellable? cancellable)
+        throws GLib.Error {
+        yield this.individual.change_is_favourite(is_favourite);
+    }
+
     /** Returns a string representation for debugging */
     public string to_string() {
         return "Contact(\"%s\")".printf(this.display_name);
@@ -122,11 +134,13 @@ public class Application.Contact : Geary.BaseObject {
     private void update() {
         if (this.individual != null) {
             this.display_name = this.individual.display_name;
+            this.is_favourite = this.individual.is_favourite;
             this.is_desktop_contact = true;
         } else {
             if (this.contact != null) {
                 this.display_name = this.contact.real_name;
             }
+            this.is_favourite = false;
             this.is_desktop_contact = false;
         }
     }
diff --git a/src/client/conversation-viewer/conversation-contact-popover.vala 
b/src/client/conversation-viewer/conversation-contact-popover.vala
index 033c59e1..640bb015 100644
--- a/src/client/conversation-viewer/conversation-contact-popover.vala
+++ b/src/client/conversation-viewer/conversation-contact-popover.vala
@@ -30,6 +30,12 @@ public class Conversation.ContactPopover : Gtk.Popover {
     [GtkChild]
     private Gtk.Label contact_address;
 
+    [GtkChild]
+    private Gtk.Button starred_button;
+
+    [GtkChild]
+    private Gtk.Button unstarred_button;
+
 
     public ContactPopover(Gtk.Widget relative_to,
                           Application.Contact contact,
@@ -114,6 +120,15 @@ public class Conversation.ContactPopover : Gtk.Popover {
             this.contact_name.valign = FILL;
             this.contact_address.hide();
         }
+
+        bool starred = false;
+        bool unstarred = false;
+        if (this.contact.is_desktop_contact) {
+            starred = this.contact.is_favourite;
+            unstarred = !this.contact.is_favourite;
+        }
+        this.starred_button.set_visible(starred);
+        this.unstarred_button.set_visible(unstarred);
     }
 
     private void on_contact_changed() {
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index ccc90448..2649284d 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -1100,7 +1100,12 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
             );
             popover.load_avatar.begin();
             popover.add_section(this.context_menu_email, values);
-            popover.add_section(this.context_menu_unknown_contact, values);
+            popover.add_section(
+                address_child.contact.is_desktop_contact
+                    ? this.context_menu_known_contact
+                    : this.context_menu_unknown_contact,
+                values
+            );
             popover.set_position(Gtk.PositionType.BOTTOM);
             popover.closed.connect(() => {
                     address_child.unset_state_flags(Gtk.StateFlags.ACTIVE);
diff --git a/ui/conversation-contact-popover.ui b/ui/conversation-contact-popover.ui
index fc81a9db..b533f3d0 100644
--- a/ui/conversation-contact-popover.ui
+++ b/ui/conversation-contact-popover.ui
@@ -20,11 +20,14 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="margin_bottom">6</property>
-            <property name="column_spacing">6</property>
+            <property name="column_spacing">12</property>
             <child>
               <object class="GtkButton" id="unstarred_button">
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="action_name">msg.contact-star</property>
                 <property name="relief">none</property>
                 <child>
                   <object class="GtkImage">
@@ -43,6 +46,9 @@
               <object class="GtkButton" id="starred_button">
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="action_name">msg.contact-star</property>
                 <property name="relief">none</property>
                 <child>
                   <object class="GtkImage">


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