NetSurf
accelerator.c
Go to the documentation of this file.
1/*
2 * Copyright 2018 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/**
20 * \file
21 * GTK accelerator support
22 *
23 */
24
25#include <stdint.h>
26#include <gtk/gtk.h>
27
28#include "utils/log.h"
29#include "utils/errors.h"
30#include "utils/hashtable.h"
31
32#include "gtk/resources.h"
33#include "gtk/accelerator.h"
34
35/** acclelerators are stored in a fixed-size hash table. */
36#define HASH_SIZE 53
37
38/** The hash table used to store the accelerators */
39static struct hash_table *accelerators_hash = NULL;
40
42{
43 nserror res;
44 const uint8_t *data;
45 size_t data_size;
46
47 if (accelerators_hash == NULL) {
49 }
50 if (accelerators_hash == NULL) {
51 NSLOG(netsurf, INFO, "Unable to create hash table");
52 return NSERROR_NOMEM;
53 }
54
55 res = nsgtk_data_from_resname("accelerators", &data, &data_size);
56 if (res == NSERROR_OK) {
57 res = hash_add_inline(accelerators_hash, data, data_size);
58 } else {
59 const char *accelerators_path;
60 /* Obtain path to accelerators */
61 res = nsgtk_path_from_resname("accelerators",
62 &accelerators_path);
63 if (res == NSERROR_OK) {
65 accelerators_path);
66 }
67 }
68
69 return res;
70}
71
72const char *nsgtk_accelerator_get_desc(const char *key)
73{
74 if ((key == NULL) ||
75 (accelerators_hash == NULL)) {
76 return NULL;
77 }
78 return hash_get(accelerators_hash, key);
79}
nserror nsgtk_accelerator_init(char **respaths)
Definition: accelerator.c:41
const char * nsgtk_accelerator_get_desc(const char *key)
Definition: accelerator.c:72
static struct hash_table * accelerators_hash
The hash table used to store the accelerators.
Definition: accelerator.c:39
#define HASH_SIZE
acclelerators are stored in a fixed-size hash table.
Definition: accelerator.c:36
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
char ** respaths
resource search path vector
Definition: findfile.c:28
struct hash_table * hash_create(unsigned int chains)
Create a new hash table.
Definition: hashtable.c:254
nserror hash_add_inline(struct hash_table *ht, const uint8_t *data, size_t size)
Add key/value pairs to a hash table with data from a memory buffer.
Definition: hashtable.c:399
nserror hash_add_file(struct hash_table *ht, const char *path)
Add key/value pairs to a hash table with data from a file.
Definition: hashtable.c:363
const char * hash_get(struct hash_table *ht, const char *key)
Looks up a the value associated with with a key from a specific hash table.
Definition: hashtable.c:339
Interface to Write-Once hash table for string to string mapping.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out)
Get direct pointer to resource data.
Definition: resources.c:574
nserror nsgtk_path_from_resname(const char *resname, const char **path_out)
Get path to resource data.
Definition: resources.c:613
Interface to gtk builtin resource handling.