giftcurs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [giFTcurs-devel] Auto-search-more idea


From: Starling
Subject: Re: [giFTcurs-devel] Auto-search-more idea
Date: 06 Nov 2003 15:21:54 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Christian Häggström <address@hidden> writes:

> I don't like that idea.. it may load the network(s) if you forget to
> turn it off.

It sends one search packet only after the search is completed, which
isn't exactly a bandwidth stealer.  And we can let the daemon deal with
load balancing, something giFT does rather well if I'm any judge.  On
the FastTrack network for one, I have found that the initial search
often requires much restarting to get any kind of results.  Doing it
manually every time is inconvenient to the point of being
debilitating.

> > and an option to delete
> > empty queries so they don't clog the up/down list of searches.
> That is a good feature.

I suppose if you wanted a diff of just that part.  It kind of ended
up dependant on the rest though.

> Sure, please send us the patch. Maybe we will change some little bits,
> but it sounds as you have made it nice.

Ok, here is the patch for the whole thing:
------------------------------------------------
diff -Naur giFTcurs-0.6.1/giFTcurs.1 giFTcurs-0.6.1-new/giFTcurs.1
--- giFTcurs-0.6.1/giFTcurs.1   Mon Jun 30 22:01:01 2003
+++ giFTcurs-0.6.1-new/giFTcurs.1       Fri Oct 31 11:07:49 2003
@@ -50,7 +50,7 @@
 \fIStart search\fP button.
 You will now hopefully see some files in the \fISearch Results\fP
 box, use tab to get there.
-You may later use tab to get back.
+You may later use tab to get back.  Note that shift makes tab cycle backwards.
 .PP
 The first number in the search results list shows how many users with that
 file currently have available upload slots.
@@ -61,6 +61,10 @@
 Use up/down, page up/down and home/end to navigate in the list.
 To change the sorting order press left or right.
 Press Enter or D when you've highlighted a file you want to download.
+.PP
+Once a search is started, the \fIStart search\fP button becomes the \fIAuto 
search more\fP button.  Pressing the \fIAuto search more\fP button will cause 
that particular search to constantly retry when the search query becomes 
completed.  If the button is dim and marked \fIAuto searching...\fP then Auto 
search more is in effect, pushing it is harmless.
+.PP
+Once a search is started, the \fIStop search\fP button is enabled.  Pressing 
this stops the search and enables the \fIClear search\fP button.  Pressing this 
clears the results box and enables the \fIDelete search\fP button.  Pressing 
this deletes the search entirely from memory so when you push up/down it will 
not appear in the search box.  At any step before \fIDelete search\fP you may 
start the search going again.  After \fIDelete search\fP is pressed you must 
type your search query in again.
 .PP
 To monitor transfers press F3, or click on the \fITransfers\fP
 button.
diff -Naur giFTcurs-0.6.1/src/list.c giFTcurs-0.6.1-new/src/list.c
--- giFTcurs-0.6.1/src/list.c   Fri Jul 25 17:47:40 2003
+++ giFTcurs-0.6.1-new/src/list.c       Fri Oct 31 10:28:56 2003
@@ -214,6 +214,14 @@
        return list_member(snafu, snafu->sel);
 }
 
+gboolean *list_set_selected(list *snafu, int sel)
+{
+       if(sel < 0) return 0;
+       if(sel >= snafu->num) return 0;
+       snafu->sel = sel;
+       return 1;
+}
+
 void *below_selected(list *snafu)
 {
        return list_member(snafu, snafu->sel + 1);
@@ -359,6 +367,18 @@
        dynarray_foreach((dynarray *) snafu, func);
 }
 
+/*** Generic filter funcs ***/
+
+gboolean list_filter_equal(void* data, void* udata) {
+       return data == udata;
+}
+
+gboolean list_filter_notequal(void* data, void* udata) {
+       return data != udata;
+}
+
+/***   end filter funcs   ***/
+
 int list_filter(list *snafu, LFilter keep, void *udata, void (*destroy) (void 
*))
 {
        int i, j, count = 0;
@@ -366,8 +386,10 @@
        for (j = i = 0; i < snafu->num; i++)
                if (keep(snafu->entries[i], udata))
                        snafu->entries[j++] = snafu->entries[i];
-               else
-                       destroy(snafu->entries[i]), count++;
+               else {
+                       if(destroy)
+                               destroy(snafu->entries[i]), count++;
+               }
        snafu->num = j;
 
        return count;
diff -Naur giFTcurs-0.6.1/src/list.h giFTcurs-0.6.1-new/src/list.h
--- giFTcurs-0.6.1/src/list.h   Tue Jul 22 17:26:25 2003
+++ giFTcurs-0.6.1-new/src/list.h       Fri Oct 31 10:28:59 2003
@@ -67,6 +67,9 @@
 /* return the selected entry */
 void *list_selected(list *);
 
+/* set which is the selected entry. (range checking) */
+gboolean *list_set_selected(list *, int);
+
 /* return the entry below selected entry */
 void *below_selected(list *);
 
@@ -86,6 +89,13 @@
 
 /* list_filter returns the number of deleted items */
 typedef gboolean (*LFilter) (void *data, void *udata);
+
+gboolean list_filter_equal(void* data, void* udata);
+/* Keeps only what is (pointerwise) equal udata */
+
+gboolean list_filter_notequal(void* data, void* udata);
+/* Keeps only what is (pointerwise) NOT equal to udata */
+
 int list_filter(list *snafu, LFilter func, void *udata, void (*destroy) (void 
*));
 
 /* unsorted list: find the pointer in list
diff -Naur giFTcurs-0.6.1/src/search.c giFTcurs-0.6.1-new/src/search.c
--- giFTcurs-0.6.1/src/search.c Thu Aug 14 09:57:43 2003
+++ giFTcurs-0.6.1-new/src/search.c     Fri Oct 31 11:03:29 2003
@@ -152,6 +152,13 @@
        return q;
 }
 
+void free_query(query *q)
+{
+       g_free(q->search_term);
+       /* We don't need to deal with tree_initialize here do we? */
+       FREE_NODE(q);
+}
+
 void gift_query_stop(query *q)
 {
        if (q->id) {
@@ -313,6 +320,13 @@
                interface_foreach_key(metatree, (PForEachFunc) 
parse_meta_data_real, udata);
 }
 
+/* From ui_main.c */
+extern int send_search_packet(query * q);
+
+void restart_search(query * q) {
+       send_search_packet(q);
+}
+
 /* This is the function that parses search hits.
    XXX: does not belong here. */
 void search_result_item_handler(ntree *data, query *q)
@@ -324,6 +338,13 @@
 
        if (interface_isempty(data)) {
                /* end of search */
+               if(q->autostart) {
+                       g_message(ngettext("We got %i unique hit for %s.  Auto 
searching more...",
+                                                          "We got %i unique 
hits for %s. Auto searching more...",tree_children(q)->num), 
tree_children(q)->num, q->search_term);
+                       restart_search(q);
+                       return;
+               }
+
                gift_unregister_id(q->id);
                q->id = 0;
                g_message(ngettext("Search complete. We got %i unique hit for 
%s.",
diff -Naur giFTcurs-0.6.1/src/search.h giFTcurs-0.6.1-new/src/search.h
--- giFTcurs-0.6.1/src/search.h Tue Jul 22 16:58:37 2003
+++ giFTcurs-0.6.1-new/src/search.h     Fri Oct 31 11:03:19 2003
@@ -36,6 +36,7 @@
        void *formatting;
        int sorting_method;
        int callback;
+       short autostart : 1;              /* Auto search more */
 } query;
 
 typedef struct {
@@ -73,7 +74,12 @@
 void gift_search_init(void);
 void gift_search_cleanup(void);
 
+/* Allocates a new query */
 query *new_query(char *search_term, int realm);
+
+/* Frees the memory associated with a query.
+   Call gift_query_clear first! */
+void free_query(query*);
 
 /* stop the search associated with id */
 void gift_search_stop(gift_id id, const char *type);
diff -Naur giFTcurs-0.6.1/src/tree.h giFTcurs-0.6.1-new/src/tree.h
--- giFTcurs-0.6.1/src/tree.h   Tue Jul 22 16:58:37 2003
+++ giFTcurs-0.6.1-new/src/tree.h       Fri Oct 31 10:58:16 2003
@@ -107,6 +107,7 @@
 #define CLASSOF(expr) (((tree_node*)(expr))->klass)
 #define INSTANCEOF(expr, type) (CLASSOF(expr) == &type##_class)
 #define NEW_NODE(type) G_GNUC_EXTENSION(({ type *_t = g_new0(type, 1); 
((tree_node*)_t)->klass = &type##_class; _t; }))
+#define FREE_NODE(type) G_GNUC_EXTENSION(g_free(type))
 
 /* useful defines */
 #define tree_children(t) (&((tree_node*)(t))->children)
diff -Naur giFTcurs-0.6.1/src/ui_main.c giFTcurs-0.6.1-new/src/ui_main.c
--- giFTcurs-0.6.1/src/ui_main.c        Sat Aug 23 13:01:44 2003
+++ giFTcurs-0.6.1-new/src/ui_main.c    Fri Oct 31 11:06:27 2003
@@ -261,37 +261,34 @@
        ui_update(my_screen_nr | 0200);
 }
 
-static void start_search_pressed(void)
-{
-       /* *INDENT-OFF* */
-       static const struct item_t {
-               const char *realm;
-               const char *command;
-               int format;
-       } names[] = {
-               {NULL, "SEARCH", 0},
-               {"audio", "SEARCH", 0},
-               {"video", "SEARCH", 0},
-               {"image", "SEARCH", 0},
-               {"text", "SEARCH", 0},
-               {"application", "SEARCH", 0},
-               {NULL, "BROWSE", 1},
-               {NULL, "LOCATE", 0},
-               {NULL, "SHARES", 1},
-       };
-       /* *INDENT-ON* */
-       const struct item_t *t;
-       query *q;
+/* *INDENT-OFF* */
+static const struct item_t {
+       const char *realm;
+       const char *command;
+       int format;
+} names[] = {
+       {NULL, "SEARCH", 0},
+       {"audio", "SEARCH", 0},
+       {"video", "SEARCH", 0},
+       {"image", "SEARCH", 0},
+       {"text", "SEARCH", 0},
+       {"application", "SEARCH", 0},
+       {NULL, "BROWSE", 1},
+       {NULL, "LOCATE", 0},
+       {NULL, "SHARES", 1},
+};
+/* *INDENT-ON* */
+
+int send_search_packet(query * q) {
        ntree *packet = NULL;
        char *includes = NULL, *excludes = NULL, *protocols = NULL;
+       const struct item_t *t;
+       int ret;
 
-       t = names + search_realm.sel;
-       q = prepare_search(t->format);
-
-       q->id = gift_new_id();
+       t = names + q->realm;
 
        interface_append_int(&packet, t->command, q->id);
-       parse_typed_query(q->search_term, &includes, &excludes, &protocols);
+       parse_typed_query(q->search_term, &includes, &excludes, &protocols);
        interface_append(&packet, "query", includes);
        if (excludes && excludes[0])
                interface_append(&packet, "exclude", excludes);
@@ -299,17 +296,32 @@
                interface_append(&packet, "realm", t->realm);
        if (protocols && protocols[0])
                interface_append(&packet, "protocol", protocols);
+       ret = gift_write(&packet);
+       g_free(includes);
+       g_free(excludes);
+       g_free(protocols);
+
+       return ret;
+}
+
+static void start_search_pressed(void)
+{
+       const struct item_t *t;
+       query *q;
+
+       t = names + search_realm.sel;
+       q = prepare_search(t->format);
+
+       q->id = gift_new_id();
+
        gift_register_id(q->id, (EventCallback) search_result_item_handler, q);
-       if (gift_write(&packet) < 0) {
+       if (send_search_packet(q) < 0) {
                g_message(_("Couldn't start search!"));
                gift_unregister_id(q->id);
                q->id = 0;
        } else {
-               g_message(_("Searching..."));
+               g_message(_("Searching %d..."), q->id);
        }
-       g_free(includes);
-       g_free(excludes);
-       g_free(protocols);
        incoming_search_item();
        refresh();
 }
@@ -373,6 +385,25 @@
        return !tree_isempty(q);
 }
 
+static int auto_searching(void) {
+       
+       query *q;
+
+       q = list_selected(&queries);
+       if (q->id)
+               return q->autostart;
+       return 0;
+}
+
+/* 1 - There are results displayed */
+static int have_results(void) {
+               
+       query *q;
+
+       q = list_selected(&queries);
+       return !tree_isempty(q);
+}
+
 /* returns 0 if key was not catched */
 static int main_screen_handler(int key)
 {
@@ -387,7 +418,11 @@
                                active_field -= FIELD_MAX;
                        if (active_field < 0)
                                active_field += FIELD_MAX;
-                       if (active_field == FIELD_STOP_BUTTON && 
!can_stop_search())
+/*                     if (active_field == FIELD_STOP_BUTTON && 
!can_stop_search())
+                       continue;
+                       ( Still part of the tab order because of Delete search. 
)
+*/
+                       if (active_field == FIELD_SEARCH_BUTTON && 
auto_searching())
                                continue;
                        if (active_field == FIELD_RESULT_LIST && 
tree_isempty(HITS))
                                continue;
@@ -443,7 +478,14 @@
                return 1;
        case FIELD_SEARCH_BUTTON:
                if (PRESSED(key)) {
-                       start_search_pressed();
+                       q = list_selected(&queries);
+
+                       if (q && q->id) {
+                               q->autostart = 1; /* User is requesting auto 
search more */
+                               g_message(_("Auto searching more %d"), q->id);
+                       } else {
+                               start_search_pressed();
+                       }
                        main_screen_update_searchbox();
                        main_screen_update_results();
                        refresh();
@@ -455,15 +497,33 @@
                        q = list_selected(&queries);
 
                        if (q->id) {
+                               q->autostart = 0; /* User is requesting a stop 
*/
                                gift_query_stop(q);
                                g_message(_("Search stopped."));
-                       } else if (!tree_isempty(q)) {
-                               gift_query_clear(q);
-                               g_message(_("Search cleared."));
-                               main_screen_update_results();
                        } else {
-                               g_message(_("A magical search appears, but it 
is cancelled too soon."));
+                               if (!tree_isempty(q)) {
+                                       gift_query_clear(q);
+                                       g_message(_("Search cleared."));
+                               } else if(queries.num >= 2) {
+                                       /* We MUST not delete the blank default 
extra query */
+                                       
+                                       /* Delete current search from queries. 
*/
+                                       /* Fie, fie you rejected search 
results! */
+                                       list_filter(&queries, 
list_filter_notequal, q, NULL);
+                                       list_set_selected(&queries, queries.sel 
- 1);
+
+                                       free_query(q);
+                                       g_message(_("Search deleted."));
+                                       
+                                       /* Re-assign global search term to new 
query */
+                                       q = list_selected(&queries);
+                                       g_assert(q);
+                                       
g_string_assign(&search_term,q->search_term);
+                                       search_pos = search_term.len; /* Place 
cursor at end */
+                               }
+                               main_screen_update_results();
                        }
+
                        main_screen_update_searchbox();
                        refresh();
                        return 1;
@@ -657,15 +717,37 @@
        /* We have resizable buttons, so we need to clear the area first */
        mvhline(STAT_BOX_H - 2, 1, ' ', SEARCH_BOX_W - 2);
 
-       draw_button(SEARCH_BOX_W / 4 + 1, STAT_BOX_H - 2, _("Start search"),
-                               COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_SEARCH_BUTTON, 1), mouse_buttonclick,
-                               GINT_TO_POINTER(FIELD_SEARCH_BUTTON));
-
-       draw_button(3 * SEARCH_BOX_W / 4, STAT_BOX_H - 2,
-                               can_stop_search() > 1 ? _("Stop search") : 
_("Clear search"),
-                               COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_STOP_BUTTON, can_stop_search()),
-                               mouse_buttonclick, 
GINT_TO_POINTER(FIELD_STOP_BUTTON));
-
+       if(can_stop_search() > 1) {
+               int test = auto_searching();
+               draw_button(SEARCH_BOX_W / 4 + 1, STAT_BOX_H - 2,
+                                       test ? _("Auto searching") : _("Auto 
search more"),
+                                       COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_SEARCH_BUTTON,
+                                                                test ? 0 : 1),
+                                       mouse_buttonclick, 
GINT_TO_POINTER(FIELD_SEARCH_BUTTON));
+
+               draw_button(3 * SEARCH_BOX_W / 4, STAT_BOX_H - 2,
+                                       _("Stop search"),
+                                       COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_STOP_BUTTON, 1),
+                                       mouse_buttonclick, 
GINT_TO_POINTER(FIELD_STOP_BUTTON));
+       } else {
+               draw_button(SEARCH_BOX_W / 4 + 1, STAT_BOX_H - 2,
+                                       _("Start search"),
+                                       COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_SEARCH_BUTTON, 1),
+                                       mouse_buttonclick, 
GINT_TO_POINTER(FIELD_SEARCH_BUTTON));
+
+               if(have_results()) {
+                       draw_button(3 * SEARCH_BOX_W / 4, STAT_BOX_H - 2,
+                                               _("Clear search"),
+                                               COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_STOP_BUTTON, 1),
+                                               mouse_buttonclick, 
GINT_TO_POINTER(FIELD_STOP_BUTTON));
+               } else {
+                       draw_button(3 * SEARCH_BOX_W / 4, STAT_BOX_H - 2,
+                                               _("Delete search"),
+                                               COLOR_BUTTON(COLOR_SEARCH_BOX, 
FIELD_STOP_BUTTON, 1),
+                                               mouse_buttonclick, 
GINT_TO_POINTER(FIELD_STOP_BUTTON));
+               }                       
+                       
+       }
        move(curs_y, curs_x);
 }
 

---------------------------------------------------

If you cut and paste the file, patch -p0 inside the source directory
should merge it.

You can see the 'Delete Search' option uses the same wristwatch style
button changing as 'Auto Search More', otherwise I suppose you could
take the one without the other.  I also added the ability to free the
memory of a node: let me know if I've done it wrong.


Starling




reply via email to

[Prev in Thread] Current Thread [Next in Thread]