summaryrefslogtreecommitdiff
path: root/src/media.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 11:15:14 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 11:15:14 +0300
commit2e2b823bfb5d34d42c6b6c1b289193c854459b45 (patch)
tree345f37aa1b84d8dedb98ff260265b41495e10878 /src/media.c
parent2f3987f5e54d95658f95c6991b0644bc15eedabf (diff)
Media and FontPacks (work in progress)
Saving this as the last point of progress. This direction is too complicated: Media needs to be a lot more sophisticated to allow dynamic and interactive media at the level of FontPacks. (A bit like Player handles audio playback.) This will be reverted. FontPack management will happen using an another method.
Diffstat (limited to 'src/media.c')
-rw-r--r--src/media.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/media.c b/src/media.c
index 0ce2ac5c..412205a7 100644
--- a/src/media.c
+++ b/src/media.c
@@ -312,15 +312,19 @@ void deinit_GmFontpack(iGmFontpack *d) {
312 312
313static void loadData_GmFontpack_(iGmFontpack *d, const iBlock *data) { 313static void loadData_GmFontpack_(iGmFontpack *d, const iBlock *data) {
314 const iString *loadPath = collect_String(localFilePathFromUrl_String(&d->props.url)); 314 const iString *loadPath = collect_String(localFilePathFromUrl_String(&d->props.url));
315 const iFontPack *pack = findPack_Fonts(loadPath); 315 const iFontPack *pack = packByPath_Fonts(loadPath);
316 d->info.isValid = d->info.isInstalled = pack != NULL; 316 d->info.isValid = d->info.isInstalled = pack != NULL;
317 d->info.isReadOnly = iFalse; 317 d->info.isReadOnly = iFalse;
318 d->info.isDisabled = iFalse;
319 clear_StringList(d->info.names);
320 clear_String(&d->packId);
318 if (!pack) { 321 if (!pack) {
319 /* Let's load it now temporarily and see what's inside. */ 322 /* Let's load it now temporarily and see what's inside. */
320 iArchive *zip = new_Archive(); 323 iArchive *zip = new_Archive();
321 if (openData_Archive(zip, data)) { 324 if (openData_Archive(zip, data)) {
322 iFontPack *fp = collect_FontPack(new_FontPack()); 325 iFontPack *fp = collect_FontPack(new_FontPack());
323 setLoadPath_FontPack(fp, loadPath); 326 setLoadPath_FontPack(fp, loadPath);
327 /* TODO: No need to load all the font files here, just the metadata. */
324 setStandalone_FontPack(fp, iTrue); 328 setStandalone_FontPack(fp, iTrue);
325 if (loadArchive_FontPack(fp, zip)) { 329 if (loadArchive_FontPack(fp, zip)) {
326 d->info.isValid = iTrue; 330 d->info.isValid = iTrue;
@@ -334,6 +338,7 @@ static void loadData_GmFontpack_(iGmFontpack *d, const iBlock *data) {
334 d->info.packId.id = &d->packId; /* we own this String */ 338 d->info.packId.id = &d->packId; /* we own this String */
335 d->info.packId.version = id_FontPack(pack).version; 339 d->info.packId.version = id_FontPack(pack).version;
336 d->info.isReadOnly = isReadOnly_FontPack(pack); 340 d->info.isReadOnly = isReadOnly_FontPack(pack);
341 d->info.isDisabled = contains_StringSet(prefs_App()->disabledFontPacks, &d->packId);
337 } 342 }
338 iPtrSet *unique = new_PtrSet(); 343 iPtrSet *unique = new_PtrSet();
339 iConstForEach(PtrArray, i, listSpecs_FontPack(pack)) { 344 iConstForEach(PtrArray, i, listSpecs_FontPack(pack)) {
@@ -455,7 +460,7 @@ iBool setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlo
455 const iBool isPartial = (flags & partialData_MediaFlag) != 0; 460 const iBool isPartial = (flags & partialData_MediaFlag) != 0;
456 const iBool allowHide = (flags & allowHide_MediaFlag) != 0; 461 const iBool allowHide = (flags & allowHide_MediaFlag) != 0;
457 const iBool isDeleting = (!mime || !data); 462 const iBool isDeleting = (!mime || !data);
458 iMediaId existing = findMediaForLink_Media(d, linkId, none_MediaType);// findLinkImage_Media(d, linkId); 463 iMediaId existing = findMediaForLink_Media(d, linkId, none_MediaType);
459 const size_t existingIndex = index_MediaId(existing); 464 const size_t existingIndex = index_MediaId(existing);
460 iBool isNew = iFalse; 465 iBool isNew = iFalse;
461 if (existing.type == image_MediaType) { 466 if (existing.type == image_MediaType) {
@@ -574,17 +579,34 @@ static iMediaId findMediaPtr_Media_(const iPtrArray *items, enum iMediaType medi
574 579
575iMediaId findMediaForLink_Media(const iMedia *d, iGmLinkId linkId, enum iMediaType mediaType) { 580iMediaId findMediaForLink_Media(const iMedia *d, iGmLinkId linkId, enum iMediaType mediaType) {
576 /* TODO: Use hashes, this will get very slow if there is a large number of media items. */ 581 /* TODO: Use hashes, this will get very slow if there is a large number of media items. */
577 iMediaId mid; 582 iMediaId mid = iInvalidMediaId;
578 for (int i = 0; i < max_MediaType; i++) { 583 for (int i = 0; i < max_MediaType; i++) {
579 if (mediaType == i || !mediaType) { 584 if (mediaType == i || !mediaType) {
580 mid = findMediaPtr_Media_(&d->items[i], i, linkId); 585 mid = findMediaPtr_Media_(&d->items[i], i, linkId);
581 if (mid.type) { 586 if (mid.type) {
582 return mid; 587 break;
583 } 588 }
584 } 589 }
585 } 590 }
586 return iInvalidMediaId; 591 return mid;
592}
593
594#if 0
595iMediaId findUrl_Media(const iMedia *d, const iString *url) {
596 iMediaId mid = iInvalidMediaId;
597 for (int i = 0; i < max_MediaType; i++) {
598 for (int j = 0; j < size_PtrArray(&d->items[i]); j++) {
599 const iGmMediaProps *props = constAt_PtrArray(&d->items[i], j);
600 if (equal_String(&props->url, url)) {
601 mid.type = i;
602 mid.id = j + 1;
603 break;
604 }
605 }
606 }
607 return mid;
587} 608}
609#endif
588 610
589size_t numAudio_Media(const iMedia *d) { 611size_t numAudio_Media(const iMedia *d) {
590 return size_PtrArray(&d->items[audio_MediaType]); 612 return size_PtrArray(&d->items[audio_MediaType]);