-- GENERATED by C->Haskell Compiler, version 0.16.0 Crystal Seed, 24 Jan 2009 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./Gnome/Keyring/Internal/Types.chs" #-}-- Copyright (C) 2009 John Millikin <jmillikin@gmail.com>
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-- 
{-# LANGUAGE DeriveDataTypeable #-}
module Gnome.Keyring.Internal.Types
	( KeyringName
	, CancellationKey (..)
	, Error (..)
	, Result (..)
	, resultToError
	, result
	, resultAndTuple
	) where
import Data.Text.Lazy (Text)
import Foreign (Ptr)
import Control.Exception (Exception)
import Data.Typeable (Typeable)

type KeyringName = Text

newtype CancellationKey = CancellationKey (Ptr ())

data Error
	= ErrorDenied
	| ErrorNoKeyringDaemon
	| ErrorAlreadyUnlocked
	| ErrorNoSuchKeyring
	| ErrorBadArguments
	| ErrorIOError
	| ErrorCancelled
	| ErrorKeyringAlreadyExists
	| ErrorNoMatch
	deriving (Show, Eq, Typeable)

instance Exception Error

data Result = RESULT_OK
            | RESULT_DENIED
            | RESULT_NO_KEYRING_DAEMON
            | RESULT_ALREADY_UNLOCKED
            | RESULT_NO_SUCH_KEYRING
            | RESULT_BAD_ARGUMENTS
            | RESULT_IO_ERROR
            | RESULT_CANCELLED
            | RESULT_KEYRING_ALREADY_EXISTS
            | RESULT_NO_MATCH
            deriving (Enum,Show)

{-# LINE 52 "./Gnome/Keyring/Internal/Types.chs" #-}

resultToError :: Result -> Error
resultToError RESULT_DENIED = ErrorDenied
resultToError RESULT_NO_KEYRING_DAEMON = ErrorNoKeyringDaemon
resultToError RESULT_ALREADY_UNLOCKED = ErrorAlreadyUnlocked
resultToError RESULT_NO_SUCH_KEYRING = ErrorNoSuchKeyring
resultToError RESULT_BAD_ARGUMENTS = ErrorBadArguments
resultToError RESULT_IO_ERROR = ErrorIOError
resultToError RESULT_CANCELLED = ErrorCancelled
resultToError RESULT_KEYRING_ALREADY_EXISTS = ErrorKeyringAlreadyExists
resultToError RESULT_NO_MATCH = ErrorNoMatch
resultToError x = error $ "Not an error: " ++ show x

result :: Integral a => a -> Result
result = toEnum . fromIntegral

resultAndTuple :: Integral a => a -> (Result, ())
resultAndTuple x = (result x, ())