~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpdbusservice.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-08-22 11:50:05 UTC
  • mfrom: (0.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20080822115005-yxj5svf3v9x1mkr7
Tags: upstream-2.4.7
ImportĀ upstreamĀ versionĀ 2.4.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * GimpDBusService
5
 
 * Copyright (C) 2007 Sven Neumann <sven@gimp.org>
 
5
 * Copyright (C) 2007, 2008 Sven Neumann <sven@gimp.org>
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
36
36
#include "gimpuimanager.c"
37
37
 
38
38
 
 
39
typedef struct
 
40
{
 
41
  gchar    *uri;
 
42
  gboolean  as_new;
 
43
} OpenData;
 
44
 
 
45
 
39
46
static void  gimp_dbus_service_class_init (GimpDBusServiceClass *klass);
40
47
static void  gimp_dbus_service_init       (GimpDBusService      *service);
 
48
static void  gimp_dbus_service_dispose    (GObject              *object);
 
49
static void  gimp_dbus_service_finalize   (GObject              *object);
 
50
 
 
51
static void  gimp_dbus_service_queue_open (GimpDBusService      *service,
 
52
                                           const gchar          *uri,
 
53
                                           gboolean              as_new);
 
54
 
 
55
static OpenData * gimp_dbus_service_open_data_new  (GimpDBusService *service,
 
56
                                                    const gchar     *uri,
 
57
                                                    gboolean         as_new);
 
58
static void       gimp_dbus_service_open_data_free (OpenData        *data);
 
59
 
41
60
 
42
61
G_DEFINE_TYPE (GimpDBusService, gimp_dbus_service, G_TYPE_OBJECT)
43
62
 
 
63
#define parent_class gimp_dbus_service_parent_class
 
64
 
44
65
 
45
66
static void
46
67
gimp_dbus_service_class_init (GimpDBusServiceClass *klass)
47
68
{
 
69
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
70
 
 
71
  object_class->dispose  = gimp_dbus_service_dispose;
 
72
  object_class->finalize = gimp_dbus_service_finalize;
 
73
 
48
74
  dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
49
75
                                   &dbus_glib_gimp_object_info);
50
76
}
52
78
static void
53
79
gimp_dbus_service_init (GimpDBusService *service)
54
80
{
 
81
  service->queue = g_queue_new ();
55
82
}
56
83
 
57
84
GObject *
68
95
  return G_OBJECT (service);
69
96
}
70
97
 
 
98
static void
 
99
gimp_dbus_service_dispose (GObject *object)
 
100
{
 
101
  GimpDBusService *service = GIMP_DBUS_SERVICE (object);
 
102
 
 
103
  if (service->source)
 
104
    {
 
105
      g_source_remove (g_source_get_id (service->source));
 
106
      service->source = NULL;
 
107
    }
 
108
 
 
109
  while (! g_queue_is_empty (service->queue))
 
110
    {
 
111
      gimp_dbus_service_open_data_free (g_queue_pop_head (service->queue));
 
112
    }
 
113
 
 
114
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
115
}
 
116
 
 
117
static void
 
118
gimp_dbus_service_finalize (GObject *object)
 
119
{
 
120
  GimpDBusService *service = GIMP_DBUS_SERVICE (object);
 
121
 
 
122
  if (service->queue)
 
123
    {
 
124
      g_queue_free (service->queue);
 
125
      service->queue = NULL;
 
126
    }
 
127
 
 
128
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
129
}
 
130
 
71
131
gboolean
72
132
gimp_dbus_service_open (GimpDBusService  *service,
73
133
                        const gchar      *uri,
78
138
  g_return_val_if_fail (uri != NULL, FALSE);
79
139
  g_return_val_if_fail (success != NULL, FALSE);
80
140
 
81
 
  *success = file_open_from_command_line (service->gimp, uri, FALSE);
 
141
  gimp_dbus_service_queue_open (service, uri, FALSE);
 
142
 
 
143
  /*  The call always succeeds as it is handled in one way or another.
 
144
   *  Even presenting an error message is considered success ;-)
 
145
   */
 
146
  *success = TRUE;
82
147
 
83
148
  return TRUE;
84
149
}
93
158
  g_return_val_if_fail (uri != NULL, FALSE);
94
159
  g_return_val_if_fail (success != NULL, FALSE);
95
160
 
96
 
  *success = file_open_from_command_line (service->gimp, uri, TRUE);
 
161
  gimp_dbus_service_queue_open (service, uri, TRUE);
 
162
 
 
163
  /*  The call always succeeds as it is handled in one way or another.
 
164
   *  Even presenting an error message is considered success ;-)
 
165
   */
 
166
  *success = TRUE;
97
167
 
98
168
  return TRUE;
99
169
}
116
186
  return TRUE;
117
187
}
118
188
 
 
189
static OpenData *
 
190
gimp_dbus_service_open_data_new (GimpDBusService *service,
 
191
                                 const gchar     *uri,
 
192
                                 gboolean         as_new)
 
193
{
 
194
  OpenData *data = g_slice_new (OpenData);
 
195
 
 
196
  data->uri    = g_strdup (uri);
 
197
  data->as_new = as_new;
 
198
 
 
199
  return data;
 
200
}
 
201
 
 
202
static void
 
203
gimp_dbus_service_open_data_free (OpenData *data)
 
204
{
 
205
  g_free (data->uri);
 
206
  g_slice_free (OpenData, data);
 
207
}
 
208
 
 
209
static gboolean
 
210
gimp_dbus_service_open_idle (GimpDBusService *service)
 
211
{
 
212
  OpenData *data = g_queue_pop_tail (service->queue);
 
213
 
 
214
  if (data)
 
215
    {
 
216
      file_open_from_command_line (service->gimp, data->uri, data->as_new);
 
217
 
 
218
      gimp_dbus_service_open_data_free (data);
 
219
 
 
220
      return TRUE;
 
221
    }
 
222
 
 
223
  service->source = NULL;
 
224
 
 
225
  return FALSE;
 
226
}
 
227
 
 
228
static void
 
229
gimp_dbus_service_queue_open (GimpDBusService *service,
 
230
                              const gchar     *uri,
 
231
                              gboolean         as_new)
 
232
{
 
233
  g_queue_push_tail (service->queue,
 
234
                     gimp_dbus_service_open_data_new (service, uri, as_new));
 
235
 
 
236
  if (! service->source)
 
237
    {
 
238
      service->source = g_idle_source_new ();
 
239
 
 
240
      g_source_set_callback (service->source,
 
241
                             (GSourceFunc) gimp_dbus_service_open_idle, service,
 
242
                             NULL);
 
243
      g_source_attach (service->source, NULL);
 
244
      g_source_unref (service->source);
 
245
    }
 
246
}
 
247
 
119
248
#endif /* HAVE_DBUS_GLIB */