Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18740 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-09-04 20:32:07 +00:00
parent a6ab64cef3
commit 1f2d7e39bf
2 changed files with 208 additions and 259 deletions
+161 -204
View File
@@ -32,38 +32,6 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
//--------------------------------------------------------------------
//
// Header.cpp
//
//--------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <StorageKit.h>
#include <InterfaceKit.h>
#include <StringView.h>
#include <E-mail.h>
#include <String.h>
#include <PopUpMenu.h>
#include <fs_index.h>
#include <fs_info.h>
#include <map>
#include <MailSettings.h>
#include <MailMessage.h>
#include <String.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
using namespace BPrivate;
using std::map;
#include "Mail.h" #include "Mail.h"
#include "Header.h" #include "Header.h"
#include "Utilities.h" #include "Utilities.h"
@@ -72,10 +40,38 @@ using std::map;
#include "Prefs.h" #include "Prefs.h"
#include <MDRLanguage.h> #include <MDRLanguage.h>
#include <MailSettings.h>
#include <MailMessage.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <E-mail.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <Query.h>
#include <String.h>
#include <StringView.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <Window.h>
#include <fs_index.h>
#include <fs_info.h>
#include <ctype.h>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace BPrivate;
using std::map;
extern uint32 gDefaultChain; extern uint32 gDefaultChain;
const char *kDateLabel = "Date:"; const char* kDateLabel = "Date:";
const uint32 kMsgFrom = 'hFrm'; const uint32 kMsgFrom = 'hFrm';
const uint32 kMsgEncoding = 'encd'; const uint32 kMsgEncoding = 'encd';
const uint32 kMsgAddressChosen = 'acsn'; const uint32 kMsgAddressChosen = 'acsn';
@@ -86,8 +82,9 @@ class QPopupMenu : public QueryMenu {
QPopupMenu(const char *title); QPopupMenu(const char *title);
private: private:
void AddPersonItem(const entry_ref *ref, ino_t node, BString &name, BString &email, void AddPersonItem(const entry_ref *ref, ino_t node, BString &name,
const char *attr, BMenu *groupMenu, BMenuItem *superItem); BString &email, const char *attr, BMenu *groupMenu,
BMenuItem *superItem);
protected: protected:
virtual void EntryCreated(const entry_ref &ref, ino_t node); virtual void EntryCreated(const entry_ref &ref, ino_t node);
@@ -96,27 +93,21 @@ class QPopupMenu : public QueryMenu {
int32 fGroups; // Current number of "group" submenus. Includes All People if present. int32 fGroups; // Current number of "group" submenus. Includes All People if present.
}; };
//==================================================================== struct CompareBStrings {
bool
struct CompareBStrings operator()(const BString *s1, const BString *s2) const
{
bool operator()(const BString *s1, const BString *s2) const
{ {
return (s1->Compare(*s2) < 0); return (s1->Compare(*s2) < 0);
} }
}; };
//====================================================================
// #pragma mark - THeaderView
THeaderView::THeaderView ( THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,
BRect rect, BEmailMessage *mail, bool resending, uint32 defaultCharacterSet)
BRect windowRect, : BBox(rect, "m_header", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW, B_NO_BORDER),
bool incoming,
BEmailMessage *mail,
bool resending,
uint32 defaultCharacterSet
) : BBox(rect, "m_header", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW, B_NO_BORDER),
fAccountMenu(NULL), fAccountMenu(NULL),
fEncodingMenu(NULL), fEncodingMenu(NULL),
fChain(gDefaultChain), fChain(gDefaultChain),
@@ -135,8 +126,8 @@ THeaderView::THeaderView (
fToMenu(NULL), fToMenu(NULL),
fEmailList(NULL) fEmailList(NULL)
{ {
BMenuField *field; BMenuField* field;
BMessage *msg; BMessage* msg;
BFont font = *be_plain_font; BFont font = *be_plain_font;
font.SetSize(FONT_SIZE); font.SetSize(FONT_SIZE);
@@ -145,8 +136,7 @@ THeaderView::THeaderView (
MDR_DIALECT_CHOICE ("Enclosures: ","添付ファイル:")) + 9; MDR_DIALECT_CHOICE ("Enclosures: ","添付ファイル:")) + 9;
float y = TO_FIELD_V; float y = TO_FIELD_V;
if (!fIncoming) if (!fIncoming) {
{
InitEmailCompletion(); InitEmailCompletion();
InitGroupCompletion(); InitGroupCompletion();
} }
@@ -165,31 +155,31 @@ THeaderView::THeaderView (
// bug). // bug).
float widestCharacterSet = 0; float widestCharacterSet = 0;
bool marked_charset = false; bool markedCharSet = false;
BMenuItem * item; BMenuItem* item;
fEncodingMenu = new BPopUpMenu (B_EMPTY_STRING); fEncodingMenu = new BPopUpMenu(B_EMPTY_STRING);
BCharacterSetRoster roster; BCharacterSetRoster roster;
BCharacterSet charset; BCharacterSet charset;
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { while (roster.GetNextCharacterSet(&charset) == B_OK) {
BString name(charset.GetPrintName()); BString name(charset.GetPrintName());
const char * mime = charset.GetMIMEName(); const char* mime = charset.GetMIMEName();
if (mime) { if (mime)
name << " (" << mime << ")"; name << " (" << mime << ")";
}
uint32 convertID;
if (mime == NULL || strcasecmp(mime, "UTF-8") != 0)
convertID = charset.GetConversionID();
else
convertID = B_MAIL_UTF8_CONVERSION;
msg = new BMessage(kMsgEncoding); msg = new BMessage(kMsgEncoding);
uint32 convert_id; msg->AddInt32("charset", convertID);
if ((mime == 0) || (strcasecmp(mime, "UTF-8") != 0)) {
convert_id = charset.GetConversionID();
} else {
convert_id = B_MAIL_UTF8_CONVERSION;
}
msg->AddInt32("charset", convert_id);
fEncodingMenu->AddItem(item = new BMenuItem(name.String(), msg)); fEncodingMenu->AddItem(item = new BMenuItem(name.String(), msg));
if (convert_id == fCharacterSetUserSees && !marked_charset) { if (convertID == fCharacterSetUserSees && !markedCharSet) {
item->SetMarked(true); item->SetMarked(true);
marked_charset = true; markedCharSet = true;
} }
if (font.StringWidth(name.String()) > widestCharacterSet) if (font.StringWidth(name.String()) > widestCharacterSet)
widestCharacterSet = font.StringWidth(name.String()); widestCharacterSet = font.StringWidth(name.String());
@@ -198,9 +188,9 @@ THeaderView::THeaderView (
msg = new BMessage(kMsgEncoding); msg = new BMessage(kMsgEncoding);
msg->AddInt32("charset", B_MAIL_US_ASCII_CONVERSION); msg->AddInt32("charset", B_MAIL_US_ASCII_CONVERSION);
fEncodingMenu->AddItem(item = new BMenuItem("US-ASCII", msg)); fEncodingMenu->AddItem(item = new BMenuItem("US-ASCII", msg));
if (fCharacterSetUserSees == B_MAIL_US_ASCII_CONVERSION && !marked_charset) { if (fCharacterSetUserSees == B_MAIL_US_ASCII_CONVERSION && !markedCharSet) {
item->SetMarked(true); item->SetMarked(true);
marked_charset = true; markedCharSet = true;
} }
if (!resending && fIncoming) { if (!resending && fIncoming) {
@@ -209,10 +199,9 @@ THeaderView::THeaderView (
msg = new BMessage(kMsgEncoding); msg = new BMessage(kMsgEncoding);
msg->AddInt32("charset", B_MAIL_NULL_CONVERSION); msg->AddInt32("charset", B_MAIL_NULL_CONVERSION);
fEncodingMenu->AddItem(item = new BMenuItem("Automatic", msg)); fEncodingMenu->AddItem(item = new BMenuItem("Automatic", msg));
if (!marked_charset) { if (!markedCharSet)
item->SetMarked(true); item->SetMarked(true);
} }
}
// First line of the header, From for reading e-mails (includes the // First line of the header, From for reading e-mails (includes the
// character set choice at the right), To when composing (nothing else in // character set choice at the right), To when composing (nothing else in
@@ -220,8 +209,7 @@ THeaderView::THeaderView (
BRect r; BRect r;
char string[20]; char string[20];
if (fIncoming && !resending) if (fIncoming && !resending) {
{
// Set up the character set pop-up menu on the right of "To" box. // Set up the character set pop-up menu on the right of "To" box.
r.Set (windowRect.Width() - widestCharacterSet - r.Set (windowRect.Width() - widestCharacterSet -
font.StringWidth (DECODING_TEXT) - 2 * SEPARATOR_MARGIN, font.StringWidth (DECODING_TEXT) - 2 * SEPARATOR_MARGIN,
@@ -236,28 +224,26 @@ THeaderView::THeaderView (
r.Set(x - font.StringWidth(FROM_TEXT) - 11, y, r.Set(x - font.StringWidth(FROM_TEXT) - 11, y,
field->Frame().left - SEPARATOR_MARGIN, y + TO_FIELD_HEIGHT); field->Frame().left - SEPARATOR_MARGIN, y + TO_FIELD_HEIGHT);
sprintf(string, FROM_TEXT); sprintf(string, FROM_TEXT);
} } else {
else
{
r.Set(x - 11, y, windowRect.Width() - SEPARATOR_MARGIN, y + TO_FIELD_HEIGHT); r.Set(x - 11, y, windowRect.Width() - SEPARATOR_MARGIN, y + TO_FIELD_HEIGHT);
string[0] = 0; string[0] = 0;
} }
y += FIELD_HEIGHT; y += FIELD_HEIGHT;
fTo = new TTextControl(r, string, new BMessage(TO_FIELD), fIncoming, resending, fTo = new TTextControl(r, string, new BMessage(TO_FIELD), fIncoming, resending,
B_FOLLOW_LEFT_RIGHT); B_FOLLOW_LEFT_RIGHT);
if (!fIncoming || resending) if (!fIncoming || resending) {
{
fTo->SetChoiceList(&fEmailList); fTo->SetChoiceList(&fEmailList);
fTo->SetAutoComplete(true); fTo->SetAutoComplete(true);
} }
AddChild(fTo); AddChild(fTo);
msg = new BMessage(FIELD_CHANGED); msg = new BMessage(FIELD_CHANGED);
msg->AddInt32("bitmask", FIELD_TO); msg->AddInt32("bitmask", FIELD_TO);
fTo->SetModificationMessage(msg); fTo->SetModificationMessage(msg);
if (!fIncoming || resending) if (!fIncoming || resending) {
{
r.right = r.left + 8; r.right = r.left + 8;
r.left = r.right - be_plain_font->StringWidth(TO_TEXT) - 30; r.left = r.right - be_plain_font->StringWidth(TO_TEXT) - 30;
r.top -= 1; r.top -= 1;
@@ -269,8 +255,7 @@ THeaderView::THeaderView (
} }
// "From:" accounts Menu and Encoding Menu. // "From:" accounts Menu and Encoding Menu.
if (!fIncoming || resending) if (!fIncoming || resending) {
{
// Put the character set box on the right of the From field. // Put the character set box on the right of the From field.
r.Set (windowRect.Width() - widestCharacterSet - r.Set (windowRect.Width() - widestCharacterSet -
font.StringWidth (ENCODING_TEXT) - 2 * SEPARATOR_MARGIN, font.StringWidth (ENCODING_TEXT) - 2 * SEPARATOR_MARGIN,
@@ -289,15 +274,12 @@ THeaderView::THeaderView (
fAccountMenu = new BPopUpMenu(B_EMPTY_STRING); fAccountMenu = new BPopUpMenu(B_EMPTY_STRING);
BList chains; BList chains;
if (GetOutboundMailChains(&chains) >= B_OK) if (GetOutboundMailChains(&chains) >= B_OK) {
{
bool marked = false; bool marked = false;
for (int32 i = 0;i < chains.CountItems();i++) for (int32 i = 0; i < chains.CountItems(); i++) {
{
BMailChain *chain = (BMailChain *)chains.ItemAt(i); BMailChain *chain = (BMailChain *)chains.ItemAt(i);
BString name = chain->Name(); BString name = chain->Name();
if ((msg = chain->MetaData()) != NULL) if ((msg = chain->MetaData()) != NULL) {
{
name << ": " << msg->FindString("real_name") name << ": " << msg->FindString("real_name")
<< " <" << msg->FindString("reply_to") << ">"; << " <" << msg->FindString("reply_to") << ">";
} }
@@ -305,24 +287,20 @@ THeaderView::THeaderView (
msg->AddInt32("id",chain->ID()); msg->AddInt32("id",chain->ID());
if (gDefaultChain == chain->ID()) if (gDefaultChain == chain->ID()) {
{
item->SetMarked(true); item->SetMarked(true);
marked = true; marked = true;
} }
fAccountMenu->AddItem(item); fAccountMenu->AddItem(item);
delete chain; delete chain;
} }
if (!marked)
{ if (!marked) {
BMenuItem *item = fAccountMenu->ItemAt(0); BMenuItem *item = fAccountMenu->ItemAt(0);
if (item != NULL) if (item != NULL) {
{
item->SetMarked(true); item->SetMarked(true);
fChain = item->Message()->FindInt32("id"); fChain = item->Message()->FindInt32("id");
} } else {
else
{
fAccountMenu->AddItem(item = new BMenuItem("<none>",NULL)); fAccountMenu->AddItem(item = new BMenuItem("<none>",NULL));
item->SetEnabled(false); item->SetEnabled(false);
fChain = ~0UL; fChain = ~0UL;
@@ -342,9 +320,8 @@ THeaderView::THeaderView (
AddChild(field); AddChild(field);
y += FIELD_HEIGHT; y += FIELD_HEIGHT;
} } else {
else // To: account // To: account
{
bool account = count_pop_accounts() > 0; bool account = count_pop_accounts() > 0;
r.Set(x - font.StringWidth(TO_TEXT) - 11, y, r.Set(x - font.StringWidth(TO_TEXT) - 11, y,
@@ -355,8 +332,7 @@ THeaderView::THeaderView (
fAccountTo->SetEnabled(false); fAccountTo->SetEnabled(false);
AddChild(fAccountTo); AddChild(fAccountTo);
if (account) if (account) {
{
r.left = r.right + 6; r.right = windowRect.Width() - SEPARATOR_MARGIN; r.left = r.right + 6; r.right = windowRect.Width() - SEPARATOR_MARGIN;
fAccount = new TTextControl(r, ACCOUNT_TEXT, NULL, fIncoming, false, B_FOLLOW_RIGHT | B_FOLLOW_TOP); fAccount = new TTextControl(r, ACCOUNT_TEXT, NULL, fIncoming, false, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fAccount->SetEnabled(false); fAccount->SetEnabled(false);
@@ -379,8 +355,8 @@ THeaderView::THeaderView (
fSubject->SetEnabled(false); fSubject->SetEnabled(false);
--y; --y;
if (!fIncoming)
{ if (!fIncoming) {
r.Set(x - 11, y, CC_FIELD_H + CC_FIELD_WIDTH, y + CC_FIELD_HEIGHT); r.Set(x - 11, y, CC_FIELD_H + CC_FIELD_WIDTH, y + CC_FIELD_HEIGHT);
fCc = new TTextControl(r, "", new BMessage(CC_FIELD), fIncoming, false); fCc = new TTextControl(r, "", new BMessage(CC_FIELD), fIncoming, false);
fCc->SetChoiceList(&fEmailList); fCc->SetChoiceList(&fEmailList);
@@ -418,9 +394,7 @@ THeaderView::THeaderView (
field->SetDivider(0.0); field->SetDivider(0.0);
field->SetEnabled(true); field->SetEnabled(true);
AddChild(field); AddChild(field);
} } else {
else
{
r.Set(x - font.StringWidth(kDateLabel) - 10, y + 4, r.Set(x - font.StringWidth(kDateLabel) - 10, y + 4,
windowRect.Width(), y + TO_FIELD_HEIGHT + 1); windowRect.Width(), y + TO_FIELD_HEIGHT + 1);
y += TO_FIELD_HEIGHT + 5; y += TO_FIELD_HEIGHT + 5;
@@ -451,11 +425,9 @@ THeaderView::InitEmailCompletion()
query.Fetch(); query.Fetch();
entry_ref ref; entry_ref ref;
while (query.GetNextRef (&ref) == B_OK) while (query.GetNextRef (&ref) == B_OK) {
{
BNode file; BNode file;
if (file.SetTo(&ref) == B_OK) if (file.SetTo(&ref) == B_OK) {
{
// Add the e-mail address as an auto-complete string. // Add the e-mail address as an auto-complete string.
BString email; BString email;
if (file.ReadAttrString("META:email", &email) >= B_OK) if (file.ReadAttrString("META:email", &email) >= B_OK)
@@ -482,11 +454,10 @@ THeaderView::InitEmailCompletion()
// multiple keyword (so you can have several e-mail addresses in // multiple keyword (so you can have several e-mail addresses in
// one attribute, perhaps comma separated) indices! Which aren't // one attribute, perhaps comma separated) indices! Which aren't
// yet in BFS. // yet in BFS.
for (int16 i = 2;i < 6;i++) for (int16 i = 2; i < 6; i++) {
{
char attr[16]; char attr[16];
sprintf(attr,"META:email%d",i); sprintf(attr, "META:email%d", i);
if (file.ReadAttrString(attr,&email) >= B_OK) if (file.ReadAttrString(attr, &email) >= B_OK)
fEmailList.AddChoice(email.String()); fEmailList.AddChoice(email.String());
} }
} }
@@ -507,11 +478,10 @@ THeaderView::InitGroupCompletion()
query.SetPredicate("META:group=**"); query.SetPredicate("META:group=**");
query.Fetch(); query.Fetch();
map<BString *, BString *, CompareBStrings> group_map; map<BString *, BString *, CompareBStrings> groupMap;
entry_ref ref; entry_ref ref;
BNode file; BNode file;
while (query.GetNextRef(&ref) == B_OK) while (query.GetNextRef(&ref) == B_OK) {
{
if (file.SetTo(&ref) != B_OK) if (file.SetTo(&ref) != B_OK)
continue; continue;
@@ -526,29 +496,28 @@ THeaderView::InitGroupCompletion()
if (address.Length() == 0) if (address.Length() == 0)
continue; continue;
char *grp = groups.LockBuffer(groups.Length()); char *group = groups.LockBuffer(groups.Length());
char *next = strchr(grp, ','); char *next = strchr(group, ',');
for (;;) for (;;) {
{ if (next)
if (next) *next = 0; *next = 0;
while (*grp && *grp == ' ') grp++;
BString *group = new BString(grp); while (*group && *group == ' ')
group++;
BString *groupString = new BString(group);
BString *addressListString = NULL; BString *addressListString = NULL;
// nobody is in this group yet, start it off // nobody is in this group yet, start it off
if (group_map[group] == NULL) if (groupMap[groupString] == NULL) {
{ addressListString = new BString(*groupString);
addressListString = new BString(*group);
addressListString->Append(" "); addressListString->Append(" ");
group_map[group] = addressListString; groupMap[groupString] = addressListString;
} } else {
else addressListString = groupMap[groupString];
{
addressListString = group_map[group];
addressListString->Append(", "); addressListString->Append(", ");
delete group; delete groupString;
} }
// Append the user's address to the end of the string with the // Append the user's address to the end of the string with the
@@ -565,20 +534,19 @@ THeaderView::InitGroupCompletion()
if (!next) if (!next)
break; break;
grp = next+1; group = next + 1;
next = strchr(grp, ','); next = strchr(group, ',');
} }
} }
map<BString *, BString *, CompareBStrings>::iterator iter; map<BString *, BString *, CompareBStrings>::iterator iter;
for (iter = group_map.begin(); iter != group_map.end();) for (iter = groupMap.begin(); iter != groupMap.end();) {
{ BString *group = iter->first;
BString *grp = iter->first;
BString *addr = iter->second; BString *addr = iter->second;
fEmailList.AddChoice(addr->String()); fEmailList.AddChoice(addr->String());
++iter; ++iter;
group_map.erase(grp); groupMap.erase(group);
delete grp; delete group;
delete addr; delete addr;
} }
} }
@@ -587,15 +555,13 @@ THeaderView::InitGroupCompletion()
void void
THeaderView::MessageReceived(BMessage *msg) THeaderView::MessageReceived(BMessage *msg)
{ {
switch (msg->what) switch (msg->what) {
{
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
{ {
BTextView *textView = dynamic_cast<BTextView *>(Window()->CurrentFocus()); BTextView *textView = dynamic_cast<BTextView *>(Window()->CurrentFocus());
if (dynamic_cast<TTextControl *>(textView->Parent()) != NULL) if (dynamic_cast<TTextControl *>(textView->Parent()) != NULL)
textView->Parent()->MessageReceived(msg); textView->Parent()->MessageReceived(msg);
else else {
{
BMessage message(*msg); BMessage message(*msg);
message.what = REFS_RECEIVED; message.what = REFS_RECEIVED;
Window()->PostMessage(&message, Window()); Window()->PostMessage(&message, Window());
@@ -618,10 +584,10 @@ THeaderView::MessageReceived(BMessage *msg)
case kMsgEncoding: case kMsgEncoding:
{ {
BMessage message(*msg); BMessage message(*msg);
int32 tempInt; int32 charSet;
if (msg->FindInt32("charset", &tempInt) == B_OK) if (msg->FindInt32("charset", &charSet) == B_OK)
fCharacterSetUserSees = tempInt; fCharacterSetUserSees = charSet;
message.what = CHARSET_CHOICE_MADE; message.what = CHARSET_CHOICE_MADE;
message.AddInt32 ("charset", fCharacterSetUserSees); message.AddInt32 ("charset", fCharacterSetUserSees);
@@ -633,20 +599,17 @@ THeaderView::MessageReceived(BMessage *msg)
void void
THeaderView::AttachedToWindow(void) THeaderView::AttachedToWindow()
{ {
if (fToMenu) if (fToMenu) {
{
fToMenu->SetTargetForItems(fTo); fToMenu->SetTargetForItems(fTo);
fToMenu->SetPredicate("META:email=**"); fToMenu->SetPredicate("META:email=**");
} }
if (fCcMenu) if (fCcMenu) {
{
fCcMenu->SetTargetForItems(fCc); fCcMenu->SetTargetForItems(fCc);
fCcMenu->SetPredicate("META:email=**"); fCcMenu->SetPredicate("META:email=**");
} }
if (fBccMenu) if (fBccMenu) {
{
fBccMenu->SetTargetForItems(fBcc); fBccMenu->SetTargetForItems(fBcc);
fBccMenu->SetPredicate("META:email=**"); fBccMenu->SetPredicate("META:email=**");
} }
@@ -672,19 +635,14 @@ THeaderView::AttachedToWindow(void)
status_t status_t
THeaderView::LoadMessage(BEmailMessage *mail) THeaderView::LoadMessage(BEmailMessage *mail)
{ {
//
// Set the date on this message // Set the date on this message
//
const char *dateField = mail->Date(); const char *dateField = mail->Date();
char string[256]; char string[256];
sprintf(string, "%s %s", kDateLabel, dateField != NULL ? dateField : "Unknown"); sprintf(string, "%s %s", kDateLabel, dateField != NULL ? dateField : "Unknown");
fDate->SetText(string); fDate->SetText(string);
//
// Set contents of header fields // Set contents of header fields
// if (fIncoming && !fResending) {
if (fIncoming && !fResending)
{
if (fBcc != NULL) if (fBcc != NULL)
fBcc->SetEnabled(false); fBcc->SetEnabled(false);
@@ -716,8 +674,7 @@ THeaderView::LoadMessage(BEmailMessage *mail)
} }
//==================================================================== // #pragma mark - TTextControl
// #pragma mark -
TTextControl::TTextControl(BRect rect, char *label, BMessage *msg, TTextControl::TTextControl(BRect rect, char *label, BMessage *msg,
@@ -756,17 +713,17 @@ TTextControl::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_SIMPLE_DATA: { case B_SIMPLE_DATA: {
if ((fIncoming == true) && (fResending == false)) return; if (fIncoming && !fResending)
return;
int32 buttons = -1; int32 buttons = -1;
BPoint point; BPoint point;
if (msg->FindInt32("buttons", &buttons) != B_OK)
if (msg->FindInt32("buttons", &buttons) != B_OK) {
buttons = B_PRIMARY_MOUSE_BUTTON; buttons = B_PRIMARY_MOUSE_BUTTON;
};
if (buttons != B_PRIMARY_MOUSE_BUTTON) { if (buttons != B_PRIMARY_MOUSE_BUTTON
if (msg->FindPoint("_drop_point_", &point) != B_OK) return; && msg->FindPoint("_drop_point_", &point) != B_OK)
}; return;
BMessage message(REFS_RECEIVED); BMessage message(REFS_RECEIVED);
bool enclosure = false; bool enclosure = false;
@@ -785,13 +742,12 @@ TTextControl::MessageReceived(BMessage *msg)
char type[B_FILE_NAME_LENGTH]; char type[B_FILE_NAME_LENGTH];
info.GetType(type); info.GetType(type);
if (fCommand != SUBJECT_FIELD && if (fCommand != SUBJECT_FIELD
!strcmp(type,"application/x-person")) { && !strcmp(type,"application/x-person")) {
// add person's E-mail address to the To: field // add person's E-mail address to the To: field
BString attr = ""; BString attr = "";
if (buttons == B_PRIMARY_MOUSE_BUTTON) { if (buttons == B_PRIMARY_MOUSE_BUTTON) {
if (msg->FindString("attr", &attr) < B_OK) if (msg->FindString("attr", &attr) < B_OK)
attr = "META:email"; // If not META:email3 etc. attr = "META:email"; // If not META:email3 etc.
} else { } else {
@@ -800,16 +756,19 @@ TTextControl::MessageReceived(BMessage *msg)
char buffer[B_ATTR_NAME_LENGTH]; char buffer[B_ATTR_NAME_LENGTH];
if (fRefDropMenu) delete fRefDropMenu; delete fRefDropMenu;
fRefDropMenu = new BPopUpMenu("RecipientMenu"); fRefDropMenu = new BPopUpMenu("RecipientMenu");
while (node.GetNextAttrName(buffer) == B_OK) { while (node.GetNextAttrName(buffer) == B_OK) {
if (strstr(buffer, "email") <= 0) continue; if (strstr(buffer, "email") <= 0)
continue;
attr = buffer; attr = buffer;
BString address; BString address;
ReadAttrString(&node, buffer, &address); ReadAttrString(&node, buffer, &address);
if (address.Length() <= 0) continue; if (address.Length() <= 0)
continue;
BMessage *itemMsg = new BMessage(kMsgAddressChosen); BMessage *itemMsg = new BMessage(kMsgAddressChosen);
itemMsg->AddString("address", address.String()); itemMsg->AddString("address", address.String());
@@ -818,7 +777,7 @@ TTextControl::MessageReceived(BMessage *msg)
BMenuItem *item = new BMenuItem(address.String(), BMenuItem *item = new BMenuItem(address.String(),
itemMsg); itemMsg);
fRefDropMenu->AddItem(item); fRefDropMenu->AddItem(item);
}; }
if (fRefDropMenu->CountItems() > 1) { if (fRefDropMenu->CountItems() > 1) {
fRefDropMenu->SetTargetForItems(this); fRefDropMenu->SetTargetForItems(this);
@@ -827,26 +786,27 @@ TTextControl::MessageReceived(BMessage *msg)
} else { } else {
delete fRefDropMenu; delete fRefDropMenu;
fRefDropMenu = NULL; fRefDropMenu = NULL;
}; }
}; }
BString email; BString email;
ReadAttrString(&file,attr.String(),&email); ReadAttrString(&file,attr.String(),&email);
/* we got something... */ // we got something...
if (email.Length() > 0) { if (email.Length() > 0) {
/* see if we can get a username as well */ // see if we can get a username as well
BString name; BString name;
ReadAttrString(&file,"META:name",&name); ReadAttrString(&file, "META:name", &name);
BString address; BString address;
/* if we have no Name, just use the email address */ if (name.Length() == 0) {
if (name.Length() == 0) // if we have no Name, just use the email address
address = email; address = email;
else { } else {
/* otherwise, pretty-format it */ // otherwise, pretty-format it
address << "\"" << name << "\" <" << email << ">"; address << "\"" << name << "\" <" << email << ">";
} }
if (addressList.Length() > 0) if (addressList.Length() > 0)
addressList << ", "; addressList << ", ";
addressList << address; addressList << address;
@@ -868,10 +828,10 @@ TTextControl::MessageReceived(BMessage *msg)
textView->Insert(addressList.String()); textView->Insert(addressList.String());
} }
if (enclosure) Window()->PostMessage(&message, Window()); if (enclosure)
Window()->PostMessage(&message, Window());
break; break;
}; }
case M_SELECT: case M_SELECT:
{ {
@@ -886,8 +846,9 @@ TTextControl::MessageReceived(BMessage *msg)
BString address; BString address;
entry_ref ref; entry_ref ref;
if (msg->FindString("address", &address) != B_OK) return; if (msg->FindString("address", &address) != B_OK
if (msg->FindRef("ref", &ref) != B_OK) return; || msg->FindRef("ref", &ref) != B_OK)
return;
if (address.Length() > 0) { if (address.Length() > 0) {
BString name; BString name;
@@ -899,18 +860,18 @@ TTextControl::MessageReceived(BMessage *msg)
if (name.Length() > 0) { if (name.Length() > 0) {
display = ""; display = "";
display << "\"" << name << "\" <" << address << ">"; display << "\"" << name << "\" <" << address << ">";
}; }
BTextView *textView = TextView(); BTextView *textView = TextView();
int end = textView->TextLength(); int end = textView->TextLength();
if (end != 0) { if (end != 0) {
textView->Select(end, end); textView->Select(end, end);
textView->Insert(", "); textView->Insert(", ");
}; }
textView->Insert(display.String()); textView->Insert(display.String());
}
}; break;
} break; }
default: default:
// BTextControl::MessageReceived(msg); // BTextControl::MessageReceived(msg);
@@ -922,15 +883,11 @@ TTextControl::MessageReceived(BMessage *msg)
bool bool
TTextControl::HasFocus() TTextControl::HasFocus()
{ {
BTextView *textView = TextView(); return TextView()->IsFocus();
return textView->IsFocus();
} }
//==================================================================== // #pragma mark - QPopupMenu
// QPopupMenu (definition at the beginning of this file)
// #pragma mark -
QPopupMenu::QPopupMenu(const char *title) QPopupMenu::QPopupMenu(const char *title)
+9 -17
View File
@@ -31,25 +31,21 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders. names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
//--------------------------------------------------------------------
//
// Header.h
//
//--------------------------------------------------------------------
#ifndef _HEADER_H #ifndef _HEADER_H
#define _HEADER_H #define _HEADER_H
#include <fs_attr.h>
#include "ComboBox.h"
#include <Box.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Point.h> #include <Point.h>
#include <Rect.h> #include <Rect.h>
#include <TextControl.h> #include <TextControl.h>
#include <View.h> #include <View.h>
#include <Window.h> #include <Window.h>
#include <fs_attr.h>
#include "ComboBox.h"
#define TO_TEXT "To:" #define TO_TEXT "To:"
#define FROM_TEXT "From:" #define FROM_TEXT "From:"
@@ -91,12 +87,11 @@ class BMenuItem;
class BPopupMenu; class BPopupMenu;
class QPopupMenu; class QPopupMenu;
//====================================================================
class THeaderView : public BBox class THeaderView : public BBox {
{
public: public:
THeaderView(BRect, BRect, bool incoming, BEmailMessage *mail, bool resending, uint32 defaultCharacterSet); THeaderView(BRect, BRect, bool incoming, BEmailMessage *mail,
bool resending, uint32 defaultCharacterSet);
virtual void MessageReceived(BMessage *); virtual void MessageReceived(BMessage *);
virtual void AttachedToWindow(void); virtual void AttachedToWindow(void);
@@ -126,10 +121,7 @@ class THeaderView : public BBox
BDefaultChoiceList fEmailList; BDefaultChoiceList fEmailList;
}; };
//==================================================================== class TTextControl : public BComboBox {
class TTextControl : public BComboBox
{
public: public:
TTextControl(BRect, char*, BMessage*, bool, bool, int32 resizingMode = B_FOLLOW_NONE); TTextControl(BRect, char*, BMessage*, bool, bool, int32 resizingMode = B_FOLLOW_NONE);