summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2022-02-13 20:27:11 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2022-02-13 20:27:11 +0200
commitfb71407409b2debd8e03c42faecd811d168321bf (patch)
treea26585d53cac41c143d9ebf35a5fc352d68716a4 /src
parent46acccaa8128a18ed026c9c5b4e6a401a307c3b0 (diff)
Added UI helper for presenting data URLs
Omit the actual data.
Diffstat (limited to 'src')
-rw-r--r--src/gmutil.c25
-rw-r--r--src/gmutil.h1
-rw-r--r--src/ui/linkinfo.c8
-rw-r--r--src/ui/sidebarwidget.c54
4 files changed, 60 insertions, 28 deletions
diff --git a/src/gmutil.c b/src/gmutil.c
index e59e6649..6c2271d7 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -22,6 +22,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#include "gmutil.h" 23#include "gmutil.h"
24#include "fontpack.h" 24#include "fontpack.h"
25#include "lang.h"
26#include "ui/color.h"
25 27
26#include <the_Foundation/file.h> 28#include <the_Foundation/file.h>
27#include <the_Foundation/fileinfo.h> 29#include <the_Foundation/fileinfo.h>
@@ -739,6 +741,29 @@ const iString *canonicalUrl_String(const iString *d) {
739 return canon ? collect_String(canon) : d; 741 return canon ? collect_String(canon) : d;
740} 742}
741 743
744const iString *prettyDataUrl_String(const iString *d, int contentColor) {
745 iUrl url;
746 init_Url(&url, d);
747 if (!equalCase_Rangecc(url.scheme, "data")) {
748 return d;
749 }
750 iString *pretty = new_String();
751 const char *comma = strchr(url.path.start, ',');
752 if (!comma) {
753 comma = iMin(constEnd_String(d), constBegin_String(d) + 256);
754 }
755 appendRange_String(pretty, (iRangecc){ constBegin_String(d), comma });
756 if (size_Range(&url.path)) {
757 if (contentColor != none_ColorId) {
758 appendCStr_String(pretty, escape_Color(contentColor));
759 }
760 appendCStr_String(pretty, " (");
761 appendCStr_String(pretty, formatCStrs_Lang("num.bytes.n", size_Range(&url.path)));
762 appendCStr_String(pretty, ")");
763 }
764 return collect_String(pretty);
765}
766
742iRangecc mediaTypeWithoutParameters_Rangecc(iRangecc mime) { 767iRangecc mediaTypeWithoutParameters_Rangecc(iRangecc mime) {
743 iRangecc part = iNullRange; 768 iRangecc part = iNullRange;
744 nextSplit_Rangecc(mime, ";", &part); 769 nextSplit_Rangecc(mime, ";", &part);
diff --git a/src/gmutil.h b/src/gmutil.h
index 1594afc4..9217b0e3 100644
--- a/src/gmutil.h
+++ b/src/gmutil.h
@@ -141,6 +141,7 @@ void urlEncodeSpaces_String (iString *);
141const iString * withSpacesEncoded_String(const iString *); 141const iString * withSpacesEncoded_String(const iString *);
142const iString * withScheme_String (const iString *, const char *scheme); /* replace URI scheme */ 142const iString * withScheme_String (const iString *, const char *scheme); /* replace URI scheme */
143const iString * canonicalUrl_String (const iString *); 143const iString * canonicalUrl_String (const iString *);
144const iString * prettyDataUrl_String (const iString *, int contentColor);
144 145
145const char * mediaType_Path (const iString *path); 146const char * mediaType_Path (const iString *path);
146const char * mediaTypeFromFileExtension_String (const iString *); 147const char * mediaTypeFromFileExtension_String (const iString *);
diff --git a/src/ui/linkinfo.c b/src/ui/linkinfo.c
index 46aa6663..15aea16e 100644
--- a/src/ui/linkinfo.c
+++ b/src/ui/linkinfo.c
@@ -92,12 +92,8 @@ void infoText_LinkInfo(const iGmDocument *doc, iGmLinkId linkId, iString *text_o
92 appendRange_String(text_out, (iRangecc){ parts.path.start, constEnd_String(url) }); 92 appendRange_String(text_out, (iRangecc){ parts.path.start, constEnd_String(url) });
93 } 93 }
94 else if (scheme == data_GmLinkScheme) { 94 else if (scheme == data_GmLinkScheme) {
95 appendCStr_String(text_out, "\U0001f4e6 "); 95 appendCStr_String(text_out, paperclip_Icon " ");
96 const char *comma = strchr(cstr_String(url), ','); 96 append_String(text_out, prettyDataUrl_String(url, none_ColorId));
97 if (!comma) {
98 comma = iMin(constEnd_String(url), constBegin_String(url) + 256);
99 }
100 appendRange_String(text_out, (iRangecc){ constBegin_String(url), comma });
101 } 97 }
102 else if (scheme != gemini_GmLinkScheme) { 98 else if (scheme != gemini_GmLinkScheme) {
103 const size_t maxDispLen = 300; 99 const size_t maxDispLen = 300;
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index da377ac2..73023a4f 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -2156,28 +2156,38 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
2156 : uiTextDim_ColorId; 2156 : uiTextDim_ColorId;
2157 iUrl parts; 2157 iUrl parts;
2158 init_Url(&parts, &d->label); 2158 init_Url(&parts, &d->label);
2159 const iBool isAbout = equalCase_Rangecc(parts.scheme, "about"); 2159 const iBool isAbout = equalCase_Rangecc(parts.scheme, "about");
2160 const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini"); 2160 const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini");
2161 draw_Text(font, 2161 const iBool isData = equalCase_Rangecc(parts.scheme, "data");
2162 add_I2(topLeft_Rect(itemRect), 2162 const int queryColor = isPressing ? uiTextPressed_ColorId
2163 init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2)), 2163 : isHover ? uiText_ColorId
2164 fg, 2164 : uiAnnotation_ColorId;
2165 "%s%s%s%s%s%s%s%s", 2165 const iInt2 textPos =
2166 isGemini ? "" : cstr_Rangecc(parts.scheme), 2166 add_I2(topLeft_Rect(itemRect),
2167 isGemini ? "" 2167 init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2));
2168 : isAbout ? ":" 2168 if (isData) {
2169 : "://", 2169 drawRange_Text(
2170 escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId 2170 font, textPos, fg, range_String(prettyDataUrl_String(&d->label, queryColor)));
2171 : uiTextFramelessHover_ColorId) 2171 }
2172 : uiTextStrong_ColorId), 2172 else {
2173 cstr_Rangecc(parts.host), 2173 draw_Text(
2174 escape_Color(fg), 2174 font,
2175 cstr_Rangecc(parts.path), 2175 textPos,
2176 !isEmpty_Range(&parts.query) ? escape_Color(isPressing ? uiTextPressed_ColorId 2176 fg,
2177 : isHover ? uiText_ColorId 2177 "%s%s%s%s%s%s%s%s",
2178 : uiAnnotation_ColorId) 2178 isGemini ? "" : cstr_Rangecc(parts.scheme),
2179 : "", 2179 isGemini ? ""
2180 !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : ""); 2180 : isAbout ? ":"
2181 : "://",
2182 escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId
2183 : uiTextFramelessHover_ColorId)
2184 : uiTextStrong_ColorId),
2185 cstr_Rangecc(parts.host),
2186 escape_Color(fg),
2187 cstr_Rangecc(parts.path),
2188 !isEmpty_Range(&parts.query) ? escape_Color(queryColor) : "",
2189 !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : "");
2190 }
2181 } 2191 }
2182 iEndCollect(); 2192 iEndCollect();
2183 } 2193 }