Author: czeidler Date: 2011-02-21 10:52:41 +0100 (Mon, 21 Feb 2011) New Revision: 40595 Changeset: http://dev.haiku-os.org/changeset/40595 Modified: haiku/trunk/headers/os/mail/E-mail.h haiku/trunk/headers/private/mail/mail_util.h haiku/trunk/src/apps/mail/MailWindow.cpp haiku/trunk/src/apps/mail/MailWindow.h haiku/trunk/src/apps/mail/Prefs.cpp haiku/trunk/src/kits/mail/mail_util.cpp Log: 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. Modified: haiku/trunk/headers/os/mail/E-mail.h =================================================================== --- haiku/trunk/headers/os/mail/E-mail.h 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/headers/os/mail/E-mail.h 2011-02-21 09:52:41 UTC (rev 40595) @@ -30,6 +30,7 @@ #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 { Modified: haiku/trunk/headers/private/mail/mail_util.h =================================================================== --- haiku/trunk/headers/private/mail/mail_util.h 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/headers/private/mail/mail_util.h 2011-02-21 09:52:41 UTC (rev 40595) @@ -17,6 +17,7 @@ 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 Modified: haiku/trunk/src/apps/mail/MailWindow.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailWindow.cpp 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/src/apps/mail/MailWindow.cpp 2011-02-21 09:52:41 UTC (rev 40595) @@ -652,9 +652,8 @@ 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 @@ void -TMailWindow::SetCurrentMessageRead(bool read) +TMailWindow::SetCurrentMessageRead(read_flags flag) { BNode node(fRef); status_t status = node.InitCheck(); @@ -844,21 +843,10 @@ 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 @@ void TMailWindow::MessageReceived(BMessage *msg) { + bool wasReadMsg = false; switch (msg->what) { case FIELD_CHANGED: { @@ -1155,8 +1144,10 @@ 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 @@ // 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 *window = static_cast<TMailApp *>(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 @@ } } 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 @@ 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 @@ if (fApp->ShowButtonBar()) { fButtonBar->RemoveButton(fReadButton); fReadButton = NULL; - if (!fAutoMarkRead && !fReadButton) { + if (!fAutoMarkRead) _AddReadButton(); - } } UpdateViews(); } Modified: haiku/trunk/src/apps/mail/MailWindow.h =================================================================== --- haiku/trunk/src/apps/mail/MailWindow.h 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/src/apps/mail/MailWindow.h 2011-02-21 09:52:41 UTC (rev 40595) @@ -42,6 +42,7 @@ #include <Messenger.h> #include <Window.h> +#include <E-mail.h> #include <mail_encoding.h> @@ -108,7 +109,7 @@ void SaveTrackerPosition(entry_ref*); void SetOriginatingWindow(BWindow* window); - void SetCurrentMessageRead(bool read = true); + void SetCurrentMessageRead(read_flags flag); void SetTrackerSelectionToCurrent(); TMailWindow* FrontmostWindow(); void UpdateViews(); Modified: haiku/trunk/src/apps/mail/Prefs.cpp =================================================================== --- haiku/trunk/src/apps/mail/Prefs.cpp 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/src/apps/mail/Prefs.cpp 2011-02-21 09:52:41 UTC (rev 40595) @@ -140,7 +140,7 @@ fSpellCheckStartOn(*fNewSpellCheckStartOn), fNewAutoMarkRead(autoMarkRead), - fAutoMarkRead(true) + fAutoMarkRead(*autoMarkRead) { strcpy(fSignature, *fNewSignature); Modified: haiku/trunk/src/kits/mail/mail_util.cpp =================================================================== --- haiku/trunk/src/kits/mail/mail_util.cpp 2011-02-21 08:47:43 UTC (rev 40594) +++ haiku/trunk/src/kits/mail/mail_util.cpp 2011-02-21 09:52:41 UTC (rev 40595) @@ -93,18 +93,39 @@ < 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