summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2022-02-15 17:49:17 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2022-02-15 17:49:17 +0200
commit64eaaaac57fc909a9c9d47302f17f0801b7f2965 (patch)
treedab57405c80dcf6de974effc91737e89ebf23019
parentd19691de189227ef1976cb8104cdc55830fdb347 (diff)
Working on site-specific settings dialog
-rw-r--r--src/gmdocument.c27
-rw-r--r--src/gmdocument.h4
-rw-r--r--src/gmutil.c14
-rw-r--r--src/gmutil.h1
-rw-r--r--src/sitespec.c13
-rw-r--r--src/sitespec.h1
-rw-r--r--src/ui/documentwidget.c12
-rw-r--r--src/ui/util.c43
-rw-r--r--src/ui/util.h15
9 files changed, 99 insertions, 31 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index a3e233f3..bc0cc073 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -1292,7 +1292,7 @@ static void updateIconBasedOnUrl_GmDocument_(iGmDocument *d) {
1292 } 1292 }
1293} 1293}
1294 1294
1295void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { 1295void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *paletteSeed, const iBlock *iconSeed) {
1296 const iPrefs * prefs = prefs_App(); 1296 const iPrefs * prefs = prefs_App();
1297 enum iGmDocumentTheme theme = currentTheme_(); 1297 enum iGmDocumentTheme theme = currentTheme_();
1298 static const iChar siteIcons[] = { 1298 static const iChar siteIcons[] = {
@@ -1303,6 +1303,16 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1303 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531, 1303 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531,
1304 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, 1304 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c,
1305 }; 1305 };
1306 if (!iconSeed) {
1307 iconSeed = paletteSeed;
1308 }
1309 if (iconSeed && !isEmpty_Block(iconSeed)) {
1310 const uint32_t seedHash = themeHash_(iconSeed);
1311 d->siteIcon = siteIcons[(seedHash >> 7) % iElemCount(siteIcons)];
1312 }
1313 else {
1314 d->siteIcon = 0;
1315 }
1306 /* Default colors. These are used on "about:" pages and local files, for example. */ { 1316 /* Default colors. These are used on "about:" pages and local files, for example. */ {
1307 /* Link colors are generally the same in all themes. */ 1317 /* Link colors are generally the same in all themes. */
1308 set_Color(tmBadLink_ColorId, get_Color(red_ColorId)); 1318 set_Color(tmBadLink_ColorId, get_Color(red_ColorId));
@@ -1504,13 +1514,11 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1504 } 1514 }
1505 } 1515 }
1506 } 1516 }
1507 if (seed && !isEmpty_Block(seed)) { 1517 if (paletteSeed && !isEmpty_Block(paletteSeed)) {
1508 d->themeSeed = themeHash_(seed); 1518 d->themeSeed = themeHash_(paletteSeed);
1509 d->siteIcon = siteIcons[(d->themeSeed >> 7) % iElemCount(siteIcons)];
1510 } 1519 }
1511 else { 1520 else {
1512 d->themeSeed = 0; 1521 d->themeSeed = 0;
1513 d->siteIcon = 0;
1514 } 1522 }
1515 /* Set up colors. */ 1523 /* Set up colors. */
1516 if (d->themeSeed) { 1524 if (d->themeSeed) {
@@ -1739,8 +1747,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1739 /* Derived colors. */ 1747 /* Derived colors. */
1740 setDerivedThemeColors_(theme); 1748 setDerivedThemeColors_(theme);
1741 /* Special exceptions. */ 1749 /* Special exceptions. */
1742 if (seed) { 1750 if (iconSeed) {
1743 if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { 1751 if (equal_CStr(cstr_Block(iconSeed), "gemini.circumlunar.space")) {
1744 d->siteIcon = 0x264a; /* gemini symbol */ 1752 d->siteIcon = 0x264a; /* gemini symbol */
1745 } 1753 }
1746 updateIconBasedOnUrl_GmDocument_(d); 1754 updateIconBasedOnUrl_GmDocument_(d);
@@ -1761,7 +1769,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1761void makePaletteGlobal_GmDocument(const iGmDocument *d) { 1769void makePaletteGlobal_GmDocument(const iGmDocument *d) {
1762 if (!d->isPaletteValid) { 1770 if (!d->isPaletteValid) {
1763 /* Recompute the palette since it's needed now. */ 1771 /* Recompute the palette since it's needed now. */
1764 setThemeSeed_GmDocument((iGmDocument *) d, urlThemeSeed_String(&d->url)); 1772 setThemeSeed_GmDocument(
1773 (iGmDocument *) d, urlPaletteSeed_String(&d->url), urlThemeSeed_String(&d->url));
1765 } 1774 }
1766 iAssert(d->isPaletteValid); 1775 iAssert(d->isPaletteValid);
1767 memcpy(get_Root()->tmPalette, d->palette, sizeof(d->palette)); 1776 memcpy(get_Root()->tmPalette, d->palette, sizeof(d->palette));
@@ -1938,7 +1947,7 @@ static void normalize_GmDocument(iGmDocument *d) {
1938void setUrl_GmDocument(iGmDocument *d, const iString *url) { 1947void setUrl_GmDocument(iGmDocument *d, const iString *url) {
1939 url = canonicalUrl_String(url); 1948 url = canonicalUrl_String(url);
1940 set_String(&d->url, url); 1949 set_String(&d->url, url);
1941 setThemeSeed_GmDocument(d, urlThemeSeed_String(url)); 1950 setThemeSeed_GmDocument(d, urlPaletteSeed_String(url), urlThemeSeed_String(url));
1942 iUrl parts; 1951 iUrl parts;
1943 init_Url(&parts, url); 1952 init_Url(&parts, url);
1944 setRange_String(&d->localHost, parts.host); 1953 setRange_String(&d->localHost, parts.host);
diff --git a/src/gmdocument.h b/src/gmdocument.h
index 0969794c..6c25dd6f 100644
--- a/src/gmdocument.h
+++ b/src/gmdocument.h
@@ -181,7 +181,9 @@ enum iGmDocumentUpdate {
181 final_GmDocumentUpdate, /* process all lines, including the last one if not terminated */ 181 final_GmDocumentUpdate, /* process all lines, including the last one if not terminated */
182}; 182};
183 183
184void setThemeSeed_GmDocument (iGmDocument *, const iBlock *seed); 184void setThemeSeed_GmDocument (iGmDocument *,
185 const iBlock *paletteSeed,
186 const iBlock *iconSeed); /* seeds may be NULL; NULL iconSeed will use paletteSeed instead */
185void setFormat_GmDocument (iGmDocument *, enum iSourceFormat format); 187void setFormat_GmDocument (iGmDocument *, enum iSourceFormat format);
186void setWidth_GmDocument (iGmDocument *, int width, int canvasWidth); 188void setWidth_GmDocument (iGmDocument *, int width, int canvasWidth);
187iBool updateWidth_GmDocument (iGmDocument *, int width, int canvasWidth); 189iBool updateWidth_GmDocument (iGmDocument *, int width, int canvasWidth);
diff --git a/src/gmutil.c b/src/gmutil.c
index 0573aac1..9188091d 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -23,6 +23,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
23#include "gmutil.h" 23#include "gmutil.h"
24#include "fontpack.h" 24#include "fontpack.h"
25#include "lang.h" 25#include "lang.h"
26#include "sitespec.h"
26#include "ui/color.h" 27#include "ui/color.h"
27 28
28#include <the_Foundation/file.h> 29#include <the_Foundation/file.h>
@@ -279,6 +280,19 @@ const iBlock *urlThemeSeed_String(const iString *url) {
279 return collect_Block(newRange_Block(user)); 280 return collect_Block(newRange_Block(user));
280} 281}
281 282
283const iBlock *urlPaletteSeed_String(const iString *url) {
284 if (equalCase_Rangecc(urlScheme_String(url), "file")) {
285 return urlThemeSeed_String(url);
286 }
287 /* Check for a site-specific setting. */
288 const iString *seed =
289 valueString_SiteSpec(collectNewRange_String(urlRoot_String(url)), paletteSeed_SiteSpecKey);
290 if (!isEmpty_String(seed)) {
291 return utf8_String(seed);
292 }
293 return urlThemeSeed_String(url);
294}
295
282static iBool isAbsolutePath_(iRangecc path) { 296static iBool isAbsolutePath_(iRangecc path) {
283 return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); 297 return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path)))));
284} 298}
diff --git a/src/gmutil.h b/src/gmutil.h
index c9d7baae..01eb8e52 100644
--- a/src/gmutil.h
+++ b/src/gmutil.h
@@ -120,6 +120,7 @@ uint16_t urlPort_String (const iString *);
120iRangecc urlUser_String (const iString *); 120iRangecc urlUser_String (const iString *);
121iRangecc urlRoot_String (const iString *); 121iRangecc urlRoot_String (const iString *);
122const iBlock * urlThemeSeed_String (const iString *); 122const iBlock * urlThemeSeed_String (const iString *);
123const iBlock * urlPaletteSeed_String (const iString *);
123 124
124const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative); 125const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative);
125iBool isLikelyUrl_String (const iString *); 126iBool isLikelyUrl_String (const iString *);
diff --git a/src/sitespec.c b/src/sitespec.c
index fe80ad13..31094981 100644
--- a/src/sitespec.c
+++ b/src/sitespec.c
@@ -37,7 +37,8 @@ struct Impl_SiteParams {
37 iString titanIdentity; /* fingerprint */ 37 iString titanIdentity; /* fingerprint */
38 int dismissWarnings; 38 int dismissWarnings;
39 iStringArray usedIdentities; /* fingerprints; latest ones at the end */ 39 iStringArray usedIdentities; /* fingerprints; latest ones at the end */
40 /* TODO: theme seed, style settings */ 40 iString paletteSeed;
41 /* TODO: style settings */
41}; 42};
42 43
43void init_SiteParams(iSiteParams *d) { 44void init_SiteParams(iSiteParams *d) {
@@ -45,9 +46,11 @@ void init_SiteParams(iSiteParams *d) {
45 init_String(&d->titanIdentity); 46 init_String(&d->titanIdentity);
46 d->dismissWarnings = 0; 47 d->dismissWarnings = 0;
47 init_StringArray(&d->usedIdentities); 48 init_StringArray(&d->usedIdentities);
49 init_String(&d->paletteSeed);
48} 50}
49 51
50void deinit_SiteParams(iSiteParams *d) { 52void deinit_SiteParams(iSiteParams *d) {
53 deinit_String(&d->paletteSeed);
51 deinit_StringArray(&d->usedIdentities); 54 deinit_StringArray(&d->usedIdentities);
52 deinit_String(&d->titanIdentity); 55 deinit_String(&d->titanIdentity);
53} 56}
@@ -149,6 +152,9 @@ static void handleIniKeyValue_SiteSpec_(void *context, const iString *table, con
149 pushBack_StringArray(&d->loadParams->usedIdentities, collectNewRange_String(seg)); 152 pushBack_StringArray(&d->loadParams->usedIdentities, collectNewRange_String(seg));
150 } 153 }
151 } 154 }
155 else if (!cmp_String(key, "paletteSeed") && value->type == string_TomlType) {
156 set_String(&d->loadParams->paletteSeed, value->value.string);
157 }
152} 158}
153 159
154static iBool load_SiteSpec_(iSiteSpec *d) { 160static iBool load_SiteSpec_(iSiteSpec *d) {
@@ -190,6 +196,11 @@ static void save_SiteSpec_(iSiteSpec *d) {
190 "usedIdentities = \"%s\"\n", 196 "usedIdentities = \"%s\"\n",
191 cstrCollect_String(joinCStr_StringArray(&params->usedIdentities, " "))); 197 cstrCollect_String(joinCStr_StringArray(&params->usedIdentities, " ")));
192 } 198 }
199 if (!isEmpty_String(&params->paletteSeed)) {
200 appendCStr_String(buf, "paletteSeed = \"");
201 append_String(buf, collect_String(quote_String(&params->paletteSeed, iFalse)));
202 appendCStr_String(buf, "\"\n");
203 }
193 appendCStr_String(buf, "\n"); 204 appendCStr_String(buf, "\n");
194 write_File(f, utf8_String(buf)); 205 write_File(f, utf8_String(buf));
195 iEndCollect(); 206 iEndCollect();
diff --git a/src/sitespec.h b/src/sitespec.h
index 11c40e3c..372e021e 100644
--- a/src/sitespec.h
+++ b/src/sitespec.h
@@ -31,6 +31,7 @@ enum iSiteSpecKey {
31 titanIdentity_SiteSpecKey, /* String */ 31 titanIdentity_SiteSpecKey, /* String */
32 dismissWarnings_SiteSpecKey, /* int */ 32 dismissWarnings_SiteSpecKey, /* int */
33 usedIdentities_SiteSpecKey, /* StringArray */ 33 usedIdentities_SiteSpecKey, /* StringArray */
34 paletteSeed_SiteSpecKey, /* String */
34}; 35};
35 36
36void init_SiteSpec (const char *saveDir); 37void init_SiteSpec (const char *saveDir);
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 293e4507..7d9ac154 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -3936,12 +3936,12 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3936 const char *unchecked = red_ColorEscape "\u2610"; 3936 const char *unchecked = red_ColorEscape "\u2610";
3937 const char *checked = green_ColorEscape "\u2611"; 3937 const char *checked = green_ColorEscape "\u2611";
3938 const iBool haveFingerprint = (d->certFlags & haveFingerprint_GmCertFlag) != 0; 3938 const iBool haveFingerprint = (d->certFlags & haveFingerprint_GmCertFlag) != 0;
3939 const int requiredForTrust = (available_GmCertFlag | haveFingerprint_GmCertFlag | 3939 const int requiredForTrust =
3940 timeVerified_GmCertFlag); 3940 (available_GmCertFlag | haveFingerprint_GmCertFlag | timeVerified_GmCertFlag);
3941 const iBool canTrust = ~d->certFlags & trusted_GmCertFlag && 3941 const iBool canTrust = ~d->certFlags & trusted_GmCertFlag &&
3942 ((d->certFlags & requiredForTrust) == requiredForTrust); 3942 ((d->certFlags & requiredForTrust) == requiredForTrust);
3943 const iRecentUrl *recent = constMostRecentUrl_History(d->mod.history); 3943 const iRecentUrl *recent = constMostRecentUrl_History(d->mod.history);
3944 const iString *meta = &d->sourceMime; 3944 const iString *meta = &d->sourceMime;
3945 if (recent && recent->cachedResponse) { 3945 if (recent && recent->cachedResponse) {
3946 meta = &recent->cachedResponse->meta; 3946 meta = &recent->cachedResponse->meta;
3947 } 3947 }
@@ -4006,6 +4006,10 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
4006 if (haveFingerprint) { 4006 if (haveFingerprint) {
4007 pushBack_Array(items, &(iMenuItem){ "${dlg.cert.fingerprint}", 0, 0, "server.copycert" }); 4007 pushBack_Array(items, &(iMenuItem){ "${dlg.cert.fingerprint}", 0, 0, "server.copycert" });
4008 } 4008 }
4009 const iRangecc root = urlRoot_String(d->mod.url);
4010 if (!isEmpty_Range(&root)) {
4011 pushBack_Array(items, &(iMenuItem){ "${pageinfo.settings}", 0, 0, "document.sitespec" });
4012 }
4009 if (!isEmpty_Array(items)) { 4013 if (!isEmpty_Array(items)) {
4010 pushBack_Array(items, &(iMenuItem){ "---", 0, 0, 0 }); 4014 pushBack_Array(items, &(iMenuItem){ "---", 0, 0, 0 });
4011 } 4015 }
@@ -4937,7 +4941,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
4937 for (size_t i = 0; i < 64; ++i) { 4941 for (size_t i = 0; i < 64; ++i) {
4938 setByte_Block(seed, i, iRandom(0, 256)); 4942 setByte_Block(seed, i, iRandom(0, 256));
4939 } 4943 }
4940 setThemeSeed_GmDocument(view->doc, seed); 4944 setThemeSeed_GmDocument(view->doc, seed, NULL);
4941 delete_Block(seed); 4945 delete_Block(seed);
4942 invalidate_DocumentWidget_(d); 4946 invalidate_DocumentWidget_(d);
4943 refresh_Widget(w); 4947 refresh_Widget(w);
diff --git a/src/ui/util.c b/src/ui/util.c
index befc2fd5..54715121 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -3169,15 +3169,14 @@ static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) {
3169} 3169}
3170 3170
3171iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { 3171iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) {
3172 const char *headingText = bookmarkId ? uiHeading_ColorEscape "${heading.feedcfg}" 3172 iWidget *dlg;
3173 : uiHeading_ColorEscape "${heading.subscribe}"; 3173 const char *headingText = bookmarkId ? "${heading.feedcfg}" : "${heading.subscribe}";
3174 const iMenuItem actions[] = { { "${cancel}" }, 3174 const iMenuItem actions[] = { { "${cancel}" },
3175 { bookmarkId ? uiTextCaution_ColorEscape "${dlg.feed.save}" 3175 { bookmarkId ? uiTextCaution_ColorEscape "${dlg.feed.save}"
3176 : uiTextCaution_ColorEscape "${dlg.feed.sub}", 3176 : uiTextCaution_ColorEscape "${dlg.feed.sub}",
3177 SDLK_RETURN, 3177 SDLK_RETURN,
3178 KMOD_PRIMARY, 3178 KMOD_PRIMARY,
3179 format_CStr("feedcfg.accept bmid:%d", bookmarkId) } }; 3179 format_CStr("feedcfg.accept bmid:%d", bookmarkId) } };
3180 iWidget *dlg;
3181 if (isUsingPanelLayout_Mobile()) { 3180 if (isUsingPanelLayout_Mobile()) {
3182 const iMenuItem typeItems[] = { 3181 const iMenuItem typeItems[] = {
3183 { "button id:feedcfg.type.gemini label:dlg.feed.type.gemini", 0, 0, "feedcfg.type arg:0" }, 3182 { "button id:feedcfg.type.gemini label:dlg.feed.type.gemini", 0, 0, "feedcfg.type arg:0" },
@@ -3234,6 +3233,32 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) {
3234 return dlg; 3233 return dlg;
3235} 3234}
3236 3235
3236iWidget *makeSiteSpecificSettings_Widget(const iString *url) {
3237 iWidget *dlg;
3238 const iMenuItem actions[] = {
3239 { "${cancel}" }, { "${sitespec.accept}", SDLK_RETURN, KMOD_PRIMARY, "sitespec.accept" }
3240 };
3241 if (isUsingPanelLayout_Mobile()) {
3242 iAssert(iFalse);
3243 }
3244 else {
3245 iWidget *headings, *values;
3246 dlg = makeSheet_Widget("sitespec");
3247 addDialogTitle_(dlg, "${heading.sitespec}", "heading.sitespec");
3248 addChild_Widget(dlg, iClob(makeTwoColumns_Widget(&headings, &values)));
3249 addDialogToggle_(headings, values, "${sitespec.ansi}", "sitespec.ansi");
3250 iInputWidget *palInput = new_InputWidget(0);
3251 addPrefsInputWithHeading_(headings, values, "sitespec.palette", iClob(palInput));
3252 as_Widget(palInput)->rect.size.x = 80 * gap_UI;
3253 addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions))));
3254 }
3255 /* Initialize. */ {
3256 const iRangecc root = urlRoot_String(url);
3257
3258 }
3259 return dlg;
3260}
3261
3237iWidget *makeIdentityCreation_Widget(void) { 3262iWidget *makeIdentityCreation_Widget(void) {
3238 const iMenuItem actions[] = { { "${dlg.newident.more}", 0, 0, "ident.showmore" }, 3263 const iMenuItem actions[] = { { "${dlg.newident.more}", 0, 0, "ident.showmore" },
3239 { "---" }, 3264 { "---" },
diff --git a/src/ui/util.h b/src/ui/util.h
index 0289d579..31c8cedc 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -336,13 +336,14 @@ iWidget * makeQuestion_Widget (const char *title, const char *msg,
336iWidget * makePreferences_Widget (void); 336iWidget * makePreferences_Widget (void);
337void updatePreferencesLayout_Widget (iWidget *prefs); 337void updatePreferencesLayout_Widget (iWidget *prefs);
338 338
339iWidget * makeBookmarkEditor_Widget (void); 339iWidget * makeBookmarkEditor_Widget (void);
340void setBookmarkEditorFolder_Widget(iWidget *editor, uint32_t folderId); 340void setBookmarkEditorFolder_Widget (iWidget *editor, uint32_t folderId);
341iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon); 341iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon);
342iWidget * makeIdentityCreation_Widget (void); 342iWidget * makeIdentityCreation_Widget (void);
343iWidget * makeFeedSettings_Widget (uint32_t bookmarkId); 343iWidget * makeFeedSettings_Widget (uint32_t bookmarkId);
344iWidget * makeTranslation_Widget (iWidget *parent); 344iWidget * makeSiteSpecificSettings_Widget (const iString *url);
345iWidget * makeGlyphFinder_Widget (void); 345iWidget * makeTranslation_Widget (iWidget *parent);
346iWidget * makeGlyphFinder_Widget (void);
346 347
347const char * languageId_String (const iString *menuItemLabel); 348const char * languageId_String (const iString *menuItemLabel);
348int languageIndex_CStr (const char *langId); 349int languageIndex_CStr (const char *langId);