aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@src.gnome.org>2008-01-14 04:42:01 +0800
committerCosimo Cecchi <cosimoc@src.gnome.org>2008-01-14 04:42:01 +0800
commitaf1c2ceaef7d949e36a7680f463c5e25f79c43d6 (patch)
tree19c94f1df613831ed8ab92b4ac904be0c20c673f /src/bookmarks
parent12d96e8a6fc9eddaffdbad58754e712af5fc5fef (diff)
downloadgsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar.gz
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar.bz2
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar.lz
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar.xz
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.tar.zst
gsoc2013-epiphany-af1c2ceaef7d949e36a7680f463c5e25f79c43d6.zip
Drop gnome-vfs dependency. Now Epiphany depends on glib >= 2.15.1.
Also, optional Zeroconf support depends on Avahi >= 0.6.22. Bug #507152. svn path=/trunk/; revision=7858
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/Makefile.am9
-rw-r--r--src/bookmarks/ephy-bookmark-action.c59
-rw-r--r--src/bookmarks/ephy-bookmarks-export.c98
-rw-r--r--src/bookmarks/ephy-bookmarks-import.c20
-rw-r--r--src/bookmarks/ephy-bookmarks.c364
-rw-r--r--src/bookmarks/ephy-topic-action.c1
6 files changed, 377 insertions, 174 deletions
diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am
index 1863fc55b..aceaeef13 100644
--- a/src/bookmarks/Makefile.am
+++ b/src/bookmarks/Makefile.am
@@ -113,6 +113,15 @@ libephybookmarks_la_CFLAGS = \
$(DEPENDENCIES_CFLAGS) \
$(AM_CFLAGS)
+libephybookmarks_la_LIBADD =
+
+if ENABLE_ZEROCONF
+libephybookmarks_la_CFLAGS += \
+ $(AVAHI_CFLAGS)
+libephybookmarks_la_LIBADD += \
+ $(AVAHI_LIBS)
+endif
+
CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c
index 2958f0f09..242cd00aa 100644
--- a/src/bookmarks/ephy-bookmark-action.c
+++ b/src/bookmarks/ephy-bookmark-action.c
@@ -32,6 +32,7 @@
#include "ephy-gui.h"
#include "ephy-debug.h"
#include "ephy-dnd.h"
+#include "ephy-string.h"
#include <glib/gi18n.h>
#include <gtk/gtkwidget.h>
@@ -46,7 +47,6 @@
#include <gtk/gtkentry.h>
#include <gtk/gtktoolitem.h>
#include <gtk/gtkmain.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
#include <string.h>
@@ -367,16 +367,17 @@ ephy_bookmark_action_activate (EphyBookmarkAction *action,
/* The entered search term is empty, and we have a smart bookmark */
if ((text == NULL || text[0] == '\0') && strstr (location, "%s") != NULL)
{
- GnomeVFSURI *uri = gnome_vfs_uri_new (location);
- if (uri != NULL)
- {
- address = g_strconcat (
- gnome_vfs_uri_get_scheme (uri),
- "://",
- gnome_vfs_uri_get_host_name (uri),
- NULL);
- gnome_vfs_uri_unref (uri);
- }
+ char *scheme;
+ char *host_name;
+
+ scheme = g_uri_get_scheme (location);
+ host_name = ephy_string_get_host_name (location);
+ address = g_strconcat (scheme,
+ "://",
+ host_name,
+ NULL);
+ g_free (scheme);
+ g_free (host_name);
}
if (address == NULL)
@@ -511,24 +512,28 @@ query_tooltip_cb (GtkWidget *proxy,
{
if (strstr (location, "%s") != NULL)
{
- GnomeVFSURI *uri = gnome_vfs_uri_new (location);
- if (uri != NULL)
+ char *scheme;
+ char *host_name;
+
+ scheme = g_uri_get_scheme (location);
+ host_name = ephy_string_get_host_name (location);
+
+ if (title[0] == '\0')
{
- if (title[0] == '\0')
- {
- text = g_markup_printf_escaped ("%s://%s",
- gnome_vfs_uri_get_scheme (uri),
- gnome_vfs_uri_get_host_name (uri));
- }
- else
- {
- text = g_markup_printf_escaped ("%s\n%s://%s",
- title,
- gnome_vfs_uri_get_scheme (uri),
- gnome_vfs_uri_get_host_name (uri));
- }
- gnome_vfs_uri_unref (uri);
+ text = g_markup_printf_escaped ("%s://%s",
+ scheme,
+ host_name);
}
+ else
+ {
+ text = g_markup_printf_escaped ("%s\n%s://%s",
+ title,
+ scheme,
+ host_name);
+ }
+
+ g_free (scheme);
+ g_free (host_name);
}
if (text == NULL)
{
diff --git a/src/bookmarks/ephy-bookmarks-export.c b/src/bookmarks/ephy-bookmarks-export.c
index a2af331a6..c220777fd 100644
--- a/src/bookmarks/ephy-bookmarks-export.c
+++ b/src/bookmarks/ephy-bookmarks-export.c
@@ -24,6 +24,7 @@
#include "ephy-bookmarks-export.h"
#include "ephy-node-common.h"
#include "ephy-file-helpers.h"
+#include "ephy-string.h"
#include "ephy-debug.h"
#include <libxml/globals.h>
@@ -32,8 +33,6 @@
#include <libxslt/xslt.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
static inline xmlChar *
sanitise_string (const xmlChar *string)
@@ -118,7 +117,7 @@ write_topics_list (EphyNode *topics,
static int
write_rdf (EphyBookmarks *bookmarks,
- const char *filename,
+ GFile *file,
xmlTextWriterPtr writer)
{
EphyNode *bmks, *topics, *smart_bmks;
@@ -168,7 +167,7 @@ write_rdf (EphyBookmarks *bookmarks,
if (ret < 0) goto out;
/* FIXME: sanitise file_uri? */
- file_uri = gnome_vfs_get_uri_from_local_path (filename);
+ file_uri = g_file_get_uri (file);
safeString = sanitise_string ((const xmlChar *) file_uri);
g_free (file_uri);
@@ -229,21 +228,20 @@ write_rdf (EphyBookmarks *bookmarks,
smart_url = ephy_node_has_child (smart_bmks, kid);
url = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_LOCATION);
- if (smart_url)
+ if (smart_url && url)
{
- GnomeVFSURI *uri;
-
- uri = gnome_vfs_uri_new (url);
-
- if (uri)
- {
- link = g_strconcat (gnome_vfs_uri_get_scheme (uri),
- "://",
- gnome_vfs_uri_get_host_name (uri),
- NULL);
-
- gnome_vfs_uri_unref (uri);
- }
+ char *scheme;
+ char *host_name;
+
+ scheme = g_uri_get_scheme (url);
+ host_name = ephy_string_get_host_name (url);
+ link = g_strconcat (scheme,
+ "://",
+ host_name,
+ NULL);
+
+ g_free (scheme);
+ g_free (host_name);
}
safeLink = sanitise_string (link ? (const xmlChar *) link : (const xmlChar *) url);
@@ -301,21 +299,20 @@ write_rdf (EphyBookmarks *bookmarks,
title = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_TITLE);
- if (smart_url)
+ if (smart_url && url)
{
- GnomeVFSURI *uri;
-
- uri = gnome_vfs_uri_new (url);
-
- if (uri)
- {
- link = g_strconcat (gnome_vfs_uri_get_scheme (uri),
- "://",
- gnome_vfs_uri_get_host_name (uri),
- NULL);
-
- gnome_vfs_uri_unref (uri);
- }
+ char *scheme;
+ char *host_name;
+
+ scheme = g_uri_get_scheme (url);
+ host_name = ephy_string_get_host_name (url);
+
+ link = g_strconcat (scheme,
+ "://",
+ host_name,
+ NULL);
+ g_free (scheme);
+ g_free (host_name);
}
if (link == NULL)
@@ -391,20 +388,23 @@ out:
void
ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
- const char *filename)
+ const char *file_path)
{
xmlTextWriterPtr writer;
- char *tmp_file;
+ GFile *file, *tmp_file;
+ char *tmp_file_path;
int ret;
LOG ("Exporting as RDF to %s", filename);
START_PROFILER ("Exporting as RDF")
- tmp_file = g_strconcat (filename, ".tmp", NULL);
+ tmp_file_path = g_strconcat (file_path, ".tmp", NULL);
+ file = g_file_new_for_path (file_path);
+ tmp_file = g_file_new_for_path (tmp_file_path);
/* FIXME: do we want to turn on compression here? */
- writer = xmlNewTextWriterFilename (tmp_file, 0);
+ writer = xmlNewTextWriterFilename (tmp_file_path, 0);
if (writer == NULL)
{
g_free (tmp_file);
@@ -417,20 +417,22 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
ret = xmlTextWriterSetIndentString (writer, (xmlChar *) " ");
if (ret < 0) goto out;
- ret = write_rdf (bookmarks, filename, writer);
+ ret = write_rdf (bookmarks, file, writer);
if (ret < 0) goto out;
xmlFreeTextWriter (writer);
out:
if (ret >= 0)
{
- if (ephy_file_switch_temp_file (filename, tmp_file) == FALSE)
+ if (ephy_file_switch_temp_file (file, tmp_file) == FALSE)
{
ret = -1;
}
}
- g_free (tmp_file);
+ g_object_unref (file);
+ g_object_unref (tmp_file);
+ g_free (tmp_file_path);
STOP_PROFILER ("Exporting as RDF")
@@ -439,31 +441,33 @@ out:
void
ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks,
- const char *filename)
+ const char *filename)
{
xsltStylesheetPtr cur = NULL;
xmlTextWriterPtr writer;
xmlDocPtr doc = NULL, res;
- char *tmp_file, *template;
+ char *tmp_file_path, *template;
+ GFile *tmp_file;
int ret = -1;
LOG ("Exporting as Mozilla to %s", filename);
template = g_build_filename (g_get_tmp_dir (),
"export-bookmarks-XXXXXX", NULL);
- tmp_file = ephy_file_tmp_filename (template, "rdf");
+ tmp_file_path = ephy_file_tmp_filename (template, "rdf");
g_free (template);
- if (tmp_file == NULL) return;
+ if (tmp_file_path == NULL) return;
writer = xmlNewTextWriterDoc (&doc, 0);
if (writer == NULL || doc == NULL)
{
- g_free (tmp_file);
+ g_free (tmp_file_path);
return;
}
- START_PROFILER ("Exporting as Mozilla")
-
+ START_PROFILER ("Exporting as Mozilla");
+
+ tmp_file = g_file_new_for_path (tmp_file_path);
ret = write_rdf (bookmarks, tmp_file, writer);
if (ret < 0) goto out;
@@ -492,7 +496,7 @@ ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks,
out:
xmlFreeTextWriter (writer);
xmlFreeDoc (doc);
- g_free (tmp_file);
+ g_free (tmp_file_path);
STOP_PROFILER ("Exporting as Mozilla")
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c
index 56d9d628f..44f5fd63a 100644
--- a/src/bookmarks/ephy-bookmarks-import.c
+++ b/src/bookmarks/ephy-bookmarks-import.c
@@ -23,10 +23,10 @@
#include "config.h"
#include <glib.h>
+#include <gio/gio.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlreader.h>
#include <string.h>
-#include <libgnomevfs/gnome-vfs-mime.h>
#include <glib/gi18n.h>
@@ -71,14 +71,21 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks,
const char *type;
char *basename;
gboolean success = FALSE;
+ GFile *file;
+ GFileInfo *file_info;
if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_BOOKMARK_EDITING)) return FALSE;
g_return_val_if_fail (filename != NULL, FALSE);
+
+ file = g_file_new_for_path (filename);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ type = g_file_info_get_content_type (file_info);
+ g_object_unref (file_info);
- type = gnome_vfs_get_file_mime_type (filename, NULL, FALSE);
-
- LOG ("Importing bookmarks of type %s", type ? type : "(null)");
+ g_debug ("Importing bookmarks of type %s", type ? type : "(null)");
if (type != NULL && (strcmp (type, "application/rdf+xml") == 0 ||
strcmp (type, "text/rdf") == 0))
@@ -92,6 +99,7 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks,
success = ephy_bookmarks_import_xbel (bookmarks, filename);
}
else if ((type != NULL && strcmp (type, "application/x-mozilla-bookmarks") == 0) ||
+ strcmp (type, "text/html") == 0 ||
strstr (filename, MOZILLA_BOOKMARKS_DIR) != NULL ||
strstr (filename, FIREFOX_BOOKMARKS_DIR_0) != NULL ||
strstr (filename, FIREFOX_BOOKMARKS_DIR_1) != NULL ||
@@ -101,7 +109,7 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks,
}
else if (type == NULL)
{
- basename = g_path_get_basename (filename);
+ basename = g_file_get_basename (file);
if (g_str_has_suffix (basename, ".rdf"))
{
@@ -124,6 +132,8 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks,
g_free (basename);
}
+ g_object_unref (file);
+
return success;
}
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index 121326874..535ac17f0 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -44,17 +44,19 @@
#include <string.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-dns-sd.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkdialog.h>
+#include <avahi-common/error.h>
+#include <avahi-gobject/ga-service-browser.h>
+#include <avahi-gobject/ga-service-resolver.h>
+#include <avahi-gobject/ga-client.h>
+#include <avahi-gobject/ga-enums.h>
#define EPHY_BOOKMARKS_XML_ROOT "ephy_bookmarks"
#define EPHY_BOOKMARKS_XML_VERSION "1.03"
#define BOOKMARKS_SAVE_DELAY 3 /* seconds */
#define MAX_FAVORITES_NUM 10
#define UPDATE_URI_DATA_KEY "updated-uri"
-#define SD_RESOLVE_TIMEOUT 0 /* ms; 0 means no timeout */
#define EPHY_BOOKMARKS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BOOKMARKS, EphyBookmarksPrivate))
@@ -85,7 +87,8 @@ struct _EphyBookmarksPrivate
#ifdef ENABLE_ZEROCONF
/* Local sites */
EphyNode *local;
- GnomeVFSDNSSDBrowseHandle *browse_handles[G_N_ELEMENTS (zeroconf_protos)];
+ GaClient *ga_client;
+ GaServiceBrowser *browse_handles[G_N_ELEMENTS (zeroconf_protos)];
GHashTable *resolve_handles;
#endif
};
@@ -782,29 +785,96 @@ backup_file (const char *original_filename, const char *extension)
#ifdef ENABLE_ZEROCONF
+/* C&P adapted from gnome-vfs-dns-sd.c */
+static GHashTable *
+decode_txt_record (AvahiStringList *input_text)
+{
+ GHashTable *hash;
+ int i;
+ int len;
+ char *key, *value, *end;
+ char *key_dup, *value_dup;
+ char *raw_txt;
+ size_t raw_txt_len;
+
+ raw_txt_len = avahi_string_list_serialize (input_text, NULL, 0);
+ raw_txt = g_malloc (raw_txt_len);
+ raw_txt_len = avahi_string_list_serialize (input_text, raw_txt, raw_txt_len);
+
+ if (raw_txt == NULL)
+ return NULL;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ i = 0;
+ while (i < raw_txt_len) {
+ len = raw_txt[i++];
+
+ if (i + len > raw_txt_len) {
+ break;
+ }
+
+ if (len == 0) {
+ continue;
+ }
+
+ key = &raw_txt[i];
+ end = &raw_txt[i + len];
+ i += len;
+
+ if (*key == '=') {
+ /* 6.4 - silently ignore keys starting with = */
+ continue;
+ }
+
+ value = memchr (key, '=', len);
+ if (value) {
+ key_dup = g_strndup (key, value - key);
+ value++; /* Skip '=' */
+ value_dup = g_strndup (value, end - value);
+ } else {
+ key_dup = g_strndup (key, len);
+ value_dup = NULL;
+ }
+ if (!g_hash_table_lookup_extended (hash,
+ key_dup,
+ NULL, NULL)) {
+ g_hash_table_insert (hash,
+ key_dup,
+ value_dup);
+ } else {
+ g_free (key_dup);
+ g_free (value_dup);
+ }
+ }
+
+ return hash;
+}
+
+/* End of copied code */
+
static char *
-get_id_for_service (const GnomeVFSDNSSDService *service)
+get_id_for_response (const char *type,
+ const char *domain,
+ const char *name)
{
/* FIXME: limit length! */
return g_strdup_printf ("%s\1%s\1%s",
- service->type,
- service->domain,
- service->name);
+ type,
+ domain,
+ name);
}
static EphyNode *
-get_node_for_service (EphyBookmarks *bookmarks,
- const GnomeVFSDNSSDService *service)
+get_node_for_id (EphyBookmarks *bookmarks,
+ char *node_id)
{
EphyBookmarksPrivate *priv = bookmarks->priv;
EphyNode *kid, *node = NULL;
GPtrArray *children;
- char *search_id;
const char *id;
guint i;
- search_id = get_id_for_service (service);
-
children = ephy_node_get_children (priv->local);
for (i = 0; i < children->len; i++)
{
@@ -813,14 +883,14 @@ get_node_for_service (EphyBookmarks *bookmarks,
id = ephy_node_get_property_string (kid,
EPHY_NODE_BMK_PROP_SERVICE_ID);
- if (g_str_equal (id, search_id))
+ if (g_str_equal (id, node_id))
{
node = kid;
break;
}
}
- g_free (search_id);
+ g_free (node_id);
return node;
}
@@ -833,21 +903,26 @@ typedef struct
} ResolveData;
static void
-resolve_cb (GnomeVFSDNSSDResolveHandle *handle,
- GnomeVFSResult result,
- const GnomeVFSDNSSDService *service,
- const char *host,
- int port,
- /* const */ GHashTable *text,
- int text_raw_len,
- const char *text_raw,
- ResolveData *data)
+resolver_found_cb (GaServiceResolver *resolver,
+ int interface,
+ GaProtocol protocol,
+ const char *name,
+ const char *type,
+ const char *domain,
+ const char *host_name,
+ const AvahiAddress *address,
+ guint16 port,
+ AvahiStringList *txt,
+ glong flags,
+ ResolveData *data)
{
EphyBookmarks *bookmarks = data->bookmarks;
EphyBookmarksPrivate *priv = bookmarks->priv;
EphyNode *node = data->node;
GValue value = { 0, };
const char *path = NULL;
+ char host[128];
+ GHashTable *text_table;
char *url;
gboolean was_immutable;
guint i;
@@ -856,39 +931,38 @@ resolve_cb (GnomeVFSDNSSDResolveHandle *handle,
ephy_node_db_set_immutable (priv->db, FALSE);
g_hash_table_steal (priv->resolve_handles, node);
-
- /* Error, don't add the service */
- if (result != GNOME_VFS_OK)
- {
- ephy_node_unref (node);
-
- ephy_node_db_set_immutable (priv->db, was_immutable);
-
- return;
- }
-
+
/* Find the protocol */
for (i = 0; i < G_N_ELEMENTS (zeroconf_protos); ++i)
{
char proto[20];
g_snprintf (proto, sizeof (proto), "_%s._tcp", zeroconf_protos[i]);
- if (strcmp (service->type, proto) == 0) break;
+ if (strcmp (type, proto) == 0) break;
}
if (i == G_N_ELEMENTS (zeroconf_protos)) return;
+
+ text_table = decode_txt_record (txt);
- if (text != NULL)
+ if (text_table != NULL)
{
- path = g_hash_table_lookup (text, "path");
+ path = g_hash_table_lookup (text_table, "path");
}
if (path == NULL || path[0] == '\0')
{
path = "/";
}
+
+ if (address == NULL)
+ {
+ g_warning ("Zeroconf failed to resolve host %s", name);
+ return;
+ }
+ avahi_address_snprint (host, sizeof (host), address);
LOG ("0conf RESOLVED type=%s domain=%s name=%s => proto=%s host=%s port=%d path=%s\n",
- service->type, service->domain, service->name,
- zeroconf_protos[i], host, port, path);
+ type, domain, name,
+ zeroconf_protos[i], host, port, path);
/* FIXME: limit length! */
url = g_strdup_printf ("%s://%s:%d%s", zeroconf_protos[i], host, port, path);
@@ -908,39 +982,84 @@ resolve_cb (GnomeVFSDNSSDResolveHandle *handle,
}
static void
-browse_cb (GnomeVFSDNSSDBrowseHandle *handle,
- GnomeVFSDNSSDServiceStatus status,
- const GnomeVFSDNSSDService *service,
- EphyBookmarks *bookmarks)
+resolver_failure_cb (GaServiceResolver *resolver,
+ GError *error,
+ ResolveData *data)
{
+ EphyBookmarks *bookmarks = data->bookmarks;
EphyBookmarksPrivate *priv = bookmarks->priv;
- GnomeVFSDNSSDResolveHandle *reshandle = NULL;
- ResolveData *data;
- EphyNode *node;
- GValue value = { 0, };
- gboolean new_node = FALSE;
+ EphyNode *node = data->node;
+ gboolean was_immutable;
- if (service == NULL) return;
+ was_immutable = ephy_node_db_is_immutable (priv->db);
+ ephy_node_db_set_immutable (priv->db, FALSE);
- node = get_node_for_service (bookmarks, service);
+ g_hash_table_steal (priv->resolve_handles, node);
- if (status == GNOME_VFS_DNS_SD_SERVICE_REMOVED)
- {
- if (node != NULL)
- {
- g_hash_table_remove (priv->resolve_handles, node);
- ephy_node_unref (node);
- }
+ /* Error, don't add the service */
+ ephy_node_unref (node);
+ ephy_node_db_set_immutable (priv->db, was_immutable);
- return;
- }
+ return;
+}
- /* status == GNOME_VFS_DNS_SD_SERVICE_ADDED */
+static void
+free_resolve_cb_data (gpointer data)
+{
+ g_slice_free (ResolveData, data);
+}
- LOG ("0conf ADD: type=%s domain=%s name=%s\n",
- service->type, service->domain, service->name);
+static void
+browser_removed_service_cb (GaServiceBrowser *browser,
+ int interface,
+ GaProtocol protocol,
+ const char *name,
+ const char *type,
+ const char *domain,
+ glong flags,
+ EphyBookmarks *bookmarks)
+{
+ EphyBookmarksPrivate *priv = bookmarks->priv;
+ EphyNode *node;
+ char *node_id;
+
+ node_id = get_id_for_response (type, domain, name);
+ node = get_node_for_id (bookmarks, node_id);
+
+ if (node != NULL)
+ {
+ g_hash_table_remove (priv->resolve_handles, node);
+ ephy_node_unref (node);
+ }
+
+ return;
+}
- if (node != NULL &&
+static void
+browser_new_service_cb (GaServiceBrowser *browser,
+ int interface,
+ GaProtocol protocol,
+ const char *name,
+ const char *type,
+ const char *domain,
+ glong flags,
+ EphyBookmarks *bookmarks)
+{
+ EphyBookmarksPrivate *priv = bookmarks->priv;
+ EphyNode *node;
+ GValue value = { 0, };
+ gboolean new_node = FALSE;
+ GaServiceResolver *resolver = NULL;
+ ResolveData *data;
+ char *node_id;
+
+ node_id = get_id_for_response (type, domain, name);
+ node = get_node_for_id (bookmarks, node_id);
+
+ LOG ("0conf ADD: type=%s domain=%s name=%s\n",
+ type, domain, name);
+
+ if (node != NULL &&
g_hash_table_lookup (priv->resolve_handles, node) != NULL) return;
if (node == NULL)
@@ -959,14 +1078,14 @@ browse_cb (GnomeVFSDNSSDBrowseHandle *handle,
ephy_node_set_is_drag_source (node, FALSE);
g_value_init (&value, G_TYPE_STRING);
- g_value_take_string (&value, get_id_for_service (service));
+ g_value_take_string (&value, get_id_for_response (type, domain, name));
ephy_node_set_property (node, EPHY_NODE_BMK_PROP_SERVICE_ID, &value);
g_value_unset (&value);
/* FIXME: limit length! */
ephy_node_set_property_string (node,
EPHY_NODE_BMK_PROP_TITLE,
- service->name);
+ name);
ephy_node_set_property_boolean (node,
EPHY_NODE_BMK_PROP_IMMUTABLE,
@@ -975,58 +1094,110 @@ browse_cb (GnomeVFSDNSSDBrowseHandle *handle,
ephy_node_db_set_immutable (priv->db, was_immutable);
}
- data = g_new (ResolveData, 1);
+ data = g_slice_new0 (ResolveData);
data->bookmarks = bookmarks;
data->node = node;
data->new_node = new_node;
-
- if (gnome_vfs_dns_sd_resolve (&reshandle,
- service->name, service->type, service->domain,
- SD_RESOLVE_TIMEOUT,
- (GnomeVFSDNSSDResolveCallback) resolve_cb,
- data,
- (GDestroyNotify) g_free) != GNOME_VFS_OK)
+
+ resolver = ga_service_resolver_new (AVAHI_IF_UNSPEC,
+ AVAHI_PROTO_UNSPEC,
+ name, type, domain,
+ AVAHI_PROTO_UNSPEC,
+ GA_LOOKUP_USE_MULTICAST);
+ g_signal_connect_data (resolver, "found",
+ G_CALLBACK (resolver_found_cb), data,
+ (GClosureNotify) free_resolve_cb_data, 0);
+ g_signal_connect_data (resolver, "failure",
+ G_CALLBACK (resolver_failure_cb), data,
+ (GClosureNotify) free_resolve_cb_data, 0);
+ if (!ga_service_resolver_attach (resolver,
+ priv->ga_client,
+ NULL))
{
+ g_warning ("Unable to resolve Zeroconf service %s", name);
ephy_node_unref (node);
- g_free (data);
-
+ free_resolve_cb_data (data);
return;
}
-
g_hash_table_insert (priv->resolve_handles,
- node, reshandle);
+ node, resolver);
}
static void
-ephy_local_bookmarks_init (EphyBookmarks *bookmarks)
+start_browsing (GaClient *ga_client,
+ EphyBookmarks *bookmarks)
{
EphyBookmarksPrivate *priv = bookmarks->priv;
guint i;
- priv->resolve_handles =
- g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL,
- (GDestroyNotify) gnome_vfs_dns_sd_cancel_resolve);
-
for (i = 0; i < G_N_ELEMENTS (zeroconf_protos); ++i)
{
- GnomeVFSDNSSDBrowseHandle *handle = NULL;
+ GaServiceBrowser *browser = NULL;
char proto[20];
g_snprintf (proto, sizeof (proto), "_%s._tcp", zeroconf_protos[i]);
- if (gnome_vfs_dns_sd_browse (&handle,
- "local", proto,
- (GnomeVFSDNSSDBrowseCallback) browse_cb,
- bookmarks,
- NULL) == GNOME_VFS_OK)
+ browser = ga_service_browser_new (proto);
+ g_signal_connect (browser, "new-service",
+ G_CALLBACK (browser_new_service_cb), bookmarks);
+ g_signal_connect (browser, "removed-service",
+ G_CALLBACK (browser_removed_service_cb), bookmarks);
+ if (!ga_service_browser_attach (browser,
+ ga_client,
+ NULL))
{
- priv->browse_handles[i] = handle;
+ g_warning ("Unable to start Zeroconf subsystem");
+ return;
}
+
+ priv->browse_handles[i] = browser;
}
}
static void
+ga_client_state_changed_cb (GaClient *ga_client,
+ GaClientState state,
+ EphyBookmarks *bookmarks)
+{
+ if (state == GA_CLIENT_STATE_FAILURE)
+ {
+ if (avahi_client_errno (ga_client->avahi_client) == AVAHI_ERR_DISCONNECTED)
+ {
+ /* Destroy and reconnect */
+ avahi_client_free (ga_client->avahi_client);
+ ga_client->avahi_client = NULL;
+ if (!ga_client_start (ga_client, NULL))
+ {
+ g_warning ("Unable to start Zeroconf subsystem");
+ }
+ }
+ }
+ if (state == GA_CLIENT_STATE_S_RUNNING)
+ {
+ start_browsing (ga_client, bookmarks);
+ }
+}
+
+static void
+ephy_local_bookmarks_init (EphyBookmarks *bookmarks)
+{
+ EphyBookmarksPrivate *priv = bookmarks->priv;
+ GaClient *ga_client;
+
+ ga_client = ga_client_new (GA_CLIENT_FLAG_NO_FAIL);
+ g_signal_connect (ga_client, "state-changed",
+ G_CALLBACK (ga_client_state_changed_cb),
+ bookmarks);
+ if (!ga_client_start (ga_client, NULL))
+ {
+ g_warning ("Unable to start Zeroconf subsystem");
+ return;
+ }
+ priv->ga_client = ga_client;
+ priv->resolve_handles = g_hash_table_new (g_direct_hash, g_direct_equal);
+}
+
+static void
ephy_local_bookmarks_stop (EphyBookmarks *bookmarks)
{
EphyBookmarksPrivate *priv = bookmarks->priv;
@@ -1036,7 +1207,6 @@ ephy_local_bookmarks_stop (EphyBookmarks *bookmarks)
{
if (priv->browse_handles[i] != NULL)
{
- gnome_vfs_dns_sd_stop_browse (priv->browse_handles[i]);
priv->browse_handles[i] = NULL;
}
}
@@ -1051,6 +1221,12 @@ ephy_local_bookmarks_stop (EphyBookmarks *bookmarks)
{
ephy_node_remove_child (priv->keywords, priv->local);
}
+
+ if (priv->ga_client != NULL)
+ {
+ g_object_unref (priv->ga_client);
+ priv->ga_client = NULL;
+ }
}
#endif /* ENABLE_ZEROCONF */
@@ -1569,7 +1745,7 @@ impl_resolve_address (EphyBookmarks *eb,
}
else
{
- escaped_arg = gnome_vfs_escape_string (arg);
+ escaped_arg = g_uri_escape_string (arg, NULL, TRUE);
g_string_append (result, escaped_arg);
g_free (escaped_arg);
g_free (arg);
@@ -1579,7 +1755,7 @@ impl_resolve_address (EphyBookmarks *eb,
}
else
{
- arg = gnome_vfs_escape_string (content);
+ arg = g_uri_escape_string (content, NULL, TRUE);
g_string_append (result, arg);
g_free (arg);
}
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index ad5eb9eef..34c9fc843 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -46,7 +46,6 @@
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkarrow.h>
#include <gtk/gtkmain.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
#include <string.h>
static const GtkTargetEntry dest_drag_types[] = {