Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

search.c File Reference


Detailed Description

GUI filtering functions.

Author:
Raphael Manfredi

Richard Eckart

Date:
2001-2003

#include "gtk/gui.h"
#include "gtk/bitzi.h"
#include "gtk/search.h"
#include "gtk/gtk-missing.h"
#include "gtk/settings.h"
#include "gtk/statusbar.h"
#include "gtk/columns.h"
#include "gtk/misc.h"
#include "gtk/notebooks.h"
#include "search_cb.h"
#include "if/gui_property_priv.h"
#include "if/bridge/ui2c.h"
#include "if/core/sockets.h"
#include "lib/atoms.h"
#include "lib/base32.h"
#include "lib/glib-missing.h"
#include "lib/iso3166.h"
#include "lib/misc.h"
#include "lib/tm.h"
#include "lib/urn.h"
#include "lib/utf8.h"
#include "lib/walloc.h"
#include "lib/override.h"

Defines

#define MAX_TAG_SHOWN   60 /**< Show only first chars of tag */
 Show only first chars of tag.


Enumerations

enum  {
  SEARCH_COL_SORT_DATA_RANDOM = 0, SEARCH_COL_SORT_DATA_SORTED_ASC, SEARCH_COL_SORT_DATA_SORTED_DES, SEARCH_COL_SORT_DATA_COUNT,
  SEARCH_COL_SORT_DATA_INFO, SEARCH_COL_SORT_DATA_DEFAULT
}
 Characteristics of data in search results columns, used for sorting. More...


Functions

 RCSID ("$Id:search.c, v 1.61 2006/02/01 22:27:29 rmanfredi Exp $")
void set_search_color (struct search *sch)
 Set proper search color in list depending on whether it is enabled.

void gui_search_create_ctree (GtkWidget **sw, GtkCTree **ctree)
 Create a new GtkCTree for search results.

void add_parent_with_sha1 (GHashTable *ht, gpointer key, GtkCTreeNode *data)
 Add the given tree node to the hashtable.

void remove_parent_with_sha1 (GHashTable *ht, const gchar *sha1)
 Removes the tree node matching the given sha1 from the hash table.

GtkCTreeNode * find_parent_with_sha1 (GHashTable *ht, gpointer key)
gboolean search_gui_free_parent (gpointer key, gpointer unused_value, gpointer unused_x)
void search_gui_free_gui_record (gpointer gui_rc)
void search_gui_reset_search (search_t *sch)
 Reset the internal model of the search.

gboolean dec_records_refcount (gpointer key, gpointer unused_value, gpointer unused_x)
 Decrement refcount of hash table key entry.

void search_gui_ctree_unref (GtkCTree *ctree, GtkCTreeNode *node, gpointer unused_data)
 Removes a reference to the record stored in the given tree node.

void search_gui_clear_ctree (GtkCTree *ctree)
 Clears all nodes from given ctree and unreferences all records referenced by the nodes row data.

void search_gui_clear_search (search_t *sch)
 Clear all results from search.

void search_gui_close_search (search_t *sch)
 Remove the search from the list of searches and free all associated ressources (including filter and gui stuff).

gboolean search_gui_new_search_full (const gchar *querystr, time_t create_time, guint lifetime, guint32 reissue_timeout, gint sort_col, gint sort_order, flag_t flags, search_t **search)
 Create a new search and start it.

gint search_gui_compare_records (gint sort_col, const gui_record_t *g1, const gui_record_t *g2)
 If the value in sort_col for r1 is "greater than" r2 returns +1 0 if they're equal, and -1 if r1 is "less than" r2.

GList * search_gui_insert_with_sort (GList *list, GtkCTreeNode *node, GtkCTree *ctree, gboolean ascending, gint sort_col)
 Inserts the given node into the given list in the proper position.

void search_gui_quick_sort_array_swap (GArray *array, gint i1, gint i2)
 Swaps the values in the given array for the given indicies.

void search_gui_quick_sort (GArray *array, gint beg, gint end, GtkCTree *ctree, gboolean ascending, gint sort_col)
 Performs a recursive quick sort on the given array between indicies beg and end.

gint search_gui_analyze_col_data (GtkCTree *ctree, gint sort_col)
 Analyze the data in the given column to decide what type of search should be performed.

void search_gui_perform_sort (GtkCTree *ctree, gboolean ascending, gint sort_col)
 Sorts the given ctree using a quicksort algorithm.

void search_gui_sort_column (search_t *search, gint column)
 Draws arrows for the given column of the GtkCTree and sorts the contents of the GtkCTree according to the sorting parameters set in search.

void search_gui_add_record (search_t *sch, record_t *rc, GString *vinfo, GdkColor *fg, GdkColor *bg)
 Adds the record to gth GtkCTree for this search.

void search_gui_set_clear_button_sensitive (gboolean flag)
void search_gui_remove_result (GtkCTree *ctree, GtkCTreeNode *node)
 Removes the given node from the ctree.

guint download_selection_of_ctree (GtkCTree *ctree, guint *selected)
 Create downloads for all the search results selected in the ctree.

guint discard_selection_of_ctree (GtkCTree *ctree)
 Discard all the search results selected in the ctree.

void search_gui_download_files (void)
 Download selected files.

void search_gui_discard_files (void)
 Discard selected files.

gboolean search_gui_search_results_col_widths_changed (property_t prop)
 Callback to update the columns withs in the currently visible search.

gboolean search_gui_search_results_col_visible_changed (property_t prop)
 Callback to update the columns withs in the currently visible search.

void search_gui_init (void)
void search_gui_shutdown (void)
const GList * search_gui_get_searches (void)
void search_gui_remove_search (search_t *sch)
 Remove the search from the gui and update all widgets accordingly.

void search_gui_set_current_search (search_t *sch)
void gui_search_force_update_tab_label (struct search *sch)
 gui_search_force_update_tab_label

gboolean gui_search_update_tab_label (struct search *sch)
 Update the label if nothing's changed or if the last update was recent.

void gui_search_clear_results (void)
 Removes all search results from the current search.

void gui_search_get_colors (search_t *sch, GdkColor **mark_color, GdkColor **ignore_color, GdkColor **download_color)
 Extract the mark/ignore/download color.

void gui_search_set_enabled (struct search *sch, gboolean enabled)
 Flag whether search is enabled.

void search_gui_expand_all (void)
 Expand all nodes in tree for current search.

void search_gui_collapse_all (void)
 Expand all nodes in tree for current search.

void search_gui_start_massive_update (search_t *sch)
void search_gui_end_massive_update (search_t *sch)
void search_gui_metadata_update (const bitzi_data_t *data)
 Metadata Update.

void search_gui_queue_bitzi_by_sha1 (const record_t *rec, gpointer unused_udata)
 Update the search displays with the correct meta-data.


Variables

gchar tmpstr [4096]
GList * searches = NULL
search_t * search_selected = NULL
GtkCTree * default_search_ctree = NULL
GtkWidget * default_scrolled_window = NULL


Define Documentation

#define MAX_TAG_SHOWN   60 /**< Show only first chars of tag */
 

Show only first chars of tag.


Enumeration Type Documentation

anonymous enum
 

Characteristics of data in search results columns, used for sorting.

Enumeration values:
SEARCH_COL_SORT_DATA_RANDOM  Randomly distributed.
SEARCH_COL_SORT_DATA_SORTED_ASC  Already sorted or almost sorted.
SEARCH_COL_SORT_DATA_SORTED_DES  Same as above but descending.
SEARCH_COL_SORT_DATA_COUNT  Sorting by "count" column.
SEARCH_COL_SORT_DATA_INFO  Sorting by Info column.
SEARCH_COL_SORT_DATA_DEFAULT  Catch all case.


Function Documentation

void add_parent_with_sha1 GHashTable *  ht,
gpointer  key,
GtkCTreeNode *  data
[inline, static]
 

Add the given tree node to the hashtable.

The key is an atomized sha1 of the search result.

Bug:
FIXME: The "key" is an atom of the record's SHA1, why don't we create that atom here, as we free it in "remove_parent_with_sha1"? Emile 02/15/2004

gboolean dec_records_refcount gpointer  key,
gpointer  unused_value,
gpointer  unused_x
[static]
 

Decrement refcount of hash table key entry.

guint discard_selection_of_ctree GtkCTree *  ctree  )  [static]
 

Discard all the search results selected in the ctree.

Returns:
the amount of discarded results.

guint download_selection_of_ctree GtkCTree *  ctree,
guint *  selected
[static]
 

Create downloads for all the search results selected in the ctree.

Returns:
the amount of downloads actually created, and the amount of items in the selection within `selected'.

GtkCTreeNode* find_parent_with_sha1 GHashTable *  ht,
gpointer  key
 

Returns:
the tree node corresponding to the given key, an atomized sha1.

void gui_search_clear_results void   ) 
 

Removes all search results from the current search.

void gui_search_create_ctree GtkWidget **  sw,
GtkCTree **  ctree
[static]
 

Create a new GtkCTree for search results.

void gui_search_force_update_tab_label struct search sch  ) 
 

gui_search_force_update_tab_label

Like search_update_tab_label but always update the label

void gui_search_get_colors search_t *  sch,
GdkColor **  mark_color,
GdkColor **  ignore_color,
GdkColor **  download_color
 

Extract the mark/ignore/download color.

void gui_search_set_enabled struct search sch,
gboolean  enabled
 

Flag whether search is enabled.

gboolean gui_search_update_tab_label struct search sch  ) 
 

Update the label if nothing's changed or if the last update was recent.

RCSID "$Id:search.  c,
v 1.61 2006/02/01 22:27:29 rmanfredi Exp $" 
 

void remove_parent_with_sha1 GHashTable *  ht,
const gchar *  sha1
[inline, static]
 

Removes the tree node matching the given sha1 from the hash table.

The atom used for the key is then freed

void search_gui_add_record search_t *  sch,
record_t rc,
GString *  vinfo,
GdkColor *  fg,
GdkColor *  bg
 

Adds the record to gth GtkCTree for this search.

This is where the search grouping (parenting) is done

gint search_gui_analyze_col_data GtkCTree *  ctree,
gint  sort_col
 

Analyze the data in the given column to decide what type of search should be performed.

This function detects whether the data is alreadt sorted ascending, descending, appears to be random, is sorting via tha count column, or via the info column.

void search_gui_clear_ctree GtkCTree *  ctree  ) 
 

Clears all nodes from given ctree and unreferences all records referenced by the nodes row data.

void search_gui_clear_search search_t *  sch  ) 
 

Clear all results from search.

void search_gui_close_search search_t *  sch  ) 
 

Remove the search from the list of searches and free all associated ressources (including filter and gui stuff).

void search_gui_collapse_all void   ) 
 

Expand all nodes in tree for current search.

gint search_gui_compare_records gint  sort_col,
const gui_record_t *  g1,
const gui_record_t *  g2
[static]
 

If the value in sort_col for r1 is "greater than" r2 returns +1 0 if they're equal, and -1 if r1 is "less than" r2.

void search_gui_ctree_unref GtkCTree *  ctree,
GtkCTreeNode *  node,
gpointer  unused_data
 

Removes a reference to the record stored in the given tree node.

void search_gui_discard_files void   ) 
 

Discard selected files.

void search_gui_download_files void   ) 
 

Download selected files.

void search_gui_end_massive_update search_t *  sch  ) 
 

void search_gui_expand_all void   ) 
 

Expand all nodes in tree for current search.

void search_gui_free_gui_record gpointer  gui_rc  ) 
 

gboolean search_gui_free_parent gpointer  key,
gpointer  unused_value,
gpointer  unused_x
 

const GList* search_gui_get_searches void   ) 
 

void search_gui_init void   ) 
 

GList* search_gui_insert_with_sort GList *  list,
GtkCTreeNode *  node,
GtkCTree *  ctree,
gboolean  ascending,
gint  sort_col
 

Inserts the given node into the given list in the proper position.

Assumes list has at least one item already and is sorted. Note: this is extremely time critical code, some code duplication is intentional.

void search_gui_metadata_update const bitzi_data_t data  ) 
 

Metadata Update.

gboolean search_gui_new_search_full const gchar *  querystr,
time_t  create_time,
guint  lifetime,
guint32  reissue_timeout,
gint  sort_col,
gint  sort_order,
flag_t  flags,
search_t **  search
 

Create a new search and start it.

Returns:
TRUE if search was sucessfully created and FALSE if an error happened. If the "search" argument is not NULL a pointer to the new search is stored there.

void search_gui_perform_sort GtkCTree *  ctree,
gboolean  ascending,
gint  sort_col
 

Sorts the given ctree using a quicksort algorithm.

Theoretically this should be O(nlogn)

The default GtkCTree sort is a mergesort which works fine for small data sets. Due to the nature of GtkCTree's and the size of the structures being passed around, the speed is unacceptable for larger sets (>2000).

We therefore implement an analytical approach to minimize sort times. We examine the first few elements of a list and try to determine the nature of the data set and then choose the best of the following algorithms.

1. Default Mergesort: The built-in merge sort works fine for random sets of varied data. eg. Sorting by name after retreiving fresh results. If the data seems random and we're not sorting by count or info, we use this algorithm.

2. Insertion Sort: Performs stunningly on ordered or almost ordered data with a complexity of about O(n). Fortunately for us it is a common case. Users will often sort a column ascending and then resort it descending. Merge/quicksort do not to so well with ordered data (besides which most of the work is done already).

3. ??? sort. The info and count columns contain very few different elements with a large amount of repetition. Insertion sort seems to work acceptably for count, but marginly for the info column. Quicksort performs dismally for both info and count. Probably some sort of pseudeo intelligent insertion sort will be needed, ie. one that makes an almost ordered list followed by a cleanup algorithm.

void search_gui_queue_bitzi_by_sha1 const record_t rec,
gpointer  unused_udata
 

Update the search displays with the correct meta-data.

(called from seach_cb.c)

void search_gui_quick_sort GArray *  array,
gint  beg,
gint  end,
GtkCTree *  ctree,
gboolean  ascending,
gint  sort_col
 

Performs a recursive quick sort on the given array between indicies beg and end.

Note:
This is extremely time critical code, some code duplication is intentional.

Choose the item in the middle for the pivot, swap it to the end

move pivot from end to its final place

void search_gui_quick_sort_array_swap GArray *  array,
gint  i1,
gint  i2
 

Swaps the values in the given array for the given indicies.

void search_gui_remove_result GtkCTree *  ctree,
GtkCTreeNode *  node
[static]
 

Removes the given node from the ctree.

void search_gui_remove_search search_t *  sch  ) 
 

Remove the search from the gui and update all widgets accordingly.

void search_gui_reset_search search_t *  sch  ) 
 

Reset the internal model of the search.

Called when a search is restarted, for example.

gboolean search_gui_search_results_col_visible_changed property_t  prop  ) 
 

Callback to update the columns withs in the currently visible search.

This is not in settings_gui because the current search should not be known outside this file.

gboolean search_gui_search_results_col_widths_changed property_t  prop  ) 
 

Callback to update the columns withs in the currently visible search.

This is not in settings_gui because the current search should not be known outside this file.

void search_gui_set_clear_button_sensitive gboolean  flag  ) 
 

void search_gui_set_current_search search_t *  sch  ) 
 

void search_gui_shutdown void   ) 
 

void search_gui_sort_column search_t *  search,
gint  column
 

Draws arrows for the given column of the GtkCTree and sorts the contents of the GtkCTree according to the sorting parameters set in search.

void search_gui_start_massive_update search_t *  sch  ) 
 

void set_search_color struct search sch  )  [static]
 

Set proper search color in list depending on whether it is enabled.


Variable Documentation

GtkWidget* default_scrolled_window = NULL [static]
 

GtkCTree* default_search_ctree = NULL
 

search_t* search_selected = NULL
 

GList* searches = NULL
 

gchar tmpstr[4096] [static]
 


Generated on Sun Feb 12 10:50:07 2006 for Gtk-Gnutella by doxygen 1.3.6