Index: conduit/dataproviders/GmailModule/config.glade =================================================================== --- conduit/dataproviders/GmailModule/config.glade (revision 838) +++ conduit/dataproviders/GmailModule/config.glade (working copy) @@ -1,699 +1,548 @@ - - - + + + - - - - True - Gmail Sink Properties - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 250 - 350 - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - True - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - False - 5 - - - - True - <b>Login Details</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - False - 0 - - - - True - Username: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - True - True - GTK_PACK_END - - - - - 0 - True - True - - - - - - True - False - 0 - - - - True - Password: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.519999980927 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - False - 0 - - True - * - False - - - 0 - True - True - - - - - 0 - False - False - - - - - - True - - - 0 - True - True - - - - - - True - <b>Saved Email Settings</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - Attach Label to Email - True - GTK_RELIEF_NORMAL - False - False - False - True - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - False - False - - - - - 0 - True - True - - - - - - - - True - Gmail Emails - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 250 - 350 - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - True - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - False - 5 - - - - True - <b>Account Details</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - Username: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - False - False - - - - - - True - Password: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - False - False - - - - - - True - <b>Return Emails Matching</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - All Emails - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - True - Unread Emails - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - True - Emails With Label - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - False - False - - - - - - True - True - Emails in Folder - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - False - 0 - - - - - - - 0 - True - True - - - - - - True - <b>When Saving Emails</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - Save With Label - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - 0 - False - False - - - - - 0 - True - True - - - - - - + + True + Gmail Sink Properties + False + 250 + 350 + GDK_WINDOW_TYPE_HINT_DIALOG + + + True + + + True + 5 + + + True + <b>Login Details</b> + True + + + False + False + + + + + True + + + True + Username: + + + False + False + + + + + True + True + + + GTK_PACK_END + 1 + + + + + 1 + + + + + True + + + True + 0.51999998092651367 + Password: + + + False + False + + + + + True + True + False + * + + + 1 + + + + + False + False + 2 + + + + + True + + + False + 3 + + + + + True + <b>Saved Email Settings</b> + True + + + False + False + 4 + + + + + True + True + Attach Label to Email + True + False + True + + + False + False + 5 + + + + + True + True + + + False + False + 6 + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + + + True + Gmail Emails + False + 250 + 350 + GDK_WINDOW_TYPE_HINT_DIALOG + + + True + + + True + 5 + + + True + <b>Account Details</b> + True + + + False + False + + + + + True + 0 + Username: + + + False + False + 1 + + + + + True + True + + + False + False + 2 + + + + + True + 0 + Password: + + + False + False + 3 + + + + + True + True + + + False + False + 4 + + + + + True + <b>Return Emails Matching</b> + True + + + False + False + 5 + + + + + True + True + All Emails + True + True + + + + False + False + 6 + + + + + True + True + Unread Emails + True + True + + + + False + False + 7 + + + + + True + True + Emails With Label + True + True + + + + False + False + 8 + + + + + True + True + + + False + False + 9 + + + + + True + True + Emails in Folder + True + True + + + + False + False + 10 + + + + + True + + + + + + 11 + + + + + True + <b>When Saving Emails</b> + True + + + False + False + 12 + + + + + True + True + Save With Label + True + True + + + + False + False + 13 + + + + + True + True + + + False + False + 14 + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + + + True + Gmail Emails + False + 250 + 350 + GDK_WINDOW_TYPE_HINT_DIALOG + + + True + + + True + 5 + + + True + <b>Account Details</b> + True + + + False + False + + + + + True + 0 + Username: + + + False + False + 1 + + + + + True + + + True + True + + + + + True + @gmail.com + + + False + False + 1 + + + + + 2 + + + + + True + 0 + Password: + + + False + False + 3 + + + + + True + True + + + False + False + 4 + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + Index: conduit/dataproviders/GmailModule/GmailModule.py =================================================================== --- conduit/dataproviders/GmailModule/GmailModule.py (revision 838) +++ conduit/dataproviders/GmailModule/GmailModule.py (working copy) @@ -8,17 +8,18 @@ import conduit from conduit import log,logd,logw import conduit.Utils as Utils -import conduit.DataProvider as DataProvider +from conduit.DataProvider import DataSource +from conduit import DataProvider import conduit.Exceptions as Exceptions import conduit.datatypes.Email as Email import conduit.datatypes.Contact as Contact -Utils.dataprovider_add_dir_to_path(__file__, "libgmail-0.1.5") +Utils.dataprovider_add_dir_to_path(__file__, "libgmail-0.1.6.1") import libgmail MODULES = { "GmailEmailTwoWay" : { "type": "dataprovider" }, -# "GmailContactTwoWay" : { "type": "dataprovider" }, + "GmailContactOneWay" : { "type": "dataprovider" }, } GOOGLE_CAT = DataProvider.DataProviderCategory("Google", "applications-internet") @@ -43,6 +44,7 @@ self.ga = libgmail.GmailAccount(self.username, self.password) self.ga.login() self.loggedIn = True + except: logw("Error logging into gmail (username %s)\n%s" % (self.username,traceback.format_exc())) raise Exceptions.RefreshError @@ -297,81 +299,102 @@ } -class GmailContactTwoWay(GmailBase, DataProvider.TwoWay): +class GmailContactOneWay(GmailBase, DataSource): _name_ = _("Contacts") _description_ = _("Sync your Gmail Contacts") _category_ = GOOGLE_CAT - _module_type_ = "twoway" + _module_type_ = "source" _in_type_ = "contact" _out_type_ = "contact" _icon_ = "contact-new" def __init__(self, *args): GmailBase.__init__(self, *args) - DataProvider.TwoWay.__init__(self) + DataSource.__init__(self) self.need_configuration(True) self.contacts = None self.username = "" self.password = "" + def initialize(self): return True def refresh(self): - DataProvider.TwoWay.refresh(self) + DataSource.refresh(self) GmailBase.refresh(self) self.contacts = {} + if self.loggedIn: result = self.ga.getContacts().getAllContacts() for c in result: - #FIXME: When Contact can load a vcard file, use that instead! - contact = Contact.Contact() + #FIXME: When Contact can load a vcard file, use that instead! + # FIXME figure out what the URI argument to the contact __init__ + # does and set it to something more meaningfull than "". It is a + # mandatory argument + contact = Contact.Contact(URI="") contact.set_from_vcard_string(c.getVCard()) contact.set_UID(c.email) + logd( "Got contact " + c.email ) self.contacts[c.email] = contact else: raise Exceptions.SyncronizeFatalError def get_all(self): - DataProvider.TwoWay.get_all(self) + DataSource.get_all(self) return [x for x in self.contacts.iterkeys()] def get(self, LUID): - DataProvider.TwoWay.get(self, LUID) + DataSource.get(self, LUID) return self.contacts[LUID] def put(self, contact, overwrite, LUID=None): - DataProvider.TwoWay.put(self, contact, overwrite, LUID) + DataSource.put(self, contact, overwrite, LUID) def finish(self): - DataProvider.TwoWay.finish(self) + DataSource.finish(self) self.contacts = None def configure(self, window): - tree = gtk.glade.XML(conduit.GLADE_FILE, "GmailSinkConfigDialog") + tree = Utils.dataprovider_glade_get_widget( + __file__, + "config.glade", + "GmailContactsConfigDialog") + #tree = gtk.glade.XML(conduit.GLADE_FILE, "GmailContactsSourceConfigDialog") + + + # TODO figure out how to get the contacts groups and add them to the dialog. + # libgmail doesn't support contact groups. + #index = 0 + #groupComboBox = gtk.combo_box_new_text() + #for group in ["Test Group 1", "Test Group 2", "Test Group 3"]: + #groupComboBox.insert_text(index,group) + #index += 1 + #groupComboBox.show() + #tree.get_widget("groupBox").pack_end(groupComboBox) + + + # TODO have option to show 'frequently mailed' - #get a whole bunch of widgets - searchLabelEmailsCb = tree.get_widget("searchLabelEmails") - labelEntry = tree.get_widget("labels") usernameEntry = tree.get_widget("username") passwordEntry = tree.get_widget("password") #preload the widgets usernameEntry.set_text(self.username) + passwordEntry.set_text(self.password) - dlg = tree.get_widget("GmailSinkConfigDialog") + dlg = tree.get_widget("GmailContactsConfigDialog") dlg.set_transient_for(window) response = dlg.run() if response == gtk.RESPONSE_OK: self.username = usernameEntry.get_text() - if passwordEntry.get_text() != self.password: - self.password = passwordEntry.get_text() - self.set_configured(True) + self.password = passwordEntry.get_text() + self.check_configuration() dlg.destroy() def get_configuration(self): @@ -380,3 +403,24 @@ "password" : self.password, } + def set_configuration(self, config): + # check that the config dict is OK + if not config.has_key('username') or not config.has_key('password'): + # FIXME is there a better / standard way to do this? + logw( "Invalid configuration for gmail contacts source. Username and/or password nor provided. The configuration given was: " + repr(config) ) + raise Exception + self.username = config['username'] + self.password = config['password'] + + self.check_configuration() + + def check_configuration(self): + # TODO make this more strict and accurate. E.g. check username for spaces etc + if self.username != "" and self.password != "": + self.set_configured(True) + else: + self.set_configured(False) + + def get_UID(self): + return self.username+":"+self.password +