Skip to content

Commit

Permalink
[core, Gtk] Split the API to manage add/remove of contacts/groups. Ch…
Browse files Browse the repository at this point in the history
…ange of the API, i think there's no need to use a contact/group view.

The GTK implementation of this is still very minimal, but at least works! The changes that remains on the aMSNContact class make sense, the __init__ should initialize the base attributes. This was quite long to explain :P
  • Loading branch information
luckyluke committed Jul 30, 2009
1 parent d419d93 commit f8afe8e
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 64 deletions.
32 changes: 17 additions & 15 deletions amsn2/core/amsn.py
Expand Up @@ -202,24 +202,26 @@ def quit(self):

# TODO: move to UImanager
def addContact(self):
# open a window, get the infos and let the contactlist manager work
def contactCB(cv):
if cv:
self._contactlist_manager.addContact(cv.account, self._account.view.email,
invite_message='hola', groups=[])
self._gui.gui.aMSNInputWindow('Contact to add: ',
(ContactView(self, aMSNContact(self)), True),
contactCB, ())
def contactCB(account, invite_msg):
if account:
self._contactlist_manager.addContact(account, self._account.view.email,
invite_msg, [])
self._gui.gui.aMSNContactInputWindow(('Contact to add: ', 'Invite message: '),
contactCB, ())

def removeContact(self):
def contactCB(cv):
if cv:
papyon_contact = self._contactlist_manager._papyon_addressbook.\
contacts.search_by('account', cv.account)[0]
def contactCB(account):
if account:
try:
papyon_contact = self._contactlist_manager._papyon_addressbook.\
contacts.search_by('account', account)[0]
except IndexError:
self._gui.gui.aMSNErrorWindow('You don\'t have the %s contact!', account)
return

self._contactlist_manager.removeContact(papyon_contact.id)
self._gui.gui.aMSNInputWindow('Contact to remove: ',
(ContactView(self, aMSNContact(self)), False),
contactCB, ())

self._gui.gui.aMSNContactDeleteWindow('Contact to remove: ', contactCB, ())

def createMainMenuView(self):
menu = MenuView()
Expand Down
67 changes: 56 additions & 11 deletions amsn2/gui/base/utility.py
Expand Up @@ -42,23 +42,68 @@ def __init__(self, message, actions):
"""
raise NotImplementedError

class aMSNInputWindow(object):
class aMSNContactInputWindow(object):
"""
This Interface represent a window used to get an input,
like a new contact or a new group.
This Interface represent a window used to get a new contact.
"""
def __init__(self, message, type, callback, params):
def __init__(self, message, callback, groups):
"""
@type message: tuple
@param message: A tuple with the messages to be shown in the input window,
of the form (account_string, invite_string).
@type callback: function
@param callback: The function that will be called when the contact info has been filled.
The prototype is callback(email, invite_message, groups).
@type groups: tuple
@param groups: a list of existing groups
"""
raise notImplementedError

class aMSNGroupInputWindow(object):
"""
This Interface represent a window used to get a new group.
"""
def __init__(self, message, callback, contacts):
"""
@type message: tuple
@param message: A tuple with the messages to be shown in the input window.
@type type: ContactView or GroupView
@param type: contains the view to fill.
@type callback: function
@param callback: The function that will be called when the view has been filled.
The prototype is callback(view), where view is the ContactView or the Grouview
filled, or None if the input has been canceled.
@type params: tuple
@param params: a list of existing contacts or groups
@param callback: The function that will be called when the group info has been filled.
The prototype is callback(name_group, contacts).
@type contacts: tuple
@param contacts: a list of existing contacts
"""
raise notImplementedError

class aMSNContactDeleteWindow(object):
"""
This Interface represent a window used to delete a contact.
"""
def __init__(self, message, callback, contacts):
"""
@type message: tuple
@param message: A tuple with the messages to be shown in the window.
@type callback: function
@param callback: The function that will be called when the account has been entered.
The prototype is callback(account), where account is the email of the account to delete.
@type contacts: tuple
@param contacts: a tuple with all the contacts that can be removed in the AddressBook.
"""
raise notImplementedError

class aMSNGroupDeleteWindow(object):
"""
This Interface represent a window used to delete a group.
"""
def __init__(self, message, callback, groups):
"""
@type message: tuple
@param message: A tuple with the messages to be shown in the window.
@type callback: function
@param callback: The function that will be called when the group has been entered.
The prototype is callback(group), where group is the group name.
@type groups: tuple
@param groups: a tuple with all the groups that can be deleted.
"""
raise notImplementedError

142 changes: 104 additions & 38 deletions amsn2/gui/front_ends/gtk/utility.py
Expand Up @@ -61,25 +61,84 @@ def onResponse(self, dialog, id):
print "Unknown dialog choice, id %s" % id
self.destroy()

# TODO: build contactinput, groupinput, contactremove, groupremove instead of one window for all, and change the base API too
class aMSNInputWindow(base.aMSNInputWindow, gtk.Dialog):
def __init__(self, message, type, callback, params):
"""
@type message: str
@type type: ContactView or GroupView
@param type: contains the view to fill.
@type callback: function
@param callback: The function that will be called when the view has been filled.
The prototype is callback(view), where view is the ContactView or the Grouview
filled, or None if the input has been canceled.
@type params: tuple
@param params: a list of existing contacts or groups
"""
gtk.Dialog.__init__(self, "aMSN Input", None, gtk.DIALOG_NO_SEPARATOR,
class aMSNContactInputWindow(base.aMSNContactInputWindow, gtk.Dialog):
def __init__(self, message, callback, groups):
gtk.Dialog.__init__(self, "aMSN Contact Input", None, gtk.DIALOG_NO_SEPARATOR,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
self._callback = callback

label = gtk.Label(message[0])
self._name = gtk.Entry()
ca = self.get_content_area()
ca.set_spacing(5)
ca.pack_start(label)
ca.pack_start(self._name)

# TODO: build list of existing groups
label2 = gtk.Label(message[1])
ca.pack_start(label2)
self._message = gtk.Entry()
ca.pack_start(self._message)
label2.show()
self._message.show()

self.connect("response", self.onResponse)
label.show()
self._name.show()
self.show()

def onResponse(self, dialog, id):
if id == gtk.RESPONSE_ACCEPT:
name = self._name.get_text()
msg = self._message.get_text()
self._callback(name, msg)
elif id == gtk.RESPONSE_REJECT:
pass
self.destroy()


class aMSNGroupInputWindow(base.aMSNGroupInputWindow, gtk.Dialog):
def __init__(self, message, callback, contacts):
gtk.Dialog.__init__(self, "aMSN Group Input", None, gtk.DIALOG_NO_SEPARATOR,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
self._callback = callback

label = gtk.Label(message[0])
self._name = gtk.Entry()
ca = self.get_content_area()
ca.set_spacing(5)
ca.pack_start(label)
ca.pack_start(self._name)

# TODO: build list of existing contacts
label2 = gtk.Label(message[1])
ca.pack_start(label2)
self._message = gtk.Entry()
ca.pack_start(self._message)
label2.show()
self._message.show()

self.connect("response", self.onResponse)
label.show()
self._name.show()
self.show()

def onResponse(self, dialog, id):
if id == gtk.RESPONSE_ACCEPT:
name = self._name.get_text()
self._callback(name)
elif id == gtk.RESPONSE_REJECT:
pass
self.destroy()

class aMSNContactDeleteWindow(base.aMSNContactDeleteWindow, gtk.Dialog):
def __init__(self, message, callback, contacts):
gtk.Dialog.__init__(self, "aMSN Contact Input", None, gtk.DIALOG_NO_SEPARATOR,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
self._callback = callback
self._view , going_to_add = type

label = gtk.Label(message)
self._name = gtk.Entry()
Expand All @@ -88,22 +147,32 @@ def __init__(self, message, type, callback, params):
ca.pack_start(label)
ca.pack_start(self._name)

# TODO: build list of existing contacts/groups if going_to_add a group or a contact
if isinstance(type[0], views.ContactView):
if going_to_add:
label2 = gtk.Label("Message: ")
ca.pack_start(label2)
self._message = gtk.Entry()
ca.pack_start(self._message)
label2.show()
self._message.show()
elif isinstance(type[0], views.GroupView):
self.connect("response", self.onResponse)
label.show()
self._name.show()
self.show()

def onResponse(self, dialog, id):
if id == gtk.RESPONSE_ACCEPT:
name = self._name.get_text()
self._callback(name)
elif id == gtk.RESPONSE_REJECT:
pass
else:
# TODO: get the string from the core
aMSNErrorWindow("Can't build an input window of type %s" % type[0])
self.destroy()
return
self.destroy()

class aMSNGroupDeleteWindow(base.aMSNGroupDeleteWindow, gtk.Dialog):
def __init__(self, message, callback, groups):
gtk.Dialog.__init__(self, "aMSN Group Input", None, gtk.DIALOG_NO_SEPARATOR,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
self._callback = callback

label = gtk.Label(message)
self._name = gtk.Entry()
ca = self.get_content_area()
ca.set_spacing(5)
ca.pack_start(label)
ca.pack_start(self._name)

self.connect("response", self.onResponse)
label.show()
Expand All @@ -112,12 +181,9 @@ def __init__(self, message, type, callback, params):

def onResponse(self, dialog, id):
if id == gtk.RESPONSE_ACCEPT:
self._view.account = self._name.get_text()
if self._view.account:
self._callback(self._view)
else:
# TODO: get the string from the core
aMSNErrorWindow("The input can't be empty")
name = self._name.get_text()
self._callback(name)
elif id == gtk.RESPONSE_REJECT:
self._callback(None)
pass
self.destroy()

0 comments on commit f8afe8e

Please sign in to comment.