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_READ "MAIL:read" // int32
#define R5_COMPATIBLE 1
// 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 read_read_attr(BNode& node, read_flags& flag);
// 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,
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<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 @@ 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();
}
+2 -1
View File
@@ -42,6 +42,7 @@ All rights reserved.
#include <Messenger.h>
#include <Window.h>
#include <E-mail.h>
#include <mail_encoding.h>
@@ -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();
+1 -1
View File
@@ -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);
+26 -5
View File
@@ -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