NetSurf
con_search.c
Go to the documentation of this file.
1/*
2 * Copyright 2025 Vincent Sanders <vince@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#include <stdbool.h>
20#include <sys/types.h>
21
22#include "utils/nsoption.h"
23#include "utils/log.h"
24#include "utils/messages.h"
25
26#include "desktop/searchweb.h"
27
28#include "riscos/gui.h"
29#include "riscos/menus.h"
30#include "riscos/wimp.h"
31#include "riscos/wimp_event.h"
32#include "riscos/configure.h"
34#include "riscos/dialog.h"
35
36
37#define SEARCH_WEB_URLBAR 2
38#define SEARCH_WEB_PROVIDER_FIELD 4
39#define SEARCH_WEB_PROVIDER_GRIGHT 5
40#define SEARCH_DEFAULT_BUTTON 6
41#define SEARCH_CANCEL_BUTTON 7
42#define SEARCH_OK_BUTTON 8
43
44
45static void ro_gui_options_search_default(wimp_pointer *pointer)
46{
47 const char *defprovider;
48 search_web_iterate_providers(-1, &defprovider);
49 if (defprovider == NULL) {
50 defprovider = "DuckDuckGo";
51 }
52
54 nsoption_bool(search_url_bar));
55
57 defprovider, true);
58}
59
60
61static bool ro_gui_options_search_ok(wimp_w w)
62{
63 char *provider;
64 const char* defprovider;
65
66 nsoption_set_bool(search_url_bar,
68
70 if (provider) {
71 /* set search provider */
73
74 /* set to default option if the default provider is selected */
75 if ((search_web_iterate_providers(-1, &defprovider) != -1) &&
76 (strcmp(provider, defprovider) == 0)) {
77 free(provider);
78 /* use default option */
79 provider = NULL;
80 }
81
82 /* set the option which takes owership of the provider allocation */
83 nsoption_set_charp(search_web_provider, provider);
84
85 } else {
86 NSLOG(netsurf, INFO, "No memory to duplicate search code");
87 ro_warn_user("NoMemory", 0);
88 }
89
91 return true;
92}
93
94
96{
97 const char* defprovider;
98
99 /* set the current values */
101 nsoption_bool(search_url_bar));
102
103 search_web_iterate_providers(-1, &defprovider);
104 if (defprovider == NULL) {
105 defprovider = "DuckDuckGo";
106 }
107
109 nsoption_charp(search_web_provider) ?
110 nsoption_charp(search_web_provider) :
111 defprovider, true);
112
113 /* initialise all functions for a newly created window */
122 ro_gui_wimp_event_set_help_prefix(w, "HelpSearchConfig");
124 return true;
125
126}
#define SEARCH_WEB_URLBAR
Definition: con_search.c:37
bool ro_gui_options_search_initialise(wimp_w w)
Definition: con_search.c:95
static bool ro_gui_options_search_ok(wimp_w w)
Definition: con_search.c:61
static void ro_gui_options_search_default(wimp_pointer *pointer)
Definition: con_search.c:45
#define SEARCH_WEB_PROVIDER_GRIGHT
Definition: con_search.c:39
#define SEARCH_DEFAULT_BUTTON
Definition: con_search.c:40
#define SEARCH_CANCEL_BUTTON
Definition: con_search.c:41
#define SEARCH_WEB_PROVIDER_FIELD
Definition: con_search.c:38
#define SEARCH_OK_BUTTON
Definition: con_search.c:42
Automated RISC OS WIMP event handling (interface).
RISC OS option setting (interface).
nserror search_web_select_provider(const char *selection)
Change the currently selected web search provider.
Definition: searchweb.c:403
ssize_t search_web_iterate_providers(ssize_t iter, const char **name)
Iterate the search providers, returning their names.
Definition: searchweb.c:512
void ro_gui_save_options(void)
Save the current options.
Definition: dialog.c:670
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
wimp_menu * search_provider_menu
Definition: menus.c:105
Localised message support (interface).
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2082
core web search facilities interface.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Definition: nsoption.h:372
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
Definition: wimp.c:269
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
Definition: wimp.c:235
void ro_gui_set_icon_selected_state(wimp_w w, wimp_i i, bool state)
Set the selected state of an icon.
Definition: wimp.c:444
bool ro_gui_get_icon_selected_state(wimp_w w, wimp_i i)
Gets the selected state of an icon.
Definition: wimp.c:463
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_set_help_prefix(wimp_w w, const char *help_prefix)
Set the associated help prefix for a given window.
Definition: wimp_event.c:390
bool ro_gui_wimp_event_register_menu_gright(wimp_w w, wimp_i i, wimp_i gright, wimp_menu *menu)
Register an icon menu to be automatically handled.
Definition: wimp_event.c:1331
bool ro_gui_wimp_event_register_cancel(wimp_w w, wimp_i i)
Register a function to be called for the Cancel action on a window.
Definition: wimp_event.c:1403
bool ro_gui_wimp_event_memorise(wimp_w w)
Memorises the current state of any registered components in a window.
Definition: wimp_event.c:139
bool ro_gui_wimp_event_register_checkbox(wimp_w w, wimp_i i)
Register a checkbox to be automatically handled.
Definition: wimp_event.c:1349
bool ro_gui_wimp_event_register_ok(wimp_w w, wimp_i i, bool(*callback)(wimp_w w))
Register a function to be called for the OK action on a window.
Definition: wimp_event.c:1417
bool ro_gui_wimp_event_register_button(wimp_w w, wimp_i i, void(*callback)(wimp_pointer *pointer))
Register a function to be called when a particular button is pressed.
Definition: wimp_event.c:1387
Automated RISC OS WIMP event handling (interface).