~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to panels/printers/pp-cups.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright 2012  Red Hat, Inc,
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Author: Marek Kasik <mkasik@redhat.com>
 
20
 */
 
21
 
 
22
#include "pp-cups.h"
 
23
 
 
24
G_DEFINE_TYPE (PpCups, pp_cups, G_TYPE_OBJECT);
 
25
 
 
26
static void
 
27
pp_cups_finalize (GObject *object)
 
28
{
 
29
  G_OBJECT_CLASS (pp_cups_parent_class)->finalize (object);
 
30
}
 
31
 
 
32
static void
 
33
pp_cups_class_init (PpCupsClass *klass)
 
34
{
 
35
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
36
 
 
37
  gobject_class->finalize = pp_cups_finalize;
 
38
}
 
39
 
 
40
static void
 
41
pp_cups_init (PpCups *cups)
 
42
{
 
43
}
 
44
 
 
45
PpCups *
 
46
pp_cups_new ()
 
47
{
 
48
  return g_object_new (PP_TYPE_CUPS, NULL);
 
49
}
 
50
 
 
51
typedef struct
 
52
{
 
53
  PpCupsDests *dests;
 
54
} CGDData;
 
55
 
 
56
static void
 
57
_pp_cups_get_dests_thread (GSimpleAsyncResult *res,
 
58
                           GObject            *object,
 
59
                           GCancellable       *cancellable)
 
60
{
 
61
  CGDData *data;
 
62
 
 
63
  data = g_simple_async_result_get_op_res_gpointer (res);
 
64
 
 
65
  data->dests = g_new0 (PpCupsDests, 1);
 
66
  data->dests->num_of_dests = cupsGetDests (&data->dests->dests);
 
67
}
 
68
 
 
69
static void
 
70
cgd_data_free (CGDData *data)
 
71
{
 
72
  if (data)
 
73
    {
 
74
      if (data->dests)
 
75
        {
 
76
          cupsFreeDests (data->dests->num_of_dests, data->dests->dests);
 
77
          g_free (data->dests);
 
78
        }
 
79
 
 
80
      g_free (data);
 
81
    }
 
82
}
 
83
 
 
84
void
 
85
pp_cups_get_dests_async (PpCups              *cups,
 
86
                         GCancellable        *cancellable,
 
87
                         GAsyncReadyCallback  callback,
 
88
                         gpointer             user_data)
 
89
{
 
90
  GSimpleAsyncResult *res;
 
91
  CGDData            *data;
 
92
 
 
93
  res = g_simple_async_result_new (G_OBJECT (cups), callback, user_data, pp_cups_get_dests_async);
 
94
  data = g_new0 (CGDData, 1);
 
95
  data->dests = NULL;
 
96
 
 
97
  g_simple_async_result_set_check_cancellable (res, cancellable);
 
98
  g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) cgd_data_free);
 
99
  g_simple_async_result_run_in_thread (res, _pp_cups_get_dests_thread, 0, cancellable);
 
100
 
 
101
  g_object_unref (res);
 
102
}
 
103
 
 
104
PpCupsDests *
 
105
pp_cups_get_dests_finish (PpCups        *cups,
 
106
                          GAsyncResult  *res,
 
107
                          GError       **error)
 
108
{
 
109
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
 
110
  PpCupsDests        *result = NULL;
 
111
  CGDData            *data;
 
112
 
 
113
  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_cups_get_dests_async);
 
114
 
 
115
  if (g_simple_async_result_propagate_error (simple, error))
 
116
    {
 
117
      return NULL;
 
118
    }
 
119
 
 
120
  data = g_simple_async_result_get_op_res_gpointer (simple);
 
121
  result = data->dests;
 
122
  data->dests = NULL;
 
123
 
 
124
  return result;
 
125
}