Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created May 19, 2012 14:16
Show Gist options
  • Save xenophobia/2730959 to your computer and use it in GitHub Desktop.
Save xenophobia/2730959 to your computer and use it in GitHub Desktop.
-- 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