NetSurf
hotlist.h
Go to the documentation of this file.
1/*
2 * Copyright 2013 Michael Drake <tlsa@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _NETSURF_DESKTOP_HOTLIST_H_
20#define _NETSURF_DESKTOP_HOTLIST_H_
21
22#include <stdbool.h>
23#include <stdint.h>
24
25#include "utils/errors.h"
26#include "netsurf/mouse.h"
27
29struct redraw_context;
30struct nsurl;
31struct rect;
32
33/**
34 * Initialise the hotlist.
35 *
36 * This opens the hotlist file, construct the hostlist, and creates a
37 * treeview. If there's no hotlist file, it generates a default hotlist.
38 *
39 * This must be called before any other hotlist_* function. It must
40 * be called before URLs can be added to the hotlist, and before the
41 * hotlist can be queried to ask if URLs are present in the hotlist.
42 *
43 * In read-only mode the hotlist can be modified, but changes will not
44 * persist over sessions.
45 *
46 * \param load_path The path to load hotlist from.
47 * \param save_path The path to save hotlist to, or NULL for read-only mode.
48 * \return NSERROR_OK on success, appropriate error otherwise
49 */
51 const char *load_path,
52 const char *save_path);
53
54/**
55 * Initialise the hotlist manager.
56 *
57 * This connects the underlying hotlist treeview to a corewindow for display.
58 *
59 * The provided core window handle must be valid until hotlist_fini is called.
60 *
61 * \param cw_t Callback table for core_window containing the treeview
62 * \param core_window_handle The handle in which the treeview is shown
63 * \return NSERROR_OK on success, appropriate error otherwise
64 */
66 void *core_window_handle);
67
68
69/**
70 * Finalise the hotlist manager.
71 *
72 * This simply disconnects the underlying treeview from its corewindow,
73 * allowing destruction of a GUI hotlist window, without finalising the
74 * hotlist module.
75 *
76 * \return NSERROR_OK on success, appropriate error otherwise
77 */
79
80/**
81 * Finalise the hotlist.
82 *
83 * This destroys the hotlist treeview and the hotlist module's
84 * internal data. After calling this if hotlist is required again,
85 * hotlist_init must be called.
86 *
87 * \return NSERROR_OK on success, appropriate error otherwise
88 */
90
91/**
92 * Add an entry to the hotlist for given URL.
93 *
94 * \param url URL for node being added
95 * \return NSERROR_OK on success, appropriate error otherwise
96 */
97nserror hotlist_add_url(struct nsurl *url);
98
99/**
100 * Check whether given URL is present in hotlist
101 *
102 * \param url Address to look for in hotlist
103 * \return true iff url is present in hotlist, false otherwise
104 */
105bool hotlist_has_url(struct nsurl *url);
106
107/**
108 * Remove any entries matching the given URL from the hotlist
109 *
110 * \param url Address to look for in hotlist
111 */
112void hotlist_remove_url(struct nsurl *url);
113
114/**
115 * Update given URL, e.g. new visited data
116 *
117 * \param url Address to update entries for
118 */
119void hotlist_update_url(struct nsurl *url);
120
121/**
122 * Add an entry to the hotlist for given Title/URL.
123 *
124 * \param url URL for entry to be added, or NULL
125 * \param title Title for entry being added (copied), or NULL
126 * \param at_y Iff true, insert at y-offest
127 * \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
128 * \return NSERROR_OK on success, appropriate error otherwise
129 */
130nserror hotlist_add_entry(struct nsurl *url, const char *title, bool at_y, int y);
131
132/**
133 * Add a folder to the hotlist.
134 *
135 * \param title Title for folder being added, or NULL
136 * \param at_y Iff true, insert at y-offest
137 * \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
138 * \return NSERROR_OK on success, appropriate error otherwise
139 */
140nserror hotlist_add_folder(const char *title, bool at_y, int y);
141
142/**
143 * Save hotlist to file
144 *
145 * \param path The path to save hotlist to
146 * \param title The title to give the hotlist, or NULL for default
147 * \return NSERROR_OK on success, or appropriate error otherwise
148 */
149nserror hotlist_export(const char *path, const char *title);
150
151/**
152 * Client callback for hotlist_iterate, reporting entry into folder
153 *
154 * \param ctx Client context
155 * \param title The entered folder's title
156 * \return NSERROR_OK on success, or appropriate error otherwise
157 */
158typedef nserror (*hotlist_folder_enter_cb)(void *ctx, const char *title);
159
160/**
161 * Client callback for hotlist_iterate, reporting a hotlist address
162 *
163 * \param ctx Client context
164 * \param url The entry's address
165 * \param title The entry's title
166 * \return NSERROR_OK on success, or appropriate error otherwise
167 */
168typedef nserror (*hotlist_address_cb)(void *ctx, struct nsurl *url, const char *title);
169
170/**
171 * Client callback for hotlist_iterate, reporting a hotlist folder departure
172 *
173 * \param ctx Client context
174 * \param title The departed folder's title
175 * \return NSERROR_OK on success, or appropriate error otherwise
176 */
177typedef nserror (*hotlist_folder_leave_cb)(void *ctx);
178
179
180/**
181 * Walk (depth first) the hotlist, calling callbacks on entering folders,
182 * address nodes, and on leaving folders.
183 *
184 * \param ctx Client context, passed back to callback function
185 * \param enter_cb Function to call on entering nodes, or NULL
186 * \param address_cb Function to call on address nodes, or NULL
187 * \param leave_cb Function to call on leaving nodes, or NULL
188 * \return NSERROR_OK on success, or appropriate error otherwise
189 *
190 * Example usage: Generate a menu containing hotlist entries. For flat list
191 * set enter_cb and leave_cb to NULL, or for hierarchical menu
192 * provide the folder callbacks.
193 */
194nserror hotlist_iterate(void *ctx,
196 hotlist_address_cb address_cb,
197 hotlist_folder_leave_cb leave_cb);
198
199/**
200 * Redraw the hotlist.
201 *
202 * \param x X coordinate to render treeview at
203 * \param y Y coordinate to render treeview at
204 * \param clip Current clip rectangle (wrt tree origin)
205 * \param ctx Current redraw context
206 */
207void hotlist_redraw(int x, int y, struct rect *clip,
208 const struct redraw_context *ctx);
209
210/**
211 * Handles all kinds of mouse action
212 *
213 * \param mouse The current mouse state
214 * \param x X coordinate
215 * \param y Y coordinate
216 */
217void hotlist_mouse_action(enum browser_mouse_state mouse, int x, int y);
218
219/**
220 * Key press handling.
221 *
222 * \param key The ucs4 character codepoint
223 * \return true if the keypress is dealt with, false otherwise.
224 */
225bool hotlist_keypress(uint32_t key);
226
227/**
228 * Determine whether there is a selection
229 *
230 * \return true iff there is a selection
231 */
232bool hotlist_has_selection(void);
233
234/**
235 * Get the first selected node
236 *
237 * \param url Updated to the selected entry's address, or NULL
238 * \param title Updated to the selected entry's title, or NULL
239 * \return true iff hotlist has a selection
240 */
241bool hotlist_get_selection(struct nsurl **url, const char **title);
242
243/**
244 * Edit the first selected node
245 */
246void hotlist_edit_selection(void);
247
248/**
249 * Expand the treeview's nodes
250 *
251 * \param only_folders Iff true, only folders are expanded.
252 * \return NSERROR_OK on success, appropriate error otherwise
253 */
254nserror hotlist_expand(bool only_folders);
255
256/**
257 * Contract the treeview's nodes
258 *
259 * \param all Iff false, only entries are contracted.
260 * \return NSERROR_OK on success, appropriate error otherwise
261 */
262nserror hotlist_contract(bool all);
263
264#endif
nserror hotlist_add_entry(struct nsurl *url, const char *title, bool at_y, int y)
Add an entry to the hotlist for given Title/URL.
Definition: hotlist.c:1624
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1698
bool hotlist_has_selection(void)
Determine whether there is a selection.
Definition: hotlist.c:1705
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1388
bool hotlist_get_selection(struct nsurl **url, const char **title)
Get the first selected node.
Definition: hotlist.c:1712
void hotlist_update_url(struct nsurl *url)
Update given URL, e.g.
Definition: hotlist.c:1603
nserror hotlist_manager_fini(void)
Finalise the hotlist manager.
Definition: hotlist.c:1373
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1683
nserror hotlist_iterate(void *ctx, hotlist_folder_enter_cb enter_cb, hotlist_address_cb address_cb, hotlist_folder_leave_cb leave_cb)
Walk (depth first) the hotlist, calling callbacks on entering folders, address nodes,...
Definition: hotlist.c:1164
void hotlist_remove_url(struct nsurl *url)
Remove any entries matching the given URL from the hotlist.
Definition: hotlist.c:1536
nserror hotlist_manager_init(struct core_window_callback_table *cw_t, void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
nserror hotlist_add_folder(const char *title, bool at_y, int y)
Add a folder to the hotlist.
Definition: hotlist.c:1661
nserror hotlist_init(const char *load_path, const char *save_path)
Initialise the hotlist.
Definition: hotlist.c:1290
nserror hotlist_export(const char *path, const char *title)
Save hotlist to file.
Definition: hotlist.c:1086
nserror hotlist_expand(bool only_folders)
Expand the treeview's nodes.
Definition: hotlist.c:1741
nserror(* hotlist_address_cb)(void *ctx, struct nsurl *url, const char *title)
Client callback for hotlist_iterate, reporting a hotlist address.
Definition: hotlist.h:168
nserror(* hotlist_folder_leave_cb)(void *ctx)
Client callback for hotlist_iterate, reporting a hotlist folder departure.
Definition: hotlist.h:177
void hotlist_edit_selection(void)
Edit the first selected node.
Definition: hotlist.c:1734
nserror(* hotlist_folder_enter_cb)(void *ctx, const char *title)
Client callback for hotlist_iterate, reporting entry into folder.
Definition: hotlist.h:158
bool hotlist_has_url(struct nsurl *url)
Check whether given URL is present in hotlist.
Definition: hotlist.c:1494
nserror hotlist_contract(bool all)
Contract the treeview's nodes.
Definition: hotlist.c:1748
nserror hotlist_add_url(struct nsurl *url)
Add an entry to the hotlist for given URL.
Definition: hotlist.c:1431
void hotlist_mouse_action(enum browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1691
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
static struct core_window_callback_table cw_t
Declare Core Window Callbacks:
Definition: treeview.c:534
Core mouse and pointer states.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Callbacks to achieve various core window functionality.
Definition: core_window.h:51
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357