Wed, 27 Nov 2024 17:14:57 +0100
move app settings to separate source file
--- a/application/Makefile Wed Nov 27 16:48:59 2024 +0100 +++ b/application/Makefile Wed Nov 27 17:14:57 2024 +0100 @@ -40,6 +40,7 @@ SRC += system.c SRC += window.c SRC += settings.c +SRC += appsettings.c OBJ = $(SRC:%.c=../build/application/%.$(OBJ_EXT))
--- a/application/application.c Wed Nov 27 16:48:59 2024 +0100 +++ b/application/application.c Wed Nov 27 17:14:57 2024 +0100 @@ -37,6 +37,7 @@ #include "config.h" #include "davcontroller.h" #include "settings.h" +#include "appsettings.h" static DavContext* davctx; @@ -59,6 +60,7 @@ exit(-1); } + appsettings_init(); window_init(); // create document for global settings (repolist, ...)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/application/appsettings.c Wed Nov 27 17:14:57 2024 +0100 @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "appsettings.h" + + +const char *flags_crypto_on = "c"; // alternative: U+1F511 +const char *flags_crypto_off = ""; +const char *flags_locked = "L"; // alternative: U+1F512 +const char *flags_unlocked = ""; +const char *flags_exec_on = ""; // alternative: U+2699 +const char *flags_exec_off = ""; + + +void appsettings_init(void) { + // browser resource flags (crypto,lock,exec) + flags_crypto_on = ui_set_default_property("idav.ui.flags.encrypted", flags_crypto_on); + flags_crypto_off = ui_set_default_property("idav.ui.flags.unencrypted", flags_crypto_off); + flags_locked = ui_set_default_property("idav.ui.flags.locked", flags_locked); + flags_unlocked = ui_set_default_property("idav.ui.flags.unlocked", flags_unlocked); + flags_exec_on = ui_set_default_property("idav.ui.flags.executable", flags_exec_on); + flags_exec_off = ui_set_default_property("idav.ui.flags.noexec", flags_exec_off); +} + + +const char* appsettings_get_cryptoflag(UiBool encrypted) { + return encrypted ? flags_crypto_on : flags_crypto_off; +} + +const char* appsettings_get_lockflag(UiBool locked) { + return locked ? flags_locked : flags_unlocked; +} + +const char* appsettings_get_execflag(UiBool executable) { + return executable ? flags_exec_on : flags_exec_off; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/application/appsettings.h Wed Nov 27 17:14:57 2024 +0100 @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APPSETTINGS_H +#define APPSETTINGS_H + +#include "application.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void appsettings_init(void); + +const char* appsettings_get_cryptoflag(UiBool encrypted); +const char* appsettings_get_lockflag(UiBool locked); +const char* appsettings_get_execflag(UiBool executable); + + +#ifdef __cplusplus +} +#endif + +#endif /* APPSETTINGS_H */ +
--- a/application/settings.c Wed Nov 27 16:48:59 2024 +0100 +++ b/application/settings.c Wed Nov 27 17:14:57 2024 +0100 @@ -1382,17 +1382,3 @@ ui_set(settings->key_file, ""); } - - - -const char* settings_get_cryptoflag(UiBool encrypted) { - return encrypted ? "c" : ""; -} - -const char* settings_get_lockflag(UiBool locked) { - return locked ? "L" : ""; -} - -const char* settings_get_execflag(UiBool executable) { - return ""; // executable flag disabled -}
--- a/application/settings.h Wed Nov 27 16:48:59 2024 +0100 +++ b/application/settings.h Wed Nov 27 17:14:57 2024 +0100 @@ -211,9 +211,7 @@ -const char* settings_get_cryptoflag(UiBool encrypted); -const char* settings_get_lockflag(UiBool locked); -const char* settings_get_execflag(UiBool executable); + #ifdef __cplusplus
--- a/application/window.c Wed Nov 27 16:48:59 2024 +0100 +++ b/application/window.c Wed Nov 27 17:14:57 2024 +0100 @@ -29,7 +29,7 @@ #include "window.h" #include "davcontroller.h" -#include "settings.h" +#include "appsettings.h" #include <ui/stock.h> #include <ui/dnd.h> @@ -136,9 +136,9 @@ "http://apache.org/dav/props/", "executable"); cxmutstr flags = cx_asprintf("%s%s%s", - settings_get_cryptoflag(keyprop ? 1 : 0), - settings_get_lockflag(lockdiscovery ? 1 : 0), - settings_get_execflag(executable ? 1 : 0)); + appsettings_get_cryptoflag(keyprop ? 1 : 0), + appsettings_get_lockflag(lockdiscovery ? 1 : 0), + appsettings_get_execflag(executable ? 1 : 0)); return flags.ptr; } case 3: { // type
--- a/ui/common/properties.c Wed Nov 27 16:48:59 2024 +0100 +++ b/ui/common/properties.c Wed Nov 27 17:14:57 2024 +0100 @@ -162,43 +162,52 @@ free(path); } -void uic_store_app_properties() { +int uic_store_app_properties() { char *path = ui_configfile("application.properties"); if(!path) { - return; + return 1; } FILE *file = fopen(path, "w"); if(!file) { fprintf(stderr, "Ui Error: Cannot open properties file: %s\n", path); free(path); - return; + return 1; } + int ret = 0; if(ucx_properties_store(application_properties, file)) { fprintf(stderr, "Ui Error: Cannot store application properties.\n"); + ret = 1; } fclose(file); free(path); + + return ret; } -char* ui_get_property(char *name) { +const char* ui_get_property(const char *name) { return cxMapGet(application_properties, name); } -void ui_set_property(char *name, char *value) { - cxMapPut(application_properties, name, value); +void ui_set_property(const char *name, const char *value) { + cxMapPut(application_properties, name, (char*)value); } -void ui_set_default_property(char *name, char *value) { - char *v = cxMapGet(application_properties, name); +const char* ui_set_default_property(const char *name, const char *value) { + const char *v = cxMapGet(application_properties, name); if(!v) { - cxMapPut(application_properties, name, value); + cxMapPut(application_properties, name, (char*)value); + v = value; } + return v; } +int ui_properties_store(void) { + return uic_store_app_properties(); +} static char* uic_concat_path(const char *base, const char *p, const char *ext) {
--- a/ui/common/properties.h Wed Nov 27 16:48:59 2024 +0100 +++ b/ui/common/properties.h Wed Nov 27 17:14:57 2024 +0100 @@ -44,7 +44,7 @@ #endif void uic_load_app_properties(); -void uic_store_app_properties(); +int uic_store_app_properties(); int uic_load_language_file(const char *path); char* uic_get_image_path(const char *imgfilename);
--- a/ui/ui/properties.h Wed Nov 27 16:48:59 2024 +0100 +++ b/ui/ui/properties.h Wed Nov 27 17:14:57 2024 +0100 @@ -35,10 +35,11 @@ extern "C" { #endif -char* ui_get_property(char *name); -void ui_set_property(char *name, char *value); +const char* ui_get_property(const char *name); +void ui_set_property(const char *name, const char *value); +const char* ui_set_default_property(const char *name, const char *value); -void ui_set_default_property(char *name, char *value); +int ui_properties_store(void); void ui_locales_dir(char *path); void ui_pixmaps_dir(char *path);