ASVolume *ASVolume_newGMount (GMount *g_m) { ASVolume *v; if (g_m == NULL || g_mount_is_shadowed (g_m)) return NULL; else { GVolume *volume = g_mount_get_volume (g_m); if (volume) { g_object_unref (volume); return NULL; } } v = ASVolume_create(); v->gMount = g_m; v->name = g_mount_get_name (v->gMount); if (g_mount_can_eject (g_m)) set_flags (v->flags, ASVolume_Ejectable); set_flags (v->flags, ASVolume_Mounted); v->icon = g_mount_get_icon (g_m); ASVolume_parseGnomeIconString (v); { char *mount_str = ASVolume_toString(v); show_activity("%s\n", mount_str); safefree(mount_str); } return v; }
static gboolean rb_removable_media_manager_source_can_eject (RBRemovableMediaManager *mgr) { RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr); GVolume *volume; GMount *mount; gboolean result; if (RB_IS_REMOVABLE_MEDIA_SOURCE (priv->selected_source) == FALSE) { return FALSE; } g_object_get (priv->selected_source, "volume", &volume, NULL); if (volume != NULL) { result = g_volume_can_eject (volume); g_object_unref (volume); return result; } g_object_get (priv->selected_source, "mount", &mount, NULL); if (mount != NULL) { result = g_mount_can_eject (mount) || g_mount_can_unmount (mount); g_object_unref (mount); return result; } return FALSE; }
static gboolean default_can_eject (RBDeviceSource *source) { gboolean result = FALSE; GVolume *volume = NULL; GMount *mount = NULL; if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } if (volume != NULL) { result = g_volume_can_eject (volume); g_object_unref (volume); if (mount != NULL) { g_object_unref (mount); } } else if (mount != NULL) { result = g_mount_can_eject (mount) || g_mount_can_unmount (mount); if (mount != NULL) { g_object_unref (mount); } } return result; }
static void rb_removable_media_manager_cmd_eject_medium (GtkAction *action, RBRemovableMediaManager *mgr) { RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr); RBRemovableMediaSource *source = RB_REMOVABLE_MEDIA_SOURCE (priv->selected_source); GVolume *volume; GMount *mount; /* try ejecting based on volume first, then based on the mount, * and finally try unmounting. */ g_object_get (source, "volume", &volume, NULL); if (volume != NULL) { if (g_volume_can_eject (volume)) { rb_debug ("ejecting volume"); g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL, (GAsyncReadyCallback) rb_removable_media_manager_eject_cb, g_object_ref (mgr)); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this volume"); } g_object_unref (volume); return; } g_object_get (source, "mount", &mount, NULL); if (mount != NULL) { if (g_mount_can_eject (mount)) { rb_debug ("ejecting mount"); g_mount_eject (mount, G_MOUNT_UNMOUNT_NONE, NULL, (GAsyncReadyCallback) rb_removable_media_manager_eject_cb, g_object_ref (mgr)); } else if (g_mount_can_unmount (mount)) { rb_debug ("unmounting mount"); g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL, (GAsyncReadyCallback) rb_removable_media_manager_unmount_cb, g_object_ref (mgr)); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this mount"); } g_object_unref (mount); } }
void GioLister::UnmountDevice(const QString &id) { QMutexLocker l(&mutex_); if (!devices_.contains(id)) return; const DeviceInfo& info = devices_[id]; if (!info.mount) return; if (info.volume) { if (g_volume_can_eject(info.volume)) { g_volume_eject_with_operation( info.volume, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) VolumeEjectFinished, NULL); g_object_unref(info.volume); return; } } if (g_mount_can_eject(info.mount)) { g_mount_eject_with_operation( info.mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) MountEjectFinished, NULL); } else if (g_mount_can_unmount(info.mount)) { g_mount_unmount_with_operation( info.mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) MountUnmountFinished, NULL); } }
static GMount * totem_get_mount_for_uri (const char *path) { GMount *mount; GFile *file; file = g_file_new_for_path (path); mount = g_file_find_enclosing_mount (file, NULL, NULL); g_object_unref (file); if (mount == NULL) return NULL; /* FIXME: We used to explicitly check whether it was a CD/DVD */ if (g_mount_can_eject (mount) == TRUE) { g_object_unref (mount); return NULL; } return mount; }
static void volume_delete_dialog (GtkWidget *parent_view, NautilusDesktopLink *link) { GMount *mount; char *dialog_str; char *display_name; mount = nautilus_desktop_link_get_mount (link); if (mount != NULL) { display_name = nautilus_desktop_link_get_display_name (link); dialog_str = g_strdup_printf (_("You cannot move the volume “%s” to the trash."), display_name); g_free (display_name); if (g_mount_can_eject (mount)) { eel_run_simple_dialog (parent_view, FALSE, GTK_MESSAGE_ERROR, dialog_str, _("If you want to eject the volume, please use Eject in the " "popup menu of the volume."), _("_OK"), NULL); } else { eel_run_simple_dialog (parent_view, FALSE, GTK_MESSAGE_ERROR, dialog_str, _("If you want to unmount the volume, please use Unmount Volume in the " "popup menu of the volume."), _("_OK"), NULL); } g_object_unref (mount); g_free (dialog_str); } }
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer) { g_return_if_fail (cURI != NULL); cd_message ("%s (%s)", __func__, cURI); gchar *cTargetURI = NULL; GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI); if (pMount == NULL || ! G_IS_MOUNT (pMount)) { return ; } if ( ! g_mount_can_unmount (pMount)) return ; gboolean bCanEject = g_mount_can_eject (pMount); gboolean bCanUnmount = g_mount_can_unmount (pMount); cd_message ("eject:%d / unmount:%d\n", bCanEject, bCanUnmount); if (! bCanEject && ! bCanUnmount) return ; gpointer *data2 = g_new (gpointer, 5); data2[0] = pCallback; data2[1] = GINT_TO_POINTER (bCanEject ? 2 : 0); data2[2] = g_mount_get_name (pMount); data2[3] = icon; data2[4] = pContainer; if (bCanEject) g_mount_eject (pMount, G_MOUNT_UNMOUNT_NONE, NULL, (GAsyncReadyCallback) _vfs_backend_mount_callback, data2); else g_mount_unmount (pMount, G_MOUNT_UNMOUNT_NONE , NULL, (GAsyncReadyCallback) _vfs_backend_mount_callback, data2); }
static void list_mounts (GList *mounts, int indent, gboolean only_with_no_volume) { GList *l; int c; GMount *mount; GVolume *volume; char *name, *uuid, *uri; GFile *root, *default_location; GIcon *icon; char **x_content_types; char *type_name; const gchar *sort_key; for (c = 0, l = mounts; l != NULL; l = l->next, c++) { mount = (GMount *) l->data; if (only_with_no_volume) { volume = g_mount_get_volume (mount); if (volume != NULL) { g_object_unref (volume); continue; } } name = g_mount_get_name (mount); root = g_mount_get_root (mount); uri = g_file_get_uri (root); g_print ("%*sMount(%d): %s -> %s\n", indent, "", c, name, uri); type_name = get_type_name (mount); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { uuid = g_mount_get_uuid (mount); if (uuid) g_print ("%*suuid=%s\n", indent + 2, "", uuid); default_location = g_mount_get_default_location (mount); if (default_location) { char *loc_uri = g_file_get_uri (default_location); g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri); g_free (loc_uri); g_object_unref (default_location); } icon = g_mount_get_icon (mount); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } x_content_types = g_mount_guess_content_type_sync (mount, FALSE, NULL, NULL); if (x_content_types != NULL && g_strv_length (x_content_types) > 0) { int n; g_print ("%*sx_content_types:", indent + 2, ""); for (n = 0; x_content_types[n] != NULL; n++) g_print (" %s", x_content_types[n]); g_print ("\n"); } g_strfreev (x_content_types); g_print ("%*scan_unmount=%d\n", indent + 2, "", g_mount_can_unmount (mount)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_mount_can_eject (mount)); g_print ("%*sis_shadowed=%d\n", indent + 2, "", g_mount_is_shadowed (mount)); sort_key = g_mount_get_sort_key (mount); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); g_free (uuid); } g_object_unref (root); g_free (name); g_free (uri); } }
/* returns TRUE if a folder window should be opened */ static gboolean do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAutorunOpenWindow open_window_func, gpointer user_data) { AutorunDialogData *data; GtkWidget *dialog; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *label; GtkWidget *combo_box; GtkWidget *always_check_button; GtkWidget *eject_button; GtkWidget *image; char *markup; char *content_description; char *mount_name; GIcon *icon; GdkPixbuf *pixbuf; CajaIconInfo *icon_info; int icon_size; gboolean user_forced_dialog; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; char *media_greeting; gboolean ret; ret = FALSE; mount_name = NULL; if (g_content_type_is_a (x_content_type, "x-content/win32-software")) { /* don't pop up the dialog anyway if the content type says * windows software. */ goto out; } user_forced_dialog = is_shift_pressed (); caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; if (user_forced_dialog) { goto show_dialog; } if (!pref_ask && !pref_ignore && !pref_open_folder) { GAppInfo *app_info; app_info = g_app_info_get_default_for_type (x_content_type, FALSE); if (app_info != NULL) { caja_autorun_launch_for_mount (mount, app_info); } goto out; } if (pref_open_folder) { ret = TRUE; goto out; } if (pref_ignore) { goto out; } show_dialog: mount_name = g_mount_get_name (mount); dialog = gtk_dialog_new (); hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); icon = g_mount_get_icon (mount); icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG); icon_info = caja_icon_info_lookup (icon, icon_size); pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); g_object_unref (icon); image = gtk_image_new_from_pixbuf (pixbuf); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0); /* also use the icon on the dialog */ gtk_window_set_title (GTK_WINDOW (dialog), mount_name); gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); g_object_unref (pixbuf); vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); label = gtk_label_new (NULL); /* Customize greeting for well-known x-content types */ if (strcmp (x_content_type, "x-content/audio-cdda") == 0) { media_greeting = _("You have just inserted an Audio CD."); } else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) { media_greeting = _("You have just inserted an Audio DVD."); } else if (strcmp (x_content_type, "x-content/video-dvd") == 0) { media_greeting = _("You have just inserted a Video DVD."); } else if (strcmp (x_content_type, "x-content/video-vcd") == 0) { media_greeting = _("You have just inserted a Video CD."); } else if (strcmp (x_content_type, "x-content/video-svcd") == 0) { media_greeting = _("You have just inserted a Super Video CD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank CD."); } else if (strcmp (x_content_type, "x-content/blank-dvd") == 0) { media_greeting = _("You have just inserted a blank DVD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank Blu-Ray disc."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank HD DVD."); } else if (strcmp (x_content_type, "x-content/image-photocd") == 0) { media_greeting = _("You have just inserted a Photo CD."); } else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) { media_greeting = _("You have just inserted a Picture CD."); } else if (strcmp (x_content_type, "x-content/image-dcf") == 0) { media_greeting = _("You have just inserted a medium with digital photos."); } else if (strcmp (x_content_type, "x-content/audio-player") == 0) { media_greeting = _("You have just inserted a digital audio player."); } else if (g_content_type_is_a (x_content_type, "x-content/software")) { media_greeting = _("You have just inserted a medium with software intended to be automatically started."); } else { /* fallback to generic greeting */ media_greeting = _("You have just inserted a medium."); } markup = g_strdup_printf ("<big><b>%s %s</b></big>", media_greeting, _("Choose what application to launch.")); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); label = gtk_label_new (NULL); content_description = g_content_type_get_description (x_content_type); markup = g_strdup_printf (_("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\"."), mount_name, content_description); g_free (content_description); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); data = g_new0 (AutorunDialogData, 1); data->dialog = dialog; data->mount = g_object_ref (mount); data->remember = !pref_ask; data->selected_ignore = pref_ignore; data->x_content_type = g_strdup (x_content_type); data->selected_app = g_app_info_get_default_for_type (x_content_type, FALSE); data->open_window_func = open_window_func; data->user_data = user_data; combo_box = gtk_combo_box_new (); caja_autorun_prepare_combo_box (combo_box, x_content_type, FALSE, TRUE, FALSE, autorun_combo_changed, data); g_signal_connect (G_OBJECT (combo_box), "key-press-event", G_CALLBACK (combo_box_enter_ok), dialog); gtk_box_pack_start (GTK_BOX (vbox), combo_box, TRUE, TRUE, 0); always_check_button = gtk_check_button_new_with_mnemonic (_("_Always perform this action")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (always_check_button), data->remember); g_signal_connect (G_OBJECT (always_check_button), "toggled", G_CALLBACK (autorun_always_toggled), data); gtk_box_pack_start (GTK_BOX (vbox), always_check_button, TRUE, TRUE, 0); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); if (g_mount_can_eject (mount)) { GtkWidget *eject_image; eject_button = gtk_button_new_with_mnemonic (_("_Eject")); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "media-eject", caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON), 0, NULL); eject_image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); gtk_button_set_image (GTK_BUTTON (eject_button), eject_image); data->should_eject = TRUE; } else { eject_button = gtk_button_new_with_mnemonic (_("_Unmount")); data->should_eject = FALSE; } gtk_dialog_add_action_widget (GTK_DIALOG (dialog), eject_button, AUTORUN_DIALOG_RESPONSE_EJECT); gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), eject_button, TRUE); /* show the dialog */ gtk_widget_show_all (dialog); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (autorun_dialog_response), data); g_signal_connect (G_OBJECT (data->mount), "unmounted", G_CALLBACK (autorun_dialog_mount_unmounted), data); out: g_free (mount_name); return ret; }
static void default_eject (RBDeviceSource *source) { GVolume *volume = NULL; GMount *mount = NULL; if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } /* try ejecting based on volume first, then based on the mount, * and finally try unmounting. */ if (volume != NULL) { if (g_volume_can_eject (volume)) { rb_debug ("ejecting volume"); g_volume_eject_with_operation (volume, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) eject_cb, NULL); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this volume"); } } else if (mount != NULL) { if (g_mount_can_eject (mount)) { rb_debug ("ejecting mount"); g_mount_eject_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) eject_cb, NULL); } else if (g_mount_can_unmount (mount)) { rb_debug ("unmounting mount"); g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) unmount_cb, NULL); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this mount"); } } if (volume != NULL) { g_object_unref (volume); } if (mount != NULL) { g_object_unref (mount); } }
// -------------------------------------------------------------------------------- // bool guGIO_Mount::CanUnmount( void ) { return g_mount_can_eject( m_Mount ); }
static VALUE rg_can_eject_p(VALUE self) { return CBOOL2RVAL(g_mount_can_eject(_SELF(self))); }
static void _tile_eject_cb (MpdStorageDeviceTile *tile, MpdDevicesTile *self) { MpdDevicesTilePrivate *priv = GET_PRIVATE (self); char const *uri; GList *mounts; GList *iter; uri = mpd_storage_device_tile_get_mount_point (tile); mounts = g_volume_monitor_get_mounts (priv->monitor); iter = g_list_find_custom (mounts, uri, (GCompareFunc) _find_mount_cb); if (iter) { GMount *mount = G_MOUNT (iter->data); GDrive *drive; GVolume *vol; gboolean ejected = TRUE; drive = g_mount_get_drive (mount); vol = g_mount_get_volume (mount); if (drive && g_drive_can_eject (drive)) { g_debug ("%s() ejecting drive %s", __FUNCTION__, uri); g_drive_eject_with_operation (drive, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback)_drive_eject_cb, tile); } else if (vol && g_volume_can_eject (vol)) { g_debug ("%s() ejecting volume %s", __FUNCTION__, uri); g_volume_eject_with_operation (vol, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback)_vol_eject_cb, tile); } else if (g_mount_can_eject (mount)) { g_debug ("%s() ejecting mount %s", __FUNCTION__, uri); g_mount_eject_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) _mount_eject_cb, tile); } else if (g_mount_can_unmount (mount)) { g_debug ("%s() unmounting mount %s", __FUNCTION__, uri); g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) _mount_unmount_cb, tile); } else { ejected = FALSE; g_warning ("Eject or unmount not possible"); } mx_widget_set_disabled (MX_WIDGET (tile), ejected); /* TODO: inform user of ejection with text inside the tile: * For that (and other reasons) this code really should be inside * MpdStorageDeviceTile */ /* TODO: we want to start a 2s timeout here, and if not done sync'ing when * expired show the message "Ejecting ..." */ if (drive) { g_object_unref (drive); } if (vol) { g_object_unref (vol); } } g_list_foreach (mounts, (GFunc) g_object_unref, NULL); g_list_free (mounts); }