diff --git a/amsn2/core/amsn.py b/amsn2/core/amsn.py index cf170225..3a607c07 100644 --- a/amsn2/core/amsn.py +++ b/amsn2/core/amsn.py @@ -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() diff --git a/amsn2/gui/base/utility.py b/amsn2/gui/base/utility.py index 4fd15c55..57d6388d 100644 --- a/amsn2/gui/base/utility.py +++ b/amsn2/gui/base/utility.py @@ -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 diff --git a/amsn2/gui/front_ends/gtk/utility.py b/amsn2/gui/front_ends/gtk/utility.py index 77c04112..fedeb11d 100644 --- a/amsn2/gui/front_ends/gtk/utility.py +++ b/amsn2/gui/front_ends/gtk/utility.py @@ -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() @@ -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() @@ -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() +