Author: jerome
Date: 2009-12-15 10:51:42 +0100 (Tue, 15 Dec 2009)
New Revision: 5976

Modified:
   
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
Log:
* Fixed and implemented configuration.
* Finished incoming calls.
* Started to implement outgoing calls. 

Modified: 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
   2009-12-15 09:08:36 UTC (rev 5975)
+++ 
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/plugin-skype.py
   2009-12-15 09:51:42 UTC (rev 5976)
@@ -59,42 +59,42 @@
         self.throwEmoticons = True
     
     
-    def getThrowEmoticons():
+    def getThrowEmoticons(self):
         '''
         Return true if emoticons will be thrown.
         '''
         return self.throwEmoticons
     
     
-    def setThrowEmoticons(aThrowEmoticons):
+    def setThrowEmoticons(self, aThrowEmoticons):
         '''
         Set the throwEmoticons parameter value.
         '''
         self.throwEmoticons = aThrowEmoticons
     
     
-    def getThrowTTS()
+    def getThrowTTS(self):
         '''
         Return the throwTTS parameter value.
         '''
         return self.throwTTS
     
     
-    def setThrowTTS(throw)
+    def setThrowTTS(self, throw):
         '''
         Set the throwTTS parameter value.
         '''
         self.throwTTS = throw
     
     
-    def getIsOutgoing()
+    def getIsOutgoing(self):
         '''
         Return the outgoing parameter value.
         '''
         return self.isOutgoing
     
     
-    def setIsOutgoing(outgoing)
+    def setIsOutgoing(self, outgoing):
         '''
         Set the outgoing parameter value.
         '''
@@ -115,10 +115,13 @@
     connectorObj  = None
     
     #Used for run command only.
-    ready = False
     command = ""
     canrun  = True
     
+    #Used for outgoing parameter only.
+    onlineList = []
+    currentContact = -1
+    
     ##----------------------------------------------------------------
     ## * Skype plugin main entry point.
     ##----------------------------------------------------------------
@@ -131,7 +134,7 @@
         self.port = TuxDroidServerUtils.getServerPort()
         
         #Check for the command.
-        if self.getCommand() == "runDaemon":
+        if self.getCommand() == "check":
             self.runDaemon()
         elif self.getCommand() == "run":
             self.run()
@@ -139,7 +142,7 @@
             self.runDaemon()
     
     ##----------------------------------------------------------------
-    ## * PLUGIN COMMAND : Set Tux Droid for a call.
+    ## * PLUGIN COMMAND : Set Tux Droid for an incoming call call.
     ##----------------------------------------------------------------
     def run(self):
         '''
@@ -150,22 +153,48 @@
         self.client.registerOnConnectedCallBack(self.ClientOnConnected)
         self.client.start()
         
+        if self.configuration().getIsOutgoing():
+            #Then getting online contact list.
+            self.command = 'outgoing'
+            self.client.notify('outgoing_call')
     
     
     def incomingPluginEvent(self, eventName, eventValues):
         '''
         Tux Droid plugin event callback.
         '''
-        if not self.ready:
-            return
-        
+        self.throwTrace(self.command)
         if self.command == 'incoming':
-            #Accept call
+            #Accept call 
             if eventName   == 'head':
                 self.client.notify('accept_call')
             #Reject Call          
             elif eventName in ['left', 'right']:
                 self.client.notify('reject_call')
+                
+        #endcall command, waiting for the call ends.
+        if self.command == 'wait_end_call':
+            self.throwTrace('here 0')
+            if eventName == 'head':
+                self.throwTrace('here 1')
+                #Then send finish call command to IPN server.
+                self.client.notify('end_call')
+    
+    
+    def outgoingPluginEvent(self, eventName, eventValues):
+        '''
+        Tux Droid event callback for outgoing calls.
+        '''
+        self.throwTrace("outgoing")
+        if self.command == 'outgoing':
+            #Proceed call
+            if eventName   == 'head':
+                self.client.notify('call_contact')
+            #Next contact          
+            elif eventName == 'left':
+                self.client.notify('next_contact')
+            elif eventName == 'right':
+                self.client.notify('previous_contact')
             
             
          
@@ -173,27 +202,40 @@
         '''
         Recieved a message from server.
         '''
+        thread = threading.Thread(target=self.OnNotification, args = (Message, 
))
+        thread.start()
+        
+    
+    def OnNotification(self, Message):
+        '''
+        Threaded client notification.
+        '''
         if Message == 'command>incoming':
             self.throwNotification("start")
             self.throwActuation("upFlippers")
             self.throwActuation("openMouth")
             self.throwNotification("stop")
-            self.ready = True
             self.command = 'incoming'
+        elif Message == 'command>wait_end_call':
+            self.command = 'wait_end_call'
         elif Message == 'command>endcall':
             self.throwNotification("start")
             self.throwActuation("downFlippers")
             self.throwActuation("closeMouth")
             self.throwNotification("stop")
             self.stop()
-                   
+        elif Message[:4].find('tts>') != -1:
+            self.throwNotification("start")
+            self.throwMessage('%s' % Message[4:])
+            self.throwNotification("stop")
+
     
     def ClientOnConnected(self, id):
         '''
         '''
         pass
-        
     
+    
     ##----------------------------------------------------------------
     ##  * DAEMON command and functions.
     ##----------------------------------------------------------------
@@ -203,12 +245,14 @@
         Run plugin command.
         '''
         #Creating and starting server.
+        
         self.serv = IPNServer('127.0.0.1', 48536)
         self.serv.registerOnClientAddedCallBack(self.ServerOnClientAdded)
         self.serv.registerOnClientRemovedCallBack(self.ServerOnClientRemoved)
         
self.serv.registerOnClientNotificationCallBack(self.ServerOnClientNotification)
         self.serv.start()
         
+        
         #Initialize skype client and api objects.
         self.connectorObj = connector.Connector()
         self.connectorObj.OnAPIReady = self.initializeDaemon
@@ -303,14 +347,14 @@
         '''
         Outgoing call finished event.
         '''
-        #Send reset switches signal.
-        self.serv.notify('command>endcall')
+        pass
         
     
     def OnOutgoingFinished(self, contactHandle):
         '''
         '''
-        pass
+        #Send reset switches signal.
+        self.serv.notify('command>endcall')
     
     
     def OnChatMessage(self, contactHandle):
@@ -328,34 +372,57 @@
         '''
         Event that notify of incoming emoticon.
         '''
+        if not self.configuration().getThrowEmoticons():
+            return
         self.throwNotification("start")
         self.throwActuation("playAttitune", attName)
         self.throwNotification("stop")
+        
+        
      
-     
     def OnTTS(self, sentence):
         '''
         Event that notify a tts sentence to be said by Tux Droid.
         '''
+        if not self.configuration().getThrowTTS():
+            return
         self.throwNotification("start")
         self.throwMessage(sentence)
         self.throwNotification("stop")
     
     
-    def ContactStatusChanged(self, UserHandle, Status):
+    def callCurrentContact(self):
         '''
-        Event that notify a contact status changed.
+        Call the current selected contact.
         '''
-        #Nothing for this plugin version, maybe later on.
         pass
     
     
+    def nextContact(self):
+        '''
+        Go next in the online contacts list.
+        '''
+        try:
+            self.currentContact += 1
+            self.serv.notify('tts>%s' % self.onlineList[self.currentUser])
+        except:
+            self.serv.notify('tts>%s' % self.onlineList[0])
+            
+    
+    def previousContact(self):
+        '''
+        Go previous in the online contacts list.
+        '''
+        pass
+    
+    
     def mainloop(self):
         '''
         Run main loop.
         '''
         while 1:
-            time.sleep(2.0)
+            time.sleep(1.0)
+            
             #Setting Tux Droid as audio peripheral.
             try:
                 #in try statement to take calls in care.
@@ -363,7 +430,7 @@
                     self.synchronious.setAudioCards()
             except:
                 pass
-                    
+                   
     
     
     ##----------------------------------------------------------------
@@ -373,13 +440,16 @@
         '''
         OnPluginStop event.
         '''
-        if self.connectorObj != None:
-            if self.getCommand() == 'outgoingCall':
-                #TODO update this function.
-                self.connectorObj.stop(KillClient=True)
-            else:
-                #In other cases, close connection but not skype client.
-                self.connectorObj.stop()
+        if self.getCommand() == 'run':
+            self.client.stop()
+        else:    
+            if self.connectorObj != None:
+                if self.getCommand() == 'outgoingCall':
+                    #TODO update this function.
+                    self.connectorObj.stop(KillClient=True)
+                else:
+                    #In other cases, close connection but not skype client.
+                    self.connectorObj.stop()
     
     
    
@@ -391,7 +461,10 @@
         '''
         #Start the adequate function for each plugin command.
         if self.getCommand() == 'run':
-            self.incomingPluginEvent(eventName, eventValues)
+            if not self.configuration().getIsOutgoing():
+                self.incomingPluginEvent(eventName, eventValues)
+            else:
+                self.outgoingPluginEvent(eventName, eventValues)
         
         
      
@@ -401,7 +474,8 @@
     def ServerOnClientAdded(self, idClient):
         '''
         '''
-        self.serv.notify( "command>" + self.command )
+        if not self.configuration().getIsOutgoing():
+            self.serv.notify( "command>" + self.command )
         
     
     def ServerOnClientRemoved(self, idClient):
@@ -413,14 +487,37 @@
     def ServerOnClientNotification(self, idClient, Message):
         '''
         '''
+        #--------  Incoming IPN messages --------#
         if Message == 'accept_call':
             if self.asynchronious.call != None:
                 #Take call
-                self.synchronious.acceptCall(self.asynchronious.call)
+                self.serv.notify('command>wait_end_call')
+                thread = threading.Thread(target=self.synchronious.acceptCall, 
args =(self.asynchronious.call, ))
+                thread.start()
         elif Message == 'reject_call' :
-             #Reject call.
-             self.synchronious.rejectCall()
+            #Reject call.
+            self.synchronious.rejectCall()
         
+        #--------  Outgoing IPN messages --------#        
+        elif Message == 'outgoing_call':
+            #Outgoing call requested, so getting online list and sending 
outgoing command.
+            self.onlineList = self.synchronious.getOnlineList()
+            self.throwTrace(self.onlineList)
+        #Outgoing
+        elif Message == 'call_contact':
+            thread = threading.Thread(target=self.callCurrentContact)
+            thread.start()
+        elif Message == 'next_contact':
+            thread = threading.Thread(target=self.nextContact)
+            thread.start()
+        elif Message == 'previous_contact':
+            thread = threading.Thread(target=self.previousContact)
+            thread.start()
+        
+        #--------  Common IPN messages --------#
+        elif Message == 'end_call':
+            self.synchronious.finishCall()
+        
 
 if __name__ == "__main__":
     plugin = SkypePlugin()


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to