summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 08:21:42 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 08:22:18 +0300
commit621c5f0c2a57415038ffc8891109919350dc0288 (patch)
tree0a9e08b5c94611a3da30b6fcb34661bcb44ba72a /src
parentb3f220197e787782294c138ef28929244960f9c2 (diff)
DocumentWidget: Inline image download indicator
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 76ceebcd..26fd81cf 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -56,15 +56,11 @@ struct Impl_MediaRequest {
56 iDocumentWidget *doc; 56 iDocumentWidget *doc;
57 iGmLinkId linkId; 57 iGmLinkId linkId;
58 iGmRequest * req; 58 iGmRequest * req;
59 iAtomicInt isUpdated;
60}; 59};
61 60
62static void updated_MediaRequest_(iAnyObject *obj) { 61static void updated_MediaRequest_(iAnyObject *obj) {
63 iMediaRequest *d = obj; 62 iMediaRequest *d = obj;
64 int wasUpdated = exchange_Atomic(&d->isUpdated, iTrue); 63 postCommandf_App("media.updated link:%u request:%p", d->linkId, d);
65 if (!wasUpdated) {
66 postCommandf_App("media.updated link:%u request:%p", d->linkId, d);
67 }
68} 64}
69 65
70static void finished_MediaRequest_(iAnyObject *obj) { 66static void finished_MediaRequest_(iAnyObject *obj) {
@@ -79,7 +75,6 @@ void init_MediaRequest(iMediaRequest *d, iDocumentWidget *doc, iGmLinkId linkId,
79 setUrl_GmRequest(d->req, url); 75 setUrl_GmRequest(d->req, url);
80 iConnect(GmRequest, d->req, updated, d, updated_MediaRequest_); 76 iConnect(GmRequest, d->req, updated, d, updated_MediaRequest_);
81 iConnect(GmRequest, d->req, finished, d, finished_MediaRequest_); 77 iConnect(GmRequest, d->req, finished, d, finished_MediaRequest_);
82 set_Atomic(&d->isUpdated, iFalse);
83 submit_GmRequest(d->req); 78 submit_GmRequest(d->req);
84} 79}
85 80
@@ -1001,7 +996,9 @@ static iBool handleMediaCommand_DocumentWidget_(iDocumentWidget *d, const char *
1001 return iFalse; /* not our request */ 996 return iFalse; /* not our request */
1002 } 997 }
1003 if (equal_Command(cmd, "media.updated")) { 998 if (equal_Command(cmd, "media.updated")) {
1004 /* TODO: Show a progress indicator */ 999 /* Update the link's progress. */
1000 invalidateLink_DocumentWidget_(d, req->linkId);
1001 refresh_Widget(d);
1005 return iTrue; 1002 return iTrue;
1006 } 1003 }
1007 else if (equal_Command(cmd, "media.finished")) { 1004 else if (equal_Command(cmd, "media.finished")) {
@@ -1786,8 +1783,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1786 const int flags = linkFlags_GmDocument(doc, run->linkId); 1783 const int flags = linkFlags_GmDocument(doc, run->linkId);
1787 const iRect linkRect = moved_Rect(run->visBounds, origin); 1784 const iRect linkRect = moved_Rect(run->visBounds, origin);
1788 iMediaRequest *mr = NULL; 1785 iMediaRequest *mr = NULL;
1789 /* Show inline content. */ 1786 /* Show metadata about inline content. */
1790 if (flags & content_GmLinkFlag) { 1787 if (flags & content_GmLinkFlag && run->flags & endOfLine_GmRunFlag) {
1791 fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart); 1788 fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart);
1792 iAssert(!isEmpty_Rect(run->bounds)); 1789 iAssert(!isEmpty_Rect(run->bounds));
1793 iGmImageInfo info; 1790 iGmImageInfo info;
@@ -1819,8 +1816,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
1819 draw_Text(metaFont, 1816 draw_Text(metaFont,
1820 topRight_Rect(linkRect), 1817 topRight_Rect(linkRect),
1821 tmInlineContentMetadata_ColorId, 1818 tmInlineContentMetadata_ColorId,
1822 " \u2014 Fetching\u2026"); 1819 " \u2014 Fetching\u2026 (%.1f MB)",
1823 /* TODO: Show amount downloaded so far. */ 1820 (float) size_Block(body_GmRequest(mr->req)) / 1.0e6f);
1824 } 1821 }
1825 } 1822 }
1826 else if (isHover) { 1823 else if (isHover) {