summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-05-20 15:23:05 +0100
committerVincent Sanders <vince@kyllikki.org>2016-05-21 12:17:49 +0100
commit5061687867ee9ae90b23469d7d6ac7f4c9c8424c (patch)
tree9d0a92f4bd65cd53a985b052cff4d751abc5ac11
parenta47a6dd52e92e75ebf11e125563fb953dd1cab8b (diff)
downloadnetsurf-5061687867ee9ae90b23469d7d6ac7f4c9c8424c.tar.gz
netsurf-5061687867ee9ae90b23469d7d6ac7f4c9c8424c.tar.bz2
store toolbar config in standard options instead of a separate file
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rw-r--r--frontends/gtk/Makefile2
-rw-r--r--frontends/gtk/gui.c10
-rw-r--r--frontends/gtk/gui.h3
-rw-r--r--frontends/gtk/options.h3
-rw-r--r--frontends/gtk/toolbar.c153
-rw-r--r--utils/nsoption.c8
8 files changed, 103 insertions, 80 deletions
diff --git a/.gitignore b/.gitignore
index 89ecd0d0c..3b674ffe3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,6 @@
\!NetSurf/Resources/nl/Messages
\!NetSurf/Resources/it/Messages
frontends/windows/res/preferences
-frontends/gtk/res/toolbarIndices
frontends/gtk/res/en/Messages
frontends/gtk/res/fr/Messages
frontends/gtk/res/de/Messages
diff --git a/Makefile b/Makefile
index c8cf35e45..4af0a0391 100644
--- a/Makefile
+++ b/Makefile
@@ -672,9 +672,6 @@ endif
ifeq ($(TARGET),windows)
$(Q)$(TOUCH) frontends/windows/res/preferences
endif
-ifeq ($(TARGET),gtk)
- $(Q)$(TOUCH) frontends/gtk/res/toolbarIndices
-endif
ifeq ($(NETSURF_STRIP_BINARY),YES)
$(VQ)echo " STRIP: $(EXETARGET)"
$(Q)$(STRIP) $(EXETARGET)
diff --git a/frontends/gtk/Makefile b/frontends/gtk/Makefile
index 7f8ffc16a..aae1d4465 100644
--- a/frontends/gtk/Makefile
+++ b/frontends/gtk/Makefile
@@ -175,7 +175,7 @@ SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RESOURCE) $(S_FRONTEND)
# ----------------------------------------------------------------------------
GTK_RESOURCES_LIST := \
- languages SearchEngines toolbarIndices ca-bundle.txt \
+ languages SearchEngines ca-bundle.txt \
default.css adblock.css quirks.css internal.css \
credits.html licence.html welcome.html maps.html Messages \
default.ico favicon.png netsurf.png netsurf.xpm netsurf-16x16.xpm \
diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c
index e705918bc..60c8e792a 100644
--- a/frontends/gtk/gui.c
+++ b/frontends/gtk/gui.c
@@ -74,8 +74,6 @@
bool nsgtk_complete = false;
-char *toolbar_indices_file_location;
-
char *nsgtk_config_home; /* exported global defined in gtk/gui.h */
GdkPixbuf *favicon_pixbuf; /** favicon default pixbuf */
@@ -276,12 +274,6 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
false, 8, 8, 32);
}
- /* Toolbar inicies file */
- toolbar_indices_file_location = filepath_find(respath,
- "toolbarIndices");
- LOG("Using '%s' as custom toolbar settings file",
- toolbar_indices_file_location);
-
/* initialise throbber */
error = nsgtk_throbber_init();
if (error != NSERROR_OK) {
@@ -457,8 +449,6 @@ static void gui_quit(void)
nsgtk_history_destroy();
nsgtk_hotlist_destroy();
- free(toolbar_indices_file_location);
-
free(nsgtk_config_home);
gtk_fetch_filetype_fin();
diff --git a/frontends/gtk/gui.h b/frontends/gtk/gui.h
index b6a6dc994..53e732437 100644
--- a/frontends/gtk/gui.h
+++ b/frontends/gtk/gui.h
@@ -21,9 +21,6 @@
struct nsurl;
-/** toolbar arrangement file path. */
-extern char *toolbar_indices_file_location;
-
/** Directory where all configuration files are held. */
extern char *nsgtk_config_home;
diff --git a/frontends/gtk/options.h b/frontends/gtk/options.h
index ac642c153..018a448be 100644
--- a/frontends/gtk/options.h
+++ b/frontends/gtk/options.h
@@ -70,3 +70,6 @@ NSOPTION_INTEGER(developer_view, 0)
/* where tabs are positioned */
NSOPTION_INTEGER(position_tab, 0)
+
+/* Toolbar customisation */
+NSOPTION_STRING(toolbar_order, NULL)
diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c
index 208b5c0b9..1def9dcaa 100644
--- a/frontends/gtk/toolbar.c
+++ b/frontends/gtk/toolbar.c
@@ -26,10 +26,10 @@
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
+#include "utils/nsoption.h"
#include "gtk/gui.h"
#include "gtk/warn.h"
-#include "gtk/scaffolding.h"
#include "gtk/search.h"
#include "gtk/throbber.h"
#include "gtk/window.h"
@@ -833,22 +833,6 @@ static bool nsgtk_toolbar_add_store_widget(GtkWidget *widget)
return true;
}
-/**
- * save toolbar settings to file
- */
-static void nsgtk_toolbar_customization_save(struct nsgtk_scaffolding *g)
-{
- int i;
- FILE *f = fopen(toolbar_indices_file_location, "w");
- if (f == NULL){
- nsgtk_warning("gtkFileError", toolbar_indices_file_location);
- return;
- }
- for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
- fprintf(f, "%d;%d|", i, nsgtk_scaffolding_button(g, i)->location);
- }
- fclose(f);
-}
/**
* cast toolbar settings to all scaffoldings referenced from the global linked
@@ -878,6 +862,93 @@ static void nsgtk_toolbar_cast(struct nsgtk_scaffolding *g)
}
}
+
+/**
+ * load toolbar settings from file; file is a set of fields arranged as
+ * [itemreference];[itemlocation]|[itemreference];[itemlocation]| etc
+ */
+void nsgtk_toolbar_customization_load(struct nsgtk_scaffolding *g)
+{
+ int i, ii;
+ char *buffer;
+ char *buffer1, *subbuffer, *ptr = NULL, *pter = NULL;
+
+ /* default toolbar button order */
+ for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
+ nsgtk_scaffolding_button(g, i)->location =
+ (i <= THROBBER_ITEM) ? i : -1;
+ }
+
+ /* ensure the option is actually set */
+ if (nsoption_charp(toolbar_order) == NULL) {
+ return;
+ }
+ buffer = strdup(nsoption_charp(toolbar_order));
+
+ i = BACK_BUTTON;
+ ii = BACK_BUTTON;
+ buffer1 = strtok_r(buffer, "|", &ptr);
+ while (buffer1 != NULL) {
+ subbuffer = strtok_r(buffer1, ";", &pter);
+ if (subbuffer != NULL) {
+ i = atoi(subbuffer);
+ subbuffer = strtok_r(NULL, ";", &pter);
+ if (subbuffer != NULL) {
+ ii = atoi(subbuffer);
+ if ((i >= BACK_BUTTON) &&
+ (i < PLACEHOLDER_BUTTON) &&
+ (ii >= -1) &&
+ (ii < PLACEHOLDER_BUTTON)) {
+ nsgtk_scaffolding_button(g, i)->location = ii;
+ }
+ }
+ }
+ buffer1 = strtok_r(NULL, "|", &ptr);
+ }
+
+ free(buffer);
+}
+
+
+/**
+ * save toolbar settings to file
+ */
+static nserror nsgtk_toolbar_customization_save(struct nsgtk_scaffolding *g)
+{
+ char *order;
+ int order_len = PLACEHOLDER_BUTTON * 12; /* length of order buffer */
+ int tbidx;
+ char *cur;
+ int plen;
+
+ order = malloc(order_len);
+
+ if (order == NULL) {
+ return NSERROR_NOMEM;
+ }
+ cur = order;
+
+ for (tbidx = BACK_BUTTON; tbidx < PLACEHOLDER_BUTTON; tbidx++) {
+ plen = snprintf(cur,
+ order_len,
+ "%d;%d|",
+ tbidx,
+ nsgtk_scaffolding_button(g, tbidx)->location);
+ if (plen == order_len) {
+ /* ran out of space, bail early */
+ LOG("toolbar ordering exceeded available space");
+ break;
+ }
+ cur += plen;
+ order_len -= plen;
+ }
+
+ nsoption_set_charp(toolbar_order, order);
+
+ return NSERROR_OK;
+}
+
+
/**
* when 'save settings' button is clicked
*/
@@ -1187,8 +1258,9 @@ void nsgtk_toolbar_customization_init(struct nsgtk_scaffolding *g)
void nsgtk_toolbar_set_physical(struct nsgtk_scaffolding *g)
{
int i;
- struct nsgtk_theme *theme =
- nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR);
+ struct nsgtk_theme *theme;
+
+ theme = nsgtk_theme_load(GTK_ICON_SIZE_LARGE_TOOLBAR);
if (theme == NULL) {
nsgtk_warning(messages_get("NoMemory"), 0);
return;
@@ -1196,8 +1268,9 @@ void nsgtk_toolbar_set_physical(struct nsgtk_scaffolding *g)
/* simplest is to clear the toolbar then reload it from memory */
gtk_container_foreach(GTK_CONTAINER(nsgtk_scaffolding_toolbar(g)),
nsgtk_toolbar_clear_toolbar, g);
- for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++)
+ for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
nsgtk_toolbar_add_item_to_toolbar(g, i, theme);
+ }
gtk_widget_show_all(GTK_WIDGET(nsgtk_scaffolding_toolbar(g)));
free(theme);
}
@@ -1374,43 +1447,3 @@ DATAHANDLER(websearch, WEBSEARCH, window)
#undef DATAHANDLER
-/**
- * load toolbar settings from file; file is a set of fields arranged as
- * [itemreference];[itemlocation]|[itemreference];[itemlocation]| etc
- */
-void nsgtk_toolbar_customization_load(struct nsgtk_scaffolding *g)
-{
- int i, ii;
- char *val;
- char buffer[SLEN("11;|") * 2 * PLACEHOLDER_BUTTON]; /* numbers 0-99 */
- buffer[0] = '\0';
- char *buffer1, *subbuffer, *ptr = NULL, *pter = NULL;
- for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++)
- nsgtk_scaffolding_button(g, i)->location =
- (i <= THROBBER_ITEM) ? i : -1;
- FILE *f = fopen(toolbar_indices_file_location, "r");
- if (f == NULL) {
- nsgtk_warning(messages_get("gtkFileError"),
- toolbar_indices_file_location);
- return;
- }
- val = fgets(buffer, sizeof buffer, f);
- if (val == NULL) {
- LOG("empty read toolbar settings");
- }
- fclose(f);
- i = BACK_BUTTON;
- ii = BACK_BUTTON;
- buffer1 = strtok_r(buffer, "|", &ptr);
- while (buffer1 != NULL) {
- subbuffer = strtok_r(buffer1, ";", &pter);
- i = atoi(subbuffer);
- subbuffer = strtok_r(NULL, ";", &pter);
- ii = atoi(subbuffer);
- if ((i >= BACK_BUTTON) && (i < PLACEHOLDER_BUTTON) &&
- (ii >= -1) && (ii < PLACEHOLDER_BUTTON)) {
- nsgtk_scaffolding_button(g, i)->location = ii;
- }
- buffer1 = strtok_r(NULL, "|", &ptr);
- }
-}
diff --git a/utils/nsoption.c b/utils/nsoption.c
index 387d7c704..7e7766622 100644
--- a/utils/nsoption.c
+++ b/utils/nsoption.c
@@ -38,6 +38,9 @@
#include "utils/utils.h"
#include "utils/nsoption.h"
+/** Length of buffer used to read lines from input file */
+#define NSOPTION_MAX_LINE_LEN 1024
+
struct nsoption_s *nsoptions = NULL;
struct nsoption_s *nsoptions_default = NULL;
@@ -597,11 +600,12 @@ nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
return NSERROR_OK;
}
+
/* exported interface documented in utils/nsoption.h */
nserror
nsoption_read(const char *path, struct nsoption_s *opts)
{
- char s[100];
+ char s[NSOPTION_MAX_LINE_LEN];
FILE *fp;
struct nsoption_s *defs;
@@ -625,7 +629,7 @@ nsoption_read(const char *path, struct nsoption_s *opts)
LOG("Successfully opened '%s' for Options file", path);
- while (fgets(s, 100, fp)) {
+ while (fgets(s, NSOPTION_MAX_LINE_LEN, fp)) {
char *colon, *value;
unsigned int idx;