From: Andy S. <And...@co...> - 2010-03-28 01:39:29
|
Sat Mar 27 21:37:19 EDT 2010 Andy Stewart <laz...@gm...> * Add new `Recent` modules Ignore-this: abf96166e4822118c76ca07a592fa960 hunk ./ApiUpdateTodoList.txt 128 -*** TODO RecentAction.chs +*** DONE RecentAction.chs hunk ./ApiUpdateTodoList.txt 130 -*** TODO RecentChooserDefault.chs +*** DONE RecentChooserDefault.chs hunk ./ApiUpdateTodoList.txt 132 -*** TODO RecentChooserMenu.chs -*** TODO RecentChooserWidget.chs -*** TODO RecentFilter.chs -*** TODO RecentInfo.chs +*** DONE RecentChooserMenu.chs +*** DONE RecentChooserWidget.chs +*** DONE RecentFilter.chs +*** DONE RecentInfo.chs hunk ./Makefile.am 806 + gtk/Graphics/UI/Gtk/Recent/RecentChooserDialog.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentChooserMenu.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentChooserWidget.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentFilter.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentInfo.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentManager.chs.pp \ + gtk/Graphics/UI/Gtk/Recent/RecentChooser.chs.pp \ hunk ./Makefile.am 884 - gtk/Graphics/UI/Gtk/ModelView/CustomStore_stub.o + gtk/Graphics/UI/Gtk/ModelView/CustomStore_stub.o \ + gtk/Graphics/UI/Gtk/Recent/RecentChooser_stub.o \ + gtk/Graphics/UI/Gtk/Recent/RecentFilter_stub.o hunk ./gtk/Graphics/UI/Gtk.hs.pp 245 - module Graphics.UI.Gtk.Pango.Enums + module Graphics.UI.Gtk.Pango.Enums, + + -- * Recent modules + module Graphics.UI.Gtk.Recent.RecentChooser, + module Graphics.UI.Gtk.Recent.RecentChooserDialog, + module Graphics.UI.Gtk.Recent.RecentChooserMenu, + module Graphics.UI.Gtk.Recent.RecentChooserWidget, + module Graphics.UI.Gtk.Recent.RecentFilter, + module Graphics.UI.Gtk.Recent.RecentInfo, + module Graphics.UI.Gtk.Recent.RecentManager, hunk ./gtk/Graphics/UI/Gtk.hs.pp 497 + +-- recent modules +import Graphics.UI.Gtk.Recent.RecentChooser +import Graphics.UI.Gtk.Recent.RecentChooserDialog +import Graphics.UI.Gtk.Recent.RecentChooserMenu +import Graphics.UI.Gtk.Recent.RecentChooserWidget +import Graphics.UI.Gtk.Recent.RecentFilter +import Graphics.UI.Gtk.Recent.RecentInfo +import Graphics.UI.Gtk.Recent.RecentManager adddir ./gtk/Graphics/UI/Gtk/Recent addfile ./gtk/Graphics/UI/Gtk/Recent/RecentChooser.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentChooser.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Interface RecentChooser +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Interface implemented by widgets displaying recently used files +-- +-- * Module available since Gtk+ version 2.10 +-- +-- The follwing functions don't bind, use corresponding attributes instead: +-- gtk_recent_chooser_set_show_private +-- gtk_recent_chooser_get_show_private +-- gtk_recent_chooser_set_show_not_found +-- gtk_recent_chooser_get_show_not_found +-- gtk_recent_chooser_set_show_icons +-- gtk_recent_chooser_get_show_icons +-- gtk_recent_chooser_set_select_multiple +-- gtk_recent_chooser_get_select_multiple +-- gtk_recent_chooser_set_local_only +-- gtk_recent_chooser_get_local_only +-- gtk_recent_chooser_set_limit +-- gtk_recent_chooser_get_limit +-- gtk_recent_chooser_set_show_tips +-- gtk_recent_chooser_get_show_tips +-- gtk_recent_chooser_set_sort_type +-- gtk_recent_chooser_get_sort_type +-- gtk_recent_chooser_set_filter +-- gtk_recent_chooser_get_filter +-- +module Graphics.UI.Gtk.Recent.RecentChooser ( + +-- * Detail +-- +-- | 'RecentChooser' is an interface that can be implemented by widgets +-- displaying the list of recently used files. In Gtk+, the main objects that +-- implement this interface are 'RecentChooserWidget', 'RecentChooserDialog' +-- and 'RecentChooserMenu'. +-- +-- Recently used files are supported since Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GInterface' +-- | +----RecentChooser +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + RecentChooser, + RecentChooserClass, + castToRecentChooser, + toRecentChooser, + +-- * Enums + RecentChooserError(..), + RecentSortType(..), + +-- * Methods + -- recentChooserSetSortFunc, + recentChooserSetCurrentURI, + recentChooserGetCurrentURI, + -- recentChooserGetCurrentItem, + recentChooserSelectURI, + recentChooserUnselectURI, + recentChooserSelectAll, + recentChooserUnselectAll, + -- recentChooserGetItems, + recentChooserGetURIs, + recentChooserAddFilter, + recentChooserRemoveFilter, + recentChooserListFilters, + recentChooserErrorQuark, + +-- * Attributes + recentChooserShowPrivate, + recentChooserShowTips, + recentChooserShowIcons, + recentChooserShowNotFound, + recentChooserSelectMultiple, + recentChooserLocalOnly, + recentChooserLimit, + recentChooserSortType, + recentChooserFilter, + +-- * Signals + recentChooserSelectionChanged, + recentChooserItemActivated, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.Attributes +import System.Glib.Properties +import System.Glib.GList +import System.Glib.GObject (Quark, quarkFromString) +import System.Glib.GError (GErrorDomain, GErrorClass(..), propagateGError) +import Graphics.UI.Gtk.Abstract.Object (makeNewObject) +{#import Graphics.UI.Gtk.Recent.RecentInfo#} (RecentInfo) +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Signals#} + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Enums +{#enum RecentChooserError {underscoreToCase} deriving (Bounded,Eq,Show)#} + +{#enum RecentSortType {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-------------------- +-- Methods + +-- | Sets the comparison function used when sorting to be @sortFunc@. If the +-- @chooser@ has the sort type set to 'RecentSortCustom' then the chooser will +-- sort using this function. +-- +-- To the comparison function will be passed two {GtkRecentInfo, FIXME: +-- boxed type} structs and @sortData@; @sortFunc@ should return a positive +-- integer if the first item comes before the second, zero if the two items are +-- equal and a negative integer if the first item comes after the second. +-- +-- recentChooserSetSortFunc :: RecentChooserClass self => self +-- -> (Maybe (RecentInfo -> IO Int)) +-- -> IO () +-- recentChooserSetSortFunc self Nothing = +-- {# call gtk_recent_chooser_set_sort_func #} +-- (toRecentChooser self) nullFunPtr nullPtr nullFunPtr +-- recentChooserSetSortFunc self (Just func) = do +-- fPtr <- mkRecentSortFunc $ \_ info _ -> func info +-- {# call gtk_recent_chooser_set_sort_func #} +-- (toRecentChooser self) +-- fPtr +-- (castFunPtrToPtr fPtr) +-- destroyFunPtr + +{#pointer RecentSortFunc#} + +foreign import ccall "wrapper" mkRecentSortFunc :: + (Ptr RecentInfo -> Ptr RecentInfo -> Ptr () -> IO {#type gint#}) + -> IO RecentSortFunc + +-- | Sets @uri@ as the current URI for @chooser@. +-- +recentChooserSetCurrentURI :: RecentChooserClass self => self + -> String -- ^ @uri@ - a URI + -> IO Bool -- ^ returns @True@ if the URI was found. +recentChooserSetCurrentURI self uri = + liftM toBool $ + propagateGError $ \errorPtr -> + withUTFString uri $ \uriPtr -> + {# call gtk_recent_chooser_set_current_uri #} + (toRecentChooser self) + uriPtr + errorPtr + +-- | Gets the URI currently selected by @chooser@. +-- +recentChooserGetCurrentURI :: RecentChooserClass self => self + -> IO String -- ^ returns a newly allocated string holding a URI. +recentChooserGetCurrentURI self = + {# call gtk_recent_chooser_get_current_uri #} + (toRecentChooser self) + >>= readUTFString + +-- | Gets the {GtkRecentInfo, FIXME: boxed type} currently selected by +-- @chooser@. +-- +-- recentChooserGetCurrentItem :: RecentChooserClass self => self +-- -> IO RecentInfo -- ^ returns a {GtkRecentInfo, FIXME: boxed type}. +-- -- Use 'recentInfoUnref' when when you have finished +-- -- using it. +-- recentChooserGetCurrentItem self = +-- {# call gtk_recent_chooser_get_current_item #} +-- (toRecentChooser self) + +-- | Selects @uri@ inside @chooser@. +-- +recentChooserSelectURI :: RecentChooserClass self => self + -> String -- ^ @uri@ - a URI + -> IO Bool -- ^ returns @True@ if @uri@ was found. +recentChooserSelectURI self uri = + liftM toBool $ + propagateGError $ \errorPtr -> + withUTFString uri $ \uriPtr -> + {# call gtk_recent_chooser_select_uri #} + (toRecentChooser self) + uriPtr + errorPtr + +-- | Unselects @uri@ inside @chooser@. +-- +recentChooserUnselectURI :: RecentChooserClass self => self + -> String -- ^ @uri@ - a URI + -> IO () +recentChooserUnselectURI self uri = + withUTFString uri $ \uriPtr -> + {# call gtk_recent_chooser_unselect_uri #} + (toRecentChooser self) + uriPtr + +-- | Selects all the items inside @chooser@, if the @chooser@ supports +-- multiple selection. +-- +recentChooserSelectAll :: RecentChooserClass self => self -> IO () +recentChooserSelectAll self = + {# call gtk_recent_chooser_select_all #} + (toRecentChooser self) + +-- | Unselects all the items inside @chooser@. +-- +recentChooserUnselectAll :: RecentChooserClass self => self -> IO () +recentChooserUnselectAll self = + {# call gtk_recent_chooser_unselect_all #} + (toRecentChooser self) + +-- | Gets the list of recently used resources in form of {GtkRecentInfo, +-- FIXME: boxed type} objects. +-- +-- The return value of this function is affected by the \"sort-type\" and +-- \"limit\" properties of @chooser@. +-- +-- recentChooserGetItems :: RecentChooserClass self => self +-- -> IO [RecentInfo] -- ^ returns A newly allocated list of +-- -- {GtkRecentInfo, FIXME: boxed type} objects. You +-- -- should use 'recentInfoUnref' on every item of +-- -- the list, and then free the list itself using +-- -- 'gListFree'. +-- recentChooserGetItems self = +-- {# call gtk_recent_chooser_get_items #} +-- (toRecentChooser self) +-- >>= fromGList + -- >>= mapM (\elemPtr -> RecentInfo elemPtr) + +-- | Gets the URI of the recently used resources. +-- +-- The return value of this function is affected by the \"sort-type\" and +-- \"limit\" properties of @chooser@. +-- +-- Since the returned array is {@NULL@, FIXME: this should probably be +-- converted to a Maybe data type} terminated, @length@ may be {@NULL@, FIXME: +-- this should probably be converted to a Maybe data type}. +-- +recentChooserGetURIs :: RecentChooserClass self => self + -> IO ([String], Int) -- ^ returns A newly allocated, {@NULL@, FIXME: this should + -- probably be converted to a Maybe data type} terminated + -- array of strings. Use 'gStrfreev' to free it. +recentChooserGetURIs self = [_$_] + alloca $ \lengthPtr -> do + str <- {# call gtk_recent_chooser_get_uris #} + (toRecentChooser self) + lengthPtr + length <- peek lengthPtr + uris <- mapM peekCString =<< peekArray 0 str + return (uris, fromIntegral length) + +-- | Adds @filter@ to the list of 'RecentFilter' objects held by @chooser@. +-- +-- If no previous filter objects were defined, this function will call +-- 'recentChooserSetFilter'. +-- +recentChooserAddFilter :: (RecentChooserClass self, RecentFilterClass filter) => self + -> filter -- ^ @filter@ - a 'RecentFilter' + -> IO () +recentChooserAddFilter self filter = + {# call gtk_recent_chooser_add_filter #} + (toRecentChooser self) + (toRecentFilter filter) + +-- | Removes @filter@ from the list of 'RecentFilter' objects held by +-- @chooser@. +-- +recentChooserRemoveFilter :: (RecentChooserClass self, RecentFilterClass filter) => self + -> filter -- ^ @filter@ - a 'RecentFilter' + -> IO () +recentChooserRemoveFilter self filter = + {# call gtk_recent_chooser_remove_filter #} + (toRecentChooser self) + (toRecentFilter filter) + +-- | Gets the 'RecentFilter' objects held by @chooser@. +-- +recentChooserListFilters :: RecentChooserClass self => self + -> IO [RecentFilter] -- ^ returns A singly linked list of + -- 'RecentFilter' objects. You should just free the + -- returned list using 'gSlistFree'. +recentChooserListFilters self = do + glist <- {# call gtk_recent_chooser_list_filters #} + (toRecentChooser self) + list <- fromGList glist + mapM (\x -> makeNewObject mkRecentFilter (return (castPtr x))) list + +-- | +-- +recentChooserErrorQuark :: IO Quark +recentChooserErrorQuark = + {# call gtk_recent_chooser_error_quark #} + +-------------------- +-- Attributes + +-- | Whether the private items should be displayed. +-- [_$_] +-- Default value: 'False' +recentChooserShowPrivate :: RecentChooserClass self => Attr self Bool +recentChooserShowPrivate = newAttrFromBoolProperty "show-private" + +-- | Whether this 'RecentChooser' should display a tooltip containing the full path of the recently used +-- resources. +-- [_$_] +-- Default value: 'False' +-- [_$_] +-- Since 2.10 +recentChooserShowTips :: RecentChooserClass self => Attr self Bool +recentChooserShowTips = newAttrFromBoolProperty "show-tips" + +-- | Whether this 'RecentChooser' should display an icon near the item. +-- [_$_] +-- Default value: 'True' +-- [_$_] +-- Since 2.10 +recentChooserShowIcons :: RecentChooserClass self => Attr self Bool +recentChooserShowIcons = newAttrFromBoolProperty "show-icons" + +-- | Whether this 'RecentChooser' should display the recently used resources even if not present +-- anymore. Setting this to 'False' will perform a potentially expensive check on every local resource +-- (every remote resource will always be displayed). +-- [_$_] +-- Default value: 'True' +-- [_$_] +-- Since 2.10 +recentChooserShowNotFound :: RecentChooserClass self => Attr self Bool +recentChooserShowNotFound = newAttrFromBoolProperty "show-not-found" + +-- | Allow the user to select multiple resources. +-- [_$_] +-- Default value: 'False' +-- [_$_] +-- Since 2.10 +recentChooserSelectMultiple :: RecentChooserClass self => Attr self Bool +recentChooserSelectMultiple = newAttrFromBoolProperty "select-multiple" + +-- | Whether this 'RecentChooser' should display only local (file:) resources. +-- [_$_] +-- Default value: 'True' +-- [_$_] +-- Since 2.10 +recentChooserLocalOnly :: RecentChooserClass self => Attr self Bool +recentChooserLocalOnly = newAttrFromBoolProperty "local-only" + +-- | The maximum number of recently used resources to be displayed, or -1 to display all items. By +-- default, the 'Setting':gtk-recent-files-limit setting is respected: you can override that limit on +-- a particular instance of 'RecentChooser' by setting this property. +-- [_$_] +-- Allowed values: >= 'GMaxulong' +-- [_$_] +-- Default value: -1 +-- [_$_] +-- Since 2.10 +recentChooserLimit :: RecentChooserClass self => Attr self Int +recentChooserLimit = newAttrFromIntProperty "limit" + +-- | Sorting order to be used when displaying the recently used resources. +-- [_$_] +-- Default value: ''RecentSortNone'' +-- [_$_] +-- Since 2.10 +recentChooserSortType :: RecentChooserClass self => Attr self RecentSortType +recentChooserSortType = newAttrFromEnumProperty "sort-type" + {# call pure unsafe gtk_recent_sort_type_get_type #} + +-- | The 'RecentFilter' object to be used when displaying the recently used resources. +-- [_$_] +-- Since 2.10 +recentChooserFilter :: (RecentChooserClass self, RecentFilterClass recentFilter) => ReadWriteAttr self RecentFilter recentFilter +recentChooserFilter = newAttrFromObjectProperty "filter" + {# call pure unsafe gtk_recent_filter_get_type #} + +-------------------- +-- Signals + +-- | This signal is emitted when there is a change in the set of selected +-- recently used resources. This can happen when a user modifies the selection +-- with the mouse or the keyboard, or when explicitely calling functions to +-- change the selection. +-- +recentChooserSelectionChanged :: RecentChooserClass self => Signal self (IO ()) +recentChooserSelectionChanged = Signal (connect_NONE__NONE "selection-changed") + +-- | This signal is emitted when the user \"activates\" a recent item in the +-- recent chooser. This can happen by double-clicking on an item in the +-- recently used resources list, or by pressing Enter. +-- +recentChooserItemActivated :: RecentChooserClass self => Signal self (IO ()) +recentChooserItemActivated = Signal (connect_NONE__NONE "item-activated") +#endif addfile ./gtk/Graphics/UI/Gtk/Recent/RecentChooserDialog.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentChooserDialog.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget RecentChooserDialog +-- +-- 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. +-- +-- TODO: the following varargs functions were not bound +-- gtk_recent_chooser_dialog_new +-- gtk_recent_chooser_dialog_new_for_manager +-- +-- | +-- Maintainer : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Displays recently used files in a dialog +-- +-- * Module available since Gtk+ version 2.10 +-- +module Graphics.UI.Gtk.Recent.RecentChooserDialog ( + +-- * Detail +-- +-- | 'RecentChooserDialog' is a dialog box suitable for displaying the +-- recently used documents. This widgets works by putting a +-- 'RecentChooserWidget' inside a 'Dialog'. It exposes the +-- {GtkRecentChooserIface, FIXME: unknown type\/value} interface, so you can +-- use all the 'RecentChooser' functions on the recent chooser dialog as well +-- as those for 'Dialog'. +-- +-- Note that 'RecentChooserDialog' does not have any methods of its own. +-- Instead, you should use the functions that work on a 'RecentChooser'. +-- +-- Recently used files are supported since Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----'Object' +-- | +----'Widget' +-- | +----'Container' +-- | +----'Bin' +-- | +----'Window' +-- | +----'Dialog' +-- | +----RecentChooserDialog +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + RecentChooserDialog, + RecentChooserDialogClass, + castToRecentChooserDialog, + toRecentChooserDialog, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +{#import Graphics.UI.Gtk.Types#} +-- CHECKME: extra imports may be required + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Interfaces + +instance RecentChooserClass RecentChooserDialog +#endif addfile ./gtk/Graphics/UI/Gtk/Recent/RecentChooserMenu.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentChooserMenu.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget RecentChooserMenu +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Displays recently used files in a menu +-- +-- * Module available since Gtk+ version 2.10 +-- +-- The follwing functions don't bind, use corresponding attributes instead: +-- gtk_recent_chooser_menu_get_show_numbers +-- gtk_recent_chooser_menu_set_show_numbers +-- +module Graphics.UI.Gtk.Recent.RecentChooserMenu ( + +-- * Detail +-- +-- | 'RecentChooserMenu' is a widget suitable for displaying recently used +-- files inside a menu. It can be used to set a sub-menu of a 'MenuItem' using +-- 'menuItemSetSubmenu', or as the menu of a 'MenuToolButton'. +-- +-- Note that 'RecentChooserMenu' does not have any methods of its own. +-- Instead, you should use the functions that work on a 'RecentChooser'. +-- +-- Note also that 'RecentChooserMenu' does not support multiple filters, as +-- it has no way to let the user choose between them as the +-- 'RecentChooserWidget' and 'RecentChooserDialog' widgets do. Thus using +-- 'recentChooserAddFilter' on a 'RecentChooserMenu' widget will yield the same +-- effects as using 'recentChooserSetFilter', replacing any currently set +-- filter with the supplied filter; 'recentChooserRemoveFilter' will remove any +-- currently set 'RecentFilter' object and will unset the current filter; +-- 'recentChooserListFilters' will return a list containing a single +-- 'RecentFilter' object. +-- +-- Recently used files are supported since Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----'Object' +-- | +----'Widget' +-- | +----'Container' +-- | +----'MenuShell' +-- | +----'Menu' +-- | +----RecentChooserMenu +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + RecentChooserMenu, + RecentChooserMenuClass, + castToRecentChooserMenu, + toRecentChooserMenu, + +-- * Constructors + recentChooserMenuNew, + recentChooserMenuNewForManager, + +-- * Attributes + recentChooserMenuShowNumbers, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Attributes +import System.Glib.Properties +import Graphics.UI.Gtk.Abstract.Object (makeNewObject) +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Interfaces + +instance RecentChooserClass RecentChooserMenu + +instance ActivatableClass RecentChooserMenu + +-------------------- +-- Constructors + +-- | Creates a new 'RecentChooserMenu' widget. +-- +-- This kind of widget shows the list of recently used resources as a menu, +-- each item as a menu item. Each item inside the menu might have an icon, +-- representing its MIME type, and a number, for mnemonic access. +-- +-- This widget implements the 'RecentChooser' interface. +-- +-- This widget creates its own 'RecentManager' object. See the +-- 'recentChooserMenuNewForManager' function to know how to create a +-- 'RecentChooserMenu' widget bound to another 'RecentManager' object. +-- +recentChooserMenuNew :: IO RecentChooserMenu +recentChooserMenuNew = + makeNewObject mkRecentChooserMenu $ + liftM (castPtr :: Ptr Widget -> Ptr RecentChooserMenu) $ + {# call gtk_recent_chooser_menu_new #} + +-- | Creates a new 'RecentChooserMenu' widget using @manager@ as the +-- underlying recently used resources manager. +-- +-- This is useful if you have implemented your own recent manager, or if you +-- have a customized instance of a 'RecentManager' object or if you wish to +-- share a common 'RecentManager' object among multiple 'RecentChooser' +-- widgets. +-- +recentChooserMenuNewForManager :: RecentManagerClass manager => + manager -- ^ @manager@ - a 'RecentManager' + -> IO RecentChooserMenu +recentChooserMenuNewForManager manager = + makeNewObject mkRecentChooserMenu $ + liftM (castPtr :: Ptr Widget -> Ptr RecentChooserMenu) $ + {# call gtk_recent_chooser_menu_new_for_manager #} + (toRecentManager manager) + +-------------------- +-- Methods + +-------------------- +-- Attributes + +-- | Whether the first ten items in the menu should be prepended by a number acting as a unique mnemonic. +-- [_$_] +-- Default value: 'False' +-- [_$_] +-- Since 2.10 +recentChooserMenuShowNumbers :: RecentChooserMenuClass self => Attr self Bool +recentChooserMenuShowNumbers = newAttrFromBoolProperty "show-numbers" +#endif addfile ./gtk/Graphics/UI/Gtk/Recent/RecentChooserWidget.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentChooserWidget.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget RecentChooserWidget +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Displays recently used files +-- +-- * Module available since Gtk+ version 2.10 +-- +module Graphics.UI.Gtk.Recent.RecentChooserWidget ( + +-- * Detail +-- +-- | 'RecentChooserWidget' is a widget suitable for selecting recently used +-- files. It is the main building block of a 'RecentChooserDialog'. Most +-- applications will only need to use the latter; you can use +-- 'RecentChooserWidget' as part of a larger window if you have special needs. +-- +-- Note that 'RecentChooserWidget' does not have any methods of its own. +-- Instead, you should use the functions that work on a 'RecentChooser'. +-- +-- Recently used files are supported since Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----'Object' +-- | +----'Widget' +-- | +----'Container' +-- | +----'Box' +-- | +----'VBox' +-- | +----RecentChooserWidget +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + RecentChooserWidget, + RecentChooserWidgetClass, + castToRecentChooserWidget, + toRecentChooserWidget, + +-- * Constructors + recentChooserWidgetNew, + recentChooserWidgetNewForManager, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Attributes +import System.Glib.Properties +{#import Graphics.UI.Gtk.Types#} +import Graphics.UI.Gtk.Abstract.Object (makeNewObject) + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Interfaces + +instance RecentChooserClass RecentChooserWidget + +-------------------- +-- Constructors + +-- | Creates a new 'RecentChooserWidget' object. This is an embeddable widget +-- used to access the recently used resources list. +-- +recentChooserWidgetNew :: IO RecentChooserWidget +recentChooserWidgetNew = + makeNewObject mkRecentChooserWidget $ + liftM (castPtr :: Ptr Widget -> Ptr RecentChooserWidget) $ + {# call gtk_recent_chooser_widget_new #} + +-- | Creates a new 'RecentChooserWidget' with a specified recent manager. +-- +-- This is useful if you have implemented your own recent manager, or if you +-- have a customized instance of a 'RecentManager' object. +-- +recentChooserWidgetNewForManager :: RecentManagerClass manager => + manager -- ^ @manager@ - a 'RecentManager' + -> IO RecentChooserWidget +recentChooserWidgetNewForManager manager = + makeNewObject mkRecentChooserWidget $ + liftM (castPtr :: Ptr Widget -> Ptr RecentChooserWidget) $ + {# call gtk_recent_chooser_widget_new_for_manager #} + (toRecentManager manager) +#endif addfile ./gtk/Graphics/UI/Gtk/Recent/RecentFilter.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentFilter.chs.pp 1 +-- -*-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 : gtk...@li... +-- 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, + RecentFilterInfo, + +-- * Enums + RecentFilterFlags(..), + +-- * Constructors + recentFilterNew, + +-- * Methods + recentFilterGetName, + recentFilterSetName, + recentFilterAddMimeType, + recentFilterAddPattern, + recentFilterAddPixbufFormats, + recentFilterAddApplication, + recentFilterAddGroup, + recentFilterAddAge, + recentFilterAddCustom, + recentFilterGetNeeded, + recentFilterFilter, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.Flags (Flags, toFlags, fromFlags) +import Graphics.UI.Gtk.Abstract.Object (makeNewObject) +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Types +{#pointer *RecentFilterInfo foreign newtype#} + +--------------------- +-- Enums +{#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: +-- +-- > FIXME: if the follwing is a C code example, port it to Haskell or remove it +-- > [_$_] +-- > GtkRecentFilter *filter = gtk_recent_filter_new (); +-- > gtk_recent_filter_add_pattern (filter, "*"); +-- +recentFilterNew :: IO RecentFilter +recentFilterNew = + makeNewObject mkRecentFilter $ + {# call gtk_recent_filter_new #} + +-------------------- +-- Methods + +recentFilterGetName :: RecentFilterClass self => self + -> IO String -- ^ returns the name of the filter, or {@NULL@, FIXME: this + -- should probably be converted to a Maybe data type}. The + -- returned string is owned by the filter object and should not + -- be freed. +recentFilterGetName self = + {# call gtk_recent_filter_get_name #} + (toRecentFilter self) + >>= peekUTFString + +recentFilterSetName :: RecentFilterClass self => 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. +-- +recentFilterAddMimeType :: RecentFilterClass self => 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. +-- +recentFilterAddPattern :: RecentFilterClass self => 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. +-- +recentFilterAddApplication :: RecentFilterClass self => 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 +-- +recentFilterAddGroup :: RecentFilterClass self => 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. +-- +recentFilterAddAge :: RecentFilterClass self => self + -> Int -- ^ @days@ - number of days + -> IO () +recentFilterAddAge self days = + {# call gtk_recent_filter_add_age #} + (toRecentFilter self) + (fromIntegral days) + +-- | Adds a rule to a filter that allows resources based on a custom callback +-- function. The bitfield @needed@ which is passed in provides information +-- about what sorts of information that the filter function needs; this allows +-- Gtk+ to avoid retrieving expensive information when it isn't needed by the +-- filter. +-- +recentFilterAddCustom :: RecentFilterClass self => self + -> RecentFilterFlags -- ^ @needed@ - bitfield of flags indicating the + -- information that the custom filter function + -- needs. + -> (IO Bool) + -> IO () +recentFilterAddCustom self needed func = do + fPtr <- mkRecentFilterFunc $ \_ _ -> liftM fromBool func [_$_] + {# call gtk_recent_filter_add_custom #} + (toRecentFilter self) + ((fromIntegral . fromEnum) needed) + fPtr + (castFunPtrToPtr fPtr) + destroyFunPtr + +{#pointer RecentFilterFunc#} + +foreign import ccall "wrapper" mkRecentFilterFunc :: + (Ptr RecentFilterInfo -> Ptr () -> IO {#type gboolean#}) + -> IO RecentFilterFunc + +-- | Gets the fields that need to be filled in for the structure passed to +-- 'recentFilterFilter' +-- +-- This function will not typically be used by applications; it is intended +-- principally for use in the implementation of 'RecentChooser'. +-- +recentFilterGetNeeded :: RecentFilterClass self => self + -> IO RecentFilterFlags -- ^ returns bitfield of flags indicating needed + -- fields when calling 'recentFilterFilter' +recentFilterGetNeeded self = [_$_] + liftM (toEnum . fromIntegral) $ [_$_] + {#call gtk_recent_filter_get_needed #} (toRecentFilter self) +-- recentFilterGetNeeded self = do + -- liftM (toFlags . fromIntegral) $ + -- restPtr <- {# call gtk_recent_filter_get_needed #} + -- (toRecentFilter self) + -- flagsList <- peekArray 0 restPtr + -- return flagsList + +-- | Tests whether a file should be displayed according to @filter@. The +-- {GtkRecentFilterInfo, FIXME: struct type} structure @filterInfo@ should +-- include the fields returned from 'recentFilterGetNeeded'. +-- +-- This function will not typically be used by applications; it is intended +-- principally for use in the implementation of 'RecentChooser'. +-- +recentFilterFilter :: RecentFilterClass self => self + -> RecentFilterInfo -- ^ @filterInfo@ - a {GtkRecentFilterInfo, + -- FIXME: struct type} structure containing + -- information about a recently used + -- resource + -> IO Bool -- ^ returns @True@ if the file should be + -- displayed +recentFilterFilter self filterInfo = + liftM toBool $ + {# call gtk_recent_filter_filter #} + (toRecentFilter self) + filterInfo + +#endif addfile ./gtk/Graphics/UI/Gtk/Recent/RecentInfo.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentInfo.chs.pp 1 +-- -*-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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- +module Graphics.UI.Gtk.Recent.RecentInfo ( + +-- * Types + RecentInfo, + +-- * Methods + recentInfoExists, + recentInfoGetAdded, + recentInfoGetAge, + recentInfoGetApplicationInfo, + recentInfoGetApplications, + recentInfoGetDescription, + recentInfoGetDisplayName, + recentInfoGetGroups, + recentInfoGetIcon, + recentInfoGetMimeType, + recentInfoGetModified, + recentInfoGetPrivateHint, + recentInfoGetShortName, + recentInfoGetURI, + recentInfoGetURIDisplay, + recentInfoGetVisited, + recentInfoHasApplication, + recentInfoHasGroup, + recentInfoIsLocal, + recentInfoLastApplication, + recentInfoMatch, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Attributes +import System.Glib.Properties +import System.Glib.UTFString +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gtk" prefix="gtk" #} + +-------------------- +-- Types +{#pointer *RecentInfo foreign newtype#} + +-------------------- +-- Methods + +-- | +-- +recentInfoExists :: RecentInfo -> IO Bool +recentInfoExists self = + liftM toBool $ + {# call gtk_recent_info_exists #} + self + +-- | +-- +recentInfoGetAdded :: RecentInfo -> IO Int +recentInfoGetAdded self = + liftM fromIntegral $ + {# call gtk_recent_info_get_added #} + self + +-- | +-- +recentInfoGetAge :: RecentInfo -> IO Int +recentInfoGetAge self = + liftM fromIntegral $ + {# call gtk_recent_info_get_age #} + self + +-- | +-- +recentInfoGetApplicationInfo :: RecentInfo -> String -> IO (Maybe ([String], Int, Int)) +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 peekCString =<< peekArray 0 execPtr + count <- peek countPtr + time <- peek timePtr + return (Just (exec, fromIntegral count, fromIntegral time)) + else return Nothing + +-- | +-- +recentInfoGetApplications :: RecentInfo -> IO ([String], Int) +recentInfoGetApplications self = [_$_] + alloca $ \lengthPtr -> do + str <- {# call gtk_recent_info_get_applications #} self lengthPtr + application <- mapM peekCString =<< peekArray 0 str + length <- peek lengthPtr + return (application, fromIntegral length) + +-- | +-- +recentInfoGetDescription :: RecentInfo -> IO String +recentInfoGetDescription self = + {# call gtk_recent_info_get_description #} + self + >>= peekUTFString + +-- | +-- +recentInfoGetDisplayName :: RecentInfo -> IO String +recentInfoGetDisplayName self = + {# call gtk_recent_info_get_display_name #} + self + >>= peekUTFString + +-- | +-- +recentInfoGetGroups :: RecentInfo -> IO ([String], Int) +recentInfoGetGroups self = [_$_] + alloca $ \lengthPtr -> do + str <- {# call gtk_recent_info_get_groups #} self lengthPtr + group <- mapM peekCString =<< peekArray 0 str + length <- peek lengthPtr + return (group, fromIntegral length) + +-- | +-- +recentInfoGetIcon :: RecentInfo -> Int -> IO Pixbuf +recentInfoGetIcon self size = + makeNewGObject mkPixbuf $ + {# call gtk_recent_info_get_icon #} + self + (fromIntegral size) + +-- | +-- +recentInfoGetMimeType :: RecentInfo -> IO String +recentInfoGetMimeType self = + {# call gtk_recent_info_get_mime_type #} + self + >>= peekUTFString + +-- | +-- +recentInfoGetModified :: RecentInfo -> IO Int +recentInfoGetModified self = + liftM fromIntegral $ + {# call gtk_recent_info_get_modified #} + self + +-- | +-- +recentInfoGetPrivateHint :: RecentInfo -> IO Bool +recentInfoGetPrivateHint self = + liftM toBool $ + {# call gtk_recent_info_get_private_hint #} + self + +-- | +-- +recentInfoGetShortName :: RecentInfo -> IO String +recentInfoGetShortName self = + {# call gtk_recent_info_get_short_name #} + self + >>= readUTFString + +-- | +-- +recentInfoGetURI :: RecentInfo -> IO String +recentInfoGetURI self = + {# call gtk_recent_info_get_uri #} + self + >>= peekUTFString + +-- | +-- +recentInfoGetURIDisplay :: RecentInfo -> IO String +recentInfoGetURIDisplay self = + {# call gtk_recent_info_get_uri_display #} + self + >>= readUTFString + +-- | +-- +recentInfoGetVisited :: RecentInfo -> IO Int +recentInfoGetVisited self = + liftM fromIntegral $ + {# call gtk_recent_info_get_visited #} + self + +-- | +-- +recentInfoHasApplication :: RecentInfo -> String -> IO Bool +recentInfoHasApplication self appName = + liftM toBool $ + withUTFString appName $ \appNamePtr -> + {# call gtk_recent_info_has_application #} + self + appNamePtr + +-- | +-- +recentInfoHasGroup :: RecentInfo -> String -> IO Bool +recentInfoHasGroup self groupName = + liftM toBool $ + withUTFString groupName $ \groupNamePtr -> + {# call gtk_recent_info_has_group #} + self + groupNamePtr + +-- | +-- +recentInfoIsLocal :: RecentInfo -> IO Bool +recentInfoIsLocal self = + liftM toBool $ + {# call gtk_recent_info_is_local #} + self + +-- | +-- +recentInfoLastApplication :: RecentInfo -> IO String +recentInfoLastApplication self = + {# call gtk_recent_info_last_application #} + self + >>= readUTFString + +-- | +-- +recentInfoMatch :: RecentInfo -> RecentInfo -> IO Bool +recentInfoMatch self infoB = + liftM toBool $ + {# call gtk_recent_info_match #} + self + infoB addfile ./gtk/Graphics/UI/Gtk/Recent/RecentManager.chs.pp hunk ./gtk/Graphics/UI/Gtk/Recent/RecentManager.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget RecentManager +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Managing Recently Used Files +-- +-- * Module available since Gtk+ version 2.10 +-- +module Graphics.UI.Gtk.Recent.RecentManager ( + +-- * Detail +-- +-- | 'RecentManager' provides a facility for adding, removing and looking up +-- recently used files. Each recently used file is identified by its URI, and +-- has meta-data associated to it, like the names and command lines of the +-- applications that have registered it, the number of time each application +-- has registered the same file, the mime type of the file and whether the file +-- should be displayed only by the applications that have registered it. +-- +-- The 'RecentManager' acts like a database of all the recently used files. +-- You can create new 'RecentManager' objects, but it is more efficient to use +-- the standard recent manager for the 'Screen' so that informations about the +-- recently used files is shared with other people using them. In case the +-- default screen is being used, adding a new recently used file is as simple +-- as: +-- +-- Recently used files are supported since Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----RecentManager +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + RecentManager, + RecentManagerClass, + castToRecentManager, + toRecentManager, + RecentData, + +-- * Constructors + recentManagerNew, + +-- * Methods + recentManagerGetDefault, + recentManagerAddItem, + recentManagerAddFull, + recentManagerRemoveItem, + -- recentManagerLookupItem, + recentManagerHasItem, + recentManagerMoveItem, + -- recentManagerGetItems, + recentManagerPurgeItems, + recentManagerErrorQuark, + +-- * Attributes + recentManagerFilename, + recentManagerLimit, + recentManagerSize, + +-- * Signals + recentManagerChanged, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Attributes +import System.Glib.Properties +import System.Glib.GList +import System.Glib.UTFString +import System.Glib.GObject (Quark, quarkFromString) +import System.Glib.GError (GErrorDomain, GErrorClass(..), propagateGError) +{#import Graphics.UI.Gtk.Recent.RecentInfo#} (RecentInfo) +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Signals#} + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) + +{#pointer *RecentData foreign newtype#} + +-------------------- +-- Constructors + +-- | Creates a new recent manager object. Recent manager objects are used to +-- handle the list of recently used resources. A 'RecentManager' object +-- monitors the recently used resources list, and emits the \"changed\" signal +-- each time something inside the list changes. +-- +recentManagerNew :: IO RecentManager +recentManagerNew = + constructNewGObject mkRecentManager $ + {# call gtk_recent_manager_new #} + +-------------------- +-- Methods + +-- | Gets a unique instance of 'RecentManager', that you can share in your +-- application without caring about memory management. The returned instance +-- will be freed when you application terminates. +-- +recentManagerGetDefault :: + IO RecentManager -- ^ returns A unique 'RecentManager'. Do not ref or + -- unref it. +recentManagerGetDefault = + makeNewGObject mkRecentManager $ + {# call gtk_recent_manager_get_default #} + +-- | Adds a new resource, pointed by @uri@, into the recently used resources +-- list. +-- +-- This function automatically retrieves some of the needed metadata and +-- setting other metadata to common default values; it then feeds the data to +-- 'recentManagerAddFull'. +-- +-- See 'recentManagerAddFull' if you want to explicitly define the metadata +-- for the resource pointed by @uri@. +-- +recentManagerAddItem :: RecentManagerClass self => self + -> String -- ^ @uri@ - a valid URI + -> IO Bool -- ^ returns @True@ if the new item was successfully added to the + -- recently used resources list +recentManagerAddItem self uri = + liftM toBool $ + withUTFString uri $ \uriPtr -> + {# call gtk_recent_manager_add_item #} + (toRecentManager self) + uriPtr + +-- | Adds a new resource, pointed by @uri@, into the recently used resources +-- list, using the metadata specified inside the {GtkRecentData, FIXME: struct +-- type} structure passed in @recentData@. +-- +-- The passed URI will be used to identify this resource inside the list. +-- +-- In order to register the new recently used resource, metadata about the +-- resource must be passed as well as the URI; the metadata is stored in a +-- {GtkRecentData, FIXME: struct type} structure, which must contain the MIME +-- type of the resource pointed by the URI; the name of the application that is +-- registering the item, and a command line to be used when launching the item. +-- +-- Optionally, a {GtkRecentData, FIXME: struct type} structure might contain +-- a UTF-8 string to be used when viewing the item instead of the last +-- component of the URI; a short description of the item; whether the item +-- should be considered private - that is, should be displayed only by the +-- applications that have registered it. +-- +recentManagerAddFull :: RecentManagerClass self => self + -> String -- ^ @uri@ - a valid URI + -> RecentData -- ^ @recentData@ - metadata of the resource + -> IO Bool -- ^ returns @True@ if the new item was + -- successfully added to the recently used + -- resources list, @False@ otherwise. +recentManagerAddFull self uri recentData = + liftM toBool $ + withUTFString uri $ \uriPtr -> + {# call gtk_recent_manager_add_full #} + (toRecentManager self) + uriPtr + recentData + +-- | Removes a resource pointed by @uri@ from the recently used resources list +-- handled by a recent manager. +-- +recentManagerRemoveItem :: RecentManagerClass self => self + -> String -- ^ @uri@ - the URI of the item you wish to remove + -> IO Bool -- ^ returns @True@ if the item pointed by @uri@ has been + -- successfully removed by the recently used resources list, and + -- @False@ otherwise. +recentManagerRemoveItem self uri = + liftM toBool $ + propagateGError $ \errorPtr -> + withUTFString uri $ \uriPtr -> + {# call gtk_recent_manager_remove_item #} + (toRecentManager self) + uriPtr + errorPtr + +-- | Searches for a URI inside the recently used resources list, and returns a +-- structure containing informations about the resource like its MIME type, or +-- its display name. +-- +-- recentManagerLookupItem :: RecentManagerClass self => self +-- -> String -- ^ @uri@ - a URI +-- -> IO RecentInfo -- ^ returns a {GtkRecentInfo, FIXME: boxed type} +-- -- structure containing information about the +-- -- resource pointed by @uri@, or {@NULL@, FIXME: this +-- -- should probably be converted to a Maybe data type} +-- -- if the URI was not registered in the recently used +-- -- resources list. Free with 'recentInfoUnref'. +-- recentManagerLookupItem self uri = +-- propagateGError $ \errorPtr -> +-- withUTFString uri $ \uriPtr -> do +-- result <- {# call unsafe gtk_recent_manager_lookup_item #} +-- (toRecentManager self) +-- uriPtr +-- errorPtr +-- makeNewRecentInfo result + +-- | Checks whether there is a recently used resource registered with @uri@ +-- inside the recent manager. +-- +recentManagerHasItem :: RecentManagerClass self => self + -> String -- ^ @uri@ - a URI + -> IO Bool -- ^ returns @True@ if the resource was found, @False@ otherwise. +recentManagerHasItem self uri = + liftM toBool $ + withUTFString uri $ \uriPtr -> + {# call gtk_recent_manager_has_item #} + (toRecentManager self) + uriPtr + +-- | Changes the location of a recently used resource from @uri@ to @newUri@. +-- +-- Please note that this function will not affect the resource pointed by +-- the URIs, but only the URI used in t... [truncated message content] |