1999-03-20 21:08:52 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-1999 The Free Software Foundation
|
|
|
|
*
|
|
|
|
* Authors: Miguel de Icaza <miguel@nuclecu.unam.mx>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "main.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <libgnome/libgnome.h>
|
|
|
|
#include "gdesktop.h"
|
|
|
|
#include "gdesktop-init.h"
|
|
|
|
#include "gprint.h"
|
|
|
|
#include "gmount.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
desktop_load_init_from (const char *file)
|
|
|
|
{
|
|
|
|
void *iterator_handle;
|
|
|
|
char *config_path = g_strconcat ("=", file, "=", NULL);
|
|
|
|
|
|
|
|
iterator_handle = gnome_config_init_iterator_sections (config_path);
|
|
|
|
|
|
|
|
do {
|
|
|
|
char *key;
|
|
|
|
char *file_and_section;
|
|
|
|
char *title, *type;
|
|
|
|
|
|
|
|
/* Get next section name */
|
|
|
|
iterator_handle = gnome_config_iterator_next (
|
|
|
|
iterator_handle, &key, NULL);
|
|
|
|
|
|
|
|
/* Now access the values in the section */
|
|
|
|
file_and_section = g_strconcat (config_path, "/", key, "/", NULL);
|
|
|
|
gnome_config_push_prefix (file_and_section);
|
|
|
|
title = gnome_config_get_translated_string ("title=None");
|
|
|
|
type = gnome_config_get_string ("type=url");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle the different link types
|
|
|
|
*/
|
|
|
|
if (strcmp (type, "url") == 0){
|
|
|
|
int used;
|
|
|
|
char *icon = NULL, *url;
|
1999-03-23 23:33:48 +03:00
|
|
|
char *icon2 = NULL;
|
1999-03-20 21:08:52 +03:00
|
|
|
|
|
|
|
url = gnome_config_get_string ("url");
|
|
|
|
icon = gnome_config_get_string_with_default ("icon=", &used);
|
|
|
|
if (!icon)
|
1999-03-23 23:33:48 +03:00
|
|
|
icon2 = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
|
|
|
|
else {
|
|
|
|
icon2 = gnome_pixmap_file (icon);
|
|
|
|
if (!icon2)
|
|
|
|
icon2 = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
|
|
|
|
}
|
1999-03-20 21:08:52 +03:00
|
|
|
if (url && *url){
|
|
|
|
char *filename = g_concat_dir_and_file (desktop_directory, key);
|
|
|
|
|
1999-03-23 23:33:48 +03:00
|
|
|
desktop_create_url (filename, title, url, icon2);
|
1999-03-20 21:08:52 +03:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url)
|
|
|
|
g_free (url);
|
|
|
|
g_free (icon);
|
1999-03-23 23:33:48 +03:00
|
|
|
g_free (icon2);
|
1999-03-20 21:08:52 +03:00
|
|
|
}
|
|
|
|
g_free (title);
|
|
|
|
g_free (file_and_section);
|
|
|
|
gnome_config_pop_prefix ();
|
|
|
|
} while (iterator_handle);
|
|
|
|
|
|
|
|
g_free (config_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
desktop_init_at (const char *dir)
|
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *dent;
|
1999-04-08 03:26:49 +04:00
|
|
|
struct stat s;
|
1999-03-20 21:08:52 +03:00
|
|
|
const int links_extlen = sizeof (".links")-1;
|
1999-03-30 10:09:56 +04:00
|
|
|
|
1999-03-20 21:08:52 +03:00
|
|
|
d = opendir (dir);
|
|
|
|
if (!d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((dent = readdir (d)) != NULL){
|
|
|
|
int len = strlen (dent->d_name);
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
fname = g_concat_dir_and_file (dir, dent->d_name);
|
1999-04-08 03:26:49 +04:00
|
|
|
if (stat (fname, &s) < 0) {
|
|
|
|
g_free (fname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (S_ISDIR (s.st_mode)) {
|
|
|
|
g_free (fname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (is_exe (s.st_mode)) {
|
|
|
|
/* let's try running it */
|
1999-03-20 21:08:52 +03:00
|
|
|
char *desktop_quoted;
|
|
|
|
char *command;
|
1999-03-30 10:09:56 +04:00
|
|
|
|
1999-03-20 21:08:52 +03:00
|
|
|
desktop_quoted = name_quote (desktop_directory, 0);
|
|
|
|
command = g_strconcat (fname, " --desktop-dir", desktop_quoted, NULL);
|
|
|
|
g_free (desktop_quoted);
|
|
|
|
|
|
|
|
my_system (EXECUTE_WAIT | EXECUTE_AS_SHELL, shell, command);
|
|
|
|
g_free (command);
|
|
|
|
g_free (fname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < links_extlen){
|
|
|
|
g_free (fname);
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-30 10:09:56 +04:00
|
|
|
|
1999-03-20 21:08:52 +03:00
|
|
|
if (strcmp (dent->d_name + len - links_extlen, ".links")){
|
|
|
|
g_free (fname);
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-30 10:09:56 +04:00
|
|
|
|
1999-03-20 21:08:52 +03:00
|
|
|
desktop_load_init_from (fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdesktop_init (void)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
desktop_init_at (DESKTOP_INIT_DIR);
|
|
|
|
|
1999-03-23 23:33:48 +03:00
|
|
|
dir = gnome_libdir_file ("desktop-links");
|
|
|
|
if (dir) {
|
|
|
|
desktop_init_at (dir);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
1999-03-20 21:08:52 +03:00
|
|
|
gmount_setup_devices ();
|
|
|
|
gprint_setup_devices ();
|
|
|
|
}
|
|
|
|
|