File: WebBackForwardList.chs

package info (click to toggle)
haskell-webkit 0.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 328 kB
  • ctags: 2
  • sloc: haskell: 386; ansic: 5; makefile: 2
file content (227 lines) | stat: -rw-r--r-- 8,528 bytes parent folder | download
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-----------------------------------------------------------------------------
--  Module      :  Graphics.UI.Gtk.WebKit.Download
--  Author      :  Cjacker Huang
--  Copyright   :  (c) 2009 Cjacker Huang <jzhuang@redflag-linux.com>
-- 
--  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)
--
-- The history of a 'WebView'
-----------------------------------------------------------------------------

module Graphics.UI.Gtk.WebKit.WebBackForwardList (
-- * Types
  WebBackForwardList,

-- * Constructors
  webBackForwardListNewWithWebView,

-- * Methods
  webBackForwardListGoForward,
  webBackForwardListGoBack,
  webBackForwardListContainsItem,
  webBackForwardListGoToItem,
  webBackForwardListGetBackItem,
  webBackForwardListGetCurrentItem,
  webBackForwardListGetForwardItem,
  webBackForwardListGetNthItem,
  webBackForwardListGetBackLength,
  webBackForwardListGetForwardLength,
  webBackForwardListGetLimit,
  webBackForwardListSetLimit,
  webBackForwardListAddItem,
  webBackForwardListGetForwardListWithLimit,
  webBackForwardListGetBackListWithLimit,
 
) where

import Control.Monad		(liftM)

import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GList
import System.Glib.GError 
import Graphics.UI.Gtk.Gdk.Events

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

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


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

-- | Create an WebBackForwardList with a controlling WebView.
webBackForwardListNewWithWebView :: (WebViewClass webview) => webview -> IO WebBackForwardList
webBackForwardListNewWithWebView webview = 
    constructNewGObject mkWebBackForwardList $ 
      {#call web_back_forward_list_new_with_web_view#} 
        (toWebView webview)

-- | Steps forward in the back forward list.
webBackForwardListGoForward :: 
    WebBackForwardListClass self => self
 -> IO()
webBackForwardListGoForward webbackforwardlist = 
    {#call web_back_forward_list_go_forward#} (toWebBackForwardList webbackforwardlist)

-- | Steps back in the back forward list.
webBackForwardListGoBack :: 
    WebBackForwardListClass self => self
 -> IO()
webBackForwardListGoBack webbackforwardlist = 
    {#call web_back_forward_list_go_back#} (toWebBackForwardList webbackforwardlist)

-- | Check if an history item in the back forward list.
webBackForwardListContainsItem :: 
    (WebBackForwardListClass self, WebHistoryItemClass item) => self
 -> item
 -> IO Bool
webBackForwardListContainsItem webbackforwardlist webhistoryitem = 
    liftM toBool $ {#call web_back_forward_list_contains_item#} 
      (toWebBackForwardList webbackforwardlist)
      (toWebHistoryItem webhistoryitem)

-- | Go to the specified history item in the back forward list.
webBackForwardListGoToItem :: 
    (WebBackForwardListClass self,WebHistoryItemClass item) => self
 -> item
 -> IO()
webBackForwardListGoToItem webbackforwardlist webhistoryitem =
    {#call web_back_forward_list_go_to_item#} 
      (toWebBackForwardList webbackforwardlist)
      (toWebHistoryItem webhistoryitem)

-- | Return the history item that precedes the current history item.
webBackForwardListGetBackItem :: 
    WebBackForwardListClass self => self 
 -> IO (Maybe WebHistoryItem) -- ^ A 'WebHistoryItem' or @Nothing@ 
                              -- if there is nothing precedes the current item.
webBackForwardListGetBackItem webbackforwardlist = 
    maybeNull (makeNewGObject mkWebHistoryItem) $ 
      {#call web_back_forward_list_get_back_item#} 
        (toWebBackForwardList webbackforwardlist)

-- | Return the current history item of the back forward list
webBackForwardListGetCurrentItem :: 
    WebBackForwardListClass self => self
 -> IO WebHistoryItem
webBackForwardListGetCurrentItem webbackforwardlist = 
    makeNewGObject mkWebHistoryItem $ 
      {#call web_back_forward_list_get_current_item#} 
      (toWebBackForwardList webbackforwardlist)

-- | Return the item that succeeds the current item 

webBackForwardListGetForwardItem :: 
    WebBackForwardListClass self => self 
 -> IO (Maybe WebHistoryItem) -- ^ A 'WebHistoryItem' or @Nothing@ 
                              -- if there is nothing succeeds the current item.
webBackForwardListGetForwardItem webbackforwardlist = 
    maybeNull (makeNewGObject mkWebHistoryItem) $ 
      {#call web_back_forward_list_get_forward_item#} 
      (toWebBackForwardList webbackforwardlist)

-- | Return the history item at a given index relative to the current item.
webBackForwardListGetNthItem :: 
    WebBackForwardListClass self => self -- ^ @webbackforwardlist@ - a WebBackForwardList
 -> Int  -- ^ @index@ - the index of the item
 -> IO WebHistoryItem
webBackForwardListGetNthItem webbackforwardlist index =  
    makeNewGObject mkWebHistoryItem  $ 
      {#call web_back_forward_list_get_nth_item#} 
      (toWebBackForwardList webbackforwardlist)
      (fromIntegral index)

-- | Return the number of items that preced the current item.
webBackForwardListGetBackLength :: 
    WebBackForwardListClass self => self
 -> IO Int 
webBackForwardListGetBackLength webbackforwardlist = 
    liftM fromIntegral $ 
      {#call web_back_forward_list_get_back_length#} 
        (toWebBackForwardList webbackforwardlist)

-- | Return the number of items that succeed the current item.
webBackForwardListGetForwardLength :: 
    WebBackForwardListClass self => self
 -> IO Int
webBackForwardListGetForwardLength webbackforwardlist = 
    liftM fromIntegral $ 
      {#call web_back_forward_list_get_forward_length#} 
        (toWebBackForwardList webbackforwardlist)

-- | Return the maximum limit of the back forward list.
webBackForwardListGetLimit :: 
    WebBackForwardListClass self => self
 -> IO Int
webBackForwardListGetLimit webbackforwardlist = 
    liftM fromIntegral $ 
      {#call web_back_forward_list_get_limit#} 
        (toWebBackForwardList webbackforwardlist)

-- | Set the maximum limit of the back forward list. 
-- 
-- if the back forward list exceeds its capacity, 
-- items will be removed everytime a new item had been added.
--
webBackForwardListSetLimit :: 
    WebBackForwardListClass self => self
 -> Int
 -> IO()
webBackForwardListSetLimit webbackforwardlist limit = 
    {#call web_back_forward_list_set_limit#} 
      (toWebBackForwardList webbackforwardlist)
      (fromIntegral limit)

-- | Add the item to the back forward list.
webBackForwardListAddItem :: 
    (WebBackForwardListClass self,WebHistoryItemClass item) => self
 -> item
 -> IO ()
webBackForwardListAddItem webbackforwardlist webhistoryitem = 
    {#call web_back_forward_list_add_item#} 
      (toWebBackForwardList webbackforwardlist)
      (toWebHistoryItem webhistoryitem)

-- | Return a list of items that succeed the current item, limited by @limit@.
webBackForwardListGetForwardListWithLimit :: 
    WebBackForwardListClass self => self 
 -> Int  -- ^ the number of items to retrieve
 -> IO [WebHistoryItem] -- ^ a 'List' of items succeeding the current item, limited by limit.
webBackForwardListGetForwardListWithLimit webbackforwardlist limit = 
  {#call web_back_forward_list_get_forward_list_with_limit#} 
    (toWebBackForwardList webbackforwardlist)
    (fromIntegral limit)
    >>= fromGList 
    >>= mapM (makeNewGObject mkWebHistoryItem . return)

-- | Return a list of items that preced the current item.
-- limited by limit.
webBackForwardListGetBackListWithLimit :: 
    WebBackForwardListClass self => self 
 -> Int -- ^ the number of items to retrieve
 -> IO [WebHistoryItem] -- ^ a 'List' of items preceding the current item, limited by limit
webBackForwardListGetBackListWithLimit webbackforwardlist limit = 
  {#call web_back_forward_list_get_back_list_with_limit#} 
    (toWebBackForwardList webbackforwardlist)
    (fromIntegral limit)
    >>= fromGList 
    >>= mapM (makeNewGObject mkWebHistoryItem . return)