[haiku-commits] haiku: hrev43664 - src/apps/mail

  • From: zharik@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 15 Jan 2012 20:57:51 +0100 (CET)

hrev43664 adds 1 changeset to branch 'master'
old head: db3aecc840859422235847724d08986a3b676959
new head: 7df4b41328242918b7201d12d80a7fbc7f1e025e

----------------------------------------------------------------------------

7df4b41: Improve the auto-signature insertion algorithm
  
  * Append the signature only after the e-mail Reader thread will finish
    it's work. This prevent from inserting the signature in wrong place;
  * Added extra lines between original e-mail quote and the signature for
    more comfortable editing of replies.
  * This fix was made during GCI2011;
  * This fixes #4590.
  
  Signed-off-by: Siarzhuk Zharski <zharik@xxxxxx>

                             [ Aleksas Pantechovskis <alexp.frl@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev43664
Commit:      7df4b41328242918b7201d12d80a7fbc7f1e025e
URL:         http://cgit.haiku-os.org/haiku/commit/?id=7df4b41
Author:      Aleksas Pantechovskis <alexp.frl@xxxxxxxxx>
Date:        Sun Jan 15 19:48:06 2012 UTC
Committer:   Siarzhuk Zharski <zharik@xxxxxx>
Commit-Date: Sun Jan 15 19:54:21 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/4590

----------------------------------------------------------------------------

3 files changed, 38 insertions(+), 21 deletions(-)
src/apps/mail/Content.cpp    |   39 ++++++++++++++++++++++++++++++-------
src/apps/mail/Content.h      |    1 +
src/apps/mail/MailWindow.cpp |   19 +++++------------

----------------------------------------------------------------------------

diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp
index b0c90c6..28a3687 100644
--- a/src/apps/mail/Content.cpp
+++ b/src/apps/mail/Content.cpp
@@ -702,6 +702,13 @@ TContentView::MessageReceived(BMessage *msg)
 
                case M_SIGNATURE:
                {
+                       if (fTextView->IsReaderThreadRunning()) {
+                               // Do not add the signature until the reader 
thread
+                               // is finished. Resubmit the message for later 
processing
+                               Window()->PostMessage(msg);
+                               break;
+                       }
+
                        entry_ref ref;
                        msg->FindRef("ref", &ref);
 
@@ -727,21 +734,23 @@ TContentView::MessageReceived(BMessage *msg)
                                const char *text = fTextView->Text();
                                int32 length = fTextView->TextLength();
 
-                               if (length && text[length - 1] != '\n') {
-                                       fTextView->Select(length, length);
-
-                                       char newLine = '\n';
-                                       fTextView->Insert(&newLine, 1);
+                               // reserve some empty lines before the signature
+                               const char* newLines = "\n\n\n\n";
+                               if (length && text[length - 1] == '\n')
+                                       newLines++;
 
-                                       length++;
-                               }
+                               fTextView->Select(length, length);
+                               fTextView->Insert(newLines, strlen(newLines));
+                               length += strlen(newLines);
 
+                               // append the signature
                                fTextView->Select(length, length);
                                fTextView->Insert(signature, bytesRead);
                                fTextView->Select(length, length + bytesRead);
                                fTextView->ScrollToSelection();
 
-                               fTextView->Select(start, finish);
+                               // set the editing cursor position
+                               fTextView->Select(length - 2 , length - 2);
                                fTextView->ScrollToSelection();
                                free (signature);
                        } else {
@@ -2086,6 +2095,20 @@ TTextView::StopLoad()
 }
 
 
+bool
+TTextView::IsReaderThreadRunning()
+{
+       if (fThread == 0)
+               return false;
+
+       thread_info info;
+       for (int i = 5; i > 0; i--, usleep(100000))
+               if (get_thread_info(fThread, &info) != B_OK)
+                       return false;
+       return true;
+}
+
+
 void
 TTextView::AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, 
mail_encoding encoding)
 {
diff --git a/src/apps/mail/Content.h b/src/apps/mail/Content.h
index 7317b43..703e986 100644
--- a/src/apps/mail/Content.h
+++ b/src/apps/mail/Content.h
@@ -168,6 +168,7 @@ class TTextView : public BTextView {
                void Open(hyper_text*);
                status_t Save(BMessage *, bool makeNewFile = true);
                void StopLoad();
+               bool IsReaderThreadRunning();
                void AddAsContent(BEmailMessage *mail, bool wrap, uint32 
charset, mail_encoding encoding);
                void CheckSpelling(int32 start, int32 end,
                        int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS);
diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp
index 43a996b..399a1d3 100644
--- a/src/apps/mail/MailWindow.cpp
+++ b/src/apps/mail/MailWindow.cpp
@@ -534,22 +534,15 @@ TMailWindow::TMailWindow(BRect rect, const char* title, 
TMailApp* app,
                        // If we find the named query, add it to the text.
                        BEntry entry;
                        if (query.GetNextEntry(&entry) == B_NO_ERROR) {
-                               off_t size;
                                BFile file;
                                file.SetTo(&entry, O_RDWR);
                                if (file.InitCheck() == B_NO_ERROR) {
-                                       file.GetSize(&size);
-                                       char *str = (char *)malloc(size);
-                                       size = file.Read(str, size);
-
-                                       fContentView->fTextView->Insert(str, 
size);
-                                       fContentView->fTextView->GoToLine(0);
-                                       
fContentView->fTextView->ScrollToSelection();
-
-                                       fStartingText = (char *)malloc(size
-                                               = 
strlen(fContentView->fTextView->Text()) + 1);
-                                       if (fStartingText != NULL)
-                                               strcpy(fStartingText, 
fContentView->fTextView->Text());
+                                       entry_ref ref;
+                                       entry.GetRef(&ref);
+
+                                       BMessage msg(M_SIGNATURE);
+                                       msg.AddRef("ref", &ref);
+                                       PostMessage(&msg);
                                }
                        } else {
                                char tempString [2048];


Other related posts:

  • » [haiku-commits] haiku: hrev43664 - src/apps/mail - zharik