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 #include <string.h>
36
37 #include <glib.h>
38 #include <glib-object.h>
39 #include <glib/gi18n-lib.h>
40
41 #include <gtk/gtk.h>
42
43 #include "brasero-medium-properties.h"
44 #include "brasero-drive-properties.h"
45 #include "brasero-image-properties.h"
46 #include "brasero-session-cfg.h"
47 #include "brasero-session-helper.h"
48
49 #include "burn-basics.h"
50 #include "brasero-track.h"
51 #include "brasero-medium.h"
52 #include "brasero-session.h"
53 #include "burn-image-format.h"
54
55 typedef struct _BraseroMediumPropertiesPrivate BraseroMediumPropertiesPrivate;
56 struct _BraseroMediumPropertiesPrivate
57 {
58 BraseroBurnSession *session;
59
60 GtkWidget *medium_prop;
61 };
62
63 #define BRASERO_MEDIUM_PROPERTIES_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_MEDIUM_PROPERTIES, BraseroMediumPropertiesPrivate))
64
65 enum {
66 PROP_0,
67 PROP_SESSION
68 };
69
70 G_DEFINE_TYPE (BraseroMediumProperties, brasero_medium_properties, GTK_TYPE_BUTTON);
71
72 static void
brasero_medium_properties_drive_properties(BraseroMediumProperties * self)73 brasero_medium_properties_drive_properties (BraseroMediumProperties *self)
74 {
75 BraseroMediumPropertiesPrivate *priv;
76 GtkWidget *medium_prop;
77 BraseroDrive *drive;
78 GtkWidget *toplevel;
79 gchar *display_name;
80 GtkWidget *dialog;
81 GtkWidget *box;
82 gchar *header;
83
84 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (self);
85
86 /* Build dialog */
87 medium_prop = brasero_drive_properties_new (BRASERO_SESSION_CFG (priv->session));
88 gtk_widget_show (medium_prop);
89
90 drive = brasero_burn_session_get_burner (priv->session);
91 display_name = brasero_drive_get_display_name (drive);
92
93 header = g_strdup_printf (_("Properties of %s"), display_name);
94 g_free (display_name);
95
96 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
97 dialog = gtk_dialog_new_with_buttons (header,
98 GTK_WINDOW (toplevel),
99 GTK_DIALOG_MODAL|
100 GTK_DIALOG_DESTROY_WITH_PARENT,
101 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
102 NULL);
103 g_free (header);
104
105 gtk_window_set_icon_name (GTK_WINDOW (dialog),
106 gtk_window_get_icon_name (GTK_WINDOW (toplevel)));
107
108 box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
109 gtk_box_pack_start (GTK_BOX (box), medium_prop, TRUE, TRUE, 0);
110
111 /* launch the dialog */
112 priv->medium_prop = dialog;
113 gtk_widget_show (dialog);
114 gtk_dialog_run (GTK_DIALOG (dialog));
115 priv->medium_prop = NULL;
116 gtk_widget_destroy (dialog);
117 }
118
119 static gboolean
brasero_medium_properties_wrong_extension(BraseroSessionCfg * session,BraseroMediumProperties * self)120 brasero_medium_properties_wrong_extension (BraseroSessionCfg *session,
121 BraseroMediumProperties *self)
122 {
123 guint answer;
124 GtkWidget *dialog;
125 GtkWidget *toplevel;
126
127 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
128 dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
129 GTK_DIALOG_DESTROY_WITH_PARENT |
130 GTK_DIALOG_MODAL,
131 GTK_MESSAGE_WARNING,
132 GTK_BUTTONS_NONE,
133 _("Do you really want to keep the current extension for the disc image name?"));
134
135 gtk_window_set_icon_name (GTK_WINDOW (dialog),
136 gtk_window_get_icon_name (GTK_WINDOW (toplevel)));
137
138 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
139 _("If you choose to keep it, programs may not be able to recognize the file type properly."));
140
141 gtk_dialog_add_button (GTK_DIALOG (dialog),
142 _("_Keep Current Extension"),
143 GTK_RESPONSE_CANCEL);
144 gtk_dialog_add_button (GTK_DIALOG (dialog),
145 _("Change _Extension"),
146 GTK_RESPONSE_YES);
147
148 answer = gtk_dialog_run (GTK_DIALOG (dialog));
149 gtk_widget_destroy (dialog);
150
151 if (answer == GTK_RESPONSE_YES)
152 return TRUE;
153
154 return FALSE;
155 }
156
157 static void
brasero_medium_properties_image_properties(BraseroMediumProperties * self)158 brasero_medium_properties_image_properties (BraseroMediumProperties *self)
159 {
160 BraseroMediumPropertiesPrivate *priv;
161 GtkWindow *toplevel;
162
163 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (self);
164
165 priv->medium_prop = brasero_image_properties_new ();
166 brasero_image_properties_set_session (BRASERO_IMAGE_PROPERTIES (priv->medium_prop),
167 BRASERO_SESSION_CFG (priv->session));
168
169 gtk_dialog_add_buttons (GTK_DIALOG (priv->medium_prop),
170 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
171 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
172 NULL);
173
174 toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
175 gtk_window_set_transient_for (GTK_WINDOW (priv->medium_prop), GTK_WINDOW (toplevel));
176 gtk_window_set_destroy_with_parent (GTK_WINDOW (priv->medium_prop), TRUE);
177 gtk_window_set_position (GTK_WINDOW (toplevel), GTK_WIN_POS_CENTER_ON_PARENT);
178
179 gtk_window_set_icon_name (GTK_WINDOW (priv->medium_prop),
180 gtk_window_get_icon_name (GTK_WINDOW (toplevel)));
181
182 /* and here we go ... run the thing */
183 gtk_widget_show (priv->medium_prop);
184 gtk_dialog_run (GTK_DIALOG (priv->medium_prop));
185 gtk_widget_destroy (priv->medium_prop);
186 priv->medium_prop = NULL;
187 }
188
189 static void
brasero_medium_properties_clicked(GtkButton * button)190 brasero_medium_properties_clicked (GtkButton *button)
191 {
192 BraseroMediumPropertiesPrivate *priv;
193 BraseroDrive *drive;
194
195 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (button);
196
197 drive = brasero_burn_session_get_burner (priv->session);
198 if (!drive)
199 return;
200
201 if (brasero_drive_is_fake (drive))
202 brasero_medium_properties_image_properties (BRASERO_MEDIUM_PROPERTIES (button));
203 else
204 brasero_medium_properties_drive_properties (BRASERO_MEDIUM_PROPERTIES (button));
205 }
206
207 static void
brasero_medium_properties_output_changed(BraseroBurnSession * session,BraseroMedium * former,BraseroMediumProperties * self)208 brasero_medium_properties_output_changed (BraseroBurnSession *session,
209 BraseroMedium *former,
210 BraseroMediumProperties *self)
211 {
212 BraseroMediumPropertiesPrivate *priv;
213 BraseroDrive *burner;
214
215 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (self);
216
217 /* make sure that's an actual change of medium
218 * as it could also be a change of path for image */
219 burner = brasero_burn_session_get_burner (session);
220 if (former == brasero_drive_get_medium (burner))
221 return;
222
223 /* close properties dialog */
224 if (priv->medium_prop) {
225 gtk_dialog_response (GTK_DIALOG (priv->medium_prop),
226 GTK_RESPONSE_CANCEL);
227 priv->medium_prop = NULL;
228 }
229 }
230
231 static void
brasero_medium_properties_init(BraseroMediumProperties * object)232 brasero_medium_properties_init (BraseroMediumProperties *object)
233 {
234 gtk_widget_set_tooltip_text (GTK_WIDGET (object), _("Configure recording options"));
235 }
236
237 static void
brasero_medium_properties_finalize(GObject * object)238 brasero_medium_properties_finalize (GObject *object)
239 {
240 BraseroMediumPropertiesPrivate *priv;
241
242 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (object);
243
244 if (priv->session) {
245 g_signal_handlers_disconnect_by_func (priv->session,
246 brasero_medium_properties_output_changed,
247 object);
248 g_signal_handlers_disconnect_by_func (priv->session,
249 brasero_medium_properties_wrong_extension,
250 object);
251 g_object_unref (priv->session);
252 priv->session = NULL;
253 }
254
255 G_OBJECT_CLASS (brasero_medium_properties_parent_class)->finalize (object);
256 }
257
258 static void
brasero_medium_properties_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)259 brasero_medium_properties_set_property (GObject *object,
260 guint property_id,
261 const GValue *value,
262 GParamSpec *pspec)
263 {
264 BraseroMediumPropertiesPrivate *priv;
265 BraseroBurnSession *session;
266
267 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (object);
268
269 switch (property_id) {
270 case PROP_SESSION:
271 if (priv->session)
272 g_object_unref (priv->session);
273
274 session = g_value_get_object (value);
275
276 /* NOTE: no need to unref a potential previous session since
277 * it's only set at construct time */
278 priv->session = session;
279 g_object_ref (session);
280
281 g_signal_connect (session,
282 "output-changed",
283 G_CALLBACK (brasero_medium_properties_output_changed),
284 object);
285 g_signal_connect (session,
286 "wrong-extension",
287 G_CALLBACK (brasero_medium_properties_wrong_extension),
288 object);
289 break;
290
291 default:
292 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
293 }
294 }
295
296 static void
brasero_medium_properties_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)297 brasero_medium_properties_get_property (GObject *object,
298 guint property_id,
299 GValue *value,
300 GParamSpec *pspec)
301 {
302 BraseroMediumPropertiesPrivate *priv;
303
304 priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (object);
305
306 switch (property_id) {
307 case PROP_SESSION:
308 g_value_set_object (value, priv->session);
309 break;
310
311 default:
312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
313 }
314 }
315
316 static void
brasero_medium_properties_class_init(BraseroMediumPropertiesClass * klass)317 brasero_medium_properties_class_init (BraseroMediumPropertiesClass *klass)
318 {
319 GObjectClass* object_class = G_OBJECT_CLASS (klass);
320 GtkButtonClass* button_class = GTK_BUTTON_CLASS (klass);
321
322 g_type_class_add_private (klass, sizeof (BraseroMediumPropertiesPrivate));
323
324 object_class->finalize = brasero_medium_properties_finalize;
325 object_class->set_property = brasero_medium_properties_set_property;
326 object_class->get_property = brasero_medium_properties_get_property;
327
328 button_class->clicked = brasero_medium_properties_clicked;
329 g_object_class_install_property (object_class,
330 PROP_SESSION,
331 g_param_spec_object ("session",
332 "The session to work with",
333 "The session to work with",
334 BRASERO_TYPE_SESSION_CFG,
335 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
336
337 }
338
339 GtkWidget *
brasero_medium_properties_new(BraseroSessionCfg * session)340 brasero_medium_properties_new (BraseroSessionCfg *session)
341 {
342 return g_object_new (BRASERO_TYPE_MEDIUM_PROPERTIES,
343 "session", session,
344 "use-stock", TRUE,
345 "label", GTK_STOCK_PROPERTIES,
346 "focus-on-click", FALSE,
347 NULL);
348 }
349