summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Hallendal <micke@codefactory.se>2002-03-02 16:55:00 +0000
committerMikael Hallendal <hallski@src.gnome.org>2002-03-02 16:55:00 +0000
commit9bb790e63177da7f80dc51bf78ae67e9c282ca5a (patch)
tree85457501fa1f4f21e042da15ec21c6d4fcf79b12
parenta26d9205d23fec03d35eef8ae36d65c001434e5e (diff)
downloadyelp-9bb790e63177da7f80dc51bf78ae67e9c282ca5a.tar.gz
- removed lots of debug output. (yvi_entry_changed_cb): implemented. call
2002-03-02 Mikael Hallendal <micke@codefactory.se> * src/yelp-view-index.c: - removed lots of debug output. (yvi_entry_changed_cb): implemented. call filter from idle. (yvi_filter_idle): added/impl. (yvi_search): removed. * src/yelp-section.c: (yelp_section_compare): take the arguments as gconstpointer so the function doesn't have to be cast everytime used. * src/yelp-scrollkeeper.c: (ys_parse_index_item): - don't add title if it's not valid utf8. Is this check needed? - call strdown on all title's in the index-terms. * src/yelp-index-model.c: (yelp_index_model_filter): added/impl. Please don't report problems running/building Yelp after this commit, I'm in the middle of hacking and will finish this during the weekend.
-rw-r--r--ChangeLog18
-rw-r--r--src/yelp-index-model.c105
-rw-r--r--src/yelp-index-model.h5
-rw-r--r--src/yelp-scrollkeeper.c12
-rw-r--r--src/yelp-section.c7
-rw-r--r--src/yelp-section.h4
-rw-r--r--src/yelp-view-index.c67
7 files changed, 182 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index cab3a860..b4a3919f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,24 @@
2002-03-02 Mikael Hallendal <micke@codefactory.se>
* src/yelp-view-index.c:
+ - removed lots of debug output.
+ (yvi_entry_changed_cb): implemented. call filter from idle.
+ (yvi_filter_idle): added/impl.
+ (yvi_search): removed.
+
+ * src/yelp-section.c:
+ (yelp_section_compare): take the arguments as gconstpointer so the
+ function doesn't have to be cast everytime used.
+
+ * src/yelp-scrollkeeper.c:
+ (ys_parse_index_item):
+ - don't add title if it's not valid utf8. Is this check needed?
+ - call strdown on all title's in the index-terms.
+
+ * src/yelp-index-model.c:
+ (yelp_index_model_filter): added/impl.
+
+ * src/yelp-view-index.c:
(yvi_index_selection_changed_cb): use the column-enum to specify
columns.
diff --git a/src/yelp-index-model.c b/src/yelp-index-model.c
index 1f471628..b3f4f469 100644
--- a/src/yelp-index-model.c
+++ b/src/yelp-index-model.c
@@ -22,13 +22,17 @@
#include <gtk/gtktreemodel.h>
#include <libgnome/gnome-i18n.h>
+#include <string.h>
+
#include "yelp-section.h"
#include "yelp-index-model.h"
struct _YelpIndexModelPriv {
- GList *index_words;
+ GList *original_list;
+
+ GList *index_words;
- gint stamp;
+ gint stamp;
};
#define G_LIST(x) ((GList *) x)
@@ -149,6 +153,7 @@ yim_init (YelpIndexModel *model)
priv->stamp = g_random_int ();
} while (priv->stamp == 0);
+ priv->original_list = NULL;
priv->index_words = NULL;
model->priv = priv;
@@ -337,7 +342,7 @@ yim_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
YelpIndexModelPriv *priv;
-
+
g_return_val_if_fail (YELP_IS_INDEX_MODEL (tree_model), -1);
priv = YELP_INDEX_MODEL(tree_model)->priv;
@@ -410,7 +415,9 @@ yelp_index_model_set_words (YelpIndexModel *model, GList *index_words)
priv = model->priv;
- priv->index_words = index_words;
+ priv->original_list = g_list_sort (index_words, yelp_section_compare);
+
+ priv->index_words = priv->original_list;
for (node = priv->index_words; node; node = node->next) {
path = gtk_tree_path_new ();
@@ -425,3 +432,93 @@ yelp_index_model_set_words (YelpIndexModel *model, GList *index_words)
gtk_tree_path_free (path);
}
}
+
+void
+yelp_index_model_filter (YelpIndexModel *model, const gchar *string)
+{
+ YelpIndexModelPriv *priv;
+ YelpSection *section;
+ GList *node;
+ GList *new_list = NULL;
+ gint new_length, old_length;
+ gint i;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ g_return_if_fail (YELP_IS_INDEX_MODEL (model));
+ g_return_if_fail (string != NULL);
+
+ priv = model->priv;
+
+ /* here we want to change the contents of index_words,
+ call update on all rows that is included in the new
+ list and remove on all outside it */
+
+ old_length = g_list_length (priv->index_words);
+
+ if (!strcmp ("", string)) {
+ new_list = priv->original_list;
+ } else {
+ for (node = priv->original_list; node; node = node->next) {
+ section = (YelpSection *) node->data;
+
+ if (!strncmp (section->name, string, strlen (string))) {
+ /* Include in the new list */
+ new_list = g_list_prepend (new_list, section);
+ }
+ }
+
+ new_list = g_list_sort (new_list, yelp_section_compare);
+ }
+
+ new_length = g_list_length (new_list);
+
+ if (priv->index_words != priv->original_list) {
+ /* Only remove the old list if it's not pointing at the
+ original list */
+ g_list_free (priv->index_words);
+ }
+
+ priv->index_words = new_list;
+
+ /* Update rows 0 - new_length */
+ for (i = 0; i < new_length; ++i) {
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, i);
+
+ yim_get_iter (GTK_TREE_MODEL (model), &iter, path);
+
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model),
+ path, &iter);
+ gtk_tree_path_free (path);
+ }
+
+ if (old_length > new_length) {
+ /* Remove rows new_length - old_length */
+ for (i = old_length - 1; i >= new_length; --i) {
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, i);
+
+ gtk_tree_model_row_deleted (GTK_TREE_MODEL (model),
+ path);
+ gtk_tree_path_free (path);
+ }
+ }
+ else if (old_length < new_length) {
+ /* Add rows old_length - new_length */
+ for (i = old_length; i < new_length; ++i) {
+ path = gtk_tree_path_new ();
+
+ gtk_tree_path_append_index (path, i);
+
+ yim_get_iter (GTK_TREE_MODEL (model), &iter, path);
+
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (model),
+ path, &iter);
+
+ gtk_tree_path_free (path);
+ }
+
+ }
+}
+
diff --git a/src/yelp-index-model.h b/src/yelp-index-model.h
index f1a28ed2..eac63e53 100644
--- a/src/yelp-index-model.h
+++ b/src/yelp-index-model.h
@@ -60,8 +60,11 @@ enum {
GtkType yelp_index_model_get_type (void);
-YelpIndexModel *yelp_index_model_new (void);
+YelpIndexModel * yelp_index_model_new (void);
void yelp_index_model_set_words (YelpIndexModel *model,
GList *index_words);
+void yelp_index_model_filter (YelpIndexModel *model,
+ const gchar *string);
+
#endif /* __YELP_INDEX_MODEL_H__ */
diff --git a/src/yelp-scrollkeeper.c b/src/yelp-scrollkeeper.c
index 548833b0..d833b17a 100644
--- a/src/yelp-scrollkeeper.c
+++ b/src/yelp-scrollkeeper.c
@@ -456,10 +456,20 @@ ys_parse_index_item (GList **index, YelpSection *section, xmlNode *node)
xmlChar *title = NULL;
xmlChar *link = NULL;
YelpSection *index_section;
+ xmlChar *xml_str;
for (cur = node->xmlChildrenNode; cur; cur = cur->next) {
if (!g_ascii_strcasecmp (cur->name, "title")) {
- title = xmlNodeGetContent (cur);
+ xml_str = xmlNodeGetContent (cur);
+
+ if (!g_utf8_validate (xml_str, -1, NULL)) {
+ g_warning ("Index title is not valid utf8");
+ xmlFree (xml_str);
+ return;
+ }
+
+ title = g_utf8_strdown (xml_str, -1);
+ xmlFree (xml_str);
}
else if (!g_ascii_strcasecmp (cur->name, "link")) {
link = xmlGetProp (cur, "linkid");
diff --git a/src/yelp-section.c b/src/yelp-section.c
index 6a038f10..cd57e36e 100644
--- a/src/yelp-section.c
+++ b/src/yelp-section.c
@@ -74,8 +74,9 @@ yelp_section_free (YelpSection *section)
}
gint
-yelp_section_compare (const YelpSection *a,
- const YelpSection *b)
+yelp_section_compare (gconstpointer a,
+ gconstpointer b)
{
- return strcmp (a->name, b->name);
+ return strcmp (((YelpSection *)a)->name,
+ ((YelpSection *)b)->name);
}
diff --git a/src/yelp-section.h b/src/yelp-section.h
index 5d7456e1..eab4dcdf 100644
--- a/src/yelp-section.h
+++ b/src/yelp-section.h
@@ -52,8 +52,8 @@ YelpSection * yelp_section_copy (const YelpSection *section);
void yelp_section_free (YelpSection *section);
-gint yelp_section_compare (const YelpSection *a,
- const YelpSection *b);
+gint yelp_section_compare (gconstpointer a,
+ gconstpointer b);
#endif /* __YELP_SECTION_H__ */
diff --git a/src/yelp-view-index.c b/src/yelp-view-index.c
index 642e6a3d..2bd97098 100644
--- a/src/yelp-view-index.c
+++ b/src/yelp-view-index.c
@@ -49,9 +49,8 @@ static void yvi_entry_text_inserted_cb (GtkEntry *entry,
gint length,
gint *position,
YelpViewIndex *view);
-static void yvi_search (YelpViewIndex *view,
- const gchar *string);
static gboolean yvi_complete_idle (YelpViewIndex *view);
+static gboolean yvi_filter_idle (YelpViewIndex *view);
static gchar * yvi_complete_func (YelpSection *section);
struct _YelpViewIndexPriv {
@@ -67,7 +66,8 @@ struct _YelpViewIndexPriv {
GCompletion *completion;
- guint complete;
+ guint idle_complete;
+ guint idle_filter;
};
GType
@@ -106,11 +106,12 @@ yvi_init (YelpViewIndex *view)
priv = g_new0 (YelpViewIndexPriv, 1);
view->priv = priv;
- priv->complete = 0;
+ priv->idle_complete = 0;
+ priv->idle_filter = 0;
+
priv->completion =
- g_completion_new ((GCompletionFunc)yvi_complete_func);
- g_completion_set_compare (priv->completion, g_ascii_strncasecmp);
-
+ g_completion_new ((GCompletionFunc) yvi_complete_func);
+
priv->index_view = gtk_tree_view_new ();
priv->model = yelp_index_model_new ();
@@ -175,7 +176,17 @@ yvi_html_url_selected_cb (YelpViewIndex *content,
static void
yvi_entry_changed_cb (GtkEntry *entry, YelpViewIndex *view)
{
- g_print ("Entry changed\n");
+ YelpViewIndexPriv *priv;
+
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+ g_return_if_fail (YELP_IS_VIEW_INDEX (view));
+
+ priv = view->priv;
+
+ if (!priv->idle_filter) {
+ priv->idle_filter =
+ g_idle_add ((GSourceFunc) yvi_filter_idle, view);
+ }
}
static void
@@ -184,9 +195,8 @@ yvi_entry_activated_cb (GtkEntry *entry, YelpViewIndex *view)
g_return_if_fail (GTK_IS_ENTRY (entry));
g_return_if_fail (YELP_IS_VIEW_INDEX (view));
- yvi_search (view, gtk_entry_get_text (entry));
-
- g_print ("Entry activated\n");
+ yelp_index_model_filter (view->priv->model,
+ gtk_entry_get_text (view->priv->entry));
}
static void
@@ -202,18 +212,10 @@ yvi_entry_text_inserted_cb (GtkEntry *entry,
priv = view->priv;
- if (!priv->complete) {
- priv->complete = g_idle_add ((GSourceFunc)yvi_complete_idle,
- view);
+ if (!priv->idle_complete) {
+ priv->idle_complete =
+ g_idle_add ((GSourceFunc) yvi_complete_idle, view);
}
-
- g_print ("Entry text insterted\n");
-}
-
-static void
-yvi_search (YelpViewIndex *view, const gchar *string)
-{
- g_print ("Doing a search on %s...\n", string);
}
static gboolean
@@ -229,8 +231,6 @@ yvi_complete_idle (YelpViewIndex *view)
priv = view->priv;
- g_print ("Completing ... \n");
-
text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
list = g_completion_complete (priv->completion,
@@ -247,7 +247,24 @@ yvi_complete_idle (YelpViewIndex *view)
text_length, -1);
}
- priv->complete = 0;
+ priv->idle_complete = 0;
+
+ return FALSE;
+}
+
+static gboolean
+yvi_filter_idle (YelpViewIndex *view)
+{
+ YelpViewIndexPriv *priv;
+
+ g_return_val_if_fail (YELP_IS_VIEW_INDEX (view), FALSE);
+
+ priv = view->priv;
+
+ yelp_index_model_filter (view->priv->model,
+ gtk_entry_get_text (priv->entry));
+
+ priv->idle_filter = 0;
return FALSE;
}