[tuxdroid-svn] r5280 - software_suite_v3/software/plugin/plugin-skype/trunk/executables
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-08-05 11:02:28
|
Author: jerome
Date: 2009-08-05 13:02:09 +0200 (Wed, 05 Aug 2009)
New Revision: 5280
Modified:
software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py
Log:
* Fixed : 152 ?\226?\128?\148 Skype plugin - Weird behaviour
Modified: software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py
===================================================================
--- software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py 2009-08-04 13:50:11 UTC (rev 5279)
+++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py 2009-08-05 11:02:09 UTC (rev 5280)
@@ -25,7 +25,9 @@
from util.SimplePlugin.SimplePlugin import SimplePlugin
from util.system.TaskBar import refreshTaskBar
from util.system.Device import *
+from Skype4Py.errors import ISkypeError as SkypeError, ISkypeAPIError as SkypeAPIError
+
class Configuration(SimplePluginConfiguration):
"""This class make an access to the plugin parameters.
Parameters are automatically filled by the SimpleGadget class at plugin
@@ -78,12 +80,14 @@
}
self.__mutexContacts = threading.Lock()
self.__mutexCall = threading.Lock()
+ self.__connectionMutex = threading.Lock()
# Skype api objects.
self.__skype = None
self.__apiAttachState = -1
self.__activeMain = True
# Skype process
self.__skypeProcess = None
+ self.attemptTimeout = 0
def start(self):
"""Plugin entry point.
@@ -101,14 +105,19 @@
self.__tuxBodyLedsBlink()
# Start Skype client if not started.
self.__startSkypeApp()
+
if not self.__activeMain:
self.stop()
- return
+ return
+
# Connect to skype api.
self.__connectSkypeAPI()
+ except SkypeAPIError:
+ pass
except:
self.throwMessage("I cannot get connected to your Skeyepe. Please, check if you are connected. And verify if I can access skeyepe.")
self.stop()
+
def onPluginStop(self):
"""Callback on plugin stop.
@@ -188,6 +197,24 @@
"""Received api connection status.
"""
self.__apiAttachState = value
+ if ( value in [Skype4Py.apiAttachSuccess, ]) and (not (self.attemptTimeout == 6)):
+ # Set tux as audio card.
+ self.__selectTuxAsAudioCard()
+ time.sleep(0.2)
+
+ # Get the contacts list.
+ self.__getContacts()
+
+ # Set the user status.
+
+ status = self.configuration().getStartupStatus()
+ if self.__allowedStatus.has_key(status):
+ self.__skype.ChangeUserStatus(self.__allowedStatus[status])
+
+ elif self.attemptTimeout == 6:
+ self.stop()
+ return
+
def __selectTuxAsAudioCard(self):
"""Set tux as audio peripheral.
@@ -218,29 +245,42 @@
return False
else:
return False
-
+
+
def __connectSkypeAPI(self):
"""Get connected to the Skype client.
"""
# Create and attach skype api
self.__skype = Skype4Py.Skype()
- self.__skype.Timeout = 20000
self.__skype.OnAttachmentStatus = self.__onSkypeAPIStatusReceived
self.__skype.OnCallStatus = self.__onSkypeCall
- self.__skype.Attach()
- # Set tux as audio card.
- self.__selectTuxAsAudioCard()
- # Set the user status.
- status = self.configuration().getStartupStatus()
- if self.__allowedStatus.has_key(status):
- self.__skype._SetCurrentUserStatus(self.__allowedStatus[status])
- # Get the contacts list.
- self.__getContacts()
+
+ try:
+ self.__skype.Timeout = 7000
+ self.__skype.Attach()
+
+ except SkypeAPIError:
+ self.__skypeConnectionFailed()
+
+
+ def __skypeConnectionFailed(self):
+ '''
+ '''
+ while self.attemptTimeout != 6:
+ time.sleep(5)
+ try:
+ self.__skype.Attach()
+ except SkypeAPIError:
+ pass
+ else:
+ self.stop()
+ return
+
def __skypeAPIIsConnected(self):
"""Return true if connected.
"""
- return self.__apiAttachState == 0
+ return self.__apiAttachState in [0, ]
def __onOutgoingCall(self, Call, Status):
"""Set outgoing calls functions.
@@ -279,26 +319,36 @@
def callCurrentContact(self, contact):
"""Call a specified contact.
"""
- self.__mutexCall.acquire()
- # Get skype name
- callName = self.__contactsDict.get(contact)
- # Place call
- if (callName != None) and (self.__currentCall == None):
- self.__currentCall = self.__skype.PlaceCall(callName)
- self.__mutexCall.release()
+ try:
+ self.__mutexCall.acquire()
+ # Get skype name
+ callName = self.__contactsDict.get(contact)
+ # Place call
+ if (callName != None) and (self.__currentCall == None):
+ self.__currentCall = self.__skype.PlaceCall(callName)
+ self.__mutexCall.release()
+ except:
+ if self.__mutexCall.locked():
+ self.__mutexCall.release()
+ return
def hangUp(self):
"""Finish all placed calls.
"""
- self.__mutexCall.acquire()
- if self.__currentCall != None:
- try:
- self.__currentCall.Finish()
- self.__currentCall = None
- except:
- self.__currentCall.Resume()
- self.__currentCal = None
- self.__mutexCall.release()
+ try:
+ self.__mutexCall.acquire()
+ if self.__currentCall != None:
+ try:
+ self.__currentCall.Finish()
+ self.__currentCall = None
+ except:
+ self.__currentCall.Resume()
+ self.__currentCal = None
+ self.__mutexCall.release()
+ except:
+ if self.__mutexCall.locked():
+ self.__mutexCall.release()
+ return
# ==========================================================================
# Skype application control
@@ -365,6 +415,7 @@
def __startSkypeAppLinux(self):
"""Start skype on linux ( thread needed to do not block the script ).
"""
+ self.throwTrace('starting skype application')
# Searching for skype binary.
result = []
found =False
@@ -384,13 +435,9 @@
#start skype
self.__skypeProcess = subprocess.Popen("skype", stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
- while True:
- try:
- buffer = self.__skypeProcess.stdout.read(100)
- except:
- buffer = ""
- if len(buffer) == 0:
- break
+
+ while not self.__getSkypeAppConnected():
+ sleep(1000)
self.__activeMain = True
else:
self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.")
@@ -448,6 +495,7 @@
else:
self.__contactsDict[userHEnc] = userHEnc
self.__contactsList.append(userHEnc)
+
self.__contactsDict["Quit gadget"] = "Quit gadget"
self.__contactsList.insert(0, "Quit gadget")
self.__currentContactIndex = 0
|