diff options
-rw-r--r-- | core/mui/gtk_webicon.rb | 36 | ||||
-rw-r--r-- | test/core/test_gtk_webicon.rb | 26 |
2 files changed, 22 insertions, 40 deletions
diff --git a/core/mui/gtk_webicon.rb b/core/mui/gtk_webicon.rb index 0082d8d5..6e924308 100644 --- a/core/mui/gtk_webicon.rb +++ b/core/mui/gtk_webicon.rb @@ -23,21 +23,29 @@ module Gtk # [height] 画像の高さ(px) def initialize(url, rect = DEFAULT_RECTANGLE, height = nil) rect = Gdk::Rectangle.new(0, 0, rect, height) if height - if(Gdk::WebImageLoader.is_local_path?(url)) - url = File.expand_path(url) - if FileTest.exist?(url) - super begin - GdkPixbuf::Pixbuf.new(file: url, width: rect.width, height: rect.height) - rescue - Gdk::WebImageLoader.notfound_pixbuf(rect.width, rect.height) end - else - super(Gdk::WebImageLoader.notfound_pixbuf(rect.width, rect.height)) end + case url + when Retriever::Model + super(load_model(url, rect)) + when GdkPixbuf::Pixbuf + super(url) else - super(Gdk::WebImageLoader.pixbuf(url, rect.width, rect.height) { |pixbuf, success| - unless destroyed? - self.pixbuf = pixbuf - self.changed - self.notify_observers end }) end end + super(load_model(Plugin::Photo::Photo[url], rect)) + end + end + + def load_model(photo, rect) + photo.load_pixbuf(width: rect.width, height: rect.height){|pb| + update_pixbuf(pb) + } + end + + def update_pixbuf(pixbuf) + unless destroyed? + self.pixbuf = pixbuf + self.changed + self.notify_observers + end + end end end diff --git a/test/core/test_gtk_webicon.rb b/test/core/test_gtk_webicon.rb deleted file mode 100644 index bd23d720..00000000 --- a/test/core/test_gtk_webicon.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -require File.expand_path(File.dirname(__FILE__) + '/../helper') -require 'webmock' -require 'gtk2' - -require 'lib/test_unit_extensions' -miquire :mui, 'webicon' - -class TC_GtkWebIcon < Test::Unit::TestCase - def setup - end - - must "local image load" do - image = Gtk::WebIcon.new(Skin.get('icon.png'), 48, 48) - assert_kind_of(GdkPixbuf::Pixbuf, image.pixbuf) - assert_not_equal(Gdk::WebImageLoader.loading_pixbuf(48, 48), image.pixbuf) - assert_not_equal(Gdk::WebImageLoader.notfound_pixbuf(48, 48), image.pixbuf) - end - - must "local image not found" do - image = Gtk::WebIcon.new('notfound-file', 48, 48) - assert_kind_of(GdkPixbuf::Pixbuf, image.pixbuf) - assert_equal(Gdk::WebImageLoader.notfound_pixbuf(48, 48), image.pixbuf) - end - -end |