RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / apps / mail / Prefs.cpp
blob0996e1a836357cbc0c456c7f686b234ca621aa45
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or
30 registered trademarks of Be Incorporated in the United States and other
31 countries. Other brand product names are registered trademarks or trademarks
32 of their respective holders. All rights reserved.
36 #include "Prefs.h"
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <strings.h>
42 #include <Application.h>
43 #include <CharacterSet.h>
44 #include <CharacterSetRoster.h>
45 #include <E-mail.h>
46 #include <GridView.h>
47 #include <LayoutBuilder.h>
48 #include <InterfaceKit.h>
49 #include <Locale.h>
50 #include <MailSettings.h>
51 #include <mail_encoding.h>
52 #include <StorageKit.h>
53 #include <String.h>
55 using namespace BPrivate;
57 #include "MailApp.h"
58 #include "MailSupport.h"
59 #include "MailWindow.h"
60 #include "Messages.h"
61 #include "Settings.h"
62 #include "Signature.h"
65 #define B_TRANSLATION_CONTEXT "Mail"
67 enum P_MESSAGES {
68 P_OK = 128, P_CANCEL, P_REVERT, P_FONT,
69 P_SIZE, P_LEVEL, P_WRAP, P_ATTACH_ATTRIBUTES,
70 P_SIG, P_ENC, P_WARN_UNENCODABLE,
71 P_SPELL_CHECK_START_ON, P_BUTTON_BAR,
72 P_ACCOUNT, P_REPLYTO, P_REPLY_PREAMBLE,
73 P_COLORED_QUOTES, P_MARK_READ
77 static inline void
78 add_menu_to_layout(BMenuField* menu, BGridLayout* layout, int32& row)
80 menu->SetAlignment(B_ALIGN_RIGHT);
81 layout->AddItem(menu->CreateLabelLayoutItem(), 0, row);
82 layout->AddItem(menu->CreateMenuBarLayoutItem(), 1, row, 2);
83 row++;
87 // #pragma mark -
90 TPrefsWindow::TPrefsWindow(BPoint leftTop, BFont* font, int32* level,
91 bool* wrap, bool* attachAttributes, bool* cquotes, int32* account,
92 int32* replyTo, char** preamble, char** sig, uint32* encoding,
93 bool* warnUnencodable, bool* spellCheckStartOn, bool* autoMarkRead,
94 uint8* buttonBar)
96 BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + 100, leftTop.y + 100),
97 B_TRANSLATE("Mail preferences"),
98 B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
99 | B_AUTO_UPDATE_SIZE_LIMITS),
101 fNewWrap(wrap),
102 fWrap(*fNewWrap),
104 fNewAttachAttributes(attachAttributes),
105 fAttachAttributes(*fNewAttachAttributes),
107 fNewButtonBar(buttonBar),
108 fButtonBar(*fNewButtonBar),
110 fNewColoredQuotes(cquotes),
111 fColoredQuotes(*fNewColoredQuotes),
113 fNewAccount(account),
114 fAccount(*fNewAccount),
116 fNewReplyTo(replyTo),
117 fReplyTo(*fNewReplyTo),
119 fNewPreamble(preamble),
121 fNewSignature(sig),
122 fSignature((char*)malloc(strlen(*fNewSignature) + 1)),
124 fNewFont(font),
125 fFont(*fNewFont),
127 fNewEncoding(encoding),
128 fEncoding(*fNewEncoding),
130 fNewWarnUnencodable(warnUnencodable),
131 fWarnUnencodable(*fNewWarnUnencodable),
133 fNewSpellCheckStartOn(spellCheckStartOn),
134 fSpellCheckStartOn(*fNewSpellCheckStartOn),
136 fNewAutoMarkRead(autoMarkRead),
137 fAutoMarkRead(*autoMarkRead)
139 strcpy(fSignature, *fNewSignature);
141 BMenuField* menu;
143 // group boxes
145 BGridView* interfaceView = new BGridView();
146 BGridLayout* interfaceLayout = interfaceView->GridLayout();
147 BGridView* mailView = new BGridView();
148 BGridLayout* mailLayout = mailView->GridLayout();
150 interfaceLayout->SetInsets(B_USE_DEFAULT_SPACING);
151 interfaceLayout->AlignLayoutWith(mailLayout, B_HORIZONTAL);
152 mailLayout->SetInsets(B_USE_DEFAULT_SPACING);
154 BBox* interfaceBox = new BBox(B_FANCY_BORDER, interfaceView);
155 interfaceBox->SetLabel(B_TRANSLATE("User interface"));
156 BBox* mailBox = new BBox(B_FANCY_BORDER, mailView);
157 mailBox->SetLabel(B_TRANSLATE("Mailing"));
159 // revert, ok & cancel
161 BButton* okButton = new BButton("ok", B_TRANSLATE("OK"),
162 new BMessage(P_OK));
163 okButton->MakeDefault(true);
165 BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
166 new BMessage(P_CANCEL));
168 fRevert = new BButton("revert", B_TRANSLATE("Revert"),
169 new BMessage(P_REVERT));
170 fRevert->SetEnabled(false);
172 // User Interface
173 int32 layoutRow = 0;
175 fButtonBarMenu = _BuildButtonBarMenu(*buttonBar);
176 menu = new BMenuField("bar", B_TRANSLATE("Button bar:"), fButtonBarMenu);
177 add_menu_to_layout(menu, interfaceLayout, layoutRow);
179 fFontMenu = _BuildFontMenu(font);
180 menu = new BMenuField("font", B_TRANSLATE("Font:"), fFontMenu);
181 add_menu_to_layout(menu, interfaceLayout, layoutRow);
183 fSizeMenu = _BuildSizeMenu(font);
184 menu = new BMenuField("size", B_TRANSLATE("Size:"), fSizeMenu);
185 add_menu_to_layout(menu, interfaceLayout, layoutRow);
187 fColoredQuotesMenu = _BuildColoredQuotesMenu(fColoredQuotes);
188 menu = new BMenuField("cquotes", B_TRANSLATE("Colored quotes:"),
189 fColoredQuotesMenu);
190 add_menu_to_layout(menu, interfaceLayout, layoutRow);
192 fSpellCheckStartOnMenu = _BuildSpellCheckStartOnMenu(fSpellCheckStartOn);
193 menu = new BMenuField("spellCheckStartOn",
194 B_TRANSLATE("Initial spell check mode:"),
195 fSpellCheckStartOnMenu);
196 add_menu_to_layout(menu, interfaceLayout, layoutRow);
198 fAutoMarkReadMenu = _BuildAutoMarkReadMenu(fAutoMarkRead);
199 menu = new BMenuField("autoMarkRead",
200 B_TRANSLATE("Automatically mark mail as read:"),
201 fAutoMarkReadMenu);
202 add_menu_to_layout(menu, interfaceLayout, layoutRow);
203 // Mail Accounts
205 layoutRow = 0;
207 fAccountMenu = _BuildAccountMenu(fAccount);
208 menu = new BMenuField("account", B_TRANSLATE("Default account:"),
209 fAccountMenu);
210 add_menu_to_layout(menu, mailLayout, layoutRow);
212 fReplyToMenu = _BuildReplyToMenu(fReplyTo);
213 menu = new BMenuField("replyTo", B_TRANSLATE("Reply account:"),
214 fReplyToMenu);
215 add_menu_to_layout(menu, mailLayout, layoutRow);
217 // Mail Contents
219 fReplyPreamble = new BTextControl("replytext",
220 B_TRANSLATE("Reply preamble:"),
221 *preamble, new BMessage(P_REPLY_PREAMBLE));
222 fReplyPreamble->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
224 fReplyPreambleMenu = _BuildReplyPreambleMenu();
225 menu = new BMenuField("replyPreamble", NULL, fReplyPreambleMenu);
226 menu->SetExplicitMaxSize(BSize(menu->MinSize().width, B_SIZE_UNSET));
228 mailLayout->AddItem(fReplyPreamble->CreateLabelLayoutItem(), 0, layoutRow);
229 mailLayout->AddItem(fReplyPreamble->CreateTextViewLayoutItem(), 1,
230 layoutRow);
231 mailLayout->AddView(menu, 2, layoutRow);
232 layoutRow++;
234 fSignatureMenu = _BuildSignatureMenu(*sig);
235 menu = new BMenuField("sig", B_TRANSLATE("Auto signature:"),
236 fSignatureMenu);
237 add_menu_to_layout(menu, mailLayout, layoutRow);
239 fEncodingMenu = _BuildEncodingMenu(fEncoding);
240 menu = new BMenuField("enc", B_TRANSLATE("Encoding:"), fEncodingMenu);
241 add_menu_to_layout(menu, mailLayout, layoutRow);
243 fWarnUnencodableMenu = _BuildWarnUnencodableMenu(fWarnUnencodable);
244 menu = new BMenuField("warnUnencodable", B_TRANSLATE("Warn unencodable:"),
245 fWarnUnencodableMenu);
246 add_menu_to_layout(menu, mailLayout, layoutRow);
248 fWrapMenu = _BuildWrapMenu(*wrap);
249 menu = new BMenuField("wrap", B_TRANSLATE("Text wrapping:"), fWrapMenu);
250 add_menu_to_layout(menu, mailLayout, layoutRow);
252 fAttachAttributesMenu = _BuildAttachAttributesMenu(*attachAttributes);
253 menu = new BMenuField("attachAttributes", B_TRANSLATE("Attach attributes:"),
254 fAttachAttributesMenu);
255 add_menu_to_layout(menu, mailLayout, layoutRow);
257 BLayoutBuilder::Group<>(this, B_VERTICAL)
258 .Add(interfaceBox)
259 .Add(mailBox)
260 .AddGroup(B_HORIZONTAL)
261 .Add(fRevert)
262 .AddGlue()
263 .Add(cancelButton)
264 .Add(okButton)
265 .End()
266 .SetInsets(B_USE_WINDOW_SPACING);
268 Show();
272 TPrefsWindow::~TPrefsWindow()
274 BMessage msg(WINDOW_CLOSED);
275 msg.AddInt32("kind", PREFS_WINDOW);
276 msg.AddPoint("window pos", Frame().LeftTop());
277 be_app->PostMessage(&msg);
281 void
282 TPrefsWindow::MessageReceived(BMessage* msg)
284 bool revert = true;
285 const char* family;
286 const char* signature;
287 const char* style;
288 char label[256];
289 int32 new_size;
290 int32 old_size;
291 font_family new_family;
292 font_family old_family;
293 font_style new_style;
294 font_style old_style;
295 BMenuItem* item;
296 BMessage message;
298 switch (msg->what) {
299 case P_OK:
300 if (strcmp(fReplyPreamble->Text(), *fNewPreamble)) {
301 free(*fNewPreamble);
302 *fNewPreamble
303 = (char *)malloc(strlen(fReplyPreamble->Text()) + 1);
304 strcpy(*fNewPreamble, fReplyPreamble->Text());
306 be_app->PostMessage(PREFS_CHANGED);
307 Quit();
308 break;
310 case P_CANCEL:
311 revert = false;
312 // supposed to fall through
313 case P_REVERT:
314 fFont.GetFamilyAndStyle(&old_family, &old_style);
315 fNewFont->GetFamilyAndStyle(&new_family, &new_style);
316 old_size = (int32)fFont.Size();
317 new_size = (int32)fNewFont->Size();
318 if (strcmp(old_family, new_family) || strcmp(old_style, new_style)
319 || old_size != new_size) {
320 fNewFont->SetFamilyAndStyle(old_family, old_style);
321 if (revert) {
322 sprintf(label, "%s %s", old_family, old_style);
323 item = fFontMenu->FindItem(label);
324 if (item != NULL)
325 item->SetMarked(true);
328 fNewFont->SetSize(old_size);
329 if (revert) {
330 sprintf(label, "%" B_PRId32, old_size);
331 item = fSizeMenu->FindItem(label);
332 if (item != NULL)
333 item->SetMarked(true);
335 message.what = M_FONT;
336 be_app->PostMessage(&message);
338 *fNewWrap = fWrap;
339 *fNewAttachAttributes = fAttachAttributes;
341 if (strcmp(fSignature, *fNewSignature)) {
342 free(*fNewSignature);
343 *fNewSignature = (char*)malloc(strlen(fSignature) + 1);
344 strcpy(*fNewSignature, fSignature);
347 *fNewEncoding = fEncoding;
348 *fNewWarnUnencodable = fWarnUnencodable;
349 *fNewSpellCheckStartOn = fSpellCheckStartOn;
350 *fNewAutoMarkRead = fAutoMarkRead;
351 *fNewButtonBar = fButtonBar;
353 be_app->PostMessage(PREFS_CHANGED);
355 if (revert) {
356 for (int i = fAccountMenu->CountItems(); --i > 0;) {
357 BMenuItem *item = fAccountMenu->ItemAt(i);
358 BMessage* itemMessage = item->Message();
359 if (itemMessage != NULL
360 && itemMessage->FindInt32("id") == *(int32 *)&fAccount) {
361 item->SetMarked(true);
362 break;
366 strcpy(label,fReplyTo == ACCOUNT_USE_DEFAULT
367 ? B_TRANSLATE("Use default account")
368 : B_TRANSLATE("Account from mail"));
369 if ((item = fReplyToMenu->FindItem(label)) != NULL)
370 item->SetMarked(true);
372 strcpy(label, fWrap ? B_TRANSLATE("On") : B_TRANSLATE("Off"));
373 if ((item = fWrapMenu->FindItem(label)) != NULL)
374 item->SetMarked(true);
376 strcpy(label, fAttachAttributes
377 ? B_TRANSLATE("Include file attributes in attachments")
378 : B_TRANSLATE("No file attributes, just plain data"));
379 if ((item = fAttachAttributesMenu->FindItem(label)) != NULL)
380 item->SetMarked(true);
382 strcpy(label, fColoredQuotes ? B_TRANSLATE("On") : B_TRANSLATE("Off"));
383 if ((item = fColoredQuotesMenu->FindItem(label)) != NULL)
384 item->SetMarked(true);
386 if (strcmp(fReplyPreamble->Text(), *fNewPreamble))
387 fReplyPreamble->SetText(*fNewPreamble);
389 item = fSignatureMenu->FindItem(fSignature);
390 if (item)
391 item->SetMarked(true);
393 uint32 index = 0;
394 while ((item = fEncodingMenu->ItemAt(index++)) != NULL) {
395 BMessage* itemMessage = item->Message();
396 if (itemMessage == NULL)
397 continue;
399 int32 encoding;
400 if (itemMessage->FindInt32("encoding", &encoding) == B_OK
401 && (uint32)encoding == *fNewEncoding) {
402 item->SetMarked(true);
403 break;
407 strcpy(label, fWarnUnencodable ? B_TRANSLATE("On") : B_TRANSLATE("Off"));
408 if ((item = fWarnUnencodableMenu->FindItem(label)) != NULL)
409 item->SetMarked(true);
411 strcpy(label, fSpellCheckStartOn ? B_TRANSLATE("On") : B_TRANSLATE("Off"));
412 if ((item = fSpellCheckStartOnMenu->FindItem(label)) != NULL)
413 item->SetMarked(true);
414 } else
415 Quit();
416 break;
418 case P_FONT:
419 family = NULL;
420 style = NULL;
421 int32 family_menu_index;
422 if (msg->FindString("font", &family) == B_OK) {
423 msg->FindString("style", &style);
424 fNewFont->SetFamilyAndStyle(family, style);
425 message.what = M_FONT;
426 be_app->PostMessage(&message);
429 /* grab this little tidbit so we can set the correct Family */
430 if (msg->FindInt32("parent_index", &family_menu_index) == B_OK)
431 fFontMenu->ItemAt(family_menu_index)->SetMarked(true);
432 break;
434 case P_SIZE:
435 old_size = (int32) fNewFont->Size();
436 msg->FindInt32("size", &new_size);
437 if (old_size != new_size) {
438 fNewFont->SetSize(new_size);
439 message.what = M_FONT;
440 be_app->PostMessage(&message);
442 break;
444 case P_WRAP:
445 msg->FindBool("wrap", fNewWrap);
446 break;
447 case P_ATTACH_ATTRIBUTES:
448 msg->FindBool("attachAttributes", fNewAttachAttributes);
449 break;
450 case P_COLORED_QUOTES:
451 msg->FindBool("cquotes", fNewColoredQuotes);
452 break;
453 case P_ACCOUNT:
454 msg->FindInt32("id",(int32*)fNewAccount);
455 break;
456 case P_REPLYTO:
457 msg->FindInt32("replyTo", fNewReplyTo);
458 break;
459 case P_REPLY_PREAMBLE:
461 int32 index = -1;
462 if (msg->FindInt32("index", &index) < B_OK)
463 break;
464 BMenuItem *item = fReplyPreambleMenu->ItemAt(index);
465 if (item == NULL) {
466 msg->PrintToStream();
467 break;
470 BTextView *text = fReplyPreamble->TextView();
471 int32 selectionStart;
472 int32 selectionEnd;
473 text->GetSelection(&selectionStart, &selectionEnd);
474 if (selectionStart != selectionEnd)
475 text->Delete(selectionStart, selectionEnd);
476 text->Insert(item->Label(), 2);
478 case P_SIG:
479 free(*fNewSignature);
480 if (msg->FindString("signature", &signature) == B_NO_ERROR) {
481 *fNewSignature = (char*)malloc(strlen(signature) + 1);
482 strcpy(*fNewSignature, signature);
483 } else {
484 *fNewSignature = (char*)malloc(
485 strlen(B_TRANSLATE("None")) + 1);
486 strcpy(*fNewSignature, B_TRANSLATE("None"));
488 break;
489 case P_ENC:
490 msg->FindInt32("encoding", (int32*)fNewEncoding);
491 break;
492 case P_WARN_UNENCODABLE:
493 msg->FindBool("warnUnencodable", fNewWarnUnencodable);
494 break;
495 case P_SPELL_CHECK_START_ON:
496 msg->FindBool("spellCheckStartOn", fNewSpellCheckStartOn);
497 break;
498 case P_MARK_READ:
499 msg->FindBool("autoMarkRead", fNewAutoMarkRead);
500 be_app->PostMessage(PREFS_CHANGED);
501 break;
502 case P_BUTTON_BAR:
503 msg->FindInt8("bar", (int8*)fNewButtonBar);
504 be_app->PostMessage(PREFS_CHANGED);
505 break;
507 default:
508 BWindow::MessageReceived(msg);
511 fFont.GetFamilyAndStyle(&old_family, &old_style);
512 fNewFont->GetFamilyAndStyle(&new_family, &new_style);
513 old_size = (int32) fFont.Size();
514 new_size = (int32) fNewFont->Size();
515 bool changed = old_size != new_size
516 || fWrap != *fNewWrap
517 || fAttachAttributes != *fNewAttachAttributes
518 || fColoredQuotes != *fNewColoredQuotes
519 || fAccount != *fNewAccount
520 || fReplyTo != *fNewReplyTo
521 || strcmp(old_family, new_family)
522 || strcmp(old_style, new_style)
523 || strcmp(fReplyPreamble->Text(), *fNewPreamble)
524 || strcmp(fSignature, *fNewSignature)
525 || fEncoding != *fNewEncoding
526 || fWarnUnencodable != *fNewWarnUnencodable
527 || fSpellCheckStartOn != *fNewSpellCheckStartOn
528 || fAutoMarkRead != *fNewAutoMarkRead
529 || fButtonBar != *fNewButtonBar;
530 fRevert->SetEnabled(changed);
534 BPopUpMenu*
535 TPrefsWindow::_BuildFontMenu(BFont* font)
537 font_family def_family;
538 font_style def_style;
539 font_family f_family;
540 font_style f_style;
542 BPopUpMenu *menu = new BPopUpMenu("");
543 font->GetFamilyAndStyle(&def_family, &def_style);
545 int32 family_menu_index = 0;
546 int family_count = count_font_families();
547 for (int family_loop = 0; family_loop < family_count; family_loop++) {
548 get_font_family(family_loop, &f_family);
549 BMenu *family_menu = new BMenu(f_family);
551 int style_count = count_font_styles(f_family);
552 for (int style_loop = 0; style_loop < style_count; style_loop++) {
553 get_font_style(f_family, style_loop, &f_style);
555 BMessage *msg = new BMessage(P_FONT);
556 msg->AddString("font", f_family);
557 msg->AddString("style", f_style);
558 // we send this to make setting the Family easier when things
559 // change
560 msg->AddInt32("parent_index", family_menu_index);
562 BMenuItem *item = new BMenuItem(f_style, msg);
563 family_menu->AddItem(item);
564 if ((strcmp(def_family, f_family) == 0)
565 && (strcmp(def_style, f_style) == 0)) {
566 item->SetMarked(true);
569 item->SetTarget(this);
572 menu->AddItem(family_menu);
573 BMenuItem *item = menu->ItemAt(family_menu_index);
574 BMessage *msg = new BMessage(P_FONT);
575 msg->AddString("font", f_family);
577 item->SetMessage(msg);
578 item->SetTarget(this);
579 if (strcmp(def_family, f_family) == 0)
580 item->SetMarked(true);
582 family_menu_index++;
584 return menu;
588 BPopUpMenu*
589 TPrefsWindow::_BuildLevelMenu(int32 level)
591 BMenuItem* item;
592 BMessage* msg;
593 BPopUpMenu* menu;
595 menu = new BPopUpMenu("");
596 msg = new BMessage(P_LEVEL);
597 msg->AddInt32("level", L_BEGINNER);
598 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Beginner"), msg));
599 if (level == L_BEGINNER)
600 item->SetMarked(true);
602 msg = new BMessage(P_LEVEL);
603 msg->AddInt32("level", L_EXPERT);
604 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Expert"), msg));
605 if (level == L_EXPERT)
606 item->SetMarked(true);
608 return menu;
612 BPopUpMenu*
613 TPrefsWindow::_BuildAccountMenu(int32 account)
615 BPopUpMenu* menu = new BPopUpMenu("");
616 BMenuItem* item;
618 //menu->SetRadioMode(true);
619 BMailAccounts accounts;
620 if (accounts.CountAccounts() == 0) {
621 menu->AddItem(item = new BMenuItem(B_TRANSLATE("<no account found>"), NULL));
622 item->SetEnabled(false);
623 return menu;
626 BMessage* msg;
627 for (int32 i = 0; i < accounts.CountAccounts(); i++) {
628 BMailAccountSettings* settings = accounts.AccountAt(i);
629 item = new BMenuItem(settings->Name(), msg = new BMessage(P_ACCOUNT));
631 msg->AddInt32("id", settings->AccountID());
633 if (account == settings->AccountID())
634 item->SetMarked(true);
636 menu->AddItem(item);
638 return menu;
642 BPopUpMenu*
643 TPrefsWindow::_BuildReplyToMenu(int32 account)
645 BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING);
647 BMenuItem* item;
648 BMessage* msg;
649 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Use default account"),
650 msg = new BMessage(P_REPLYTO)));
651 msg->AddInt32("replyTo", ACCOUNT_USE_DEFAULT);
652 if (account == ACCOUNT_USE_DEFAULT)
653 item->SetMarked(true);
655 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Account from mail"),
656 msg = new BMessage(P_REPLYTO)));
657 msg->AddInt32("replyTo", ACCOUNT_FROM_MAIL);
658 if (account == ACCOUNT_FROM_MAIL)
659 item->SetMarked(true);
661 return menu;
665 BMenu*
666 TPrefsWindow::_BuildReplyPreambleMenu()
668 BMenu *menu = new BMenu(B_EMPTY_STRING);
670 menu->AddItem(new BMenuItem(B_TRANSLATE("%n - Full name"),
671 new BMessage(P_REPLY_PREAMBLE)));
673 menu->AddItem(new BMenuItem(B_TRANSLATE("%e - E-mail address"),
674 new BMessage(P_REPLY_PREAMBLE)));
676 menu->AddItem(new BMenuItem(B_TRANSLATE("%d - Date"),
677 new BMessage(P_REPLY_PREAMBLE)));
679 menu->AddSeparatorItem();
681 menu->AddItem(new BMenuItem(B_TRANSLATE("\\n - Newline"),
682 new BMessage(P_REPLY_PREAMBLE)));
684 return menu;
688 BPopUpMenu*
689 TPrefsWindow::_BuildSignatureMenu(char* sig)
691 char name[B_FILE_NAME_LENGTH];
692 BEntry entry;
693 BFile file;
694 BMenuItem* item;
695 BMessage* msg;
696 BQuery query;
697 BVolume vol;
698 BVolumeRoster volume;
700 BPopUpMenu* menu = new BPopUpMenu("");
702 msg = new BMessage(P_SIG);
703 msg->AddString("signature", B_TRANSLATE("None"));
704 menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), msg));
705 if (!strcmp(sig, B_TRANSLATE("None")))
706 item->SetMarked(true);
708 msg = new BMessage(P_SIG);
709 msg->AddString("signature", B_TRANSLATE("Random"));
710 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Random"), msg));
711 if (!strcmp(sig, B_TRANSLATE("Random")))
712 item->SetMarked(true);
713 menu->AddSeparatorItem();
715 volume.GetBootVolume(&vol);
716 query.SetVolume(&vol);
717 query.SetPredicate("_signature = *");
718 query.Fetch();
720 while (query.GetNextEntry(&entry) == B_NO_ERROR) {
721 file.SetTo(&entry, O_RDONLY);
722 if (file.InitCheck() == B_NO_ERROR) {
723 msg = new BMessage(P_SIG);
724 file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name));
725 msg->AddString("signature", name);
726 menu->AddItem(item = new BMenuItem(name, msg));
727 if (!strcmp(sig, name))
728 item->SetMarked(true);
731 return menu;
735 BPopUpMenu*
736 TPrefsWindow::_BuildSizeMenu(BFont* font)
738 char label[16];
739 uint32 loop;
740 int32 sizes[] = {9, 10, 11, 12, 14, 18, 24};
741 float size;
742 BMenuItem* item;
743 BMessage* msg;
744 BPopUpMenu* menu;
746 menu = new BPopUpMenu("");
747 size = font->Size();
748 for (loop = 0; loop < sizeof(sizes) / sizeof(int32); loop++) {
749 msg = new BMessage(P_SIZE);
750 msg->AddInt32("size", sizes[loop]);
751 sprintf(label, "%" B_PRId32, sizes[loop]);
752 menu->AddItem(item = new BMenuItem(label, msg));
753 if (sizes[loop] == (int32)size)
754 item->SetMarked(true);
756 return menu;
760 BPopUpMenu*
761 TPrefsWindow::_BuildBoolMenu(uint32 what, const char* boolItem, bool isTrue)
763 BMenuItem* item;
764 BMessage* msg;
765 BPopUpMenu* menu;
767 menu = new BPopUpMenu("");
768 msg = new BMessage(what);
769 msg->AddBool(boolItem, true);
770 menu->AddItem(item = new BMenuItem(B_TRANSLATE("On"), msg));
771 if (isTrue)
772 item->SetMarked(true);
774 msg = new BMessage(what);
775 msg->AddInt32(boolItem, false);
776 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Off"), msg));
777 if (!isTrue)
778 item->SetMarked(true);
780 return menu;
784 BPopUpMenu*
785 TPrefsWindow::_BuildWrapMenu(bool wrap)
787 return _BuildBoolMenu(P_WRAP, "wrap", wrap);
791 BPopUpMenu*
792 TPrefsWindow::_BuildAttachAttributesMenu(bool attachAttributes)
794 BMenuItem* item;
795 BMessage* msg;
796 BPopUpMenu* menu;
798 menu = new BPopUpMenu("");
799 msg = new BMessage(P_ATTACH_ATTRIBUTES);
800 msg->AddBool("attachAttributes", true);
801 menu->AddItem(item = new BMenuItem(
802 B_TRANSLATE("Include file attributes in attachments"), msg));
803 if (attachAttributes)
804 item->SetMarked(true);
806 msg = new BMessage(P_ATTACH_ATTRIBUTES);
807 msg->AddInt32("attachAttributes", false);
808 menu->AddItem(item = new BMenuItem(
809 B_TRANSLATE("No file attributes, just plain data"), msg));
810 if (!attachAttributes)
811 item->SetMarked(true);
813 return menu;
817 BPopUpMenu*
818 TPrefsWindow::_BuildColoredQuotesMenu(bool quote)
820 return _BuildBoolMenu(P_COLORED_QUOTES, "cquotes", quote);
824 BPopUpMenu*
825 TPrefsWindow::_BuildEncodingMenu(uint32 encoding)
827 BMenuItem* item;
828 BMessage* msg;
829 BPopUpMenu* menu;
831 menu = new BPopUpMenu("");
833 BCharacterSetRoster roster;
834 BCharacterSet charset;
835 while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
836 BString name(charset.GetPrintName());
837 const char* mime = charset.GetMIMEName();
838 if (mime)
839 name << " (" << mime << ")";
840 msg = new BMessage(P_ENC);
841 uint32 convert_id;
842 if ((mime == 0) || (strcasecmp(mime, "UTF-8") != 0))
843 convert_id = charset.GetConversionID();
844 else
845 convert_id = B_MAIL_UTF8_CONVERSION;
846 msg->AddInt32("encoding", convert_id);
847 menu->AddItem(item = new BMenuItem(name.String(), msg));
848 if (convert_id == encoding)
849 item->SetMarked(true);
852 msg = new BMessage(P_ENC);
853 msg->AddInt32("encoding", B_MAIL_US_ASCII_CONVERSION);
854 menu->AddItem(item = new BMenuItem("US-ASCII", msg));
855 if (encoding == B_MAIL_US_ASCII_CONVERSION)
856 item->SetMarked(true);
858 return menu;
862 BPopUpMenu*
863 TPrefsWindow::_BuildWarnUnencodableMenu(bool warnUnencodable)
865 return _BuildBoolMenu(P_WARN_UNENCODABLE, "warnUnencodable",
866 warnUnencodable);
870 BPopUpMenu*
871 TPrefsWindow::_BuildSpellCheckStartOnMenu(bool spellCheckStartOn)
873 return _BuildBoolMenu(P_SPELL_CHECK_START_ON, "spellCheckStartOn",
874 spellCheckStartOn);
878 BPopUpMenu*
879 TPrefsWindow::_BuildAutoMarkReadMenu(bool autoMarkRead)
881 return _BuildBoolMenu(P_MARK_READ, "autoMarkRead",
882 autoMarkRead);
886 BPopUpMenu*
887 TPrefsWindow::_BuildButtonBarMenu(uint8 show)
889 BMenuItem* item;
890 BMessage* msg;
891 BPopUpMenu* menu = new BPopUpMenu("");
893 msg = new BMessage(P_BUTTON_BAR);
894 msg->AddInt8("bar", kShowToolBar);
895 menu->AddItem(item = new BMenuItem(
896 B_TRANSLATE("Show icons & labels"), msg));
897 if (show & 1)
898 item->SetMarked(true);
900 msg = new BMessage(P_BUTTON_BAR);
901 msg->AddInt8("bar", kShowToolBarIconsOnly);
902 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show icons only"), msg));
903 if (show & 2)
904 item->SetMarked(true);
906 msg = new BMessage(P_BUTTON_BAR);
907 msg->AddInt8("bar", kHideToolBar);
908 menu->AddItem(item = new BMenuItem(B_TRANSLATE("Hide"), msg));
909 if (!show)
910 item->SetMarked(true);
912 return menu;