[gnome-control-center] printers: Add PpCups object for getting destinations



commit 5a2794a7fefaebe7c3467136a27ad8c9facda747
Author: Marek Kasik <mkasik redhat com>
Date:   Mon Sep 3 21:46:50 2012 +0200

    printers: Add PpCups object for getting destinations
    
    PpCups object represents local CUPS server. It contains
    asynchronous method for getting printers installed on
    the server. It is an asynchronous version of cupsGetDests().
    (#683229)

 panels/printers/Makefile.am |    2 +
 panels/printers/pp-cups.c   |  125 +++++++++++++++++++++++++++++++++++++++++++
 panels/printers/pp-cups.h   |   71 ++++++++++++++++++++++++
 3 files changed, 198 insertions(+), 0 deletions(-)
---
diff --git a/panels/printers/Makefile.am b/panels/printers/Makefile.am
index 0fb0c60..acd742b 100644
--- a/panels/printers/Makefile.am
+++ b/panels/printers/Makefile.am
@@ -22,6 +22,8 @@ ccpanels_LTLIBRARIES = libprinters.la
 
 libprinters_la_SOURCES =		\
 	printers-module.c		\
+	pp-cups.c			\
+	pp-cups.h			\
 	pp-utils.c			\
 	pp-utils.h			\
 	pp-ppd-option-widget.c		\
diff --git a/panels/printers/pp-cups.c b/panels/printers/pp-cups.c
new file mode 100644
index 0000000..b6beee3
--- /dev/null
+++ b/panels/printers/pp-cups.c
@@ -0,0 +1,125 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2012  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 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Marek Kasik <mkasik redhat com>
+ */
+
+#include "pp-cups.h"
+
+G_DEFINE_TYPE (PpCups, pp_cups, G_TYPE_OBJECT);
+
+static void
+pp_cups_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (pp_cups_parent_class)->finalize (object);
+}
+
+static void
+pp_cups_class_init (PpCupsClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = pp_cups_finalize;
+}
+
+static void
+pp_cups_init (PpCups *cups)
+{
+}
+
+PpCups *
+pp_cups_new ()
+{
+  return g_object_new (PP_TYPE_CUPS, NULL);
+}
+
+typedef struct
+{
+  PpCupsDests *dests;
+} CGDData;
+
+static void
+_pp_cups_get_dests_thread (GSimpleAsyncResult *res,
+                           GObject            *object,
+                           GCancellable       *cancellable)
+{
+  CGDData *data;
+
+  data = g_simple_async_result_get_op_res_gpointer (res);
+
+  data->dests = g_new0 (PpCupsDests, 1);
+  data->dests->num_of_dests = cupsGetDests (&data->dests->dests);
+}
+
+static void
+cgd_data_free (CGDData *data)
+{
+  if (data)
+    {
+      if (data->dests)
+        {
+          cupsFreeDests (data->dests->num_of_dests, data->dests->dests);
+          g_free (data->dests);
+        }
+
+      g_free (data);
+    }
+}
+
+void
+pp_cups_get_dests_async (PpCups              *cups,
+                         GCancellable        *cancellable,
+                         GAsyncReadyCallback  callback,
+                         gpointer             user_data)
+{
+  GSimpleAsyncResult *res;
+  CGDData            *data;
+
+  res = g_simple_async_result_new (G_OBJECT (cups), callback, user_data, pp_cups_get_dests_async);
+  data = g_new0 (CGDData, 1);
+  data->dests = NULL;
+
+  g_simple_async_result_set_check_cancellable (res, cancellable);
+  g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) cgd_data_free);
+  g_simple_async_result_run_in_thread (res, _pp_cups_get_dests_thread, 0, cancellable);
+
+  g_object_unref (res);
+}
+
+PpCupsDests *
+pp_cups_get_dests_finish (PpCups        *cups,
+                          GAsyncResult  *res,
+                          GError       **error)
+{
+  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+  PpCupsDests        *result = NULL;
+  CGDData            *data;
+
+  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_cups_get_dests_async);
+
+  if (g_simple_async_result_propagate_error (simple, error))
+    {
+      return NULL;
+    }
+
+  data = g_simple_async_result_get_op_res_gpointer (simple);
+  result = data->dests;
+  data->dests = NULL;
+
+  return result;
+}
diff --git a/panels/printers/pp-cups.h b/panels/printers/pp-cups.h
new file mode 100644
index 0000000..27467f4
--- /dev/null
+++ b/panels/printers/pp-cups.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2012  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 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Marek Kasik <mkasik redhat com>
+ */
+
+#ifndef __PP_CUPS_H__
+#define __PP_CUPS_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include "pp-utils.h"
+
+G_BEGIN_DECLS
+
+#define PP_TYPE_CUPS         (pp_cups_get_type ())
+#define PP_CUPS(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), PP_TYPE_CUPS, PpCups))
+#define PP_CUPS_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), PP_TYPE_CUPS, PpCupsClass))
+#define PP_IS_CUPS(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), PP_TYPE_CUPS))
+#define PP_IS_CUPS_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), PP_TYPE_CUPS))
+#define PP_CUPS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PP_TYPE_CUPS, PpCupsClass))
+
+typedef struct{
+  cups_dest_t *dests;
+  gint         num_of_dests;
+} PpCupsDests;
+
+typedef struct _PpCups        PpCups;
+typedef struct _PpCupsClass   PpCupsClass;
+
+struct _PpCups
+{
+  GObject parent_instance;
+};
+
+struct _PpCupsClass
+{
+  GObjectClass parent_class;
+};
+
+GType        pp_cups_get_type         (void) G_GNUC_CONST;
+
+PpCups      *pp_cups_new              (void);
+
+void         pp_cups_get_dests_async  (PpCups               *cups,
+                                       GCancellable         *cancellable,
+                                       GAsyncReadyCallback   callback,
+                                       gpointer              user_data);
+
+PpCupsDests *pp_cups_get_dests_finish (PpCups               *cups,
+                                       GAsyncResult         *result,
+                                       GError              **error);
+
+G_END_DECLS
+
+#endif /* __PP_CUPS_H__ */



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