summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-20 14:09:08 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-20 14:09:08 +0200
commitdf0e00463c5b55f89471720c1bf4d83e1f428aae (patch)
tree00f39e4c7d7308e5b1d65473a538c691181abefa /src
parentc998b25d4d428e860520bb8fa4fd5450c1b865fd (diff)
Preferences: Added a Gemini proxy
Diffstat (limited to 'src')
-rw-r--r--src/app.c27
-rw-r--r--src/prefs.c2
-rw-r--r--src/prefs.h1
-rw-r--r--src/ui/documentwidget.c24
-rw-r--r--src/ui/util.c5
5 files changed, 38 insertions, 21 deletions
diff --git a/src/app.c b/src/app.c
index 02c69d64..f2741ee6 100644
--- a/src/app.c
+++ b/src/app.c
@@ -193,6 +193,7 @@ static iString *serializePrefs_App_(const iApp *d) {
193 appendFormat_String(str, "doctheme.dark.set arg:%d\n", d->prefs.docThemeDark); 193 appendFormat_String(str, "doctheme.dark.set arg:%d\n", d->prefs.docThemeDark);
194 appendFormat_String(str, "doctheme.light.set arg:%d\n", d->prefs.docThemeLight); 194 appendFormat_String(str, "doctheme.light.set arg:%d\n", d->prefs.docThemeLight);
195 appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f)); 195 appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f));
196 appendFormat_String(str, "proxy.gemini address:%s\n", cstr_String(&d->prefs.geminiProxy));
196 appendFormat_String(str, "proxy.gopher address:%s\n", cstr_String(&d->prefs.gopherProxy)); 197 appendFormat_String(str, "proxy.gopher address:%s\n", cstr_String(&d->prefs.gopherProxy));
197 appendFormat_String(str, "proxy.http address:%s\n", cstr_String(&d->prefs.httpProxy)); 198 appendFormat_String(str, "proxy.http address:%s\n", cstr_String(&d->prefs.httpProxy));
198 appendFormat_String(str, "downloads path:%s\n", cstr_String(&d->prefs.downloadDir)); 199 appendFormat_String(str, "downloads path:%s\n", cstr_String(&d->prefs.downloadDir));
@@ -616,13 +617,16 @@ enum iColorTheme colorTheme_App(void) {
616const iString *schemeProxy_App(iRangecc scheme) { 617const iString *schemeProxy_App(iRangecc scheme) {
617 iApp *d = &app_; 618 iApp *d = &app_;
618 const iString *proxy = NULL; 619 const iString *proxy = NULL;
619 if (equalCase_Rangecc(scheme, "gopher")) { 620 if (equalCase_Rangecc(scheme, "gemini")) {
621 proxy = &d->prefs.geminiProxy;
622 }
623 else if (equalCase_Rangecc(scheme, "gopher")) {
620 proxy = &d->prefs.gopherProxy; 624 proxy = &d->prefs.gopherProxy;
621 } 625 }
622 if (equalCase_Rangecc(scheme, "http") || equalCase_Rangecc(scheme, "https")) { 626 else if (equalCase_Rangecc(scheme, "http") || equalCase_Rangecc(scheme, "https")) {
623 proxy = &d->prefs.httpProxy; 627 proxy = &d->prefs.httpProxy;
624 } 628 }
625 return !isEmpty_String(proxy) ? proxy : NULL; 629 return isEmpty_String(proxy) ? NULL : proxy;
626} 630}
627 631
628int run_App(int argc, char **argv) { 632int run_App(int argc, char **argv) {
@@ -744,10 +748,12 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) {
744 isSelected_Widget(findChild_Widget(d, "prefs.smoothscroll"))); 748 isSelected_Widget(findChild_Widget(d, "prefs.smoothscroll")));
745 postCommandf_App("ostheme arg:%d", 749 postCommandf_App("ostheme arg:%d",
746 isSelected_Widget(findChild_Widget(d, "prefs.ostheme"))); 750 isSelected_Widget(findChild_Widget(d, "prefs.ostheme")));
747 postCommandf_App("proxy.http address:%s", 751 postCommandf_App("proxy.gemini address:%s",
748 cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.http")))); 752 cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.gemini"))));
749 postCommandf_App("proxy.gopher address:%s", 753 postCommandf_App("proxy.gopher address:%s",
750 cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.gopher")))); 754 cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.gopher"))));
755 postCommandf_App("proxy.http address:%s",
756 cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.http"))));
751 const iWidget *tabs = findChild_Widget(d, "prefs.tabs"); 757 const iWidget *tabs = findChild_Widget(d, "prefs.tabs");
752 postCommandf_App("prefs.dialogtab arg:%u", 758 postCommandf_App("prefs.dialogtab arg:%u",
753 tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs))); 759 tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs)));
@@ -1024,6 +1030,10 @@ iBool handleCommand_App(const char *cmd) {
1024 postCommandf_App("theme.changed auto:1"); 1030 postCommandf_App("theme.changed auto:1");
1025 return iTrue; 1031 return iTrue;
1026 } 1032 }
1033 else if (equal_Command(cmd, "proxy.gemini")) {
1034 setCStr_String(&d->prefs.geminiProxy, suffixPtr_Command(cmd, "address"));
1035 return iTrue;
1036 }
1027 else if (equal_Command(cmd, "proxy.gopher")) { 1037 else if (equal_Command(cmd, "proxy.gopher")) {
1028 setCStr_String(&d->prefs.gopherProxy, suffixPtr_Command(cmd, "address")); 1038 setCStr_String(&d->prefs.gopherProxy, suffixPtr_Command(cmd, "address"));
1029 return iTrue; 1039 return iTrue;
@@ -1177,10 +1187,9 @@ iBool handleCommand_App(const char *cmd) {
1177 dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))), 1187 dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))),
1178 selected_WidgetFlag, 1188 selected_WidgetFlag,
1179 iTrue); 1189 iTrue);
1180 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.http"), 1190 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gemini"), &d->prefs.geminiProxy);
1181 schemeProxy_App(range_CStr("http"))); 1191 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"), &d->prefs.gopherProxy);
1182 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"), 1192 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.http"), &d->prefs.httpProxy);
1183 schemeProxy_App(range_CStr("gopher")));
1184 iWidget *tabs = findChild_Widget(dlg, "prefs.tabs"); 1193 iWidget *tabs = findChild_Widget(dlg, "prefs.tabs");
1185 showTabPage_Widget(tabs, tabPage_Widget(tabs, d->prefs.dialogTab)); 1194 showTabPage_Widget(tabs, tabPage_Widget(tabs, d->prefs.dialogTab));
1186 setCommandHandler_Widget(dlg, handlePrefsCommands_); 1195 setCommandHandler_Widget(dlg, handlePrefsCommands_);
diff --git a/src/prefs.c b/src/prefs.c
index 5c73833e..80b11c30 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -42,12 +42,14 @@ void init_Prefs(iPrefs *d) {
42 d->docThemeDark = colorfulDark_GmDocumentTheme; 42 d->docThemeDark = colorfulDark_GmDocumentTheme;
43 d->docThemeLight = white_GmDocumentTheme; 43 d->docThemeLight = white_GmDocumentTheme;
44 d->saturation = 1.0f; 44 d->saturation = 1.0f;
45 init_String(&d->geminiProxy);
45 init_String(&d->gopherProxy); 46 init_String(&d->gopherProxy);
46 init_String(&d->httpProxy); 47 init_String(&d->httpProxy);
47 init_String(&d->downloadDir); 48 init_String(&d->downloadDir);
48} 49}
49 50
50void deinit_Prefs(iPrefs *d) { 51void deinit_Prefs(iPrefs *d) {
52 deinit_String(&d->geminiProxy);
51 deinit_String(&d->gopherProxy); 53 deinit_String(&d->gopherProxy);
52 deinit_String(&d->httpProxy); 54 deinit_String(&d->httpProxy);
53 deinit_String(&d->downloadDir); 55 deinit_String(&d->downloadDir);
diff --git a/src/prefs.h b/src/prefs.h
index 2488d43b..33ce8b41 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -40,6 +40,7 @@ struct Impl_Prefs {
40 iBool smoothScrolling; 40 iBool smoothScrolling;
41 iBool useSystemTheme; 41 iBool useSystemTheme;
42 enum iColorTheme theme; 42 enum iColorTheme theme;
43 iString geminiProxy;
43 iString gopherProxy; 44 iString gopherProxy;
44 iString httpProxy; 45 iString httpProxy;
45 iString downloadDir; 46 iString downloadDir;
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 8640e7ae..59f5a92c 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -2004,9 +2004,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2004 iArray items; 2004 iArray items;
2005 init_Array(&items, sizeof(iMenuItem)); 2005 init_Array(&items, sizeof(iMenuItem));
2006 if (d->contextLink) { 2006 if (d->contextLink) {
2007 const iString *linkUrl = linkUrl_GmDocument(d->doc, d->contextLink->linkId); 2007 const iString *linkUrl = linkUrl_GmDocument(d->doc, d->contextLink->linkId);
2008 const iRangecc scheme = urlScheme_String(linkUrl); 2008 const iRangecc scheme = urlScheme_String(linkUrl);
2009 if (willUseProxy_App(scheme) || equalCase_Rangecc(scheme, "gemini") || 2009 const iBool isGemini = equalCase_Rangecc(scheme, "gemini");
2010 if (willUseProxy_App(scheme) || isGemini ||
2010 equalCase_Rangecc(scheme, "gopher")) { 2011 equalCase_Rangecc(scheme, "gopher")) {
2011 /* Regular links that we can open. */ 2012 /* Regular links that we can open. */
2012 pushBackN_Array( 2013 pushBackN_Array(
@@ -2031,14 +2032,15 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2031 format_CStr("!open url:%s", cstr_String(linkUrl)) }); 2032 format_CStr("!open url:%s", cstr_String(linkUrl)) });
2032 } 2033 }
2033 if (willUseProxy_App(scheme)) { 2034 if (willUseProxy_App(scheme)) {
2034 pushBackN_Array(&items, 2035 pushBackN_Array(
2035 (iMenuItem[]){ { "---", 0, 0, NULL }, 2036 &items,
2036 { "Open Link in Default Browser", 2037 (iMenuItem[]){
2037 0, 2038 { "---", 0, 0, NULL },
2038 0, 2039 { isGemini ? "Open without Proxy" : "Open Link in Default Browser",
2039 format_CStr("!open noproxy:1 url:%s", 2040 0,
2040 cstr_String(linkUrl)) } }, 2041 0,
2041 2); 2042 format_CStr("!open noproxy:1 url:%s", cstr_String(linkUrl)) } },
2043 2);
2042 } 2044 }
2043 pushBackN_Array(&items, 2045 pushBackN_Array(&items,
2044 (iMenuItem[]){ { "---", 0, 0, NULL }, 2046 (iMenuItem[]){ { "---", 0, 0, NULL },
diff --git a/src/ui/util.c b/src/ui/util.c
index bdb348f9..0f0fa039 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1111,6 +1111,8 @@ iWidget *makePreferences_Widget(void) {
1111 } 1111 }
1112 /* Proxies. */ { 1112 /* Proxies. */ {
1113 appendTwoColumnPage_(tabs, "Proxies", '4', &headings, &values); 1113 appendTwoColumnPage_(tabs, "Proxies", '4', &headings, &values);
1114 addChild_Widget(headings, iClob(makeHeading_Widget("Gemini proxy:")));
1115 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.gemini");
1114 addChild_Widget(headings, iClob(makeHeading_Widget("Gopher proxy:"))); 1116 addChild_Widget(headings, iClob(makeHeading_Widget("Gopher proxy:")));
1115 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.gopher"); 1117 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.gopher");
1116 addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:"))); 1118 addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:")));
@@ -1125,8 +1127,9 @@ iWidget *makePreferences_Widget(void) {
1125 arrange_Widget(dlg); 1127 arrange_Widget(dlg);
1126 /* Set input field sizes. */ { 1128 /* Set input field sizes. */ {
1127 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.downloads")); 1129 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.downloads"));
1128 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http")); 1130 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gemini"));
1129 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher")); 1131 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher"));
1132 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http"));
1130 } 1133 }
1131 iWidget *div = new_Widget(); { 1134 iWidget *div = new_Widget(); {
1132 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 1135 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);