static gboolean volume_is_blank (GVolume *volume) { BraseroMediumMonitor *monitor; BraseroMedium *medium; BraseroDrive *drive; gchar *device; gboolean is_blank; is_blank = FALSE; device = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); if (!device) return FALSE; DEBUG_PRINT ("Got device: %s\n", device); monitor = brasero_medium_monitor_get_default (); drive = brasero_medium_monitor_get_drive (monitor, device); g_object_unref (monitor); g_free (device); if (drive == NULL) return FALSE; medium = brasero_drive_get_medium (drive); is_blank = (brasero_medium_get_status (medium) & BRASERO_MEDIUM_BLANK); g_object_unref (drive); return is_blank; }
gboolean sj_metadata_helper_check_media (const char *cdrom, GError **error) { #ifndef USE_TOTEM_PL_PARSER BraseroMediumMonitor *monitor; BraseroMedium *medium; BraseroDrive *drive; /* This initialize the library if it isn't done yet */ monitor = brasero_medium_monitor_get_default (); if (brasero_medium_monitor_is_probing (monitor)) { /* FIXME: would be nicer to only check if "cdrom" is being probed, * but libbrasero doesn't seem to have an API for that */ g_set_error (error, SJ_ERROR, SJ_ERROR_CD_BUSY, _("Cannot read CD: %s"), _("Devices haven't been all probed yet")); return FALSE; } drive = brasero_medium_monitor_get_drive (monitor, cdrom); if (drive == NULL) { return FALSE; } medium = brasero_drive_get_medium (drive); g_object_unref (drive); if (!medium || !BRASERO_MEDIUM_VALID (brasero_medium_get_status (medium))) { char *msg; SjError err; if (access (cdrom, W_OK) == 0) { msg = g_strdup_printf (_("Device '%s' does not contain any media"), cdrom); err = SJ_ERROR_CD_NO_MEDIA; } else { msg = g_strdup_printf (_("Device '%s' could not be opened. Check the access permissions on the device."), cdrom); err = SJ_ERROR_CD_PERMISSION_ERROR; } g_set_error (error, SJ_ERROR, err, _("Cannot read CD: %s"), msg); g_free (msg); return FALSE; } #else GError *totem_error = NULL; totem_cd_detect_type (cdrom, &totem_error); if (totem_error != NULL) { g_set_error (error, SJ_ERROR, SJ_ERROR_CD_NO_MEDIA, _("Cannot read CD: %s"), totem_error->message); g_error_free (totem_error); return FALSE; } #endif /* !USE_TOTEM_PL_PARSER */ return TRUE; }
static void brasero_medium_selection_medium_added_cb (BraseroMediumMonitor *monitor, BraseroMedium *medium, BraseroMediumSelection *self) { BraseroMediumSelectionPrivate *priv; gboolean add = FALSE; GtkTreeModel *model; BraseroDrive *drive; gchar *medium_name; GIcon *medium_icon; GtkTreeIter iter; priv = BRASERO_MEDIUM_SELECTION_PRIVATE (self); model = gtk_combo_box_get_model (GTK_COMBO_BOX (self)); /* Make sure it's not already in our list */ if (gtk_tree_model_get_iter_first (model, &iter)) { do { BraseroMedium *tmp; tmp = NULL; gtk_tree_model_get (model, &iter, MEDIUM_COL, &tmp, -1); if (tmp == medium) return; } while (gtk_tree_model_iter_next (model, &iter)); } /* Make sure it does fit the types of media to display */ drive = brasero_medium_get_drive (medium); if ((priv->type & BRASERO_MEDIA_TYPE_CD) == priv->type && (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) add = TRUE; if ((priv->type & BRASERO_MEDIA_TYPE_ANY_IN_BURNER) && (brasero_drive_can_write (drive))) { if ((priv->type & BRASERO_MEDIA_TYPE_CD)) { if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD) add = TRUE; } else add = TRUE; } if ((priv->type & BRASERO_MEDIA_TYPE_AUDIO) && (brasero_medium_get_status (medium) & BRASERO_MEDIUM_HAS_AUDIO)) { if ((priv->type & BRASERO_MEDIA_TYPE_CD)) { if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD) add = TRUE; } else add = TRUE; } if ((priv->type & BRASERO_MEDIA_TYPE_DATA) && (brasero_medium_get_status (medium) & BRASERO_MEDIUM_HAS_DATA)) { if ((priv->type & BRASERO_MEDIA_TYPE_CD)) { if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD) add = TRUE; } else add = TRUE; } if (priv->type & BRASERO_MEDIA_TYPE_WRITABLE) { if (brasero_medium_can_be_written (medium)) { if ((priv->type & BRASERO_MEDIA_TYPE_CD)) { if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD) add = TRUE; } else add = TRUE; } } if (priv->type & BRASERO_MEDIA_TYPE_REWRITABLE) { if (brasero_medium_can_be_rewritten (medium)) { if ((priv->type & BRASERO_MEDIA_TYPE_CD)) { if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD) add = TRUE; } else add = TRUE; } } if (!add) { BraseroMedium *tmp; /* Try to get the first iter (it shouldn't fail) */ if (!gtk_tree_model_get_iter_first (model, &iter)) { brasero_medium_selection_add_no_disc_entry (self); return; } /* See if that's a real medium or not; if so, return. */ tmp = NULL; gtk_tree_model_get (model, &iter, MEDIUM_COL, &tmp, -1); if (tmp) { g_object_unref (tmp); return; } brasero_medium_selection_update_no_disc_entry (self, model, &iter); return; } /* remove warning message */ if (gtk_tree_model_get_iter_first (model, &iter)) { BraseroMedium *tmp; gtk_tree_model_get (model, &iter, MEDIUM_COL, &tmp, -1); if (!tmp) gtk_list_store_remove (GTK_LIST_STORE (model), &iter); else g_object_unref (tmp); } gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1, 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); gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE); if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter); brasero_medium_selection_set_current_medium (self, &iter); } }
static gchar * brasero_medium_selection_get_medium_string (BraseroMediumSelection *self, BraseroMedium *medium) { gchar *label; gint64 size = 0; gchar *size_string; gchar *medium_name; BraseroMedia media; BraseroMediumSelectionClass *klass; klass = BRASERO_MEDIUM_SELECTION_GET_CLASS (self); if (klass->format_medium_string) { gchar *label; label = klass->format_medium_string (self, medium); if (label) return label; } medium_name = brasero_volume_get_name (BRASERO_VOLUME (medium)); if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_FILE) return medium_name; media = brasero_medium_get_status (medium); if (media & BRASERO_MEDIUM_BLANK) { /* NOTE for translators, the first %s is the medium name */ label = g_strdup_printf (_("%s: empty"), medium_name); g_free (medium_name); return label; } brasero_medium_get_data_size (medium, &size, NULL); /* format the size */ if (media & BRASERO_MEDIUM_HAS_DATA) { size_string = g_format_size (size); /* NOTE for translators: the first %s is the medium name, the * second %s is the space (kio, gio) used by data on the disc. */ label = g_strdup_printf (_("%s: %s"), medium_name, size_string); } else { size_string = brasero_units_get_time_string_from_size (size, TRUE, TRUE); /* NOTE for translators: the first %s is the medium name, the * second %s is the space (time) used by data on the disc. * I really don't know if I should set this string as * translatable. */ label = g_strdup_printf (_("%s: %s"), medium_name, size_string); } g_free (medium_name); g_free (size_string); return label; }
static gboolean brasero_tool_dialog_run (BraseroToolDialog *self) { BraseroToolDialogPrivate *priv; BraseroToolDialogClass *klass; gboolean close = FALSE; BraseroMedium *medium; BraseroMedia media; GdkCursor *cursor; GdkWindow *window; priv = BRASERO_TOOL_DIALOG_PRIVATE (self); medium = brasero_medium_selection_get_active (BRASERO_MEDIUM_SELECTION (priv->selector)); /* set up */ gtk_widget_set_sensitive (priv->upper_box, FALSE); gtk_widget_set_sensitive (priv->lower_box, TRUE); gtk_widget_set_sensitive (GTK_WIDGET (priv->button), FALSE); cursor = gdk_cursor_new (GDK_WATCH); window = gtk_widget_get_window (GTK_WIDGET (self)); gdk_window_set_cursor (window, cursor); g_object_unref (cursor); gtk_button_set_label (GTK_BUTTON (priv->cancel), GTK_STOCK_CANCEL); /* check the contents of the drive */ media = brasero_medium_get_status (medium); if (media == BRASERO_MEDIUM_NONE) { brasero_tool_dialog_no_media (self); gtk_widget_set_sensitive (GTK_WIDGET (priv->button), TRUE); goto end; } else if (media == BRASERO_MEDIUM_UNSUPPORTED) { /* error out */ gtk_widget_set_sensitive (GTK_WIDGET (priv->button), TRUE); brasero_tool_dialog_media_error (self); goto end; } else if (media == BRASERO_MEDIUM_BUSY) { gtk_widget_set_sensitive (GTK_WIDGET (priv->button), TRUE); brasero_tool_dialog_media_busy (self); goto end; } priv->running = TRUE; klass = BRASERO_TOOL_DIALOG_GET_CLASS (self); if (klass->activate) close = klass->activate (self, medium); priv->running = FALSE; if (medium) g_object_unref (medium); if (close) return TRUE; end: gdk_window_set_cursor (window, NULL); gtk_button_set_label (GTK_BUTTON (priv->cancel), GTK_STOCK_CLOSE); gtk_widget_set_sensitive (priv->upper_box, TRUE); gtk_widget_set_sensitive (priv->lower_box, FALSE); brasero_burn_progress_reset (BRASERO_BURN_PROGRESS (priv->progress)); return FALSE; }
static GList * nautilus_disc_burn_get_file_items (NautilusMenuProvider *provider, GtkWidget *window, GList *selection) { GList *items = NULL; NautilusMenuItem *item; NautilusFileInfo *file_info; GFile *file; GMount *mount; GVolume *volume; GDrive *drive; char *mime_type; gboolean is_iso; DEBUG_PRINT ("Getting file items\n"); if (!selection || selection->next != NULL) { return NULL; } file_info = NAUTILUS_FILE_INFO (selection->data); if (nautilus_file_info_is_gone (file_info)) { return NULL; } file = nautilus_file_info_get_location (file_info); if (file == NULL) { DEBUG_PRINT ("No file found\n"); return NULL; } mime_type = nautilus_file_info_get_mime_type (file_info); DEBUG_PRINT ("Mime type: %s\n", mime_type); if (! mime_type) { g_object_unref (file); return NULL; } is_iso = (strcmp (mime_type, "application/x-iso-image") == 0) || (strcmp (mime_type, "application/x-cd-image") == 0) || (strcmp (mime_type, "application/x-cue") == 0) || (strcmp (mime_type, "application/x-toc") == 0) || (strcmp (mime_type, "application/x-cdrdao-toc") == 0); if (is_iso) { /* Whether or not this file is local is not a problem */ item = nautilus_menu_item_new ("NautilusDiscBurn::write_iso", _("_Write to Disc…"), _("Write disc image to a CD or DVD"), "media-optical-data-new"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_signal_connect (item, "activate", G_CALLBACK (write_iso_activate_cb), window); items = g_list_append (items, item); } /* * We handle two cases here. The selection is: * A) a volume * B) a drive * * This is because there is very little distinction between * the two for CD/DVD media */ drive = NULL; volume = NULL; mount = nautilus_file_info_get_mount (file_info); if (mount != NULL) { drive = g_mount_get_drive (mount); volume = g_mount_get_volume (mount); } else { char *uri = g_file_get_uri (file); DEBUG_PRINT ("Mount not found: %s\n", uri); g_free (uri); } if (drive == NULL && volume != NULL) { /* case A */ drive = g_volume_get_drive (volume); } else if (volume == NULL && drive != NULL) { /* case B */ volume = drive_get_first_volume (drive); if (volume == NULL) { DEBUG_PRINT ("Volume not found\n"); } } if (drive != NULL && volume != NULL && drive_is_cd_device (drive) && ! volume_is_blank (volume)) { char *device_path; BraseroMediumMonitor *monitor; BraseroDrive *bdrive; BraseroMedium *medium; BraseroMedia media; BraseroTrackType *type; /* Reminder: the following is not needed since it is already * called in drive_is_cd_device (). * ensure_initialized(); */ device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); monitor = brasero_medium_monitor_get_default (); bdrive = brasero_medium_monitor_get_drive (monitor, device_path); g_object_unref (monitor); medium = brasero_drive_get_medium (bdrive); media = brasero_medium_get_status (medium); g_object_unref (bdrive); type = brasero_track_type_new (); brasero_track_type_set_has_medium (type); brasero_track_type_set_medium_type (type, media); if (brasero_burn_library_input_supported (type) == BRASERO_BURN_OK) { /* user may want to copy it ... */ item = nautilus_menu_item_new ("NautilusDiscBurn::copy_disc", _("_Copy Disc…"), _("Create a copy of this CD or DVD"), "media-optical-copy"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (copy_disc_activate_cb), window); items = g_list_append (items, item); } brasero_track_type_free (type); if (brasero_burn_library_get_media_capabilities (media) & BRASERO_MEDIUM_REWRITABLE) { /* ... or if it's a rewritable medium to blank it ... */ item = nautilus_menu_item_new ("NautilusDiscBurn::blank_disc", _("_Blank Disc…"), _("Blank this CD or DVD"), "media-optical-blank"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (blank_disc_activate_cb), window); items = g_list_append (items, item); } /* - library should be able to checksum * - disc must have a data session */ if (brasero_burn_library_can_checksum () && (media & BRASERO_MEDIUM_HAS_DATA)) { /* ... or verify medium. */ item = nautilus_menu_item_new ("NautilusDiscBurn::check_disc", _("_Check Disc…"), _("Check the data integrity on this CD or DVD"), NULL); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (check_disc_activate_cb), window); items = g_list_append (items, item); } g_free (device_path); } g_object_unref (file); if (drive != NULL) { g_object_unref (drive); } if (volume != NULL) { g_object_unref (volume); } g_free (mime_type); DEBUG_PRINT ("Items returned\n"); return items; }
static BraseroBurnResult brasero_readom_set_argv (BraseroProcess *process, GPtrArray *argv, GError **error) { BraseroBurnResult result = FALSE; BraseroTrackType *output = NULL; BraseroImageFormat format; BraseroJobAction action; BraseroReadom *readom; BraseroMedium *medium; BraseroDrive *drive; BraseroTrack *track; BraseroMedia media; gchar *outfile_arg; gchar *dev_str; readom = BRASERO_READOM (process); /* This is a kind of shortcut */ brasero_job_get_action (BRASERO_JOB (process), &action); if (action == BRASERO_JOB_ACTION_SIZE) return brasero_readom_get_size (readom, error); g_ptr_array_add (argv, g_strdup ("readom")); brasero_job_get_current_track (BRASERO_JOB (readom), &track); drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track)); if (!brasero_drive_get_device (drive)) return BRASERO_BURN_ERR; dev_str = g_strdup_printf ("dev=%s", brasero_drive_get_device (drive)); g_ptr_array_add (argv, dev_str); g_ptr_array_add (argv, g_strdup ("-nocorr")); medium = brasero_drive_get_medium (drive); media = brasero_medium_get_status (medium); output = brasero_track_type_new (); brasero_job_get_output_type (BRASERO_JOB (readom), output); format = brasero_track_type_get_image_format (output); brasero_track_type_free (output); if ((media & BRASERO_MEDIUM_DVD) && format != BRASERO_IMAGE_FORMAT_BIN) { g_set_error (error, BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, _("An internal error occurred")); return BRASERO_BURN_ERR; } if (format == BRASERO_IMAGE_FORMAT_CLONE) { /* NOTE: with this option the sector size is 2448 * because it is raw96 (2352+96) otherwise it is 2048 */ g_ptr_array_add (argv, g_strdup ("-clone")); } else if (format == BRASERO_IMAGE_FORMAT_BIN) { g_ptr_array_add (argv, g_strdup ("-noerror")); /* don't do it for clone since we need the entire disc */ result = brasero_readom_argv_set_iso_boundary (readom, argv, error); if (result != BRASERO_BURN_OK) return result; } else BRASERO_JOB_NOT_SUPPORTED (readom); if (brasero_job_get_fd_out (BRASERO_JOB (readom), NULL) != BRASERO_BURN_OK) { gchar *image; if (format != BRASERO_IMAGE_FORMAT_CLONE && format != BRASERO_IMAGE_FORMAT_BIN) BRASERO_JOB_NOT_SUPPORTED (readom); result = brasero_job_get_image_output (BRASERO_JOB (readom), &image, NULL); if (result != BRASERO_BURN_OK) return result; outfile_arg = g_strdup_printf ("-f=%s", image); g_ptr_array_add (argv, outfile_arg); g_free (image); } else if (format == BRASERO_IMAGE_FORMAT_BIN) { outfile_arg = g_strdup ("-f=-"); g_ptr_array_add (argv, outfile_arg); } else /* unfortunately raw images can't be piped out */ BRASERO_JOB_NOT_SUPPORTED (readom); brasero_job_set_use_average_rate (BRASERO_JOB (process), TRUE); return BRASERO_BURN_OK; }