File: MountOperation.chs

package info (click to toggle)
haskell-gio 0.13.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: haskell: 169; makefile: 10
file content (183 lines) | stat: -rw-r--r-- 6,896 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{-# LANGUAGE CPP #-}
--  GIMP Toolkit (GTK) Binding for Haskell: binding to gio -*-haskell-*-
--
--  Author : Andy Stewart
--  Created: 30-Apirl-2010
--
--  Copyright (c) 2010 Andy Stewart
--
--  This library is free software: you can redistribute it and/or
--  modify it under the terms of the GNU Lesser General Public License
--  as published by the Free Software Foundation, either version 3 of
--  the License, or (at your option) any later version.
--
--  This library 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
--  Lesser General Public License for more details.
--
--  You should have received a copy of the GNU Lesser General Public
--  License along with this program.  If not, see
--  <http://www.gnu.org/licenses/>.
--
--  GIO, the C library which this Haskell library depends on, is
--  available under LGPL Version 2. The documentation included with
--  this library is based on the original GIO documentation.
--
-- | Maintainer  : gtk2hs-devel@lists.sourceforge.net
--   Stability   : alpha
--   Portability : portable (depends on GHC)
module System.GIO.File.MountOperation (
-- * Details
--
-- | 'MountOperation' provides a mechanism for interacting with the user. It can be used for
-- authenticating mountable operations, such as loop mounting files, hard drive partitions or server
-- locations. It can also be used to ask the user questions or show a list of applications preventing
-- unmount or eject operations from completing.
--
-- Note that 'Mount'Operation is used for more than just 'Mount' objects – for example it is also used in
-- 'driveStart'.
--
-- Users should instantiate a subclass of this that implements all the various callbacks to show the
-- required dialogs, such as 'MountOperation'. If no user interaction is desired (for example when
-- automounting filesystems at login time), usually 'Nothing' can be passed, see each method taking a
-- 'MountOperation' for details.

-- * Types
   MountOperation(..),
   MountOperationClass,

-- * Enums
   MountOperationResult(..),
   AskPasswordFlags(..),
   PasswordSave(..),

-- * Methods
    mountOperationNew,
    mountOperationReply,

-- * Attributes
    mountOperationAnonymous,
    mountOperationChoice,
    mountOperationDomain,
    mountOperationPassword,
    mountOperationPasswordSave,
    mountOperationUsername,

-- * Signals
#if GLIB_CHECK_VERSION(2,20,0)
    mountOperationAborted,
    mountOperationAskPassword,
    -- askQuestion,
    mountOperationReplySignal,
    -- showProcesses,
#endif
    ) where

#include <gio/gio.h>

import Control.Monad
import System.GIO.Enums
import System.Glib.Attributes
import System.Glib.FFI
import System.Glib.Flags
import System.Glib.GError
import System.Glib.GObject
import System.Glib.Properties
import System.Glib.Signals
import System.Glib.UTFString
{#import System.GIO.Signals#}
{#import System.GIO.Types#}

{# context lib = "gio" prefix = "g" #}

--------------------
-- Methods

-- | Creates a new mount operation.
mountOperationNew :: IO MountOperation
mountOperationNew =
    wrapNewGObject mkMountOperation $
    {# call g_mount_operation_new #}

-- | Emits the "reply" signal.
mountOperationReply :: MountOperationClass op => op -> MountOperationResult -> IO ()
mountOperationReply op result =
  {#call g_mount_operation_reply#} (toMountOperation op) ((fromIntegral . fromEnum) result)

--------------------
-- Attributes
-- | Whether to use an anonymous user when authenticating.
--
-- Default value: 'False'
mountOperationAnonymous :: MountOperationClass op => Attr op Bool
mountOperationAnonymous = newAttrFromBoolProperty "anonymous"

-- | The index of the user's choice when a question is asked during the mount operation. See the
-- 'askQuestion' signal.
--
-- Allowed values: >= 0
--
-- Default value: 0
mountOperationChoice :: MountOperationClass op => Attr op Int
mountOperationChoice = newAttrFromIntProperty "choice"

-- | The domain to use for the mount operation.
--
-- Default value: \"\"
mountOperationDomain :: (MountOperationClass op, GlibString string) => Attr op string
mountOperationDomain = newAttrFromStringProperty "domain"

-- | The password that is used for authentication when carrying out the mount operation.
--
-- Default value: \"\"
mountOperationPassword :: (MountOperationClass op, GlibString string) => Attr op string
mountOperationPassword = newAttrFromStringProperty "password"

-- | Determines if and how the password information should be saved.
--
-- Default value: 'PasswordSaveNever'
mountOperationPasswordSave :: MountOperationClass op => Attr op PasswordSave
mountOperationPasswordSave = newAttrFromEnumProperty "password-save"
               {#call pure unsafe g_password_save_get_type #}

-- | The user name that is used for authentication when carrying out the mount operation.
--
-- Default value: \"\"
mountOperationUsername :: (MountOperationClass op, GlibString string) => Attr op string
mountOperationUsername = newAttrFromStringProperty "username"

--------------------
-- Signals
#if GLIB_CHECK_VERSION(2,20,0)
-- | Emitted by the backend when e.g. a device becomes unavailable while a mount operation is in
-- progress.
--
-- Implementations of 'MountOperation' should handle this signal by dismissing open password dialogs.
--
-- Since 2.20
mountOperationAborted :: MountOperationClass op => Signal op (IO ())
mountOperationAborted = Signal (connect_NONE__NONE "aborted")
#endif

-- | Emitted when a mount operation asks the user for a password.
--
-- If the message contains a line break, the first line should be presented as a heading. For example,
-- it may be used as the primary text in a 'MessageDialog'.
mountOperationAskPassword :: (MountOperationClass op, GlibString string) => Signal op (string -> string -> string -> AskPasswordFlags -> IO ())
mountOperationAskPassword = Signal (connect_GLIBSTRING_GLIBSTRING_GLIBSTRING_ENUM__NONE "ask-password")

-- | Emitted when asking the user a question and gives a list of choices for the user to choose from.
--
-- If the message contains a line break, the first line should be presented as a heading. For example,
-- it may be used as the primary text in a 'MessageDialog'.
-- askQuestion :: MountOperationClass op => Signal op (String -> [String] -> IO ())
-- askQuestion Signal (\after obj user -> connect_GLIBSTRING_BOXED__NONE "ask-question" after obj
--                                       (\message choicesPtr -> do
--                                          choices <- peekUTFString choicesPtr
--                                          user str choices))

-- | Emitted when the user has replied to the mount operation.
mountOperationReplySignal :: MountOperationClass op => Signal op (MountOperationResult -> IO ())
mountOperationReplySignal = Signal (connect_ENUM__NONE "reply")