summaryrefslogtreecommitdiff
path: root/desktop/searchweb.h
blob: 69748b6d6d85d971189a2ab0e102ac10becf5dac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * \file desktop/searchweb.h
 * \brief core web search facilities interface.
 */

#ifndef _NETSURF_DESKTOP_SEARCH_WEB_H_
#define _NETSURF_DESKTOP_SEARCH_WEB_H_

struct bitmap;
struct nsurl;

/**
 * Graphical user interface browser web search function table.
 *
 */
struct gui_search_web_table {
	/**
	 * called when the search provider details are updated.
	 *
	 * \param provider_name The name of the provider.
	 * \param ico_bitmap The bitmap of the search icon may be NULL
	 * if no icon is yet available.
	 */
	nserror (*provider_update)(const char *provider_name, struct bitmap *ico_bitmap);
};

/**
 * Flags which alter the behaviour of the omin search.
 */
enum search_web_omni_flags {
	/** no changes to default operation */
	SEARCH_WEB_OMNI_NONE = 0,

	/** The search does not attempt to interpret the url as a url
	 * before using it as a search term.
	 */
	SEARCH_WEB_OMNI_SEARCHONLY = 1,
};

/**
 * Generate a nsurl from a search term.
 *
 * This interface obtains a url appropriate for the given search
 * term. The flags allow control over the operation. By default the
 * operations are:
 *  - interpret the \a term as a url
 *  - if missing a scheme as a http: url
 *  - combined with the search providers url into a url for that provider.
 *
 * \param term The search term.
 * \param flags Flags to control operation.
 * \param url_out The ourput url on success.
 * \return NSERROR_OK on success or appropriate error code.
 */
nserror search_web_omni(const char *term, enum search_web_omni_flags flags, struct nsurl **url_out);


/**
 * obtain the current providers bitmap
 *
 * obtain the icon representing the current web search provider
 *
 * \param bitmap_out recives the resulting bitmap which may be NULL
 * \return NSERROR_OK on success or NSERROR_INIT_FAILED if not initialised
 */
nserror search_web_get_provider_bitmap(struct bitmap **bitmap_out);

/**
 * Change the currently selected web search provider.
 *
 * \param selection Index of the search provider to select or -1 to
 *                  reselect the current provider
 * \return NSERROR_OK on success or appropriate error code.
 */
nserror search_web_select_provider(int selection);


/**
 * Iterate the search providers, returning their names.
 *
 * \param from Index to start iteration from.  Use 0 to begin iteration.
 *             Use the value returned from search_web_iterate_providers to
 *             continue an iteration.
 * \param name Pointer to fill in with the search provider name requested.
 * \return -1 if there are no more, otherwise the iterator for the next item.
 *
 * \verbatim
 *     ssize_t iter;
 *     const char *name;
 *     ...
 *     for (iter = search_web_iterate_providers(0, &name);
 *          iter != -1;
 *          iter = search_web_iterate_providers(iter, &name)) {
 *         do_something_with(name);
 *     }
 * \endverbatim
 */
ssize_t search_web_iterate_providers(ssize_t from, const char **name);


/**
 * Initialise the web search operations.
 *
 * \param provider_fname Path to web search providers file.
 * \return NSERROR_OK on successful initialisation or appropriate error code.
 */
nserror search_web_init(const char *provider_fname);

/**
 * Finalise the web search operations freeing all resources.
 *
 * \return NSERROR_OK on success or appropriate error code.
 */
nserror search_web_finalise(void);

#endif