1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3 * Libbrasero-burn
4 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
5 *
6 * Libbrasero-burn 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-burn authors hereby grant permission for non-GPL compatible
12 * GStreamer plugins to be used and distributed together with GStreamer
13 * and Libbrasero-burn. This permission is above and beyond the permissions granted
14 * by the GPL license by which Libbrasero-burn 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-burn 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
36 #include "brasero-status.h"
37
38
39 typedef struct _BraseroStatusPrivate BraseroStatusPrivate;
40 struct _BraseroStatusPrivate
41 {
42 BraseroBurnResult res;
43 GError * error;
44 gdouble progress;
45 gchar * current_action;
46 };
47
48 #define BRASERO_STATUS_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_STATUS, BraseroStatusPrivate))
49
50 G_DEFINE_TYPE (BraseroStatus, brasero_status, G_TYPE_OBJECT);
51
52
53 /**
54 * brasero_status_new:
55 *
56 * Creates a new #BraseroStatus object.
57 *
58 * Return value: a #BraseroStatus.
59 **/
60
61 BraseroStatus *
brasero_status_new(void)62 brasero_status_new (void)
63 {
64 return g_object_new (BRASERO_TYPE_STATUS, NULL);
65 }
66
67 /**
68 * brasero_status_get_result:
69 * @status: a #BraseroStatus.
70 *
71 * After an object (see brasero_burn_track_get_status ()) has
72 * been requested its status, this function returns that status.
73 *
74 * Return value: a #BraseroBurnResult.
75 * BRASERO_BURN_OK if the object is ready.
76 * BRASERO_BURN_NOT_READY if some time should be given to the object before it is ready.
77 * BRASERO_BURN_ERR if there is an error.
78 **/
79
80 BraseroBurnResult
brasero_status_get_result(BraseroStatus * status)81 brasero_status_get_result (BraseroStatus *status)
82 {
83 BraseroStatusPrivate *priv;
84
85 g_return_val_if_fail (status != NULL, BRASERO_BURN_ERR);
86 g_return_val_if_fail (BRASERO_IS_STATUS (status), BRASERO_BURN_ERR);
87
88 priv = BRASERO_STATUS_PRIVATE (status);
89 return priv->res;
90 }
91
92 /**
93 * brasero_status_get_progress:
94 * @status: a #BraseroStatus.
95 *
96 * If brasero_status_get_result () returned BRASERO_BURN_NOT_READY,
97 * this function returns the progress regarding the operation completion.
98 *
99 * Return value: a #gdouble
100 **/
101
102 gdouble
brasero_status_get_progress(BraseroStatus * status)103 brasero_status_get_progress (BraseroStatus *status)
104 {
105 BraseroStatusPrivate *priv;
106
107 g_return_val_if_fail (status != NULL, -1.0);
108 g_return_val_if_fail (BRASERO_IS_STATUS (status), -1.0);
109
110 priv = BRASERO_STATUS_PRIVATE (status);
111 if (priv->res == BRASERO_BURN_OK)
112 return 1.0;
113
114 if (priv->res != BRASERO_BURN_NOT_READY)
115 return -1.0;
116
117 return priv->progress;
118 }
119
120 /**
121 * brasero_status_get_error:
122 * @status: a #BraseroStatus.
123 *
124 * If brasero_status_get_result () returned BRASERO_BURN_ERR,
125 * this function returns the error.
126 *
127 * Return value: a #GError
128 **/
129
130 GError *
brasero_status_get_error(BraseroStatus * status)131 brasero_status_get_error (BraseroStatus *status)
132 {
133 BraseroStatusPrivate *priv;
134
135 g_return_val_if_fail (status != NULL, NULL);
136 g_return_val_if_fail (BRASERO_IS_STATUS (status), NULL);
137
138 priv = BRASERO_STATUS_PRIVATE (status);
139 if (priv->res != BRASERO_BURN_ERR)
140 return NULL;
141
142 return g_error_copy (priv->error);
143 }
144
145 /**
146 * brasero_status_get_current_action:
147 * @status: a #BraseroStatus.
148 *
149 * If brasero_status_get_result () returned BRASERO_BURN_NOT_READY,
150 * this function returns a string describing the operation currently performed.
151 * Free the string when it is not needed anymore.
152 *
153 * Return value: a #gchar.
154 **/
155
156 gchar *
brasero_status_get_current_action(BraseroStatus * status)157 brasero_status_get_current_action (BraseroStatus *status)
158 {
159 gchar *string;
160 BraseroStatusPrivate *priv;
161
162 g_return_val_if_fail (status != NULL, NULL);
163 g_return_val_if_fail (BRASERO_IS_STATUS (status), NULL);
164
165 priv = BRASERO_STATUS_PRIVATE (status);
166
167 if (priv->res != BRASERO_BURN_NOT_READY)
168 return NULL;
169
170 string = g_strdup (priv->current_action);
171 return string;
172
173 }
174
175 /**
176 * brasero_status_set_completed:
177 * @status: a #BraseroStatus.
178 *
179 * Sets the status for a request to BRASERO_BURN_OK.
180 *
181 **/
182
183 void
brasero_status_set_completed(BraseroStatus * status)184 brasero_status_set_completed (BraseroStatus *status)
185 {
186 BraseroStatusPrivate *priv;
187
188 g_return_if_fail (status != NULL);
189 g_return_if_fail (BRASERO_IS_STATUS (status));
190
191 priv = BRASERO_STATUS_PRIVATE (status);
192
193 priv->res = BRASERO_BURN_OK;
194 priv->progress = 1.0;
195 }
196
197 /**
198 * brasero_status_set_not_ready:
199 * @status: a #BraseroStatus.
200 * @progress: a #gdouble or -1.0.
201 * @current_action: a #gchar or NULL.
202 *
203 * Sets the status for a request to BRASERO_BURN_NOT_READY.
204 * Allows to set a string describing the operation currently performed
205 * as well as the progress regarding the operation completion.
206 *
207 **/
208
209 void
brasero_status_set_not_ready(BraseroStatus * status,gdouble progress,const gchar * current_action)210 brasero_status_set_not_ready (BraseroStatus *status,
211 gdouble progress,
212 const gchar *current_action)
213 {
214 BraseroStatusPrivate *priv;
215
216 g_return_if_fail (status != NULL);
217 g_return_if_fail (BRASERO_IS_STATUS (status));
218
219 priv = BRASERO_STATUS_PRIVATE (status);
220
221 priv->res = BRASERO_BURN_NOT_READY;
222 priv->progress = progress;
223
224 if (priv->current_action)
225 g_free (priv->current_action);
226 priv->current_action = g_strdup (current_action);
227 }
228
229 /**
230 * brasero_status_set_running:
231 * @status: a #BraseroStatus.
232 * @progress: a #gdouble or -1.0.
233 * @current_action: a #gchar or NULL.
234 *
235 * Sets the status for a request to BRASERO_BURN_RUNNING.
236 * Allows to set a string describing the operation currently performed
237 * as well as the progress regarding the operation completion.
238 *
239 **/
240
241 void
brasero_status_set_running(BraseroStatus * status,gdouble progress,const gchar * current_action)242 brasero_status_set_running (BraseroStatus *status,
243 gdouble progress,
244 const gchar *current_action)
245 {
246 BraseroStatusPrivate *priv;
247
248 g_return_if_fail (status != NULL);
249 g_return_if_fail (BRASERO_IS_STATUS (status));
250
251 priv = BRASERO_STATUS_PRIVATE (status);
252
253 priv->res = BRASERO_BURN_RUNNING;
254 priv->progress = progress;
255
256 if (priv->current_action)
257 g_free (priv->current_action);
258 priv->current_action = g_strdup (current_action);
259 }
260
261 /**
262 * brasero_status_set_error:
263 * @status: a #BraseroStatus.
264 * @error: a #GError or NULL.
265 *
266 * Sets the status for a request to BRASERO_BURN_ERR.
267 *
268 **/
269
270 void
brasero_status_set_error(BraseroStatus * status,GError * error)271 brasero_status_set_error (BraseroStatus *status,
272 GError *error)
273 {
274 BraseroStatusPrivate *priv;
275
276 g_return_if_fail (status != NULL);
277 g_return_if_fail (BRASERO_IS_STATUS (status));
278
279 priv = BRASERO_STATUS_PRIVATE (status);
280
281 priv->res = BRASERO_BURN_ERR;
282 priv->progress = -1.0;
283
284 if (priv->error)
285 g_error_free (priv->error);
286 priv->error = error;
287 }
288
289 static void
brasero_status_init(BraseroStatus * object)290 brasero_status_init (BraseroStatus *object)
291 {}
292
293 static void
brasero_status_finalize(GObject * object)294 brasero_status_finalize (GObject *object)
295 {
296 BraseroStatusPrivate *priv;
297
298 priv = BRASERO_STATUS_PRIVATE (object);
299 if (priv->error)
300 g_error_free (priv->error);
301
302 if (priv->current_action)
303 g_free (priv->current_action);
304
305 G_OBJECT_CLASS (brasero_status_parent_class)->finalize (object);
306 }
307
308 static void
brasero_status_class_init(BraseroStatusClass * klass)309 brasero_status_class_init (BraseroStatusClass *klass)
310 {
311 GObjectClass* object_class = G_OBJECT_CLASS (klass);
312
313 g_type_class_add_private (klass, sizeof (BraseroStatusPrivate));
314
315 object_class->finalize = brasero_status_finalize;
316 }
317
318