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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget RecentInfo
--
-- 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)
--
--
module Graphics.UI.Gtk.Recent.RecentInfo (
#if GTK_CHECK_VERSION(2,10,0)
-- * Types
RecentInfo,
mkRecentInfo,
-- * Methods
recentInfoExists,
recentInfoGetAdded,
recentInfoGetAge,
recentInfoGetApplicationInfo,
recentInfoGetApplications,
recentInfoGetDescription,
recentInfoGetDisplayName,
recentInfoGetGroups,
recentInfoGetIcon,
recentInfoGetMimeType,
recentInfoGetModified,
recentInfoGetPrivateHint,
recentInfoGetShortName,
recentInfoGetURI,
recentInfoGetURIDisplay,
recentInfoGetVisited,
recentInfoHasApplication,
recentInfoHasGroup,
recentInfoIsLocal,
recentInfoLastApplication,
recentInfoMatch,
#endif
) where
#if GTK_CHECK_VERSION(2,10,0)
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
{#import Graphics.UI.Gtk.Types#}
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Types
{#pointer *RecentInfo foreign newtype#}
--------------------
-- Methods
-- | Helper function for build 'RecentInfo'
mkRecentInfo :: Ptr RecentInfo -> IO RecentInfo
mkRecentInfo rPtr = do
info <- newForeignPtr rPtr gtk_recent_info_unref
return (RecentInfo info)
foreign import ccall unsafe ">k_recent_info_unref"
gtk_recent_info_unref :: FinalizerPtr RecentInfo
-- | Checks whether the resource pointed by info still exists. At the moment this check is done only on
-- resources pointing to local files.
--
-- * Available since Gtk+ version 2.10
--
recentInfoExists :: RecentInfo
-> IO Bool -- ^ returns 'True' if the resource exists
recentInfoExists self =
liftM toBool $
{# call gtk_recent_info_exists #}
self
-- | Gets the timestamp (seconds from system's Epoch) when the resource was added to the recently used
-- resources list.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetAdded :: RecentInfo
-> IO Int -- ^ returns the number of seconds elapsed from system's Epoch when the resource was added to the list, or -1 on failure.
recentInfoGetAdded self =
liftM fromIntegral $
{# call gtk_recent_info_get_added #}
self
-- | Gets the number of days elapsed since the last update of the resource pointed by info.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetAge :: RecentInfo
-> IO Int -- ^ returns a positive integer containing the number of days elapsed since the time this resource was last modified.
recentInfoGetAge self =
liftM fromIntegral $
{# call gtk_recent_info_get_age #}
self
-- | Gets the data regarding the application that has registered the resource pointed by info.
--
-- If the command line contains any escape characters defined inside the storage specification, they
-- will be expanded.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetApplicationInfo :: GlibString string => RecentInfo
-> string -- ^ @appName@ the name of the application that has registered this item
-> IO (Maybe ([string], Int, Int))
-- ^ @appExec@ return location for the string containing the command line. transfer none.
-- ^ @count@ return location for the number of times this item was registered. out.
-- ^ @time@ out. out.
recentInfoGetApplicationInfo self appName =
alloca $ \countPtr ->
alloca $ \timePtr ->
allocaArray 0 $ \execPtr ->
withUTFString appName $ \appNamePtr -> do
success <- liftM toBool $
{# call gtk_recent_info_get_application_info #}
self
appNamePtr
execPtr
countPtr
timePtr
if success
then do
exec <- mapM peekUTFString =<< peekArray 0 execPtr
count <- peek countPtr
time <- peek timePtr
return (Just (exec, fromIntegral count, fromIntegral time))
else return Nothing
-- | Retrieves the list of applications that have registered this resource.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetApplications :: GlibString string => RecentInfo -> IO [string]
recentInfoGetApplications self =
alloca $ \lengthPtr -> do
str <- {# call gtk_recent_info_get_applications #} self lengthPtr
length <- peek lengthPtr
mapM peekUTFString =<< peekArray (fromIntegral length) str
-- | Gets the (short) description of the resource.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetDescription :: GlibString string => RecentInfo
-> IO string -- ^ returns the description of the resource.
recentInfoGetDescription self =
{# call gtk_recent_info_get_description #}
self
>>= peekUTFString
-- | Gets the name of the resource. If none has been defined, the basename of the resource is obtained.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetDisplayName :: GlibString string => RecentInfo
-> IO string -- ^ returns the display name of the resource.
recentInfoGetDisplayName self =
{# call gtk_recent_info_get_display_name #}
self
>>= peekUTFString
-- | Returns all groups registered for the recently used item info.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetGroups :: GlibString string => RecentInfo -> IO [string]
recentInfoGetGroups self =
alloca $ \lengthPtr -> do
str <- {# call gtk_recent_info_get_groups #} self lengthPtr
length <- peek lengthPtr
mapM peekUTFString =<< peekArray (fromIntegral length) str
-- | Retrieves the icon of size size associated to the resource MIME type.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetIcon :: RecentInfo
-> Int -- ^ @size@ the size of the icon in pixels
-> IO (Maybe Pixbuf) -- ^ returns a 'Pixbuf' containing the icon, or 'Nothing'
recentInfoGetIcon self size =
maybeNull (makeNewGObject mkPixbuf) $
{# call gtk_recent_info_get_icon #}
self
(fromIntegral size)
-- | Gets the MIME type of the resource.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetMimeType :: GlibString string => RecentInfo
-> IO string -- ^ returns the MIME type of the resource.
recentInfoGetMimeType self =
{# call gtk_recent_info_get_mime_type #}
self
>>= peekUTFString
-- | Gets the timestamp (seconds from system's Epoch) when the resource was last modified.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetModified :: RecentInfo
-> IO Int -- ^ returns the number of seconds elapsed from system's Epoch when the resource was last modified, or -1 on failure.
recentInfoGetModified self =
liftM fromIntegral $
{# call gtk_recent_info_get_modified #}
self
-- | Gets the value of the "private" flag. Resources in the recently used list that have this flag set to
-- 'True' should only be displayed by the applications that have registered them.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetPrivateHint :: RecentInfo
-> IO Bool -- ^ returns 'True' if the private flag was found, 'False' otherwise.
recentInfoGetPrivateHint self =
liftM toBool $
{# call gtk_recent_info_get_private_hint #}
self
-- | Computes a valid UTF-8 string that can be used as the name of the item in a menu or list. For
-- example, calling this function on an item that refers to \"file:///foo/bar.txt\" will yield \"bar.txt\".
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetShortName :: GlibString string => RecentInfo
-> IO string
recentInfoGetShortName self =
{# call gtk_recent_info_get_short_name #}
self
>>= readUTFString
-- | Gets the URI of the resource.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetURI :: GlibString string => RecentInfo
-> IO string -- ^ returns the URI of the resource.
recentInfoGetURI self =
{# call gtk_recent_info_get_uri #}
self
>>= peekUTFString
-- | Gets a displayable version of the resource's URI. If the resource is local, it returns a local path;
-- if the resource is not local, it returns the UTF-8 encoded content of 'recentInfoGetUri'.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetURIDisplay :: GlibString string => RecentInfo -> IO string
recentInfoGetURIDisplay self =
{# call gtk_recent_info_get_uri_display #}
self
>>= readUTFString
-- | Gets the timestamp (seconds from system's Epoch) when the resource was last visited.
--
-- * Available since Gtk+ version 2.10
--
recentInfoGetVisited :: RecentInfo
-> IO Int -- ^ returns the number of seconds elapsed from system's Epoch when the resource was last visited, or -1 on failure.
recentInfoGetVisited self =
liftM fromIntegral $
{# call gtk_recent_info_get_visited #}
self
-- | Checks whether an application registered this resource using @appName@.
--
-- * Available since Gtk+ version 2.10
--
recentInfoHasApplication :: GlibString string => RecentInfo
-> string -- ^ @appName@ a string containing an application name
-> IO Bool -- ^ returns 'True' if an application with name @appName@ was found, 'False' otherwise.
recentInfoHasApplication self appName =
liftM toBool $
withUTFString appName $ \appNamePtr ->
{# call gtk_recent_info_has_application #}
self
appNamePtr
-- | Checks whether @groupName@ appears inside the groups registered for the recently used item info.
--
-- * Available since Gtk+ version 2.10
--
recentInfoHasGroup :: GlibString string => RecentInfo
-> string -- ^ @groupName@ name of a group
-> IO Bool -- ^ returns 'True' if the group was found.
recentInfoHasGroup self groupName =
liftM toBool $
withUTFString groupName $ \groupNamePtr ->
{# call gtk_recent_info_has_group #}
self
groupNamePtr
-- | Checks whether the resource is local or not by looking at the scheme of its URI.
--
-- * Available since Gtk+ version 2.10
--
recentInfoIsLocal :: RecentInfo
-> IO Bool -- ^ returns 'True' if the resource is local.
recentInfoIsLocal self =
liftM toBool $
{# call gtk_recent_info_is_local #}
self
-- | Gets the name of the last application that have registered the recently used resource represented by
-- info.
--
-- * Available since Gtk+ version 2.10
--
recentInfoLastApplication :: GlibString string => RecentInfo
-> IO string -- ^ returns an application name.
recentInfoLastApplication self =
{# call gtk_recent_info_last_application #}
self
>>= readUTFString
-- | Checks whether two 'RecentInfo' structures point to the same resource.
--
-- * Available since Gtk+ version 2.10
--
recentInfoMatch :: RecentInfo -> RecentInfo
-> IO Bool -- ^ returns 'True' if both 'RecentInfo' structures point to se same resource, 'False' otherwise.
recentInfoMatch self infoB =
liftM toBool $
{# call gtk_recent_info_match #}
self
infoB
#endif
|