~mfisch/brasero/update-to-3.8.0

« back to all changes in this revision

Viewing changes to libbrasero-media/burn-hal-watch.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-07-14 14:13:00 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20090714141300-e08q13sp48b2xzwd
Tags: 2.27.4-0ubuntu1
* New upstream release: (LP: #399112)
  - Hal support removed, now relies on GIO only for drives/media probing
  - New layout for size reporting in data/audio/video project
  - Lot's of bug fixes
  - Fixed some memleaks
  - Bump libbrasero-media version to reflect changes (important to packagers)
  - Fix #582261 – brasero shows 0% done, while continues burning disc
  - Fix #582513 – Bogus VIDEO_TS directory error if AUDIO_TS directory present
  - Fix #573805 – "Increase compatibility with Windows systems"?
  - Fix #585190 – remove 0 from 03 % status
  - Fix #586744 – Use AS_HELP_STRING for configure switches
  - Fix #584793 – Poor language in warning dialog when attempting to burn an audio CD onto a CDRW
  - Fix #580617 – Brasero floods .xsession-errors log with "Unknown (or already deleted) monitored directory" warnings
  - Fix #563501 – Brasero burning window shouldn't try to show drive speed while is converting audio files
  - Fix #485719 – Burn dialog CD icon
  - Fix #585481 – Deep hierarchy warning
  - Fix #554070 – The need of a "replace all" and "replace non" button
  - Fix #582461 – Brasero hangs at normalizing tracks
  - Fix #587284 – nautilus hangs every time
  - Fix #574093 – Caret visible in instructions for project creation
  - Fix #581742 – port from HAL to DeviceKit-disks
  - Fix #573801 – Bad error message when burning empty burn:///
  - Fix #573486 – Various i18n and string issues for good
  - Fix #587399 – License clarification
  - Fix #587554 – Unclear meaning of text
  - Fix #582979 – brasero should not include Categories in mime handler .desktop files
  - Fix #586040 – duplicated command listed in open-with dialog
  - Fixes for #573486 – Various i18n and string issues
* debian/control.in:
  - Add in missing comma in brasero suggests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
/*
3
 
 * Libbrasero-media
4
 
 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
5
 
 *
6
 
 * Libbrasero-media is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * The Libbrasero-media authors hereby grant permission for non-GPL compatible
12
 
 * GStreamer plugins to be used and distributed together with GStreamer
13
 
 * and Libbrasero-media. This permission is above and beyond the permissions granted
14
 
 * by the GPL license by which Libbrasero-media is covered. If you modify this code
15
 
 * you may extend this exception to your version of the code, but you are not
16
 
 * obligated to do so. If you do not wish to do so, delete this exception
17
 
 * statement from your version.
18
 
 * 
19
 
 * Libbrasero-media is distributed in the hope that it will be useful,
20
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
 * GNU Library General Public License for more details.
23
 
 * 
24
 
 * You should have received a copy of the GNU General Public License
25
 
 * along with this program; if not, write to:
26
 
 *      The Free Software Foundation, Inc.,
27
 
 *      51 Franklin Street, Fifth Floor
28
 
 *      Boston, MA  02110-1301, USA.
29
 
 */
30
 
 
31
 
#ifdef HAVE_CONFIG_H
32
 
#  include <config.h>
33
 
#endif
34
 
 
35
 
#include <glib.h>
36
 
#include <glib-object.h>
37
 
 
38
 
#include <dbus/dbus.h>
39
 
#include <dbus/dbus-glib.h>
40
 
#include <dbus/dbus-glib-lowlevel.h>
41
 
 
42
 
#include <libhal.h>
43
 
 
44
 
#include "brasero-media.h"
45
 
#include "brasero-media-private.h"
46
 
 
47
 
#include "burn-hal-watch.h"
48
 
#include "libbrasero-marshal.h"
49
 
 
50
 
typedef struct _BraseroHALWatchPrivate BraseroHALWatchPrivate;
51
 
struct _BraseroHALWatchPrivate
52
 
{
53
 
        LibHalContext * ctx;
54
 
};
55
 
 
56
 
#define BRASERO_HAL_WATCH_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_HAL_WATCH, BraseroHALWatchPrivate))
57
 
 
58
 
enum
59
 
{
60
 
        PROPERTY_CHANGED,
61
 
        DEVICE_ADDED,
62
 
        DEVICE_REMOVED,
63
 
        LAST_SIGNAL
64
 
};
65
 
 
66
 
 
67
 
static guint hal_watch_signals[LAST_SIGNAL] = { 0 };
68
 
 
69
 
G_DEFINE_TYPE (BraseroHALWatch, brasero_hal_watch, G_TYPE_OBJECT);
70
 
 
71
 
LibHalContext *
72
 
brasero_hal_watch_get_ctx (BraseroHALWatch *self)
73
 
{
74
 
        BraseroHALWatchPrivate *priv;
75
 
 
76
 
        priv = BRASERO_HAL_WATCH_PRIVATE (self);
77
 
        if (!priv->ctx)
78
 
                BRASERO_MEDIA_LOG ("HAL context is NULL");
79
 
 
80
 
        return priv->ctx;
81
 
}
82
 
 
83
 
static void
84
 
brasero_hal_watch_property_changed_cb (LibHalContext *ctx,
85
 
                                       const char *udi,
86
 
                                       const char *key,
87
 
                                       dbus_bool_t is_removed,
88
 
                                       dbus_bool_t is_added)
89
 
{
90
 
        BraseroHALWatch *self;
91
 
 
92
 
        self = libhal_ctx_get_user_data (ctx);
93
 
        g_signal_emit (self,
94
 
                       hal_watch_signals [PROPERTY_CHANGED],
95
 
                       0,
96
 
                       udi,
97
 
                       key);
98
 
}
99
 
 
100
 
static void
101
 
brasero_hal_watch_device_added_cb (LibHalContext *ctx,
102
 
                                   const char *udi)
103
 
{
104
 
        BraseroHALWatch *self;
105
 
 
106
 
        self = libhal_ctx_get_user_data (ctx);
107
 
        g_signal_emit (self,
108
 
                       hal_watch_signals [DEVICE_ADDED],
109
 
                       0,
110
 
                       udi);
111
 
}
112
 
 
113
 
static void
114
 
brasero_hal_watch_device_removed_cb (LibHalContext *ctx,
115
 
                                     const char *udi)
116
 
{
117
 
        BraseroHALWatch *self;
118
 
 
119
 
        self = libhal_ctx_get_user_data (ctx);
120
 
        g_signal_emit (self,
121
 
                       hal_watch_signals [DEVICE_REMOVED],
122
 
                       0,
123
 
                       udi);
124
 
}
125
 
 
126
 
static void
127
 
brasero_hal_watch_init (BraseroHALWatch *object)
128
 
{
129
 
        DBusError error;
130
 
        BraseroHALWatchPrivate *priv;
131
 
        DBusConnection *dbus_connection = NULL;
132
 
 
133
 
        priv = BRASERO_HAL_WATCH_PRIVATE (object);
134
 
 
135
 
        /* initialize the connection with hal */
136
 
        priv->ctx = libhal_ctx_new ();
137
 
        if (priv->ctx == NULL) {
138
 
                g_warning ("Cannot initialize hal library\n");
139
 
                goto error;
140
 
        }
141
 
 
142
 
        dbus_error_init (&error);
143
 
        dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
144
 
        if (dbus_error_is_set (&error)) {
145
 
                g_warning ("Cannot connect to DBus %s\n", error.message);
146
 
                dbus_error_free (&error);
147
 
                goto error;
148
 
        }
149
 
 
150
 
        dbus_connection_setup_with_g_main (dbus_connection, NULL);
151
 
        libhal_ctx_set_dbus_connection (priv->ctx, dbus_connection);
152
 
 
153
 
        libhal_ctx_set_user_data (priv->ctx, object);
154
 
        libhal_ctx_set_cache (priv->ctx, FALSE);
155
 
 
156
 
        /* monitor devices addition and removal */
157
 
        libhal_ctx_set_device_added (priv->ctx, brasero_hal_watch_device_added_cb);
158
 
        libhal_ctx_set_device_removed (priv->ctx, brasero_hal_watch_device_removed_cb);
159
 
        libhal_ctx_set_device_property_modified (priv->ctx, brasero_hal_watch_property_changed_cb);
160
 
 
161
 
        if (libhal_ctx_init (priv->ctx, &error))
162
 
                return;
163
 
 
164
 
        g_warning ("Failed to initialize hal : %s\n", error.message);
165
 
        dbus_error_free (&error);
166
 
 
167
 
error:
168
 
 
169
 
        libhal_ctx_shutdown (priv->ctx, NULL);
170
 
        libhal_ctx_free (priv->ctx);
171
 
        priv->ctx = NULL;
172
 
 
173
 
        if (dbus_connection)
174
 
                dbus_connection_unref (dbus_connection);
175
 
}
176
 
 
177
 
static void
178
 
brasero_hal_watch_finalize (GObject *object)
179
 
{
180
 
        BraseroHALWatchPrivate *priv;
181
 
 
182
 
        priv = BRASERO_HAL_WATCH_PRIVATE (object);
183
 
 
184
 
        if (priv->ctx) {
185
 
                DBusConnection *connection;
186
 
 
187
 
                connection = libhal_ctx_get_dbus_connection (priv->ctx);
188
 
                dbus_connection_unref (connection);
189
 
 
190
 
                libhal_ctx_shutdown (priv->ctx, NULL);
191
 
                libhal_ctx_free (priv->ctx);
192
 
                priv->ctx = NULL;
193
 
        }
194
 
 
195
 
        G_OBJECT_CLASS (brasero_hal_watch_parent_class)->finalize (object);
196
 
}
197
 
 
198
 
static void
199
 
brasero_hal_watch_class_init (BraseroHALWatchClass *klass)
200
 
{
201
 
        GObjectClass* object_class = G_OBJECT_CLASS (klass);
202
 
 
203
 
        g_type_class_add_private (klass, sizeof (BraseroHALWatchPrivate));
204
 
 
205
 
        object_class->finalize = brasero_hal_watch_finalize;
206
 
 
207
 
        hal_watch_signals[PROPERTY_CHANGED] =
208
 
                g_signal_new ("property_changed",
209
 
                              G_OBJECT_CLASS_TYPE (klass),
210
 
                              G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
211
 
                              0,
212
 
                              NULL, NULL,
213
 
                              brasero_marshal_VOID__STRING_STRING,
214
 
                              G_TYPE_NONE, 2,
215
 
                              G_TYPE_STRING,
216
 
                              G_TYPE_STRING);
217
 
        hal_watch_signals[DEVICE_ADDED] =
218
 
                g_signal_new ("device_added",
219
 
                              G_OBJECT_CLASS_TYPE (klass),
220
 
                              G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
221
 
                              0,
222
 
                              NULL, NULL,
223
 
                              g_cclosure_marshal_VOID__STRING,
224
 
                              G_TYPE_NONE, 1,
225
 
                              G_TYPE_STRING);
226
 
        hal_watch_signals[DEVICE_REMOVED] =
227
 
                g_signal_new ("device_removed",
228
 
                              G_OBJECT_CLASS_TYPE (klass),
229
 
                              G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
230
 
                              0,
231
 
                              NULL, NULL,
232
 
                              g_cclosure_marshal_VOID__STRING,
233
 
                              G_TYPE_NONE, 1,
234
 
                              G_TYPE_STRING);
235
 
}
236
 
 
237
 
static BraseroHALWatch *singleton = NULL;
238
 
 
239
 
BraseroHALWatch *
240
 
brasero_hal_watch_get_default (void)
241
 
{
242
 
        if (singleton)
243
 
                return singleton;
244
 
 
245
 
        singleton = g_object_new (BRASERO_TYPE_HAL_WATCH, NULL);
246
 
        return singleton;
247
 
}
248
 
 
249
 
void
250
 
brasero_hal_watch_destroy (void)
251
 
{
252
 
        if (singleton) {
253
 
                g_object_unref (singleton);
254
 
                singleton = NULL;
255
 
        }
256
 
}