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
This commit is contained in:
Clemens Zeidler
2011-02-21 09:52:41 +00:00
parent 8fbb452a31
commit d773c5bf4c
6 changed files with 67 additions and 48 deletions
+1
View File
@@ -30,6 +30,7 @@ struct entry_ref;
#define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32 #define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32
#define B_MAIL_ATTR_READ "MAIL:read" // int32 #define B_MAIL_ATTR_READ "MAIL:read" // int32
#define R5_COMPATIBLE 1
// read flags // read flags
enum read_flags { enum read_flags {
+1
View File
@@ -17,6 +17,7 @@ class BString;
status_t write_read_attr(BNode& node, read_flags flag); 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 // The next couple of functions are our wrapper around convert_to_utf8 and
+36 -41
View File
@@ -652,9 +652,8 @@ TMailWindow::BuildButtonBar()
fNextButton = bbar->AddButton(B_TRANSLATE("Next"), 24, fNextButton = bbar->AddButton(B_TRANSLATE("Next"), 24,
new BMessage(M_NEXTMSG)); new BMessage(M_NEXTMSG));
bbar->AddButton(B_TRANSLATE("Previous"), 20, new BMessage(M_PREVMSG)); bbar->AddButton(B_TRANSLATE("Previous"), 20, new BMessage(M_PREVMSG));
if (!fAutoMarkRead) { if (!fAutoMarkRead)
_AddReadButton(); _AddReadButton();
}
} }
bbar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); bbar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -832,7 +831,7 @@ TMailWindow::SetTrackerSelectionToCurrent()
void void
TMailWindow::SetCurrentMessageRead(bool read) TMailWindow::SetCurrentMessageRead(read_flags flag)
{ {
BNode node(fRef); BNode node(fRef);
status_t status = node.InitCheck(); status_t status = node.InitCheck();
@@ -844,21 +843,10 @@ TMailWindow::SetCurrentMessageRead(bool read)
sizeof(account)) < 0) sizeof(account)) < 0)
account = -1; account = -1;
BString mailStatus; // don't wait for the server write the attribute directly
status = ReadAttrString(&node, B_MAIL_ATTR_STATUS, &mailStatus); write_read_attr(node, flag);
if (status != B_OK)
return;
if (read && !mailStatus.ICompare("New")) { BMailDaemon::MarkAsRead(account, *fRef, flag);
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);
}
} }
@@ -965,6 +953,7 @@ TMailWindow::MenusBeginning()
void void
TMailWindow::MessageReceived(BMessage *msg) TMailWindow::MessageReceived(BMessage *msg)
{ {
bool wasReadMsg = false;
switch (msg->what) { switch (msg->what) {
case FIELD_CHANGED: case FIELD_CHANGED:
{ {
@@ -1155,8 +1144,10 @@ TMailWindow::MessageReceived(BMessage *msg)
foundRef = GetTrackerWindowFile(&nextRef, foundRef = GetTrackerWindowFile(&nextRef,
msg->what == M_DELETE_NEXT); msg->what == M_DELETE_NEXT);
} }
if (fIncoming && fAutoMarkRead) if (fIncoming) {
SetCurrentMessageRead(); read_flags flag = (fAutoMarkRead == true) ? B_READ : B_SEEN;
SetCurrentMessageRead(flag);
}
if (!fTrackerMessenger.IsValid() || !fIncoming) { if (!fTrackerMessenger.IsValid() || !fIncoming) {
// Not associated with a tracker window. Create a new // Not associated with a tracker window. Create a new
@@ -1494,11 +1485,13 @@ TMailWindow::MessageReceived(BMessage *msg)
// Navigation Messages // Navigation Messages
// //
case M_UNREAD: case M_UNREAD:
SetCurrentMessageRead(false); SetCurrentMessageRead(B_SEEN);
_UpdateReadButton(); _UpdateReadButton();
break; break;
case M_READ: case M_READ:
SetCurrentMessageRead(); wasReadMsg = true;
SetCurrentMessageRead(B_READ);
_UpdateReadButton();
msg->what = M_NEXTMSG; msg->what = M_NEXTMSG;
case M_PREVMSG: case M_PREVMSG:
case M_NEXTMSG: case M_NEXTMSG:
@@ -1508,8 +1501,15 @@ TMailWindow::MessageReceived(BMessage *msg)
TMailWindow *window = static_cast<TMailApp *>(be_app) TMailWindow *window = static_cast<TMailApp *>(be_app)
->FindWindow(nextRef); ->FindWindow(nextRef);
if (window == NULL) { if (window == NULL) {
if (fAutoMarkRead) BNode node(fRef);
SetCurrentMessageRead(); 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, OpenMessage(&nextRef,
fHeaderView->fCharacterSetUserSees, msg); fHeaderView->fCharacterSetUserSees, msg);
} else { } else {
@@ -1732,8 +1732,8 @@ TMailWindow::QuitRequested()
} }
} else if (fRef != NULL && !sKeepStatusOnQuit) { } else if (fRef != NULL && !sKeepStatusOnQuit) {
// ...Otherwise just set the message read // ...Otherwise just set the message read
if (fAutoMarkRead) read_flags flag = (fAutoMarkRead == true) ? B_READ : B_SEEN;
SetCurrentMessageRead(); SetCurrentMessageRead(flag);
} }
BPrivate::BPathMonitor::StopWatching(BMessenger(this, this)); BPrivate::BPathMonitor::StopWatching(BMessenger(this, this));
@@ -3187,23 +3187,19 @@ TMailWindow::_BuildQueryString(BEntry* entry) const
void void
TMailWindow::_AddReadButton() TMailWindow::_AddReadButton()
{ {
bool newMail = false;
BNode node(fRef); BNode node(fRef);
if (node.InitCheck() == B_NO_ERROR) {
BString status; read_flags flag = B_UNREAD;
if (ReadAttrString(&node, B_MAIL_ATTR_STATUS, &status) == B_NO_ERROR read_read_attr(node, flag);
&& !status.ICompare("New")) {
newMail = true;
}
}
int32 buttonIndex = fButtonBar->IndexOf(fNextButton); int32 buttonIndex = fButtonBar->IndexOf(fNextButton);
if (newMail) if (flag == B_READ) {
fReadButton = fButtonBar->AddButton( fReadButton = fButtonBar->AddButton(B_TRANSLATE("Unread"), 28,
B_TRANSLATE(" Read "), 24, new BMessage(M_READ), buttonIndex); new BMessage(M_UNREAD), buttonIndex);
else } else {
fReadButton = fButtonBar->AddButton( fReadButton = fButtonBar->AddButton(B_TRANSLATE(" Read "), 24,
B_TRANSLATE("Unread"), 28, new BMessage(M_UNREAD), buttonIndex); new BMessage(M_READ), buttonIndex);
}
} }
@@ -3213,9 +3209,8 @@ TMailWindow::_UpdateReadButton()
if (fApp->ShowButtonBar()) { if (fApp->ShowButtonBar()) {
fButtonBar->RemoveButton(fReadButton); fButtonBar->RemoveButton(fReadButton);
fReadButton = NULL; fReadButton = NULL;
if (!fAutoMarkRead && !fReadButton) { if (!fAutoMarkRead)
_AddReadButton(); _AddReadButton();
}
} }
UpdateViews(); UpdateViews();
} }
+2 -1
View File
@@ -42,6 +42,7 @@ All rights reserved.
#include <Messenger.h> #include <Messenger.h>
#include <Window.h> #include <Window.h>
#include <E-mail.h>
#include <mail_encoding.h> #include <mail_encoding.h>
@@ -108,7 +109,7 @@ class TMailWindow : public BWindow {
void SaveTrackerPosition(entry_ref*); void SaveTrackerPosition(entry_ref*);
void SetOriginatingWindow(BWindow* window); void SetOriginatingWindow(BWindow* window);
void SetCurrentMessageRead(bool read = true); void SetCurrentMessageRead(read_flags flag);
void SetTrackerSelectionToCurrent(); void SetTrackerSelectionToCurrent();
TMailWindow* FrontmostWindow(); TMailWindow* FrontmostWindow();
void UpdateViews(); void UpdateViews();
+1 -1
View File
@@ -140,7 +140,7 @@ TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap,
fSpellCheckStartOn(*fNewSpellCheckStartOn), fSpellCheckStartOn(*fNewSpellCheckStartOn),
fNewAutoMarkRead(autoMarkRead), fNewAutoMarkRead(autoMarkRead),
fAutoMarkRead(true) fAutoMarkRead(*autoMarkRead)
{ {
strcpy(fSignature, *fNewSignature); strcpy(fSignature, *fNewSignature);
+26 -5
View File
@@ -93,18 +93,39 @@ write_read_attr(BNode& node, read_flags flag)
< 0) < 0)
return B_ERROR; return B_ERROR;
if (flag == B_SEEN) #if R5_COMPATIBLE
return B_OK; const char* statusString = (flag == B_READ) ? "Read"
: (flag == B_SEEN) ? "Seen" : "New";
const char* statusString = (flag == B_READ) ? "Read" : "New";
if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString, if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString,
strlen(statusString)) < 0) strlen(statusString)) < 0)
return B_ERROR; return B_ERROR;
#endif
return B_OK; 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 // 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 // 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 // specifying the B_MAIL_UTF8_CONVERSION constant as the conversion operation. It