import CORBA
import bonobo
import gtk
import GNOME.Evolution
import GNOME__POA.Evolution
from gtk import TRUE, FALSE
from GNOME.Evolution.Calendar import Listener

class CalListener(GNOME__POA.Evolution.Calendar.Listener):
    def notifyCalOpened(self, status, cal):
        self._cal=cal
        print "Calendar opened."
        uids=cal.getUIDs(GNOME.Evolution.Calendar.TYPE_ANY)
        for u in uids:
            cobj=cal.getObject(u)
            print cobj
        # we're done now
        gtk.mainquit()

    def notifyCategoriesChanged(self, cats):
        pass

def init_server ():
    print "About to instantiate calendar server"
    calserver = bonobo.get_object(
        "OAFIID:GNOME_Evolution_Wombat_CalendarFactory",
        "GNOME/Evolution/Calendar/CalFactory")
    if not calserver:
        print 'Cannot get CalendarFactory'
        return FALSE
    print "Got calendar server"
    listener=CalListener()
    r=calserver.open('file:///tmp/calendar.ics', 
        0,
        listener._this())

    return FALSE

gtk.idle_add (init_server)
bonobo.main ()
