예제 #1
0
 def __init__(self, app, name):
     PluginBase.__init__(self, app, name)
     self.available_settings = {
         "show":
         ("Which items show - list of 'available','unavailable','chat',"
          "'online','away','xa' or 'all'", list, self.set_show),
         "buffer_preference":
         ("Preference of roster buffers when switching to the next active buffer. If 0 then the buffer is not even shown in active buffer list.",
          int),
         "cache_file": ("Location of roster cache files."
                        " /unset it not to keep local copy of the roster.",
                        (unicode, None))
     }
     self.settings = {
         "show": ["all"],
         "buffer_preference": 2,
         "cache_file": "%($HOME)s/.cjc/cache/%(jid)s.roster",
     }
     app.add_info_handler("rostername", self.info_rostername)
     app.add_info_handler("rostergroups", self.info_rostergroups)
     app.add_event_handler("roster updated", self.ev_roster_updated)
     app.add_event_handler("presence changed", self.ev_presence_changed)
     app.add_event_handler("layout changed", self.ev_layout_changed)
     app.add_event_handler("stream closed", self.ev_stream_closed)
     app.add_event_handler("config loaded", self.ev_config_loaded)
     cjc_globals.theme_manager.set_default_attrs(theme_attrs)
     cjc_globals.theme_manager.set_default_formats(theme_formats)
     self.buffer = ListBuffer("Roster")
     self.buffer.preference = self.settings["buffer_preference"]
     self.extra_items = []
     ui.activate_cmdtable("roster", self)
예제 #2
0
파일: roster.py 프로젝트: AdamPrzybyla/cjc
 def __init__(self,app,name):
     PluginBase.__init__(self,app,name)
     self.available_settings={
         "show": ("Which items show - list of 'available','unavailable','chat',"
                 "'online','away','xa' or 'all'",list,self.set_show),
         "buffer_preference": ("Preference of roster buffers when switching to the next active buffer. If 0 then the buffer is not even shown in active buffer list.",int),
         "cache_file": ("Location of roster cache files."
             " /unset it not to keep local copy of the roster.",
                                     (unicode, None))
         }
     self.settings={
             "show": ["all"],
             "buffer_preference": 2,
             "cache_file": "%($HOME)s/.cjc/cache/%(jid)s.roster",
             }
     app.add_info_handler("rostername",self.info_rostername)
     app.add_info_handler("rostergroups",self.info_rostergroups)
     app.add_event_handler("roster updated",self.ev_roster_updated)
     app.add_event_handler("presence changed",self.ev_presence_changed)
     app.add_event_handler("layout changed",self.ev_layout_changed)
     app.add_event_handler("stream closed", self.ev_stream_closed)
     app.add_event_handler("config loaded", self.ev_config_loaded)
     cjc_globals.theme_manager.set_default_attrs(theme_attrs)
     cjc_globals.theme_manager.set_default_formats(theme_formats)
     self.buffer=ListBuffer("Roster")
     self.buffer.preference=self.settings["buffer_preference"]
     self.extra_items=[]
     ui.activate_cmdtable("roster",self)
예제 #3
0
class Plugin(PluginBase, NamedService):
    service_name = "roster"

    def __init__(self, app, name):
        PluginBase.__init__(self, app, name)
        self.available_settings = {
            "show":
            ("Which items show - list of 'available','unavailable','chat',"
             "'online','away','xa' or 'all'", list, self.set_show),
            "buffer_preference":
            ("Preference of roster buffers when switching to the next active buffer. If 0 then the buffer is not even shown in active buffer list.",
             int),
            "cache_file": ("Location of roster cache files."
                           " /unset it not to keep local copy of the roster.",
                           (unicode, None))
        }
        self.settings = {
            "show": ["all"],
            "buffer_preference": 2,
            "cache_file": "%($HOME)s/.cjc/cache/%(jid)s.roster",
        }
        app.add_info_handler("rostername", self.info_rostername)
        app.add_info_handler("rostergroups", self.info_rostergroups)
        app.add_event_handler("roster updated", self.ev_roster_updated)
        app.add_event_handler("presence changed", self.ev_presence_changed)
        app.add_event_handler("layout changed", self.ev_layout_changed)
        app.add_event_handler("stream closed", self.ev_stream_closed)
        app.add_event_handler("config loaded", self.ev_config_loaded)
        cjc_globals.theme_manager.set_default_attrs(theme_attrs)
        cjc_globals.theme_manager.set_default_formats(theme_formats)
        self.buffer = ListBuffer("Roster")
        self.buffer.preference = self.settings["buffer_preference"]
        self.extra_items = []
        ui.activate_cmdtable("roster", self)

    def info_rostername(self, k, v):
        if not v:
            return None
        return "Roster name", v

    def info_rostergroups(self, k, v):
        if not v:
            return None
        return "Roster groups", string.join(v, ",")

    def set_show(self, oldval, newval):
        self.write_all()

    def ev_config_loaded(self, event, arg):
        if not self.cjc.roster:
            self.load_cache()

    def ev_roster_updated(self, event, arg):
        if not arg:
            for item in self.cjc.roster.get_items():
                for group, it in self.extra_items:
                    if not isinstance(it, pyxmpp.JID) or group != VG_UNKNOWN:
                        continue
                    jid = item.jid
                    if group == VG_UNKNOWN and it == jid or it.bare() == jid:
                        self.extra_items.remove((VG_UNKNOWN, it))
                        if self.buffer.has_key((VG_UNKNOWN, it)):
                            self.buffer.remove_item((VG_UNKNOWN, it))
            self.write_all()
            return
        self.update_item(arg)

    def ev_presence_changed(self, event, arg):
        if arg:
            self.update_item(arg)

    def ev_layout_changed(self, event, arg):
        if self.cjc.roster_window:
            self.cjc.roster_window.set_buffer(self.buffer)

    def ev_stream_closed(self, event, arg):
        self.save_cache()

    @property
    def cache_filename(self):
        filename = self.settings.get("cache_file")
        if not filename:
            return
        if self.cjc.jid:
            my_jid = self.cjc.jid
        else:
            my_jid = self.cjc.settings.get("jid")
        if not my_jid:
            return
        filename = cjc_globals.theme_manager.substitute(
            filename, {
                "jid": unicode(my_jid.bare())
            }).encode("utf-8")
        return os.path.expanduser(filename)

    def save_cache(self):
        if not self.cjc.roster:
            return
        filename = self.cache_filename
        if not filename:
            return
        parent = os.path.dirname(filename)
        if not os.path.exists(parent):
            try:
                os.makedirs(parent.encode("utf-8"))
            except (OSError, IOError), err:
                self.error("Cannot write roster cache file."
                           "Cannot make directory {0}: {1}".format(
                               parent, err))
                return
        try:
            with open(filename, "w") as roster_file:
                print >> roster_file, str(self.cjc.roster)
        except IOError, err:
            self.error("Cannot write roster cache file {0}: {1}".format(
                filename, err))
예제 #4
0
파일: roster.py 프로젝트: AdamPrzybyla/cjc
class Plugin(PluginBase, NamedService):
    service_name = "roster"
    def __init__(self,app,name):
        PluginBase.__init__(self,app,name)
        self.available_settings={
            "show": ("Which items show - list of 'available','unavailable','chat',"
                    "'online','away','xa' or 'all'",list,self.set_show),
            "buffer_preference": ("Preference of roster buffers when switching to the next active buffer. If 0 then the buffer is not even shown in active buffer list.",int),
            "cache_file": ("Location of roster cache files."
                " /unset it not to keep local copy of the roster.",
                                        (unicode, None))
            }
        self.settings={
                "show": ["all"],
                "buffer_preference": 2,
                "cache_file": "%($HOME)s/.cjc/cache/%(jid)s.roster",
                }
        app.add_info_handler("rostername",self.info_rostername)
        app.add_info_handler("rostergroups",self.info_rostergroups)
        app.add_event_handler("roster updated",self.ev_roster_updated)
        app.add_event_handler("presence changed",self.ev_presence_changed)
        app.add_event_handler("layout changed",self.ev_layout_changed)
        app.add_event_handler("stream closed", self.ev_stream_closed)
        app.add_event_handler("config loaded", self.ev_config_loaded)
        cjc_globals.theme_manager.set_default_attrs(theme_attrs)
        cjc_globals.theme_manager.set_default_formats(theme_formats)
        self.buffer=ListBuffer("Roster")
        self.buffer.preference=self.settings["buffer_preference"]
        self.extra_items=[]
        ui.activate_cmdtable("roster",self)

    def info_rostername(self,k,v):
        if not v:
            return None
        return "Roster name",v

    def info_rostergroups(self,k,v):
        if not v:
            return None
        return "Roster groups",string.join(v,",")

    def set_show(self,oldval,newval):
        self.write_all()
    
    def ev_config_loaded(self, event, arg):
        if not self.cjc.roster:
            self.load_cache()

    def ev_roster_updated(self,event,arg):
        if not arg:
            for item in self.cjc.roster.get_items():
                for group,it in self.extra_items:
                    if not isinstance(it,pyxmpp.JID) or group!=VG_UNKNOWN:
                        continue
                    jid=item.jid
                    if group==VG_UNKNOWN and it==jid or it.bare()==jid:
                        self.extra_items.remove((VG_UNKNOWN,it))
                        if self.buffer.has_key((VG_UNKNOWN,it)):
                            self.buffer.remove_item((VG_UNKNOWN,it))
            self.write_all()
            return
        self.update_item(arg)

    def ev_presence_changed(self,event,arg):
        if arg:
            self.update_item(arg)

    def ev_layout_changed(self,event,arg):
        if self.cjc.roster_window:
            self.cjc.roster_window.set_buffer(self.buffer)

    def ev_stream_closed(self, event, arg):
        self.save_cache()

    @property
    def cache_filename(self):
        filename = self.settings.get("cache_file")
        if not filename:
            return
        if self.cjc.jid:
            my_jid = self.cjc.jid
        else:
            my_jid = self.cjc.settings.get("jid")
        if not my_jid:
            return
        filename = cjc_globals.theme_manager.substitute(filename,
                            {"jid": unicode(my_jid.bare())}).encode("utf-8")
        return os.path.expanduser(filename)

    def save_cache(self):
        if not self.cjc.roster:
            return
        filename = self.cache_filename
        if not filename:
            return
        parent = os.path.dirname(filename)
        if not os.path.exists(parent):
            try:
                os.makedirs(parent.encode("utf-8"))
            except (OSError, IOError), err:
                self.error("Cannot write roster cache file."
                                    "Cannot make directory {0}: {1}"
                                                    .format(parent, err))
                return
        try:
            with open(filename, "w") as roster_file:
                print >>roster_file, str(self.cjc.roster)
        except IOError, err:
            self.error("Cannot write roster cache file {0}: {1}"
                                                .format(filename, err))