gi-nm

Bindings for NM (NetworkManager library), autogenerated by haskell-gi.


Keywords
lgpl, library, Propose Tags, Report a vulnerability, Skip to Readme, Index, Quick Jump, GI.NM, GI.NM.Callbacks, GI.NM.Config, GI.NM.Constants, GI.NM.Enums, GI.NM.Flags, GI.NM.Functions, GI.NM.Interfaces, GI.NM.Interfaces.Connection, GI.NM.Interfaces.VpnEditor, GI.NM.Interfaces.VpnEditorPlugin, GI.NM.Objects, GI.NM.Objects.AccessPoint, GI.NM.Objects.ActiveConnection, GI.NM.Objects.Checkpoint, GI.NM.Objects.Client, GI.NM.Objects.Device, GI.NM.Objects.Device6Lowpan, GI.NM.Objects.DeviceAdsl, GI.NM.Objects.DeviceBond, GI.NM.Objects.DeviceBridge, GI.NM.Objects.DeviceBt, GI.NM.Objects.DeviceDummy, GI.NM.Objects.DeviceEthernet, GI.NM.Objects.DeviceGeneric, GI.NM.Objects.DeviceHsr, GI.NM.Objects.DeviceIPTunnel, GI.NM.Objects.DeviceInfiniband, GI.NM.Objects.DeviceLoopback, GI.NM.Objects.DeviceMacsec, GI.NM.Objects.DeviceMacvlan, GI.NM.Objects.DeviceModem, GI.NM.Objects.DeviceOlpcMesh, GI.NM.Objects.DeviceOvsBridge, GI.NM.Objects.DeviceOvsInterface, GI.NM.Objects.DeviceOvsPort, GI.NM.Objects.DevicePpp, GI.NM.Objects.DeviceTeam, GI.NM.Objects.DeviceTun, GI.NM.Objects.DeviceVeth, GI.NM.Objects.DeviceVlan, GI.NM.Objects.DeviceVrf, GI.NM.Objects.DeviceVxlan, GI.NM.Objects.DeviceWifi, GI.NM.Objects.DeviceWifiP2P, GI.NM.Objects.DeviceWimax, GI.NM.Objects.DeviceWireGuard, GI.NM.Objects.DeviceWpan, GI.NM.Objects.DhcpConfig, GI.NM.Objects.IPConfig, GI.NM.Objects.Object, GI.NM.Objects.RemoteConnection, GI.NM.Objects.SecretAgentOld, GI.NM.Objects.Setting, GI.NM.Objects.Setting6Lowpan, GI.NM.Objects.Setting8021x, GI.NM.Objects.SettingAdsl, GI.NM.Objects.SettingBluetooth, GI.NM.Objects.SettingBond, GI.NM.Objects.SettingBondPort, GI.NM.Objects.SettingBridge, GI.NM.Objects.SettingBridgePort, GI.NM.Objects.SettingCdma, GI.NM.Objects.SettingConnection, GI.NM.Objects.SettingDcb, GI.NM.Objects.SettingDummy, GI.NM.Objects.SettingEthtool, GI.NM.Objects.SettingGeneric, GI.NM.Objects.SettingGsm, GI.NM.Objects.SettingHostname, GI.NM.Objects.SettingHsr, GI.NM.Objects.SettingIP4Config, GI.NM.Objects.SettingIP6Config, GI.NM.Objects.SettingIPConfig, GI.NM.Objects.SettingIPTunnel, GI.NM.Objects.SettingInfiniband, GI.NM.Objects.SettingLink, GI.NM.Objects.SettingLoopback, GI.NM.Objects.SettingMacsec, GI.NM.Objects.SettingMacvlan, GI.NM.Objects.SettingMatch, GI.NM.Objects.SettingOlpcMesh, GI.NM.Objects.SettingOvsBridge, GI.NM.Objects.SettingOvsDpdk, GI.NM.Objects.SettingOvsExternalIDs, GI.NM.Objects.SettingOvsInterface, GI.NM.Objects.SettingOvsOtherConfig, GI.NM.Objects.SettingOvsPatch, GI.NM.Objects.SettingOvsPort, GI.NM.Objects.SettingPpp, GI.NM.Objects.SettingPppoe, GI.NM.Objects.SettingProxy, GI.NM.Objects.SettingSerial, GI.NM.Objects.SettingSriov, GI.NM.Objects.SettingTCConfig, GI.NM.Objects.SettingTeam, GI.NM.Objects.SettingTeamPort, GI.NM.Objects.SettingTun, GI.NM.Objects.SettingUser, GI.NM.Objects.SettingVeth, GI.NM.Objects.SettingVlan, GI.NM.Objects.SettingVpn, GI.NM.Objects.SettingVrf, GI.NM.Objects.SettingVxlan, GI.NM.Objects.SettingWifiP2P, GI.NM.Objects.SettingWimax, GI.NM.Objects.SettingWireGuard, GI.NM.Objects.SettingWired, GI.NM.Objects.SettingWireless, GI.NM.Objects.SettingWirelessSecurity, GI.NM.Objects.SettingWpan, GI.NM.Objects.SimpleConnection, GI.NM.Objects.VpnConnection, GI.NM.Objects.VpnPluginInfo, GI.NM.Objects.VpnPluginOld, GI.NM.Objects.VpnServicePlugin, GI.NM.Objects.WifiP2PPeer, GI.NM.Objects.WimaxNsp, GI.NM.Structs, GI.NM.Structs.BridgeVlan, GI.NM.Structs.DnsEntry, GI.NM.Structs.IPAddress, GI.NM.Structs.IPRoute, GI.NM.Structs.IPRoutingRule, GI.NM.Structs.KeyfileHandlerData, GI.NM.Structs.LldpNeighbor, GI.NM.Structs.Range, GI.NM.Structs.SriovVF, GI.NM.Structs.TCAction, GI.NM.Structs.TCQdisc, GI.NM.Structs.TCTfilter, GI.NM.Structs.TeamLinkWatcher, GI.NM.Structs.VariantAttributeSpec, GI.NM.Structs.VpnEditorPluginVT, GI.NM.Structs.WireGuardPeer, gi-nm-1.0.1.tar.gz, browse, Package description, Package maintainers, inaki, edit package information , https://hackage.haskell.org/package/gi-nm-1.0.1/docs/GI-NM.html](https://hackage.haskell.org/package/gi-nm-1.0.1/docs/GI-NM.html), haskell-gi, the project page, the Wiki, ghc, gobject-introspection, gtk, haskell, haskell-bindings
License
LGPL-2.1-only
Install
cabal install gi-nm-1.0.1

Documentation

haskell-gi

Generate Haskell bindings for GObject Introspection capable libraries.

Installation

To compile the bindings generated by haskell-gi, make sure that you have installed the necessary development packages for the libraries you are interested in. The following are examples for some common distributions. (If your distribution is not listed please send a pull request!)

Fedora

sudo dnf install gobject-introspection-devel webkitgtk4-devel gtksourceview3-devel

Debian / Ubuntu

sudo apt-get install libgirepository1.0-dev libwebkit2gtk-4.0-dev libgtksourceview-3.0-dev

Arch Linux

sudo pacman -S gobject-introspection gobject-introspection-runtime gtksourceview3 webkit2gtk

Mac OSX

Install Homebrew and install GTK and GObject Introspection:

brew install gobject-introspection gtk4

Ensure the path to libffi (probably /usr/local/opt/libffi/lib/pkgconfig) is in the PKG_CONFIG_PATH environment variable.

Windows

Please see here for detailed installation instructions in Windows.

Using the generated bindings

The most recent versions of the generated bindings are available from hackage. To install, start by making sure that you have a recent (2.0 or later) version of cabal-install, for instance:

$ cabal install cabal-install
$ cabal --version
cabal-install version 2.4.1.0
compiled using version 2.4.1.0 of the Cabal library

Here is an example "Hello World" program:

{-# LANGUAGE OverloadedStrings, OverloadedLabels, OverloadedRecordDot, ImplicitParams #-}
{- cabal:
build-depends: base >= 4.16, haskell-gi-base, gi-gtk == 4.0.*
-}
import Control.Monad (void)

import qualified GI.Gtk as Gtk
import Data.GI.Base

activate :: Gtk.Application -> IO ()
activate app = do
  button <- new Gtk.Button [#label := "Click me",
                            On #clicked (?self `set` [#sensitive := False,
                                                      #label := "Thanks for clicking me"])]

  window <- new Gtk.ApplicationWindow [#application := app,
                                       #title := "Hi there",
                                       #child := button]
  window.show

main :: IO ()
main = do
  app <- new Gtk.Application [#applicationId := "haskell-gi.example",
                              On #activate (activate ?self)]

  void $ app.run Nothing

This program uses the new OverloadedRecordDot extension in GHC 9.2, so make sure you have a recent enough version of GHC installed. To run this program, copy it to a file (hello.hs, say), and then

$ cabal run hello.hs

For a more involved example, see for instance this WebKit example. Further documentation can be found in the Wiki.

Translating from the C API to the haskell-gi generated API

The translation from the original C API to haskell-gi is fairly straightforward: for method names simply remove the library prefix (gtk, gdk, etc.), and convert to camelCase. I.e. gtk_widget_show becomes widgetShow in the module GI.Gtk (provided by the gi-gtk package).

For properties, add the type of the object as a prefix: so the sensitive property of GtkWidget becomes widgetSensitive in gi-gtk. These can be set using the new syntax, as follows:

b <- new Button [widgetSensitive := True]

or using set after having created the button

b `set` [widgetSensitive := False]

Alternatively you can use setWidgetSensitive and friends to set properties individually if you don't like the list syntax.

Finally, for signals you want to use the onTypeSignalName functions, for example onButtonClicked:

onButtonClicked b $ do ...

This is the basic dictionary. Note that all the resulting symbols can be conveniently searched in hoogle.

There is also support for the OverloadedLabels extension in GHC 8.0 or higher. So the examples above can be shortened (by omitting the type that introduces the signal/property/method) to

b <- new Button [#sensitive := True]
on b #clicked $ do ...
#show b

Hopefully this helps to get started! For any further questions there is a gitter channel that may be helpful at https://gitter.im/haskell-gi/haskell-gi.

Binding to new libraries

It should be rather easy to generate bindings to any library with gobject-introspection support, see the examples in the bindings folder. Pull requests appreciated!

Higher-Level Bindings

The bindings in haskell-gi aim for complete coverage of the bound APIs, but as a result they are imperative in flavour. For nicer, higher-level approaches based on these bindings, see:

Other Resources


Join the chat at https://gitter.im/haskell-gi/haskell-gi Linux CI