Commit 6a3cbb79 authored by Philippe Rouquier's avatar Philippe Rouquier

Display the size that would be used by the data to burn in the combo box

parent 20470676
......@@ -46,9 +46,10 @@
#include "brasero-track.h"
#include "brasero-medium.h"
#include "brasero-session.h"
#include "burn-plugin-manager.h"
#include "brasero-drive.h"
#include "brasero-volume.h"
#include "brasero-burn-lib.h"
#include "burn-plugin-manager.h"
#include "brasero-medium-selection-priv.h"
#include "brasero-dest-selection.h"
......@@ -74,7 +75,6 @@ enum {
G_DEFINE_TYPE (BraseroDestSelection, brasero_dest_selection, BRASERO_TYPE_MEDIUM_SELECTION);
void
brasero_dest_selection_lock (BraseroDestSelection *self,
gboolean locked)
......@@ -385,12 +385,15 @@ static gchar *
brasero_dest_selection_format_medium_string (BraseroMediumSelection *selection,
BraseroMedium *medium)
{
guint used;
gchar *label;
goffset blocks = 0;
gchar *medium_name;
gchar *size_string;
BraseroMedia media;
gint64 size_bytes = 0;
BraseroBurnFlag flags;
goffset size_bytes = 0;
goffset data_blocks = 0;
BraseroTrackType *input = NULL;
BraseroDestSelectionPrivate *priv;
......@@ -412,6 +415,10 @@ brasero_dest_selection_format_medium_string (BraseroMediumSelection *selection,
path);
g_free (medium_name);
g_free (path);
brasero_medium_selection_update_used_space (BRASERO_MEDIUM_SELECTION (selection),
medium,
0);
return label;
}
......@@ -437,43 +444,57 @@ brasero_dest_selection_format_medium_string (BraseroMediumSelection *selection,
* holding the source disc */
label = g_strdup_printf (_("New disc in the burner holding source disc"));
g_free (medium_name);
brasero_medium_selection_update_used_space (BRASERO_MEDIUM_SELECTION (selection),
medium,
0);
return label;
}
}
media = brasero_medium_get_status (medium);
flags = brasero_burn_session_get_flags (priv->session);
brasero_burn_session_get_size (priv->session,
&data_blocks,
NULL);
if ((media & BRASERO_MEDIUM_BLANK)
|| ((flags & BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE)
&& brasero_burn_session_can_blank (priv->session) == BRASERO_BURN_OK)) {
brasero_medium_get_capacity (medium,
&size_bytes,
NULL);
}
else if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND)) {
if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND)) {
brasero_medium_get_free_space (medium,
&size_bytes,
NULL);
&blocks);
}
else {
brasero_medium_get_free_space (medium, NULL, &blocks);
/* if data would not fit, try to see if once blanked it would
* work. This also covers the case where the media is closed as
* its free space would be 0. This is the best way to do it
* instead of checking for a CLOSED medium as it allows the
* overwrite media to be appended or merged if need be. */
if ((!blocks || blocks > data_blocks)
&& (brasero_burn_library_get_media_capabilities (media) & BRASERO_MEDIUM_REWRITABLE))
brasero_medium_get_capacity (medium,
&size_bytes,
&blocks);
}
else if (media & BRASERO_MEDIUM_CLOSED) {
if (!brasero_burn_session_can_blank (priv->session) == BRASERO_BURN_OK) {
brasero_track_type_free (input);
/* NOTE for translators, the first %s is the medium name */
label = g_strdup_printf (_("%s: no free space"), medium_name);
g_free (medium_name);
return label;
}
brasero_medium_get_capacity (medium,
&size_bytes,
NULL);
if (blocks) {
used = data_blocks * 100 / blocks;
used = MIN (100, used);
}
else {
brasero_medium_get_capacity (medium,
&size_bytes,
NULL);
else
used = 0;
brasero_medium_selection_update_used_space (BRASERO_MEDIUM_SELECTION (selection),
medium,
used);
if (!blocks) {
brasero_track_type_free (input);
/* NOTE for translators, the first %s is the medium name */
label = g_strdup_printf (_("%s: no free space"), medium_name);
g_free (medium_name);
return label;
}
/* format the size */
......
......@@ -35,7 +35,8 @@
G_BEGIN_DECLS
typedef gboolean (*BraseroMediumSelectionFunc) (BraseroMedium *medium, gpointer callback_data);
typedef gboolean (*BraseroMediumSelectionFunc) (BraseroMedium *medium,
gpointer callback_data);
guint
brasero_medium_selection_get_media_num (BraseroMediumSelection *selection);
......@@ -45,6 +46,11 @@ brasero_medium_selection_foreach (BraseroMediumSelection *selection,
BraseroMediumSelectionFunc function,
gpointer callback_data);
void
brasero_medium_selection_update_used_space (BraseroMediumSelection *selection,
BraseroMedium *medium,
guint used_space);
void
brasero_medium_selection_update_media_string (BraseroMediumSelection *selection);
......
......@@ -74,6 +74,9 @@ enum {
MEDIUM_COL,
NAME_COL,
ICON_COL,
USED_COL,
VISIBLE_PROGRESS_COL,
VISIBLE_TEXT_COL,
NUM_COL
};
......@@ -176,6 +179,75 @@ brasero_medium_selection_get_medium_string (BraseroMediumSelection *self,
return label;
}
void
brasero_medium_selection_update_used_space (BraseroMediumSelection *selector,
BraseroMedium *medium_arg,
guint used_space)
{
BraseroMediumSelectionPrivate *priv;
GtkTreeModel *model;
GtkTreeIter iter;
priv = BRASERO_MEDIUM_SELECTION_PRIVATE (selector);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (selector));
if (!gtk_tree_model_get_iter_first (model, &iter))
return;
do {
BraseroMedium *medium;
medium = NULL;
gtk_tree_model_get (model, &iter,
MEDIUM_COL, &medium,
-1);
if (medium == medium_arg) {
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
USED_COL, used_space,
VISIBLE_PROGRESS_COL, (gboolean) (used_space > 0),
VISIBLE_TEXT_COL, (gboolean) (used_space <= 0),
-1);
break;
}
} while (gtk_tree_model_iter_next (model, &iter));
}
static void
brasero_medium_selection_set_show_used_space (BraseroMediumSelection *selector)
{
GtkCellRenderer *renderer;
BraseroMediumSelectionPrivate *priv;
priv = BRASERO_MEDIUM_SELECTION_PRIVATE (selector);
gtk_cell_layout_clear (GTK_CELL_LAYOUT (selector));
renderer = gtk_cell_renderer_pixbuf_new ();
g_object_set (renderer, "follow-state", TRUE, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (selector), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (selector), renderer,
"gicon", ICON_COL,
NULL);
renderer = gtk_cell_renderer_progress_new ();
g_object_set (renderer, "xpad", 8, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (selector), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (selector), renderer,
"text", NAME_COL,
"value", USED_COL,
"visible", VISIBLE_PROGRESS_COL,
NULL);
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "xpad", 8, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (selector), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (selector), renderer,
"markup", NAME_COL,
"visible", VISIBLE_TEXT_COL,
NULL);
}
void
brasero_medium_selection_update_media_string (BraseroMediumSelection *self)
{
......@@ -370,6 +442,8 @@ brasero_medium_selection_update_no_disc_entry (BraseroMediumSelection *self,
gtk_list_store_set (GTK_LIST_STORE (model), iter,
NAME_COL, _("Searching for available discs"),
ICON_COL, icon,
VISIBLE_TEXT_COL, TRUE,
VISIBLE_PROGRESS_COL, FALSE,
-1);
}
else {
......@@ -377,6 +451,8 @@ brasero_medium_selection_update_no_disc_entry (BraseroMediumSelection *self,
gtk_list_store_set (GTK_LIST_STORE (model), iter,
NAME_COL, _("No available disc"),
ICON_COL, icon,
VISIBLE_TEXT_COL, TRUE,
VISIBLE_PROGRESS_COL, FALSE,
-1);
}
......@@ -477,14 +553,18 @@ brasero_medium_selection_show_media_type (BraseroMediumSelection *selector,
medium = item->data;
medium_name = brasero_medium_selection_get_medium_string (selector, medium);
medium_icon = brasero_volume_get_icon (BRASERO_VOLUME (medium));
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
MEDIUM_COL, medium,
-1);
medium_name = brasero_medium_selection_get_medium_string (selector, medium);
medium_icon = brasero_volume_get_icon (BRASERO_VOLUME (medium));
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
NAME_COL, medium_name,
ICON_COL, medium_icon,
VISIBLE_TEXT_COL, TRUE,
VISIBLE_PROGRESS_COL, FALSE,
-1);
g_free (medium_name);
g_object_unref (medium_icon);
......@@ -615,13 +695,18 @@ brasero_medium_selection_medium_added_cb (BraseroMediumMonitor *monitor,
g_object_unref (tmp);
}
medium_name = brasero_medium_selection_get_medium_string (self, medium);
medium_icon = brasero_volume_get_icon (BRASERO_VOLUME (medium));
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
MEDIUM_COL, medium,
-1);
medium_name = brasero_medium_selection_get_medium_string (self, medium);
medium_icon = brasero_volume_get_icon (BRASERO_VOLUME (medium));
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
NAME_COL, medium_name,
ICON_COL, medium_icon,
VISIBLE_TEXT_COL, TRUE,
VISIBLE_PROGRESS_COL, FALSE,
-1);
g_free (medium_name);
g_object_unref (medium_icon);
......@@ -679,7 +764,6 @@ static void
brasero_medium_selection_init (BraseroMediumSelection *object)
{
GtkListStore *model;
GtkCellRenderer *renderer;
BraseroMediumMonitor *monitor;
BraseroMediumSelectionPrivate *priv;
......@@ -701,24 +785,15 @@ brasero_medium_selection_init (BraseroMediumSelection *object)
model = gtk_list_store_new (NUM_COL,
G_TYPE_OBJECT,
G_TYPE_STRING,
G_TYPE_ICON);
G_TYPE_ICON,
G_TYPE_UINT,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
gtk_combo_box_set_model (GTK_COMBO_BOX (object), GTK_TREE_MODEL (model));
g_object_unref (model);
renderer = gtk_cell_renderer_pixbuf_new ();
g_object_set (renderer, "follow-state", TRUE, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
"gicon", ICON_COL,
NULL);
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "xpad", 8, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
"markup", NAME_COL,
NULL);
brasero_medium_selection_set_show_used_space (object);
}
static void
......
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