#!/usr/bin/env python

import gconf, gtk, sys

ID	= None
BASEDIR	= "/apps/revelation"
KEY	= "/apps/revelation/view/passwords"
RUN = 0


def callback(client, id, entry, data):

	if id != ID:
		print "mismatch:", RUN, id, ID
		sys.exit(1)


client = gconf.client_get_default()
client.add_dir(BASEDIR, gconf.CLIENT_PRELOAD_NONE)


# test multiple callbacks using
print "test 1"
ID = client.notify_add(KEY, callback)

value = 1
for i in range(10000):
	RUN += 1
	value = 1 - value

	node = client.get(KEY)
	node.set_bool(value)
	client.set(KEY, node)

	while gtk.events_pending() == True:
		gtk.main_iteration()

client.notify_remove(ID)


# test single callback multiple times
print "test 2"

value = 1
RUN = 0
for i in range(10000):
	RUN += 1
	value = 1 - value
	ID = client.notify_add(KEY, callback)

	node = client.get(KEY)
	node.set_bool(value)
	client.set(KEY, node)

	while gtk.events_pending() == True:
		gtk.main_iteration()

	client.notify_remove(ID)
