Author: gwadavel
Date: 2009-09-18 16:52:16 +0200 (Fri, 18 Sep 2009)
New Revision: 5449

Modified:
   
software_suite_v3/software/plugin/plugin-pidgin/trunk/executables/plugin-pidgin.py
Log:
rewrite plugin-pidgin

Modified: 
software_suite_v3/software/plugin/plugin-pidgin/trunk/executables/plugin-pidgin.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-pidgin/trunk/executables/plugin-pidgin.py
  2009-09-18 12:33:53 UTC (rev 5448)
+++ 
software_suite_v3/software/plugin/plugin-pidgin/trunk/executables/plugin-pidgin.py
  2009-09-18 14:52:16 UTC (rev 5449)
@@ -45,9 +45,8 @@
         self.__chat = True
         self.__im = True
         self.__away = False
-        self.__cia = False
+        self.__cia = True
 
-
     def getChat(self):
         return self.__chat
 
@@ -90,17 +89,17 @@
         self.theString += data
 
 
-class Pidgin(object):
+class PidginPlugin(SimplePlugin):
+    """This class override the SimplePlugin class to make easy
+    the plugin coding.
     """
-    Manage Pidgin
-    """
 
-    def __init__(self, plug):
-        '''
-        '''
-        self.plugin = plug 
-
-        self.conf = Configuration()        
+    def __init__(self):
+        """Initialization of the class.
+        """
+        # Call the super class
+        SimplePlugin.__init__(self)
+        # Initialize some values ...
         self.bus = dbus.SessionBus()
 
         try:
@@ -110,35 +109,53 @@
             self.purple = dbus.Interface(self.obj, 
"im.pidgin.purple.PurpleInterface")
 
         except dbus.DBusException, msg:
-            self.plugin.throwNotification("start")
-            self.plugin.throwMessage("Pidgin is not launched")
-            self.plugin.throwNotification("stop")
-            print str(msg)          
+            self.throwNotification("start")
+            self.throwMessage("Pidgin is not launched")
+            self.throwNotification("stop")          
             sys.exit(1)
 
-        self.plugin.throwNotification("start")
-        self.plugin.throwMessage("Pidgin is launched")
-        self.plugin.throwNotification("stop")        
+        self.throwNotification("start")
+        self.throwMessage("Pidgin is launched")
+        self.throwNotification("stop")        
         
-        self.all_alias = self.account()
+        self.all_alias = []
 
-        if self.conf.getIm(): 
-            self.bus.add_signal_receiver(self.received_im_msg,
+    def start(self):
+        """Plugin entry point.
+        This method should be used to dispatch commands.
+        """
+        if self.getCommand() == "run":
+            self.run()   
+        else:
+            self.run()
+
+    def run(self):
+        """Plugin entry point for the "run" command.
+        """    
+        self.__startAll()
+
+    def onPluginStop(self):
+        """Callback on plugin stop.
+        """
+        self.__stopAll()
+
+    def __busConnect(self):
+        """Connect bus signal receiver
+        """
+        if self.configuration().getIm():
+            self.bus.add_signal_receiver(self.__received_im_msg,
                         dbus_interface = "im.pidgin.purple.PurpleInterface",
                         signal_name = "ReceivedImMsg")
-
-            self.bus.add_signal_receiver(self.buddy_signed_on,
+            self.bus.add_signal_receiver(self.__buddy_signed_on,
                         dbus_interface = "im.pidgin.purple.PurpleInterface",
                         signal_name = "BuddySignedOn")
-                        
 
-        if self.conf.getChat():
-            self.bus.add_signal_receiver(self.received_im_msg,
+        if self.configuration().getChat():
+            self.bus.add_signal_receiver(self.__received_im_msg,
                         dbus_interface = "im.pidgin.purple.PurpleInterface",
                         signal_name = "ReceivedChatMsg")
 
-
-    def account(self):
+    def __account(self):
         """ List of your alias """
 
         self.list_alias = []
@@ -149,8 +166,7 @@
             self.list_alias.append(self.alias)
         return self.list_alias
 
-
-    def stateAway(self):
+    def __stateAway(self):
         """ Test status away ou available """
     
         # i found this here 
http://arstechnica.com/reviews/apps/pidgin-2-0.ars/4
@@ -166,8 +182,7 @@
         else:
             return False    
 
-
-    def received_im_msg(self, account, name, message, conversation, flags):
+    def __received_im_msg(self, account, name, message, conversation, flags):
         """ This method is execute when a message is receive """
     
         self.buddy = self.purple.PurpleFindBuddy(account, name)
@@ -178,77 +193,57 @@
             self.alias = name     
         if self.alias in self.all_alias:
             return
-        if self.conf.getCia() and self.alias[:3].upper() == "CIA":
+        if self.configuration().getCia() and self.alias[:3].upper() == "CIA":
             self.text = "commit on svn"
+            self.__tux_speak(self.text)
         else:
             self.MessageP = MessageParser()
             self.message = self.MessageP.strip(message)
             self.text = "%s " %self.alias + "{0}" + " %s" %self.message
-        self.tux_speak(self.text, "said")
- 
-    def buddy_signed_on(self, buddyid):
+            self.__tux_speak(self.text, "said")
+
+    def __buddy_signed_on(self, buddyid):
         """ This method is excute when a buddy is sign on """
     
         self.alias = self.purple.PurpleBuddyGetAlias(buddyid)
         self.text = "%s " %self.alias + "{0}"
 
-        self.tux_speak(self.text, "is online")
+        self.__tux_speak(self.text, "is online")
 
+    def __buddy_signed_on(self, buddyid):
+        """ This method is excute when a buddy is sign on """
+    
+        self.alias = self.purple.PurpleBuddyGetAlias(buddyid)
+        self.text = "%s " %self.alias + "{0}"
 
-    def tux_speak(self, text, say):
+        self.__tux_speak(self.text, "is online")
+
+
+    def __tux_speak(self, text, say = None):
         """ Tux speak the text """
  
         self.__text = text.encode("utf-8")
         self.__say = say
-        if self.conf.getAway() and self.stateAway():
+        if self.configuration().getAway() and self.__stateAway():
            return        
-        self.plugin.throwNotification("start")        
-        self.plugin.throwMessage(self.__text, self.__say)        
-        self.plugin.throwNotification("stop")
+        self.throwNotification("start")        
+        self.throwMessage(self.__text, self.__say)        
+        self.throwNotification("stop")
 
-    def start(self):
+    def __startAll(self):
         """Start Loop
         """
+        self.all_alias = self.__account()
+        self.__busConnect()
         self.loop = gobject.MainLoop()
         self.loop.run()
 
-    def stop(self):
+    def __stopAll(self):
         """Stop Loop
         """
         self.loop.quit()
 
-class PidginPlugin(SimplePlugin):
-    """This class override the SimplePlugin class to make easy
-    the plugin coding.
-    """
 
-    def __init__(self):
-        """Initialization of the class.
-        """
-        # Call the super class
-        SimplePlugin.__init__(self)
-        # Initialize some values ...
-        self.spidgin = Pidgin(self)
-
-    def start(self):
-        """Plugin entry point.
-        This method should be used to dispatch commands.
-        """
-        if self.getCommand() == "run":
-            self.run()   
-        else:
-            self.run()
-
-    def run(self):
-        """Plugin entry point for the "run" command.
-        """    
-        self.spidgin.start()
-
-    def onPluginStop(self):
-        """Callback on plugin stop.
-        """
-        self.spidgin.stop()
-
 if __name__ == "__main__":
     plugin = PidginPlugin()
     plugin.boot(sys.argv[1:], Configuration())


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to