• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

D wrapper around (some) of the pixiv web API


Commit MetaInfo

Révisionfff4a231002b0048fdae574183f4343848f0bfeb (tree)
l'heure2023-08-13 10:11:17
Auteursupercell <stigma@disr...>
Commitersupercell

Message de Log

Add signals for download progress and completion

This makes use of std.signals. This will emit the DownloadProgressEvent
when downloading individual pages or the ZIP (in the case of Ugoira).

The DownloadCompleteEvent is emitted after the file being written to has
been closed.

Change Summary

Modification

--- a/source/pixivd/client.d
+++ b/source/pixivd/client.d
@@ -6,6 +6,7 @@ import std.array : appender;
66 import std.format : format;
77 import std.json;
88 import std.net.curl : HTTP;
9+import std.signals;
910
1011 import graphicsmagick_c;
1112 import graphicsmagick_c.magick.api;
@@ -17,6 +18,16 @@ import pixivd.types;
1718 public enum PixivDVersion = 0.8;
1819 public enum PixivDVersionString = "0.8";
1920
21+struct DownloadProgressEvent
22+{
23+ size_t total;
24+ size_t current;
25+}
26+
27+struct DownloadCompleteEvent
28+{
29+}
30+
2031 /**
2132 *
2233 * The main client for performing pixiv API requests.
@@ -85,6 +96,10 @@ public:
8596 }
8697 }
8798
99+ /* Signals */
100+ mixin Signal!(DownloadProgressEvent);
101+ mixin Signal!(DownloadCompleteEvent);
102+
88103 /**
89104 * Fetch an illustration
90105 *
@@ -713,9 +728,14 @@ private:
713728 imageFile.rawWrite(data);
714729 return data.length;
715730 };
731+ m_client.onProgress = (size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) {
732+ emit(DownloadProgressEvent(dlTotal, dlNow));
733+ return 0;
734+ };
716735
717736 m_client.perform();
718737 imageFile.close();
738+ emit(DownloadCompleteEvent());
719739
720740 SysTime createDate = SysTime.fromISOExtString(illust.createDate);
721741
@@ -769,9 +789,15 @@ private:
769789 img.rawWrite(data);
770790 return data.length;
771791 };
792+ m_client.onProgress = (size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) {
793+ emit(DownloadProgressEvent(dlTotal, dlNow));
794+ return 0;
795+ };
796+
772797
773798 m_client.perform();
774799 img.close();
800+ emit(DownloadCompleteEvent());
775801 }
776802 }
777803
@@ -823,8 +849,13 @@ private:
823849 outFile.rawWrite(data);
824850 return data.length;
825851 };
852+ m_client.onProgress = (size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) {
853+ emit(DownloadProgressEvent(dlTotal, dlNow));
854+ return 0;
855+ };
826856 m_client.perform();
827857 outFile.close();
858+ emit(DownloadCompleteEvent());
828859
829860 SysTime createDate = SysTime.fromISOExtString(illust.createDate);
830861
@@ -887,6 +918,10 @@ private:
887918 zipFile.rawWrite(data);
888919 return data.length;
889920 };
921+ m_client.onProgress = (size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) {
922+ emit(DownloadProgressEvent(dlTotal, dlNow));
923+ return 0;
924+ };
890925
891926 m_client.perform();
892927 zipFile.close();
@@ -977,5 +1012,6 @@ private:
9771012 }
9781013
9791014 DestroyExceptionInfo(&exception);
1015+ emit(DownloadCompleteEvent());
9801016 }
9811017 }