Mail: minor cleanup.

This commit is contained in:
Axel Dörfler
2015-08-17 21:12:42 +02:00
parent f8300bd979
commit b20d210d5a
4 changed files with 319 additions and 351 deletions
+7
View File
@@ -1253,6 +1253,13 @@ BComboBox::Text() const
} }
int32
BComboBox::TextLength() const
{
return fText->TextLength();
}
BTextView * BTextView *
BComboBox::TextView() BComboBox::TextView()
{ {
+1
View File
@@ -150,6 +150,7 @@ public:
virtual void SetLabel(const char *text); virtual void SetLabel(const char *text);
virtual void SetText(const char *text); virtual void SetText(const char *text);
const char *Text() const; const char *Text() const;
int32 TextLength() const;
BTextView *TextView(); BTextView *TextView();
virtual void SetDivider(float dividing_line); virtual void SetDivider(float dividing_line);
float Divider() const; float Divider() const;
+192 -235
View File
@@ -93,7 +93,7 @@ of their respective holders. All rights reserved.
using namespace BPrivate; using namespace BPrivate;
const char *kUndoStrings[] = { const char* kUndoStrings[] = {
"Undo", "Undo",
"Undo typing", "Undo typing",
"Undo cut", "Undo cut",
@@ -102,7 +102,7 @@ const char *kUndoStrings[] = {
"Undo drop" "Undo drop"
}; };
const char *kRedoStrings[] = { const char* kRedoStrings[] = {
"Redo", "Redo",
"Redo typing", "Redo typing",
"Redo cut", "Redo cut",
@@ -113,7 +113,7 @@ const char *kRedoStrings[] = {
// Text for both the main menu and the pop-up menu. // Text for both the main menu and the pop-up menu.
static const char *kSpamMenuItemTextArray[] = { static const char* kSpamMenuItemTextArray[] = {
"Mark as spam and move to trash", // M_TRAIN_SPAM_AND_DELETE "Mark as spam and move to trash", // M_TRAIN_SPAM_AND_DELETE
"Mark as spam", // M_TRAIN_SPAM "Mark as spam", // M_TRAIN_SPAM
"Unmark this message", // M_UNTRAIN "Unmark this message", // M_UNTRAIN
@@ -122,12 +122,12 @@ static const char *kSpamMenuItemTextArray[] = {
static const uint32 kMsgQuitAndKeepAllStatus = 'Casm'; static const uint32 kMsgQuitAndKeepAllStatus = 'Casm';
static const char *kQueriesDirectory = "mail/queries"; static const char* kQueriesDirectory = "mail/queries";
static const char *kAttrQueryInitialMode = "_trk/qryinitmode"; static const char* kAttrQueryInitialMode = "_trk/qryinitmode";
// taken from src/kits/tracker/Attributes.h // taken from src/kits/tracker/Attributes.h
static const char *kAttrQueryInitialString = "_trk/qryinitstr"; static const char* kAttrQueryInitialString = "_trk/qryinitstr";
static const char *kAttrQueryInitialNumAttrs = "_trk/qryinitnumattrs"; static const char* kAttrQueryInitialNumAttrs = "_trk/qryinitnumattrs";
static const char *kAttrQueryInitialAttrs = "_trk/qryinitattrs"; static const char* kAttrQueryInitialAttrs = "_trk/qryinitattrs";
static const uint32 kAttributeItemMain = 'Fatr'; static const uint32 kAttributeItemMain = 'Fatr';
// taken from src/kits/tracker/FindPanel.h // taken from src/kits/tracker/FindPanel.h
static const uint32 kByNameItem = 'Fbyn'; static const uint32 kByNameItem = 'Fbyn';
@@ -138,11 +138,30 @@ static const uint32 kByForumlaItem = 'Fbyq';
// taken from src/kits/tracker/FindPanel.h // taken from src/kits/tracker/FindPanel.h
// static bitmap cache
BObjectList<TMailWindow::BitmapItem> TMailWindow::sBitmapCache;
BLocker TMailWindow::sBitmapCacheLock;
// static list for tracking of Windows // static list for tracking of Windows
BList TMailWindow::sWindowList; BList TMailWindow::sWindowList;
BLocker TMailWindow::sWindowListLock; BLocker TMailWindow::sWindowListLock;
class HorizontalLine : public BView {
public:
HorizontalLine(BRect rect)
:
BView (rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW)
{
}
virtual void Draw(BRect rect)
{
FillRect(rect, B_SOLID_HIGH);
}
};
// #pragma mark - // #pragma mark -
@@ -216,8 +235,7 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
// few seconds. // few seconds.
if (!fIncoming) { if (!fIncoming) {
QueryMenu *queryMenu; QueryMenu* queryMenu = new QueryMenu(B_TRANSLATE("Open draft"), false);
queryMenu = new QueryMenu(B_TRANSLATE("Open draft"), false);
queryMenu->SetTargetForItems(be_app); queryMenu->SetTargetForItems(be_app);
queryMenu->SetPredicate("MAIL:draft==1"); queryMenu->SetPredicate("MAIL:draft==1");
@@ -377,7 +395,7 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
menu = new BMenu(B_TRANSLATE("Message")); menu = new BMenu(B_TRANSLATE("Message"));
if (!resending && fIncoming) { if (!resending && fIncoming) {
BMenuItem *menuItem; BMenuItem* menuItem;
menu->AddItem(new BMenuItem(B_TRANSLATE("Reply"), menu->AddItem(new BMenuItem(B_TRANSLATE("Reply"),
new BMessage(M_REPLY),'R')); new BMessage(M_REPLY),'R'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Reply to sender"), menu->AddItem(new BMenuItem(B_TRANSLATE("Reply to sender"),
@@ -492,7 +510,7 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
r = Frame(); r = Frame();
r.OffsetTo(0, 0); r.OffsetTo(0, 0);
r.top = fHeaderView->Frame().bottom - 1; r.top = fHeaderView->Frame().bottom - 1;
fContentView = new TContentView(r, fIncoming, const_cast<BFont *>(font), fContentView = new TContentView(r, fIncoming, const_cast<BFont*>(font),
false, fApp->ColoredQuotes()); false, fApp->ColoredQuotes());
// TContentView needs to be properly const, for now cast away constness // TContentView needs to be properly const, for now cast away constness
@@ -554,20 +572,17 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
} }
BObjectList<TMailWindow::BitmapItem> TMailWindow::fBitmapCache;
BLocker TMailWindow::fBitmapCacheLock;
BBitmap* BBitmap*
TMailWindow::_RetrieveVectorIcon(int32 id) TMailWindow::_RetrieveVectorIcon(int32 id)
{ {
// Lock access to the list // Lock access to the list
BAutolock lock(fBitmapCacheLock); BAutolock lock(sBitmapCacheLock);
if (!lock.IsLocked()) if (!lock.IsLocked())
return NULL; return NULL;
// Check for the bitmap in the cache first // Check for the bitmap in the cache first
BitmapItem* item; BitmapItem* item;
for (int32 i = 0; (item = fBitmapCache.ItemAt(i)) != NULL; i++) { for (int32 i = 0; (item = sBitmapCache.ItemAt(i)) != NULL; i++) {
if (item->id == id) if (item->id == id)
return item->bm; return item->bm;
} }
@@ -588,7 +603,7 @@ TMailWindow::_RetrieveVectorIcon(int32 id)
item = (BitmapItem*)malloc(sizeof(BitmapItem)); item = (BitmapItem*)malloc(sizeof(BitmapItem));
item->bm = bitmap; item->bm = bitmap;
item->id = id; item->id = id;
fBitmapCache.AddItem(item); sBitmapCache.AddItem(item);
return bitmap; return bitmap;
} }
@@ -599,7 +614,7 @@ TMailWindow::_RetrieveVectorIcon(int32 id)
void void
TMailWindow::BuildToolBar() TMailWindow::BuildToolBar()
{ {
fToolBar = new BToolBar(BRect(0, 0, 100, 50)); fToolBar = new BToolBar();
fToolBar->AddAction(M_NEW, this, _RetrieveVectorIcon(11), NULL, fToolBar->AddAction(M_NEW, this, _RetrieveVectorIcon(11), NULL,
B_TRANSLATE("New")); B_TRANSLATE("New"));
fToolBar->AddSeparator(); fToolBar->AddSeparator();
@@ -720,7 +735,7 @@ TMailWindow::~TMailWindow()
status_t status_t
TMailWindow::GetMailNodeRef(node_ref &nodeRef) const TMailWindow::GetMailNodeRef(node_ref& nodeRef) const
{ {
if (fRef == NULL) if (fRef == NULL)
return B_ERROR; return B_ERROR;
@@ -731,7 +746,7 @@ TMailWindow::GetMailNodeRef(node_ref &nodeRef) const
bool bool
TMailWindow::GetTrackerWindowFile(entry_ref *ref, bool next) const TMailWindow::GetTrackerWindowFile(entry_ref* ref, bool next) const
{ {
// Position was already saved // Position was already saved
if (next && fNextTrackerPositionSaved) { if (next && fNextTrackerPositionSaved) {
@@ -789,7 +804,7 @@ TMailWindow::GetTrackerWindowFile(entry_ref *ref, bool next) const
void void
TMailWindow::SaveTrackerPosition(entry_ref *ref) TMailWindow::SaveTrackerPosition(entry_ref* ref)
{ {
// if only one of them is saved, we're not going to do it again // if only one of them is saved, we're not going to do it again
if (fNextTrackerPositionSaved || fPrevTrackerPositionSaved) if (fNextTrackerPositionSaved || fPrevTrackerPositionSaved)
@@ -803,7 +818,7 @@ TMailWindow::SaveTrackerPosition(entry_ref *ref)
void void
TMailWindow::SetOriginatingWindow(BWindow *window) TMailWindow::SetOriginatingWindow(BWindow* window)
{ {
delete fOriginatingWindow; delete fOriginatingWindow;
fOriginatingWindow = new BMessenger(window); fOriginatingWindow = new BMessenger(window);
@@ -824,7 +839,7 @@ TMailWindow::SetTrackerSelectionToCurrent()
void void
TMailWindow::PreserveReadingPos(bool save) TMailWindow::PreserveReadingPos(bool save)
{ {
BScrollBar *scroll = fContentView->fTextView->ScrollBar(B_VERTICAL); BScrollBar* scroll = fContentView->fTextView->ScrollBar(B_VERTICAL);
if (scroll == NULL || fRef == NULL) if (scroll == NULL || fRef == NULL)
return; return;
@@ -881,7 +896,7 @@ TMailWindow::MenusBeginning()
bool enable; bool enable;
int32 finish = 0; int32 finish = 0;
int32 start = 0; int32 start = 0;
BTextView *textView; BTextView* textView;
if (!fIncoming) { if (!fIncoming) {
bool gotToField = fHeaderView->fTo->Text()[0] != 0; bool gotToField = fHeaderView->fTo->Text()[0] != 0;
@@ -937,9 +952,9 @@ TMailWindow::MenusBeginning()
fPrint->SetEnabled(fContentView->fTextView->TextLength()); fPrint->SetEnabled(fContentView->fTextView->TextLength());
textView = dynamic_cast<BTextView *>(CurrentFocus()); textView = dynamic_cast<BTextView*>(CurrentFocus());
if (textView != NULL if (textView != NULL
&& dynamic_cast<TTextControl *>(textView->Parent()) != NULL) { && dynamic_cast<TTextControl*>(textView->Parent()) != NULL) {
// one of To:, Subject:, Account:, Cc:, Bcc: // one of To:, Subject:, Account:, Cc:, Bcc:
textView->GetSelection(&start, &finish); textView->GetSelection(&start, &finish);
} else if (fContentView->fTextView->IsFocus()) { } else if (fContentView->fTextView->IsFocus()) {
@@ -958,7 +973,7 @@ TMailWindow::MenusBeginning()
bool isRedo = false; bool isRedo = false;
undo_state undoState = B_UNDO_UNAVAILABLE; undo_state undoState = B_UNDO_UNAVAILABLE;
BTextView *focusTextView = dynamic_cast<BTextView *>(CurrentFocus()); BTextView* focusTextView = dynamic_cast<BTextView*>(CurrentFocus());
if (focusTextView != NULL) if (focusTextView != NULL)
undoState = focusTextView->UndoState(&isRedo); undoState = focusTextView->UndoState(&isRedo);
@@ -985,7 +1000,7 @@ TMailWindow::MenusBeginning()
void void
TMailWindow::MessageReceived(BMessage *msg) TMailWindow::MessageReceived(BMessage* msg)
{ {
bool wasReadMsg = false; bool wasReadMsg = false;
switch (msg->what) { switch (msg->what) {
@@ -1012,15 +1027,15 @@ TMailWindow::MessageReceived(BMessage *msg)
{ {
int32 prevState = fFieldState; int32 prevState = fFieldState;
int32 fieldMask = msg->FindInt32("bitmask"); int32 fieldMask = msg->FindInt32("bitmask");
void *source; void* source;
if (msg->FindPointer("source", &source) == B_OK) { if (msg->FindPointer("source", &source) == B_OK) {
int32 length; int32 length;
if (fieldMask == FIELD_BODY) if (fieldMask == FIELD_BODY)
length = ((TTextView *)source)->TextLength(); length = ((TTextView*)source)->TextLength();
else else
length = ((BComboBox *)source)->TextView()->TextLength(); length = ((BComboBox*)source)->TextView()->TextLength();
if (length) if (length)
fFieldState |= fieldMask; fFieldState |= fieldMask;
@@ -1039,7 +1054,7 @@ TMailWindow::MessageReceived(BMessage *msg)
fChanged = true; fChanged = true;
// Update title bar if "subject" has changed // Update title bar if "subject" has changed
if (!fIncoming && fieldMask & FIELD_SUBJECT) { if (!fIncoming && (fieldMask & FIELD_SUBJECT) != 0) {
// If no subject, set to "Mail" // If no subject, set to "Mail"
if (!fHeaderView->fSubject->TextView()->TextLength()) if (!fHeaderView->fSubject->TextView()->TextLength())
SetTitle(B_TRANSLATE_SYSTEM_NAME("Mail")); SetTitle(B_TRANSLATE_SYSTEM_NAME("Mail"));
@@ -1077,7 +1092,7 @@ TMailWindow::MessageReceived(BMessage *msg)
TODO: Replace this code with a split toolbar button TODO: Replace this code with a split toolbar button
*/ */
uint32 buttons; uint32 buttons;
if (msg->FindInt32("buttons", (int32 *)&buttons) == B_OK if (msg->FindInt32("buttons", (int32*)&buttons) == B_OK
&& buttons == B_SECONDARY_MOUSE_BUTTON) { && buttons == B_SECONDARY_MOUSE_BUTTON) {
BPopUpMenu menu("Spam Actions", false, false); BPopUpMenu menu("Spam Actions", false, false);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@@ -1086,7 +1101,7 @@ TMailWindow::MessageReceived(BMessage *msg)
BPoint where; BPoint where;
msg->FindPoint("where", &where); msg->FindPoint("where", &where);
BMenuItem *item; BMenuItem* item;
if ((item = menu.Go(where, false, false)) != NULL) if ((item = menu.Go(where, false, false)) != NULL)
PostMessage(item->Message()); PostMessage(item->Message());
break; break;
@@ -1116,7 +1131,7 @@ TMailWindow::MessageReceived(BMessage *msg)
// TODO: This needs removed in favor of a split toolbar button. // TODO: This needs removed in favor of a split toolbar button.
// See comments for Spam button // See comments for Spam button
uint32 buttons; uint32 buttons;
if (msg->FindInt32("buttons", (int32 *)&buttons) == B_OK if (msg->FindInt32("buttons", (int32*)&buttons) == B_OK
&& buttons == B_SECONDARY_MOUSE_BUTTON) { && buttons == B_SECONDARY_MOUSE_BUTTON) {
BPopUpMenu menu("Reply To", false, false); BPopUpMenu menu("Reply To", false, false);
menu.AddItem(new BMenuItem(B_TRANSLATE("Reply"), menu.AddItem(new BMenuItem(B_TRANSLATE("Reply"),
@@ -1129,7 +1144,7 @@ TMailWindow::MessageReceived(BMessage *msg)
BPoint where; BPoint where;
msg->FindPoint("where", &where); msg->FindPoint("where", &where);
BMenuItem *item; BMenuItem* item;
if ((item = menu.Go(where, false, false)) != NULL) { if ((item = menu.Go(where, false, false)) != NULL) {
item->SetTarget(this); item->SetTarget(this);
PostMessage(item->Message()); PostMessage(item->Message());
@@ -1143,7 +1158,7 @@ TMailWindow::MessageReceived(BMessage *msg)
// TODO: This needs removed in favor of a split toolbar button. // TODO: This needs removed in favor of a split toolbar button.
// See comments for Spam button // See comments for Spam button
uint32 buttons; uint32 buttons;
if (msg->FindInt32("buttons", (int32 *)&buttons) == B_OK if (msg->FindInt32("buttons", (int32*)&buttons) == B_OK
&& buttons == B_SECONDARY_MOUSE_BUTTON) { && buttons == B_SECONDARY_MOUSE_BUTTON) {
BPopUpMenu menu("Forward", false, false); BPopUpMenu menu("Forward", false, false);
menu.AddItem(new BMenuItem(B_TRANSLATE("Forward"), menu.AddItem(new BMenuItem(B_TRANSLATE("Forward"),
@@ -1155,7 +1170,7 @@ TMailWindow::MessageReceived(BMessage *msg)
BPoint where; BPoint where;
msg->FindPoint("where", &where); msg->FindPoint("where", &where);
BMenuItem *item; BMenuItem* item;
if ((item = menu.Go(where, false, false)) != NULL) { if ((item = menu.Go(where, false, false)) != NULL) {
item->SetTarget(this); item->SetTarget(this);
PostMessage(item->Message()); PostMessage(item->Message());
@@ -1182,7 +1197,7 @@ TMailWindow::MessageReceived(BMessage *msg)
case M_DELETE_PREV: case M_DELETE_PREV:
case M_DELETE_NEXT: case M_DELETE_NEXT:
{ {
if (msg->what == M_DELETE_NEXT && (modifiers() & B_SHIFT_KEY)) if (msg->what == M_DELETE_NEXT && (modifiers() & B_SHIFT_KEY) != 0)
msg->what = M_DELETE_PREV; msg->what = M_DELETE_PREV;
bool foundRef = false; bool foundRef = false;
@@ -1233,8 +1248,8 @@ TMailWindow::MessageReceived(BMessage *msg)
// If the next file was found, open it. If it was not, // If the next file was found, open it. If it was not,
// we have no choice but to close this window. // we have no choice but to close this window.
if (foundRef) { if (foundRef) {
TMailWindow *window TMailWindow* window
= static_cast<TMailApp *>(be_app)->FindWindow(nextRef); = static_cast<TMailApp*>(be_app)->FindWindow(nextRef);
if (window == NULL) if (window == NULL)
OpenMessage(&nextRef, fHeaderView->fCharacterSetUserSees); OpenMessage(&nextRef, fHeaderView->fCharacterSetUserSees);
else else
@@ -1272,10 +1287,8 @@ TMailWindow::MessageReceived(BMessage *msg)
break; break;
case M_CLOSE_CUSTOM: case M_CLOSE_CUSTOM:
if (msg->HasString("status")) { if (msg->HasString("status")) {
const char *str;
msg->FindString("status", (const char**) &str);
BMessage message(B_CLOSE_REQUESTED); BMessage message(B_CLOSE_REQUESTED);
message.AddString("status", str); message.AddString("status", msg->GetString("status"));
PostMessage(&message); PostMessage(&message);
} else { } else {
BRect r = Frame(); BRect r = Frame();
@@ -1331,7 +1344,7 @@ TMailWindow::MessageReceived(BMessage *msg)
case M_SAVE: case M_SAVE:
{ {
const char* address; const char* address;
if (msg->FindString("address", (const char**)&address) != B_NO_ERROR) if (msg->FindString("address", (const char**)&address) != B_OK)
break; break;
BVolumeRoster volumeRoster; BVolumeRoster volumeRoster;
@@ -1448,10 +1461,10 @@ TMailWindow::MessageReceived(BMessage *msg)
} }
if (sigList.CountItems() > 0) { if (sigList.CountItems() > 0) {
srand(time(0)); srand(time(0));
PostMessage((BMessage *)sigList.ItemAt(rand() PostMessage((BMessage*)sigList.ItemAt(rand()
% sigList.CountItems())); % sigList.CountItems()));
for (int32 i = 0; (message = (BMessage *)sigList.ItemAt(i)) for (int32 i = 0; (message = (BMessage*)sigList.ItemAt(i))
!= NULL; i++) != NULL; i++)
delete message; delete message;
} }
@@ -1466,8 +1479,8 @@ TMailWindow::MessageReceived(BMessage *msg)
} }
case M_SIG_MENU: case M_SIG_MENU:
{ {
TMenu *menu; TMenu* menu;
BMenuItem *item; BMenuItem* item;
menu = new TMenu("Add Signature", INDEX_SIGNATURE, M_SIGNATURE, menu = new TMenu("Add Signature", INDEX_SIGNATURE, M_SIGNATURE,
true); true);
@@ -1481,7 +1494,7 @@ TMailWindow::MessageReceived(BMessage *msg)
if ((item = menu->Go(where, false, true)) != NULL) { if ((item = menu->Go(where, false, true)) != NULL) {
item->SetTarget(this); item->SetTarget(this);
(dynamic_cast<BInvoker *>(item))->Invoke(); (dynamic_cast<BInvoker*>(item))->Invoke();
} }
delete menu; delete menu;
break; break;
@@ -1544,7 +1557,7 @@ TMailWindow::MessageReceived(BMessage *msg)
entry_ref orgRef = *fRef; entry_ref orgRef = *fRef;
entry_ref nextRef = *fRef; entry_ref nextRef = *fRef;
if (GetTrackerWindowFile(&nextRef, (msg->what == M_NEXTMSG))) { if (GetTrackerWindowFile(&nextRef, (msg->what == M_NEXTMSG))) {
TMailWindow *window = static_cast<TMailApp *>(be_app) TMailWindow* window = static_cast<TMailApp*>(be_app)
->FindWindow(nextRef); ->FindWindow(nextRef);
if (window == NULL) { if (window == NULL) {
BNode node(fRef); BNode node(fRef);
@@ -1672,7 +1685,7 @@ TMailWindow::MessageReceived(BMessage *msg)
void void
TMailWindow::AddEnclosure(BMessage *msg) TMailWindow::AddEnclosure(BMessage* msg)
{ {
if (fEnclosuresView == NULL && !fIncoming) { if (fEnclosuresView == NULL && !fIncoming) {
BRect r; BRect r;
@@ -1720,7 +1733,7 @@ TMailWindow::QuitRequested()
|| (fEnclosuresView != NULL || (fEnclosuresView != NULL
&& fEnclosuresView->fList->CountItems()))) { && fEnclosuresView->fList->CountItems()))) {
if (fResending) { if (fResending) {
BAlert *alert = new BAlert("", B_TRANSLATE( BAlert* alert = new BAlert("", B_TRANSLATE(
"Send this message before closing?"), "Send this message before closing?"),
B_TRANSLATE("Cancel"), B_TRANSLATE("Cancel"),
B_TRANSLATE("Don't send"), B_TRANSLATE("Don't send"),
@@ -1741,7 +1754,7 @@ TMailWindow::QuitRequested()
break; break;
} }
} else { } else {
BAlert *alert = new BAlert("", BAlert* alert = new BAlert("",
B_TRANSLATE("Save this message as a draft before closing?"), B_TRANSLATE("Save this message as a draft before closing?"),
B_TRANSLATE("Cancel"), B_TRANSLATE("Cancel"),
B_TRANSLATE("Don't save"), B_TRANSLATE("Don't save"),
@@ -1771,7 +1784,7 @@ TMailWindow::QuitRequested()
if (CurrentMessage() && CurrentMessage()->HasString("status")) { if (CurrentMessage() && CurrentMessage()->HasString("status")) {
// User explicitly requests a status to set this message to. // User explicitly requests a status to set this message to.
if (!CurrentMessage()->HasString("same")) { if (!CurrentMessage()->HasString("same")) {
const char *status = CurrentMessage()->FindString("status"); const char* status = CurrentMessage()->FindString("status");
if (status != NULL) { if (status != NULL) {
BNode node(fRef); BNode node(fRef);
if (node.InitCheck() == B_NO_ERROR) { if (node.InitCheck() == B_NO_ERROR) {
@@ -1807,7 +1820,7 @@ TMailWindow::Show()
if (!fResending && (fIncoming || fReplying)) { if (!fResending && (fIncoming || fReplying)) {
fContentView->fTextView->MakeFocus(true); fContentView->fTextView->MakeFocus(true);
} else { } else {
BTextView *textView = fHeaderView->fTo->TextView(); BTextView* textView = fHeaderView->fTo->TextView();
fHeaderView->fTo->MakeFocus(true); fHeaderView->fTo->MakeFocus(true);
textView->Select(0, textView->TextLength()); textView->Select(0, textView->TextLength());
} }
@@ -1822,61 +1835,57 @@ TMailWindow::Zoom(BPoint /*pos*/, float /*x*/, float /*y*/)
{ {
float height; float height;
float width; float width;
BScreen screen(this);
BRect r;
BRect s_frame = screen.Frame();
r = Frame(); BRect rect = Frame();
width = 80 * fApp->ContentFont().StringWidth("M") width = 80 * fApp->ContentFont().StringWidth("M")
+ (r.Width() - fContentView->fTextView->Bounds().Width() + 6); + (rect.Width() - fContentView->fTextView->Bounds().Width() + 6);
if (width > (s_frame.Width() - 8))
width = s_frame.Width() - 8; BScreen screen(this);
BRect screenFrame = screen.Frame();
if (width > (screenFrame.Width() - 8))
width = screenFrame.Width() - 8;
height = max_c(fContentView->fTextView->CountLines(), 20) height = max_c(fContentView->fTextView->CountLines(), 20)
* fContentView->fTextView->LineHeight(0) * fContentView->fTextView->LineHeight(0)
+ (r.Height() - fContentView->fTextView->Bounds().Height()); + (rect.Height() - fContentView->fTextView->Bounds().Height());
if (height > (s_frame.Height() - 29)) if (height > (screenFrame.Height() - 29))
height = s_frame.Height() - 29; height = screenFrame.Height() - 29;
r.right = r.left + width; rect.right = rect.left + width;
r.bottom = r.top + height; rect.bottom = rect.top + height;
if (abs((int)(Frame().Width() - r.Width())) < 5 if (abs((int)(Frame().Width() - rect.Width())) < 5
&& abs((int)(Frame().Height() - r.Height())) < 5) { && abs((int)(Frame().Height() - rect.Height())) < 5) {
r = fZoom; rect = fZoom;
} else { } else {
fZoom = Frame(); fZoom = Frame();
s_frame.InsetBy(6, 6); screenFrame.InsetBy(6, 6);
if (r.Width() > s_frame.Width()) if (rect.Width() > screenFrame.Width())
r.right = r.left + s_frame.Width(); rect.right = rect.left + screenFrame.Width();
if (r.Height() > s_frame.Height()) if (rect.Height() > screenFrame.Height())
r.bottom = r.top + s_frame.Height(); rect.bottom = rect.top + screenFrame.Height();
if (r.right > s_frame.right) if (rect.right > screenFrame.right) {
{ rect.left -= rect.right - screenFrame.right;
r.left -= r.right - s_frame.right; rect.right = screenFrame.right;
r.right = s_frame.right;
} }
if (r.bottom > s_frame.bottom) if (rect.bottom > screenFrame.bottom) {
{ rect.top -= rect.bottom - screenFrame.bottom;
r.top -= r.bottom - s_frame.bottom; rect.bottom = screenFrame.bottom;
r.bottom = s_frame.bottom;
} }
if (r.left < s_frame.left) if (rect.left < screenFrame.left) {
{ rect.right += screenFrame.left - rect.left;
r.right += s_frame.left - r.left; rect.left = screenFrame.left;
r.left = s_frame.left;
} }
if (r.top < s_frame.top) if (rect.top < screenFrame.top) {
{ rect.bottom += screenFrame.top - rect.top;
r.bottom += s_frame.top - r.top; rect.top = screenFrame.top;
r.top = s_frame.top;
} }
} }
ResizeTo(r.Width(), r.Height()); ResizeTo(rect.Width(), rect.Height());
MoveTo(r.LeftTop()); MoveTo(rect.LeftTop());
} }
@@ -1892,10 +1901,10 @@ TMailWindow::WindowActivated(bool status)
void void
TMailWindow::Forward(entry_ref *ref, TMailWindow *window, TMailWindow::Forward(entry_ref* ref, TMailWindow* window,
bool includeAttachments) bool includeAttachments)
{ {
BEmailMessage *mail = window->Mail(); BEmailMessage* mail = window->Mail();
if (mail == NULL) if (mail == NULL)
return; return;
@@ -1915,10 +1924,10 @@ TMailWindow::Forward(entry_ref *ref, TMailWindow *window,
if (useAccountFrom == ACCOUNT_FROM_MAIL) { if (useAccountFrom == ACCOUNT_FROM_MAIL) {
fHeaderView->fAccountID = fMail->Account(); fHeaderView->fAccountID = fMail->Account();
BMenu *menu = fHeaderView->fAccountMenu; BMenu* menu = fHeaderView->fAccountMenu;
for (int32 i = menu->CountItems(); i-- > 0;) { for (int32 i = menu->CountItems(); i-- > 0;) {
BMenuItem *item = menu->ItemAt(i); BMenuItem* item = menu->ItemAt(i);
BMessage *msg; BMessage* msg;
if (item && (msg = item->Message()) != NULL if (item && (msg = item->Message()) != NULL
&& msg->FindInt32("id") == fHeaderView->fAccountID) && msg->FindInt32("id") == fHeaderView->fAccountID)
item->SetMarked(true); item->SetMarked(true);
@@ -1939,19 +1948,6 @@ TMailWindow::Forward(entry_ref *ref, TMailWindow *window,
} }
class HorizontalLine : public BView {
public:
HorizontalLine(BRect rect)
:
BView (rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW) {}
virtual void Draw(BRect rect)
{
FillRect(rect, B_SOLID_HIGH);
}
};
void void
TMailWindow::Print() TMailWindow::Print()
{ {
@@ -1989,8 +1985,7 @@ TMailWindow::Print()
add_header_field(fSubject); add_header_field(fSubject);
add_header_field(fTo); add_header_field(fTo);
if ((fHeaderView->fCc != NULL) if (fHeaderView->fCc != NULL && fHeaderView->fCc->TextLength() != 0)
&& (strcmp(fHeaderView->fCc->Text(),"") != 0))
add_header_field(fCc); add_header_field(fCc);
if (fHeaderView->fDate != NULL) if (fHeaderView->fDate != NULL)
@@ -2025,21 +2020,18 @@ TMailWindow::Print()
BPoint(0.0, curPageRect.bottom - ((curPage == 1) BPoint(0.0, curPageRect.bottom - ((curPage == 1)
? header_height : 0))); ? header_height : 0)));
float curPageHeight = fContentView->fTextView-> float curPageHeight = fContentView->fTextView->TextHeight(
TextHeight(fromLine, lastLine) + ((curPage == 1) fromLine, lastLine) + (curPage == 1 ? header_height : 0);
? header_height : 0);
if (curPageHeight > pageRect.Height()) { if (curPageHeight > pageRect.Height()) {
curPageHeight = fContentView->fTextView->TextHeight( curPageHeight = fContentView->fTextView->TextHeight(
fromLine, --lastLine) + ((curPage == 1) fromLine, --lastLine) + (curPage == 1 ? header_height : 0);
? header_height : 0);
} }
curPageRect.bottom = curPageRect.top + curPageHeight - 1.0; curPageRect.bottom = curPageRect.top + curPageHeight - 1.0;
if ((curPage >= print.FirstPage()) if (curPage >= print.FirstPage() && curPage <= print.LastPage()) {
&& (curPage <= print.LastPage())) {
print.DrawView(fContentView->fTextView, curPageRect, print.DrawView(fContentView->fTextView, curPageRect,
BPoint(0.0, (curPage == 1) ? header_height : 0.0)); BPoint(0.0, curPage == 1 ? header_height : 0.0));
print.SpoolPage(); print.SpoolPage();
} }
@@ -2072,8 +2064,8 @@ TMailWindow::PrintSetup()
void void
TMailWindow::SetTo(const char *mailTo, const char *subject, const char *ccTo, TMailWindow::SetTo(const char* mailTo, const char* subject, const char* ccTo,
const char *bccTo, const BString *body, BMessage *enclosures) const char* bccTo, const BString* body, BMessage* enclosures)
{ {
Lock(); Lock();
@@ -2099,7 +2091,7 @@ TMailWindow::SetTo(const char *mailTo, const char *subject, const char *ccTo,
void void
TMailWindow::CopyMessage(entry_ref *ref, TMailWindow *src) TMailWindow::CopyMessage(entry_ref* ref, TMailWindow* src)
{ {
BNode file(ref); BNode file(ref);
if (file.InitCheck() == B_OK) { if (file.InitCheck() == B_OK) {
@@ -2117,8 +2109,8 @@ TMailWindow::CopyMessage(entry_ref *ref, TMailWindow *src)
fHeaderView->fCc->SetText(string.String()); fHeaderView->fCc->SetText(string.String());
} }
TTextView *text = src->fContentView->fTextView; TTextView* text = src->fContentView->fTextView;
text_run_array *style = text->RunArray(0, text->TextLength()); text_run_array* style = text->RunArray(0, text->TextLength());
fContentView->fTextView->SetText(text->Text(), text->TextLength(), style); fContentView->fTextView->SetText(text->Text(), text->TextLength(), style);
@@ -2127,12 +2119,12 @@ TMailWindow::CopyMessage(entry_ref *ref, TMailWindow *src)
void void
TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type) TMailWindow::Reply(entry_ref* ref, TMailWindow* window, uint32 type)
{ {
fRepliedMail = *ref; fRepliedMail = *ref;
SetOriginatingWindow(window); SetOriginatingWindow(window);
BEmailMessage *mail = window->Mail(); BEmailMessage* mail = window->Mail();
if (mail == NULL) if (mail == NULL)
return; return;
@@ -2167,10 +2159,10 @@ TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type)
else else
fHeaderView->fAccountID = accountID; fHeaderView->fAccountID = accountID;
BMenu *menu = fHeaderView->fAccountMenu; BMenu* menu = fHeaderView->fAccountMenu;
for (int32 i = menu->CountItems(); i-- > 0;) { for (int32 i = menu->CountItems(); i-- > 0;) {
BMenuItem *item = menu->ItemAt(i); BMenuItem* item = menu->ItemAt(i);
BMessage *msg; BMessage* msg;
if (item && (msg = item->Message()) != NULL if (item && (msg = item->Message()) != NULL
&& msg->FindInt32("id") == fHeaderView->fAccountID) && msg->FindInt32("id") == fHeaderView->fAccountID)
item->SetMarked(true); item->SetMarked(true);
@@ -2204,7 +2196,7 @@ TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type)
int32 finish, start; int32 finish, start;
window->fContentView->fTextView->GetSelection(&start, &finish); window->fContentView->fTextView->GetSelection(&start, &finish);
if (start != finish) { if (start != finish) {
char *text = (char *)malloc(finish - start + 1); char* text = (char*)malloc(finish - start + 1);
if (text == NULL) if (text == NULL)
return; return;
@@ -2219,11 +2211,11 @@ TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type)
finish = fContentView->fTextView->CountLines(); finish = fContentView->fTextView->CountLines();
for (int32 loop = 0; loop < finish; loop++) { for (int32 loop = 0; loop < finish; loop++) {
fContentView->fTextView->GoToLine(loop); fContentView->fTextView->GoToLine(loop);
fContentView->fTextView->Insert((const char *)QUOTE); fContentView->fTextView->Insert((const char*)QUOTE);
} }
if (fApp->ColoredQuotes()) { if (fApp->ColoredQuotes()) {
const BFont *font = fContentView->fTextView->Font(); const BFont* font = fContentView->fTextView->Font();
int32 length = fContentView->fTextView->TextLength(); int32 length = fContentView->fTextView->TextLength();
TextRunArray style(length / 8 + 8); TextRunArray style(length / 8 + 8);
@@ -2433,9 +2425,9 @@ TMailWindow::Send(bool now)
characterSetToUse, encodingForBody); characterSetToUse, encodingForBody);
if (fEnclosuresView != NULL) { if (fEnclosuresView != NULL) {
TListItem *item; TListItem* item;
int32 index = 0; int32 index = 0;
while ((item = (TListItem *)fEnclosuresView->fList->ItemAt(index++)) while ((item = (TListItem*)fEnclosuresView->fList->ItemAt(index++))
!= NULL) { != NULL) {
if (item->Component()) if (item->Component())
continue; continue;
@@ -2529,7 +2521,8 @@ TMailWindow::Send(bool now)
if (result != B_NO_ERROR && result != B_MAIL_NO_DAEMON) { if (result != B_NO_ERROR && result != B_MAIL_NO_DAEMON) {
beep(); beep();
BAlert* alert = new BAlert("", errorMessage.String(), B_TRANSLATE("OK")); BAlert* alert = new BAlert("", errorMessage.String(),
B_TRANSLATE("OK"));
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(); alert->Go();
} }
@@ -2547,20 +2540,20 @@ TMailWindow::Send(bool now)
status_t status_t
TMailWindow::SaveAsDraft() TMailWindow::SaveAsDraft()
{ {
status_t status;
BPath draftPath; BPath draftPath;
BDirectory dir; BDirectory dir;
BFile draft; BFile draft;
uint32 flags = 0; uint32 flags = 0;
if (fDraft) { if (fDraft) {
if ((status = draft.SetTo(fRef, status_t status = draft.SetTo(fRef,
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)) != B_OK) { B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (status != B_OK)
return status; return status;
}
} else { } else {
// Get the user home directory // Get the user home directory
if ((status = find_directory(B_USER_DIRECTORY, &draftPath)) != B_OK) status_t status = find_directory(B_USER_DIRECTORY, &draftPath);
if (status != B_OK)
return status; return status;
// Append the relative path of the draft directory // Append the relative path of the draft directory
@@ -2588,12 +2581,18 @@ TMailWindow::SaveAsDraft()
uint32 originalLength = strlen(fileName); uint32 originalLength = strlen(fileName);
// convert /, \ and : to - // convert /, \ and : to -
for (char *bad = fileName; (bad = strchr(bad, '/')) != NULL; for (char* bad = fileName; (bad = strchr(bad, '/')) != NULL;
++bad) *bad = '-'; ++bad) {
for (char *bad = fileName; (bad = strchr(bad, '\\')) != NULL; *bad = '-';
++bad) *bad = '-'; }
for (char *bad = fileName; (bad = strchr(bad, ':')) != NULL; for (char* bad = fileName; (bad = strchr(bad, '\\')) != NULL;
++bad) *bad = '-'; ++bad) {
*bad = '-';
}
for (char* bad = fileName; (bad = strchr(bad, ':')) != NULL;
++bad) {
*bad = '-';
}
// Create the file; if the name exists, find a unique name // Create the file; if the name exists, find a unique name
flags = B_WRITE_ONLY | B_CREATE_FILE | B_FAIL_IF_EXISTS; flags = B_WRITE_ONLY | B_CREATE_FILE | B_FAIL_IF_EXISTS;
@@ -2627,9 +2626,7 @@ TMailWindow::SaveAsDraft()
draft.Write(fContentView->fTextView->Text(), draft.Write(fContentView->fTextView->Text(),
fContentView->fTextView->TextLength()); fContentView->fTextView->TextLength());
//
// Add the header stuff as attributes // Add the header stuff as attributes
//
WriteAttrString(&draft, B_MAIL_ATTR_NAME, fHeaderView->fTo->Text()); WriteAttrString(&draft, B_MAIL_ATTR_NAME, fHeaderView->fTo->Text());
WriteAttrString(&draft, B_MAIL_ATTR_TO, fHeaderView->fTo->Text()); WriteAttrString(&draft, B_MAIL_ATTR_TO, fHeaderView->fTo->Text());
WriteAttrString(&draft, B_MAIL_ATTR_SUBJECT, fHeaderView->fSubject->Text()); WriteAttrString(&draft, B_MAIL_ATTR_SUBJECT, fHeaderView->fSubject->Text());
@@ -2654,12 +2651,11 @@ TMailWindow::SaveAsDraft()
// Add Attachment paths in attribute // Add Attachment paths in attribute
if (fEnclosuresView != NULL) { if (fEnclosuresView != NULL) {
TListItem *item; TListItem* item;
BPath path;
BString pathStr; BString pathStr;
for (int32 i = 0; (item = (TListItem *) for (int32 i = 0; (item = (TListItem*)fEnclosuresView->fList->ItemAt(i))
fEnclosuresView->fList->ItemAt(i)) != NULL; i++) { != NULL; i++) {
if (i > 0) if (i > 0)
pathStr.Append(":"); pathStr.Append(":");
@@ -2667,6 +2663,7 @@ TMailWindow::SaveAsDraft()
if (!entry.Exists()) if (!entry.Exists())
continue; continue;
BPath path;
entry.GetPath(&path); entry.GetPath(&path);
pathStr.Append(path.Path()); pathStr.Append(path.Path());
} }
@@ -2688,10 +2685,9 @@ TMailWindow::SaveAsDraft()
status_t status_t
TMailWindow::TrainMessageAs(const char *CommandWord) TMailWindow::TrainMessageAs(const char* commandWord)
{ {
status_t errorCode = -1; status_t errorCode = -1;
char errorString[1500];
BEntry fileEntry; BEntry fileEntry;
BPath filePath; BPath filePath;
BMessage replyMessage; BMessage replyMessage;
@@ -2700,7 +2696,7 @@ TMailWindow::TrainMessageAs(const char *CommandWord)
if (fRef == NULL) if (fRef == NULL)
goto ErrorExit; // Need to have a real file and name. goto ErrorExit; // Need to have a real file and name.
errorCode = fileEntry.SetTo(fRef, true /* traverse */); errorCode = fileEntry.SetTo(fRef, true);
if (errorCode != B_OK) if (errorCode != B_OK)
goto ErrorExit; goto ErrorExit;
errorCode = fileEntry.GetPath(&filePath); errorCode = fileEntry.GetPath(&filePath);
@@ -2717,15 +2713,17 @@ TMailWindow::TrainMessageAs(const char *CommandWord)
if (errorCode != B_OK) { if (errorCode != B_OK) {
BPath path; BPath path;
entry_ref ref; entry_ref ref;
directory_which places[] directory_which places[] = {B_SYSTEM_NONPACKAGED_BIN_DIRECTORY,
= {B_SYSTEM_NONPACKAGED_BIN_DIRECTORY, B_SYSTEM_BIN_DIRECTORY}; B_SYSTEM_BIN_DIRECTORY};
for (int32 i = 0; i < 2; i++) { for (int32 i = 0; i < 2; i++) {
find_directory(places[i],&path); find_directory(places[i],&path);
path.Append("spamdbm"); path.Append("spamdbm");
if (!BEntry(path.Path()).Exists()) if (!BEntry(path.Path()).Exists())
continue; continue;
get_ref_for_path(path.Path(),&ref); get_ref_for_path(path.Path(),&ref);
if ((errorCode = be_roster->Launch (&ref)) == B_OK)
errorCode = be_roster->Launch(&ref);
if (errorCode == B_OK)
break; break;
} }
if (errorCode != B_OK) if (errorCode != B_OK)
@@ -2751,9 +2749,9 @@ TMailWindow::TrainMessageAs(const char *CommandWord)
scriptingMessage.MakeEmpty(); scriptingMessage.MakeEmpty();
scriptingMessage.what = B_SET_PROPERTY; scriptingMessage.what = B_SET_PROPERTY;
scriptingMessage.AddSpecifier(CommandWord); scriptingMessage.AddSpecifier(commandWord);
errorCode = scriptingMessage.AddData("data", B_STRING_TYPE, errorCode = scriptingMessage.AddData("data", B_STRING_TYPE,
filePath.Path(), strlen(filePath.Path()) + 1, false /* fixed size */); filePath.Path(), strlen(filePath.Path()) + 1, false);
if (errorCode != B_OK) if (errorCode != B_OK)
goto ErrorExit; goto ErrorExit;
replyMessage.MakeEmpty(); replyMessage.MakeEmpty();
@@ -2770,9 +2768,10 @@ TMailWindow::TrainMessageAs(const char *CommandWord)
ErrorExit: ErrorExit:
beep(); beep();
sprintf(errorString, "Unable to train the message file \"%s\" as %s. " char errorString[1500];
"Possibly useful error code: %s (%" B_PRId32 ").", snprintf(errorString, sizeof(errorString), "Unable to train the message "
filePath.Path(), CommandWord, strerror(errorCode), errorCode); "file \"%s\" as %s. Possibly useful error code: %s (%" B_PRId32 ").",
filePath.Path(), commandWord, strerror(errorCode), errorCode);
BAlert* alert = new BAlert("", errorString, B_TRANSLATE("OK")); BAlert* alert = new BAlert("", errorString, B_TRANSLATE("OK"));
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(); alert->Go();
@@ -2784,9 +2783,7 @@ ErrorExit:
void void
TMailWindow::SetTitleForMessage() TMailWindow::SetTitleForMessage()
{ {
//
// Figure out the title of this message and set the title bar // Figure out the title of this message and set the title bar
//
BString title = B_TRANSLATE_SYSTEM_NAME("Mail"); BString title = B_TRANSLATE_SYSTEM_NAME("Mail");
if (fIncoming) { if (fIncoming) {
@@ -2800,19 +2797,19 @@ TMailWindow::SetTitleForMessage()
if (fApp->ShowSpamGUI() && fRef != NULL) { if (fApp->ShowSpamGUI() && fRef != NULL) {
BString classification; BString classification;
BNode node (fRef); BNode node(fRef);
char numberString [30]; char numberString[30];
BString oldTitle (title); BString oldTitle(title);
float spamRatio; float spamRatio;
if (node.InitCheck() != B_OK || node.ReadAttrString if (node.InitCheck() != B_OK || node.ReadAttrString(
("MAIL:classification", &classification) != B_OK) "MAIL:classification", &classification) != B_OK)
classification = "Unrated"; classification = "Unrated";
if (classification != "Spam" && classification != "Genuine") { if (classification != "Spam" && classification != "Genuine") {
// Uncertain, Unrated and other unknown classes, show the ratio. // Uncertain, Unrated and other unknown classes, show the ratio.
if (node.InitCheck() == B_OK && sizeof (spamRatio) == if (node.InitCheck() == B_OK && node.ReadAttr("MAIL:ratio_spam",
node.ReadAttr("MAIL:ratio_spam", B_FLOAT_TYPE, 0, B_FLOAT_TYPE, 0, &spamRatio, sizeof(spamRatio))
&spamRatio, sizeof (spamRatio))) { == sizeof(spamRatio)) {
sprintf (numberString, "%.4f", spamRatio); sprintf(numberString, "%.4f", spamRatio);
classification << " " << numberString; classification << " " << numberString;
} }
} }
@@ -2824,20 +2821,17 @@ TMailWindow::SetTitleForMessage()
} }
// /*! Open *another* message in the existing mail window. Some code here is
// Open *another* message in the existing mail window. Some code here is duplicated from various constructors.
// duplicated from various constructors. TODO: The duplicated code should be moved to a private initializer method
// The duplicated code should be in a private initializer method -- axeld. */
//
status_t status_t
TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding) TMailWindow::OpenMessage(const entry_ref* ref, uint32 characterSetForDecoding)
{ {
if (ref == NULL) if (ref == NULL)
return B_ERROR; return B_ERROR;
//
// Set some references to the email file // Set some references to the email file
//
delete fRef; delete fRef;
fRef = new entry_ref(*ref); fRef = new entry_ref(*ref);
@@ -2907,8 +2901,8 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
BMessage msg(REFS_RECEIVED); BMessage msg(REFS_RECEIVED);
entry_ref enc_ref; entry_ref enc_ref;
char *s = strtok((char *)string.String(), ":"); char* s = strtok((char*)string.String(), ":");
while (s) { while (s != NULL) {
BEntry entry(s, true); BEntry entry(s, true);
if (entry.Exists()) { if (entry.Exists()) {
entry.GetRef(&enc_ref); entry.GetRef(&enc_ref);
@@ -2942,10 +2936,8 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
SetTitleForMessage(); SetTitleForMessage();
if (fIncoming) { if (fIncoming) {
//
// Put the addresses in the 'Save Address' Menu // Put the addresses in the 'Save Address' Menu
// BMenuItem* item;
BMenuItem *item;
while ((item = fSaveAddrMenu->RemoveItem((int32)0)) != NULL) while ((item = fSaveAddrMenu->RemoveItem((int32)0)) != NULL)
delete item; delete item;
@@ -2957,10 +2949,10 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
get_address_list(addressList, fMail->From(), extract_address); get_address_list(addressList, fMail->From(), extract_address);
get_address_list(addressList, fMail->ReplyTo(), extract_address); get_address_list(addressList, fMail->ReplyTo(), extract_address);
BMessage *msg; BMessage* msg;
for (int32 i = addressList.CountItems(); i-- > 0;) { for (int32 i = addressList.CountItems(); i-- > 0;) {
char *address = (char *)addressList.RemoveItem((int32)0); char* address = (char*)addressList.RemoveItem((int32)0);
// insert the new address in alphabetical order // insert the new address in alphabetical order
int32 index = 0; int32 index = 0;
@@ -2984,9 +2976,7 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
free(address); free(address);
} }
//
// Clear out existing contents of text view. // Clear out existing contents of text view.
//
fContentView->fTextView->SetText("", (int32)0); fContentView->fTextView->SetText("", (int32)0);
fContentView->fTextView->LoadMessage(fMail, false, NULL); fContentView->fTextView->LoadMessage(fMail, false, NULL);
@@ -2999,50 +2989,17 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
} }
TMailWindow * TMailWindow*
TMailWindow::FrontmostWindow() TMailWindow::FrontmostWindow()
{ {
BAutolock locker(sWindowListLock); BAutolock locker(sWindowListLock);
if (sWindowList.CountItems() > 0) if (sWindowList.CountItems() > 0)
return (TMailWindow *)sWindowList.ItemAt(0); return (TMailWindow*)sWindowList.ItemAt(0);
return NULL; return NULL;
} }
/*
// Copied from src/kits/tracker/FindPanel.cpp.
uint32
TMailWindow::InitialMode(const BNode *node)
{
if (!node || node->InitCheck() != B_OK)
return kByNameItem;
uint32 result;
if (node->ReadAttr(kAttrQueryInitialMode, B_INT32_TYPE, 0,
(int32 *)&result, sizeof(int32)) <= 0)
return kByNameItem;
return result;
}
// Copied from src/kits/tracker/FindPanel.cpp.
int32
TMailWindow::InitialAttrCount(const BNode *node)
{
if (!node || node->InitCheck() != B_OK)
return 1;
int32 result;
if (node->ReadAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0,
&result, sizeof(int32)) <= 0)
return 1;
return result;
}*/
// #pragma mark - // #pragma mark -
@@ -3168,7 +3125,7 @@ TMailWindow::_BuildQueryString(BEntry* entry) const
{ {
int32 count = 1; int32 count = 1;
if (node.ReadAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0, if (node.ReadAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0,
(int32 *)&count, sizeof(int32)) <= 0) { (int32*)&count, sizeof(int32)) <= 0) {
count = 1; count = 1;
} }
@@ -3179,14 +3136,14 @@ TMailWindow::_BuildQueryString(BEntry* entry) const
if (count > 1) if (count > 1)
queryString << "("; queryString << "(";
char *buffer = new char[info.size]; char* buffer = new char[info.size];
if (node.ReadAttr(kAttrQueryInitialAttrs, B_MESSAGE_TYPE, 0, if (node.ReadAttr(kAttrQueryInitialAttrs, B_MESSAGE_TYPE, 0,
buffer, (size_t)info.size) == info.size) { buffer, (size_t)info.size) == info.size) {
BMessage message; BMessage message;
if (message.Unflatten(buffer) == B_OK) { if (message.Unflatten(buffer) == B_OK) {
for (int32 index = 0; /*index < count*/; index++) { for (int32 index = 0; /*index < count*/; index++) {
const char *field; const char* field;
const char *value; const char* value;
if (message.FindString("menuSelection", index, &field) if (message.FindString("menuSelection", index, &field)
!= B_OK != B_OK
|| message.FindString("attrViewText", index, &value) || message.FindString("attrViewText", index, &value)
+11 -8
View File
@@ -65,8 +65,9 @@ class BMenuBar;
class BMenuItem; class BMenuItem;
class Words; class Words;
class TMailWindow : public BWindow { class TMailWindow : public BWindow {
public: public:
TMailWindow(BRect frame, const char* title, TMailWindow(BRect frame, const char* title,
TMailApp* app, const entry_ref* ref, TMailApp* app, const entry_ref* ref,
const char* to, const BFont *font, const char* to, const BFont *font,
@@ -94,7 +95,7 @@ class TMailWindow : public BWindow {
void PrintSetup(); void PrintSetup();
void Reply(entry_ref*, TMailWindow*, uint32); void Reply(entry_ref*, TMailWindow*, uint32);
void CopyMessage(entry_ref* ref, TMailWindow* src); void CopyMessage(entry_ref* ref, TMailWindow* src);
status_t Send(bool); status_t Send(bool now);
status_t SaveAsDraft(); status_t SaveAsDraft();
status_t OpenMessage(const entry_ref* ref, status_t OpenMessage(const entry_ref* ref,
uint32 characterSetForDecoding uint32 characterSetForDecoding
@@ -116,13 +117,13 @@ class TMailWindow : public BWindow {
void UpdateViews(); void UpdateViews();
void UpdatePreferences(); void UpdatePreferences();
protected: protected:
void SetTitleForMessage(); void SetTitleForMessage();
void AddEnclosure(BMessage* msg); void AddEnclosure(BMessage* msg);
void BuildToolBar(); void BuildToolBar();
status_t TrainMessageAs(const char* commandWord); status_t TrainMessageAs(const char* commandWord);
private: private:
void _UpdateSizeLimits(); void _UpdateSizeLimits();
status_t _GetQueryPath(BPath* path) const; status_t _GetQueryPath(BPath* path) const;
@@ -134,6 +135,9 @@ class TMailWindow : public BWindow {
void _SetDownloading(bool downloading); void _SetDownloading(bool downloading);
static BBitmap* _RetrieveVectorIcon(int32 id);
private:
TMailApp* fApp; TMailApp* fApp;
BEmailMessage* fMail; BEmailMessage* fMail;
@@ -166,13 +170,12 @@ class TMailWindow : public BWindow {
BMenu* fQueryMenu; BMenu* fQueryMenu;
BMenu* fLeaveStatusMenu; BMenu* fLeaveStatusMenu;
static BBitmap* _RetrieveVectorIcon(int32 id);
struct BitmapItem { struct BitmapItem {
BBitmap* bm; BBitmap* bm;
int32 id; int32 id;
}; };
static BObjectList<BitmapItem> fBitmapCache; static BObjectList<BitmapItem> sBitmapCache;
static BLocker fBitmapCacheLock; static BLocker sBitmapCacheLock;
BToolBar* fToolBar; BToolBar* fToolBar;
@@ -213,5 +216,5 @@ class TMailWindow : public BWindow {
bool fDownloading; bool fDownloading;
}; };
#endif // _MAIL_WINDOW_H
#endif // _MAIL_WINDOW_H