Commit 3edb513f authored by Philippe Rouquier's avatar Philippe Rouquier

Convert brasero-drive-properties to use BraseroBurnSession directly

Drop the use of GtkFileChooserButton for a custom buttom which fixes #578175 – "Temporary files" location in Properties confusing when folder doesn't exist
Make sure we save all properties of the session when the medium changes
parent c92d67b4
......@@ -147,6 +147,7 @@ brasero_blank_dialog_caps_changed (BraseroPluginManager *manager,
static void
brasero_blank_dialog_output_changed (BraseroBurnSession *session,
BraseroMedium *former,
BraseroBlankDialog *dialog)
{
brasero_blank_dialog_device_opts_setup (dialog);
......
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include <gtk/gtk.h>
#include "brasero-drive.h"
#include "brasero-session-cfg.h"
G_BEGIN_DECLS
......@@ -51,39 +52,16 @@ typedef struct _BraseroDriveProperties BraseroDriveProperties;
struct _BraseroDrivePropertiesClass
{
GtkDialogClass parent_class;
GtkAlignmentClass parent_class;
};
struct _BraseroDriveProperties
{
GtkDialog parent_instance;
GtkAlignment parent_instance;
};
GType brasero_drive_properties_get_type (void) G_GNUC_CONST;
GtkWidget *brasero_drive_properties_new ();
void
brasero_drive_properties_set_drive (BraseroDriveProperties *props,
BraseroDrive *drive,
gint64 rate);
void
brasero_drive_properties_set_flags (BraseroDriveProperties *props,
BraseroBurnFlag flags,
BraseroBurnFlag supported,
BraseroBurnFlag compulsory);
void
brasero_drive_properties_set_tmpdir (BraseroDriveProperties *props,
const gchar *path);
BraseroBurnFlag
brasero_drive_properties_get_flags (BraseroDriveProperties *props);
gint64
brasero_drive_properties_get_rate (BraseroDriveProperties *props);
gchar *
brasero_drive_properties_get_tmpdir (BraseroDriveProperties *props);
GtkWidget *brasero_drive_properties_new (BraseroSessionCfg *session);
G_END_DECLS
......
......@@ -60,6 +60,7 @@ struct _BraseroMediumPropertiesPrivate
GtkWidget *medium_prop;
glong valid_sig;
glong output_sig;
guint default_format:1;
guint default_path:1;
......@@ -79,68 +80,48 @@ static void
brasero_medium_properties_drive_properties (BraseroMediumProperties *self)
{
BraseroMediumPropertiesPrivate *priv;
BraseroBurnFlag compulsory = 0;
BraseroBurnFlag supported = 0;
BraseroBurnFlag flags = 0;
GtkWidget *medium_prop;
BraseroDrive *drive;
GtkWidget *toplevel;
const gchar *path;
gint result;
gint64 rate;
gchar *display_name;
GtkWidget *dialog;
GtkWidget *box;
gchar *header;
priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (self);
/* Build dialog */
priv->medium_prop = brasero_drive_properties_new ();
medium_prop = brasero_drive_properties_new (BRASERO_SESSION_CFG (priv->session));
gtk_widget_show (medium_prop);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
gtk_window_set_transient_for (GTK_WINDOW (priv->medium_prop), GTK_WINDOW (toplevel));
gtk_window_set_destroy_with_parent (GTK_WINDOW (priv->medium_prop), TRUE);
gtk_window_set_position (GTK_WINDOW (toplevel), GTK_WIN_POS_CENTER_ON_PARENT);
/* get information */
drive = brasero_burn_session_get_burner (priv->session);
rate = brasero_burn_session_get_rate (priv->session);
brasero_drive_properties_set_drive (BRASERO_DRIVE_PROPERTIES (priv->medium_prop),
drive,
rate);
flags = brasero_burn_session_get_flags (priv->session);
brasero_burn_session_get_burn_flags (priv->session,
&supported,
&compulsory);
brasero_drive_properties_set_flags (BRASERO_DRIVE_PROPERTIES (priv->medium_prop),
flags,
supported,
compulsory);
path = brasero_burn_session_get_tmpdir (priv->session);
brasero_drive_properties_set_tmpdir (BRASERO_DRIVE_PROPERTIES (priv->medium_prop),
path);
display_name = brasero_drive_get_display_name (drive);
header = g_strdup_printf (_("Properties of %s"), display_name);
g_free (display_name);
dialog = gtk_dialog_new_with_buttons (header,
GTK_WINDOW (toplevel),
GTK_DIALOG_MODAL|
GTK_DIALOG_NO_SEPARATOR|
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
g_free (header);
box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
gtk_box_pack_start (GTK_BOX (box), medium_prop, TRUE, TRUE, 0);
/* launch the dialog */
gtk_widget_show_all (priv->medium_prop);
result = gtk_dialog_run (GTK_DIALOG (priv->medium_prop));
if (result != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy (priv->medium_prop);
priv->medium_prop = NULL;
return;
}
rate = brasero_drive_properties_get_rate (BRASERO_DRIVE_PROPERTIES (priv->medium_prop));
brasero_burn_session_set_rate (priv->session, rate);
brasero_burn_session_remove_flag (priv->session, BRASERO_DRIVE_PROPERTIES_FLAGS);
flags = brasero_drive_properties_get_flags (BRASERO_DRIVE_PROPERTIES (priv->medium_prop));
brasero_session_cfg_add_flags (BRASERO_SESSION_CFG (priv->session), flags);
path = brasero_drive_properties_get_tmpdir (BRASERO_DRIVE_PROPERTIES (priv->medium_prop));
brasero_burn_session_set_tmpdir (priv->session, path);
gtk_widget_destroy (priv->medium_prop);
priv->medium_prop = dialog;
gtk_widget_show (dialog);
gtk_dialog_run (GTK_DIALOG (dialog));
priv->medium_prop = NULL;
gtk_widget_destroy (dialog);
/* FIXME: save */
//brasero_session_cfg_save_drive_properties (BRASERO_SESSION_CFG (priv->session));
}
static gchar *
......@@ -551,8 +532,8 @@ brasero_medium_properties_update_image_output (BraseroMediumProperties *self,
/* we always need to do this */
brasero_medium_properties_set_output_path (self,
valid_format,
path);
valid_format,
path);
g_free (path);
......@@ -568,6 +549,23 @@ brasero_medium_properties_update_image_output (BraseroMediumProperties *self,
}
}
static void
brasero_medium_properties_output_changed (BraseroBurnSession *session,
BraseroMedium *former,
BraseroMediumProperties *self)
{
BraseroMediumPropertiesPrivate *priv;
priv = BRASERO_MEDIUM_PROPERTIES_PRIVATE (self);
/* close properties dialog */
if (priv->medium_prop) {
gtk_dialog_response (GTK_DIALOG (priv->medium_prop),
GTK_RESPONSE_CANCEL);
priv->medium_prop = NULL;
}
}
static void
brasero_medium_properties_valid_session (BraseroSessionCfg *session,
BraseroMediumProperties *self)
......@@ -607,7 +605,11 @@ brasero_medium_properties_finalize (GObject *object)
priv->valid_sig);
priv->valid_sig = 0;
}
if (priv->output_sig) {
g_signal_handler_disconnect (priv->session,
priv->output_sig);
priv->output_sig = 0;
}
if (priv->session) {
g_object_unref (priv->session);
priv->session = NULL;
......@@ -643,6 +645,10 @@ brasero_medium_properties_set_property (GObject *object,
"is-valid",
G_CALLBACK (brasero_medium_properties_valid_session),
object);
priv->output_sig = g_signal_connect (session,
"output-changed",
G_CALLBACK (brasero_medium_properties_output_changed),
object);
break;
default:
......
......@@ -92,23 +92,20 @@ G_DEFINE_TYPE (BraseroSessionCfg, brasero_session_cfg, BRASERO_TYPE_SESSION_SPAN
static gchar *
brasero_session_cfg_get_gconf_key (BraseroSessionCfg *self,
BraseroMedium *medium,
const gchar *property)
{
BraseroTrackType *type;
BraseroMedium *medium;
BraseroDrive *drive;
gchar *display_name;
gchar *key = NULL;
gchar *disc_type;
drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (self));
if (!drive)
return NULL;
medium = brasero_drive_get_medium (drive);
if (brasero_medium_get_status (medium) == BRASERO_MEDIUM_NONE)
return NULL;
drive = brasero_medium_get_drive (medium);
/* make sure display_name doesn't contain any forbidden characters */
if (!brasero_drive_is_fake (drive)) {
gchar *tmp;
......@@ -191,39 +188,54 @@ brasero_session_cfg_disable (BraseroSessionCfg *self)
}
static void
brasero_session_cfg_save_drive_properties (BraseroSessionCfg *self)
brasero_session_cfg_save_drive_flags (BraseroSessionCfg *self,
BraseroMedium *medium)
{
BraseroSessionCfgPrivate *priv;
BraseroBurnFlag flags;
GConfClient *client;
const gchar *path;
guint64 rate;
gchar *key;
priv = BRASERO_SESSION_CFG_PRIVATE (self);
client = gconf_client_get_default ();
rate = brasero_burn_session_get_rate (BRASERO_BURN_SESSION (self));
key = brasero_session_cfg_get_gconf_key (self, "speed");
key = brasero_session_cfg_get_gconf_key (self, medium, "flags");
if (!key) {
g_object_unref (client);
return;
}
gconf_client_set_int (client, key, rate / 1000, NULL);
flags = gconf_client_get_int (client, key, NULL);
flags &= ~BRASERO_DEST_SAVED_FLAGS;
flags |= (brasero_burn_session_get_flags (BRASERO_BURN_SESSION (self)) & BRASERO_DEST_SAVED_FLAGS);
gconf_client_set_int (client, key, flags, NULL);
g_free (key);
}
key = brasero_session_cfg_get_gconf_key (self, "flags");
static void
brasero_session_cfg_save_drive_properties (BraseroSessionCfg *self,
BraseroMedium *medium)
{
BraseroSessionCfgPrivate *priv;
GConfClient *client;
const gchar *path;
guint64 rate;
gchar *key;
priv = BRASERO_SESSION_CFG_PRIVATE (self);
brasero_session_cfg_save_drive_flags (self, medium);
client = gconf_client_get_default ();
rate = brasero_burn_session_get_rate (BRASERO_BURN_SESSION (self));
key = brasero_session_cfg_get_gconf_key (self, medium, "speed");
if (!key) {
g_object_unref (client);
return;
}
flags = gconf_client_get_int (client, key, NULL);
flags &= ~BRASERO_DEST_SAVED_FLAGS;
flags |= (brasero_burn_session_get_flags (BRASERO_BURN_SESSION (self)) & BRASERO_DEST_SAVED_FLAGS);
gconf_client_set_int (client, key, flags, NULL);
gconf_client_set_int (client, key, rate / 1000, NULL);
g_free (key);
/* temporary directory */
......@@ -241,12 +253,22 @@ brasero_session_cfg_add_drive_properties_flags (BraseroSessionCfg *self,
{
BraseroMedia media;
BraseroBurnFlag flag;
BraseroDrive *drive;
BraseroMedium *medium;
BraseroBurnResult result;
BraseroSessionCfgPrivate *priv;
priv = BRASERO_SESSION_CFG_PRIVATE (self);
media = brasero_burn_session_get_dest_media (BRASERO_BURN_SESSION (self));
drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (self));
if (!drive)
return;
medium = brasero_drive_get_medium (drive);
if (!medium)
return;
media = brasero_medium_get_status (medium);
/* add flags then wipe out flags from session to check them one by one */
flags |= brasero_burn_session_get_flags (BRASERO_BURN_SESSION (self));
......@@ -350,7 +372,7 @@ brasero_session_cfg_add_drive_properties_flags (BraseroSessionCfg *self,
}
/* Always save flags */
brasero_session_cfg_save_drive_properties (self);
brasero_session_cfg_save_drive_flags (self, medium);
}
static void
......@@ -381,7 +403,7 @@ brasero_session_cfg_set_drive_properties (BraseroSessionCfg *self)
/* Update/set the rate */
client = gconf_client_get_default ();
key = brasero_session_cfg_get_gconf_key (self, "speed");
key = brasero_session_cfg_get_gconf_key (self, medium, "speed");
value = gconf_client_get_without_default (client, key, NULL);
g_free (key);
......@@ -405,7 +427,7 @@ brasero_session_cfg_set_drive_properties (BraseroSessionCfg *self)
/* Do the same with the flags.
* NOTE: we only save/load PROPERTIES_FLAGS */
key = brasero_session_cfg_get_gconf_key (self, "flags");
key = brasero_session_cfg_get_gconf_key (self, medium, "flags");
if (!key) {
g_object_unref (client);
return;
......@@ -846,7 +868,8 @@ brasero_session_cfg_input_changed (BraseroBurnSession *session)
}
static void
brasero_session_cfg_output_changed (BraseroBurnSession *session)
brasero_session_cfg_output_changed (BraseroBurnSession *session,
BraseroMedium *former)
{
BraseroSessionCfgPrivate *priv;
......@@ -854,6 +877,9 @@ brasero_session_cfg_output_changed (BraseroBurnSession *session)
if (priv->disabled)
return;
brasero_session_cfg_save_drive_properties (BRASERO_SESSION_CFG (session),
former);
/* In this case need to :
* - load flags
* - check if all flags are thereafter supported
......@@ -888,6 +914,7 @@ brasero_session_cfg_add_flags (BraseroSessionCfg *self,
BraseroBurnFlag flags)
{
BraseroSessionCfgPrivate *priv;
BraseroDrive *drive;
priv = BRASERO_SESSION_CFG_PRIVATE (self);
......@@ -905,7 +932,9 @@ brasero_session_cfg_add_flags (BraseroSessionCfg *self,
&priv->compulsory);
/* Always save flags */
brasero_session_cfg_save_drive_properties (self);
drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (self));
if (drive && brasero_drive_get_medium (drive))
brasero_session_cfg_save_drive_flags (self, brasero_drive_get_medium (drive));
brasero_session_cfg_update (self,
FALSE,
......@@ -917,6 +946,7 @@ brasero_session_cfg_remove_flags (BraseroSessionCfg *self,
BraseroBurnFlag flags)
{
BraseroSessionCfgPrivate *priv;
BraseroDrive *drive;
priv = BRASERO_SESSION_CFG_PRIVATE (self);
......@@ -928,7 +958,9 @@ brasero_session_cfg_remove_flags (BraseroSessionCfg *self,
&priv->compulsory);
/* Always save flags */
brasero_session_cfg_save_drive_properties (self);
drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (self));
if (drive && brasero_drive_get_medium (drive))
brasero_session_cfg_save_drive_flags (self, brasero_drive_get_medium (drive));
brasero_session_cfg_update (self,
FALSE,
......@@ -974,9 +1006,15 @@ static void
brasero_session_cfg_finalize (GObject *object)
{
BraseroSessionCfgPrivate *priv;
BraseroDrive *drive;
priv = BRASERO_SESSION_CFG_PRIVATE (object);
drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (object));
if (drive && brasero_drive_get_medium (drive))
brasero_session_cfg_save_drive_properties (BRASERO_SESSION_CFG (object),
brasero_drive_get_medium (drive));
if (priv->caps_sig) {
BraseroPluginManager *manager;
......
......@@ -420,9 +420,11 @@ brasero_burn_session_dest_media_added (BraseroDrive *drive,
BraseroMedium *medium,
BraseroBurnSession *self)
{
/* No medium before */
g_signal_emit (self,
brasero_burn_session_signals [OUTPUT_CHANGED_SIGNAL],
0);
0,
NULL);
}
static void
......@@ -432,7 +434,8 @@ brasero_burn_session_dest_media_removed (BraseroDrive *drive,
{
g_signal_emit (self,
brasero_burn_session_signals [OUTPUT_CHANGED_SIGNAL],
0);
0,
medium);
}
void
......@@ -440,6 +443,7 @@ brasero_burn_session_set_burner (BraseroBurnSession *self,
BraseroDrive *drive)
{
BraseroBurnSessionPrivate *priv;
BraseroMedium *former;
g_return_if_fail (BRASERO_IS_BURN_SESSION (self));
......@@ -448,6 +452,11 @@ brasero_burn_session_set_burner (BraseroBurnSession *self,
if (drive == priv->settings->burner)
return;
former = brasero_drive_get_medium (priv->settings->burner);
if (former)
former = g_object_ref (former);
/* If there was no drive before no need for a changing signal */
if (priv->settings->burner) {
if (priv->dest_added_sig) {
g_signal_handler_disconnect (priv->settings->burner,
......@@ -480,7 +489,10 @@ brasero_burn_session_set_burner (BraseroBurnSession *self,
g_signal_emit (self,
brasero_burn_session_signals [OUTPUT_CHANGED_SIGNAL],
0);
0,
former);
if (former)
g_object_unref (former);
}
BraseroDrive *
......@@ -628,6 +640,35 @@ brasero_burn_session_get_output_format (BraseroBurnSession *self)
* the type of image it can be a toc (cue) or the path of the image (all others)
*/
static void
brasero_burn_session_set_image_output_real (BraseroBurnSession *self,
BraseroImageFormat format,
const gchar *image,
const gchar *toc)
{
BraseroBurnSessionPrivate *priv;
priv = BRASERO_BURN_SESSION_PRIVATE (self);
if (priv->settings->image)
g_free (priv->settings->image);
if (image)
priv->settings->image = g_strdup (image);
else
priv->settings->image = NULL;
if (priv->settings->toc)
g_free (priv->settings->toc);
if (toc)
priv->settings->toc = g_strdup (toc);
else
priv->settings->toc = NULL;
priv->settings->format = format;
}
BraseroBurnResult
brasero_burn_session_set_image_output_full (BraseroBurnSession *self,
BraseroImageFormat format,
......@@ -648,6 +689,8 @@ brasero_burn_session_set_image_output_full (BraseroBurnSession *self,
BraseroDrive *drive;
GSList *list;
/* NOTE: changing/changed signals are handled in
* set_burner (). */
monitor = brasero_medium_monitor_get_default ();
list = brasero_medium_monitor_get_media (monitor, BRASERO_MEDIA_TYPE_FILE);
drive = brasero_medium_get_drive (list->data);
......@@ -659,29 +702,13 @@ brasero_burn_session_set_image_output_full (BraseroBurnSession *self,
return BRASERO_BURN_OK;
}
if (priv->settings->image)
g_free (priv->settings->image);
if (image)
priv->settings->image = g_strdup (image);
else
priv->settings->image = NULL;
if (priv->settings->toc)
g_free (priv->settings->toc);
if (toc)
priv->settings->toc = g_strdup (toc);
else
priv->settings->toc = NULL;
priv->settings->format = format;
if (!BRASERO_BURN_SESSION_WRITE_TO_FILE (priv)) {
BraseroMediumMonitor *monitor;
BraseroDrive *drive;
GSList *list;
brasero_burn_session_set_image_output_real (self, format, image, toc);
monitor = brasero_medium_monitor_get_default ();
list = brasero_medium_monitor_get_media (monitor,BRASERO_MEDIA_TYPE_FILE);
drive = brasero_medium_get_drive (list->data);
......@@ -689,10 +716,13 @@ brasero_burn_session_set_image_output_full (BraseroBurnSession *self,
g_object_unref (monitor);
g_slist_free (list);
}
else
else {
brasero_burn_session_set_image_output_real (self, format, image, toc);
g_signal_emit (self,
brasero_burn_session_signals [OUTPUT_CHANGED_SIGNAL],
0);
0,
brasero_drive_get_medium (priv->settings->burner));
}
return BRASERO_BURN_OK;
}
......@@ -711,6 +741,10 @@ brasero_burn_session_set_tmpdir (BraseroBurnSession *self,
priv = BRASERO_BURN_SESSION_PRIVATE (self);
if (priv->settings->tmpdir && path
&& !strcmp (priv->settings->tmpdir, path))
return BRASERO_BURN_OK;
if (priv->settings->tmpdir)
g_free (priv->settings->tmpdir);
......@@ -1128,11 +1162,15 @@ brasero_burn_session_pop_settings (BraseroBurnSession *self)
{
BraseroSessionSetting *settings;
BraseroBurnSessionPrivate *priv;
BraseroMedium *former;
g_return_if_fail (BRASERO_IS_BURN_SESSION (self));
priv = BRASERO_BURN_SESSION_PRIVATE (self);
if (!priv->pile_settings)
return;
if (priv->dest_added_sig) {
g_signal_handler_disconnect (priv->settings->burner,
priv->dest_added_sig);
......@@ -1145,10 +1183,11 @@ brasero_burn_session_pop_settings (BraseroBurnSession *self)
priv->dest_removed_sig = 0;
}
brasero_session_settings_clean (priv->settings);
former = brasero_drive_get_medium (priv->settings->burner);
if (former)
former = g_object_ref (former);
if (!priv->pile_settings)
return;
brasero_session_settings_clean (priv->settings);
settings = priv->pile_settings->data;
priv->pile_settings = g_slist_remove (priv->pile_settings, settings);
......@@ -1169,7 +1208,10 @@ brasero_burn_session_pop_settings (BraseroBurnSession *self)
g_signal_emit (self,
brasero_burn_session_signals [OUTPUT_CHANGED_SIGNAL],
0);
0,
former);
if (former)
g_object_unref (former);
}
void
......@@ -1691,9 +1733,10 @@ brasero_burn_session_class_init (BraseroBurnSessionClass *klass)
G_STRUCT_OFFSET (BraseroBurnSessionClass, output_changed),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
0);
1,
BRASERO_TYPE_MEDIUM);
brasero_burn_session_signals [INPUT_CHANGED_SIGNAL] =
g_signal_new ("input_changed",
......
......@@ -67,7 +67,8 @@ struct _BraseroBurnSessionClass {
* the session properties they are interested in.
*/
void (*input_changed) (BraseroBurnSession *session);
void (*output_changed) (BraseroBurnSession *session);
void (*output_changed) (BraseroBurnSession *session,
BraseroMedium *medium);
};
GType brasero_burn_session_get_type ();
......
......@@ -572,7 +572,8 @@ brasero_src_image_init (BraseroSrcImage *object)
g_object_unref (file);
}
g_free (uri);
/* Translators: this is a disc image */
string = g_strdup_printf ("<i>%s</i>", _("Click here to select an _image"));
label = gtk_label_new_with_mnemonic (string);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment