[Haskell-cafe] Re: Opening a gtk2hs link in default browser

Andy Stewart lazycat.manatee at gmail.com
Sun Oct 17 07:43:01 EDT 2010


Hi Dmitry,

Dmitry V'yal <akamaus at gmail.com> writes:

> Hello list,
>
> I'm trying to make a clickable link in gtk2hs program. Clicking it should open an url in the default
> browser. Can I hope to find some portable solution in gtk2hs (it should work in linux and windows)
> or should I start searching platform specific ones, like /usr/bin/xdg-open or something?
>
> Can any examples be found in existing haskell software?
The answer is yes, use GIO function (Unfortunately, those code in gtk2hs darcs).

Here is demo code:

openUrlBySystemTool :: String -> IO ()
openUrlBySystemTool url = do
  infos <- appInfoGetAllForType "text/html"
  case infos of
    [] -> return ()
    xs -> appInfoLaunchUris (head xs) [url] Nothing
    
Function 'appInfoGetAllForType' return list of AppInfo for given
contentType (like mime type for file)

AppInfo is abstract type to contain application information in system
(cross Windows and Linux)

After you got [AppInfo] (list of program for open url) from
"appInfoGetAllForType "text/html", 
you can use function 'appInfoLaunchUris' launch link with any program register in system.

Cheers,

  -- Andy



More information about the Haskell-Cafe mailing list