NetSurf
Data Structures | Macros | Enumerations | Functions | Variables
global_history.c File Reference
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/utf8.h"
#include "utils/libdom.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "content/urldb.h"
#include "desktop/global_history.h"
#include "desktop/treeview.h"
#include "netsurf/browser_window.h"
Include dependency graph for global_history.c:

Go to the source code of this file.

Data Structures

struct  global_history_folder
 
struct  global_history_ctx
 
struct  global_history_entry
 
struct  treeview_export_walk_ctx
 

Macros

#define N_DAYS   28
 
#define N_SEC_PER_DAY   (60 * 60 * 24)
 

Enumerations

enum  global_history_folders {
  GH_TODAY = 0 , GH_YESTERDAY , GH_2_DAYS_AGO , GH_3_DAYS_AGO ,
  GH_4_DAYS_AGO , GH_5_DAYS_AGO , GH_6_DAYS_AGO , GH_LAST_WEEK ,
  GH_2_WEEKS_AGO , GH_3_WEEKS_AGO , GH_N_FOLDERS
}
 
enum  global_history_fields {
  GH_TITLE , GH_URL , GH_LAST_VISIT , GH_VISITS ,
  GH_PERIOD , N_FIELDS
}
 

Functions

static struct global_history_entryglobal_history_find (nsurl *url)
 Find an entry in the global history. More...
 
static nserror global_history_create_dir (enum global_history_folders f)
 Initialise the treeview directories. More...
 
static nserror global_history_get_parent_treeview_node (treeview_node **parent, int slot)
 Get the treeview folder for history entires in a particular slot. More...
 
static nserror global_history_create_treeview_field_data (struct global_history_entry *e, const struct url_data *data)
 Set a global history entry's data from the url_data. More...
 
static nserror global_history_entry_insert (struct global_history_entry *e, int slot)
 Add a global history entry to the treeview. More...
 
static nserror global_history_add_entry_internal (nsurl *url, int slot, const struct url_data *data, bool got_treeview)
 Add an entry to the global history (creates the entry). More...
 
static void global_history_delete_entry_internal (struct global_history_entry *e)
 Delete a global history entry. More...
 
static bool global_history_add_entry (nsurl *url, const struct url_data *data)
 Internal routine to actually perform global history addition. More...
 
static nserror global_history_initialise_entry_fields (void)
 Initialise the treeview entry feilds. More...
 
static nserror global_history_initialise_time (void)
 Initialise the time. More...
 
static nserror global_history_init_entries (void)
 Initialise the treeview entries. More...
 
static nserror global_history_tree_node_folder_cb (struct treeview_node_msg msg, void *data)
 
static nserror global_history_tree_node_entry_cb (struct treeview_node_msg msg, void *data)
 
nserror global_history_init (void *core_window_handle)
 Initialise the global history. More...
 
nserror global_history_fini (void)
 Finalise the global history. More...
 
nserror global_history_add (nsurl *url)
 Add an entry to the global history. More...
 
static nserror global_history_export_enter_cb (void *ctx, void *node_data, enum treeview_node_type type, bool *abort)
 Callback for treeview_walk node entering. More...
 
static nserror global_history_export_leave_cb (void *ctx, void *node_data, enum treeview_node_type type, bool *abort)
 Callback for treeview_walk node leaving. More...
 
nserror global_history_export (const char *path, const char *title)
 Save global history to file (html) More...
 
void global_history_redraw (int x, int y, struct rect *clip, const struct redraw_context *ctx)
 Redraw the global history. More...
 
void global_history_mouse_action (browser_mouse_state mouse, int x, int y)
 Handles all kinds of mouse action. More...
 
bool global_history_keypress (uint32_t key)
 Key press handling. More...
 
bool global_history_has_selection (void)
 Determine whether there is a selection. More...
 
bool global_history_get_selection (nsurl **url, const char **title)
 Get the first selected node. More...
 
nserror global_history_expand (bool only_folders)
 Expand the treeview's nodes. More...
 
nserror global_history_contract (bool all)
 Contract the treeview's nodes. More...
 

Variables

struct global_history_ctx gh_ctx
 
struct global_history_entrygh_list [N_DAYS]
 
struct treeview_callback_table gh_tree_cb_t
 

Macro Definition Documentation

◆ N_DAYS

#define N_DAYS   28

Definition at line 36 of file global_history.c.

◆ N_SEC_PER_DAY

#define N_SEC_PER_DAY   (60 * 60 * 24)

Definition at line 37 of file global_history.c.

Enumeration Type Documentation

◆ global_history_fields

Enumerator
GH_TITLE 
GH_URL 
GH_LAST_VISIT 
GH_VISITS 
GH_PERIOD 
N_FIELDS 

Definition at line 53 of file global_history.c.

◆ global_history_folders

Enumerator
GH_TODAY 
GH_YESTERDAY 
GH_2_DAYS_AGO 
GH_3_DAYS_AGO 
GH_4_DAYS_AGO 
GH_5_DAYS_AGO 
GH_6_DAYS_AGO 
GH_LAST_WEEK 
GH_2_WEEKS_AGO 
GH_3_WEEKS_AGO 
GH_N_FOLDERS 

Definition at line 39 of file global_history.c.

Function Documentation

◆ global_history_add()

nserror global_history_add ( struct nsurl url)

Add an entry to the global history.

If the URL already exists in the global history, the old node is removed.

Parameters
urlURL for node being added
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 829 of file global_history.c.

References gh_ctx, global_history_add_entry(), NSERROR_BAD_PARAMETER, NSERROR_OK, NSLOG, global_history_ctx::tree, and urldb_get_url_data().

Referenced by browser_window_content_ready().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_add_entry()

static bool global_history_add_entry ( nsurl url,
const struct url_data data 
)
static

Internal routine to actually perform global history addition.

Parameters
urlThe URL to add
dataURL data associated with URL
Returns
true (for urldb_iterate_entries)

Definition at line 476 of file global_history.c.

References global_history_entry::data, global_history_entry::entry, gh_ctx, global_history_add_entry_internal(), global_history_find(), N_DAYS, N_SEC_PER_DAY, NSERROR_OK, global_history_entry::slot, global_history_ctx::today, global_history_ctx::tree, TREE_OPTION_SUPPRESS_REDRAW, TREE_OPTION_SUPPRESS_RESIZE, treeview_delete_node(), and global_history_entry::url.

Referenced by global_history_add(), and global_history_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_add_entry_internal()

static nserror global_history_add_entry_internal ( nsurl url,
int  slot,
const struct url_data data,
bool  got_treeview 
)
static

Add an entry to the global history (creates the entry).

If the treeview has already been created, the entry will be added to the treeview. Otherwise, the entry will have to be added to the treeview later.

When we first create the global history we create it without the treeview, to simplfy sorting the entries.

Parameters
urlURL for entry to add to history
slotGlobal history slot to contain history entry
dataURL data for the entry
got_treeviewWhether the treeview has been created already
Returns
NSERROR_OK on success, or appropriate error otherwise

Definition at line 357 of file global_history.c.

References global_history_entry::data, global_history_entry::entry, gh_list, global_history_create_treeview_field_data(), global_history_entry_insert(), global_history_entry::next, NSERROR_NOMEM, NSERROR_OK, nsurl_ref(), global_history_entry::prev, global_history_entry::slot, global_history_entry::t, global_history_entry::url, and global_history_entry::user_delete.

Referenced by global_history_add_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_contract()

nserror global_history_contract ( bool  all)

Contract the treeview's nodes.

Parameters
allIff false, only entries are contracted.
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1009 of file global_history.c.

References gh_ctx, global_history_ctx::tree, and treeview_contract().

Referenced by global_history_menu_select(), global_history_toolbar_click(), HOOKF(), and MENUHANDLER().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_create_dir()

static nserror global_history_create_dir ( enum global_history_folders  f)
static

Initialise the treeview directories.

Parameters
fIdent for folder to create
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 128 of file global_history.c.

References global_history_ctx::built, global_history_folder::data, treeview_field_desc::field, treeview_field_data::field, global_history_ctx::fields, global_history_folder::folder, global_history_ctx::folders, GH_2_DAYS_AGO, GH_2_WEEKS_AGO, GH_3_DAYS_AGO, GH_3_WEEKS_AGO, GH_4_DAYS_AGO, GH_5_DAYS_AGO, GH_6_DAYS_AGO, gh_ctx, GH_LAST_WEEK, GH_TODAY, GH_YESTERDAY, messages_get(), N_FIELDS, NSERROR_BAD_PARAMETER, global_history_ctx::tree, TREE_OPTION_NONE, TREE_OPTION_SUPPRESS_REDRAW, TREE_OPTION_SUPPRESS_RESIZE, TREE_REL_FIRST_CHILD, TREE_REL_NEXT_SIBLING, treeview_create_node_folder(), treeview_field_data::value, and treeview_field_data::value_len.

Referenced by global_history_get_parent_treeview_node(), and global_history_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_create_treeview_field_data()

static nserror global_history_create_treeview_field_data ( struct global_history_entry e,
const struct url_data data 
)
static

Set a global history entry's data from the url_data.

Parameters
eGlobal history entry to set up
dataData associated with entry's URL
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 262 of file global_history.c.

References buffer, global_history_folder::data, global_history_entry::data, treeview_field_desc::field, treeview_field_data::field, global_history_ctx::fields, gh_ctx, GH_LAST_VISIT, GH_TITLE, GH_URL, GH_VISITS, url_data::last_visit, messages_get(), NSERROR_OK, nsurl_access(), nsurl_length(), global_history_entry::url, treeview_field_data::value, treeview_field_data::value_len, and url_data::visits.

Referenced by global_history_add_entry_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_delete_entry_internal()

static void global_history_delete_entry_internal ( struct global_history_entry e)
static

Delete a global history entry.

This does not delete the treeview node, rather it should only be called from the treeview node delete event message.

Parameters
eEntry to delete

Definition at line 430 of file global_history.c.

References global_history_entry::data, global_history_entry::entry, GH_LAST_VISIT, gh_list, GH_TITLE, GH_VISITS, global_history_entry::next, nsurl_unref(), global_history_entry::prev, global_history_entry::slot, global_history_entry::url, urldb_reset_url_visit_data(), global_history_entry::user_delete, and treeview_field_data::value.

Referenced by global_history_tree_node_entry_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_entry_insert()

static nserror global_history_entry_insert ( struct global_history_entry e,
int  slot 
)
static

Add a global history entry to the treeview.

Parameters
eentry to add to treeview
slotglobal history slot containing entry
Returns
NSERROR_OK on success, or appropriate error otherwise

It is assumed that the entry is unique (for its URL) in the global history table

Definition at line 318 of file global_history.c.

References global_history_ctx::built, global_history_entry::data, global_history_entry::entry, gh_ctx, global_history_get_parent_treeview_node(), NSERROR_OK, parent, global_history_ctx::tree, TREE_OPTION_NONE, TREE_OPTION_SUPPRESS_REDRAW, TREE_OPTION_SUPPRESS_RESIZE, TREE_REL_FIRST_CHILD, and treeview_create_node_entry().

Referenced by global_history_add_entry_internal(), and global_history_init_entries().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_expand()

nserror global_history_expand ( bool  only_folders)

Expand the treeview's nodes.

Parameters
only_foldersIff true, only folders are expanded.
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 1002 of file global_history.c.

References gh_ctx, global_history_ctx::tree, and treeview_expand().

Referenced by global_history_menu_select(), global_history_toolbar_click(), HOOKF(), and MENUHANDLER().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_export()

nserror global_history_export ( const char *  path,
const char *  title 
)

Save global history to file (html)

Parameters
pathThe path to save history to
titleThe title to give the document, or NULL for default
Returns
NSERROR_OK on success, or appropriate error otherwise

Definition at line 912 of file global_history.c.

References treeview_export_walk_ctx::fp, gh_ctx, global_history_export_enter_cb(), global_history_export_leave_cb(), NSERROR_OK, NSERROR_SAVE_FAILED, path(), global_history_ctx::tree, TREE_NODE_ENTRY, TREE_NODE_FOLDER, and treeview_walk().

Referenced by HOOKF(), MENUHANDLER(), and ro_gui_save_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_export_enter_cb()

static nserror global_history_export_enter_cb ( void *  ctx,
void *  node_data,
enum treeview_node_type  type,
bool *  abort 
)
static

Callback for treeview_walk node entering.

Definition at line 854 of file global_history.c.

References global_history_folder::data, global_history_entry::data, treeview_export_walk_ctx::fp, GH_TITLE, GH_URL, NSERROR_OK, NSERROR_SAVE_FAILED, TREE_NODE_ENTRY, TREE_NODE_FOLDER, type, utf8_to_html(), treeview_field_data::value, and treeview_field_data::value_len.

Referenced by global_history_export().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_export_leave_cb()

static nserror global_history_export_leave_cb ( void *  ctx,
void *  node_data,
enum treeview_node_type  type,
bool *  abort 
)
static

Callback for treeview_walk node leaving.

Definition at line 900 of file global_history.c.

References treeview_export_walk_ctx::fp, NSERROR_OK, TREE_NODE_FOLDER, and type.

Referenced by global_history_export().

Here is the caller graph for this function:

◆ global_history_find()

static struct global_history_entry * global_history_find ( nsurl url)
static

Find an entry in the global history.

Parameters
urlThe URL to find
Returns
Pointer to history entry, or NULL if not found

Definition at line 98 of file global_history.c.

References gh_list, N_DAYS, global_history_entry::next, nsurl_compare(), NSURL_COMPLETE, and global_history_entry::url.

Referenced by global_history_add_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_fini()

nserror global_history_fini ( void  )

Finalise the global history.

This destroys the global history treeview and the global history module's internal data. After calling this if global history is required again, global_history_init must be called.

Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 799 of file global_history.c.

References global_history_ctx::built, treeview_field_desc::field, global_history_ctx::fields, gh_ctx, N_FIELDS, NSERROR_OK, NSLOG, global_history_ctx::tree, treeview_destroy(), and treeview_fini().

Referenced by ami_history_global_destroy(), atari_global_history_finish(), nsgtk_global_history_destroy(), nsw32_global_history_finalise(), and ro_gui_global_history_finalise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_get_parent_treeview_node()

static nserror global_history_get_parent_treeview_node ( treeview_node **  parent,
int  slot 
)
inlinestatic

Get the treeview folder for history entires in a particular slot.

Parameters
parentUpdated to parent folder.
slotGlobal history slot of entry we want folder node for
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 214 of file global_history.c.

References global_history_folder::folder, global_history_ctx::folders, GH_2_WEEKS_AGO, GH_3_WEEKS_AGO, gh_ctx, GH_LAST_WEEK, global_history_create_dir(), N_DAYS, NSERROR_BAD_PARAMETER, NSERROR_OK, and parent.

Referenced by global_history_entry_insert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_get_selection()

bool global_history_get_selection ( struct nsurl **  url,
const char **  title 
)

Get the first selected node.

Parameters
urlUpdated to the selected entry's address, or NULL
titleUpdated to the selected entry's title, or NULL
Returns
true iff global history has a selection

Definition at line 980 of file global_history.c.

References global_history_entry::data, gh_ctx, GH_TITLE, global_history_ctx::tree, TREE_NODE_ENTRY, treeview_get_selection(), type, global_history_entry::url, and treeview_field_data::value.

Referenced by ami_history_global_drag_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_has_selection()

bool global_history_has_selection ( void  )

Determine whether there is a selection.

Returns
true iff there is a selection

Definition at line 973 of file global_history.c.

References gh_ctx, global_history_ctx::tree, and treeview_has_selection().

Referenced by ami_history_global_drag_end(), global_history_menu_prepare(), and global_history_toolbar_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_init()

nserror global_history_init ( void *  core_window_handle)

Initialise the global history.

This iterates through the URL database, generating the global history data, and creates a treeview.

This must be called before any other global_history_* function.

Parameters
core_window_handleThe core_window in which the global history is shown.
Returns
NSERROR_OK on success, appropriate error otherwise

Definition at line 726 of file global_history.c.

References global_history_ctx::built, global_history_ctx::fields, global_history_folder::folder, global_history_ctx::folders, gh_ctx, GH_TODAY, gh_tree_cb_t, global_history_add_entry(), global_history_create_dir(), global_history_init_entries(), global_history_initialise_entry_fields(), global_history_initialise_time(), N_FIELDS, NSERROR_OK, NSLOG, global_history_ctx::tree, treeview_create(), TREEVIEW_DEL_EMPTY_DIRS, treeview_get_height(), treeview_init(), TREEVIEW_NO_MOVES, treeview_node_expand(), TREEVIEW_SEARCHABLE, and urldb_iterate_entries().

Referenced by ami_history_global_present(), atari_global_history_init_phase2(), nsgtk_global_history_init(), nsw32_global_history_init(), and ro_global_history_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_init_entries()

static nserror global_history_init_entries ( void  )
static

Initialise the treeview entries.

Returns
NSERROR_OK on success, or appropriate error otherwise

Definition at line 630 of file global_history.c.

References gh_list, global_history_entry_insert(), N_DAYS, global_history_entry::next, NSERROR_OK, and global_history_entry::prev.

Referenced by global_history_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_initialise_entry_fields()

static nserror global_history_initialise_entry_fields ( void  )
static

Initialise the treeview entry feilds.

Returns
NSERROR_OK on success, or appropriate error otherwise

Definition at line 524 of file global_history.c.

References treeview_field_desc::field, global_history_ctx::fields, treeview_field_desc::flags, gh_ctx, GH_LAST_VISIT, GH_PERIOD, GH_TITLE, GH_URL, GH_VISITS, messages_get(), N_FIELDS, NSERROR_OK, NSERROR_UNKNOWN, TREE_FLAG_COPY_TEXT, TREE_FLAG_DEFAULT, TREE_FLAG_SEARCHABLE, and TREE_FLAG_SHOW_NAME.

Referenced by global_history_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_initialise_time()

static nserror global_history_initialise_time ( void  )
static

Initialise the time.

Returns
NSERROR_OK on success, or appropriate error otherwise

Definition at line 595 of file global_history.c.

References gh_ctx, NSERROR_OK, NSERROR_UNKNOWN, NSLOG, global_history_ctx::today, and global_history_ctx::weekday.

Referenced by global_history_init().

Here is the caller graph for this function:

◆ global_history_keypress()

bool global_history_keypress ( uint32_t  key)

Key press handling.

Parameters
keyThe ucs4 character codepoint
Returns
true if the keypress is dealt with, false otherwise.

Definition at line 966 of file global_history.c.

References gh_ctx, global_history_ctx::tree, and treeview_keypress().

Referenced by ami_history_global_key(), atari_global_history_keypress(), global_history_key(), global_history_menu_select(), global_history_toolbar_click(), HOOKF(), MENUHANDLER(), nsgtk_global_history_key(), and nsw32_global_history_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_mouse_action()

void global_history_mouse_action ( enum browser_mouse_state  mouse,
int  x,
int  y 
)

Handles all kinds of mouse action.

Parameters
mouseThe current mouse state
xX coordinate
yY coordinate

Definition at line 959 of file global_history.c.

References gh_ctx, global_history_ctx::tree, and treeview_mouse_action().

Referenced by ami_history_global_mouse(), atari_global_history_mouse_action(), global_history_mouse(), nsgtk_global_history_mouse(), and nsw32_global_history_mouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_redraw()

void global_history_redraw ( int  x,
int  y,
struct rect clip,
const struct redraw_context ctx 
)

Redraw the global history.

Parameters
xX coordinate to render treeview at
yY coordinate to render treeview at
clipCurrent clip rectangle (wrt tree origin)
ctxCurrent redraw context

Definition at line 951 of file global_history.c.

References clip(), gh_ctx, global_history_ctx::tree, and treeview_redraw().

Referenced by ami_history_global_draw(), atari_global_history_draw(), global_history_draw(), nsgtk_global_history_draw(), and nsw32_global_history_draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_history_tree_node_entry_cb()

static nserror global_history_tree_node_entry_cb ( struct treeview_node_msg  msg,
void *  data 
)
static

◆ global_history_tree_node_folder_cb()

static nserror global_history_tree_node_folder_cb ( struct treeview_node_msg  msg,
void *  data 
)
static

Variable Documentation

◆ gh_ctx

struct global_history_ctx gh_ctx

◆ gh_list

struct global_history_entry* gh_list[N_DAYS]

◆ gh_tree_cb_t

struct treeview_callback_table gh_tree_cb_t
Initial value:
= {
}
static nserror global_history_tree_node_entry_cb(struct treeview_node_msg msg, void *data)
static nserror global_history_tree_node_folder_cb(struct treeview_node_msg msg, void *data)

Definition at line 719 of file global_history.c.

Referenced by global_history_init().