summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c43
-rw-r--r--src/ui/documentwidget.h3
-rw-r--r--src/ui/mediaui.c48
-rw-r--r--src/ui/mediaui.h7
4 files changed, 83 insertions, 18 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 924dc0c4..1aca895c 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -2916,6 +2916,27 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2916 updateMedia_DocumentWidget_(d); 2916 updateMedia_DocumentWidget_(d);
2917 return iFalse; 2917 return iFalse;
2918 } 2918 }
2919 else if (equal_Command(cmd, "media.fontpack.updated")) {
2920 iMedia *media = pointerLabel_Command(cmd, "media");
2921 if (media == media_GmDocument(d->doc)) {
2922 /*iGmMediaInfo info;
2923 if (info_Media(media,
2924 (iMediaId){ fontpack_MediaType, argU32Label_Command(cmd, "id")},
2925 &info)) {
2926
2927 }*/
2928
2929// findCachedContent_App(<#const iString *url#>, <#iString *mime_out#>, <#iBlock *data_out#>)
2930// setData_Media(media,
2931 }
2932 return iFalse;
2933 }
2934 else if (equal_Command(cmd, "media.fontpack.install")) {
2935 if (pointerLabel_Command(cmd, "media") == media_GmDocument(d->doc)) {
2936 /* TODO: This is ours, we may have a MediaRequest with the data in memory. */
2937 }
2938 return iFalse;
2939 }
2919 else if (equal_Command(cmd, "document.stop") && document_App() == d) { 2940 else if (equal_Command(cmd, "document.stop") && document_App() == d) {
2920 if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) { 2941 if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) {
2921 return iTrue; 2942 return iTrue;
@@ -5169,6 +5190,28 @@ void updateSize_DocumentWidget(iDocumentWidget *d) {
5169 invalidate_DocumentWidget_(d); 5190 invalidate_DocumentWidget_(d);
5170} 5191}
5171 5192
5193iBool findCachedContent_DocumentWidget(const iDocumentWidget *d, const iString *url,
5194 iString *mime_out, iBlock *data_out) {
5195 if (equal_String(d->mod.url, url) && !isRequestOngoing_DocumentWidget(d)) {
5196 /* It's the currently open page. */
5197 set_String(mime_out, &d->sourceMime);
5198 set_Block(data_out, &d->sourceContent);
5199 return iTrue;
5200 }
5201 /* Finished media requests are kept in memory while the page is open. */
5202 iConstForEach(ObjectList, i, d->media) {
5203 const iMediaRequest *mr = i.object;
5204 if (mr->req &&
5205 isFinished_GmRequest(mr->req) &&
5206 equal_String(linkUrl_GmDocument(d->doc, mr->linkId), url)) {
5207 set_String(mime_out, meta_GmRequest(mr->req));
5208 set_Block(data_out, body_GmRequest(mr->req));
5209 return iTrue;
5210 }
5211 }
5212 return iFalse;
5213}
5214
5172iBeginDefineSubclass(DocumentWidget, Widget) 5215iBeginDefineSubclass(DocumentWidget, Widget)
5173 .processEvent = (iAny *) processEvent_DocumentWidget_, 5216 .processEvent = (iAny *) processEvent_DocumentWidget_,
5174 .draw = (iAny *) draw_DocumentWidget_, 5217 .draw = (iAny *) draw_DocumentWidget_,
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h
index 1f2ecfc0..9bfab57a 100644
--- a/src/ui/documentwidget.h
+++ b/src/ui/documentwidget.h
@@ -48,6 +48,9 @@ const iString * bookmarkTitle_DocumentWidget (const iDocumentWidget *);
48const iString * feedTitle_DocumentWidget (const iDocumentWidget *); 48const iString * feedTitle_DocumentWidget (const iDocumentWidget *);
49int documentWidth_DocumentWidget (const iDocumentWidget *); 49int documentWidth_DocumentWidget (const iDocumentWidget *);
50 50
51iBool findCachedContent_DocumentWidget(const iDocumentWidget *, const iString *url,
52 iString *mime_out, iBlock *data_out);
53
51enum iDocumentWidgetSetUrlFlags { 54enum iDocumentWidgetSetUrlFlags {
52 useCachedContentIfAvailable_DocumentWidgetSetUrlFlag = iBit(1), 55 useCachedContentIfAvailable_DocumentWidgetSetUrlFlag = iBit(1),
53 openedFromSidebar_DocumentWidgetSetUrlFlag = iBit(2), 56 openedFromSidebar_DocumentWidgetSetUrlFlag = iBit(2),
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c
index aa45d73a..ac9475dd 100644
--- a/src/ui/mediaui.c
+++ b/src/ui/mediaui.c
@@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28#include "paint.h" 28#include "paint.h"
29#include "util.h" 29#include "util.h"
30#include "lang.h" 30#include "lang.h"
31#include "app.h"
31 32
32#include <the_Foundation/path.h> 33#include <the_Foundation/path.h>
33#include <the_Foundation/stringlist.h> 34#include <the_Foundation/stringlist.h>
@@ -281,14 +282,28 @@ void draw_DownloadUI(const iDownloadUI *d, iPaint *p) {
281 282
282/*----------------------------------------------------------------------------------------------*/ 283/*----------------------------------------------------------------------------------------------*/
283 284
285static iMenuItem action_FontpackUI_(const iFontpackUI *d) {
286 if (d->info.isInstalled) {
287 return (iMenuItem){ d->info.isDisabled ? "${media.fontpack.enable}"
288 : close_Icon " ${media.fontpack.disable}",
289 0, 0, format_CStr("media.fontpack.enable arg:%d", d->info.isDisabled) };
290 }
291 return (iMenuItem){ d->info.isInstalled ? close_Icon " ${media.fontpack.disable}"
292 : "${media.fontpack.install}",
293 0, 0,
294 d->info.isInstalled ? "media.fontpack.enable arg:0" : "media.fontpack.install" };
295}
296
284void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) { 297void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) {
285 d->media = media; 298 d->media = media;
286 d->mediaId = mediaId; 299 d->mediaId = mediaId;
300 fontpackInfo_Media(d->media, (iMediaId){ fontpack_MediaType, d->mediaId }, &d->info);
287 d->bounds = bounds; 301 d->bounds = bounds;
288 d->installRect.size = add_I2(measure_Text(uiLabel_FontId, "${media.fontpack.install}").bounds.size, 302 iMenuItem action = action_FontpackUI_(d);
289 muli_I2(gap2_UI, 3)); 303 d->buttonRect.size = add_I2(measure_Text(uiLabel_FontId, action.label).bounds.size,
290 d->installRect.pos.x = right_Rect(d->bounds) - gap_UI - d->installRect.size.x; 304 muli_I2(gap2_UI, 3));
291 d->installRect.pos.y = mid_Rect(d->bounds).y - d->installRect.size.y / 2; 305 d->buttonRect.pos.x = right_Rect(d->bounds) - gap_UI - d->buttonRect.size.x;
306 d->buttonRect.pos.y = mid_Rect(d->bounds).y - d->buttonRect.size.y / 2;
292} 307}
293 308
294iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) { 309iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) {
@@ -296,7 +311,12 @@ iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) {
296 case SDL_MOUSEBUTTONDOWN: 311 case SDL_MOUSEBUTTONDOWN:
297 case SDL_MOUSEBUTTONUP: { 312 case SDL_MOUSEBUTTONUP: {
298 const iInt2 pos = init_I2(ev->button.x, ev->button.y); 313 const iInt2 pos = init_I2(ev->button.x, ev->button.y);
299 if (contains_Rect(d->installRect, pos)) { 314 if (contains_Rect(d->buttonRect, pos)) {
315 if (ev->type == SDL_MOUSEBUTTONUP) {
316 postCommandf_App("%s media:%p mediaid:%u packid:%s",
317 action_FontpackUI_(d).command,
318 d->media, d->mediaId, cstr_String(d->info.packId.id));
319 }
300 return iTrue; 320 return iTrue;
301 } 321 }
302 break; 322 break;
@@ -322,24 +342,22 @@ void draw_FontpackUI(const iFontpackUI *d, iPaint *p) {
322 /* Draw a background box. */ 342 /* Draw a background box. */
323 fillRect_Paint(p, d->bounds, uiBackground_ColorId); 343 fillRect_Paint(p, d->bounds, uiBackground_ColorId);
324 drawRect_Paint(p, d->bounds, uiSeparator_ColorId); 344 drawRect_Paint(p, d->bounds, uiSeparator_ColorId);
325 iFontpackMediaInfo info;
326 fontpackInfo_Media(d->media, (iMediaId){ fontpack_MediaType, d->mediaId }, &info);
327 iInt2 pos = topLeft_Rect(d->bounds); 345 iInt2 pos = topLeft_Rect(d->bounds);
328 const char *checks[] = { "\u2610", "\u2611" }; 346 const char *checks[] = { "\u2610", "\u2611" };
329 draw_Text(uiContentBold_FontId, pos, uiHeading_ColorId, "\"%s\" v%d", 347 draw_Text(uiContentBold_FontId, pos,
330 cstr_String(info.packId.id), info.packId.version); 348 d->info.isDisabled ? uiText_ColorId : uiHeading_ColorId, "\"%s\" v%d",
349 cstr_String(d->info.packId.id), d->info.packId.version);
331 pos.y += lineHeight_Text(uiContentBold_FontId); 350 pos.y += lineHeight_Text(uiContentBold_FontId);
332 draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s", 351 draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s",
333 info.sizeInBytes / 1.0e6, size_StringList(info.names), 352 d->info.sizeInBytes / 1.0e6, size_StringList(d->info.names),
334// checks[info.isValid], info.isValid ? "No errors" : "Errors detected", 353// checks[info.isValid], info.isValid ? "No errors" : "Errors detected",
335 checks[info.isInstalled], info.isInstalled ? "Installed" : "Not installed", 354 checks[d->info.isInstalled], d->info.isInstalled ? "Installed" : "Not installed",
336 info.isReadOnly ? "Read-Only" : ""); 355 d->info.isReadOnly ? "Read-Only" : "");
337 pos.y += lineHeight_Text(uiLabelBold_FontId); 356 pos.y += lineHeight_Text(uiLabelBold_FontId);
338 iConstForEach(StringList, i, info.names) { 357 iConstForEach(StringList, i, d->info.names) {
339 drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value)); 358 drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value));
340 pos.y += lineHeight_Text(uiLabel_FontId); 359 pos.y += lineHeight_Text(uiLabel_FontId);
341 } 360 }
342 /* Buttons. */ 361 /* Buttons. */
343 drawInlineButton_(p, d->installRect, 362 drawInlineButton_(p, d->buttonRect, action_FontpackUI_(d).label, uiLabel_FontId);
344 "${media.fontpack.install}", uiLabel_FontId);
345} 363}
diff --git a/src/ui/mediaui.h b/src/ui/mediaui.h
index 73de1994..03ea0afc 100644
--- a/src/ui/mediaui.h
+++ b/src/ui/mediaui.h
@@ -22,6 +22,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#pragma once 23#pragma once
24 24
25#include "../media.h"
26
25#include <the_Foundation/rect.h> 27#include <the_Foundation/rect.h>
26#include <SDL_events.h> 28#include <SDL_events.h>
27 29
@@ -46,8 +48,6 @@ void draw_PlayerUI (iPlayerUI *, iPaint *p);
46 48
47/*----------------------------------------------------------------------------------------------*/ 49/*----------------------------------------------------------------------------------------------*/
48 50
49iDeclareType(DocumentWidget)
50iDeclareType(Media)
51iDeclareType(DownloadUI) 51iDeclareType(DownloadUI)
52 52
53struct Impl_DownloadUI { 53struct Impl_DownloadUI {
@@ -67,8 +67,9 @@ iDeclareType(FontpackUI)
67struct Impl_FontpackUI { 67struct Impl_FontpackUI {
68 const iMedia *media; 68 const iMedia *media;
69 uint16_t mediaId; 69 uint16_t mediaId;
70 iFontpackMediaInfo info;
70 iRect bounds; 71 iRect bounds;
71 iRect installRect; 72 iRect buttonRect;
72}; 73};
73 74
74void init_FontpackUI (iFontpackUI *, const iMedia *media, uint16_t mediaId, iRect bounds); 75void init_FontpackUI (iFontpackUI *, const iMedia *media, uint16_t mediaId, iRect bounds);