NSButton+WebCache.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDWebImageCompat.h"
  9. #if SD_MAC
  10. #import "SDWebImageManager.h"
  11. @interface NSButton (WebCache)
  12. #pragma mark - Image
  13. /**
  14. * Get the current image URL.
  15. */
  16. - (nullable NSURL *)sd_currentImageURL;
  17. /**
  18. * Set the button `image` with an `url`.
  19. *
  20. * The download is asynchronous and cached.
  21. *
  22. * @param url The url for the image.
  23. */
  24. - (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
  25. /**
  26. * Set the button `image` with an `url` and a placeholder.
  27. *
  28. * The download is asynchronous and cached.
  29. *
  30. * @param url The url for the image.
  31. * @param placeholder The image to be set initially, until the image request finishes.
  32. * @see sd_setImageWithURL:placeholderImage:options:
  33. */
  34. - (void)sd_setImageWithURL:(nullable NSURL *)url
  35. placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  36. /**
  37. * Set the button `image` with an `url`, placeholder and custom options.
  38. *
  39. * The download is asynchronous and cached.
  40. *
  41. * @param url The url for the image.
  42. * @param placeholder The image to be set initially, until the image request finishes.
  43. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  44. */
  45. - (void)sd_setImageWithURL:(nullable NSURL *)url
  46. placeholderImage:(nullable UIImage *)placeholder
  47. options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
  48. /**
  49. * Set the button `image` with an `url`.
  50. *
  51. * The download is asynchronous and cached.
  52. *
  53. * @param url The url for the image.
  54. * @param completedBlock A block called when operation has been completed. This block has no return value
  55. * and takes the requested UIImage as first parameter. In case of error the image parameter
  56. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  57. * indicating if the image was retrieved from the local cache or from the network.
  58. * The fourth parameter is the original image url.
  59. */
  60. - (void)sd_setImageWithURL:(nullable NSURL *)url
  61. completed:(nullable SDExternalCompletionBlock)completedBlock;
  62. /**
  63. * Set the button `image` with an `url`, placeholder.
  64. *
  65. * The download is asynchronous and cached.
  66. *
  67. * @param url The url for the image.
  68. * @param placeholder The image to be set initially, until the image request finishes.
  69. * @param completedBlock A block called when operation has been completed. This block has no return value
  70. * and takes the requested UIImage as first parameter. In case of error the image parameter
  71. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  72. * indicating if the image was retrieved from the local cache or from the network.
  73. * The fourth parameter is the original image url.
  74. */
  75. - (void)sd_setImageWithURL:(nullable NSURL *)url
  76. placeholderImage:(nullable UIImage *)placeholder
  77. completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  78. /**
  79. * Set the button `image` with an `url`, placeholder and custom options.
  80. *
  81. * The download is asynchronous and cached.
  82. *
  83. * @param url The url for the image.
  84. * @param placeholder The image to be set initially, until the image request finishes.
  85. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  86. * @param completedBlock A block called when operation has been completed. This block has no return value
  87. * and takes the requested UIImage as first parameter. In case of error the image parameter
  88. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  89. * indicating if the image was retrieved from the local cache or from the network.
  90. * The fourth parameter is the original image url.
  91. */
  92. - (void)sd_setImageWithURL:(nullable NSURL *)url
  93. placeholderImage:(nullable UIImage *)placeholder
  94. options:(SDWebImageOptions)options
  95. completed:(nullable SDExternalCompletionBlock)completedBlock;
  96. /**
  97. * Set the button `image` with an `url`, placeholder and custom options.
  98. *
  99. * The download is asynchronous and cached.
  100. *
  101. * @param url The url for the image.
  102. * @param placeholder The image to be set initially, until the image request finishes.
  103. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  104. * @param progressBlock A block called while image is downloading
  105. * @note the progress block is executed on a background queue
  106. * @param completedBlock A block called when operation has been completed. This block has no return value
  107. * and takes the requested UIImage as first parameter. In case of error the image parameter
  108. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  109. * indicating if the image was retrieved from the local cache or from the network.
  110. * The fourth parameter is the original image url.
  111. */
  112. - (void)sd_setImageWithURL:(nullable NSURL *)url
  113. placeholderImage:(nullable UIImage *)placeholder
  114. options:(SDWebImageOptions)options
  115. progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  116. completed:(nullable SDExternalCompletionBlock)completedBlock;
  117. #pragma mark - Alternate Image
  118. /**
  119. * Get the current alternateImage URL.
  120. */
  121. - (nullable NSURL *)sd_currentAlternateImageURL;
  122. /**
  123. * Set the button `alternateImage` with an `url`.
  124. *
  125. * The download is asynchronous and cached.
  126. *
  127. * @param url The url for the alternateImage.
  128. */
  129. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
  130. /**
  131. * Set the button `alternateImage` with an `url` and a placeholder.
  132. *
  133. * The download is asynchronous and cached.
  134. *
  135. * @param url The url for the alternateImage.
  136. * @param placeholder The alternateImage to be set initially, until the alternateImage request finishes.
  137. * @see sd_setAlternateImageWithURL:placeholderImage:options:
  138. */
  139. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  140. placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  141. /**
  142. * Set the button `alternateImage` with an `url`, placeholder and custom options.
  143. *
  144. * The download is asynchronous and cached.
  145. *
  146. * @param url The url for the alternateImage.
  147. * @param placeholder The alternateImage to be set initially, until the alternateImage request finishes.
  148. * @param options The options to use when downloading the alternateImage. @see SDWebImageOptions for the possible values.
  149. */
  150. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  151. placeholderImage:(nullable UIImage *)placeholder
  152. options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
  153. /**
  154. * Set the button `alternateImage` with an `url`.
  155. *
  156. * The download is asynchronous and cached.
  157. *
  158. * @param url The url for the alternateImage.
  159. * @param completedBlock A block called when operation has been completed. This block has no return value
  160. * and takes the requested UIImage as first parameter. In case of error the alternateImage parameter
  161. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  162. * indicating if the alternateImage was retrieved from the local cache or from the network.
  163. * The fourth parameter is the original alternateImage url.
  164. */
  165. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  166. completed:(nullable SDExternalCompletionBlock)completedBlock;
  167. /**
  168. * Set the button `alternateImage` with an `url`, placeholder.
  169. *
  170. * The download is asynchronous and cached.
  171. *
  172. * @param url The url for the alternateImage.
  173. * @param placeholder The alternateImage to be set initially, until the alternateImage request finishes.
  174. * @param completedBlock A block called when operation has been completed. This block has no return value
  175. * and takes the requested UIImage as first parameter. In case of error the alternateImage parameter
  176. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  177. * indicating if the alternateImage was retrieved from the local cache or from the network.
  178. * The fourth parameter is the original alternateImage url.
  179. */
  180. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  181. placeholderImage:(nullable UIImage *)placeholder
  182. completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  183. /**
  184. * Set the button `alternateImage` with an `url`, placeholder and custom options.
  185. *
  186. * The download is asynchronous and cached.
  187. *
  188. * @param url The url for the alternateImage.
  189. * @param placeholder The alternateImage to be set initially, until the alternateImage request finishes.
  190. * @param options The options to use when downloading the alternateImage. @see SDWebImageOptions for the possible values.
  191. * @param completedBlock A block called when operation has been completed. This block has no return value
  192. * and takes the requested UIImage as first parameter. In case of error the alternateImage parameter
  193. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  194. * indicating if the alternateImage was retrieved from the local cache or from the network.
  195. * The fourth parameter is the original alternateImage url.
  196. */
  197. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  198. placeholderImage:(nullable UIImage *)placeholder
  199. options:(SDWebImageOptions)options
  200. completed:(nullable SDExternalCompletionBlock)completedBlock;
  201. /**
  202. * Set the button `alternateImage` with an `url`, placeholder and custom options.
  203. *
  204. * The download is asynchronous and cached.
  205. *
  206. * @param url The url for the alternateImage.
  207. * @param placeholder The alternateImage to be set initially, until the alternateImage request finishes.
  208. * @param options The options to use when downloading the alternateImage. @see SDWebImageOptions for the possible values.
  209. * @param progressBlock A block called while alternateImage is downloading
  210. * @note the progress block is executed on a background queue
  211. * @param completedBlock A block called when operation has been completed. This block has no return value
  212. * and takes the requested UIImage as first parameter. In case of error the alternateImage parameter
  213. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  214. * indicating if the alternateImage was retrieved from the local cache or from the network.
  215. * The fourth parameter is the original alternateImage url.
  216. */
  217. - (void)sd_setAlternateImageWithURL:(nullable NSURL *)url
  218. placeholderImage:(nullable UIImage *)placeholder
  219. options:(SDWebImageOptions)options
  220. progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  221. completed:(nullable SDExternalCompletionBlock)completedBlock;
  222. #pragma mark - Cancel
  223. /**
  224. * Cancel the current image download
  225. */
  226. - (void)sd_cancelCurrentImageLoad;
  227. /**
  228. * Cancel the current alternateImage download
  229. */
  230. - (void)sd_cancelCurrentAlternateImageLoad;
  231. @end
  232. #endif