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
28struct redraw_context;
29struct nsurl;
30struct rect;
31
32/**
33 * Initialise the hotlist.
34 *
35 * This opens the hotlist file, construct the hostlist, and creates a
36 * treeview. If there's no hotlist file, it generates a default hotlist.
37 *
38 * This must be called before any other hotlist_* function. It must
39 * be called before URLs can be added to the hotlist, and before the
40 * hotlist can be queried to ask if URLs are present in the hotlist.
41 *
42 * In read-only mode the hotlist can be modified, but changes will not
43 * persist over sessions.
44 *
45 * \param load_path The path to load hotlist from.
46 * \param save_path The path to save hotlist to, or NULL for read-only mode.
47 * \return NSERROR_OK on success, appropriate error otherwise
48 */
49nserror hotlist_init(const char *load_path, const char *save_path);
50
51/**
52 * Initialise the hotlist manager.
53 *
54 * This connects the underlying hotlist treeview to a corewindow for display.
55 *
56 * The provided core window handle must be valid until hotlist_fini is called.
57 *
58 * \param core_window_handle The handle in which the hotlist is shown
59 * \return NSERROR_OK on success, appropriate error otherwise
60 */
61nserror hotlist_manager_init(void *core_window_handle);
62
63
64/**
65 * Finalise the hotlist manager.
66 *
67 * This simply disconnects the underlying treeview from its corewindow,
68 * allowing destruction of a GUI hotlist window, without finalising the
69 * hotlist module.
70 *
71 * \return NSERROR_OK on success, appropriate error otherwise
72 */
74
75/**
76 * Finalise the hotlist.
77 *
78 * This destroys the hotlist treeview and the hotlist module's
79 * internal data. After calling this if hotlist is required again,
80 * hotlist_init must be called.
81 *
82 * \return NSERROR_OK on success, appropriate error otherwise
83 */
85
86/**
87 * Add an entry to the hotlist for given URL.
88 *
89 * \param url URL for node being added
90 * \return NSERROR_OK on success, appropriate error otherwise
91 */
92nserror hotlist_add_url(struct nsurl *url);
93
94/**
95 * Check whether given URL is present in hotlist
96 *
97 * \param url Address to look for in hotlist
98 * \return true iff url is present in hotlist, false otherwise
99 */
100bool hotlist_has_url(struct nsurl *url);
101
102/**
103 * Remove any entries matching the given URL from the hotlist
104 *
105 * \param url Address to look for in hotlist
106 */
107void hotlist_remove_url(struct nsurl *url);
108
109/**
110 * Update given URL, e.g. new visited data
111 *
112 * \param url Address to update entries for
113 */
114void hotlist_update_url(struct nsurl *url);
115
116/**
117 * Add an entry to the hotlist for given Title/URL.
118 *
119 * \param url URL for entry to be added, or NULL
120 * \param title Title for entry being added (copied), or NULL
121 * \param at_y Iff true, insert at y-offest
122 * \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
123 * \return NSERROR_OK on success, appropriate error otherwise
124 */
125nserror hotlist_add_entry(struct nsurl *url, const char *title, bool at_y, int y);
126
127/**
128 * Add a folder to the hotlist.
129 *
130 * \param title Title for folder being added, or NULL
131 * \param at_y Iff true, insert at y-offest
132 * \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
133 * \return NSERROR_OK on success, appropriate error otherwise
134 */
135nserror hotlist_add_folder(const char *title, bool at_y, int y);
136
137/**
138 * Save hotlist to file
139 *
140 * \param path The path to save hotlist to
141 * \param title The title to give the hotlist, or NULL for default
142 * \return NSERROR_OK on success, or appropriate error otherwise
143 */
144nserror hotlist_export(const char *path, const char *title);
145
146/**
147 * Client callback for hotlist_iterate, reporting entry into folder
148 *
149 * \param ctx Client context
150 * \param title The entered folder's title
151 * \return NSERROR_OK on success, or appropriate error otherwise
152 */
153typedef nserror (*hotlist_folder_enter_cb)(void *ctx, const char *title);
154
155/**
156 * Client callback for hotlist_iterate, reporting a hotlist address
157 *
158 * \param ctx Client context
159 * \param url The entry's address
160 * \param title The entry's title
161 * \return NSERROR_OK on success, or appropriate error otherwise
162 */
163typedef nserror (*hotlist_address_cb)(void *ctx, struct nsurl *url, const char *title);
164
165/**
166 * Client callback for hotlist_iterate, reporting a hotlist folder departure
167 *
168 * \param ctx Client context
169 * \param title The departed folder's title
170 * \return NSERROR_OK on success, or appropriate error otherwise
171 */
172typedef nserror (*hotlist_folder_leave_cb)(void *ctx);
173
174
175/**
176 * Walk (depth first) the hotlist, calling callbacks on entering folders,
177 * address nodes, and on leaving folders.
178 *
179 * \param ctx Client context, passed back to callback function
180 * \param enter_cb Function to call on entering nodes, or NULL
181 * \param address_cb Function to call on address nodes, or NULL
182 * \param leave_cb Function to call on leaving nodes, or NULL
183 * \return NSERROR_OK on success, or appropriate error otherwise
184 *
185 * Example usage: Generate a menu containing hotlist entries. For flat list
186 * set enter_cb and leave_cb to NULL, or for hierarchical menu
187 * provide the folder callbacks.
188 */
189nserror hotlist_iterate(void *ctx,
191 hotlist_address_cb address_cb,
192 hotlist_folder_leave_cb leave_cb);
193
194/**
195 * Redraw the hotlist.
196 *
197 * \param x X coordinate to render treeview at
198 * \param y Y coordinate to render treeview at
199 * \param clip Current clip rectangle (wrt tree origin)
200 * \param ctx Current redraw context
201 */
202void hotlist_redraw(int x, int y, struct rect *clip,
203 const struct redraw_context *ctx);
204
205/**
206 * Handles all kinds of mouse action
207 *
208 * \param mouse The current mouse state
209 * \param x X coordinate
210 * \param y Y coordinate
211 */
212void hotlist_mouse_action(enum browser_mouse_state mouse, int x, int y);
213
214/**
215 * Key press handling.
216 *
217 * \param key The ucs4 character codepoint
218 * \return true if the keypress is dealt with, false otherwise.
219 */
220bool hotlist_keypress(uint32_t key);
221
222/**
223 * Determine whether there is a selection
224 *
225 * \return true iff there is a selection
226 */
227bool hotlist_has_selection(void);
228
229/**
230 * Get the first selected node
231 *
232 * \param url Updated to the selected entry's address, or NULL
233 * \param title Updated to the selected entry's title, or NULL
234 * \return true iff hotlist has a selection
235 */
236bool hotlist_get_selection(struct nsurl **url, const char **title);
237
238/**
239 * Edit the first selected node
240 */
241void hotlist_edit_selection(void);
242
243/**
244 * Expand the treeview's nodes
245 *
246 * \param only_folders Iff true, only folders are expanded.
247 * \return NSERROR_OK on success, appropriate error otherwise
248 */
249nserror hotlist_expand(bool only_folders);
250
251/**
252 * Contract the treeview's nodes
253 *
254 * \param all Iff false, only entries are contracted.
255 * \return NSERROR_OK on success, appropriate error otherwise
256 */
257nserror hotlist_contract(bool all);
258
259#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:1623
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1697
bool hotlist_has_selection(void)
Determine whether there is a selection.
Definition: hotlist.c:1704
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1387
bool hotlist_get_selection(struct nsurl **url, const char **title)
Get the first selected node.
Definition: hotlist.c:1711
nserror hotlist_manager_init(void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
void hotlist_update_url(struct nsurl *url)
Update given URL, e.g.
Definition: hotlist.c:1602
nserror hotlist_manager_fini(void)
Finalise the hotlist manager.
Definition: hotlist.c:1372
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1682
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:1535
nserror hotlist_add_folder(const char *title, bool at_y, int y)
Add a folder to the hotlist.
Definition: hotlist.c:1660
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:1740
nserror(* hotlist_address_cb)(void *ctx, struct nsurl *url, const char *title)
Client callback for hotlist_iterate, reporting a hotlist address.
Definition: hotlist.h:163
nserror(* hotlist_folder_leave_cb)(void *ctx)
Client callback for hotlist_iterate, reporting a hotlist folder departure.
Definition: hotlist.h:172
void hotlist_edit_selection(void)
Edit the first selected node.
Definition: hotlist.c:1733
nserror(* hotlist_folder_enter_cb)(void *ctx, const char *title)
Client callback for hotlist_iterate, reporting entry into folder.
Definition: hotlist.h:153
bool hotlist_has_url(struct nsurl *url)
Check whether given URL is present in hotlist.
Definition: hotlist.c:1493
nserror hotlist_contract(bool all)
Contract the treeview's nodes.
Definition: hotlist.c:1747
nserror hotlist_add_url(struct nsurl *url)
Add an entry to the hotlist for given URL.
Definition: hotlist.c:1430
void hotlist_mouse_action(enum browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1690
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
Core mouse and pointer states.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
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