[gnome-contacts] Create InAppNotification class and remove libgd.



commit a483ccf5a68fc044af126246809369e314afa7a8
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Jun 24 13:52:24 2017 +0200

    Create InAppNotification class and remove libgd.
    
    Libgd is bound to remove Gd.Notification, and removing it also means it
    gets easier to port our build system to Meson.
    
    Furthermore, we can now use some more sane defaults for our application
    w.r.t. notifications.

 .gitmodules                             |    3 -
 Makefile.am                             |    4 +-
 configure.ac                            |    9 ---
 data/Makefile.am                        |    3 +-
 data/contacts.gresource.xml             |    3 +-
 data/ui/contacts-in-app-notification.ui |   49 +++++++++++++++++
 libgd                                   |    1 -
 src/Makefile.am                         |    6 +-
 src/contacts-app.vala                   |   13 +----
 src/contacts-in-app-notification.vala   |   78 ++++++++++++++++++++++++++
 src/contacts-window.vala                |   91 ++++++++++---------------------
 11 files changed, 168 insertions(+), 92 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 2b60687..e14176e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,10 @@
 ACLOCAL_AMFLAGS = -I m4 -I libgd ${ACLOCAL_FLAGS}
 NULL=
-SUBDIRS = libgd vapi src data po
+SUBDIRS = vapi src data po
 if BUILD_MAN_PAGES
 SUBDIRS += man
 endif
-DIST_SUBDIRS = libgd vapi src data po man
+DIST_SUBDIRS = vapi src data po man
 
 EXTRA_DIST = \
        autogen.sh \
diff --git a/configure.ac b/configure.ac
index 6f2c039..ca85748 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,7 +100,6 @@ AS_IF([test "x$enable_man_pages" != "xno"],
 AM_CONDITIONAL([BUILD_MAN_PAGES], [test "x$have_manutils" = "xyes"])
 
 AC_CONFIG_FILES([Makefile
-               libgd/Makefile
                vapi/Makefile
                src/Makefile
                man/Makefile
@@ -108,12 +107,4 @@ AC_CONFIG_FILES([Makefile
                po/Makefile.in
                ])
 
-dnl libgd
-LIBGD_INIT([
-  gtk-hacks
-  notification
-  static
-  vapi
-])
-
 AC_OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
index 5e13654..0f52d3d 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -36,8 +36,9 @@ EXTRA_DIST = \
        contacts.gresource.xml \
        ui/app-menu.ui \
        ui/contacts-address-map.ui \
-       ui/contacts-window.ui \
+       ui/contacts-in-app-notification.ui \
        ui/contacts-list-pane.ui \
+       ui/contacts-window.ui \
        ui/style.css \
        $(NULL)
 
diff --git a/data/contacts.gresource.xml b/data/contacts.gresource.xml
index 98bfee4..9f29f00 100644
--- a/data/contacts.gresource.xml
+++ b/data/contacts.gresource.xml
@@ -4,7 +4,8 @@
     <file compressed="true">ui/style.css</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/app-menu.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/contacts-address-map.ui</file>
-    <file compressed="true" preprocess="xml-stripblanks">ui/contacts-window.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/contacts-in-app-notification.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/contacts-list-pane.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/contacts-window.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/contacts-in-app-notification.ui b/data/ui/contacts-in-app-notification.ui
new file mode 100644
index 0000000..76d71fe
--- /dev/null
+++ b/data/ui/contacts-in-app-notification.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.14"/>
+  <template class="ContactsInAppNotification" parent="GtkRevealer">
+    <property name="visible">True</property>
+    <property name="halign">center</property>
+    <property name="valign">start</property>
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="column_spacing">8</property>
+        <style>
+          <class name="app-notification"/>
+        </style>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="visible">True</property>
+            <property name="wrap">True</property>
+            <property name="wrap_mode">PANGO_WRAP_WORD_CHAR</property>
+          </object>
+          <packing>
+            <property name="top_attach">0</property>
+            <property name="left_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="close_button">
+            <property name="visible">True</property>
+            <property name="focus_on_click">False</property>
+            <property name="relief">none</property>
+            <signal name="clicked" handler="on_close_button_clicked" swapped="no"/>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="pixel_size">16</property>
+                <property name="icon_name">window-close-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="top_attach">0</property>
+            <property name="left_attach">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 642977e..637052f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,6 @@ NULL =
 AM_CPPFLAGS = \
        -include config.h \
        $(CONTACTS_CFLAGS) \
-       -I$(top_srcdir)/libgd \
        -DLOCALEDIR=\""$(localedir)"\" \
        -DPKGDATADIR=\""$(pkgdatadir)"\" \
        -DPKGLIBDIR=\""$(pkglibdir)"\" \
@@ -11,7 +10,7 @@ AM_CPPFLAGS = \
        $(NULL)
 
 AM_VALAFLAGS = \
-       --vapidir=../vapi --vapidir=../libgd --pkg config --pkg custom --pkg gd-1.0 \
+       --vapidir=../vapi --pkg config --pkg custom \
        @CONTACTS_PACKAGES@ \
        --target-glib=2.38 --gresources=$(top_srcdir)/data/contacts.gresource.xml \
        $(NULL)
@@ -31,6 +30,7 @@ vala_sources = \
        contacts-contact-editor.vala \
        contacts-contact-pane.vala \
        contacts-types.vala \
+       contacts-in-app-notification.vala \
        contacts-list-pane.vala \
        contacts-linked-accounts-dialog.vala \
        contacts-linking.vala \
@@ -63,7 +63,7 @@ gnome_contacts_SOURCES = \
        contacts-esd-setup.c \
        $(NULL)
 
-gnome_contacts_LDADD = $(CONTACTS_LIBS) -lm $(top_builddir)/libgd/libgd.la
+gnome_contacts_LDADD = $(CONTACTS_LIBS) -lm
 
 if BUILD_CHEESE
 gnome_contacts_LDADD += $(CHEESE_LIBS)
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 89919a4..c5213b0 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -285,17 +285,8 @@ public class Contacts.App : Gtk.Application {
   }
 
   public void show_message (string message) {
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    var l = new Label (message);
-    l.set_line_wrap (true);
-    l.set_line_wrap_mode (Pango.WrapMode.WORD_CHAR);
-    notification.add (l);
-
-    notification.show_all ();
+    var notification = new InAppNotification (message);
+    notification.show ();
     window.add_notification (notification);
   }
 
diff --git a/src/contacts-in-app-notification.vala b/src/contacts-in-app-notification.vala
new file mode 100644
index 0000000..b3f9aea
--- /dev/null
+++ b/src/contacts-in-app-notification.vala
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Niels De Graef <nielsdegraef gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/contacts/ui/contacts-in-app-notification.ui")]
+public class Contacts.InAppNotification : Revealer {
+  // Close the in-app notification after 5 seconds by default.
+  private const uint DEFAULT_KEEPALIVE = 5;
+
+  [GtkChild]
+  private Grid grid;
+
+  [GtkChild]
+  private Label label;
+  public Label message_label {
+    get { return this.label; }
+  }
+
+  /**
+   * Fired when the notification is completely dismissed (i.e. gone).
+   */
+  public signal void dismissed ();
+
+  /**
+   * Creates an in-app notification with the given message, and an accompanying button if not null.
+   */
+  public InAppNotification (string message, Button? button = null) {
+    this.label.label = message;
+
+    if (button != null) {
+      this.grid.attach (button, 1, 0);
+      button.show();
+    }
+
+    this.notify["child-revealed"].connect (on_child_revealed_changed);
+  }
+
+  public new void show () {
+    base.show ();
+    this.reveal_child = true;
+
+    Timeout.add_seconds (DEFAULT_KEEPALIVE, () => {
+        dismiss ();
+        return false;
+      });
+  }
+
+  public void dismiss () {
+    this.reveal_child = false;
+  }
+
+  private void on_child_revealed_changed (Object o, ParamSpec p) {
+    if (!this.child_revealed) {
+      dismissed ();
+      destroy ();
+    }
+  }
+
+  [GtkCallback]
+  private void on_close_button_clicked(Button close_button) {
+    dismiss();
+  }
+}
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index 085da1a..0b6d89f 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -282,8 +282,9 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     }
   }
 
-  public void add_notification (Widget notification) {
-    overlay.add_overlay (notification);
+  public void add_notification (InAppNotification notification) {
+    this.overlay.add_overlay (notification);
+    notification.show ();
   }
 
   public void set_shown_contact (Contact? c) {
@@ -401,31 +402,21 @@ public class Contacts.Window : Gtk.ApplicationWindow {
         operation = link_contacts_list.end (result);
       });
 
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
-
     string msg = ngettext ("%d contacts linked",
                            "%d contacts linked",
                            contact_list.size).printf (contact_list.size);
 
     var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (new Label (msg));
-    g.add (b);
-
-    notification.show_all ();
-    add_notification (notification);
 
+    var notification = new InAppNotification (msg);
     /* signal handlers */
     b.clicked.connect ( () => {
         /* here, we will unlink the thing in question */
         operation.undo.begin ();
-
         notification.dismiss ();
       });
+
+    add_notification (notification);
   }
 
   void list_pane_delete_contacts_cb (LinkedList<Contact> contact_list) {
@@ -433,89 +424,68 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     set_shown_contact (null);
     select_button.set_active (false);
 
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
-
     string msg = ngettext ("%d contact deleted",
                            "%d contacts deleted",
                            contact_list.size).printf (contact_list.size);
 
     var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (new Label (msg));
-    g.add (b);
 
-    notification.show_all ();
-    add_notification (notification);
+    var notification = new InAppNotification (msg, b);
 
     /* signal handlers */
     bool really_delete = true;
-    notification.dismissed.connect ( () => {
-        if (really_delete) {
-          foreach (var c in contact_list) {
-            c.remove_personas.begin ();
-          }
-        }
-      });
     b.clicked.connect ( () => {
         really_delete = false;
         notification.dismiss ();
+      });
+    notification.dismissed.connect ( () => {
+        if (really_delete)
+          foreach (var c in contact_list)
+            c.remove_personas.begin ();
+      });
+
+    add_notification (notification);
+
        foreach (var c in contact_list) {
          c.show ();
        }
        set_shown_contact (contact_list.last ());
-      });
   }
 
   [GtkCallback]
   void contact_pane_delete_contact_cb (Contact contact) {
     /* unsetting edit-mode */
     set_shown_contact (null);
-    select_button.set_active (false);
-
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
+    this.select_button.active = false;
 
-    var label = new Label (_("Contact deleted: ā€œ%sā€").printf (contact.display_name));
-    label.set_max_width_chars (45);
-    label.set_ellipsize (Pango.EllipsizeMode.END);
+    // XXX
+    var msg = _("Contact deleted: ā€œ%sā€").printf (contact.display_name);
     var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (label);
-    g.add (b);
+
+    var notification = new InAppNotification (msg, b);
+    // Don't wrap (default), but ellipsize
+    notification.message_label.wrap = false;
+    notification.message_label.max_width_chars = 45;
+    notification.message_label.ellipsize = Pango.EllipsizeMode.END;
 
     bool really_delete = true;
-    notification.show_all ();
     notification.dismissed.connect ( () => {
         if (really_delete)
           contact.remove_personas.begin ( () => {
               contact.show ();
             });
       });
+    add_notification (notification);
     b.clicked.connect ( () => {
         really_delete = false;
         notification.dismiss ();
         contact.show ();
         set_shown_contact (contact);
       });
-    add_notification (notification);
   }
 
   [GtkCallback]
   void contact_pane_contacts_linked_cb (string? main_contact, string linked_contact, LinkOperation 
operation) {
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
-
     string msg;
     if (main_contact != null)
       msg = _("%s linked to %s").printf (main_contact, linked_contact);
@@ -523,14 +493,13 @@ public class Contacts.Window : Gtk.ApplicationWindow {
       msg = _("%s linked to the contact").printf (linked_contact);
 
     var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (new Label (msg));
-    g.add (b);
+    var notification = new InAppNotification (msg, b);
 
-    notification.show_all ();
     b.clicked.connect ( () => {
-       notification.dismiss ();
-       operation.undo.begin ();
+        notification.dismiss ();
+        operation.undo.begin ();
       });
+
     add_notification (notification);
   }
 }


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