diff --git a/birthday_reminder/birthday_reminder_large.png b/birthday_reminder/birthday_reminder_large.png new file mode 100644 index 0000000000000000000000000000000000000000..d150022ee35d2e383e8fd38f02546d64b984d419 Binary files /dev/null and b/birthday_reminder/birthday_reminder_large.png differ diff --git a/birthday_reminder/manifest.ini b/birthday_reminder/manifest.ini index 9fa626d47d4aec56b72e78ba096bc391f3465a10..22fd658cc36df59d40f69dde487ca3856dcaac51 100644 --- a/birthday_reminder/manifest.ini +++ b/birthday_reminder/manifest.ini @@ -1,8 +1,7 @@ [info] name: Birthday reminder short_name: birthday_reminder -version: 0.0.2 -description: Birthday reminder plugin +version: 0.0.3 +description: Birthday reminder plugin. Reminder before 5,3,1 and birthday days. authors: Evgeniy Popov <evgeniypopov@gmail.com> -homepage: https://bitbucket.org/axce1/bday -min_gajim_version: 0.15.10 +homepage: http://trac-plugins.gajim.org/wiki/BirthdayReminderPlugin diff --git a/birthday_reminder/plugin.py b/birthday_reminder/plugin.py index 60fb5c6fa6899bcef1123cfed87d7f95d18ef889..0333ce5f3c2db99a813dcc8d3b970465be7bc7a4 100644 --- a/birthday_reminder/plugin.py +++ b/birthday_reminder/plugin.py @@ -9,6 +9,8 @@ from plugins.helpers import log_calls from notify import popup from common import configpaths +from common import gajim +from common import ged class BirthDayPlugin(GajimPlugin): @@ -18,12 +20,31 @@ class BirthDayPlugin(GajimPlugin): self.config_dialog = None self.description = ('Birthday reminder plugin') + self.events_handlers = { + 'roster-received': (ged.GUI2, self.roster_received)} configpath = configpaths.ConfigPaths() cache_path = configpath.cache_root self.vcard_path = os.path.join(cache_path, 'vcards') + os.sep self.timeout_id = 0 + self.showed_accounts = [] - def check_birthdays(self): + def check_birthdays(self, account=None): + def show_popup(account, jid): + contact_instances = gajim.contacts.get_contacts(account, jid) + contact = gajim.contacts.get_highest_prio_contact_from_contacts( + contact_instances) + if contact: + nick = gobject.markup_escape_text(contact.get_shown_name()) + try: + image = os.path.dirname(__file__) + os.sep + \ + 'birthday_reminder_large.png' + except: + image = None + + popup('Send message', contact.jid, account, msg_type='', \ + path_to_image=image, title=title, text=text + ' ' + nick) + + accounts = gajim.contacts.get_accounts() vcards = [] date_dict = {} for jid in glob.glob(self.vcard_path + '*@*'): @@ -39,8 +60,8 @@ class BirthDayPlugin(GajimPlugin): name = xml.getElementsByTagName('BDAY') for node in name: try: - data = node.childNodes[0].nodeValue - date_dict[xmldoc[len(self.vcard_path):]] = data + data = node.childNodes[0].nodeValue + date_dict[xmldoc[len(self.vcard_path):][:-1]] = data except: pass @@ -64,15 +85,20 @@ class BirthDayPlugin(GajimPlugin): if time_to_bday.days > 5: continue if time_to_bday.days == 5: - text = "5 days before BDay %s" % key + text = "5 days before BDay" elif time_to_bday.days == 3: - text = "3 days before BDay %s" % key + text = "3 days before BDay" elif time_to_bday.days == 1: - text = "Tommorrow BDay %s" % key + text = "Tomorrow BDay" elif time_to_bday.days == 0: - text = "Today BDay %s" % key - if text: - popup('', key, key, title=title, text=text) + text = "Today BDay" + if not text: + continue + if account: + show_popup(account,key) + else: + for acct in accounts: + show_popup(account, key) return True @log_calls('BirthDayPlugin') @@ -85,3 +111,11 @@ class BirthDayPlugin(GajimPlugin): def deactivate(self): if self.timeout_id > 0: GObject.source_remove(self.timeout_id) + + + @log_calls('BirthDayPlugin') + def roster_received(self, obj): + if obj.conn.name not in self.showed_accounts: + self.check_birthdays(obj.conn.name) + self.showed_accounts.append(obj.conn.name) +