aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-location-action.c
diff options
context:
space:
mode:
authorDiego Escalante Urrelo <diegoe@src.gnome.org>2007-12-26 07:38:48 +0800
committerDiego Escalante Urrelo <diegoe@src.gnome.org>2007-12-26 07:38:48 +0800
commit4ccad4249c928907f8b9a0f089b47ddb5c7bbfae (patch)
tree985030477b7b91bd9ea8d1ed1d57cb497035be86 /src/ephy-location-action.c
parent2ac5ef454443b113eb54a1b1ce21065db295d8c7 (diff)
downloadgsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar.gz
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar.bz2
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar.lz
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar.xz
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.tar.zst
gsoc2013-epiphany-4ccad4249c928907f8b9a0f089b47ddb5c7bbfae.zip
Moves the completion_func from lib/widgets/ephy-location-entry.c to
src/ephy-location-action.c. Adds a function to set the completion_func in lib/widgets/ephy-location-entry.c|h. Part of bug #392979. svn path=/trunk/; revision=7821
Diffstat (limited to 'src/ephy-location-action.c')
-rw-r--r--src/ephy-location-action.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c
index 713ede9fb..d0a68eca1 100644
--- a/src/ephy-location-action.c
+++ b/src/ephy-location-action.c
@@ -23,6 +23,7 @@
#include "config.h"
#include "ephy-embed-container.h"
+#include "ephy-history.h"
#include "ephy-location-action.h"
#include "ephy-location-entry.h"
#include "ephy-shell.h"
@@ -37,6 +38,7 @@
#include <gtk/gtkentrycompletion.h>
#include <gtk/gtkmain.h>
+#include <string.h>
#define EPHY_LOCATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_LOCATION_ACTION, EphyLocationActionPrivate))
struct _EphyLocationActionPrivate
@@ -86,6 +88,106 @@ static guint signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
+static const struct
+{
+ const char *prefix;
+ int len;
+}
+web_prefixes [] =
+{
+ { "http://www.", 11 },
+ { "http://ftp.", 11 },
+ { "http://", 7 },
+ { "https://www.", 12 },
+ { "https://", 8 },
+ { "ftp://", 6},
+ { "ftp://ftp.", 10},
+ { "www.", 4 },
+ { "ftp.", 4}
+};
+
+
+static gboolean
+keyword_match (const char *list,
+ const char *keyword)
+{
+ const char *p;
+ gsize keyword_len;
+
+ p = list;
+ keyword_len = strlen (keyword);
+
+ while (*p)
+ {
+ int i;
+
+ for (i = 0; i < keyword_len; i++)
+ {
+ if (p[i] != keyword[i])
+ {
+ goto next_token;
+ }
+ }
+
+ return TRUE;
+
+ next_token:
+
+ while (*p && !g_ascii_ispunct(*p) && !g_ascii_isspace(*p)) p++;
+ while (*p && (g_ascii_ispunct(*p) || g_ascii_isspace(*p))) p++;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+completion_func (GtkEntryCompletion *completion,
+ const char *key,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ int i, len_key, len_prefix;
+ char *item = NULL;
+ char *keywords = NULL;
+ gboolean ret = FALSE;
+ GtkTreeModel *model;
+
+ model = gtk_entry_completion_get_model (completion);
+
+ gtk_tree_model_get (model, iter,
+ EPHY_COMPLETION_TEXT_COL, &item,
+ EPHY_COMPLETION_KEYWORDS_COL, &keywords,
+ -1);
+
+ len_key = strlen (key);
+ if (!strncasecmp (key, item, len_key))
+ {
+ ret = TRUE;
+ }
+ else if (keyword_match (keywords, key))
+ {
+ ret = TRUE;
+ }
+ else
+ {
+ for (i = 0; i < G_N_ELEMENTS (web_prefixes); i++)
+ {
+ len_prefix = web_prefixes[i].len;
+ if (!strncmp (web_prefixes[i].prefix, item, len_prefix) &&
+ !strncasecmp (key, item + len_prefix, len_key))
+ {
+ ret = TRUE;
+ break;
+ }
+ }
+ }
+
+ g_free (item);
+ g_free (keywords);
+
+ return ret;
+}
+
GType
ephy_location_action_get_type (void)
{
@@ -376,6 +478,9 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
EPHY_COMPLETION_FAVICON_COL,
EPHY_COMPLETION_URL_COL);
+ ephy_location_entry_set_completion_func (EPHY_LOCATION_ENTRY (proxy),
+ completion_func);
+
add_completion_actions (action, proxy);
sync_address (action, NULL, proxy);