comparison sat.tac @ 101:783e9d6980ec

Couchsurfing plugin: first draft SàT core: adding additionnal menu method bridge: new methods getMenus, getMenuHelp and callMenu wix: new menu are added on startup CS plugin: login on CS
author Goffi <goffi@goffi.org>
date Sat, 19 Jun 2010 17:15:30 +0800
parents 4020931569b8
children 94011f553cd0
comparison
equal deleted inserted replaced
100:50f1591c8fc6 101:783e9d6980ec
325 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id) 325 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id)
326 self.__general_cb_map = {} #callback called for general reasons (key = name) 326 self.__general_cb_map = {} #callback called for general reasons (key = name)
327 self.__private_data = {} #used for internal callbacks (key = id) 327 self.__private_data = {} #used for internal callbacks (key = id)
328 self.profiles = {} 328 self.profiles = {}
329 self.plugins = {} 329 self.plugins = {}
330 self.menus = {} #used to know which new menus are wanted by plugins
330 331
331 self.memory=Memory(self) 332 self.memory=Memory(self)
332 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future 333 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
333 334
334 self.bridge=DBusBridge() 335 self.bridge=DBusBridge()
355 self.bridge.register("delContact", self.delContact) 356 self.bridge.register("delContact", self.delContact)
356 self.bridge.register("isConnected", self.isConnected) 357 self.bridge.register("isConnected", self.isConnected)
357 self.bridge.register("launchAction", self.launchAction) 358 self.bridge.register("launchAction", self.launchAction)
358 self.bridge.register("confirmationAnswer", self.confirmationAnswer) 359 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
359 self.bridge.register("getProgress", self.getProgress) 360 self.bridge.register("getProgress", self.getProgress)
361 self.bridge.register("getMenus", self.getMenus)
362 self.bridge.register("getMenuHelp", self.getMenuHelp)
363 self.bridge.register("callMenu", self.callMenu)
360 364
361 self._import_plugins() 365 self._import_plugins()
362 366
363 367
364 def _import_plugins(self): 368 def _import_plugins(self):
687 self.bridge.askConfirmation(type, id, data) 691 self.bridge.askConfirmation(type, id, data)
688 692
689 693
690 def confirmationAnswer(self, id, accepted, data): 694 def confirmationAnswer(self, id, accepted, data):
691 """Called by frontends to answer confirmation requests""" 695 """Called by frontends to answer confirmation requests"""
692 debug (_("Received confirmation answer for id [%(id)s]: %(success)s") % {'id': id, 'success':u("accepted") if accepted else _("refused")}) 696 debug (_("Received confirmation answer for id [%(id)s]: %(success)s") % {'id': id, 'success':_("accepted") if accepted else _("refused")})
693 if not self.__waiting_conf.has_key(id): 697 if not self.__waiting_conf.has_key(id):
694 error (_("Received an unknown confirmation")) 698 error (_("Received an unknown confirmation"))
695 else: 699 else:
696 cb = self.__waiting_conf[id] 700 cb = self.__waiting_conf[id]
697 del self.__waiting_conf[id] 701 del self.__waiting_conf[id]
738 return self.__general_cb_map[name](*args, **kwargs) 742 return self.__general_cb_map[name](*args, **kwargs)
739 except KeyError: 743 except KeyError:
740 error(_("Trying to call unknown function")) 744 error(_("Trying to call unknown function"))
741 return None 745 return None
742 746
747 #Menus management
748
749 def importMenu(self, category, name, callback, help_string = "", type = "NORMAL"):
750 """register a new menu for frontends
751 @param category: category of the menu
752 @param name: menu item entry
753 @param callback: method to be called when menuitem is selected"""
754 if self.menus.has_key((category,name)):
755 error ("Want to register a menu which already existe")
756 return
757 self.menus[(category,name,type)] = {'callback':callback, 'help_string':help_string, 'type':type}
758
759 def getMenus(self):
760 """Return all menus registered"""
761 return self.menus.keys()
762
763 def getMenuHelp(self, category, name, type="NORMAL"):
764 """return the help string of the menu"""
765 try:
766 return self.menus[(category,name,type)]['help_string']
767 except KeyError:
768 error (_("Trying to access an unknown menu"))
769 return ""
770
771 def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'):
772 """return the help string of the menu"""
773 profile = self.memory.getProfileName(profile_key)
774 if not profile_key:
775 error (_('Non-exsitant profile'))
776 return ""
777 try:
778 id = self.get_next_id()
779 self.menus[(category,name,type)]['callback'](id, profile)
780 return id
781 except KeyError:
782 error (_("Trying to access an unknown menu"))
783 return ""
784
785
786
743 application = service.Application('SàT') 787 application = service.Application('SàT')
744 service = SAT() 788 service = SAT()
745 service.setServiceParent(application) 789 service.setServiceParent(application)