[gnome-photos] Add PhotosPrintNotification



commit b01dd70fea34632fac865e285a898f41f56353f2
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Mar 16 13:29:45 2014 +0100

    Add PhotosPrintNotification

 po/POTFILES.in                  |    1 +
 src/Makefile.am                 |    2 +
 src/photos-base-item.c          |    6 +
 src/photos-icons.h              |    2 +
 src/photos-print-notification.c |  211 +++++++++++++++++++++++++++++++++++++++
 src/photos-print-notification.h |   75 ++++++++++++++
 6 files changed, 297 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9f6a381..eabc930 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,6 +25,7 @@ src/photos-main-window.c
 src/photos-organize-collection-dialog.c
 [type: gettext/glade]src/photos-preview-menu.ui
 src/photos-preview-nav-buttons.c
+src/photos-print-notification.c
 src/photos-print-operation.c
 src/photos-print-setup.c
 src/photos-properties-dialog.c
diff --git a/src/Makefile.am b/src/Makefile.am
index ec6acee..32b0d60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -159,6 +159,8 @@ gnome_photos_service_SOURCES = \
        photos-preview-nav-buttons.h \
        photos-preview-view.c \
        photos-preview-view.h \
+       photos-print-notification.c \
+       photos-print-notification.h \
        photos-print-operation.c \
        photos-print-operation.h \
        photos-print-preview.c \
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index d7ebf4c..2de1eda 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -38,6 +38,7 @@
 #include "photos-delete-item-job.h"
 #include "photos-filterable.h"
 #include "photos-icons.h"
+#include "photos-print-notification.h"
 #include "photos-print-operation.h"
 #include "photos-query.h"
 #include "photos-search-context.h"
@@ -810,6 +811,11 @@ photos_base_item_print_load (GObject *source_object, GAsyncResult *res, gpointer
                          g_object_ref (self),
                          (GClosureNotify) g_object_unref,
                          G_CONNECT_SWAPPED);
+
+
+  /* It is self managing. */
+  photos_print_notification_new (print_op);
+
   gtk_print_operation_run (print_op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, toplevel, NULL);
 
  out:
diff --git a/src/photos-icons.h b/src/photos-icons.h
index 7fd01f0..50e7f21 100644
--- a/src/photos-icons.h
+++ b/src/photos-icons.h
@@ -37,6 +37,8 @@ G_BEGIN_DECLS
 
 #define PHOTOS_ICON_PHOTOS_SYMBOLIC "emblem-photos-symbolic"
 
+#define PHOTOS_ICON_PROCESS_STOP_SYMBOLIC "process-stop-symbolic"
+
 #define PHOTOS_ICON_SYSTEM_SYMBOLIC "emblem-system-symbolic"
 
 #define PHOTOS_ICON_VIDEO_DISPLAY_SYMBOLIC "video-display-symbolic"
diff --git a/src/photos-print-notification.c b/src/photos-print-notification.c
new file mode 100644
index 0000000..b67b662
--- /dev/null
+++ b/src/photos-print-notification.c
@@ -0,0 +1,211 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-icons.h"
+#include "photos-print-notification.h"
+#include "photos-notification-manager.h"
+
+
+struct _PhotosPrintNotificationPrivate
+{
+  GtkPrintOperation *print_op;
+  GtkWidget *ntfctn_mngr;
+  GtkWidget *spinner;
+  GtkWidget *status_label;
+  GtkWidget *stop_button;
+};
+
+enum
+{
+  PROP_0,
+  PROP_PRINT_OP
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosPrintNotification, photos_print_notification, GTK_TYPE_GRID);
+
+
+static void
+photos_print_notification_begin_print (PhotosPrintNotification *self)
+{
+  PhotosPrintNotificationPrivate *priv = self->priv;
+
+  photos_notification_manager_add_notification (PHOTOS_NOTIFICATION_MANAGER (priv->ntfctn_mngr),
+                                                GTK_WIDGET (self));
+  gtk_spinner_start (GTK_SPINNER (priv->spinner));
+}
+
+
+static void
+photos_print_notification_status_changed (PhotosPrintNotification *self)
+{
+  PhotosPrintNotificationPrivate *priv = self->priv;
+  const gchar *status_str;
+  gchar *job_name = NULL;
+  gchar *status = NULL;
+
+  status_str = gtk_print_operation_get_status_string (priv->print_op);
+  g_object_get (priv->print_op, "job-name", &job_name, NULL);
+  status = g_strdup_printf (_("Printing “%s”: %s"), job_name, status_str);
+  gtk_label_set_text (GTK_LABEL (priv->status_label), status);
+
+  if (gtk_print_operation_is_finished (priv->print_op))
+    gtk_widget_destroy (GTK_WIDGET (self));
+
+  g_free (job_name);
+  g_free (status);
+}
+
+
+static void
+photos_print_notification_stop_clicked (PhotosPrintNotification *self)
+{
+  gtk_print_operation_cancel (self->priv->print_op);
+  gtk_widget_destroy (GTK_WIDGET (self));
+}
+
+
+static void
+photos_print_notification_constructed (GObject *object)
+{
+  PhotosPrintNotification *self = PHOTOS_PRINT_NOTIFICATION (object);
+  PhotosPrintNotificationPrivate *priv = self->priv;
+
+  G_OBJECT_CLASS (photos_print_notification_parent_class)->constructed (object);
+
+  g_signal_connect_object (priv->print_op,
+                           "begin-print",
+                           G_CALLBACK (photos_print_notification_begin_print),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (priv->print_op,
+                           "status-changed",
+                           G_CALLBACK (photos_print_notification_status_changed),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+
+static void
+photos_print_notification_dispose (GObject *object)
+{
+  PhotosPrintNotification *self = PHOTOS_PRINT_NOTIFICATION (object);
+  PhotosPrintNotificationPrivate *priv = self->priv;
+
+  g_clear_object (&priv->print_op);
+  g_clear_object (&priv->ntfctn_mngr);
+
+  G_OBJECT_CLASS (photos_print_notification_parent_class)->dispose (object);
+}
+
+
+static void
+photos_print_notification_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
+{
+  PhotosPrintNotification *self = PHOTOS_PRINT_NOTIFICATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_PRINT_OP:
+      self->priv->print_op = GTK_PRINT_OPERATION (g_value_dup_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_print_notification_init (PhotosPrintNotification *self)
+{
+  PhotosPrintNotificationPrivate *priv;
+  GtkWidget *image;
+
+  self->priv = photos_print_notification_get_instance_private (self);
+  priv = self->priv;
+
+  priv->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+
+  priv->spinner = gtk_spinner_new ();
+  gtk_widget_set_size_request (priv->spinner, 16, 16);
+  gtk_container_add (GTK_CONTAINER (self), priv->spinner);
+
+  priv->status_label = gtk_label_new (NULL);
+  gtk_widget_set_halign (priv->status_label, GTK_ALIGN_START);
+  gtk_container_add (GTK_CONTAINER (self), priv->status_label);
+
+  image = gtk_image_new_from_icon_name (PHOTOS_ICON_PROCESS_STOP_SYMBOLIC, GTK_ICON_SIZE_INVALID);
+  gtk_widget_set_margin_bottom (image, 2);
+  gtk_widget_set_margin_top (image, 2);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
+
+  priv->stop_button = gtk_button_new ();
+  gtk_widget_set_valign (priv->stop_button, GTK_ALIGN_CENTER);
+  gtk_container_add (GTK_CONTAINER (priv->stop_button), image);
+  gtk_container_add (GTK_CONTAINER (self), priv->stop_button);
+  g_signal_connect_swapped (priv->stop_button,
+                            "clicked",
+                            G_CALLBACK (photos_print_notification_stop_clicked),
+                            self);
+}
+
+
+static void
+photos_print_notification_class_init (PhotosPrintNotificationClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructed = photos_print_notification_constructed;
+  object_class->dispose = photos_print_notification_dispose;
+  object_class->set_property = photos_print_notification_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_PRINT_OP,
+                                   g_param_spec_object ("print-op",
+                                                        "GtkPrintOperation object",
+                                                        "The print operation in progress",
+                                                        GTK_TYPE_PRINT_OPERATION,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+}
+
+
+GtkWidget *
+photos_print_notification_new (GtkPrintOperation *print_op)
+{
+  return g_object_new (PHOTOS_TYPE_PRINT_NOTIFICATION,
+                       "column-spacing", 12,
+                       "margin-start", 12,
+                       "margin-end", 12,
+                       "orientation", GTK_ORIENTATION_HORIZONTAL,
+                       "print-op", print_op,
+                       NULL);
+}
diff --git a/src/photos-print-notification.h b/src/photos-print-notification.h
new file mode 100644
index 0000000..9d64109
--- /dev/null
+++ b/src/photos-print-notification.h
@@ -0,0 +1,75 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_PRINT_NOTIFICATION_H
+#define PHOTOS_PRINT_NOTIFICATION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_PRINT_NOTIFICATION (photos_print_notification_get_type ())
+
+#define PHOTOS_PRINT_NOTIFICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_PRINT_NOTIFICATION, PhotosPrintNotification))
+
+#define PHOTOS_PRINT_NOTIFICATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_PRINT_NOTIFICATION, PhotosPrintNotificationClass))
+
+#define PHOTOS_IS_PRINT_NOTIFICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_PRINT_NOTIFICATION))
+
+#define PHOTOS_IS_PRINT_NOTIFICATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_PRINT_NOTIFICATION))
+
+#define PHOTOS_PRINT_NOTIFICATION_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_PRINT_NOTIFICATION, PhotosPrintNotificationClass))
+
+typedef struct _PhotosPrintNotification        PhotosPrintNotification;
+typedef struct _PhotosPrintNotificationClass   PhotosPrintNotificationClass;
+typedef struct _PhotosPrintNotificationPrivate PhotosPrintNotificationPrivate;
+
+struct _PhotosPrintNotification
+{
+  GtkGrid parent_instance;
+  PhotosPrintNotificationPrivate *priv;
+};
+
+struct _PhotosPrintNotificationClass
+{
+  GtkGridClass parent_class;
+};
+
+GType               photos_print_notification_get_type           (void) G_GNUC_CONST;
+
+GtkWidget          *photos_print_notification_new                (GtkPrintOperation *print_op);
+
+G_END_DECLS
+
+#endif /* PHOTOS_PRINT_NOTIFICATION_H */


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