auto emblems for user XDG directories



hello, I'm writing an extension that automatically adds emblems to
user XDG directories (Documents, Music...)
I've quite finished my work, but something strange happens whenever I
launch nautilus for the first time.
the extension is a nautilus-info-provider that does these things:
1. tests if the file is a directory
2. if so tests if the path is equal to the one provided by
g_get_user_special_dir() for each iser XDG dir
3. if so it selects the correct emblems and adds it to the NautilusFileInfo

This is my problem: when I re-launch nautilus the following things are done:
1. the desktop directory is scanned
2. the home directory is scanned
BUT XDG directories in my home are not passed to my extension: only
other dirs: to make things more clear:
- $HOME/Documents is not passed
- $HOME/source is instead passed
if I move back and forward or reopen the home directory XDG dirs are
not passed again
if I hit REFRESH it works, and emblems are added.

I think this is not the correct behaviour.
BTW I'm using nautilus 2.22.3-0ubuntu2

I will attach the source file: the debug is done appending the name of
the scanned files to /tmp/log since I don't know how to output to
.xsession-errors
please tell me if this works for you, or if it has the same behavior
Thanks!
#include <stdio.h>
#include <libnautilus-extension/nautilus-file-info.h>
#include <libnautilus-extension/nautilus-info-provider.h>

static void xdg_emblems_provider_iface_init (NautilusInfoProviderIface *iface);
static void xdg_emblems_cancel_update(NautilusInfoProvider     *provider, NautilusOperationHandle  *handle);
static NautilusOperationResult xdg_emblems_update_file_info(NautilusInfoProvider *provider, NautilusFileInfo *file, GClosure *update_complete, NautilusOperationHandle **handle);

static GType tpp_type = 0;

static void xdg_emblems_provider_iface_init (NautilusInfoProviderIface *iface)
{
	iface->cancel_update = xdg_emblems_cancel_update;
	iface->update_file_info = xdg_emblems_update_file_info;
}

static NautilusOperationResult xdg_emblems_update_file_info(NautilusInfoProvider *provider, NautilusFileInfo *file, GClosure *update_complete, NautilusOperationHandle **handle)
{	
	NautilusFileInfoIface *file_iface = NAUTILUS_FILE_INFO_GET_IFACE(file);
	
	FILE* f = fopen("/tmp/log","a");
	if (f!=NULL)
	{
		char* name = file_iface->get_name(file);
		fprintf(f, "dir=%s\n", name);
		g_free(name);
		fclose(f);
	}

	if (file_iface->is_directory(file))
	{
		const gchar* doc_dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
		const gchar* down_dir = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD);
		const gchar* music_dir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
		const gchar* videos_dir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);
		const gchar* pictures_dir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES);
		const gchar* shared_dir = g_get_user_special_dir(G_USER_DIRECTORY_PUBLIC_SHARE);
		const gchar* templates_dir = g_get_user_special_dir(G_USER_DIRECTORY_TEMPLATES);
		
		char* uri = file_iface->get_uri(file);
		const char* dir;
		const char* emblem;
		if (g_str_has_prefix(uri, "file://"))
		{
			dir = uri + 7; //  remove file:// 
			
			if (g_str_equal(dir, doc_dir))
				emblem = "documents";
			else if (g_str_equal(dir, down_dir))
				emblem="web";
			else if (g_str_equal(dir, music_dir))
				emblem="sound";
			else if (g_str_equal(dir, videos_dir))
				emblem="multimedia";
			else if (g_str_equal(dir, pictures_dir))
				emblem="pictures";
			else if (g_str_equal(dir, shared_dir))
				emblem="shared";
			else if (g_str_equal(dir, templates_dir))
				emblem="new";
			else
				emblem=NULL;
			
			if (emblem != NULL)
				file_iface->add_emblem(file, emblem);
			
			g_free(uri);
		}
	}
	return NAUTILUS_OPERATION_COMPLETE;
}

static void xdg_emblems_cancel_update(NautilusInfoProvider  *provider, NautilusOperationHandle  *handle)
{
}

void totem_xdg_emblems_plugin_register_type(GTypeModule  *module)
{	
	const GTypeInfo info = {
		sizeof (GObjectClass),
		(GBaseInitFunc) NULL,
		(GBaseFinalizeFunc) NULL,
		(GClassInitFunc) NULL,
		NULL,
		NULL,
		sizeof (GObject),
		0,
		(GInstanceInitFunc) NULL
	};
	const GInterfaceInfo xdg_emblems_provider_iface_info = {
		(GInterfaceInitFunc)xdg_emblems_provider_iface_init,
		NULL,
		NULL
	};

	tpp_type = g_type_module_register_type (module, G_TYPE_OBJECT,
			"TotemXdgEmblemsInfoPlugin",
			&info, 0);
	g_type_module_add_interface (module,
			tpp_type,
			NAUTILUS_TYPE_INFO_PROVIDER,
			&xdg_emblems_provider_iface_info);
}

void nautilus_module_initialize (GTypeModule  *module)
{
	totem_xdg_emblems_plugin_register_type(module);
}

void nautilus_module_shutdown   (void)
{	
}

void nautilus_module_list_types (const GType **types, int          *num_types)
{
	static GType type_list[1];

	type_list[0] = tpp_type;
	*types = type_list;
	*num_types = G_N_ELEMENTS (type_list);
}

Attachment: Makefile
Description: Binary data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]