File: RecentFilter.chs

package info (click to toggle)
haskell-gtk 0.15.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,964 kB
  • sloc: haskell: 3,346; ansic: 826; makefile: 161
file content (223 lines) | stat: -rw-r--r-- 6,905 bytes parent folder | download | duplicates (9)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget RecentFilter
--
--  Author : Andy Stewart
--
--  Created: 27 Mar 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 2.1 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.
--
-- |
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
-- Stability   : provisional
-- Portability : portable (depends on GHC)
--
-- A filter for selecting a subset of recently used files
--
-- * Module available since Gtk+ version 2.10
--
module Graphics.UI.Gtk.Recent.RecentFilter (

-- * Detail
--
-- | A 'RecentFilter' can be used to restrict the files being shown in a
-- 'RecentChooser'. Files can be filtered based on their name (with
-- 'recentFilterAddPattern'), on their mime type (with
-- 'fileFilterAddMimeType'), on the application that has registered them (with
-- 'recentFilterAddApplication'), or by a custom filter function (with
-- 'recentFilterAddCustom').
--
-- Filtering by mime type handles aliasing and subclassing of mime types;
-- e.g. a filter for text\/plain also matches a file with mime type
-- application\/rtf, since application\/rtf is a subclass of text\/plain. Note
-- that 'RecentFilter' allows wildcards for the subtype of a mime type, so you
-- can e.g. filter for image\/.
--
-- Normally, filters are used by adding them to a 'RecentChooser', see
-- 'recentChooserAddFilter', but it is also possible to manually use a filter
-- on a file with 'recentFilterFilter'.
--
-- Recently used files are supported since Gtk+ 2.10.

-- * Class Hierarchy
--
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----RecentFilter
-- @

#if GTK_CHECK_VERSION(2,10,0)
-- * Types
  RecentFilter,
  RecentFilterClass,
  castToRecentFilter,
  toRecentFilter,

-- * Enums
  RecentFilterFlags(..),

-- * Constructors
  recentFilterNew,

-- * Methods
  recentFilterGetName,
  recentFilterSetName,
  recentFilterAddMimeType,
  recentFilterAddPattern,
  recentFilterAddPixbufFormats,
  recentFilterAddApplication,
  recentFilterAddGroup,
  recentFilterAddAge,
#endif
  ) where

#if GTK_CHECK_VERSION(2,10,0)

import System.Glib.FFI
import System.Glib.UTFString
import Graphics.UI.Gtk.Abstract.Object  (makeNewObject)
{#import Graphics.UI.Gtk.Types#}

{# context lib="gtk" prefix="gtk" #}

---------------------
-- Enums
-- | These flags indicate what parts of a 'RecentFilterInfo' struct are filled or need to be filled.
{#enum RecentFilterFlags {underscoreToCase} deriving (Bounded,Eq,Show)#}

--------------------
-- Constructors

-- | Creates a new 'RecentFilter' with no rules added to it. Such filter does
-- not accept any recently used resources, so is not particularly useful until
-- you add rules with 'recentFilterAddPattern', 'recentFilterAddMimeType',
-- 'recentFilterAddApplication', 'recentFilterAddAge'. To create a filter that
-- accepts any recently used resource, use:
--
-- > filter <- recentFilterNew
-- > recentFilterAddPattern filter "*"
--
-- * Available since Gtk+ version 2.10
--
recentFilterNew :: IO RecentFilter
recentFilterNew =
  makeNewObject mkRecentFilter $
  {# call gtk_recent_filter_new #}

--------------------
-- Methods
-- | Gets the human-readable name for the filter. See 'recentFilterSetName'.
--
-- * Available since Gtk+ version 2.10
--
recentFilterGetName :: (RecentFilterClass self, GlibString string) => self
 -> IO string -- ^ returns the name of the filter
recentFilterGetName self =
  {# call gtk_recent_filter_get_name #}
    (toRecentFilter self)
  >>= peekUTFString

-- | Sets the human-readable name of the filter; this is the string that will be displayed in the
-- recently used resources selector user interface if there is a selectable list of filters.
--
-- * Available since Gtk+ version 2.10
--
recentFilterSetName :: (RecentFilterClass self, GlibString string) => self
 -> string -- ^ @name@ - then human readable name of @filter@
 -> IO ()
recentFilterSetName self name =
  withUTFString name $ \namePtr ->
  {# call gtk_recent_filter_set_name #}
    (toRecentFilter self)
    namePtr

-- | Adds a rule that allows resources based on their registered MIME type.
--
-- * Available since Gtk+ version 2.10
--
recentFilterAddMimeType :: (RecentFilterClass self, GlibString string) => self
 -> string -- ^ @mimeType@ - a MIME type
 -> IO ()
recentFilterAddMimeType self mimeType =
  withUTFString mimeType $ \mimeTypePtr ->
  {# call gtk_recent_filter_add_mime_type #}
    (toRecentFilter self)
    mimeTypePtr

-- | Adds a rule that allows resources based on a pattern matching their
-- display name.
--
-- * Available since Gtk+ version 2.10
--
recentFilterAddPattern :: (RecentFilterClass self, GlibString string) => self
 -> string -- ^ @pattern@ - a file pattern
 -> IO ()
recentFilterAddPattern self pattern =
  withUTFString pattern $ \patternPtr ->
  {# call gtk_recent_filter_add_pattern #}
    (toRecentFilter self)
    patternPtr

-- | Adds a rule allowing image files in the formats supported by 'Pixbuf'.
--
recentFilterAddPixbufFormats :: RecentFilterClass self => self -> IO ()
recentFilterAddPixbufFormats self =
  {# call gtk_recent_filter_add_pixbuf_formats #}
    (toRecentFilter self)

-- | Adds a rule that allows resources based on the name of the application
-- that has registered them.
--
--
-- * Available since Gtk+ version 2.10
--
recentFilterAddApplication :: (RecentFilterClass self, GlibString string) => self
 -> string -- ^ @application@ - an application name
 -> IO ()
recentFilterAddApplication self application =
  withUTFString application $ \applicationPtr ->
  {# call gtk_recent_filter_add_application #}
    (toRecentFilter self)
    applicationPtr

-- | Adds a rule that allows resources based on the name of the group to which
-- they belong
--
--
-- * Available since Gtk+ version 2.10
--
recentFilterAddGroup :: (RecentFilterClass self, GlibString string) => self
 -> string -- ^ @group@ - a group name
 -> IO ()
recentFilterAddGroup self group =
  withUTFString group $ \groupPtr ->
  {# call gtk_recent_filter_add_group #}
    (toRecentFilter self)
    groupPtr

-- | Adds a rule that allows resources based on their age - that is, the
-- number of days elapsed since they were last modified.
--
-- * Available since Gtk+ version 2.10
--
recentFilterAddAge :: RecentFilterClass self => self
 -> Int -- ^ @days@ - number of days
 -> IO ()
recentFilterAddAge self days =
  {# call gtk_recent_filter_add_age #}
    (toRecentFilter self)
    (fromIntegral days)
#endif