[nautilus] nautilus-window: don't use libgd notifications



commit 21c38ac32e0d7ec1c119df6e308a7fa789c76648
Author: Carlos Soriano <csoriano gnome org>
Date:   Sun Mar 1 19:23:24 2015 +0100

    nautilus-window: don't use libgd notifications
    
    We are using notifications just for one window and one type of
    notification and only one notification at once, so we don't need to use
    notification-manager from libgd.
    Given that the manager is not necessary, the reasons to use libgd
    notifications becomes weak.
    
    Instead of libgd notifications create our own with a GtkRevealer and
    remove all the libgd notifications, so we have a cleaner code.

 src/Makefile.am                     |    4 -
 src/nautilus-notification-delete.c  |  210 -----------------------------------
 src/nautilus-notification-delete.h  |   57 ----------
 src/nautilus-notification-delete.ui |   71 ++++++++++++
 src/nautilus-notification-manager.c |   77 -------------
 src/nautilus-notification-manager.h |   59 ----------
 src/nautilus-window-private.h       |    6 +-
 src/nautilus-window.c               |  122 +++++++++++++++++++--
 src/nautilus.gresource.xml          |    1 +
 9 files changed, 190 insertions(+), 417 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 82a7511..d797d23 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -178,10 +178,6 @@ nautilus_SOURCES = \
        nautilus-list-view.h                    \
        nautilus-location-entry.c               \
        nautilus-location-entry.h               \
-       nautilus-notification-delete.c          \
-       nautilus-notification-delete.h          \
-       nautilus-notification-manager.c         \
-       nautilus-notification-manager.h         \
        nautilus-main.c                         \
        nautilus-mime-actions.c                 \
        nautilus-mime-actions.h                 \
diff --git a/src/nautilus-notification-delete.ui b/src/nautilus-notification-delete.ui
new file mode 100644
index 0000000..785b1af
--- /dev/null
+++ b/src/nautilus-notification-delete.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkRevealer" id="notification_delete">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="halign">center</property>
+    <property name="valign">start</property>
+    <property name="transition_duration">100</property>
+    <child>
+      <object class="GtkFrame">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="margin_end">12</property>
+            <property name="margin_top">2</property>
+            <property name="margin_bottom">2</property>
+            <child>
+              <object class="GtkLabel" id="notification_delete_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="max_width_chars">50</property>
+                <property name="ellipsize">middle</property>
+                <property name="margin_end">30</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkButton" id="notification_delete_undo">
+                <property name="label" translatable="yes">undo</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="no_show_all">True</property>
+                <property name="margin_end">6</property>
+              </object>
+              <style>
+                <class name="text-button"/>
+              </style>
+            </child>
+            <child>
+              <object class="GtkButton" id="notification_delete_close">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="relief">none</property>
+                <property name="focus_on_click">False</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">window-close-symbolic</property>
+                    <property name="icon_size">2</property>
+                  </object>
+                </child>
+                <style>
+                  <class name="image-button"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <style>
+          <class name="app-notification"/>
+        </style>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index cbd018b..849760e 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -55,7 +55,11 @@ struct NautilusWindowDetails
         GtkWidget *main_view;
 
        /* Notifications */
-        GtkWidget *notification_manager;
+        GtkWidget *notification_delete;
+        GtkWidget *notification_delete_label;
+        GtkWidget *notification_delete_close;
+        GtkWidget *notification_delete_undo;
+       guint notification_delete_timeout_id;
 
         /* Toolbar */
         GtkWidget *toolbar;
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index c1c909a..da948f2 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -42,8 +42,6 @@
 #include "nautilus-window-slot.h"
 #include "nautilus-list-view.h"
 #include "nautilus-view.h"
-#include "nautilus-notification-manager.h"
-#include "nautilus-notification-delete.h"
 
 #include <eel/eel-debug.h>
 #include <eel/eel-gtk-extensions.h>
@@ -95,6 +93,8 @@ static GtkWidget * nautilus_window_ensure_location_entry (NautilusWindow *window
  */
 #define UPPER_MOUSE_LIMIT 14
 
+#define NOTIFICATION_TIMEOUT 6 //s
+
 enum {
        PROP_DISABLE_CHROME = 1,
        NUM_PROPERTIES,
@@ -1463,15 +1463,100 @@ nautilus_window_ensure_location_entry (NautilusWindow *window)
 }
 
 static void
+nautilus_window_on_notification_delete_undo_clicked (GtkWidget  *notification,
+                                                     gpointer    user_data)
+{
+       NautilusWindow *window;
+
+       window = NAUTILUS_WINDOW (user_data);
+
+       if (window->details->notification_delete_timeout_id != 0) {
+               g_source_remove (window->details->notification_delete_timeout_id);
+               window->details->notification_delete_timeout_id = 0;
+       }
+
+       gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE);
+       nautilus_file_undo_manager_undo (GTK_WINDOW (window));
+}
+
+static void
+nautilus_window_on_notification_delete_close_clicked (GtkWidget  *notification,
+                                                      gpointer    user_data)
+{
+       NautilusWindow *window;
+
+       window = NAUTILUS_WINDOW (user_data);
+
+       if (window->details->notification_delete_timeout_id != 0) {
+               g_source_remove (window->details->notification_delete_timeout_id);
+               window->details->notification_delete_timeout_id = 0;
+       }
+
+       gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE);
+}
+
+static gboolean
+nautilus_window_on_notification_delete_timeout (gpointer user_data)
+{
+       NautilusWindow *window;
+
+       window = NAUTILUS_WINDOW (user_data);
+
+       if (window->details->notification_delete_timeout_id != 0) {
+               g_source_remove (window->details->notification_delete_timeout_id);
+               window->details->notification_delete_timeout_id = 0;
+       }
+
+       gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE);
+
+       return FALSE;
+}
+
+static char *
+nautilus_window_notification_delete_get_label (NautilusFileUndoInfo *undo_info,
+                                               GList *files)
+{
+       gchar *file_label;
+       gchar *markup;
+       gchar *label;
+       gint length;
+
+       length = g_list_length (files);
+       if (length == 1) {
+               file_label = g_file_get_basename (files->data);
+               markup = g_markup_printf_escaped ("<b>%s</b>", file_label);
+               label = g_strdup_printf (_("%s deleted"), markup);
+       } else {
+               /* Translators: this is the first part of a "%d files deleted" string */
+               file_label = g_strdup_printf (ngettext ("%d file", "%d files", length), length);
+               markup = g_markup_printf_escaped ("<b>%s</b>", file_label);
+
+               /* Translators: this is the second part of a "%d files deleted" string */
+               label = g_strdup_printf (ngettext ("%s deleted", "%s deleted", length), markup);
+       }
+
+       g_free (file_label);
+       g_free (markup);
+
+       return label;
+}
+
+static void
 nautilus_window_on_undo_changed (NautilusFileUndoManager *manager,
                                  NautilusWindow          *window)
 {
-       NautilusNotificationDelete *notification;
        NautilusFileUndoInfo *undo_info;
        NautilusFileUndoManagerState state;
+       int transition_durantion;
+       gchar *label;
        GList *files;
 
-       nautilus_notification_manager_remove_all (NAUTILUS_NOTIFICATION_MANAGER 
(window->details->notification_manager));
+       /* Hide it inmediatily so we can animate the new notification. */
+       transition_durantion = gtk_revealer_get_transition_duration (GTK_REVEALER 
(window->details->notification_delete));
+       gtk_revealer_set_transition_duration (GTK_REVEALER (window->details->notification_delete), 0);
+       gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), FALSE);
+       gtk_revealer_set_transition_duration (GTK_REVEALER (window->details->notification_delete), 
transition_durantion);
+
        undo_info = nautilus_file_undo_manager_get_action ();
        state = nautilus_file_undo_manager_get_state ();
 
@@ -1484,9 +1569,13 @@ nautilus_window_on_undo_changed (NautilusFileUndoManager *manager,
                 * is not in the this window. This is an easy way to know from which window
                 * was the delete operation made */
                if (g_list_length (files) > 0 && gtk_window_has_toplevel_focus (GTK_WINDOW (window))) {
-                       notification = nautilus_notification_delete_new (window);
-                       nautilus_notification_manager_add_notification (NAUTILUS_NOTIFICATION_MANAGER 
(window->details->notification_manager),
-                                                                       GTK_WIDGET (notification));
+                       label = nautilus_window_notification_delete_get_label (undo_info, files);
+                       gtk_label_set_markup (GTK_LABEL (window->details->notification_delete_label), label);
+                       gtk_revealer_set_reveal_child (GTK_REVEALER (window->details->notification_delete), 
TRUE);
+                       window->details->notification_delete_timeout_id = g_timeout_add_seconds 
(NOTIFICATION_TIMEOUT,
+                                                                                                
nautilus_window_on_notification_delete_timeout,
+                                                                                                window);
+                       g_free (label);
                }
                g_list_free (files);
        }
@@ -1868,6 +1957,7 @@ nautilus_window_constructed (GObject *self)
        GtkWidget *grid;
        NautilusWindowSlot *slot;
        NautilusApplication *application;
+       g_autoptr (GtkBuilder) builder;
 
        window = NAUTILUS_WINDOW (self);
 
@@ -1907,9 +1997,18 @@ nautilus_window_constructed (GObject *self)
        window->details->notebook = create_notebook (window);
        nautilus_window_set_initial_window_geometry (window);
 
-       window->details->notification_manager = GTK_WIDGET (nautilus_notification_manager_new ());
+       builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/nautilus-notification-delete.ui");
+       window->details->notification_delete = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete"));
+       window->details->notification_delete_label = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_label"));
+       window->details->notification_delete_close = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_close"));
+       window->details->notification_delete_undo = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_undo"));
        gtk_overlay_add_overlay (GTK_OVERLAY (window->details->main_view),
-                                 window->details->notification_manager);
+                                 window->details->notification_delete);
+       g_signal_connect_object (window->details->notification_delete_close, "clicked",
+                                G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 
0);
+       g_signal_connect_object (window->details->notification_delete_undo, "clicked",
+                                G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);
+
        g_signal_connect_after (nautilus_file_undo_manager_get (), "undo-changed",
                                 G_CALLBACK (nautilus_window_on_undo_changed), self);
 
@@ -2037,6 +2136,11 @@ nautilus_window_finalize (GObject *object)
                window->details->sidebar_width_handler_id = 0;
        }
 
+       if (window->details->notification_delete_timeout_id != 0) {
+               g_source_remove (window->details->notification_delete_timeout_id);
+               window->details->notification_delete_timeout_id = 0;
+       }
+
        g_signal_handlers_disconnect_by_func (nautilus_file_undo_manager_get (),
                                               G_CALLBACK (nautilus_window_on_undo_changed),
                                               window);
diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml
index 9f16f58..2038a9c 100644
--- a/src/nautilus.gresource.xml
+++ b/src/nautilus.gresource.xml
@@ -10,6 +10,7 @@
     <file>nautilus-view-context-menus.xml</file>
     <file>nautilus-progress-info-widget.xml</file>
     <file>nautilus-move-to-trash-shortcut-changed.ui</file>
+    <file>nautilus-notification-delete.ui</file>
     <file alias="icons/thumbnail_frame.png">../icons/thumbnail_frame.png</file>
     <file alias="icons/filmholes.png">../icons/filmholes.png</file>
     <file alias="icons/knob.png">../icons/knob.png</file>


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