Created
May 19, 2012 14:16
-
-
Save xenophobia/2730959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- GUILibrary.hs | |
-- アイコン画像を取得 | |
getIcon :: String -> IO String | |
getIcon url = do | |
let outFile = "./icon/" ++ urlEncode url | |
fileExist <- doesFileExist outFile | |
if fileExist | |
then return outFile | |
else do | |
let request = defaultGETRequest $ fromJust $ parseURI url | |
iconImage <- getResponseBody =<< simpleHTTP request | |
fin <- openBinaryFile outFile WriteMode | |
hPutStr fin iconImage | |
hClose fin | |
return outFile | |
-- HshstterMain.hs(IconTableはHashTable String String、GUI.IconはPixbufの、それぞれ型シノニム) | |
-- アイコンのPixbufを取得 | |
getIconImage :: IconTable -> Tweet -> IO GUI.Icon | |
getIconImage iconTable twt = do | |
icon <- Hash.lookup iconTable (profile_image_url twt) | |
pixbufNewFromFile =<< case icon of {Nothing -> getAndRegisterIcon; Just ic -> return ic} | |
where getAndRegisterIcon = do | |
ic <- getIcon (profile_image_url twt) | |
Hash.insert iconTable (profile_image_url twt) ic | |
return ic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment