* Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42256 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-06-19 21:16:15 +00:00
parent 2648a38678
commit 51ecde2887

View File

@ -1,28 +1,29 @@
/* BMailProtocolConfigView - the standard config view for all protocols /*
** * Copyright 20011, Haiku Inc. All Rights Reserved.
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/ * Distributed under the terms of the MIT License.
*/
#include <TextControl.h> //! The standard config view for all protocols.
#include <MenuField.h>
#include <PopUpMenu.h>
#include <String.h>
#include <Message.h>
#include <MenuItem.h>
#include <CheckBox.h>
#include <stdlib.h>
#include <stdio.h>
#include <MDRLanguage.h>
class _EXPORT BMailProtocolConfigView;
#include <crypt.h>
#include "ProtocolConfigView.h" #include "ProtocolConfigView.h"
#include <stdio.h>
#include <stdlib.h>
#include <CheckBox.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Message.h>
#include <PopUpMenu.h>
#include <String.h>
#include <TextControl.h>
#include <crypt.h>
#include <MDRLanguage.h>
const char* kPartialDownloadLimit = "partial_download_limit"; const char* kPartialDownloadLimit = "partial_download_limit";
@ -131,18 +132,18 @@ float FindWidestLabel(BView *view);
static float sItemHeight; static float sItemHeight;
inline const char * inline const char *
TextControl(BView *parent,const char *name) TextControl(BView *parent,const char *name)
{ {
BTextControl *control = (BTextControl *)(parent->FindView(name)); BTextControl *control = (BTextControl *)(parent->FindView(name));
if (control != NULL) if (control != NULL)
return control->Text(); return control->Text();
return ""; return "";
} }
BTextControl * BTextControl *
AddTextField(BRect &rect, const char *name, const char *label) AddTextField(BRect &rect, const char *name, const char *label)
{ {
BTextControl *text_control = new BTextControl(rect,name,label,"",NULL,B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); BTextControl *text_control = new BTextControl(rect,name,label,"",NULL,B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
// text_control->SetDivider(be_plain_font->StringWidth(label)); // text_control->SetDivider(be_plain_font->StringWidth(label));
@ -161,7 +162,7 @@ BMenuField *AddMenuField (BRect &rect, const char *name, const char *label) {
inline BCheckBox * inline BCheckBox *
AddCheckBox(BRect &rect, const char *name, const char *label, BMessage *msg = NULL) AddCheckBox(BRect &rect, const char *name, const char *label, BMessage *msg = NULL)
{ {
BCheckBox *control = new BCheckBox(rect,name,label,msg); BCheckBox *control = new BCheckBox(rect,name,label,msg);
rect.OffsetBy(0,sItemHeight); rect.OffsetBy(0,sItemHeight);
@ -169,8 +170,8 @@ AddCheckBox(BRect &rect, const char *name, const char *label, BMessage *msg = NU
} }
inline void inline void
SetTextControl(BView *parent, const char *name, const char *text) SetTextControl(BView *parent, const char *name, const char *text)
{ {
BTextControl *control = (BTextControl *)(parent->FindView(name)); BTextControl *control = (BTextControl *)(parent->FindView(name));
if (control != NULL) if (control != NULL)
@ -178,7 +179,7 @@ SetTextControl(BView *parent, const char *name, const char *text)
} }
float float
FindWidestLabel(BView *view) FindWidestLabel(BView *view)
{ {
float width = 0; float width = 0;
@ -196,7 +197,7 @@ FindWidestLabel(BView *view)
//----------------Real code---------------------- //----------------Real code----------------------
BMailProtocolConfigView::BMailProtocolConfigView(uint32 options_mask) BMailProtocolConfigView::BMailProtocolConfigView(uint32 options_mask)
: :
BView (BRect(0,0,100,20), "protocol_config_view", B_FOLLOW_LEFT BView (BRect(0,0,100,20), "protocol_config_view", B_FOLLOW_LEFT
| B_FOLLOW_TOP, B_WILL_DRAW), | B_FOLLOW_TOP, B_WILL_DRAW),
@ -213,19 +214,19 @@ BMailProtocolConfigView::BMailProtocolConfigView(uint32 options_mask)
if (options_mask & B_MAIL_PROTOCOL_HAS_HOSTNAME) if (options_mask & B_MAIL_PROTOCOL_HAS_HOSTNAME)
AddChild(AddTextField(rect,"host",MDR_DIALECT_CHOICE ("Mail server:","サーバ名 :"))); AddChild(AddTextField(rect,"host",MDR_DIALECT_CHOICE ("Mail server:","サーバ名 :")));
if (options_mask & B_MAIL_PROTOCOL_HAS_USERNAME) if (options_mask & B_MAIL_PROTOCOL_HAS_USERNAME)
AddChild(AddTextField(rect,"user",MDR_DIALECT_CHOICE ("Username:","ユーザーID"))); AddChild(AddTextField(rect,"user",MDR_DIALECT_CHOICE ("Username:","ユーザーID")));
if (options_mask & B_MAIL_PROTOCOL_HAS_PASSWORD) { if (options_mask & B_MAIL_PROTOCOL_HAS_PASSWORD) {
BTextControl *control = AddTextField(rect,"pass",MDR_DIALECT_CHOICE ("Password:","パスワード:")); BTextControl *control = AddTextField(rect,"pass",MDR_DIALECT_CHOICE ("Password:","パスワード:"));
control->TextView()->HideTyping(true); control->TextView()->HideTyping(true);
AddChild(control); AddChild(control);
} }
if (options_mask & B_MAIL_PROTOCOL_HAS_FLAVORS) if (options_mask & B_MAIL_PROTOCOL_HAS_FLAVORS)
AddChild(AddMenuField(rect,"flavor","Connection type:")); AddChild(AddMenuField(rect,"flavor","Connection type:"));
if (options_mask & B_MAIL_PROTOCOL_HAS_AUTH_METHODS) if (options_mask & B_MAIL_PROTOCOL_HAS_AUTH_METHODS)
AddChild(AddMenuField(rect,"auth_method",MDR_DIALECT_CHOICE ("Login type:","認証方法 :"))); AddChild(AddMenuField(rect,"auth_method",MDR_DIALECT_CHOICE ("Login type:","認証方法 :")));
@ -255,22 +256,22 @@ BMailProtocolConfigView::BMailProtocolConfigView(uint32 options_mask)
// resize views // resize views
float height; float height;
GetPreferredSize(&width,&height); GetPreferredSize(&width,&height);
ResizeTo(width,height); ResizeTo(width,height);
for (int32 i = CountChildren();i-- > 0;) { for (int32 i = CountChildren();i-- > 0;) {
// this doesn't work with BTextControl, does anyone know why? -- axeld. // this doesn't work with BTextControl, does anyone know why? -- axeld.
if (BView *view = ChildAt(i)) if (BView *view = ChildAt(i))
view->ResizeTo(width - 10,view->Bounds().Height()); view->ResizeTo(width - 10,view->Bounds().Height());
} }
} }
BMailProtocolConfigView::~BMailProtocolConfigView() BMailProtocolConfigView::~BMailProtocolConfigView()
{ {
} }
void void
BMailProtocolConfigView::SetTo(MailAddonSettings& settings) BMailProtocolConfigView::SetTo(MailAddonSettings& settings)
{ {
const BMessage* archive = &settings.Settings(); const BMessage* archive = &settings.Settings();
@ -288,7 +289,7 @@ BMailProtocolConfigView::SetTo(MailAddonSettings& settings)
delete[] password; delete[] password;
} else } else
SetTextControl(this,"pass", archive->FindString("password")); SetTextControl(this,"pass", archive->FindString("password"));
if (archive->HasInt32("flavor")) { if (archive->HasInt32("flavor")) {
BMenuField *menu = (BMenuField *)(FindView("flavor")); BMenuField *menu = (BMenuField *)(FindView("flavor"));
if (menu != NULL) { if (menu != NULL) {
@ -296,7 +297,7 @@ BMailProtocolConfigView::SetTo(MailAddonSettings& settings)
item->SetMarked(true); item->SetMarked(true);
} }
} }
if (archive->HasInt32("auth_method")) { if (archive->HasInt32("auth_method")) {
BMenuField *menu = (BMenuField *)(FindView("auth_method")); BMenuField *menu = (BMenuField *)(FindView("auth_method"));
if (menu != NULL) { if (menu != NULL) {
@ -310,15 +311,15 @@ BMailProtocolConfigView::SetTo(MailAddonSettings& settings)
} }
} }
BCheckBox *box = (BCheckBox *)(FindView("leave_mail_on_server")); BCheckBox *box = (BCheckBox *)(FindView("leave_mail_on_server"));
if (box != NULL) if (box != NULL)
box->SetValue(archive->FindBool("leave_mail_on_server") ? B_CONTROL_ON : B_CONTROL_OFF); box->SetValue(archive->FindBool("leave_mail_on_server") ? B_CONTROL_ON : B_CONTROL_OFF);
box = (BCheckBox *)(FindView("delete_remote_when_local")); box = (BCheckBox *)(FindView("delete_remote_when_local"));
if (box != NULL) { if (box != NULL) {
box->SetValue(archive->FindBool("delete_remote_when_local") ? B_CONTROL_ON : B_CONTROL_OFF); box->SetValue(archive->FindBool("delete_remote_when_local") ? B_CONTROL_ON : B_CONTROL_OFF);
if (archive->FindBool("leave_mail_on_server")) if (archive->FindBool("leave_mail_on_server"))
box->SetEnabled(true); box->SetEnabled(true);
else else
@ -330,8 +331,8 @@ BMailProtocolConfigView::SetTo(MailAddonSettings& settings)
} }
void void
BMailProtocolConfigView::AddFlavor(const char *label) BMailProtocolConfigView::AddFlavor(const char *label)
{ {
BMenuField *menu = (BMenuField *)(FindView("flavor")); BMenuField *menu = (BMenuField *)(FindView("flavor"));
if (menu != NULL) { if (menu != NULL) {
@ -342,15 +343,15 @@ BMailProtocolConfigView::AddFlavor(const char *label)
} }
void void
BMailProtocolConfigView::AddAuthMethod(const char *label,bool needUserPassword) BMailProtocolConfigView::AddAuthMethod(const char *label,bool needUserPassword)
{ {
BMenuField *menu = (BMenuField *)(FindView("auth_method")); BMenuField *menu = (BMenuField *)(FindView("auth_method"));
if (menu != NULL) { if (menu != NULL) {
BMenuItem *item = new BMenuItem(label,new BMessage(needUserPassword ? 'some' : 'none')); BMenuItem *item = new BMenuItem(label,new BMessage(needUserPassword ? 'some' : 'none'));
menu->Menu()->AddItem(item); menu->Menu()->AddItem(item);
if (menu->Menu()->FindMarked() == NULL) { if (menu->Menu()->FindMarked() == NULL) {
menu->Menu()->ItemAt(0)->SetMarked(true); menu->Menu()->ItemAt(0)->SetMarked(true);
MessageReceived(menu->Menu()->ItemAt(0)->Message()); MessageReceived(menu->Menu()->ItemAt(0)->Message());
@ -359,21 +360,21 @@ BMailProtocolConfigView::AddAuthMethod(const char *label,bool needUserPassword)
} }
void void
BMailProtocolConfigView::AttachedToWindow() BMailProtocolConfigView::AttachedToWindow()
{ {
BMenuField *menu = (BMenuField *)(FindView("auth_method")); BMenuField *menu = (BMenuField *)(FindView("auth_method"));
if (menu != NULL) if (menu != NULL)
menu->Menu()->SetTargetForItems(this); menu->Menu()->SetTargetForItems(this);
BCheckBox *box = (BCheckBox *)(FindView("leave_mail_on_server")); BCheckBox *box = (BCheckBox *)(FindView("leave_mail_on_server"));
if (box != NULL) if (box != NULL)
box->SetTarget(this); box->SetTarget(this);
} }
void void
BMailProtocolConfigView::MessageReceived(BMessage *msg) BMailProtocolConfigView::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case 'some': case 'some':
@ -384,7 +385,7 @@ BMailProtocolConfigView::MessageReceived(BMessage *msg)
disable_control("user"); disable_control("user");
disable_control("pass"); disable_control("pass");
break; break;
case 'lmos': case 'lmos':
if (msg->FindInt32("be:value") == 1) { if (msg->FindInt32("be:value") == 1) {
enable_control("delete_remote_when_local"); enable_control("delete_remote_when_local");
@ -396,8 +397,8 @@ BMailProtocolConfigView::MessageReceived(BMessage *msg)
} }
status_t status_t
BMailProtocolConfigView::Archive(BMessage *into, bool deep) const BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
{ {
const char *host = TextControl((BView *)this,"host"); const char *host = TextControl((BView *)this,"host");
int32 port = -1; int32 port = -1;
@ -406,7 +407,7 @@ BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
port = atol(host_name.String() + host_name.FindFirst(':') + 1); port = atol(host_name.String() + host_name.FindFirst(':') + 1);
host_name.Truncate(host_name.FindFirst(':')); host_name.Truncate(host_name.FindFirst(':'));
} }
if (into->ReplaceString("server",host_name.String()) != B_OK) if (into->ReplaceString("server",host_name.String()) != B_OK)
into->AddString("server",host_name.String()); into->AddString("server",host_name.String());
@ -418,34 +419,34 @@ BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
if (into->ReplaceString("username",TextControl((BView *)this,"user")) != B_OK) if (into->ReplaceString("username",TextControl((BView *)this,"user")) != B_OK)
into->AddString("username",TextControl((BView *)this,"user")); into->AddString("username",TextControl((BView *)this,"user"));
// remove old unencrypted passwords // remove old unencrypted passwords
into->RemoveName("password"); into->RemoveName("password");
set_passwd(into,"cpasswd",TextControl((BView *)this,"pass")); set_passwd(into,"cpasswd",TextControl((BView *)this,"pass"));
BMenuField *field; BMenuField *field;
int32 index = -1; int32 index = -1;
if ((field = (BMenuField *)(FindView("flavor"))) != NULL) { if ((field = (BMenuField *)(FindView("flavor"))) != NULL) {
BMenuItem *item = field->Menu()->FindMarked(); BMenuItem *item = field->Menu()->FindMarked();
if (item != NULL) if (item != NULL)
index = field->Menu()->IndexOf(item); index = field->Menu()->IndexOf(item);
} }
if (into->ReplaceInt32("flavor",index) != B_OK) if (into->ReplaceInt32("flavor",index) != B_OK)
into->AddInt32("flavor",index); into->AddInt32("flavor",index);
index = -1; index = -1;
if ((field = (BMenuField *)(FindView("auth_method"))) != NULL) { if ((field = (BMenuField *)(FindView("auth_method"))) != NULL) {
BMenuItem *item = field->Menu()->FindMarked(); BMenuItem *item = field->Menu()->FindMarked();
if (item != NULL) if (item != NULL)
index = field->Menu()->IndexOf(item); index = field->Menu()->IndexOf(item);
} }
if (into->ReplaceInt32("auth_method",index) != B_OK) if (into->ReplaceInt32("auth_method",index) != B_OK)
into->AddInt32("auth_method",index); into->AddInt32("auth_method",index);
if (FindView("leave_mail_on_server") != NULL) { if (FindView("leave_mail_on_server") != NULL) {
BControl* control = (BControl*)FindView("leave_mail_on_server"); BControl* control = (BControl*)FindView("leave_mail_on_server");
bool on = (control->Value() == B_CONTROL_ON); bool on = (control->Value() == B_CONTROL_ON);
@ -460,7 +461,7 @@ BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
} else { } else {
if (into->ReplaceBool("leave_mail_on_server", false) != B_OK) if (into->ReplaceBool("leave_mail_on_server", false) != B_OK)
into->AddBool("leave_mail_on_server", false); into->AddBool("leave_mail_on_server", false);
if (into->ReplaceBool("delete_remote_when_local", false) != B_OK) if (into->ReplaceBool("delete_remote_when_local", false) != B_OK)
into->AddBool("delete_remote_when_local", false); into->AddBool("delete_remote_when_local", false);
} }
@ -470,9 +471,9 @@ BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
return B_OK; return B_OK;
} }
void void
BMailProtocolConfigView::GetPreferredSize(float *width, float *height) BMailProtocolConfigView::GetPreferredSize(float *width, float *height)
{ {
float minWidth = 250; float minWidth = 250;
if (BView *view = FindView("delete_remote_when_local")) { if (BView *view = FindView("delete_remote_when_local")) {