#!/usr/bin/python
# -*- coding: UTF8 -*-

"""
    Tux Droid - Italian Tux Droid gajim gadget
    Copyright (C) 2007 Francesco Frassinelli <frafra _at_ autistici _dot_ org>

    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 2, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
"""

__author__  = 'Francesco Frassinelli <frafra _at_ autistici _dot_ org>'
__appname__ = 'italian gajim gadget'
__version__ = '0.0.1'
__date__    = '2007/12/25'
__license__ = 'GPL'

from sys import path
path.append('/opt/tuxdroid/api/python')
from tux import *
import dbus, gobject, dbus.glib

bus = dbus.SessionBus()

obj = bus.get_object("org.gajim.dbus", "/org/gajim/dbus/RemoteObject")
gajim = dbus.Interface(obj, "org.gajim.dbus.RemoteInterface")

def onSignOn(details):
    nick = details[1][0].split(u'@')[0]
    say = "%s, si è connesso" % nick.encode("utf-8")
    say = say
    tux.tts.speak(say)

def onMessage(details):
	message = details[1]
	user = message[0].split(u'@')[0]
	text = message[1].replace("'", "'\\''").replace("~", " euro")
	msgtype = message[4]
	say = "%s, ha detto: %s" % (user, text)
	say = say.encode("utf-8")
	tux.tts.speak(say)

gajim.connect_to_signal("NewMessage", onMessage)
gajim.connect_to_signal("ContactPresence", onSignOn)

gobject.MainLoop().run()
