static gboolean
try_query_info (GVfsBackend *backend,
                GVfsJobQueryInfo *job,
                const char *filename,
                GFileQueryInfoFlags flags,
                GFileInfo *info,
                GFileAttributeMatcher *matcher)
{
  if (is_root (filename))
  {
    GIcon *icon;
    
    g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
    g_file_info_set_name (info, "/");
    g_file_info_set_display_name (info, g_vfs_backend_get_display_name (backend));
    g_file_info_set_content_type (info, "inode/directory");
    icon = g_vfs_backend_get_icon (backend);
    if (icon != NULL)
      g_file_info_set_icon (info, icon);
    g_vfs_job_succeeded (G_VFS_JOB (job));
  }
  else
    update_cache (G_VFS_BACKEND_AFP_BROWSE (backend), G_VFS_JOB (job)->cancellable,
                  query_info_cb, job);
  
  return TRUE;
}
Exemple #2
0
static GFileInfo *
create_root_file_info (GVfsBackendFtp *ftp)
{
  GFileInfo *info;
  GIcon *icon;
  char *display_name;
 
  info = g_file_info_new ();
  g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);

  g_file_info_set_name (info, "/");
  display_name = g_strdup_printf (_("/ on %s"), ftp->host_display_name);
  g_file_info_set_display_name (info, display_name);
  g_free (display_name);
  g_file_info_set_edit_name (info, "/");

  g_file_info_set_content_type (info, "inode/directory");
  g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, "inode/directory");

  icon = g_themed_icon_new ("folder-remote");
  g_file_info_set_icon (info, icon);
  g_object_unref (icon);

  return info;
}
static void
fill_info (GFileInfo *info, GVfsAfpVolumeData *vol_data, GVfsBackendAfpBrowse *afp_backend)
{
  GIcon *icon;
  GMountSpec *mount_spec;
  char *uri;

  g_file_info_set_name (info, vol_data->name);
  g_file_info_set_display_name (info, vol_data->name);
  g_file_info_set_edit_name (info, vol_data->name);
  g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL, TRUE);
  g_file_info_set_content_type (info, "inode/directory");
  g_file_info_set_file_type (info, G_FILE_TYPE_MOUNTABLE);

  g_file_info_set_attribute_boolean (info, "afp::volume-password-protected", (vol_data->flags & 0x01));

  icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-afp");
  g_file_info_set_icon (info, icon);
  g_object_unref (icon);

  icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
  g_file_info_set_symbolic_icon (info, icon);
  g_object_unref (icon);

  mount_spec = g_mount_spec_new ("afp-volume");
  g_mount_spec_set (mount_spec, "host",
                    g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr)));
  g_mount_spec_set (mount_spec, "volume", vol_data->name);
  g_mount_spec_set (mount_spec, "user", afp_backend->logged_in_user);

  if (g_mount_tracker_has_mount_spec (afp_backend->mount_tracker, mount_spec))
  {
    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, FALSE);
    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, TRUE);
  }
  else
  {
    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, TRUE);
    g_file_info_set_attribute_boolean(info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, FALSE);
  }
  g_mount_spec_unref (mount_spec);

  uri = g_strdup_printf ("afp://%s/%s",
                         g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr)),
                         vol_data->name);
  g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
                                    uri);
  g_free (uri);
}
Exemple #4
0
static gboolean
trash_backend_query_info (GVfsBackend           *vfs_backend,
                          GVfsJobQueryInfo      *job,
                          const char            *filename,
                          GFileQueryInfoFlags    flags,
                          GFileInfo             *info,
                          GFileAttributeMatcher *matcher)
{
  GVfsBackendTrash *backend = G_VFS_BACKEND_TRASH (vfs_backend);

  g_assert (filename[0] == '/');

  if (filename[1])
    {
      GError *error = NULL;
      gboolean is_toplevel;
      TrashItem *item;
      GFile *real;

      real = trash_backend_get_file (backend, filename,
                                     &item, &is_toplevel, &error);

      if (real)
        {
          GFileInfo *real_info;

          real_info = g_file_query_info (real, 
                                         job->attributes,
                                         flags,
                                         G_VFS_JOB (job)->cancellable,
                                         &error);
          g_object_unref (real);

          if (real_info)
            {
              g_file_info_copy_into (real_info, info);
              trash_backend_add_info (item, info, is_toplevel);
              g_vfs_job_succeeded (G_VFS_JOB (job));
              trash_item_unref (item);
              g_object_unref (real_info);

              return TRUE;
            }

          trash_item_unref (item);
        }

      g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
      g_error_free (error);
    }
  else
    {
      GIcon *icon;
      int n_items;

      n_items = trash_root_get_n_items (backend->root);

      g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
      g_file_info_set_name (info, "/");
      /* Translators: this is the display name of the backend */
      g_file_info_set_display_name (info, _("Trash"));
      g_file_info_set_content_type (info, "inode/directory");

      icon = g_themed_icon_new (n_items ? "user-trash-full" : "user-trash");
      g_file_info_set_icon (info, icon);
      g_object_unref (icon);

      icon = g_themed_icon_new (n_items ? "user-trash-full-symbolic" : "user-trash-symbolic");
      g_file_info_set_symbolic_icon (info, icon);
      g_object_unref (icon);

      g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, n_items);

      g_vfs_job_succeeded (G_VFS_JOB (job));
    }

  return TRUE;
}
Exemple #5
0
static gboolean
recent_backend_query_info (GVfsBackend           *vfs_backend,
                           GVfsJobQueryInfo      *job,
                           const char            *filename,
                           GFileQueryInfoFlags    flags,
                           GFileInfo             *info,
                           GFileAttributeMatcher *matcher)
{
  GVfsBackendRecent *backend = G_VFS_BACKEND_RECENT (vfs_backend);

  g_assert (filename[0] == '/');

  if (filename[1])
    {
      GError *error = NULL;
      RecentItem *item = NULL;
      GFile *real;

      real = recent_backend_get_file (backend, filename, &item, &error);

      if (real)
        {
          GFileInfo *real_info;

          real_info = g_file_query_info (real,
                                         job->attributes,
                                         flags,
                                         G_VFS_JOB (job)->cancellable,
                                         &error);
          g_object_unref (real);

          if (real_info)
            {
              g_file_info_copy_into (real_info, info);
              recent_backend_add_info (item, info);
              g_vfs_job_succeeded (G_VFS_JOB (job));
              g_object_unref (real_info);

              return TRUE;
            }
        }

      g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
      g_error_free (error);
    }
  else
    {
      GIcon *icon;

      g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
      g_file_info_set_name (info, "/");
      /* Translators: this is the display name of the backend */
      g_file_info_set_display_name (info, _("Recent"));
      g_file_info_set_content_type (info, "inode/directory");
      g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE);
      g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE);
      g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE);

      icon = g_themed_icon_new ("document-open-recent");
      g_file_info_set_icon (info, icon);
      g_object_unref (icon);
      icon = g_themed_icon_new ("document-open-recent-symbolic");
      g_file_info_set_symbolic_icon (info, icon);
      g_object_unref (icon);

      g_vfs_job_succeeded (G_VFS_JOB (job));
    }

  return TRUE;
}
Exemple #6
0
static void
file_info_from_message (SoupMessage *msg,
                        GFileInfo *info,
                        GFileAttributeMatcher *matcher)
{
  const char *text;
  GHashTable *params;
  char       *basename;
  char       *ed_name;

  basename = ed_name = NULL;

  /* prefer the filename from the Content-Disposition (rfc2183) header
     if one if present. See bug 551298. */
  if (soup_message_headers_get_content_disposition (msg->response_headers,
                                                    NULL, &params))
    {
      const char *name = g_hash_table_lookup (params, "filename");

      if (name)
        basename = g_strdup (name);

      g_hash_table_destroy (params);
    }

  if (basename == NULL)
    {
      const SoupURI *uri;

      uri = soup_message_get_uri (msg);
      basename = http_uri_get_basename (uri->path);
    }

  g_debug ("basename:%s\n", basename);

  /* read http/1.1 rfc, until then we copy the local files
   * behaviour */
  if (basename != NULL &&
      (g_file_attribute_matcher_matches (matcher,
                                         G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) ||
       g_file_attribute_matcher_matches (matcher,
                                         G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME)))
    ed_name = gvfs_file_info_populate_names_as_local (info, basename);

  g_free (basename);
  g_free (ed_name);

  if (soup_message_headers_get_encoding (msg->response_headers) == SOUP_ENCODING_CONTENT_LENGTH)
    {
      goffset start, end, length;
      gboolean ret;

      ret = soup_message_headers_get_content_range (msg->response_headers,
                                                    &start, &end, &length);
      if (ret && length != -1)
        {
          g_file_info_set_size (info, length);
        }
      else if (!ret)
        {
          length = soup_message_headers_get_content_length (msg->response_headers);
          g_file_info_set_size (info, length);
        }
    }

  g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR);

  text = soup_message_headers_get_content_type (msg->response_headers, NULL);
  if (text)
    {
      GIcon *icon;

      g_file_info_set_content_type (info, text);
      g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, text);

      icon = g_content_type_get_icon (text);
      g_file_info_set_icon (info, icon);
      g_object_unref (icon);

      icon = g_content_type_get_symbolic_icon (text);
      g_file_info_set_symbolic_icon (info, icon);
      g_object_unref (icon);
    }


  text = soup_message_headers_get_one (msg->response_headers,
                                       "Last-Modified");
  if (text)
    {
      SoupDate *sd;
      GTimeVal tv;

      sd = soup_date_new_from_string(text);
      if (sd)
        {
          soup_date_to_timeval (sd, &tv);
	  g_file_info_set_modification_time (info, &tv);
          soup_date_free (sd);
        }
    }


  text = soup_message_headers_get_one (msg->response_headers,
                                       "ETag");
  if (text)
    {
      g_file_info_set_attribute_string (info,
                                        G_FILE_ATTRIBUTE_ETAG_VALUE,
                                        text);
    }
}
/* Function implementations */
static void 
fl_parser_start_node_cb (void        *user_data,
			 const char  *node_name,
			 const char **attr)
{
	ParserData *data;
	GFileInfo  *info;
	
	data = (ParserData *) user_data;
	
	data->depth++;
	
	d(g_print ("%d: %s\n", data->depth, node_name));

	if (data->depth > 2) {
		g_set_error (data->error,  
			     G_MARKUP_ERROR,  
			     G_MARKUP_ERROR_INVALID_CONTENT,  
			     "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'",  
			     node_name); 
		return;
	}
	else if (data->depth == 1) {
		if (strcmp (node_name, "folder-listing") != 0) {
			g_set_error (data->error,  
				     G_MARKUP_ERROR,  
				     G_MARKUP_ERROR_INVALID_CONTENT,  
				     "Expected 'folder-listing', got '%s'",  
				     node_name);  
			return;
		}

		return;
	}

	if (strcmp (node_name, "parent-folder") == 0) {
		/* Just ignore parent-folder items */
		return;
	}
	
	info = g_file_info_new ();

	if (strcmp (node_name, "file") == 0) {
		g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR);
	}
	else if (strcmp (node_name, "folder") == 0) {
		GIcon *icon;
		g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
		g_file_info_set_content_type (info, "inode/directory");

		icon = g_themed_icon_new ("folder");
		g_file_info_set_icon (info, icon);
		g_object_unref (icon);
		icon = g_themed_icon_new ("folder-symbolic");
		g_file_info_set_symbolic_icon (info, icon);
		g_object_unref (icon);
	} else {
		g_set_error (data->error,
			     G_MARKUP_ERROR,
			     G_MARKUP_ERROR_UNKNOWN_ELEMENT,
			     "Unknown element '%s'",
			     node_name);
		return;
	}

	if (!fl_parser_fill_file_info (info, attr)) {
		d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n",
			   node_name));
		g_object_unref (info);
		return;
	}

	if (g_file_info_get_content_type (info) == NULL) {
		char *mime_type;
		mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL);
		g_file_info_set_content_type (info, mime_type);
		g_free (mime_type);
	}

	if (g_file_info_get_content_type (info) == NULL) {
		g_file_info_set_content_type (info, "application/octet-stream");
	}

	if (g_file_info_get_file_type (info) ==  G_FILE_TYPE_REGULAR) {
		GIcon *icon;
                const char *content_type;

                content_type = g_file_info_get_content_type (info);

		icon = g_content_type_get_icon (content_type);
		if (icon != NULL) {
			if (G_IS_THEMED_ICON (icon))
				g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic");
			g_file_info_set_icon (info, icon);
			g_object_unref (icon);
		}

		icon = g_content_type_get_symbolic_icon (content_type);
		if (icon != NULL) {
			if (G_IS_THEMED_ICON (icon))
				g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic");
			g_file_info_set_symbolic_icon (info, icon);
			g_object_unref (icon);
		}
	}

	/* Permissions on folders in OBEX has different semantics than POSIX.
	 * In POSIX, if a folder is not writable, it means that it's content
	 * can't be removed, whereas in OBEX, it just means that the folder
	 * itself can't be removed. Therefore we must set all folders to RWD and
	 * handle the error when it happens. */
	if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
		g_file_info_set_attribute_boolean (info,
						   G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
						   TRUE);
		g_file_info_set_attribute_boolean (info,
						   G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
						   TRUE);
	}
	
	data->elements = g_list_prepend (data->elements, info);
}