Re: desktop.links entries - was Re: Advocacy report [part 2]


I always forget about it...

Well; now I attach it, so you can decide about it (or, Miguel, would you
want I simply cvs commit it to mc CVS module ?)

It is a little program that accepts several command line parameters and
according to that creates desktop icons.
It can be useful for automatic creation of desktop icons for programs
not having that feature inside them (which is the case of all non-Gnome
programs:) ).

Still needs to be improved for error checking, and also for metadata
properties I missed.

Ki a vos vye bn,
Pablo Saratxaga		PGP Key available, key ID: 0x8F0E4975
 * Gnome Desktop linker.
 * This program creates links for the desktop icons
 * Authors:
 *   Pablo Saratxaga
 * Under the GNU General Public License
#include <sys/stat.h>
#include <string.h>

#include <config.h>
#include <gnome.h>

static char *progname;
static char *icon_name;
static char *icon_caption;
static char *link_name;
static char *desktop_dir;
static char *drop_action;

static const struct poptOption options [] = {
	{ "progname", 0, POPT_ARG_STRING, &progname, NULL,
	  N_("Name of the program to link to") },
	{ "icon-name", 0, POPT_ARG_STRING, &icon_name, NULL,
	  N_("Name of the icon to use on the desktop") },
	{ "icon-caption", 0, POPT_ARG_STRING, &icon_caption, NULL,
	  N_("Caption of the icon to be created") },
	{ "link-name", 0, POPT_ARG_STRING, &link_name, NULL,
	  N_("Name of the symlink to create") },
	{ "desktop-dir", 0, POPT_ARG_STRING, &desktop_dir, N_("DESKTOP-DIR"),
	  N_("Creates links to this program in the directory specified") }, 
	{ "drop-action", 0, POPT_ARG_STRING, &drop_action, NULL,
	  N_("Specifies the action to perform when dropping some object") },
	{ NULL, 0, 0, NULL, 0 }

main (int argc, char *argv [])
	poptContext ctx;
	char dir [8192];
	char *str;
	struct stat buf;

	gnome_init_with_popt_table ("GDesktopLnk", VERSION, argc, argv, options, 0, &ctx);

	if (!progname)
		return 1;

	if (!desktop_dir)
		return 2;

	if (chdir (desktop_dir) == -1)
		return 3;

	getcwd (dir, sizeof (dir));

	if (!link_name) {
		if (str)
			link_name = g_strdup_printf("%s",str+1);
			link_name = g_strdup_printf("%s",progname);

	if (lstat (link_name, &buf) == 0){
		if (S_ISLNK (buf.st_mode))
			unlink (link_name);
	if (symlink (progname, link_name) == 0){

		str = g_concat_dir_and_file (desktop_dir, link_name);

		if (drop_action)
			gnome_metadata_set (str, "drop-action",
					strlen (drop_action)+1, drop_action);

		if (icon_caption)
			gnome_metadata_set (str, "icon-caption",
					strlen (icon_caption)+1, icon_caption);

		if (icon_name) {
			char *icon;

			icon = gnome_unconditional_pixmap_file(icon_name);
			gnome_metadata_set (str, "icon-filename",
					strlen (icon)+1, icon);

	g_free (str);
	return 0;

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