|
From: Stas Z. <sta...@us...> - 2005-09-14 11:36:42
|
Update of /cvsroot/gmailagent/GA-main In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22517 Modified Files: AboutDialog_forms.py AddressDialog.ui AddressDialog.ui.h AddressDialog_forms.py Gmail.py GmailAgent.e3p GmailAgent.py GuiQT.py HelpDialog_forms.py LoginDialog_forms.py MainWin_forms.py TODO filelist setup.py Log Message: Updates Index: Gmail.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/Gmail.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Gmail.py 14 Jun 2005 14:17:31 -0000 1.19 --- Gmail.py 14 Sep 2005 11:36:28 -0000 1.20 *************** *** 18,28 **** # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. GM_DEBUG = 1 ! import libgmail2,urllib2,logging,ConfigParser,os ! try: ! import Contrgmc except ImportError,info: USE_CONTACTS = False else: --- 18,38 ---- # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + """Provides some abstraction from the libgmail lib + It also imports the gcm stuff, if available, so GA can through this module + access gcm stuff.""" GM_DEBUG = 1 ! import libgmail,urllib2,logging,ConfigParser,os ! try: ! logging.basicConfig(level=logging.DEBUG,\ ! format='\n%(levelname)s,%(module)s:LineNo %(lineno)d:%(message)s') ! except TypeError: ! # Python <=2.3? ! pass try: ! from GCM_qt import Contrgcm ! from GCM_qt.QgcmDialogs import ModalPopup except ImportError,info: + print info USE_CONTACTS = False else: *************** *** 31,38 **** def login(name,pas): if GM_DEBUG: logging.debug("\n>>>>>>>> Function: login") ! ga = libgmail2.GmailAccount(name,pas) try: ga.login() ! except (libgmail2.GmailLoginFailure,urllib2.HTTPError),info: if GM_DEBUG: logging.warning("%s" % info) return (1,"%s" % info) --- 41,48 ---- def login(name,pas): if GM_DEBUG: logging.debug("\n>>>>>>>> Function: login") ! ga = libgmail.GmailAccount(name,pas) try: ga.login() ! except (libgmail.GmailLoginFailure,urllib2.HTTPError),info: if GM_DEBUG: logging.warning("%s" % info) return (1,"%s" % info) *************** *** 45,49 **** header = obj.mailheader ! gmsg = libgmail2.GmailComposedMessage(to = header['to'], subject = header['subject'], body = obj.mailbody, --- 55,59 ---- header = obj.mailheader ! gmsg = libgmail.GmailComposedMessage(to = header['to'], subject = header['subject'], body = obj.mailbody, *************** *** 82,261 **** except: if GM_DEBUG: logging.warning("Failed to load the password from %s" % rcfile) ! return (1,"Failed to load the password from %s" % rcfile) return (0,(name,pas)) - ######## Everything below this point will become part of a seperate module ##### - ######## Leave it here until the new contacts frontend is functional ########### ! ##def upload_local_contacts(addrfile,ga): ! ## """Returns the contacts from the local file which don't have a ID entry. ! ## Contacts without an ID are considered local only and must be added to the Gmail ! ## contacts list. ! ## This function is called whenever the user logs into Gmail. ! ## Returns error message on faillure, None on succes.""" ! ## if GM_DEBUG: logging.debug("\n>>>>>>>> Function: upload_local_contacts") ! ## contacts = load_addressfile(addrfile) ! ## for line in contacts: ! ## if GM_DEBUG: logging.debug("Found local contact %s %s %s %s" % line) ! ## if not line[3]: ! ## logging.debug("Adding %s %s %s %s to Gmail" % line) ! ## if not ga.addContact(line[0],line[1],line[2]):#libgmail2 checks for exception ! ## return ("Unable to add contact %s %s %s %s" % line) ! ## # Now we reload the contacts to create a new local contacts list ! ## #import_contacts(addrfile,ga) ! ## ! ## ! ##def store_address(addrfile,name,addr,notes='',id='',ga=None): ! ## """The contacts will be stored in the local copy on disk. ! ## If the id is given we assume the contact has a valid Gmail id and ! ## the contact is removed from the online contacts and replaced by the ! ## given contact. It will get a new id from Gmail. ! ## """ ! ## if GM_DEBUG: ! ## logging.debug("\n>>>>>>>> Function: store_address") ! ## logging.debug("store contact %s %s %s %s %s" % (name,addr,notes,id,ga)) ! ## if id and ga: ! ## if GM_DEBUG: logging.debug("Found id, removing original contact first") ! ## contacts = ga.getContacts() ! ## contact = contacts.getContactById(id) ! ## if contact: ! ## if not ga.removeContact(contact): ! ## logging.warning("Failed to remove contact %s" % contact) ! ## else: ! ## # Build the new local file with the contacts from Gmail ! ## import_contacts(addrfile,ga) ! ## # now we add the new contact to the local file ! ## store_address(addrfile,name,addr,notes) ! ## # And upload it to Gmail ! ## upload_local_contacts(addrfile,ga) ! ## # Retrieve Gmail contacts so that we have get an id for the new contact. ! ## import_contacts(addrfile,ga) ! ## # stuff is stored in a file like this: ! ## # name&&addr&¬es&&id ! ## # Contacts that are not (yet) in the Gmail contacts list have an empty ! ## # string as id. ! ## # After syncronizing the file with the contacts the id fields will be asigned. ! ## try: ! ## f = open(addrfile,'r') ! ## lines = f.readlines() ! ## f.close() ! ## except IOError,info: ! ## mesg = "Failed to check the address (IO), %s" % info ! ## if GM_DEBUG: logging.warning(mesg) ! ## return mesg ! ## else: ! ## for line in lines: ! ## if name in line and addr in line: ! ## return ! ## # It's a new entry ! ## line = "%s&&%s&&%s&&%s\n" % (name,addr,notes,id) ! ## if GM_DEBUG: logging.debug("Found new contact %s" % line) ! ## try: ! ## f = open(addrfile,'a') ! ## f.write(line) ! ## f.close() ! ## except IOError,info: ! ## f.close() ! ## mesg = "Failed to store address, %s" % info ! ## if GM_DEBUG: logging.warning(mesg) ! ## return mesg ! ## ! ##def load_addressfile(filename): ! ## if GM_DEBUG: logging.debug("\n>>>>>>>> Function: load_addressfile") ! ## try: ! ## f = open(filename,'r') ! ## lines = f.readlines() ! ## f.close() ! ## except IOError,info: ! ## if GM_DEBUG: logging.warning(str(info)) ! ## return ! ## if GM_DEBUG: logging.debug(str(lines)) ! ## newlines = [] ! ## for line in lines: ! ## newlines.append(tuple(line[:-1].split("&&"))) ! ## return (newlines) ! ## ! ##def import_contacts(addrfile,ga): ! ## """This gets the gmail contacts create a new local contacts list on disk.""" ! ## if GM_DEBUG: logging.debug("\n>>>>>>>> Function: import_contacts") ! ## upload_local_contacts(addrfile,ga) ! ## contacts = ga.getContacts().getAllContacts() ! ## logging.debug("Contacts imported:\n%s" % contacts) ! ## if contacts: ! ## # remove local file, we can remove it because the upload_local_contacts method will make sure ! ## # that the contacts are syncronized. ! ## logging.debug("Removing local file") ! ## open(addrfile,'w').close() ! ## else: ! ## return ! ## for obj in contacts: ! ## store_address(addrfile,\ ! ## obj.getName(),\ ! ## obj.getEmail(),\ ! ## obj.getNotes(),\ ! ## obj.getId()) ! ## return load_addressfile(addrfile) ! ## ! ##def export_contacts(addrfile,ga): ! ## """This will remove the contacts at the online contacts list and replace ! ## it with the local copy fom disk. ! ## It will return a message on any error. ! ## It returns None on succes.""" ! ## if GM_DEBUG: logging.debug("\n>>>>>>>> Function: export_contacts") ! ## entries = load_addressfile(addrfile) ! ## if len(entries) < 1: ! ## text = "Failed to load address file, %s" % addrfile ! ## if GM_DEBUG: logging.critical(text) ! ## return text ! ## try: ! ## contacts = ga.getContacts().getAllContacts() ! ## # Just to test save_contacts ! ## save_contacts(contacts) ! ## for contact in contacts: ! ## if GM_DEBUG: logging.debug("Removing contact %s", contact) ! ## ga.removeContact(contact) ! ## except Exception,info: ! ## logging.critical(str(info)) ! ## if contacts: ! ## save_contacts(contacts) ! ## return "An error occured, tried to save your contacts to\n%s and %s" %\ ! ## ('~/.GmailContacts.txt','~/.GmailContacts.pickle') ! ## # Now we fill the contacts list again from the local file. ! ## try: ! ## for entry in entries: ! ## if GM_DEBUG: logging.debug("Adding contact %s", entry) ! ## apply(ga.addContact,entry[:-1]) ! ## except Exception,info: ! ## logging.critical(str(info)) ! ## save_contacts(contacts) ! ## ! ##def save_contacts(contacts): ! ## """Save the contact in case of an error. This is an attempt to prevent ! ## data loss in case of an error when interacting with Gmail contacts.""" ! ## if GM_DEBUG: logging.debug("\n>>>>>>>> Function: save_contacts") ! ## try: ! ## f = open(os.path.expanduser('~/.GmailContacts.pickle'),'w') ! ## pickle.dump(contacts,f) ! ## ## XXX TODO: some way to load the pickled object and restore it ! ## except Exception,info: ! ## text = "Attempt to pickle the contacts %s" % str(info) ! ## logging.critical(text) ! ## f.close() ! ## try: ! ## f =open(os.path.expanduser('~/.GmailContacts.txt'),'w') ! ## text = "#An error occured in GmailAgent and these contacts are saved\n"+\ ! ## "#to this file in an attempt to save them\n"+\ ! ## "#A contact is saved as follows:\n"+\ ! ## "#GmailID Name email notes\n" ! ## f.write(text) ! ## for con in contacts: ! ## name,email,notes,id = con.getName(),con.getEmail(),con.getNotes(),con.getId() ! ## f.write("%s %s %s %s\n" % (con.getId(),\ ! ## con.getName(),\ ! ## con.getEmail(),\ ! ## con.getNotes())) ! ## f.close() ! ## except Exception,info: ! ## logging.critical(str(info)) ! ## return str(info) ! ## --- 92,111 ---- except: if GM_DEBUG: logging.warning("Failed to load the password from %s" % rcfile) ! return (1,"Failed to load the name and password from %s" % rcfile) return (0,(name,pas)) ! def start_gcm(gac,qapp): ! if not USE_CONTACTS: ! return (1, "Can't find gcm-qt.\nMake sure that you have installed gcm.\See the GmailAgent for more info.") ! try: ! from GCM_qt import GuiQTgcm ! gcm = GuiQTgcm.MainWin(gac=gac,application=qapp) ! except Exception,info: ! print info ! return (1, "An error occured in gcm:\n%s" % info) ! else: ! return (0, gcm) ! ! ! Index: AddressDialog.ui =================================================================== RCS file: /cvsroot/gmailagent/GA-main/AddressDialog.ui,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AddressDialog.ui 8 Jun 2005 12:28:17 -0000 1.5 --- AddressDialog.ui 14 Sep 2005 11:36:28 -0000 1.6 *************** *** 41,63 **** <widget class="QLabel"> <property name="name"> - <cstring>textLabel1</cstring> - </property> - <property name="geometry"> - <rect> - <x>80</x> - <y>10</y> - <width>140</width> - <height>20</height> - </rect> - </property> - <property name="text"> - <string><b>Addressbook</b></string> - </property> - <property name="textFormat"> - <enum>RichText</enum> - </property> - </widget> - <widget class="QLabel"> - <property name="name"> <cstring>textLabel2</cstring> </property> --- 41,44 ---- *************** *** 273,290 **** </property> </widget> ! <widget class="QPushButton"> <property name="name"> ! <cstring>pushButtonImport</cstring> </property> <property name="geometry"> <rect> ! <x>160</x> ! <y>360</y> ! <width>120</width> ! <height>26</height> </rect> </property> <property name="text"> ! <string>Import contacts</string> </property> </widget> --- 254,274 ---- </property> </widget> ! <widget class="QLabel"> <property name="name"> ! <cstring>textLabel1</cstring> </property> <property name="geometry"> <rect> ! <x>80</x> ! <y>10</y> ! <width>140</width> ! <height>20</height> </rect> </property> <property name="text"> ! <string><b>Gmail contacts</b></string> ! </property> ! <property name="textFormat"> ! <enum>RichText</enum> </property> </widget> *************** *** 363,372 **** <slot>lineEditSearch_textChanged(const QString&)</slot> </connection> - <connection> - <sender>pushButtonImport</sender> - <signal>clicked()</signal> - <receiver>FormAddress</receiver> - <slot>pushButtonImport_clicked()</slot> - </connection> </connections> <includes> --- 347,350 ---- *************** *** 382,386 **** <slot>listViewSend_clicked( QListViewItem * )</slot> <slot>lineEditSearch_textChanged( const QString & )</slot> - <slot>pushButtonImport_clicked()</slot> </slots> <layoutdefaults spacing="6" margin="11"/> --- 360,363 ---- Index: AddressDialog_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/AddressDialog_forms.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AddressDialog_forms.py 8 Jun 2005 12:28:17 -0000 1.13 --- AddressDialog_forms.py 14 Sep 2005 11:36:28 -0000 1.14 *************** *** 3,7 **** # Form implementation generated from reading ui file 'AddressDialog.ui' # ! # Created: Mon Jun 6 20:34:33 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'AddressDialog.ui' # ! # Created: Mon Aug 15 12:50:15 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # *************** *** 118,125 **** - self.textLabel1 = QLabel(self,"textLabel1") - self.textLabel1.setGeometry(QRect(80,10,140,20)) - self.textLabel1.setTextFormat(QLabel.RichText) - self.textLabel2 = QLabel(self,"textLabel2") self.textLabel2.setGeometry(QRect(390,10,80,20)) --- 118,121 ---- *************** *** 163,168 **** self.listViewBook.setShowSortIndicator(1) ! self.pushButtonImport = QPushButton(self,"pushButtonImport") ! self.pushButtonImport.setGeometry(QRect(160,360,120,26)) self.pushButtonEdit = QPushButton(self,"pushButtonEdit") --- 159,165 ---- self.listViewBook.setShowSortIndicator(1) ! self.textLabel1 = QLabel(self,"textLabel1") ! self.textLabel1.setGeometry(QRect(80,10,140,20)) ! self.textLabel1.setTextFormat(QLabel.RichText) self.pushButtonEdit = QPushButton(self,"pushButtonEdit") *************** *** 182,191 **** self.connect(self.listViewSend,SIGNAL("clicked(QListViewItem*)"),self.listViewSend_clicked) self.connect(self.lineEditSearch,SIGNAL("textChanged(const QString&)"),self.lineEditSearch_textChanged) - self.connect(self.pushButtonImport,SIGNAL("clicked()"),self.pushButtonImport_clicked) def languageChange(self): self.setCaption(self.__tr("GmailAgent - Addressbook")) - self.textLabel1.setText(self.__tr("<b>Addressbook</b>")) self.textLabel2.setText(self.__tr("<b>Send to:</b>")) self.pushButton_add.setText(QString.null) --- 179,186 ---- *************** *** 200,204 **** self.listViewBook.header().setLabel(0,self.__tr("Name")) self.listViewBook.header().setLabel(1,self.__tr("Email Address")) ! self.pushButtonImport.setText(self.__tr("Import contacts")) self.pushButtonEdit.setText(self.__tr("Edit addressbook")) --- 195,199 ---- self.listViewBook.header().setLabel(0,self.__tr("Name")) self.listViewBook.header().setLabel(1,self.__tr("Email Address")) ! self.textLabel1.setText(self.__tr("<b>Gmail contacts</b>")) self.pushButtonEdit.setText(self.__tr("Edit addressbook")) *************** *** 228,234 **** print "FormAddress.lineEditSearch_textChanged(const QString&): Not implemented yet" - def pushButtonImport_clicked(self): - print "FormAddress.pushButtonImport_clicked(): Not implemented yet" - def __tr(self,s,c = None): return qApp.translate("FormAddress",s,c) --- 223,226 ---- Index: GmailAgent.e3p =================================================================== RCS file: /cvsroot/gmailagent/GA-main/GmailAgent.e3p,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GmailAgent.e3p 6 Jun 2005 18:26:08 -0000 1.14 --- GmailAgent.e3p 14 Sep 2005 11:36:28 -0000 1.15 *************** *** 2,6 **** <!DOCTYPE Project SYSTEM "Project-3.5.dtd"> <!-- Project file for project GmailAgent --> ! <!-- Saved: 2005-06-06, 17:29:27 --> <!-- Copyright (C) 2005 Stas Zytkiewicz, st...@li... --> <Project version="3.5"> --- 2,6 ---- <!DOCTYPE Project SYSTEM "Project-3.5.dtd"> <!-- Project file for project GmailAgent --> ! <!-- Saved: 2005-08-11, 17:20:42 --> <!-- Copyright (C) 2005 Stas Zytkiewicz, st...@li... --> <Project version="3.5"> *************** *** 38,44 **** </Source> <Source> - <Name>AddressBook.py</Name> - </Source> - <Source> <Name>AddressDialog_forms.py</Name> </Source> --- 38,41 ---- *************** *** 55,61 **** <Name>AddressEditorDialog_forms.py</Name> </Source> - <Source> - <Name>libgmail2.py</Name> - </Source> </Sources> <Forms> --- 52,55 ---- Index: AddressDialog.ui.h =================================================================== RCS file: /cvsroot/gmailagent/GA-main/AddressDialog.ui.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AddressDialog.ui.h 1 Jun 2005 18:07:28 -0000 1.2 --- AddressDialog.ui.h 14 Sep 2005 11:36:28 -0000 1.3 *************** *** 60,65 **** - void FormAddress::pushButtonImport_clicked() - { - - } --- 60,61 ---- Index: filelist =================================================================== RCS file: /cvsroot/gmailagent/GA-main/filelist,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** filelist 1 Jun 2005 18:35:23 -0000 1.8 --- filelist 14 Sep 2005 11:36:28 -0000 1.9 *************** *** 1,13 **** INSTALL README - ../GA-libgmail2/constants.py GmailAgent.py Gmail.py GuiQT.py - ../GA-libgmail2/libgmail2.py AboutDialog_forms.py LoginDialog_forms.py MainWin_forms.py - AddressBook.py AddressDialog_forms.py HelpDialog_forms.py --- 1,10 ---- Index: GuiQT.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/GuiQT.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** GuiQT.py 14 Jun 2005 14:17:31 -0000 1.35 --- GuiQT.py 14 Sep 2005 11:36:28 -0000 1.36 *************** *** 31,35 **** from AddressDialog_forms import FormAddress ! import Gmail,AddressBook import sys,os,logging --- 31,36 ---- from AddressDialog_forms import FormAddress ! import Gmail ! import sys,os,logging *************** *** 41,63 **** helppath = paths.helppath if GQ_DEBUG: logging.debug("helppath is %s" % helppath) ! rcfile = os.path.expanduser('~/.gmailagent') ! # TODO Add a addrfile path to the rcfile? # By doing so we can startup with the user selected addressfile? # REMINDER the addressfile is a local copy of the Gmail contacts. ! addrfile = os.path.expanduser('~/.gmailaddressbook') ! if not os.path.exists(addrfile): ! try: ! open(addrfile,'w') ! except IOError,info: ! if GQ_DEBUG: logging.warning(str(info)) class Message: ! """Just a container to pass stuff around""" pass # see self.send_message for usage class Observer: ! """Classic observer to monitor changes in some model""" def __init__(self,func): if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) --- 42,65 ---- helppath = paths.helppath if GQ_DEBUG: logging.debug("helppath is %s" % helppath) ! RCFILE = os.path.expanduser('~/.gmailagent') ! # TODO Add a addrfile path to the RCFILE? # By doing so we can startup with the user selected addressfile? # REMINDER the addressfile is a local copy of the Gmail contacts. ! ##addrfile = os.path.expanduser('~/.gmailaddressbook') ! ##if not os.path.exists(addrfile): ! ## try: ! ## open(addrfile,'w') ! ## except IOError,info: ! ## if GQ_DEBUG: logging.warning(str(info)) class Message: ! """Just a container to hold the message.""" pass # see self.send_message for usage class Observer: ! """Classic observer to monitor changes in some model ! TODO: replace this with the Observer from the gcm.""" def __init__(self,func): if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) *************** *** 97,100 **** --- 99,103 ---- self.mailbody = '' self.attachments = att + self.ga = None self.login = {'login':'','passwrd':''} if self.attachments: *************** *** 110,114 **** def pushButtonSend_clicked(self): - # get all the data from the dialog modal=0 --- 113,116 ---- *************** *** 140,144 **** def send_message(self,ga): """This will send the message to Gmail and stores the address(es) in the ! addressbook.""" self.progress_dlg.update() --- 142,147 ---- def send_message(self,ga): """This will send the message to Gmail and stores the address(es) in the ! addressbook. ! It's called by the observer.""" self.progress_dlg.update() *************** *** 149,153 **** #obj.login = self.login# not used, yet? obj.ga = ga#gmail account object ! result = Gmail.send_message(obj) if result[0]: --- 152,156 ---- #obj.login = self.login# not used, yet? obj.ga = ga#gmail account object ! self.ga = ga result = Gmail.send_message(obj) if result[0]: *************** *** 157,169 **** else: self.progress_dlg.update() - adrlist = self.mailheader['to'].split(',') - for adr in adrlist: - try: - name,foo = adr.split("@") - except Exception,info: - if GQ_DEBUG: logging.warning("trying to store address, %s" % info) - else: - if Gmail.store_address(addrfile,name,adr): - pass QMessageBox.information(self, "Info",result[1], --- 160,163 ---- *************** *** 182,186 **** return 1# this is checked by closeEvent ! def pushButtonAdress_clicked(self): # lineEditTo.setCurrentText will called when the model calls the update method of the obs #The 'To:' field is filled by the AddressBookDialog through the observer --- 176,180 ---- return 1# this is checked by closeEvent ! def pushButtonAdress_clicked(self,ga=None): # lineEditTo.setCurrentText will called when the model calls the update method of the obs #The 'To:' field is filled by the AddressBookDialog through the observer *************** *** 192,197 **** QMessageBox.Ok) return self.obs = Observer(self.lineEditTo.setText) ! ad = AddressBookDialog(self,observer=self.obs) def lineEditTo_textChanged(self,a0): --- 186,215 ---- QMessageBox.Ok) return + # we have gcm so now we can use it here and in the AddressBookDialog + if not self.ga: + txt = "Do you want to import your contacts from your Gmail\n"+\ + "account?\n"+\ + "If you do not then a local copy, if available, will\n"+\ + "be used.\n"+\ + "Be aware that any changes you want to make to the\n"+\ + "contacts require access to your Gmail account." + dlg = Gmail.ModalPopup(parent=self,text=txt) + ## BIG TODO: make this work :-) + if dlg.start():# Yes + obs = Observer(self._get_contacts) + login = Login(parent=self,observer=obs) + else: + self._get_local_contacts() + else: + self._get_contacts(self.ga) + + def _get_contacts(self,ga): + """Callback for the observer""" self.obs = Observer(self.lineEditTo.setText) ! AddressBookDialog(self,gac=ga,observer=self.obs) ! def _get_local_contacts(self): ! """get the contacts from the local dbase, if available""" ! self.obs = Observer(self.lineEditTo.setText) ! AddressBookDialog(self,observer=self.obs) def lineEditTo_textChanged(self,a0): *************** *** 209,214 **** self.keepsettings = 0 self.logindata = None ! if os.path.exists(rcfile): ! result = Gmail.load_login(rcfile) if result[0]: self.logindata = None --- 227,232 ---- self.keepsettings = 0 self.logindata = None ! if os.path.exists(RCFILE): ! result = Gmail.load_login(RCFILE) if result[0]: self.logindata = None *************** *** 295,299 **** class AddressBookDialog(FormAddress): ! def __init__(self,parent=None,name=None,modal=0,fl=0,file=addrfile,observer=None): if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) FormAddress.__init__(self,parent,name,modal,fl) --- 313,317 ---- class AddressBookDialog(FormAddress): ! def __init__(self,parent=None,name=None,modal=0,fl=0,gac='',observer=None): if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) FormAddress.__init__(self,parent,name,modal,fl) *************** *** 302,316 **** self.parent_observer = observer self.progress_dlg = None ! if os.path.exists(file): ! self._load(file) self.show() def pushButtonEdit_clicked(self): ! pass ! # seems we must prevent the garbage collector from removing the observer ! # object so we make it a class attribute. ! ##self.Myobs = Observer(self._load) ! #ad = AddressBook.ABMainWindow(parent=self,observer=self.Myobs,file=addrfile) ! ##AddressBookEditorDialog(parent=self) def pushButtonOk_clicked(self): --- 320,357 ---- self.parent_observer = observer self.progress_dlg = None ! self.ga = gac ! self.gcm = None ! # The mainwin checks for availablility gcm ! if self.ga: ! self.GC = Gmail.Contrgcm.GC(self.ga.name,'',self.ga) ! conlist = self.GC.import_contacts_gmail() ! else: ! result = Gmail.load_login(RCFILE) ! if result[0]: ! QMessageBox.critical(self, ! "Error", result[1], ! QMessageBox.Ok) ! return ! name,pas = result[1] ! self.GC = Gmail.Contrgcm.GC(name,pas) ! conlist = self.GC.import_contacts_db() ! if conlist: ! self._load(conlist) ! print "AddressBookDialog conlist",conlist self.show() def pushButtonEdit_clicked(self): ! if self.gcm: ! return ! result = Gmail.start_gcm(self.GC,Qapplication) ! print "result",result ! if result[0]: ! QMessageBox.critical(self, ! "Error", result[1], ! QMessageBox.Ok) ! return ! else: ! #We make it a attribute to prevent destruction by the Python Garbage collector ! self.gcm = result[1] def pushButtonOk_clicked(self): *************** *** 364,389 **** break ! def pushButtonImport_clicked(self): ! print "FormAddressEditor.pushButtonImport_clicked()" ! # The observer is passed to Login, after succes Login will call the observers ! # _login_success method ! obs = Observer(self._login_success) ! # this looks like a hack but Login is used by other objects also. ! Login(parent=self.parent,observer=obs) ! def _login_success(self,ga): ! """This is the method which is called through the observer by the Login.""" ! # ga is the Gmail account after a succseful login ! self.ga = ga ! # Get the contacts and merge them with the local copy ! # The new local copy will be saved on disk and returnt to the caller. ! Gmail.import_contacts(addrfile,self.ga) ! self._load(addrfile) ! def _load( self, filename): """Loads a local address file into the widget.""" # this is also called from the observer self.listViewBook.clear() ! lines = Gmail.load_addressfile(addrfile) # used by lineEditSearch_textChanged to lookup the name # keys are the names, vals are the listviewitems objects --- 405,430 ---- break ! ## def pushButtonImport_clicked(self): ! ## print "FormAddressEditor.pushButtonImport_clicked()" ! ## # The observer is passed to Login, after succes Login will call the observers ! ## # _login_success method ! ## obs = Observer(self._login_success) ! ## # this looks like a hack but Login is used by other objects also. ! ## Login(parent=self.parent,observer=obs) ! ## def _login_success(self,ga): ! ## """This is the method which is called through the observer by the Login.""" ! ## # ga is the Gmail account after a succseful login ! ## self.ga = ga ! ## # Get the contacts and merge them with the local copy ! ## # The new local copy will be saved on disk and returnt to the caller. ! ## Gmail.import_contacts(addrfile,self.ga) ! ## self._load(addrfile) ! def _load( self, lines): """Loads a local address file into the widget.""" # this is also called from the observer self.listViewBook.clear() ! ##lines = Gmail.load_addressfile(addrfile) # used by lineEditSearch_textChanged to lookup the name # keys are the names, vals are the listviewitems objects *************** *** 414,573 **** return objlist - ######## Everything below this point will become part of a seperate module ##### - ######## Leave it here until the new contacts frontend is functional ########### - - ##class AddressBookEditorDialog(FormAddressEditor): - ## def __init__(self,parent=None,name=None,modal=0,fl=0,file=addrfile,observer=None): - ## if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) - ## FormAddressEditor.__init__(self,parent,name,modal,fl) - ## self.parent = parent - ## self.parent_observer = observer - ## self.loaded_local_file = None - ## self.selecteditem = None - ## self.ga = None# we want to test if we already have a Gmail account - ## text = "GmailAgent uses a local copy of your Gmail contacts list so\n"+\ - ## "before making changes you should (re)import your contacts list.\n\n"+\ - ## "Shall I import your Gmail contacts list now?" - ## ans = QMessageBox.information(self,"Question", text, - ## QMessageBox.Cancel,QMessageBox.Ok) - ## if ans == 1: - ## self.pushButtonImport_clicked() - ## else: - ## conlist = Gmail.load_addressfile(addrfile) - ## self._load(conlist) - ## self.loaded_local_file = 1 - ## self.show() - ## - ## def pushButtonImport_clicked(self): - ## print "FormAddressEditor.pushButtonImport_clicked()" - ## # The observer is passed to Login, after succes Login will call the observers - ## # _login_success method - ## self.progress_dlg = ProgressDialog(self,"Importing contacts",2) - ## obs = Observer(self._login_success) - ## # this looks like a hack but Login is used by other objects also. - ## Login(parent=self.parent,observer=obs) - ## - ## def _login_success(self,ga): - ## """This is the method which is called through the observer by the Login.""" - ## # ga is the Gmail account after a succseful login - ## self.ga = ga - ## self.progress_dlg.update() - ## # Get the contacts and merge them with the local copy - ## # The new local copy will be saved on disk and returnt to the caller. - ## conlist = Gmail.import_contacts(addrfile,self.ga) - ## self.loaded_local_file = None - ## self._load(conlist) - ## - ## def _load( self, conlist): - ## """Loads a contacts list into the widget.""" - ## self.listViewContacts.clear() - ## nameshash = {}# used also as a lookup hash - ## for line in conlist: - ## item = QListViewItem(self.listViewContacts) - ## try: - ## nameshash[line[0]] = item - ## item.setText(0,line[0]) - ## item.setText(1,line[1]) - ## item.setText(2,line[2][:60]) - ## item.setText(3,line[3]) - ## except Exception,info: - ## if GQ_DEBUG: - ## logging.warning("Reading addressbook failed, %s" % str(info)) - ## print info - ## return - ## self.parent._load(addrfile)# fill the parents view - ## try: - ## self.progress_dlg.update() - ## except: - ## pass - ## - ## def pushButtonOk_clicked(self): - ## print "FormAddressEditor.pushButtonOk_clicked()" - ## text = "Your contacts are kept in a local file on this system and you\n"+\ - ## "should summit it to your Gmail contacts list to keep everything\n"+\ - ## "in sync.\n\n"+\ - ## "WARNING,\n"+\ - ## "when summiting these contacts to your Gmail account the online Gmail\n"+\ - ## "the contacts list will be cleared and you will loose any changes you made online.\n\n"+\ - ## "Should I upload these contacts to your Gmail accounts contacts list?" - ## ans = QMessageBox.information(self,"Question", text, - ## QMessageBox.Cancel,QMessageBox.Ok) - ## if ans == 1: - ## if not self.ga: - ## obs = Observer(self._export_contacts) - ## Login(parent=self.parent,observer=obs) - ## else: - ## self._export_contacts(self.ga) - ## self.pushButtonCancel_clicked() - ## - ## def _export_contacts(self,ga): - ## Gmail.export_contacts(addrfile,ga) - ## - ## def pushButtonCancel_clicked(self): - ## # XXX we should also update the parent with the new contacts. - ## self.done(1) - ## - ## def pushButtonEdit_clicked(self): - ## print "FormAddressEditor.pushButtonEdit_clicked()" - ## entry = self.listViewContacts.selectedItem() - ## if not self.ga: - ## text = "You're not logged in your Gmail account.\n"+\ - ## "Hit the 'Import contacts' button to login and\n"+\ - ## "then you can edit the contacts." - ## QMessageBox.information(self,"Information", text,QMessageBox.Ok) - ## return - ## AddressBookEditDialog(entry,parent=self,ga=self.ga) - ## - ## def listView3_clicked(self,a0): - ## print "FormAddressEditor.listView3_clicked(QListViewItem*): Not implemented yet" - ## - ## def lineEditSearch_textChanged(self,a0): - ## print "FormAddressEditor.lineEditSearch_textChanged(const QString&)" - ## if not self.nameshash: return - ## # a0 is the text object - ## txt = str(a0) - ## for k,v in self.nameshash.items(): - ## if txt in k: - ## if self.selecteditem: - ## self.selecteditem.setSelected(0) - ## self.selecteditem.repaint() - ## v.setSelected(1) - ## v.repaint() - ## self.selecteditem = v - ## break - ## - ## def pushButtonAdd_clicked(self): - ## print "FormAddressEditor.pushButtonAdd_clicked(): Not implemented yet" - ## - ## def pushButtonRemove_clicked(self): - ## print "FormAddressEditor.pushButtonRemove_clicked(): Not implemented yet" - ## - ## def pushButtonHelp_clicked(self): - ## print "FormAddressEditor.pushButtonHelp_clicked(): Not implemented yet" - ## - ##class AddressBookEditDialog(FormAddressEdit): - ## def __init__(self,entry,parent=None,name=None,modal=0,fl=0,file=addrfile,observer=None,ga=None): - ## if GQ_DEBUG: logging.debug("\n>>>>>>>> Class: %s" % self.__class__.__name__) - ## FormAddressEdit.__init__(self,parent,name,modal,fl) - ## self.parent = parent - ## self.parent_observer = observer - ## self.entry = entry - ## self.ga = ga - ## name, email, notes,self.id = entry.text(0),entry.text(1),entry.text(2),entry.text(3) - ## if GQ_DEBUG: logging.debug("received entry: %s %s %s %s" % (name,email,notes,self.id)) - ## self.lineEditName.setText(name) - ## self.lineEditEmail.setText(email) - ## self.textEditNotes.setText(notes) - ## self.show() - ## - ## def pushButtonOk_clicked(self): - ## print "FormAddressEdit.pushButtonOk_clicked(): Not implemented yet" - ## self.entry.repaint()#update the entry in the view - ## name = str(self.lineEditName.text()) - ## email = str(self.lineEditEmail.text()) - ## notes = str(self.textEditNotes.text()) - ## Gmail.store_address(addrfile,name,email,notes,id=self.id,ga=self.ga) - ## - ## def pushButtonCancel_clicked(self): - ## self.done(1) - --- 455,456 ---- Index: MainWin_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/MainWin_forms.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** MainWin_forms.py 8 Jun 2005 12:28:17 -0000 1.26 --- MainWin_forms.py 14 Sep 2005 11:36:28 -0000 1.27 *************** *** 3,7 **** # Form implementation generated from reading ui file 'MainWin.ui' # ! # Created: Mon Jun 6 20:34:32 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'MainWin.ui' # ! # Created: Mon Aug 15 12:50:15 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # Index: HelpDialog_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/HelpDialog_forms.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** HelpDialog_forms.py 8 Jun 2005 12:28:17 -0000 1.12 --- HelpDialog_forms.py 14 Sep 2005 11:36:28 -0000 1.13 *************** *** 3,7 **** # Form implementation generated from reading ui file 'HelpDialog.ui' # ! # Created: Mon Jun 6 20:34:33 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'HelpDialog.ui' # ! # Created: Mon Aug 15 12:50:15 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # Index: AboutDialog_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/AboutDialog_forms.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** AboutDialog_forms.py 8 Jun 2005 12:28:17 -0000 1.23 --- AboutDialog_forms.py 14 Sep 2005 11:36:28 -0000 1.24 *************** *** 3,7 **** # Form implementation generated from reading ui file 'AboutDialog.ui' # ! # Created: Mon Jun 6 20:34:33 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'AboutDialog.ui' # ! # Created: Mon Aug 15 12:50:15 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # Index: LoginDialog_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/LoginDialog_forms.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** LoginDialog_forms.py 8 Jun 2005 12:28:17 -0000 1.26 --- LoginDialog_forms.py 14 Sep 2005 11:36:28 -0000 1.27 *************** *** 3,7 **** # Form implementation generated from reading ui file 'LoginDialog.ui' # ! # Created: Mon Jun 6 20:34:33 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'LoginDialog.ui' # ! # Created: Mon Aug 15 12:50:15 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # Index: GmailAgent.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/GmailAgent.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GmailAgent.py 14 Jun 2005 14:17:31 -0000 1.16 --- GmailAgent.py 14 Sep 2005 11:36:28 -0000 1.17 *************** *** 31,35 **** try: logging.basicConfig(level=logging.DEBUG,\ ! format='GmailAgent:%(module)s,%(lineno)d; %(levelname)s %(message)s') except TypeError: # Python <=2.3? --- 31,35 ---- try: logging.basicConfig(level=logging.DEBUG,\ ! format='\nGmailAgent:%(module)s,%(lineno)d; %(levelname)s %(message)s') except TypeError: # Python <=2.3? Index: setup.py =================================================================== RCS file: /cvsroot/gmailagent/GA-main/setup.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** setup.py 26 May 2005 06:23:29 -0000 1.5 --- setup.py 14 Sep 2005 11:36:28 -0000 1.6 *************** *** 10,13 **** --- 10,24 ---- execpath = '/usr/local/bin/gmailagent' + import sys + # check for libgmail + try: + import libgmail + except ImportError,info: + print "******* ERROR ******" + print info + print "GmailAgent depends on libgmail which is not installed." + print "See http://libgmail.sf.net" + sys.exit(1) + import version DESCRIPTION = """GmailAgent is a application that acts as a email client and can be used by programs *************** *** 31,35 **** #get us to the correct directory ! import os, sys path = os.path.split(os.path.abspath(sys.argv[0]))[0] os.chdir(path) --- 42,46 ---- #get us to the correct directory ! import os path = os.path.split(os.path.abspath(sys.argv[0]))[0] os.chdir(path) *************** *** 123,127 **** print "=========== Installation Ok ================" ! print "\nThe GmailAgent executable is installed in\n %s" % os.path.dirname(execpath) print "You should read the README file that came with this package\nfor possible usage" --- 134,138 ---- print "=========== Installation Ok ================" ! print "\nThe GmailAgent executable is %s" % execpath print "You should read the README file that came with this package\nfor possible usage" Index: TODO =================================================================== RCS file: /cvsroot/gmailagent/GA-main/TODO,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TODO 10 Jun 2005 09:22:07 -0000 1.13 --- TODO 14 Sep 2005 11:36:28 -0000 1.14 *************** *** 5,16 **** Perhaps copy the first message and add 'part #' to the subject line ? ! Make sure we remove old addressbook files when installing ! new vesrions. ! ! New addressbook ! Add button callbacks ! Check if the logic is sound and we don't loose contacts ! ! Contacts stuff still sucks (local) Make sure any progressdialogs are closed when a cancel button is pressed. --- 5,9 ---- Perhaps copy the first message and add 'part #' to the subject line ? ! Check if the logic is sound and we don't loose contacts Make sure any progressdialogs are closed when a cancel button is pressed. |