1 /* Customizable desktop links for the Midnight Commander
3 * Copyright (C) 1998-1999 The Free Software Foundation
5 * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx>
10 #include <libgnome/libgnome.h>
15 #include "gdesktop-init.h"
18 #include "../vfs/vfs.h"
21 desktop_load_init_from (const char *file
)
24 char *file_and_section
;
27 void *iterator_handle
;
28 char *config_path
= g_strconcat ("=", file
, "=", NULL
);
30 iterator_handle
= gnome_config_init_iterator_sections (config_path
);
32 iterator_handle
= gnome_config_iterator_next (
33 iterator_handle
, &key
, NULL
);
36 /* Now access the values in the section */
37 file_and_section
= g_strconcat (config_path
, "/", key
, "/", NULL
);
39 gnome_config_push_prefix (file_and_section
);
40 title
= gnome_config_get_translated_string ("title=None");
41 type
= gnome_config_get_string ("type=url");
44 * handle the different link types
46 if (strcmp (type
, "url") == 0){
51 url
= gnome_config_get_string ("url");
52 icon
= gnome_config_get_string_with_default ("icon=", &used
);
54 icon2
= gnome_pixmap_file (icon
);
58 icon2
= g_concat_dir_and_file (ICONDIR
, "gnome-http-url.png");
60 char *filename
= g_concat_dir_and_file (desktop_directory
, key
);
62 desktop_create_url (filename
, title
, url
, icon2
);
71 g_free (file_and_section
);
72 gnome_config_pop_prefix ();
74 /* Get next section name */
75 iterator_handle
= gnome_config_iterator_next (
76 iterator_handle
, &key
, NULL
);
78 } while (iterator_handle
);
84 desktop_init_at (const char *dir
)
89 const int links_extlen
= sizeof (".links")-1;
95 while ((dent
= readdir (d
)) != NULL
){
96 int len
= strlen (dent
->d_name
);
99 fname
= g_concat_dir_and_file (dir
, dent
->d_name
);
100 if (stat (fname
, &s
) < 0) {
104 if (S_ISDIR (s
.st_mode
)) {
108 if (is_exe (s
.st_mode
)) {
109 /* let's try running it */
110 char *desktop_quoted
;
113 desktop_quoted
= name_quote (desktop_directory
, 0);
114 command
= g_strconcat (fname
, " --desktop-dir=", desktop_quoted
, NULL
);
115 g_free (desktop_quoted
);
117 my_system (EXECUTE_WAIT
| EXECUTE_AS_SHELL
, shell
, command
);
123 if (len
< links_extlen
){
128 if (strcmp (dent
->d_name
+ len
- links_extlen
, ".links")){
133 desktop_load_init_from (fname
);
140 gdesktop_links_init (void)
146 /* Create the link to the user's home directory so that he will have an icon */
147 link_name
= g_concat_dir_and_file (desktop_directory
, _("Home directory"));
148 mc_symlink (gnome_user_home_dir
, link_name
);
151 /* Create the link to the user's trash directory */
152 link_name
= g_concat_dir_and_file (desktop_directory
, "Trash.gmc");
153 icon
= gnome_pixmap_file ("mc/gnome-trashcan.png");
154 mc_mkdir (link_name
, S_IRUSR
| S_IWUSR
| S_IXUSR
);
156 gnome_metadata_set (link_name
, "icon-filename", strlen (icon
) + 1, icon
);
159 gnome_metadata_set (link_name
, "icon-caption", strlen (_("Trash")) + 1, _("Trash"));
162 /* Create custom links */
164 desktop_init_at (DESKTOP_INIT_DIR
);
166 dir
= gnome_libdir_file ("desktop-links");
168 desktop_init_at (dir
);