static ThunarVfsVolume*
thunar_vfs_volume_manager_real_get_volume_by_info (ThunarVfsVolumeManager *manager, 
                                                   const ThunarVfsInfo    *info)
{
  ThunarVfsVolume *best_volume = NULL;
  ThunarVfsPath   *best_path = NULL;
  ThunarVfsPath   *info_path;
  ThunarVfsPath   *path;
  GList           *lp;

  /* translate the info's path to a local path */
  info_path = _thunar_vfs_path_translate (info->path, THUNAR_VFS_PATH_SCHEME_FILE, NULL);
  if (G_LIKELY (info_path != NULL))
    {
      /* otherwise try to find it the hard way */
      for (lp = manager->volumes; lp != NULL; lp = lp->next)
        {
          /* check if the volume is mounted */
          if (!thunar_vfs_volume_is_mounted (lp->data))
            continue;

          /* check if the mount point is an ancestor of the info path */
          path = thunar_vfs_volume_get_mount_point (lp->data);
          if (path == NULL || (!thunar_vfs_path_equal (info_path, path) && !thunar_vfs_path_is_ancestor (info_path, path)))
            continue;

          /* possible match, check if better than previous match */
          if (best_volume == NULL || thunar_vfs_path_equal (path, best_path) || thunar_vfs_path_is_ancestor (path, best_path))
            {
              best_volume = lp->data;
              best_path = path;
            }
        }

      /* cleanup */
      thunar_vfs_path_unref (info_path);
    }

  return best_volume;
}
Exemplo n.º 2
0
static void
thunar_location_entry_item_activated (GtkWidget           *item,
                                      ThunarLocationEntry *location_entry)
{
  ThunarVfsVolume *volume;
  ThunarFile      *file;
  GtkWidget       *window;
  GError          *error = NULL;

  _thunar_return_if_fail (GTK_IS_MENU_ITEM (item));
  _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry));

  /* determine the toplevel window */
  window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry));

  /* check if the item corresponds to a volume */
  volume = g_object_get_data (G_OBJECT (item), "thunar-vfs-volume");
  if (G_UNLIKELY (volume != NULL))
    {
      /* check if the volume isn't already mounted */
      if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume)))
        {
          /* try to mount the volume */
          if (!thunar_vfs_volume_mount (volume, window, &error))
            {
              /* display an error dialog to inform the user */
              thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume));
              g_error_free (error);
              return;
            }
        }

      /* try to determine the mount point of the volume */
      file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (volume), &error);
      if (G_UNLIKELY (file == NULL))
        {
          /* display an error dialog to inform the user */
          thunar_dialogs_show_error (window, error, _("Failed to determine the mount point for %s"), thunar_vfs_volume_get_name (volume));
          g_error_free (error);
          return;
        }
    }
  else
    {
      /* determine the file from the item */
      file = g_object_get_data (G_OBJECT (item), "thunar-file");
      if (G_LIKELY (file != NULL))
        g_object_ref (G_OBJECT (file));
    }

  /* check if we have a file object now */
  if (G_LIKELY (file != NULL))
    {
      /* make sure that this is actually a directory */
      if (thunar_file_is_directory (file))
        {
          /* open the new directory */
          thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file);
        }

      /* cleanup */
      g_object_unref (G_OBJECT (file));
    }
}