[gnome-photos/wip/foo: 6/7] Add PhotosPrintOperation



commit 2bbe414dd63046f88773e4f953dda20629db5c45
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 25 23:11:48 2013 +0100

    Add PhotosPrintOperation

 src/Makefile.am              |    2 +
 src/photos-print-operation.c |  193 ++++++++++++++++++++++++++++++++++++++++++
 src/photos-print-operation.h |   73 ++++++++++++++++
 3 files changed, 268 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 51cd2c2..a27a96a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,8 @@ gnome_photos_SOURCES = \
        photos-organize-collection-view.h \
        photos-preview-view.c \
        photos-preview-view.h \
+       photos-print-operation.c \
+       photos-print-operation.h \
        photos-properties-dialog.c \
        photos-properties-dialog.h \
        photos-query.c \
diff --git a/src/photos-print-operation.c b/src/photos-print-operation.c
new file mode 100644
index 0000000..9dc27a1
--- /dev/null
+++ b/src/photos-print-operation.c
@@ -0,0 +1,193 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-print-operation.h"
+
+
+struct _PhotosPrintOperationPrivate
+{
+  GtkUnit unit;
+  PhotosBaseItem *item;
+  gdouble left_margin;
+  gdouble top_margin;
+  gdouble scale_factor;
+};
+
+
+enum
+{
+  PROP_0,
+  PROP_ITEM
+};
+
+
+G_DEFINE_TYPE (PhotosPrintOperation, photos_print_operation, GTK_TYPE_PRINT_OPERATION);
+
+
+static void
+photos_print_operation_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr)
+{
+}
+
+
+static void
+photos_print_operation_constructed (GObject *object)
+{
+  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
+  PhotosPrintOperationPrivate *priv = self->priv;
+  GeglRectangle bbox;
+  GtkPageSetup *page_setup;
+  gchar *name;
+
+  page_setup = gtk_page_setup_new ();
+  gtk_print_operation_set_default_page_setup (GTK_PRINT_OPERATION (self), page_setup);
+
+  bbox = photos_base_item_get_bbox (priv->item);
+  if (bbox.height >= bbox.width)
+    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
+  else
+    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
+
+  g_object_unref (page_setup);
+
+  name = g_strdup (photos_base_item_get_name (priv->item));
+  if (name == NULL)
+    {
+      GFile *file;
+      const gchar *uri;
+      gchar *basename;
+
+      uri = photos_base_item_get_uri (priv->item);
+      file = g_file_new_for_uri (uri);
+      basename = g_file_get_basename (file);
+
+      if (g_utf8_validate (basename, -1, NULL))
+        name = g_strdup (basename);
+      else
+        name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
+
+      g_free (basename);
+      g_object_unref (file);
+    }
+  gtk_print_operation_set_job_name (GTK_PRINT_OPERATION (self), name);
+
+  G_OBJECT_CLASS (photos_print_operation_parent_class)->constructed (object);
+}
+
+
+static void
+photos_print_operation_dispose (GObject *object)
+{
+  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
+  PhotosPrintOperationPrivate *priv = self->priv;
+
+  g_clear_object (&priv->item);
+
+  G_OBJECT_CLASS (photos_print_operation_parent_class)->dispose (object);
+}
+
+
+static void
+photos_print_operation_finalize (GObject *object)
+{
+  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
+  PhotosPrintOperationPrivate *priv = self->priv;
+
+  G_OBJECT_CLASS (photos_print_operation_parent_class)->finalize (object);
+}
+
+
+static void
+photos_print_operation_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_ITEM:
+      self->priv->item = PHOTOS_BASE_ITEM (g_value_dup_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_print_operation_init (PhotosPrintOperation *self)
+{
+  PhotosPrintOperationPrivate *priv;
+  GtkPrintSettings *settings;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            PHOTOS_TYPE_PRINT_OPERATION,
+                                            PhotosPrintOperationPrivate);
+  priv = self->priv;
+
+  priv->unit = GTK_UNIT_INCH;
+  priv->left_margin = 0.0;
+  priv->top_margin = 0.0;
+  priv->scale_factor = 100.0;
+
+  settings = gtk_print_settings_new ();
+  gtk_print_operation_set_print_settings (GTK_PRINT_OPERATION (self), settings);
+  g_object_unref (settings);
+
+  gtk_print_operation_set_embed_page_setup (GTK_PRINT_OPERATION (self), TRUE);
+  gtk_print_operation_set_n_pages (GTK_PRINT_OPERATION (self), 1);
+}
+
+
+static void
+photos_print_operation_class_init (PhotosPrintOperationClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkPrintOperationClass *operation_class = GTK_PRINT_OPERATION_CLASS (class);
+
+  object_class->constructed= photos_print_operation_constructed;
+  object_class->dispose = photos_print_operation_dispose;
+  object_class->finalize = photos_print_operation_finalize;
+  object_class->set_property = photos_print_operation_set_property;
+  operation_class->draw_page = photos_print_operation_draw_page;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ITEM,
+                                   g_param_spec_object ("item",
+                                                        "PhotosBaseItem object",
+                                                        "The item to print",
+                                                        PHOTOS_TYPE_BASE_ITEM,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_type_class_add_private (class, sizeof (PhotosPrintOperationPrivate));
+}
+
+
+GtkPrintOperation *
+photos_print_operation_new (PhotosBaseItem *item)
+{
+  return g_object_new (PHOTOS_TYPE_PRINT_OPERATION, "item", item, NULL);
+}
diff --git a/src/photos-print-operation.h b/src/photos-print-operation.h
new file mode 100644
index 0000000..f968fd2
--- /dev/null
+++ b/src/photos-print-operation.h
@@ -0,0 +1,73 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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.
+ */
+
+#ifndef PHOTOS_PRINT_OPERATION_H
+#define PHOTOS_PRINT_OPERATION_H
+
+#include <gtk/gtk.h>
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_PRINT_OPERATION (photos_print_operation_get_type ())
+
+#define PHOTOS_PRINT_OPERATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_PRINT_OPERATION, PhotosPrintOperation))
+
+#define PHOTOS_PRINT_OPERATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_PRINT_OPERATION, PhotosPrintOperationClass))
+
+#define PHOTOS_IS_PRINT_OPERATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_PRINT_OPERATION))
+
+#define PHOTOS_IS_PRINT_OPERATION_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_PRINT_OPERATION))
+
+#define PHOTOS_PRINT_OPERATION_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_PRINT_OPERATION, PhotosPrintOperationClass))
+
+typedef struct _PhotosPrintOperation        PhotosPrintOperation;
+typedef struct _PhotosPrintOperationClass   PhotosPrintOperationClass;
+typedef struct _PhotosPrintOperationPrivate PhotosPrintOperationPrivate;
+
+struct _PhotosPrintOperation
+{
+  GtkPrintOperation parent_instance;
+  PhotosPrintOperationPrivate *priv;
+};
+
+struct _PhotosPrintOperationClass
+{
+  GtkPrintOperationClass parent_class;
+};
+
+GType               photos_print_operation_get_type           (void) G_GNUC_CONST;
+
+GtkPrintOperation  *photos_print_operation_new                (PhotosBaseItem *item);
+
+G_END_DECLS
+
+#endif /* PHOTOS_PRINT_OPERATION_H */


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