Permalink
Browse files

Added possibility to wrap Skype application

  • Loading branch information...
1 parent 93217e1 commit 74f586c642906297bd3f1282c7eeadbd4e9dd5fe @ashkop ashkop committed May 29, 2011
Showing with 44 additions and 7 deletions.
  1. +17 −0 README
  2. +27 −7 skype-notifier.py
View
@@ -0,0 +1,17 @@
+skype-notifier - script that integrates Skype in Ubuntu Messaging menu
+
+Requires: python, python-skype, python-notify, python-gtk
+
+It could be used in two ways:
+ - just launch script from terminal. It will launch Skype if it is not running
+ yet, and will display Skype and new messages in Ubuntu Messaging Menu. When
+ you will exit Skype, items in Messaging Menu will disappear
+
+ - Use script as a wrapper for Skype application.
+ Edit /usr/share/applications/skype.desktop file, point Exec parameter to
+ skype-notifier script (don't forget to do chmod uo+x).
+
+ If you'd like to be able to launch Skype from Messaging Menu add
+ /usr/share/indicators/messaging/applications/skype file with one line in it:
+
+ /usr/share/applications/skype.desktop
View
@@ -27,6 +27,7 @@ def __init__(self, skype):
self.server = indicate.indicate_server_ref_default()
self.server.set_type("message.im")
+ # TODO: path to desktop file shouldn't be hardcoded
self.server.set_desktop_file("/usr/share/applications/skype.desktop")
self.server.connect("server-display", skype.focus)
self.server.show()
@@ -90,20 +91,26 @@ class SkypeHandler:
def __init__(self):
self.client = self.get_client()
- self.client.Attach()
+
+ # This block attends to solve problem of attaching to Skype client
+ # First Attach call queries for attachment status but when Skype client
+ # is not logged in, it refuses attachment and API raises exception.
+ # When client logs in, it does notsend any event, so I had to add gtk
+ # timeout function
+ try:
+ self.client.Attach()
+ except Skype4Py.skype.SkypeAPIError:
+ gtk.timeout_add(5000, self.attach_client)
self.indicators = Indicators(self)
- # Handle messages that were received before script launch
- self.handle_unread_messages()
-
def get_client(self):
""" Reveice Skype4Py.Skype instance
** Maybe launch Skype if not launched?
"""
skype = Skype4Py.Skype(Events=self, Api=SkypeAPI({}))
if not skype.Client.IsRunning:
- raise Exception("Skype is not running")
+ skype.Client.Start()
return skype
@@ -136,17 +143,30 @@ def MessageStatus(self, msg, status):
else:
label = msg.FromDisplayName
handle = msg.FromHandle
- if status == 'RECEIVED':
+ if status == Skype4Py.skype.cmsReceived:
self.indicators.add_indicator(label, handle, msg.Timestamp, msg.Id)
self.indicators.notify(label, msg.Body)
- elif status == "READ":
+ elif status == Skype4Py.skype.cmsRead:
self.indicators.remove_indicator(handle, msg.Id)
def handle_unread_messages(self):
for msg in self.client.MissedMessages:
self.MessageStatus(msg, msg.Status)
+ # gtk timeout callback
+ def attach_client(self):
+ """ tries to attach API to client """
+ self.client.Attach()
+ return self.client.AttachmentStatus != Skype4Py.skype.apiAttachSuccess
+
+ def AttachmentStatus(self, status):
+ #Quit when Skype quits
+ if status == Skype4Py.skype.apiAttachNotAvailable:
+ gtk.main_quit()
+ #process unread messages after attachment
+ elif status == Skype4Py.skype.apiAttachSuccess:
+ self.handle_unread_messages()
if __name__ == '__main__':
SkypeHandler()

0 comments on commit 74f586c

Please sign in to comment.