import rhythmdb
import rb
import sys
import speechd 
import glib

class DJAquaPlugin(rb.Plugin):
    def __init__(self):
        rb.Plugin.__init__(self)
        
    def activate(self, shell):
        self.dj = speechd.SSIPClient('djaqua')

        self.sp = shell.get_player()

        self.sp.connect('playing-song-changed', self.playing_song_changed)

    def dj_done_callback(self, callback_type=None, event_types=None):
        if callback_type == speechd.CallbackType.BEGIN:
            print >> sys.stderr, "CallbackType %s: lowering volume" % callback_type
            self.lower_volume();
        elif callback_type in (speechd.CallbackType.END, speechd.CallbackType.CANCEL):
            print >> sys.stderr, "CallbackType %s: raising volume" % callback_type
            self.raise_volume();

    def playing_song_changed(self, sp, entry):
        script = "Testing 1 2 3"
#        self.lower_volume();
        self.dj.speak(script,
                      callback=self.dj_done_callback,
                      event_types=(speechd.CallbackType.BEGIN,
                                   speechd.CallbackType.CANCEL,
                                   speechd.CallbackType.END))
        
    def deactive(self, shell):
        self.client.close()

    def lower_volume(self):
        self.sp.set_volume(self.sp.get_volume() / 4)
        return False

    def raise_volume(self):
        self.sp.set_volume(self.sp.get_volume() * 4);
        return False

        

        
        


        
