Debian Codegraph @

core/mui/gtk_web_image_loader.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # 画像のURLを受け取って、Gtk::Pixbufを返す
3
4 require 'serialthread'
5 require 'skin'
6
7 require 'addressable/uri'
8 require 'fileutils'
9 require 'net/http'
10 require 'thread'
11 require 'uri'
12
13 module Gdk::WebImageLoader
14 extend Gdk::WebImageLoader
15 extend Gem::Deprecate
16
17 # mikutter 3.5から、このメソッドはDeprecateです。
18 # 今後は、次のようなコードを書いてください。
19 # ==== Example
20 # photo = Plugin.collect(:photo_filter, url).first
21 # photo.load_pixbuf(width: width, height: height, &load_callback)
22 def pixbuf(url, width, height = nil, &load_callback)
23 if width.respond_to?(:width) and width.respond_to?(:height)
24 width, height = width.width, width.height
25 end
26 if load_callback
27 Plugin.collect(:photo_filter, url, Pluggaloid::COLLECT)
28 .first
29 .load_pixbuf(width: width, height: height, &load_callback)
30 else
31 Plugin.collect(:photo_filter, url, Pluggaloid::COLLECT)
32 .first
33 .pixbuf(width: width, height: height)
34 end
35 rescue => err
36 warn err
37 Skin[:notfound].pixbuf(width: width, height: height)
38 end
39 deprecate :pixbuf, "Diva::Model::PhotoMixin#load_pixbuf", 2018, 1 if Environment::VERSION >= [3, 6]
40
41 # mikutter 3.5から、このメソッドはDeprecateです。
42 def local_path(url, width = 48, height = width)
43 url.freeze
44 ext = (File.extname(url).split("?", 2)[0] or File.extname(url))
45 filename = File.expand_path(File.join(Environment::TMPDIR, Digest::MD5.hexdigest(url + "#{width}x#{height}") + ext + '.png'))
46 pb = pixbuf(url, width, height)
47 if(pb)
48 pb.save(filename, 'png') if not FileTest.exist?(filename)
49 local_path_files_add(filename)
50 filename end end
51 deprecate :local_path, :none, 2018, 1 if Environment::VERSION >= [3, 6]
52
53 # mikutter 3.5から、このメソッドはDeprecateです。
54 # 今後は、次のようなコードを書いてください。
55 # ==== Example
56 # photo = Plugin.collect(:photo_filter, url).first
57 # photo.download.next(&load_callback).trap{|exception|
58 # # ダウンロードに失敗した時に呼ばれる
59 # }
60 def get_raw_data(url, &load_callback) # :yield: raw, exception, url
61 result = Enumerator.new{|y|
62 Plugin.filtering(:photo_filter, url, y)
63 }.blob
64 if result
65 result
66 else
67 Enumerator.new{|y|
68 Plugin.filtering(:photo_filter, url, y)
69 }.download do |photo|
70 load_callback.(photo.blob)
71 end
72 :wait
73 end
74 end
75 deprecate :get_raw_data, "Diva::Model::PhotoMixin#download", 2018, 1 if Environment::VERSION >= [3, 6]
76
77 # mikutter 3.5から、このメソッドはDeprecateです。
78 # 今後は、次のようなコードを書いてください。
79 # ==== Example
80 # photo = Plugin.collect(:photo_filter, url).first
81 # photo.download
82 def get_raw_data_d(url)
83 Enumerator.new{|y|
84 Plugin.filtering(:photo_filter, url, y)
85 }.download.next{|photo| photo.blob }
86 end
87 deprecate :get_raw_data_d, "Diva::Model::PhotoMixin#download", 2018, 1 if Environment::VERSION >= [3, 6]
88
89 # mikutter 3.5から、このメソッドはDeprecateです。
90 def is_local_path?(url)
91 not url.start_with?('http') end
92 deprecate :is_local_path?, :none, 2018, 1 if Environment::VERSION >= [3, 6]
93
94 # mikutter 3.5から、このメソッドはDeprecateです。
95 # 今後は、次のようなコードを書いてください。
96 # ==== Example
97 # Skin[:loading].pixbuf(width: width, height: height)
98 def loading_pixbuf(rect, height = nil)
99 if height
100 Skin[:loading].pixbuf(width: rect, height: height)
101 else
102 Skin[:loading].pixbuf(width: rect.width, height: rect.height)
103 end
104 end
105 deprecate :loading_pixbuf, 'Skin[\'loading.png\'].pixbuf(width: width, height: height)', 2018, 1 if Environment::VERSION >= [3, 6]
106
107 # mikutter 3.5から、このメソッドはDeprecateです。
108 # 今後は、次のようなコードを書いてください。
109 # ==== Example
110 # Skin[:notfound].pixbuf(width: width, height: height)
111 def notfound_pixbuf(rect, height = nil)
112 if height
113 Skin[:notfound].pixbuf(width: rect, height: height)
114 else
115 Skin[:notfound].pixbuf(width: rect.width, height: rect.height)
116 end
117 end
118 deprecate :notfound_pixbuf, 'Skin[\'notfound.png\'].pixbuf(width: width, height: height)', 2018, 1 if Environment::VERSION >= [3, 6]
119 private
120
121 def local_path_files_add(path)
122 atomic{
123 if not defined?(@local_path_files)
124 @local_path_files = Set.new
125 at_exit{ FileUtils.rm(@local_path_files.to_a) } end }
126 @local_path_files << path
127 end
128 end
129
130 module Gdk
131 deprecate_constant :WebImageLoader if respond_to?(:deprecate_constant) and Environment::VERSION >= [3, 6]
132 end