summaryrefslogtreecommitdiff
path: root/papyon/msnp/mailbox.py
blob: 902247fc1830112336fb117552549ba3697a511e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
#
# papyon - a python client library for Msn
#
# Copyright (C) 2008 Alen Bou-Haidar <alencool@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


import gobject

__all__ = ['Mailbox', 'MailMessage']

class MailMessage(object):

    def __init__(self, name, address, subject, post_url, form_data):
        self._name = name
        self._subject = subject
        self._address = address
        self._post_url = post_url
        self._form_data = form_data

    @property
    def name(self):
        """The name of the person who sent the email"""
        return self._name

    @property
    def address(self):
        """Email address of the person who sent the email"""
        return self._address

    @property
    def post_url(self):
        """post url"""
        return self._post_url

    @property
    def form_data(self):
        """form url"""
        return self._form_data

class Mailbox(gobject.GObject):
    """Mailbox information of the User connecting to the service

        @undocumented: __gsignals__, __gproperties__, do_get_property"""

    __gsignals__ = {
            "new-mail-received" : (gobject.SIGNAL_RUN_FIRST,
                                  gobject.TYPE_NONE,
                                  (object,)),
            "unread-mail-count-changed" : (gobject.SIGNAL_RUN_FIRST,
                                  gobject.TYPE_NONE,
                                  (gobject.TYPE_UINT, bool)),
            }

    __gproperties__ = {
            "unread-mail-count": (gobject.TYPE_UINT,
                "Inbox Unread",
                "Number of unread mail in the users inbox",
                0, gobject.G_MAXUINT, 0,
                gobject.PARAM_READABLE),
            }

    def __init__(self, ns_client):
        gobject.GObject.__init__(self)
        self._ns_client = ns_client
        self._unread_mail_count = 0

    @property
    def unread_mail_count(self):
        """Number of unread mail in the users inbox
            @rtype: integer"""
        return self._unread_mail_count

    def request_compose_mail_url(self, contact, callback):
        self._ns_client.send_url_request(('COMPOSE', contact.account), callback)            

    def request_inbox_url(self, callback):
        self._ns_client.send_url_request(('INBOX',), callback)

    def _unread_mail_increased(self, delta):
        self._unread_mail_count += delta
        self.emit("unread-mail-count-changed", self._unread_mail_count, False)
        self.notify("unread-mail-count")

    def _unread_mail_decreased(self, delta):
        if self._unread_mail_count > 0:
            self._unread_mail_count -= delta
            self.emit("unread-mail-count-changed", self._unread_mail_count, False)
            self.notify("unread-mail-count")

    def _initial_set(self, unread_number):
        if unread_number > 0:
            self._unread_mail_count = unread_number
            self.emit("unread-mail-count-changed", unread_number, True)
            self.notify("unread-mail-count")

    def _new_mail(self, name, address, subject, post_url, form_data):
        mail = MailMessage(name, address, subject, post_url, form_data)
        self.emit("new-mail-received", mail)

    def do_get_property(self, pspec):
        name = pspec.name.lower().replace("-", "_")
        return getattr(self, name)
gobject.type_register(Mailbox)