mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-09-20 00:02:12 +00:00
added some web linksets and made nautilus-link support remote images by
added some web linksets and made nautilus-link support remote images by fetching them through http and caching them locally.
This commit is contained in:
parent
68eeed5cdd
commit
e7d660625e
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
2000-06-05 Andy Hertzfeld <andy@eazel.com>
|
||||||
|
|
||||||
|
* data/linksets/Makefile.am:
|
||||||
|
* data/linksets/portals.xml:
|
||||||
|
* data/linksets/search_engines.xml:
|
||||||
|
added 2 new linksets of web links
|
||||||
|
* libnautilus-extensions/Makefile.am:
|
||||||
|
made us link with ghttp
|
||||||
|
* libnautilus-extensions/nautilus-file-utilities.c:
|
||||||
|
(nautilus_get_user_main_directory):
|
||||||
|
install the search engines linkset by default (temporarily until we have more UI)
|
||||||
|
* libnautilus-extensions/nautilus-link.c: (load_image_from_http),
|
||||||
|
(make_local_path), (nautilus_link_get_image_uri):
|
||||||
|
made links handle remote images by loading them through http using g_http, and
|
||||||
|
caching them locally.
|
||||||
|
|
||||||
2000-06-04 Andy Hertzfeld <andy@eazel.com>
|
2000-06-04 Andy Hertzfeld <andy@eazel.com>
|
||||||
|
|
||||||
* libnautilus-extensions/nautilus-global-preferences.c:
|
* libnautilus-extensions/nautilus-global-preferences.c:
|
||||||
|
|
|
@ -5,6 +5,8 @@ linkdir = $(datadir)/nautilus/linksets
|
||||||
link_DATA = \
|
link_DATA = \
|
||||||
apps.xml \
|
apps.xml \
|
||||||
desktop.xml \
|
desktop.xml \
|
||||||
|
portals.xml \
|
||||||
|
search_engines.xml \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
EXTRA_DIST = $(link_DATA)
|
EXTRA_DIST = $(link_DATA)
|
||||||
|
|
5
data/linksets/portals.xml
Normal file
5
data/linksets/portals.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<linkset name="Portals">
|
||||||
|
<link name="Yahoo" image="http://dellbert.differnet.com/webicons/yahoo.png" uri="http://www.yahoo.com"/>
|
||||||
|
<link name="Excite" image="http://dellbert.differnet.com/webicons/excite.png" uri="http://www.excite.com"/>
|
||||||
|
</linkset>
|
5
data/linksets/search_engines.xml
Normal file
5
data/linksets/search_engines.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<linkset name="Portals">
|
||||||
|
<link name="Google" image="http://dellbert.differnet.com/webicons/google.png" uri="http://www.google.com"/>
|
||||||
|
<link name="Alta Vista" image="http://dellbert.differnet.com/webicons/altavista.png" uri="http://www.altavista.com"/>
|
||||||
|
</linkset>
|
|
@ -6,6 +6,7 @@ INCLUDES= -I$(top_srcdir) -I$(top_builddir) -I$(top_builddir)/libnautilus -I. \
|
||||||
$(GNOME_CFLAGS) \
|
$(GNOME_CFLAGS) \
|
||||||
$(BONOBO_CFLAGS) \
|
$(BONOBO_CFLAGS) \
|
||||||
$(OAF_CFLAGS) \
|
$(OAF_CFLAGS) \
|
||||||
|
$(GHTTP_CFLAGS) \
|
||||||
$(GNOMECANVASPIXBUF_INCLUDEDIR) \
|
$(GNOMECANVASPIXBUF_INCLUDEDIR) \
|
||||||
$(VFS_CFLAGS) \
|
$(VFS_CFLAGS) \
|
||||||
$(XML_CFLAGS) \
|
$(XML_CFLAGS) \
|
||||||
|
@ -16,6 +17,7 @@ libnautilus_extensions_la_LDFLAGS=\
|
||||||
$(GNOME_LIBS) \
|
$(GNOME_LIBS) \
|
||||||
$(OAF_LIBS) \
|
$(OAF_LIBS) \
|
||||||
$(BONOBO_LIBS) \
|
$(BONOBO_LIBS) \
|
||||||
|
$(GHTTP_LIBS) \
|
||||||
$(GNOMECANVASPIXBUF_LIBS) \
|
$(GNOMECANVASPIXBUF_LIBS) \
|
||||||
$(VFS_LIBS) \
|
$(VFS_LIBS) \
|
||||||
$(XML_LIBS) \
|
$(XML_LIBS) \
|
||||||
|
|
|
@ -209,6 +209,7 @@ nautilus_get_user_main_directory (void)
|
||||||
|
|
||||||
/* install the default link set */
|
/* install the default link set */
|
||||||
nautilus_link_set_install(user_main_directory, "apps");
|
nautilus_link_set_install(user_main_directory, "apps");
|
||||||
|
nautilus_link_set_install(user_main_directory, "search_engines");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,20 @@
|
||||||
#include <parser.h>
|
#include <parser.h>
|
||||||
#include <xmlmemory.h>
|
#include <xmlmemory.h>
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs-utils.h>
|
#include <ghttp.h>
|
||||||
|
|
||||||
|
#include <libgnomevfs/gnome-vfs.h>
|
||||||
|
|
||||||
#include "nautilus-link.h"
|
#include "nautilus-link.h"
|
||||||
|
#include "nautilus-file-utilities.h"
|
||||||
#include "nautilus-metadata.h"
|
#include "nautilus-metadata.h"
|
||||||
#include "nautilus-string.h"
|
#include "nautilus-string.h"
|
||||||
#include "nautilus-xml-extensions.h"
|
#include "nautilus-xml-extensions.h"
|
||||||
#include "nautilus-global-preferences.h"
|
#include "nautilus-global-preferences.h"
|
||||||
#include "nautilus-widgets/nautilus-preferences.h"
|
#include "nautilus-widgets/nautilus-preferences.h"
|
||||||
|
|
||||||
|
#define REMOTE_ICON_DIR_PERMISSIONS (GNOME_VFS_PERM_USER_ALL | GNOME_VFS_PERM_GROUP_ALL | GNOME_VFS_PERM_OTHER_ALL)
|
||||||
|
|
||||||
/* given a uri, returns TRUE if it's a link file */
|
/* given a uri, returns TRUE if it's a link file */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -70,14 +75,100 @@ char* nautilus_link_get_additional_text(const char *link_file_uri)
|
||||||
return extra_text;
|
return extra_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* utility routine to load an image through http asynchronously */
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_image_from_http (char* uri, char* destination_path)
|
||||||
|
{
|
||||||
|
FILE* outfile;
|
||||||
|
gint length;
|
||||||
|
char* body;
|
||||||
|
ghttp_request* request;
|
||||||
|
char* proxy;
|
||||||
|
|
||||||
|
request = NULL;
|
||||||
|
proxy = g_getenv ("http_proxy");
|
||||||
|
|
||||||
|
request = ghttp_request_new();
|
||||||
|
|
||||||
|
if (!request)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (proxy && (ghttp_set_proxy (request, proxy) != 0)) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ghttp_set_uri (request, uri) != 0) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ghttp_set_type (request, ghttp_type_get);
|
||||||
|
ghttp_set_header (request, http_hdr_Accept, "image/*");
|
||||||
|
ghttp_set_header (request, http_hdr_User_Agent, "Nautilus/0.1 (Linux)");
|
||||||
|
|
||||||
|
ghttp_set_header (request, http_hdr_Connection, "close");
|
||||||
|
|
||||||
|
if (ghttp_prepare (request) != 0) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* soon we'll be asynchronous, but this first implementation is synchrounous */
|
||||||
|
|
||||||
|
/* initiate the request */
|
||||||
|
|
||||||
|
/* here's where it spends all the time doing the actual request */
|
||||||
|
if (ghttp_process (request) != ghttp_done) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the result and save it to the destination file */
|
||||||
|
outfile = fopen(destination_path, "w");
|
||||||
|
|
||||||
|
length = ghttp_get_body_len(request);
|
||||||
|
body = ghttp_get_body(request);
|
||||||
|
|
||||||
|
if (body != NULL)
|
||||||
|
fwrite(body, length, 1, outfile);
|
||||||
|
fclose(outfile);
|
||||||
|
|
||||||
|
ghttp_request_destroy(request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* utility to return the local pathname of a cached icon, given the leaf name */
|
||||||
|
/* if the icons directory hasn't been created yet, create it */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
make_local_path(const char *image_name)
|
||||||
|
{
|
||||||
|
GnomeVFSResult result;
|
||||||
|
char *escaped_uri, *local_directory_path, *local_file_path;
|
||||||
|
|
||||||
|
escaped_uri = nautilus_str_escape_slashes (image_name + 7);
|
||||||
|
local_directory_path = g_strdup_printf("%s/.nautilus/remote_icons", g_get_home_dir());
|
||||||
|
|
||||||
|
/* we must create the directory if it doesnt exist */
|
||||||
|
result = gnome_vfs_make_directory(local_directory_path, REMOTE_ICON_DIR_PERMISSIONS);
|
||||||
|
|
||||||
|
local_file_path = nautilus_make_path(local_directory_path, escaped_uri);
|
||||||
|
g_free(escaped_uri);
|
||||||
|
g_free(local_directory_path);
|
||||||
|
return local_file_path;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns the image associated with a link file */
|
/* returns the image associated with a link file */
|
||||||
|
|
||||||
char*
|
char*
|
||||||
nautilus_link_get_image_uri(const char *link_file_uri)
|
nautilus_link_get_image_uri(const char *link_file_uri)
|
||||||
{
|
{
|
||||||
xmlDoc *doc;
|
xmlDoc *doc;
|
||||||
char *file_uri;
|
char *file_uri, *icon_str;
|
||||||
char *icon_str = NULL;
|
char *local_path;
|
||||||
|
icon_str = NULL;
|
||||||
|
|
||||||
if (link_file_uri == NULL)
|
if (link_file_uri == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -92,6 +183,24 @@ nautilus_link_get_image_uri(const char *link_file_uri)
|
||||||
xmlFreeDoc (doc);
|
xmlFreeDoc (doc);
|
||||||
}
|
}
|
||||||
g_free(file_uri);
|
g_free(file_uri);
|
||||||
|
|
||||||
|
/* if the image is remote, see if we can find it in our local cache */
|
||||||
|
|
||||||
|
if (nautilus_str_has_prefix(icon_str, "http://")) {
|
||||||
|
|
||||||
|
local_path = make_local_path(icon_str);
|
||||||
|
|
||||||
|
if (g_file_exists(local_path)) {
|
||||||
|
g_free(icon_str);
|
||||||
|
return local_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for now, handle things synchronously */
|
||||||
|
load_image_from_http(icon_str, local_path);
|
||||||
|
g_free(icon_str);
|
||||||
|
return local_path;
|
||||||
|
}
|
||||||
|
|
||||||
return icon_str;
|
return icon_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ INCLUDES= -I$(top_srcdir) -I$(top_builddir) -I$(top_builddir)/libnautilus -I. \
|
||||||
$(GNOME_CFLAGS) \
|
$(GNOME_CFLAGS) \
|
||||||
$(BONOBO_CFLAGS) \
|
$(BONOBO_CFLAGS) \
|
||||||
$(OAF_CFLAGS) \
|
$(OAF_CFLAGS) \
|
||||||
|
$(GHTTP_CFLAGS) \
|
||||||
$(GNOMECANVASPIXBUF_INCLUDEDIR) \
|
$(GNOMECANVASPIXBUF_INCLUDEDIR) \
|
||||||
$(VFS_CFLAGS) \
|
$(VFS_CFLAGS) \
|
||||||
$(XML_CFLAGS) \
|
$(XML_CFLAGS) \
|
||||||
|
@ -16,6 +17,7 @@ libnautilus_extensions_la_LDFLAGS=\
|
||||||
$(GNOME_LIBS) \
|
$(GNOME_LIBS) \
|
||||||
$(OAF_LIBS) \
|
$(OAF_LIBS) \
|
||||||
$(BONOBO_LIBS) \
|
$(BONOBO_LIBS) \
|
||||||
|
$(GHTTP_LIBS) \
|
||||||
$(GNOMECANVASPIXBUF_LIBS) \
|
$(GNOMECANVASPIXBUF_LIBS) \
|
||||||
$(VFS_LIBS) \
|
$(VFS_LIBS) \
|
||||||
$(XML_LIBS) \
|
$(XML_LIBS) \
|
||||||
|
|
|
@ -209,6 +209,7 @@ nautilus_get_user_main_directory (void)
|
||||||
|
|
||||||
/* install the default link set */
|
/* install the default link set */
|
||||||
nautilus_link_set_install(user_main_directory, "apps");
|
nautilus_link_set_install(user_main_directory, "apps");
|
||||||
|
nautilus_link_set_install(user_main_directory, "search_engines");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,20 @@
|
||||||
#include <parser.h>
|
#include <parser.h>
|
||||||
#include <xmlmemory.h>
|
#include <xmlmemory.h>
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs-utils.h>
|
#include <ghttp.h>
|
||||||
|
|
||||||
|
#include <libgnomevfs/gnome-vfs.h>
|
||||||
|
|
||||||
#include "nautilus-link.h"
|
#include "nautilus-link.h"
|
||||||
|
#include "nautilus-file-utilities.h"
|
||||||
#include "nautilus-metadata.h"
|
#include "nautilus-metadata.h"
|
||||||
#include "nautilus-string.h"
|
#include "nautilus-string.h"
|
||||||
#include "nautilus-xml-extensions.h"
|
#include "nautilus-xml-extensions.h"
|
||||||
#include "nautilus-global-preferences.h"
|
#include "nautilus-global-preferences.h"
|
||||||
#include "nautilus-widgets/nautilus-preferences.h"
|
#include "nautilus-widgets/nautilus-preferences.h"
|
||||||
|
|
||||||
|
#define REMOTE_ICON_DIR_PERMISSIONS (GNOME_VFS_PERM_USER_ALL | GNOME_VFS_PERM_GROUP_ALL | GNOME_VFS_PERM_OTHER_ALL)
|
||||||
|
|
||||||
/* given a uri, returns TRUE if it's a link file */
|
/* given a uri, returns TRUE if it's a link file */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -70,14 +75,100 @@ char* nautilus_link_get_additional_text(const char *link_file_uri)
|
||||||
return extra_text;
|
return extra_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* utility routine to load an image through http asynchronously */
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_image_from_http (char* uri, char* destination_path)
|
||||||
|
{
|
||||||
|
FILE* outfile;
|
||||||
|
gint length;
|
||||||
|
char* body;
|
||||||
|
ghttp_request* request;
|
||||||
|
char* proxy;
|
||||||
|
|
||||||
|
request = NULL;
|
||||||
|
proxy = g_getenv ("http_proxy");
|
||||||
|
|
||||||
|
request = ghttp_request_new();
|
||||||
|
|
||||||
|
if (!request)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (proxy && (ghttp_set_proxy (request, proxy) != 0)) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ghttp_set_uri (request, uri) != 0) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ghttp_set_type (request, ghttp_type_get);
|
||||||
|
ghttp_set_header (request, http_hdr_Accept, "image/*");
|
||||||
|
ghttp_set_header (request, http_hdr_User_Agent, "Nautilus/0.1 (Linux)");
|
||||||
|
|
||||||
|
ghttp_set_header (request, http_hdr_Connection, "close");
|
||||||
|
|
||||||
|
if (ghttp_prepare (request) != 0) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* soon we'll be asynchronous, but this first implementation is synchrounous */
|
||||||
|
|
||||||
|
/* initiate the request */
|
||||||
|
|
||||||
|
/* here's where it spends all the time doing the actual request */
|
||||||
|
if (ghttp_process (request) != ghttp_done) {
|
||||||
|
ghttp_request_destroy (request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the result and save it to the destination file */
|
||||||
|
outfile = fopen(destination_path, "w");
|
||||||
|
|
||||||
|
length = ghttp_get_body_len(request);
|
||||||
|
body = ghttp_get_body(request);
|
||||||
|
|
||||||
|
if (body != NULL)
|
||||||
|
fwrite(body, length, 1, outfile);
|
||||||
|
fclose(outfile);
|
||||||
|
|
||||||
|
ghttp_request_destroy(request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* utility to return the local pathname of a cached icon, given the leaf name */
|
||||||
|
/* if the icons directory hasn't been created yet, create it */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
make_local_path(const char *image_name)
|
||||||
|
{
|
||||||
|
GnomeVFSResult result;
|
||||||
|
char *escaped_uri, *local_directory_path, *local_file_path;
|
||||||
|
|
||||||
|
escaped_uri = nautilus_str_escape_slashes (image_name + 7);
|
||||||
|
local_directory_path = g_strdup_printf("%s/.nautilus/remote_icons", g_get_home_dir());
|
||||||
|
|
||||||
|
/* we must create the directory if it doesnt exist */
|
||||||
|
result = gnome_vfs_make_directory(local_directory_path, REMOTE_ICON_DIR_PERMISSIONS);
|
||||||
|
|
||||||
|
local_file_path = nautilus_make_path(local_directory_path, escaped_uri);
|
||||||
|
g_free(escaped_uri);
|
||||||
|
g_free(local_directory_path);
|
||||||
|
return local_file_path;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns the image associated with a link file */
|
/* returns the image associated with a link file */
|
||||||
|
|
||||||
char*
|
char*
|
||||||
nautilus_link_get_image_uri(const char *link_file_uri)
|
nautilus_link_get_image_uri(const char *link_file_uri)
|
||||||
{
|
{
|
||||||
xmlDoc *doc;
|
xmlDoc *doc;
|
||||||
char *file_uri;
|
char *file_uri, *icon_str;
|
||||||
char *icon_str = NULL;
|
char *local_path;
|
||||||
|
icon_str = NULL;
|
||||||
|
|
||||||
if (link_file_uri == NULL)
|
if (link_file_uri == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -92,6 +183,24 @@ nautilus_link_get_image_uri(const char *link_file_uri)
|
||||||
xmlFreeDoc (doc);
|
xmlFreeDoc (doc);
|
||||||
}
|
}
|
||||||
g_free(file_uri);
|
g_free(file_uri);
|
||||||
|
|
||||||
|
/* if the image is remote, see if we can find it in our local cache */
|
||||||
|
|
||||||
|
if (nautilus_str_has_prefix(icon_str, "http://")) {
|
||||||
|
|
||||||
|
local_path = make_local_path(icon_str);
|
||||||
|
|
||||||
|
if (g_file_exists(local_path)) {
|
||||||
|
g_free(icon_str);
|
||||||
|
return local_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for now, handle things synchronously */
|
||||||
|
load_image_from_http(icon_str, local_path);
|
||||||
|
g_free(icon_str);
|
||||||
|
return local_path;
|
||||||
|
}
|
||||||
|
|
||||||
return icon_str;
|
return icon_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue