blob: d03d7c1f84e6c6999684bcb632833697f6f991ef [file] [log] [blame]
{-# LANGUAGE DeriveDataTypeable #-}
-- Copyright (C) 2009-2011 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/>.
module Gnome.Keyring.Internal.Types
( Keyring(..)
, defaultKeyring
, keyring
, CancellationKey (..)
, KeyringError(..)
, keyringErrorMessage
, KeyringException (..)
, Result (..)
, result
, resultAndTuple
) where
import Control.Exception (Exception)
import Data.Typeable (Typeable)
import Foreign (Ptr)
#include <gnome-keyring.h>
data Keyring
= DefaultKeyring
| NamedKeyring String
deriving (Eq, Show)
defaultKeyring :: Keyring
defaultKeyring = DefaultKeyring
keyring :: String -> Keyring
keyring = NamedKeyring
newtype CancellationKey = CancellationKey (Ptr ())
newtype KeyringError = KeyringError String
deriving (Eq, Show)
keyringErrorMessage :: KeyringError -> String
keyringErrorMessage (KeyringError msg) = msg
newtype KeyringException = KeyringException KeyringError
deriving (Show, Eq, Typeable)
instance Exception KeyringException
{# enum GnomeKeyringResult as Result {}
with prefix = "gnome_keyring_"
deriving (Show) #}
result :: Integral a => a -> Result
result = toEnum . fromIntegral
resultAndTuple :: Integral a => a -> (Result, ())
resultAndTuple x = (result x, ())