UI/EmailDialog.py

changeset 6828
bb6667ea9ae7
parent 6825
e659bb96cdfa
child 6834
ae1e7530c854
--- a/UI/EmailDialog.py	Sat Mar 02 11:12:25 2019 +0100
+++ b/UI/EmailDialog.py	Sat Mar 02 17:33:58 2019 +0100
@@ -60,6 +60,7 @@
 
 encoders.encode_base64 = _encode_base64
 # WORK AROUND: implement our corrected encoder
+# TODO: check, if this work-around is still needed
 
 
 class EmailDialog(QDialog, Ui_EmailDialog):
@@ -123,6 +124,7 @@
         self.__deleteFiles = []
         
         self.__helpDialog = None
+        self.__googleMail = None
     
     def keyPressEvent(self, ev):
         """
@@ -170,10 +172,11 @@
                 from E5Network.E5GoogleMail import GoogleMailHelp
                 helpStr = GoogleMailHelp()
             except ImportError:
+                from E5Network.E5GoogleMailHelpers import getInstallCommand
                 helpStr = self.tr(
                     "<p>The Google Mail Client API is not installed."
-                    " Use <code>pip install --upgrade google-api-python-client"
-                    " google-auth-oauthlib</code> to install it.</p>")
+                    " Use <code>{0}</code> to install it.</p>"
+                ).format(getInstallCommand())
             
             from E5Gui.E5SimpleHelpDialog import E5SimpleHelpDialog
             self.__helpDialog = E5SimpleHelpDialog(
@@ -193,18 +196,23 @@
             msg = self.__createSimpleMail()
         
         if Preferences.getUser("UseGoogleMailOAuth2"):
-            ok = self.__sendmailGoogle(msg)
+            self.__sendmailGoogle(msg)
         else:
             ok = self.__sendmail(msg.as_string())
-        
-        if ok:
-            for f in self.__deleteFiles:
-                try:
-                    os.remove(f)
-                except OSError:
-                    pass
-            self.accept()
-        
+            if ok:
+                self.__deleteAttachedFiles()
+                self.accept()
+    
+    def __deleteAttachedFiles(self):
+        """
+        Private method to delete attached files.
+        """
+        for f in self.__deleteFiles:
+            try:
+                os.remove(f)
+            except OSError:
+                pass
+    
     def __encodedText(self, txt):
         """
         Private method to create a MIMEText message with correct encoding.
@@ -401,25 +409,38 @@
         
         @param msg email message to be sent
         @type email.mime.text.MIMEBase
-        @return flag indicating success
-        @rtype bool
+        """
+        from E5Network.E5GoogleMail import E5GoogleMail
+        
+        if self.__googleMail is None:
+            self.__googleMail = E5GoogleMail(self)
+            self.__googleMail.sendResult.connect(self.__gmailSendResult)
+        
+        self.__googleMail.sendMessage(msg)
+    
+    @pyqtSlot(bool, str)
+    def __gmailSendResult(self, ok, message):
         """
-        from E5Network.E5GoogleMail import GoogleMailSendMessage
-        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
-        QApplication.processEvents()
-        ok, result = GoogleMailSendMessage(msg)
-        QApplication.restoreOverrideCursor()
-        if not ok:
+        Private slot handling the send result reported by the Google Mail
+        interface.
+        
+        @param ok flag indicating success
+        @type bool
+        @param message message from the interface
+        @type str
+        """
+        if ok:
+            self.__deleteAttachedFiles()
+            self.accept()
+        else:
             # we got an error
             E5MessageBox.critical(
                 self,
-                self.tr("Send Message"),
+                self.tr("Send Message via Gmail"),
                 self.tr(
                     """<p>Message could not be sent.<br>Reason: {0}</p>""")
-                .format(result)
+                .format(message)
             )
-        
-        return ok
     
     @pyqtSlot()
     def on_addButton_clicked(self):

eric ide

mercurial