aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--lib/widgets/ephy-location-entry.c113
-rw-r--r--lib/widgets/ephy-location-entry.h4
-rw-r--r--src/ephy-location-action.c105
3 files changed, 121 insertions, 101 deletions
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 0282589ff..c531b7169 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -38,6 +38,7 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtktoolbar.h>
#include <gtk/gtkentry.h>
+#include <gtk/gtkentrycompletion.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkcellrendererpixbuf.h>
@@ -90,24 +91,6 @@ struct _EphyLocationEntryPrivate
guint needs_reset : 1;
};
-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 const GtkTargetEntry url_drag_types [] =
{
{ EPHY_DND_URL_TYPE, 0, 0 },
@@ -435,88 +418,6 @@ entry_activate_after_cb (GtkEntry *entry,
}
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;
- EphyLocationEntry *le = EPHY_LOCATION_ENTRY (data);
- GtkTreeModel *model;
-
- model = gtk_entry_completion_get_model (completion);
-
- gtk_tree_model_get (model, iter,
- le->priv->text_col, &item,
- le->priv->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;
-}
-
-static gboolean
match_selected_cb (GtkEntryCompletion *completion,
GtkTreeModel *model,
GtkTreeIter *iter,
@@ -1039,6 +940,17 @@ extracell_data_func (GtkCellLayout *cell_layout,
}
void
+ephy_location_entry_set_completion_func (EphyLocationEntry *le,
+ GtkEntryCompletionMatchFunc completion_func)
+{
+ EphyLocationEntryPrivate *priv = le->priv;
+ GtkEntryCompletion *completion;
+
+ completion = gtk_entry_get_completion (GTK_ENTRY (priv->icon_entry->entry));
+ gtk_entry_completion_set_match_func (completion, completion_func, NULL, NULL);
+}
+
+void
ephy_location_entry_set_completion (EphyLocationEntry *le,
GtkTreeModel *model,
guint text_col,
@@ -1071,7 +983,6 @@ ephy_location_entry_set_completion (EphyLocationEntry *le,
completion = gtk_entry_completion_new ();
gtk_entry_completion_set_model (completion, sort_model);
g_object_unref (sort_model);
- gtk_entry_completion_set_match_func (completion, completion_func, le, NULL);
g_signal_connect (completion, "match-selected",
G_CALLBACK (match_selected_cb), le);
g_signal_connect_after (completion, "action-activated",
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 549416c23..c7e905bc5 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -28,6 +28,7 @@
#include <gtk/gtkwidget.h>
#include <gtk/gtktoolitem.h>
#include <gtk/gtktreemodel.h>
+#include <gtk/gtkentrycompletion.h>
G_BEGIN_DECLS
@@ -80,6 +81,9 @@ void ephy_location_entry_set_location (EphyLocationEntry *le,
const char *address,
const char *typed_address);
+void ephy_location_entry_set_completion_func (EphyLocationEntry *le,
+ GtkEntryCompletionMatchFunc completion_func);
+
const char *ephy_location_entry_get_location (EphyLocationEntry *le);
gboolean ephy_location_entry_reset (EphyLocationEntry *entry);
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);