static void do_mount_tests (GDrive *drive, GVolume *volume, GMount *mount) { GDrive *d; GVolume *v; gchar *name; gchar *uuid; name = g_mount_get_name (mount); g_assert (name != NULL); g_free (name); v = g_mount_get_volume (mount); g_assert (v == volume); if (v != NULL) g_object_unref (v); d = g_mount_get_drive (mount); g_assert (d == drive); if (d != NULL) g_object_unref (d); uuid = g_mount_get_uuid (mount); if (uuid) { GMount *m; m = g_volume_monitor_get_mount_for_uuid (monitor, uuid); g_assert (m == mount); g_object_unref (m); g_free (uuid); } }
void GioLister::MountChanged(GMount* mount) { QString id; { QMutexLocker l(&mutex_); id = FindUniqueIdByMount(mount); if (id.isNull()) return; g_object_ref(mount); DeviceInfo new_info; new_info.ReadMountInfo(mount); new_info.ReadVolumeInfo(g_mount_get_volume(mount)); new_info.ReadDriveInfo(g_mount_get_drive(mount)); // Ignore the change if the new info is useless if (new_info.invalid_enclosing_mount || (devices_[id].filesystem_size != 0 && new_info.filesystem_size == 0) || (!devices_[id].filesystem_type.isEmpty() && new_info.filesystem_type.isEmpty())) return; devices_[id] = new_info; } emit DeviceChanged(id); }
static void test_mounts (void) { GList *mounts, *l; mounts = g_volume_monitor_get_mounts (monitor); for (l = mounts; l; l = l->next) { GMount *mount = l->data; GVolume *volume; GDrive *drive; drive = g_mount_get_drive (mount); volume = g_mount_get_volume (mount); do_mount_tests (drive, volume, mount); if (drive != NULL) g_object_unref (drive); if (volume != NULL) g_object_unref (volume); } g_list_free_full (mounts, g_object_unref); }
static void g_udisks_mount_eject_with_operation (GMount* base, GMountUnmountFlags flags, GMountOperation* mount_operation, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data) { GUDisksMount* mnt = G_UDISKS_MOUNT(base); GDrive* drv = g_mount_get_drive(base); if(drv) { EjectData* data = g_slice_new(EjectData); data->mnt = g_object_ref(mnt); data->callback = callback; data->user_data = user_data; g_drive_eject(drv, flags, cancellable, on_drive_ejected, data); g_object_unref(drv); } }
void GioLister::MountAdded(GMount* mount) { g_object_ref(mount); DeviceInfo info; info.ReadVolumeInfo(g_mount_get_volume(mount)); #ifdef HAVE_AUDIOCD if (info.volume_root_uri.startsWith("cdda")) // Audio CD devices are already handled by CDDA lister return; #endif info.ReadMountInfo(mount); info.ReadDriveInfo(g_mount_get_drive(mount)); if (!info.is_suitable()) return; QString old_id; { QMutexLocker l(&mutex_); // The volume might already exist - either mounted or unmounted. foreach (const QString& id, devices_.keys()) { if (devices_[id].volume == info.volume) { old_id = id; break; } } if (!old_id.isEmpty() && old_id != info.unique_id()) { // If the ID has changed (for example, after it's been mounted), we need // to remove the old device. devices_.remove(old_id); emit DeviceRemoved(old_id); old_id = QString(); } devices_[info.unique_id()] = info; } if (!old_id.isEmpty()) emit DeviceChanged(old_id); else { emit DeviceAdded(info.unique_id()); } }
gboolean nemo_action_get_visibility (NemoAction *action, GList *selection, NemoFile *parent) { gboolean selection_type_show = FALSE; gboolean extension_type_show = TRUE; gboolean condition_type_show = TRUE; recalc_dbus_conditions (action); if (!nemo_action_get_dbus_satisfied (action)) goto out; gchar **conditions = nemo_action_get_conditions (action); guint condition_count = conditions != NULL ? g_strv_length (conditions) : 0; if (condition_count > 0) { int j; gchar *condition; for (j = 0; j < condition_count; j++) { condition = conditions[j]; if (g_strcmp0 (condition, "desktop") == 0) { gchar *name = nemo_file_get_display_name (parent); if (g_strcmp0 (name, "x-nemo-desktop") != 0) condition_type_show = FALSE; g_free (name); } else if (g_strcmp0 (condition, "removable") == 0) { gboolean is_removable = FALSE; if (g_list_length (selection) > 0) { GMount *mount = nemo_file_get_mount (selection->data); if (mount) { GDrive *drive = g_mount_get_drive (mount); if (drive) { if (g_drive_is_media_removable (drive)) is_removable = TRUE; g_object_unref (drive); } } } condition_type_show = is_removable; } else if (g_str_has_prefix (condition, "gsettings")) { condition_type_show = check_gsettings_condition (action, condition); } if (!condition_type_show) break; } } if (!condition_type_show) goto out; SelectionType selection_type = nemo_action_get_selection_type (action); GList *iter; guint selected_count = g_list_length (selection); switch (selection_type) { case SELECTION_SINGLE: selection_type_show = selected_count == 1; break; case SELECTION_MULTIPLE: selection_type_show = selected_count > 1; break; case SELECTION_NOT_NONE: selection_type_show = selected_count > 0; break; case SELECTION_NONE: selection_type_show = selected_count == 0; break; case SELECTION_ANY: selection_type_show = TRUE; break; default: selection_type_show = selected_count == selection_type; break; } gchar **extensions = nemo_action_get_extension_list (action); gchar **mimetypes = nemo_action_get_mimetypes_list (action); guint ext_count = extensions != NULL ? g_strv_length (extensions) : 0; guint mime_count = mimetypes != NULL ? g_strv_length (mimetypes) : 0; if (ext_count == 1 && g_strcmp0 (extensions[0], "any") == 0) goto out; gboolean found_match = TRUE; for (iter = selection; iter != NULL && found_match; iter = iter->next) { found_match = FALSE; gchar *raw_fn = nemo_file_get_name (NEMO_FILE (iter->data)); gchar *filename = g_ascii_strdown (raw_fn, -1); g_free (raw_fn); int i; gboolean is_dir = get_is_dir_hack (iter->data); if (ext_count > 0) { for (i = 0; i < ext_count; i++) { if (g_strcmp0 (extensions[i], "dir") == 0) { if (is_dir) { found_match = TRUE; break; } } else if (g_strcmp0 (extensions[i], "none") == 0) { if (g_strrstr (filename, ".") == NULL) { found_match = TRUE; break; } } else if (g_strcmp0 (extensions[i], "nodirs") == 0) { if (!is_dir) { found_match = TRUE; break; } } else { gchar *str = g_ascii_strdown (extensions[i], -1); if (g_str_has_suffix (filename, str)) { found_match = TRUE; } g_free (str); if (found_match) { break; } } } g_free (filename); } if (mime_count > 0) { for (i = 0; i < mime_count; i++) { if (nemo_file_is_mime_type (NEMO_FILE (iter->data), mimetypes[i])) { found_match = TRUE; break; } } } if (nemo_file_is_mime_type (NEMO_FILE (iter->data), "application/x-nemo-link")) { found_match = FALSE; } } extension_type_show = found_match; out: return selection_type_show && extension_type_show && condition_type_show; }
static void update_device_source_list (DialogData *data) { gboolean source_available = FALSE; GList *mounts; GList *scan; gtk_list_store_clear (data->device_list_store); mounts = g_volume_monitor_get_mounts (g_volume_monitor_get ()); for (scan = mounts; scan; scan = scan->next) { GMount *mount = scan->data; GtkTreeIter iter; GFile *root; GIcon *icon; char *name; GDrive *drive; if (g_mount_is_shadowed (mount)) continue; gtk_list_store_append (data->device_list_store, &iter); root = g_mount_get_root (mount); if (data->source == NULL) data->source = g_file_dup (root); icon = g_mount_get_icon (mount); name = g_mount_get_name (mount); drive = g_mount_get_drive (mount); if (drive != NULL) { char *drive_name; char *tmp; drive_name = g_drive_get_name (drive); tmp = g_strconcat (drive_name, ": ", name, NULL); g_free (name); g_object_unref (drive); name = tmp; g_free (drive_name); } gtk_list_store_set (data->device_list_store, &iter, SOURCE_LIST_COLUMN_MOUNT, mount, SOURCE_LIST_COLUMN_ICON, icon, SOURCE_LIST_COLUMN_NAME, name, -1); if (g_file_equal (data->source, root)) { source_available = TRUE; gtk_combo_box_set_active_iter (GTK_COMBO_BOX (data->device_chooser), &iter); } g_free (name); g_object_unref (icon); g_object_unref (root); } if (! source_available) { _g_object_unref (data->source); data->source = NULL; load_file_list (data); } _g_object_list_unref (mounts); }
static VALUE rg_drive(VALUE self) { return GOBJ2RVAL_UNREF(g_mount_get_drive(_SELF(self))); }
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI) { g_return_val_if_fail (cBaseURI != NULL, NULL); cd_message ("%s (%s)", __func__, cBaseURI); gchar *cURI; gboolean bAddHome = FALSE; if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0) { cURI = g_strdup ("computer://"); bAddHome = TRUE; ///*cFullURI = cURI; ///return vfs_backend_list_volumes (); //vfs_backend_list_volumes (); } else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0) cURI = g_strdup ("network://"); else cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : g_strdup (cBaseURI)); *cFullURI = cURI; GFile *pFile = g_file_new_for_uri (cURI); GError *erreur = NULL; const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile, cAttributes, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return NULL; } int iOrder = 0; GList *pIconList = NULL; Icon *icon; GFileInfo *pFileInfo; do { pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); erreur = NULL; continue; } if (pFileInfo == NULL) break ; gboolean bIsHidden = g_file_info_get_is_hidden (pFileInfo); if (bListHiddenFiles || ! bIsHidden) { GFileType iFileType = g_file_info_get_file_type (pFileInfo); GIcon *pFileIcon = g_file_info_get_icon (pFileInfo); if (pFileIcon == NULL) { cd_message ("AUCUNE ICONE"); continue; } const gchar *cFileName = g_file_info_get_name (pFileInfo); const gchar *cMimeType = g_file_info_get_content_type (pFileInfo); gchar *cName = NULL; icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strconcat (*cFullURI, "/", cFileName, NULL); cd_message ("+ %s (mime:%s)", icon->cBaseURI, cMimeType); if (iFileType == G_FILE_TYPE_MOUNTABLE) { const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); cd_message (" c'est un point de montage correspondant a %s", cTargetURI); GMount *pMount = NULL; if (cTargetURI != NULL) { icon->acCommand = g_strdup (cTargetURI); GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { cName = g_mount_get_name (pMount); cd_message ("un GMount existe (%s)", cName); GVolume *volume = g_mount_get_volume (pMount); if (volume) cd_message (" volume associe : %s", g_volume_get_name (volume)); GDrive *drive = g_mount_get_drive (pMount); if (drive) cd_message (" disque associe : %s", g_drive_get_name (drive)); ///pFileIcon = g_mount_get_icon (pMount); } else { cName = g_strdup (cFileName); gchar *str = strrchr (cName, '.'); // on vire l'extension ".volume" ou ".drive". if (str != NULL) { *str = '\0'; if (strcmp (str+1, "link") == 0) { if (strcmp (cName, "root") == 0) { g_free (cName); cName = g_strdup ("/"); } } else if (strcmp (str+1, "drive") == 0) // on cherche un nom plus parlant si possible. { gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cName); if (cVolumeName != NULL) { g_free (cName); g_free (cVolumeName); continue; /// apparemment il n'est plus necessaire d'afficher les .drives qui ont 1 (ou plusieurs ?) volumes, car ces derniers sont dans la liste, donc ca fait redondant. /**if (strcmp (cVolumeName, "discard") == 0) continue; g_free (cName); cName = cVolumeName;*/ } } } } icon->iVolumeID = 1; cd_message ("le nom de ce volume est : %s", cName); } else cName = g_strdup (cFileName); if (icon->acCommand == NULL) icon->acCommand = g_strdup (icon->cBaseURI); icon->acName = cName; icon->acFileName = NULL; if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0) { gchar *cHostname = NULL; gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur); if (erreur != NULL) { g_error_free (erreur); erreur = NULL; } else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux. { icon->acFileName = g_strdup (cFilePath); cairo_dock_remove_html_spaces (icon->acFileName); } g_free (cHostname); g_free (cFilePath); } if (icon->acFileName == NULL) { icon->acFileName = _cd_get_icon_path (pFileIcon); cd_message ("icon->acFileName : %s", icon->acFileName); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE) icon->fOrder = g_file_info_get_size (pFileInfo); else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE) { GTimeVal t; g_file_info_get_modification_time (pFileInfo, &t); icon->fOrder = t.tv_sec; } else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE) icon->fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0); if (icon->fOrder == 0) // un peu moyen mais mieux que rien non ? icon->fOrder = iOrder; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); //g_list_prepend (pIconList, icon); iOrder ++; } } while (TRUE); // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'. if (bAddHome && pIconList != NULL) { icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strdup_printf ("file://%s", "/home"); icon->acCommand = g_strdup ("/home"); //icon->acCommand = g_strdup (icon->cBaseURI); icon->iVolumeID = 0; icon->acName = g_strdup ("home"); Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/"); if (pRootIcon == NULL) { pRootIcon = cairo_dock_get_first_icon (pIconList); g_print ("domage ! (%s:%s)\n", pRootIcon->acCommand, pRootIcon->acName); } icon->acFileName = g_strdup (pRootIcon->acFileName); icon->fOrder = iOrder++; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME) pIconList = cairo_dock_sort_icons_by_name (pIconList); else pIconList = cairo_dock_sort_icons_by_order (pIconList); return pIconList; }
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 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); }