{-# LANGUAGE OverloadedStrings #-}

-- | Random GTK utils
module Yi.Frontend.Pango.Utils where

import Control.Exception (catch, throw)

import Data.Text (append)
import Paths_yi_frontend_pango
import System.FilePath
import Graphics.UI.Gtk
import System.Glib.GError

loadIcon :: FilePath -> IO Pixbuf
loadIcon :: FilePath -> IO Pixbuf
loadIcon fpath :: FilePath
fpath = do
  FilePath
iconfile <- FilePath -> IO FilePath
getDataFileName (FilePath -> IO FilePath) -> FilePath -> IO FilePath
forall a b. (a -> b) -> a -> b
$ "art" FilePath -> FilePath -> FilePath
</> FilePath
fpath
  Pixbuf
icoProject <-
    IO Pixbuf -> (GError -> IO Pixbuf) -> IO Pixbuf
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch (FilePath -> IO Pixbuf
forall fp. GlibFilePath fp => fp -> IO Pixbuf
pixbufNewFromFile FilePath
iconfile)
    (\(GError dom :: GErrorDomain
dom code :: GErrorCode
code msg :: GErrorMessage
msg) ->
      GError -> IO Pixbuf
forall a e. Exception e => e -> a
throw (GError -> IO Pixbuf) -> GError -> IO Pixbuf
forall a b. (a -> b) -> a -> b
$ GErrorDomain -> GErrorCode -> GErrorMessage -> GError
GError GErrorDomain
dom GErrorCode
code (GErrorMessage -> GError) -> GErrorMessage -> GError
forall a b. (a -> b) -> a -> b
$
        GErrorMessage
msg GErrorMessage -> GErrorMessage -> GErrorMessage
`append` " -- use the yi_datadir environment variable to"
            GErrorMessage -> GErrorMessage -> GErrorMessage
`append` " specify an alternate location")
  Pixbuf -> Maybe (Word8, Word8, Word8) -> IO Pixbuf
pixbufAddAlpha Pixbuf
icoProject ((Word8, Word8, Word8) -> Maybe (Word8, Word8, Word8)
forall a. a -> Maybe a
Just (0,255,0))