def _replace(self, template, msg): '''replace the variables on template for the values on msg ''' msg.alias = Plus.msnplus_strip(msg.alias) msg.display_name = Plus.msnplus_strip(msg.display_name) if (len(msg.alias) > DISPLAY_NAME_LIMIT): msg.alias = msg.alias.decode('utf-8')[0:DISPLAY_NAME_LIMIT] + "..." if (len(msg.display_name) > DISPLAY_NAME_LIMIT): msg.display_name = msg.display_name.decode( 'utf-8')[0:DISPLAY_NAME_LIMIT] + "..." image_path = escape(MarkupParser.path_to_url(msg.image_path)) status_path = escape(MarkupParser.path_to_url(msg.status_path)) if msg.style is not None: msg.message = style_message(msg.message, msg.style) if msg.alias: template = template.replace('%sender%', escape(msg.alias)) else: template = template.replace('%sender%', escape(msg.display_name)) template = template.replace('%senderScreenName%', escape(msg.sender)) template = template.replace('%senderDisplayName%', escape(msg.display_name)) template = template.replace('%userIconPath%', image_path) template = template.replace('%senderStatusIcon%', status_path) template = template.replace('%messageDirection%', escape(msg.direction)) template = template.replace('%message%', escape_no_xml(msg.message)) if msg.timestamp is None: template = template.replace('%time%', escape(time.strftime("%H:%M"))) else: def utc_to_local(t): secs = calendar.timegm(t) return time.localtime(secs) l_time = utc_to_local(msg.timestamp.timetuple()) #time.struct_time d_time = datetime.datetime.fromtimestamp(time.mktime(l_time)) template = template.replace('%time%', escape(d_time.strftime('%x %X'))) template = re.sub("%time{(.*?)}%", replace_time, template) template = template.replace('%shortTime%', escape(time.strftime("%H:%M"))) template = template.replace('%service%', escape(msg.service)) template = template.replace('%messageClasses%', escape(msg.classes)) template = template.replace('%status%', escape(msg.status)) return template.replace('\n', '')
def replace(self, template, msg, style=None, cedict={}, cedir=None): '''replace the variables on template for the values on msg ''' msg.alias = Plus.msnplus_strip(msg.alias) msg.display_name = Plus.msnplus_strip(msg.display_name) if(len(msg.alias) > DISPLAY_NAME_LIMIT): msg.alias = msg.alias.decode('utf-8')[0:DISPLAY_NAME_LIMIT] + "..." if(len(msg.display_name) > DISPLAY_NAME_LIMIT): msg.display_name = msg.display_name.decode('utf-8')[0:DISPLAY_NAME_LIMIT] + "..." msgtext = MarkupParser.replace_emotes(escape(msg.message), cedict, cedir, msg.sender) msgtext = MarkupParser.urlify(msgtext) image_path = escape(MarkupParser.path_to_url(msg.image_path)) status_path = escape(MarkupParser.path_to_url(msg.status_path)) if style is not None: msgtext = style_message(msgtext, style) if msg.alias: template = template.replace('%sender%', escape(msg.alias)) else: template = template.replace('%sender%', escape(msg.display_name)) template = template.replace('%senderScreenName%', escape(msg.sender)) template = template.replace('%senderDisplayName%', escape(msg.display_name)) template = template.replace('%userIconPath%', image_path) template = template.replace('%senderStatusIcon%', status_path) template = template.replace('%messageDirection%', escape(msg.direction)) template = template.replace('%message%', msgtext) if msg.timestamp is None: template = template.replace('%time%', escape(time.strftime("%H:%M"))) else: def utc_to_local(t): secs = calendar.timegm(t) return time.localtime(secs) l_time = utc_to_local(msg.timestamp.timetuple()) #time.struct_time d_time = datetime.datetime.fromtimestamp(time.mktime(l_time)) template = template.replace('%time%', escape(d_time.strftime('%x %X'))) template = re.sub("%time{(.*?)}%", replace_time, template) template = template.replace('%shortTime%', escape(time.strftime("%H:%M"))) template = template.replace('%service%', escape(msg.service)) template = template.replace('%messageClasses%', escape(msg.classes)) template = template.replace('%status%', escape(msg.status)) return template.replace('\n', '')
def update_group_information(self): """ update the information for a conversation with multiple users """ if self.session.account.account in self.members: # this can happen sometimes (e.g. when you're invisible. see #1297) self.members.remove(self.session.account.account) # TODO add plus support for nick to the tab label! # We now strip Plus tags when we cut the nickname members_nick = [] i = 0 for account in self.members: i += 1 contact = self.session.contacts.get(account) if contact is None or contact.nick is None: nick = account elif len(contact.nick) > 20 and i != len(self.members): nick = Plus.msnplus_strip(contact.nick.decode("utf-8"))[:20] + "..." else: nick = contact.nick members_nick.append(nick) self.header.information = (_("%d members") % (len(self.members) + 1,), ", ".join(members_nick)) self.info.update_group(self.members) self.update_tab()
def update_group_information(self): """ update the information for a conversation with multiple users """ if self.session.account.account in self.members: # this can happen sometimes (e.g. when you're invisible. see #1297) self.members.remove(self.session.account.account) #TODO add plus support for nick to the tab label! # We now strip Plus tags when we cut the nickname members_nick = [] i = 0 for account in self.members: i += 1 contact = self.session.contacts.get(account) if contact is None or contact.nick is None: nick = account elif len(contact.nick) > 20 and i != len(self.members): nick = Plus.msnplus_strip( contact.nick.decode('utf-8'))[:20] + '...' else: nick = contact.nick members_nick.append(nick) self.header.information = \ (_('%d members') % (len(self.members) + 1, ), ", ".join(members_nick)) self.info.update_group(self.members) self.update_tab()
def replace(self, template, msg, style=None, cedict={}, cedir=None): """replace the variables on template for the values on msg """ msg.alias = Plus.msnplus_strip(msg.alias) msg.display_name = Plus.msnplus_strip(msg.display_name) msgtext = MarkupParser.replace_emotes(escape(msg.message), cedict, cedir, msg.sender) msgtext = MarkupParser.urlify(msgtext) image_path = escape(MarkupParser.path_to_url(msg.image_path)) status_path = escape(MarkupParser.path_to_url(msg.status_path)) if style is not None: msgtext = style_message(msgtext, style) if msg.alias: template = template.replace("%sender%", escape(msg.alias)) else: template = template.replace("%sender%", escape(msg.display_name)) template = template.replace("%senderScreenName%", escape(msg.sender)) template = template.replace("%senderDisplayName%", escape(msg.display_name)) template = template.replace("%userIconPath%", image_path) template = template.replace("%senderStatusIcon%", status_path) template = template.replace("%messageDirection%", escape(msg.direction)) template = template.replace("%message%", msgtext) if msg.timestamp is None: template = template.replace("%time%", escape(time.strftime(self.timefmt))) else: def utc_to_local(t): secs = calendar.timegm(t) return time.localtime(secs) l_time = utc_to_local(msg.timestamp.timetuple()) # time.struct_time d_time = datetime.datetime.fromtimestamp(time.mktime(l_time)) template = template.replace("%time%", escape(d_time.strftime("%x %X"))) template = re.sub("%time{(.*?)}%", replace_time, template) template = template.replace("%shortTime%", escape(time.strftime("%H:%M"))) template = template.replace("%service%", escape(msg.service)) template = template.replace("%messageClasses%", escape(msg.classes)) template = template.replace("%status%", escape(msg.status)) return template.replace("\n", "")
def get_body(self, source, target, target_display, source_img, target_img): """return the template to put as html content """ # first try load custom Template.html from theme path = urljoin(self.resources_path, "Template.html") if not os.path.exists(path): path = urljoin("gui", "base", "template.html") template = read_file(path) resources_url = MarkupParser.path_to_url(self.resources_path) css_path = urljoin(resources_url, "main.css") template = template.replace("%@", resources_url + "/", 1) template = template.replace("%@", css_path, 1) if self.variant is not None: variant_css_path = urljoin(resources_url, "Variants", self.variant + ".css") variant_tag = ( '<style id="mainStyle" type="text/css"' + 'media="screen,print"> @import url( "' + variant_css_path + '" ); </style>' ) else: variant_tag = "" template = template.replace("%@", variant_tag, 1) target = Plus.msnplus_strip(target) target_display = Plus.msnplus_strip(target_display) header = read_file(self.resources_path, "Header.html") or "" if header: header = self.replace_header_or_footer(header, source, target, target_display, source_img, target_img) template = template.replace("%@", header, 1) footer = read_file(self.resources_path, "Footer.html") or "" if footer: footer = self.replace_header_or_footer(footer, source, target, target_display, source_img, target_img) template = template.replace("%@", footer, 1) return template
def get_body(self, source, target, target_display, source_img, target_img): '''return the template to put as html content ''' template = self.template resources_url = MarkupParser.path_to_url(self.resources_path) css_path = urljoin(resources_url, "main.css") template = template.replace("%@", resources_url + "/", 1) template = template.replace("%@", css_path, 1) if self.variant is not None: variant_css_path = urljoin(resources_url, "Variants", self.variant + ".css") variant_tag = '<style id="mainStyle" type="text/css"' + \ 'media="screen,print"> @import url( "' + variant_css_path + '" ); </style>' else: variant_tag = "" template = template.replace("%@", variant_tag, 1) target = Plus.msnplus_strip(target) target_display = Plus.msnplus_strip(target_display) header = self.header if header: header = self._replace_header_or_footer(header, source, target, target_display, source_img, target_img) template = template.replace("%@", header, 1) footer = self.footer if footer: footer = self._replace_header_or_footer(footer, source, target, target_display, source_img, target_img) template = template.replace("%@", footer, 1) return template