BirthdayReminderPlugin. new version
This commit is contained in:
BIN
birthday_reminder/birthday_reminder_large.png
Normal file
BIN
birthday_reminder/birthday_reminder_large.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user