From d773c5bf4c484fb21a244b9a2fae240bc6160204 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Mon, 21 Feb 2011 09:52:41 +0000 Subject: [PATCH] If not in "mark automatically as read" mode mark the mail as seen. Fix selection of this option in the preference window. Fix some read/unread bugs. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40595 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/mail/E-mail.h | 1 + headers/private/mail/mail_util.h | 1 + src/apps/mail/MailWindow.cpp | 77 +++++++++++++++----------------- src/apps/mail/MailWindow.h | 3 +- src/apps/mail/Prefs.cpp | 2 +- src/kits/mail/mail_util.cpp | 31 ++++++++++--- 6 files changed, 67 insertions(+), 48 deletions(-) diff --git a/headers/os/mail/E-mail.h b/headers/os/mail/E-mail.h index 72662586c4..d3c024450c 100644 --- a/headers/os/mail/E-mail.h +++ b/headers/os/mail/E-mail.h @@ -30,6 +30,7 @@ struct entry_ref; #define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32 #define B_MAIL_ATTR_READ "MAIL:read" // int32 +#define R5_COMPATIBLE 1 // read flags enum read_flags { diff --git a/headers/private/mail/mail_util.h b/headers/private/mail/mail_util.h index df94e1a006..293bb4a9da 100644 --- a/headers/private/mail/mail_util.h +++ b/headers/private/mail/mail_util.h @@ -17,6 +17,7 @@ class BString; status_t write_read_attr(BNode& node, read_flags flag); +status_t read_read_attr(BNode& node, read_flags& flag); // The next couple of functions are our wrapper around convert_to_utf8 and diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index 029c20c28a..de1ec47ee6 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -652,9 +652,8 @@ TMailWindow::BuildButtonBar() fNextButton = bbar->AddButton(B_TRANSLATE("Next"), 24, new BMessage(M_NEXTMSG)); bbar->AddButton(B_TRANSLATE("Previous"), 20, new BMessage(M_PREVMSG)); - if (!fAutoMarkRead) { + if (!fAutoMarkRead) _AddReadButton(); - } } bbar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -832,7 +831,7 @@ TMailWindow::SetTrackerSelectionToCurrent() void -TMailWindow::SetCurrentMessageRead(bool read) +TMailWindow::SetCurrentMessageRead(read_flags flag) { BNode node(fRef); status_t status = node.InitCheck(); @@ -844,21 +843,10 @@ TMailWindow::SetCurrentMessageRead(bool read) sizeof(account)) < 0) account = -1; - BString mailStatus; - status = ReadAttrString(&node, B_MAIL_ATTR_STATUS, &mailStatus); - if (status != B_OK) - return; + // don't wait for the server write the attribute directly + write_read_attr(node, flag); - if (read && !mailStatus.ICompare("New")) { - node.RemoveAttr(B_MAIL_ATTR_STATUS); - WriteAttrString(&node, B_MAIL_ATTR_STATUS, "Read"); - BMailDaemon::MarkAsRead(account, *fRef, B_READ); - } - if (!read && !mailStatus.ICompare("Read")) { - node.RemoveAttr(B_MAIL_ATTR_STATUS); - WriteAttrString(&node, B_MAIL_ATTR_STATUS, "New"); - BMailDaemon::MarkAsRead(account, *fRef, B_UNREAD); - } + BMailDaemon::MarkAsRead(account, *fRef, flag); } @@ -965,6 +953,7 @@ TMailWindow::MenusBeginning() void TMailWindow::MessageReceived(BMessage *msg) { + bool wasReadMsg = false; switch (msg->what) { case FIELD_CHANGED: { @@ -1155,8 +1144,10 @@ TMailWindow::MessageReceived(BMessage *msg) foundRef = GetTrackerWindowFile(&nextRef, msg->what == M_DELETE_NEXT); } - if (fIncoming && fAutoMarkRead) - SetCurrentMessageRead(); + if (fIncoming) { + read_flags flag = (fAutoMarkRead == true) ? B_READ : B_SEEN; + SetCurrentMessageRead(flag); + } if (!fTrackerMessenger.IsValid() || !fIncoming) { // Not associated with a tracker window. Create a new @@ -1494,11 +1485,13 @@ TMailWindow::MessageReceived(BMessage *msg) // Navigation Messages // case M_UNREAD: - SetCurrentMessageRead(false); + SetCurrentMessageRead(B_SEEN); _UpdateReadButton(); break; case M_READ: - SetCurrentMessageRead(); + wasReadMsg = true; + SetCurrentMessageRead(B_READ); + _UpdateReadButton(); msg->what = M_NEXTMSG; case M_PREVMSG: case M_NEXTMSG: @@ -1508,8 +1501,15 @@ TMailWindow::MessageReceived(BMessage *msg) TMailWindow *window = static_cast(be_app) ->FindWindow(nextRef); if (window == NULL) { - if (fAutoMarkRead) - SetCurrentMessageRead(); + BNode node(fRef); + read_flags currentFlag; + if (read_read_attr(node, currentFlag) != B_OK) + currentFlag = B_UNREAD; + if (fAutoMarkRead == true) + SetCurrentMessageRead(B_READ); + else if (currentFlag != B_READ && !wasReadMsg) + SetCurrentMessageRead(B_SEEN); + OpenMessage(&nextRef, fHeaderView->fCharacterSetUserSees, msg); } else { @@ -1732,8 +1732,8 @@ TMailWindow::QuitRequested() } } else if (fRef != NULL && !sKeepStatusOnQuit) { // ...Otherwise just set the message read - if (fAutoMarkRead) - SetCurrentMessageRead(); + read_flags flag = (fAutoMarkRead == true) ? B_READ : B_SEEN; + SetCurrentMessageRead(flag); } BPrivate::BPathMonitor::StopWatching(BMessenger(this, this)); @@ -3187,23 +3187,19 @@ TMailWindow::_BuildQueryString(BEntry* entry) const void TMailWindow::_AddReadButton() { - bool newMail = false; BNode node(fRef); - if (node.InitCheck() == B_NO_ERROR) { - BString status; - if (ReadAttrString(&node, B_MAIL_ATTR_STATUS, &status) == B_NO_ERROR - && !status.ICompare("New")) { - newMail = true; - } - } + + read_flags flag = B_UNREAD; + read_read_attr(node, flag); int32 buttonIndex = fButtonBar->IndexOf(fNextButton); - if (newMail) - fReadButton = fButtonBar->AddButton( - B_TRANSLATE(" Read "), 24, new BMessage(M_READ), buttonIndex); - else - fReadButton = fButtonBar->AddButton( - B_TRANSLATE("Unread"), 28, new BMessage(M_UNREAD), buttonIndex); + if (flag == B_READ) { + fReadButton = fButtonBar->AddButton(B_TRANSLATE("Unread"), 28, + new BMessage(M_UNREAD), buttonIndex); + } else { + fReadButton = fButtonBar->AddButton(B_TRANSLATE(" Read "), 24, + new BMessage(M_READ), buttonIndex); + } } @@ -3213,9 +3209,8 @@ TMailWindow::_UpdateReadButton() if (fApp->ShowButtonBar()) { fButtonBar->RemoveButton(fReadButton); fReadButton = NULL; - if (!fAutoMarkRead && !fReadButton) { + if (!fAutoMarkRead) _AddReadButton(); - } } UpdateViews(); } diff --git a/src/apps/mail/MailWindow.h b/src/apps/mail/MailWindow.h index c17b2da111..30c81b071d 100644 --- a/src/apps/mail/MailWindow.h +++ b/src/apps/mail/MailWindow.h @@ -42,6 +42,7 @@ All rights reserved. #include #include +#include #include @@ -108,7 +109,7 @@ class TMailWindow : public BWindow { void SaveTrackerPosition(entry_ref*); void SetOriginatingWindow(BWindow* window); - void SetCurrentMessageRead(bool read = true); + void SetCurrentMessageRead(read_flags flag); void SetTrackerSelectionToCurrent(); TMailWindow* FrontmostWindow(); void UpdateViews(); diff --git a/src/apps/mail/Prefs.cpp b/src/apps/mail/Prefs.cpp index 7afcdf5ee8..f6754e0daf 100644 --- a/src/apps/mail/Prefs.cpp +++ b/src/apps/mail/Prefs.cpp @@ -140,7 +140,7 @@ TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap, fSpellCheckStartOn(*fNewSpellCheckStartOn), fNewAutoMarkRead(autoMarkRead), - fAutoMarkRead(true) + fAutoMarkRead(*autoMarkRead) { strcpy(fSignature, *fNewSignature); diff --git a/src/kits/mail/mail_util.cpp b/src/kits/mail/mail_util.cpp index 7f452f4ec3..72d6e36fbf 100644 --- a/src/kits/mail/mail_util.cpp +++ b/src/kits/mail/mail_util.cpp @@ -93,18 +93,39 @@ write_read_attr(BNode& node, read_flags flag) < 0) return B_ERROR; - if (flag == B_SEEN) - return B_OK; - - const char* statusString = (flag == B_READ) ? "Read" : "New"; +#if R5_COMPATIBLE + const char* statusString = (flag == B_READ) ? "Read" + : (flag == B_SEEN) ? "Seen" : "New"; if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString, strlen(statusString)) < 0) return B_ERROR; - +#endif return B_OK; } +status_t +read_read_attr(BNode& node, read_flags& flag) +{ + if (node.ReadAttr(B_MAIL_ATTR_READ, B_INT32_TYPE, 0, &flag, sizeof(int32)) + == sizeof(int32)) + return B_OK; + +#if R5_COMPATIBLE + BString statusString; + if (node.ReadAttrString(B_MAIL_ATTR_STATUS, &statusString) == B_OK) { + if (statusString.ICompare("New")) + flag = B_UNREAD; + else + flag = B_READ; + + return B_OK; + } +#endif + return B_ERROR; +} + + // The next couple of functions are our wrapper around convert_to_utf8 and // convert_from_utf8 so that they can also convert from UTF-8 to UTF-8 by // specifying the B_MAIL_UTF8_CONVERSION constant as the conversion operation. It