Exemplo n.º 1
0
static void
thunar_folder_monitor (ThunarVfsMonitor       *monitor,
                       ThunarVfsMonitorHandle *handle,
                       ThunarVfsMonitorEvent   event,
                       ThunarVfsPath          *handle_path,
                       ThunarVfsPath          *event_path,
                       gpointer                user_data)
{
  ThunarFolder *folder = THUNAR_FOLDER (user_data);
  ThunarFile   *file;
  GList        *lp;
  GList         list;

  _thunar_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor));
  _thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
  _thunar_return_if_fail (folder->monitor == monitor);
  _thunar_return_if_fail (folder->handle == handle);
  _thunar_return_if_fail (folder->job == NULL);

  /* check on which file the event occurred */
  if (!thunar_vfs_path_equal (event_path, thunar_file_get_path (folder->corresponding_file)))
    {
      /* check if we already ship the file */
      for (lp = folder->files; lp != NULL; lp = lp->next)
        if (thunar_vfs_path_equal (event_path, thunar_file_get_path (lp->data)))
          break;

      /* if we don't have it, add it if the event is not an "deleted" event */
      if (G_UNLIKELY (lp == NULL && event != THUNAR_VFS_MONITOR_EVENT_DELETED))
        {
          /* allocate a file for the path */
          file = thunar_file_get_for_path (event_path, NULL);
          if (G_UNLIKELY (file == NULL))
            return;

          /* prepend it to our internal list */
          folder->files = g_list_prepend (folder->files, file);

          /* tell others about the new file */
          list.data = file; list.next = list.prev = NULL;
          g_signal_emit (G_OBJECT (folder), folder_signals[FILES_ADDED], 0, &list);
        }
      else if (lp != NULL)
        {
          /* update/destroy the file */
          if (event == THUNAR_VFS_MONITOR_EVENT_DELETED)
            thunar_file_destroy (lp->data);
          else
            thunar_file_reload (lp->data);
        }
    }
  else
    {
      /* update/destroy the corresponding file */
      if (event == THUNAR_VFS_MONITOR_EVENT_DELETED)
        thunar_file_destroy (folder->corresponding_file);
      else
        thunar_file_reload (folder->corresponding_file);
    }
}
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;
}