summaryrefslogtreecommitdiff
path: root/src/prefs.c
blob: 13a1dab7cf8415354f964b5c4e5ce2e2df0542c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Copyright 2020 Jaakko Keränen <jaakko.keranen@iki.fi>

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 OWNER 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 "prefs.h"

#include <the_Foundation/fileinfo.h>
#include <assert.h>

_Static_assert(offsetof(iPrefs, plainTextWrap) == offsetof(iPrefs, bools[plainTextWrap_PrefsBool]),
               "memory layout mismatch (needs struct packing?)");

void init_Prefs(iPrefs *d) {
    iForIndices(i, d->strings) {
        init_String(&d->strings[i]);
    }
    d->dialogTab         = 0;
    d->langFrom          = 3; /* fr */
    d->langTo            = 2; /* en */
    d->useSystemTheme    = iTrue;
    d->systemPreferredColorTheme[0] = d->systemPreferredColorTheme[1] = -1;
    d->theme             = dark_ColorTheme;
    d->accent            = cyan_ColorAccent;
    d->customFrame       = iFalse; /* needs some more work to be default */
    d->retainWindowSize  = iTrue;
    d->uiAnimations      = iTrue;
    d->uiScale           = 1.0f; /* default set elsewhere */
    d->zoomPercent       = 100;
    d->navbarActions[0]  = back_ToolbarAction;
    d->navbarActions[1]  = forward_ToolbarAction;
    d->navbarActions[2]  = sidebar_ToolbarAction;
    d->navbarActions[3]  = home_ToolbarAction;
#if defined (iPlatformAndroidMobile)
    /* Android has a system-wide back button so no need to have a duplicate. */
    d->toolbarActions[0] = closeTab_ToolbarAction;
#else
    d->toolbarActions[0] = back_ToolbarAction;
#endif
    d->toolbarActions[1] = forward_ToolbarAction;
    d->sideIcon          = iTrue;
    d->hideToolbarOnScroll = iTrue;
    d->blinkingCursor    = iTrue;
    d->pinSplit          = 1;
    d->time24h           = iTrue;
    d->returnKey         = default_ReturnKeyBehavior;
    d->hoverLink         = iFalse;
    d->smoothScrolling   = iTrue;
    d->smoothScrollSpeed[keyboard_ScrollType] = 13;
    d->smoothScrollSpeed[mouse_ScrollType]    = 13;
    d->loadImageInsteadOfScrolling = iFalse;
    d->collapsePreOnLoad      = iFalse;
    d->openArchiveIndexPages  = iTrue;
    d->addBookmarksToBottom   = iTrue;
    d->warnAboutMissingGlyphs = iTrue;
    d->decodeUserVisibleURLs  = iTrue;
    d->maxCacheSize      = 10;
    d->maxMemorySize     = 200;
    setCStr_String(&d->strings[uiFont_PrefsString], "default");
    setCStr_String(&d->strings[headingFont_PrefsString], "default");
    setCStr_String(&d->strings[bodyFont_PrefsString], "default");
    setCStr_String(&d->strings[monospaceFont_PrefsString], "iosevka");
    setCStr_String(&d->strings[monospaceDocumentFont_PrefsString], "iosevka-body");
    d->disabledFontPacks = new_StringSet();
    d->fontSmoothing     = iTrue;
    d->gemtextAnsiEscapes = allowFg_AnsiFlag;
    d->monospaceGemini   = iFalse;
    d->monospaceGopher   = iFalse;
    d->boldLinkVisited   = iFalse;
    d->boldLinkDark      = iTrue;
    d->boldLinkLight     = iTrue;
    d->lineWidth         = 38;
    d->lineSpacing       = 1.0f;
    d->bigFirstParagraph = iTrue;
    d->quoteIcon         = iTrue;
    d->centerShortDocs   = iTrue;
    d->plainTextWrap     = iTrue;
    d->imageStyle        = original_ImageStyle;
    d->docThemeDark      = colorfulDark_GmDocumentTheme;
    d->docThemeLight     = white_GmDocumentTheme;
    d->saturation        = 1.0f;
    setCStr_String(&d->strings[uiLanguage_PrefsString], "en");
    /* TODO: Add some platform-specific common locations? */
    if (fileExistsCStr_FileInfo("/etc/ssl/cert.pem")) { /* macOS */
        setCStr_String(&d->strings[caFile_PrefsString], "/etc/ssl/cert.pem");
    }
    if (fileExistsCStr_FileInfo("/etc/ssl/certs")) {
        setCStr_String(&d->strings[caPath_PrefsString], "/etc/ssl/certs");
    }
}

void deinit_Prefs(iPrefs *d) {
    iRelease(d->disabledFontPacks);
    iForIndices(i, d->strings) {
        deinit_String(&d->strings[i]);
    }
}