Skip to content
This repository
Browse code

cache avatars

  • Loading branch information...
commit 3de6222555e8c0bd09a71432646937943631622e 1 parent 607d8a7
Paul Philippov authored

Showing 1 changed file with 6 additions and 2 deletions. Show diff stats Hide diff stats

  1. 8  lib/grumblr/ui.rb
8  lib/grumblr/ui.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'gtk2'
2 2
 require 'open-uri'
  3
+require 'ftools'
3 4
 
4 5
 module Grumblr
5 6
 
@@ -387,12 +388,15 @@ def scrollable(widget)
387 388
     end
388 389
 
389 390
     def pixbuffer_from_url(url)
  391
+      cache_dir = File.expand_path(File.join('~', '.cache', Grumblr::APP_NAME.downcase))
  392
+      FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
  393
+      file = File.join(cache_dir, File.basename(url))
  394
+      File.open(file, 'w') { |f| f.write(open(url).read) } unless File.exists?(file)
390 395
       pb = Gdk::PixbufLoader.new
391 396
       pb.set_size 16, 16
392  
-      pb.last_write(open(url) { |f| f.read })
  397
+      pb.last_write(open(file) { |f| f.read })
393 398
       pb.pixbuf
394 399
     end
395  
-
396 400
   end
397 401
 
398 402
   class MessageDialog < Gtk::Dialog

0 notes on commit 3de6222

Please sign in to comment.
Something went wrong with that request. Please try again.