Exemplo n.º 1
0
static void _volumes_refresh(Volumes * volumes, GList * selection)
{
	char * path = (selection != NULL) ? selection->data : NULL;
#ifdef __NetBSD__
	struct statvfs * mnt;
	int res;
	int i;
#endif

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, path);
#endif
	if(path == NULL)
	{
		if(volumes->source != 0)
			g_source_remove(volumes->source);
		volumes->source = 0;
		return;
	}
	/* FIXME no longer clear the list every time */
	gtk_list_store_clear(volumes->store);
#ifdef __NetBSD__
	if((res = getmntinfo(&mnt, ST_WAIT)) <= 0)
		return;
	for(i = 0; i < res; i++)
		_refresh_add(volumes, NULL, mnt[i].f_mntfromname,
				mnt[i].f_mntonname, mnt[i].f_fstypename);
#else
	_refresh_add(volumes, NULL, NULL, "/", NULL);
#endif
	if(volumes->source == 0)
		volumes->source = g_timeout_add(1000, _volumes_on_timeout,
				volumes);
}
Exemplo n.º 2
0
static void _favorites_refresh(Favorites * favorites, GList * selection)
{
	const char scheme[] = "file:///";
	FILE * fp;
	gchar * filename;
	gint size;
	char buf[512];
	size_t len;
	int c;

	/* obtain the current selection */
	g_list_foreach(favorites->selection, (GFunc)g_free, NULL);
	g_list_free(favorites->selection);
	favorites->selection = NULL;
	g_list_foreach(selection, (GFunc)_refresh_copy, favorites);
	/* refresh the bookmarks */
	gtk_list_store_clear(favorites->store);
	if((filename = _favorites_get_filename()) == NULL)
		return;
	fp = fopen(filename, "r");
	g_free(filename);
	if(fp == NULL)
		return;
	gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &size, &size);
	while(fgets(buf, sizeof(buf), fp) != NULL)
	{
		if((len = strlen(buf)) == 0)
			/* ignore empty lines */
			continue;
		else if(buf[len - 1] != '\n')
		{
			/* skip the rest of the current line */
			while((c = fgetc(fp)) != EOF && c != '\n');
			continue;
		}
		buf[len - 1] = '\0';
		if(strncmp(buf, scheme, sizeof(scheme) - 1) == 0)
			_refresh_add_file(favorites, size, buf);
		else
			_refresh_add(favorites, buf);
	}
	fclose(fp);
}