[nautilus/wip/delete_notification: 63/63] delete notification



commit 4b48bf43f5de28586ab0cc7cfc153e81eb977ec4
Author: Carlos Soriano <csoriano gnome org>
Date:   Sat Jan 24 02:03:39 2015 +0100

    delete notification

 nautilus-delete-notification.h      |   39 ++++++++
 src/nautilus-delete-notification.c  |   97 +++++++++++++++++++
 src/nautilus-notification-delete.c  |  174 +++++++++++++++++++++++++++++++++++
 src/nautilus-notification-delete.h  |   55 +++++++++++
 src/nautilus-notification-manager.c |   74 +++++++++++++++
 src/nautilus-notification-manager.h |   56 +++++++++++
 6 files changed, 495 insertions(+), 0 deletions(-)
---
diff --git a/nautilus-delete-notification.h b/nautilus-delete-notification.h
new file mode 100644
index 0000000..3794e88
--- /dev/null
+++ b/nautilus-delete-notification.h
@@ -0,0 +1,39 @@
+#ifndef NAUTILUS_DELETE_NOTIFICATION_H
+#define NAUTILUS_DELETE_NOTIFICATION_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_DELETE_NOTIFICATION            (nautilus_delete_notification_get_type())
+#define NAUTILUS_DELETE_NOTIFICATION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_DELETE_NOTIFICATION, NautilusDeleteNotification))
+#define NAUTILUS_DELETE_NOTIFICATION_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_DELETE_NOTIFICATION, NautilusDeleteNotification const))
+#define NAUTILUS_DELETE_NOTIFICATION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
NAUTILUS_TYPE_DELETE_NOTIFICATION, NautilusDeleteNotificationClass))
+#define NAUTILUS_IS_DELETE_NOTIFICATION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
NAUTILUS_TYPE_DELETE_NOTIFICATION))
+#define NAUTILUS_IS_DELETE_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
NAUTILUS_TYPE_DELETE_NOTIFICATION))
+#define NAUTILUS_DELETE_NOTIFICATION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
NAUTILUS_TYPE_DELETE_NOTIFICATION, NautilusDeleteNotificationClass))
+
+typedef struct _NautilusDeleteNotification        NautilusDeleteNotification;
+typedef struct _NautilusDeleteNotificationClass   NautilusDeleteNotificationClass;
+typedef struct _NautilusDeleteNotificationPrivate NautilusDeleteNotificationPrivate;
+
+struct _NautilusDeleteNotification
+{
+  GtkGrid parent;
+
+  /*< private >*/
+  NautilusDeleteNotificationPrivate *priv;
+};
+
+struct _NautilusDeleteNotificationClass
+{
+  GtkGridClass parent;
+};
+
+GType                           nautilus_delete_notification_get_type (void);
+NautilusDeleteNotification     *nautilus_delete_notification_new      (void);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_DELETE_NOTIFICATION_H */
diff --git a/src/nautilus-delete-notification.c b/src/nautilus-delete-notification.c
new file mode 100644
index 0000000..46da6a5
--- /dev/null
+++ b/src/nautilus-delete-notification.c
@@ -0,0 +1,97 @@
+#include "nautilus-delete-notification.h"
+
+struct _NautilusDeleteNotificationPrivate
+{
+  GList *items;
+  guint timeout_id;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (NautilusDeleteNotification, nautilus_delete_notification, GTK_TYPE_GRID)
+
+enum {
+  PROP_0,
+  PROP_ITEMS,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+NautilusDeleteNotification *
+nautilus_delete_notification_new (void)
+{
+  return g_object_new (NAUTILUS_TYPE_DELETE_NOTIFICATION, NULL);
+}
+
+static void
+nautilus_delete_notification_finalize (GObject *object)
+{
+  NautilusDeleteNotificationPrivate *priv = NAUTILUS_DELETE_NOTIFICATION (object)->priv;
+
+  G_OBJECT_CLASS (nautilus_delete_notification_parent_class)->finalize (object);
+}
+
+static void
+nautilus_delete_notification_get_property (GObject    *object,
+                                           guint       prop_id,
+                                           GValue     *value,
+                                           GParamSpec *pspec)
+{
+  NautilusDeleteNotification *self = NAUTILUS_DELETE_NOTIFICATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_ITEMS:
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+nautilus_delete_notification_set_property (GObject      *object,
+                                           guint         prop_id,
+                                           const GValue *value,
+                                           GParamSpec   *pspec)
+{
+  NautilusDeleteNotification *self = NAUTILUS_DELETE_NOTIFICATION (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+nautilus_delete_notification_class_init (NautilusDeleteNotificationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = nautilus_delete_notification_finalize;
+  object_class->get_property = nautilus_delete_notification_get_property;
+  object_class->set_property = nautilus_delete_notification_set_property;
+}
+
+static void
+nautilus_delete_notification_init (NautilusDeleteNotification *self)
+{
+  self->priv = nautilus_delete_notification_get_instance_private (self);
+}
+
+static void
+nautilus_delete_notification_remove_timeout (NAutilusDeleteNotification *self)
+{
+  if (self->priv->timeout_id != 0)
+    {
+      g_source_remove (self->priv->timeout_id);
+      self->priv->timeout_id = 0;
+    }
+}
+
+static void
+nautilus_delete_notification_destroy (PhotosDeleteNotification *self)
+{
+  nautilus_delete_notification_remove_timeout (self);
+  gtk_widget_destroy (GTK_WIDGET (self));
+}
+
diff --git a/src/nautilus-notification-delete.c b/src/nautilus-notification-delete.c
new file mode 100644
index 0000000..2d3b394
--- /dev/null
+++ b/src/nautilus-notification-delete.c
@@ -0,0 +1,174 @@
+/* nautilus-notification-delete.c
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * 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 3 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/>.
+ */
+#include "nautilus-notification-delete.h"
+
+struct _NautilusNotificationDeletePrivate
+{
+  guint items;
+  guint timeout;
+  GtkWidget *notification_manager;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (NautilusNotificationDelete, nautilus_notification_delete, GTK_TYPE_GRID)
+
+enum {
+  PROP_0,
+  PROP_ITEMS,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+static const NOTIFICATION_TIMEOUT = 10;
+
+static void
+nautilus_notification_delete_remove_timeout (NautilusNotificationDelete *self)
+{
+  if (self->priv->timeout_id != 0)
+    {
+      g_source_remove (self->priv->timeout_id);
+      self->priv->timeout_id = 0;
+    }
+}
+
+static void
+nautilus_notification_delete_destroy (NautilusNotificationDelete *self)
+{
+  nautilus_notification_delete_remove_timeout (self);
+  gtk_widget_destroy (GTK_WIDGET (self));
+}
+
+static void
+nautilus_notification_delete_on_timeout (gpointer user_data)
+{
+  NautilusNotificationDelete *self = NAUTILUS_NOTIFICATION_DELETE (user_data);
+
+  self->priv->timeout_id = 0;
+  nautilus_notification_delete_destroy (self);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+nautilus_notification_delete_undo_clicked (NautilusNotificationDelete *self)
+{
+  nautilus_notification_delete_destroy (self);
+}
+
+static void
+nautilus_notification_delete_constructed (GObject *object)
+{
+  NautilusNotificationDelete *self = NAUTILUS_NOTIFICATION_DELETE (object);
+  GtkWidget *close;
+  GtkWidget *label;
+  GtkWidget *undo;
+  guint length;
+
+  G_OBJECT_CLASS (nautilus_notification_delete_parent_class)->constructed (object);
+
+  if (self->priv->n_items > 1)
+         label = _("Selected item has been deleted"),
+  else
+    label = g_strdup_printf (_("%d items have been deleted"),
+                                self->priv->n_item);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_container_add (GTK_CONTAINER (self), label);
+
+  undo = gtk_button_new_with_label (_("Undo"));
+  gtk_widget_set_valign (undo, GTK_ALIGN_CENTER);
+  gtk_container_add (GTK_CONTAINER (self), undo);
+  g_signal_connect_swapped (undo, "clicked", G_CALLBACK (nautilus_notification_delete_undo_clicked), self);
+
+  close = gtk_button_new_from_icon_name ("window-close-symbolic", 16);
+  gtk_widget_set_valign (close, GTK_ALIGN_CENTER);
+  gtk_button_set_focus_on_click (GTK_BUTTON (close), FALSE);
+  gtk_button_set_relief (GTK_BUTTON (close), GTK_RELIEF_NONE);
+  gtk_container_add (GTK_CONTAINER (self), close);
+  g_signal_connect_swapped (close, "clicked", G_CALLBACK (nautilus_notification_delete_destroy), self);
+
+  nautilus_notification_manager_add_notification (NAUTILUS_NOTIFICATION_MANAGER (priv->notification_manager),
+                                                 GTK_WIDGET (self));
+
+  priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+                                                 NOTIFICATION_TIMEOUT,
+                                                 nautilus_notification_delete_on_timeout,
+                                                 g_object_ref (self),
+                                                 g_object_unref);
+}
+
+NautilusNotificationDelete *
+nautilus_notification_delete_new (void)
+{
+  return g_object_new (NAUTILUS_TYPE_NOTIFICATION_DELETE, NULL);
+}
+
+static void
+nautilus_notification_delete_finalize (GObject *object)
+{
+  NautilusNotificationDeletePrivate *priv = NAUTILUS_NOTIFICATION_DELETE (object)->priv;
+
+  G_OBJECT_CLASS (nautilus_notification_delete_parent_class)->finalize (object);
+}
+
+static void
+nautilus_notification_delete_get_property (GObject    *object,
+                                           guint       prop_id,
+                                           GValue     *value,
+                                           GParamSpec *pspec)
+{
+  NautilusNotificationDelete *self = NAUTILUS_NOTIFICATION_DELETE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+nautilus_notification_delete_set_property (GObject      *object,
+                                           guint         prop_id,
+                                           const GValue *value,
+                                           GParamSpec   *pspec)
+{
+  NautilusNotificationDelete *self = NAUTILUS_NOTIFICATION_DELETE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+nautilus_notification_delete_class_init (NautilusNotificationDeleteClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = nautilus_notification_delete_finalize;
+  object_class->get_property = nautilus_notification_delete_get_property;
+  object_class->set_property = nautilus_notification_delete_set_property;
+}
+
+static void
+nautilus_notification_delete_init (NautilusNotificationDelete *self)
+{
+  self->priv = nautilus_notification_delete_get_instance_private (self);
+  self->priv->notification_manager = g_object_ref_sink (nautilus_notification_manager_dup_singleton ());
+}
+
diff --git a/src/nautilus-notification-delete.h b/src/nautilus-notification-delete.h
new file mode 100644
index 0000000..3b736de
--- /dev/null
+++ b/src/nautilus-notification-delete.h
@@ -0,0 +1,55 @@
+/* nautilus-notification-delete.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * 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 3 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/>.
+ */
+#ifndef NAUTILUS_NOTIFICATION_DELETE_H
+#define NAUTILUS_NOTIFICATION_DELETE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_NOTIFICATION_DELETE            (nautilus_notification_delete_get_type())
+#define NAUTILUS_NOTIFICATION_DELETE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_NOTIFICATION_DELETE, NautilusNotificationDelete))
+#define NAUTILUS_NOTIFICATION_DELETE_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_NOTIFICATION_DELETE, NautilusNotificationDelete const))
+#define NAUTILUS_NOTIFICATION_DELETE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
NAUTILUS_TYPE_NOTIFICATION_DELETE, NautilusNotificationDeleteClass))
+#define NAUTILUS_IS_NOTIFICATION_DELETE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
NAUTILUS_TYPE_NOTIFICATION_DELETE))
+#define NAUTILUS_IS_NOTIFICATION_DELETE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
NAUTILUS_TYPE_NOTIFICATION_DELETE))
+#define NAUTILUS_NOTIFICATION_DELETE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
NAUTILUS_TYPE_NOTIFICATION_DELETE, NautilusNotificationDeleteClass))
+
+typedef struct _NautilusNotificationDelete        NautilusNotificationDelete;
+typedef struct _NautilusNotificationDeleteClass   NautilusNotificationDeleteClass;
+typedef struct _NautilusNotificationDeletePrivate NautilusNotificationDeletePrivate;
+
+struct _NautilusNotificationDelete
+{
+       GtkGrid parent;
+
+       /*< private >*/
+       NautilusNotificationDeletePrivate *priv;
+};
+
+struct _NautilusNotificationDeleteClass
+{
+       GtkGridClass parent;
+};
+
+GType                           nautilus_notification_delete_get_type (void);
+NautilusNotificationDelete     *nautilus_notification_delete_new      (void);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_NOTIFICATION_DELETE_H */
diff --git a/src/nautilus-notification-manager.c b/src/nautilus-notification-manager.c
new file mode 100644
index 0000000..c844227
--- /dev/null
+++ b/src/nautilus-notification-manager.c
@@ -0,0 +1,74 @@
+#include "nautilus-notification-manager.h"
+
+struct _NautilusNotificationManagerPrivate
+{
+  GtkWidget *grid;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (NautilusNotificationManager, nautilus_notification_manager, GD_TYPE_NOTIFICATION)
+
+NautilusNotificationManager *
+nautilus_notification_manager_dup_singleton (void)
+{
+  return g_object_new (NAUTILUS_TYPE_NOTIFICATION_MANAGER,
+                       "show-close-button", FALSE,
+                       "timeout", -1,
+                       NULL);
+}
+
+static GObject *
+nautilus_notification_manager_constructor (GType type,
+                                           guint n_construct_params,
+                                           GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (nautilus_notification_manager_parent_class)->constructor (type,
+                                                                                       n_construct_params,
+                                                                                       construct_params);
+      g_object_add_weak_pointer (self, (gpointer) &self);
+      return self;
+    }
+
+  return g_object_ref (self);
+}
+
+static void
+nautilus_notification_manager_remove (NautilusNotificationManager *self)
+{
+  GList *children;
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->priv->grid));
+  if (children == NULL)
+    gtk_widget_hide (GTK_WIDGET (self));
+  else
+    g_list_free (children);
+}
+
+static void
+nautilus_notification_manager_class_init (NautilusNotificationManagerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructor = nautilus_notification_manager_constructor;
+}
+
+static void
+nautilus_notification_manager_init (NautilusNotificationManager *self)
+{
+  self->priv = nautilus_notification_manager_get_instance_private (self);
+
+  gtk_widget_set_halign (GTK_WIDGET (self), GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (GTK_WIDGET (self), GTK_ALIGN_START);
+
+  self->priv->grid = gtk_grid_new ();
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self->priv->grid),
+                                  GTK_ORIENTATION_VERTICAL);
+  gtk_grid_set_row_spacing (GTK_GRID (self->priv->grid), 6);
+  gtk_container_add (GTK_CONTAINER (self), self->priv->grid);
+
+  g_signal_connect_swapped (self->priv->grid, "remove",
+                            G_CALLBACK (nautilus_notification_manager_remove), self);
+}
diff --git a/src/nautilus-notification-manager.h b/src/nautilus-notification-manager.h
new file mode 100644
index 0000000..5be7497
--- /dev/null
+++ b/src/nautilus-notification-manager.h
@@ -0,0 +1,56 @@
+/* nautilus-notification-manager.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * 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 3 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/>.
+ */
+
+#ifndef NAUTILUS_NOTIFICATION_MANAGER_H
+#define NAUTILUS_NOTIFICATION_MANAGER_H
+
+#include <libgd/gd.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_NOTIFICATION_MANAGER            (nautilus_notification_manager_get_type())
+#define NAUTILUS_NOTIFICATION_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_NOTIFICATION_MANAGER, NautilusNotificationManager))
+#define NAUTILUS_NOTIFICATION_MANAGER_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
NAUTILUS_TYPE_NOTIFICATION_MANAGER, NautilusNotificationManager const))
+#define NAUTILUS_NOTIFICATION_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
NAUTILUS_TYPE_NOTIFICATION_MANAGER, NautilusNotificationManagerClass))
+#define NAUTILUS_IS_NOTIFICATION_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
NAUTILUS_TYPE_NOTIFICATION_MANAGER))
+#define NAUTILUS_IS_NOTIFICATION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
NAUTILUS_TYPE_NOTIFICATION_MANAGER))
+#define NAUTILUS_NOTIFICATION_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
NAUTILUS_TYPE_NOTIFICATION_MANAGER, NautilusNotificationManagerClass))
+
+typedef struct _NautilusNotificationManager        NautilusNotificationManager;
+typedef struct _NautilusNotificationManagerClass   NautilusNotificationManagerClass;
+typedef struct _NautilusNotificationManagerPrivate NautilusNotificationManagerPrivate;
+
+struct _NautilusNotificationManager
+{
+  GdNotification parent;
+
+  /*< private >*/
+  NautilusNotificationManagerPrivate *priv;
+};
+
+struct _NautilusNotificationManagerClass
+{
+  GdNotificationClass parent;
+};
+
+GType                            nautilus_notification_manager_get_type      (void);
+NautilusNotificationManager     *nautilus_notification_manager_dup_singleton (void);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_NOTIFICATION_MANAGER_H */


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