summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2018-04-22 13:10:16 +0100
committerVincent Sanders <vince@kyllikki.org>2018-04-22 14:03:18 +0100
commitd196ea7795ada760dbc243fe640769eb9bc65dff (patch)
treef091b6f7222a06b07d60df3d474cd996e10efe8b
parentb94b96e272140f17a82ce0847e1634d081b5dc6c (diff)
downloadnetsurf-d196ea7795ada760dbc243fe640769eb9bc65dff.tar.gz
netsurf-d196ea7795ada760dbc243fe640769eb9bc65dff.tar.bz2
fix gtk accelerator loading
-rw-r--r--frontends/gtk/accelerator.c39
-rw-r--r--frontends/gtk/fetch.c3
2 files changed, 31 insertions, 11 deletions
diff --git a/frontends/gtk/accelerator.c b/frontends/gtk/accelerator.c
index 9339de8a8..11b7fb1d0 100644
--- a/frontends/gtk/accelerator.c
+++ b/frontends/gtk/accelerator.c
@@ -25,36 +25,55 @@
#include <stdint.h>
#include <gtk/gtk.h>
+#include "utils/log.h"
#include "utils/errors.h"
#include "utils/hashtable.h"
#include "gtk/resources.h"
#include "gtk/accelerator.h"
+/** acclelerators are stored in a fixed-size hash table. */
+#define HASH_SIZE 53
+
/** The hash table used to store the accelerators */
static struct hash_table *accelerators_hash = NULL;
nserror nsgtk_accelerator_init(char **respaths)
{
- nserror ret;
+ nserror res;
const uint8_t *data;
size_t data_size;
- ret = nsgtk_data_from_resname("accelerators", &data, &data_size);
- if (ret == NSERROR_OK) {
- //ret = hashtable_add_from_inline(data, data_size);
+ if (accelerators_hash == NULL) {
+ accelerators_hash = hash_create(HASH_SIZE);
+ }
+ if (accelerators_hash == NULL) {
+ NSLOG(netsurf, INFO, "Unable to create hash table");
+ return NSERROR_NOMEM;
+ }
+
+ res = nsgtk_data_from_resname("accelerators", &data, &data_size);
+ if (res == NSERROR_OK) {
+ res = hash_add_inline(accelerators_hash, data, data_size);
} else {
- const char *accelerators;
+ const char *accelerators_path;
/* Obtain path to accelerators */
- ret = nsgtk_path_from_resname("accelerators", &accelerators);
- if (ret == NSERROR_OK) {
- //ret = hashtable_add_from_file(messages);
+ res = nsgtk_path_from_resname("accelerators",
+ &accelerators_path);
+ if (res == NSERROR_OK) {
+ res = hash_add_file(accelerators_hash,
+ accelerators_path);
}
}
- return ret;
+
+ return res;
}
const char *nsgtk_accelerator_get_desc(const char *key)
{
- return NULL;
+ if ((key == NULL) ||
+ (accelerators_hash == NULL)) {
+ return NULL;
+ }
+ return hash_get(accelerators_hash, key);
}
diff --git a/frontends/gtk/fetch.c b/frontends/gtk/fetch.c
index 7286aec34..b05c1bd95 100644
--- a/frontends/gtk/fetch.c
+++ b/frontends/gtk/fetch.c
@@ -30,6 +30,7 @@
* ASCII hence not using locale dependant ctype functions for parsing.
*/
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -39,8 +40,8 @@
#include <strings.h>
#include <gtk/gtk.h>
-#include "utils/hashtable.h"
#include "utils/log.h"
+#include "utils/hashtable.h"
#include "utils/filepath.h"
#include "utils/file.h"
#include "utils/nsurl.h"