* gdesktop.c (desktop_create_url): Accept new parameter

is_template.  Use mc_mkstemps() is it's TRUE.  Change all
callers.
* gcmd.c (gnome_new_link): Don't calculate the filename, trust
desktop_create_url() to do it.
* gdnd.c (drop_url_on_directory): Likewise.  Add support for
drag and drop from Mozilla.
This commit is contained in:
Pavel Roskin 2001-07-27 19:38:31 +00:00
parent b4be52ba78
commit 7f0c460355
6 changed files with 64 additions and 32 deletions

View File

@ -1,3 +1,13 @@
2001-07-27 Pavel Roskin <proski@gnu.org>
* gdesktop.c (desktop_create_url): Accept new parameter
is_template. Use mc_mkstemps() is it's TRUE. Change all
callers.
* gcmd.c (gnome_new_link): Don't calculate the filename, trust
desktop_create_url() to do it.
* gdnd.c (drop_url_on_directory): Likewise. Add support for
drag and drop from Mozilla.
2001-07-26 Pavel Roskin <proski@gnu.org>
* gfind.c (get_list_info): Get row number as argument. Return

View File

@ -973,6 +973,7 @@ void
gnome_new_link (GtkWidget *widget, WPanel *panel)
{
char *template;
char *icon;
char *url;
url = input_expand_dialog (_("Creating a desktop link"),
@ -980,15 +981,12 @@ gnome_new_link (GtkWidget *widget, WPanel *panel)
if (!url)
return;
template = g_concat_dir_and_file (desktop_directory, "urlXXXXXX");
template = g_concat_dir_and_file (desktop_directory, "url");
if (mktemp (template)) {
char *icon;
icon = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
desktop_create_url (template, url, url, icon, TRUE);
icon = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
desktop_create_url (template, url, url, icon);
g_free (icon);
}
g_free (icon);
g_free (template);
g_free (url);
}

View File

@ -59,7 +59,7 @@ desktop_load_init_from (const char *file)
if (url && *url){
char *filename = g_concat_dir_and_file (desktop_directory, key);
desktop_create_url (filename, title, url, icon2);
desktop_create_url (filename, title, url, icon2, FALSE);
g_free (filename);
}

View File

@ -3593,21 +3593,36 @@ desktop_destroy (void)
}
void
desktop_create_url (const char *filename, const char *title, const char *url, const char *icon)
desktop_create_url (const char *filename, const char *title,
const char *url, const char *icon, gboolean is_template)
{
FILE *f;
char *tmpname = NULL;
f = fopen (filename, "w");
if (f) {
if (is_template) {
int fd;
fprintf (f, "URL: %s\n", url);
fclose (f);
gnome_metadata_set (filename, "desktop-url",
strlen (url) + 1, url);
gnome_metadata_set (filename, "icon-caption",
strlen (title) + 1, title);
gnome_metadata_set (filename, "icon-filename", strlen (icon) + 1, icon);
fd = mc_mkstemps (&tmpname, filename, NULL);
if (fd == -1)
return;
f = fdopen (fd, "w");
filename = tmpname;
} else {
f = fopen (filename, "w");
}
if (!f) {
g_free (tmpname);
return;
}
fprintf (f, "URL: %s\n", url);
fclose (f);
gnome_metadata_set (filename, "desktop-url",
strlen (url) + 1, url);
gnome_metadata_set (filename, "icon-caption",
strlen (title) + 1, title);
gnome_metadata_set (filename, "icon-filename", strlen (icon) + 1, icon);
}

View File

@ -75,7 +75,9 @@ void desktop_rescan_devices (void);
void desktop_recreate_default_icons (void);
void desktop_reload_icons (int user_pos, int xpos, int ypos);
void desktop_arrange_icons (SortType type);
void desktop_create_url (const char *filename, const char *title, const char *url, const char *icon);
void desktop_create_url (const char *filename, const char *title,
const char *url, const char *icon,
gboolean is_template);
void desktop_tidy_icons (void);

View File

@ -263,20 +263,27 @@ static void
drop_url_on_directory (GdkDragContext *context, GtkSelectionData *selection_data, char *destdir)
{
char *template;
char *icon;
char *url;
char *title;
template = g_concat_dir_and_file (destdir, "urlXXXXXX");
template = g_concat_dir_and_file (destdir, "url");
icon = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
if (mktemp (template)) {
char *icon;
icon = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
desktop_create_url (
template,
selection_data->data,
selection_data->data,
icon);
g_free (icon);
/* Mozilla uses newline to separate URL from title. */
url = g_strdup(selection_data->data);
title = strchr (url, '\n');
if (title) {
title[0] = 0;
title++;
} else {
title = url;
}
desktop_create_url (template, title, url, icon, TRUE);
g_free (url);
g_free (icon);
g_free (template);
}