#!/usr/bin/env python
#
# Author: Matt Fischer <matthew.fischer@canonical.com>
# Copyright (C) 2012 Canonical, Ltd
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version. See http://www.gnu.org/copyleft/gpl.html the full text of the
# license.
#
# This code is based on the LightDM GTK Greeter which was written by:
# Robert Ancell <robert.ancell@canonical.com>

# required packages:
# liblightdm-gobject-1-0
# gir1.2-lightdm-1
# python-gobject
# gir1.2-glib-2.0
# gir1.2-gtk-3.0

from gi.repository import GObject
#from gi.repository import GLib
#from gi.repository import Gtk
from gi.repository import LightDM
import sys

greeter = None


# Callback for after we send LightDM the password, this method
# has to handle a successful login, in which case we start the session
# or a failed login, in which case we tell the user
def authentication_complete_cb(greeter):
    if greeter.get_is_authenticated():
        # For our simple example we always start Unity-2d.  The LightDM
        # API has ways to query available sessions, please see the docs.
        if not greeter.start_session_sync("xubuntu"):
            print >> sys.stderr, "Failed to start xubuntu session"
    else:
        print >> sys.stderr, "Login failed"

if __name__ == '__main__':
    main_loop = GObject.MainLoop ()
    greeter = LightDM.Greeter()

    # connect signal handlers to LightDM
    greeter.connect ("authentication-complete", authentication_complete_cb)

    # connect to greeter
    greeter.connect_sync()

    greeter.authenticate("guest");

    main_loop.run ()
