[tuxdroid-svn] r5521 - software_suite_v3/software/plugin/plugin-skype/trunk/executables
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-09-30 13:13:23
|
Author: jerome
Date: 2009-09-30 14:22:19 +0200 (Wed, 30 Sep 2009)
New Revision: 5521
Modified:
software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py
Log:
* Fixed a bug retrieving contacts list at gadget startup on Linux.
* Improved contacts list handling.
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-09-29 11:22:08 UTC (rev 5520)
+++ software_suite_v3/software/plugin/plugin-skype/trunk/executables/plugin-skype.py 2009-09-30 12:22:19 UTC (rev 5521)
@@ -65,6 +65,7 @@
"""
# Call the super class
SimplePlugin.__init__(self)
+
# Initialize some values ...
self.__currentCall = None
self.__currentContactIndex = -1
@@ -95,6 +96,7 @@
"""Plugin entry point.
This method should be used to dispatch commands.
"""
+ self.__skype = Skype4Py.Skype()
if self.getCommand() == "run":
self.run()
else:
@@ -113,6 +115,7 @@
return
# Connect to skype api.
+
self.__connectSkypeAPI()
except SkypeAPIError:
pass
@@ -215,13 +218,18 @@
if self.count <= 1:
self.__getContacts()
else:
- self.__getContacts(say=False)
+ self.__contact(User)
self.count = self.count + 1
def __onSkypeAPIStatusReceived(self, value):
"""Received api connection status.
"""
self.__apiAttachState = value
+
+ if ( value in [Skype4Py.apiAttachAvailable, ] ):
+ self.ThrowTrace('reconnecting skype api')
+ self.__connectSkypeAPI()
+
if ( value in [Skype4Py.apiAttachSuccess, ]) and (not (self.attemptTimeout == 6)):
# Set tux as audio card.
self.__selectTuxAsAudioCard()
@@ -240,10 +248,11 @@
#Start Pooling skype.
thread = threading.Thread(target = self.__poolSkypeApplication)
thread.start()
+
- elif self.attemptTimeout == 6:
- self.stop()
- return
+ #elif self.attemptTimeout == 6:
+ # self.stop()
+ # return
def __selectTuxAsAudioCard(self):
@@ -281,7 +290,7 @@
"""Get connected to the Skype client.
"""
# Create and attach skype api
- self.__skype = Skype4Py.Skype()
+
self.__skype.OnOnlineStatus = self.__onOnlineStatus
self.__skype.OnAttachmentStatus = self.__onSkypeAPIStatusReceived
self.__skype.OnCallStatus = self.__onSkypeCall
@@ -405,69 +414,10 @@
if self.__getSkypeAppConnected():
self.normalStart = True
return
- self.throwMessage("Please wait while I launch the skeyepe application")
- if os.name == "nt":
- thread = threading.Thread(target = self.__startSkypeAppWindows)
- thread.start()
- else:
- thread = threading.Thread(target = self.__startSkypeAppLinux)
- thread.start()
+ self.throwMessage("Please wait while I launch the skeyepe application")
+ self.__skype.Client.Start(Minimized=False, Nosplash=True)
+
- def __startSkypeAppWindows(self):
- """Start skype on windows.
- """
- if "ProgramFiles" in os.environ:
- try:
- skypePath = os.environ["ProgramFiles"] + "\\Skype\\Phone\\Skype.exe"
- if os.path.isfile(skypePath):
- cmd = [
- skypePath,
- '"workforplugins"',
- ]
- self.__skypeProcess = subprocess.Popen(
- cmd,
- stdin = subprocess.PIPE,
- stdout = subprocess.PIPE)
-
- else:
- self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.")
- self.__activeMain = False
- self.stop()
- except WindowsError:
- self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.")
- self.__activeMain = False
- self.stop()
-
- 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
-
- result = os.environ
-
- result = result['PATH'].split(':')
-
- for path in result:
- cmd = 'ls ' + path + ' | grep skype'
- res = commands.getoutput(cmd)
- if res.find('skype') >= 0:
- found = True
- break
-
- if found:
- #start skype
- self.__skypeProcess = subprocess.Popen("skype", stdin = subprocess.PIPE,
- stdout = subprocess.PIPE)
-
- self.__activeMain = True
- else:
- self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.")
- self.__activeMain = False
- self.stop()
-
# ==========================================================================
# Tux Droid body
# ==========================================================================
@@ -498,44 +448,105 @@
# ==========================================================================
# Contacs list
# ==========================================================================
-
- def __getContacts(self, say=True):
- """Retrieve the contact list from skype.
- """
- self.__mutexContacts.acquire()
+
+ def __contact(self, user):
+ '''
+ Add a contacts from the contacts list.
+ '''
- self.throwTrace( self.__skype.AttachmentStatus)
- while (not ( self.__skype.AttachmentStatus in [Skype4Py.apiAttachSuccess, ])):
- time.sleep(0.2)
-
- self.__contactsList = []
- self.__contactsDict = {}
-
- for user in self.__skype.Friends:
+ userFNEnc = user.FullName.encode("UTF-8").replace(" ", "_")
+ self.throwTrace(userFNEnc)
+ userDNEnc = user.DisplayName.encode("UTF-8").replace(" ", "_")
+ userHEnc = user.Handle.encode("UTF-8").replace(" ", "_")
+
+ #Add contact.
+ if user.OnlineStatus not in [Skype4Py.olsUnknown, Skype4Py.olsOffline, Skype4Py.olsInvisible]:
- if user.OnlineStatus not in [Skype4Py.olsUnknown,
- Skype4Py.olsOffline, Skype4Py.olsInvisible]:
- userFNEnc = user.FullName.encode("UTF-8").replace(" ", "_")
- userDNEnc = user.DisplayName.encode("UTF-8").replace(" ", "_")
+ if not ( ( userHEnc, userDNEnc, userHEnc ) in self.__contactsList ):
- userHEnc = user.Handle.encode("UTF-8").replace(" ", "_")
-
if len(userFNEnc) > 0:
self.__contactsDict[userFNEnc] = userHEnc
self.__contactsList.append(userFNEnc)
+
elif len(userDNEnc) > 0:
self.__contactsDict[userDNEnc] = userHEnc
self.__contactsList.append(userDNEnc)
else:
self.__contactsDict[userHEnc] = userHEnc
self.__contactsList.append(userHEnc)
-
+ #Remove contact.
+ else:
+
+ if userFNEnc in self.__contactsList:
+ self.__contactsList.remove(userFNEnc)
+ del self.__contactsDict[userFNEnc]
+
+ elif userDNEnc in 0:
+ self.__contactsList.remove(userDNEnc)
+ del self.__contactsDict[userDNEnc]
+
+ else:
+ self.__contactsList.remove(userHEnc)
+ del self.__contactsDict[userHEnc]
+
+
+
+
+ def __queryContacts(self):
+ '''
+ Query for contacts.
+ '''
+ try:
+ while (not ( self.__skype.AttachmentStatus in [Skype4Py.apiAttachSuccess, ])):
+ time.sleep(0.2)
+
+ self.__contactsList = []
+ self.__contactsDict = {}
+
+ for user in self.__skype.Friends:
+
+ if user.OnlineStatus not in [Skype4Py.olsUnknown,
+ Skype4Py.olsOffline, Skype4Py.olsInvisible]:
+ userFNEnc = user.FullName.encode("UTF-8").replace(" ", "_")
+ userDNEnc = user.DisplayName.encode("UTF-8").replace(" ", "_")
+
+ userHEnc = user.Handle.encode("UTF-8").replace(" ", "_")
+
+ if len(userFNEnc) > 0:
+ self.__contactsDict[userFNEnc] = userHEnc
+ self.__contactsList.append(userFNEnc)
+ elif len(userDNEnc) > 0:
+ self.__contactsDict[userDNEnc] = userHEnc
+ self.__contactsList.append(userDNEnc)
+ else:
+ self.__contactsDict[userHEnc] = userHEnc
+ self.__contactsList.append(userHEnc)
+ return True
+ except:
+ return False
+
+ def __getContacts(self, say=True):
+ """Retrieve the contact list from skype.
+ """
+ try:
+ self.__mutexContacts.acquire()
+ if not self.__queryContacts():
+ time.sleep(3.0)
+ self.__queryContacts()
+
+ except:
+ time.sleep(2.0)
+ say = True
+ self.__queryContacts()
+
self.__contactsDict["Quit gadget"] = "Quit gadget"
self.__contactsList.insert(0, "Quit gadget")
self.__currentContactIndex = 0
self.__mutexContacts.release()
+
self.__tuxBodyResetLeds()
self.nextContact(tts=say)
+
def __selectContact(self, incIdx, say=True):
"""
|