Author: kirilla Date: 2011-04-01 04:07:48 +0200 (Fri, 01 Apr 2011) New Revision: 41158 Changeset: https://dev.haiku-os.org/changeset/41158 Ticket: https://dev.haiku-os.org/ticket/6721 Modified: haiku/trunk/src/apps/mail/MailApp.cpp haiku/trunk/src/apps/mail/MailWindow.cpp haiku/trunk/src/apps/mail/Prefs.cpp Log: Workaround for ticket #6721 by using %b (line break) instead of \n for newline. (I looked into the string escaping issue in the locale kit and it appears to work as expected, so I don't know.) Simplification of some code. Addition of a default reply preamble. The name variable now results in just the name. Removal of commented out First/Last name variables, as the order of these is culture-dependent. Insert at point of selection. Modified: haiku/trunk/src/apps/mail/MailApp.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailApp.cpp 2011-03-31 21:58:06 UTC (rev 41157) +++ haiku/trunk/src/apps/mail/MailApp.cpp 2011-04-01 02:07:48 UTC (rev 41158) @@ -122,8 +122,7 @@ fAutoMarkRead = true; fSignature = (char*)malloc(strlen(B_TRANSLATE("None")) + 1); strcpy(fSignature, B_TRANSLATE("None")); - fReplyPreamble = (char*)malloc(1); - fReplyPreamble[0] = '\0'; + fReplyPreamble = strdup(B_TRANSLATE("%e wrote:%b")); fMailWindowFrame.Set(0, 0, 0, 0); fSignatureWindowFrame.Set(6, TITLE_BAR_HEIGHT, 6 + kSigWidth, Modified: haiku/trunk/src/apps/mail/MailWindow.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailWindow.cpp 2011-03-31 21:58:06 UTC (rev 41157) +++ haiku/trunk/src/apps/mail/MailWindow.cpp 2011-04-01 02:07:48 UTC (rev 41158) @@ -2053,8 +2053,6 @@ void TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type) { - const char *notImplementedString = "<Not Yet Implemented>"; - fRepliedMail = *ref; SetOriginatingWindow(window); @@ -2105,80 +2103,28 @@ // create preamble string - BString replyPreamble = fApp->ReplyPreamble(); + BString preamble = fApp->ReplyPreamble(); - char preamble[1024]; - const char* from = replyPreamble.String(); - char* to = preamble; + BString name; + mail->GetName(&name); + if (name.Length() <= 0) + name = B_TRANSLATE("(Name unavailable)"); - while (*from) { - if (*from == '%') { - // insert special content - int32 length; + BString address(mail->From()); + if (address.Length() <= 0) + address = B_TRANSLATE("(Address unavailable)"); - switch (*++from) { - case 'n': // full name - { - BString fullName(mail->From()); - if (fullName.Length() <= 0) - fullName = "No-From-Address-Available"; + BString date(mail->Date()); + if (date.Length() <= 0) + date = B_TRANSLATE("(Date unavailable)"); + + preamble.ReplaceAll("%n", name); + preamble.ReplaceAll("%e", address); + preamble.ReplaceAll("%d", date); + preamble.ReplaceAll("%b", "\n"); + preamble.ReplaceAll("\\n", "\n"); + // backwards compatability with older settings - extract_address_name(fullName); - length = fullName.Length(); - memcpy(to, fullName.String(), length); - to += length; - break; - } - - case 'e': // eMail address - { - const char *address = mail->From(); - if (address == NULL) - address = "<unknown>"; - length = strlen(address); - memcpy(to, address, length); - to += length; - break; - } - - case 'd': // date - { - const char *date = mail->Date(); - if (date == NULL) - date = "No-Date-Available"; - length = strlen(date); - memcpy(to, date, length); - to += length; - break; - } - - // ToDo: parse stuff! - case 'f': // first name - case 'l': // last name - length = strlen(notImplementedString); - memcpy(to, notImplementedString, length); - to += length; - break; - - default: // Sometimes a % is just a %. - *to++ = *from; - } - } else if (*from == '\\') { - switch (*++from) { - case 'n': - *to++ = '\n'; - break; - - default: - *to++ = *from; - } - } else - *to++ = *from; - - from++; - } - *to = '\0'; - // insert (if selection) or load (if whole mail) message text into text view int32 finish, start; @@ -2216,7 +2162,7 @@ } fContentView->fTextView->GoToLine(0); - if (strlen(preamble) > 0) + if (preamble.Length() > 0) fContentView->fTextView->Insert(preamble); } else { fContentView->fTextView->LoadMessage(mail, true, preamble); Modified: haiku/trunk/src/apps/mail/Prefs.cpp =================================================================== --- haiku/trunk/src/apps/mail/Prefs.cpp 2011-03-31 21:58:06 UTC (rev 41157) +++ haiku/trunk/src/apps/mail/Prefs.cpp 2011-04-01 02:07:48 UTC (rev 41158) @@ -484,8 +484,12 @@ } BTextView *text = fReplyPreamble->TextView(); - // To do: insert at selection point rather than at the end. - text->Insert(text->TextLength(), item->Label(), 2); + int32 selectionStart; + int32 selectionEnd; + text->GetSelection(&selectionStart, &selectionEnd); + if (selectionStart != selectionEnd) + text->Delete(selectionStart, selectionEnd); + text->Insert(item->Label(), 2); } case P_SIG: free(*fNewSignature); @@ -677,30 +681,22 @@ BMenu* TPrefsWindow::_BuildReplyPreambleMenu() { - const char *substitutes[] = { -/* To do: Not yet working, leave out for 2.0.0 beta 4: - "%f - First name", - "%l - Last name", -*/ - B_TRANSLATE("%n - Full name"), - B_TRANSLATE("%e - E-mail address"), - B_TRANSLATE("%d - Date"), - "", - B_TRANSLATE("\\n - Newline"), - NULL - }; - BMenu *menu = new BMenu(B_EMPTY_STRING); - for (int32 i = 0; substitutes[i]; i++) { - if (*substitutes[i] == '\0') { - menu->AddSeparatorItem(); - } else { - menu->AddItem(new BMenuItem(substitutes[i], - new BMessage(P_REPLY_PREAMBLE))); - } - } + menu->AddItem(new BMenuItem(B_TRANSLATE("%n - Full name"), + new BMessage(P_REPLY_PREAMBLE))); + menu->AddItem(new BMenuItem(B_TRANSLATE("%e - E-mail address"), + new BMessage(P_REPLY_PREAMBLE))); + + menu->AddItem(new BMenuItem(B_TRANSLATE("%d - Date"), + new BMessage(P_REPLY_PREAMBLE))); + + menu->AddSeparatorItem(); + + menu->AddItem(new BMenuItem(B_TRANSLATE("%b - Line break"), + new BMessage(P_REPLY_PREAMBLE))); + return menu; }