From ca13bd31a784e07f54384f3ef42839c78bf7ff94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 22 Jun 2007 00:15:17 +0000 Subject: [PATCH] * The Deskbar tray icon menu "Check Mail" and the status window "Check Now" button are now only enabled if there are any inbound accounts. * BMailSettings::StatusWindowFrame() now returns some useful defaults. * Minor cleanup. * The MDR kit needs some serious overhaul before it can be part of R1. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21493 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/mail/status.h | 22 +- src/kits/mail/MailSettings.cpp | 374 ++++++++++++++++++------------- src/kits/mail/StatusWindow.cpp | 111 +++++---- src/servers/mail/deskbarview.cpp | 175 ++++++++------- 4 files changed, 401 insertions(+), 281 deletions(-) diff --git a/headers/private/mail/status.h b/headers/private/mail/status.h index 276dfd374a..a1214311dd 100644 --- a/headers/private/mail/status.h +++ b/headers/private/mail/status.h @@ -1,15 +1,18 @@ +/* + * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. + * Copyright 2004-2007, Haiku Inc. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ #ifndef ZOIDBERG_STATUS_WINDOW_H #define ZOIDBERG_STATUS_WINDOW_H -/* StatusWindow - the status window while fetching/sending mails -** -** Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. -*/ -#include +#include #include #include -#include +#include +#include class BStatusBar; class BStringView; @@ -17,7 +20,7 @@ class BMailStatusView; class BMailStatusWindow : public BWindow { public: - BMailStatusWindow(BRect rect, const char *name, uint32 show_when); + BMailStatusWindow(BRect rect, const char *name, uint32 showMode); ~BMailStatusWindow(); virtual void FrameMoved(BPoint origin); @@ -35,9 +38,12 @@ class BMailStatusWindow : public BWindow { private: friend class BMailStatusView; + void _CheckChains(); void SetBorderStyle(int32 look); void ActuallyAddStatusView(BMailStatusView *status); + node_ref fChainDirectory; + BButton* fCheckNowButton; BList fStatusViews; uint32 fShowMode; BView *fDefaultView; @@ -47,7 +53,7 @@ class BMailStatusWindow : public BWindow { int32 fWindowMoved; int32 fLastWorkspace; BRect fFrame; - + uint32 _reserved[5]; }; diff --git a/src/kits/mail/MailSettings.cpp b/src/kits/mail/MailSettings.cpp index 03e026d5af..9a5d721625 100644 --- a/src/kits/mail/MailSettings.cpp +++ b/src/kits/mail/MailSettings.cpp @@ -1,8 +1,14 @@ -/* BMailSettings - the mail daemon's settings -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ +/* + * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. + * Copyright 2004-2007, Haiku Inc. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ +//! The mail daemon's settings + + +#include #include #include @@ -17,64 +23,175 @@ #include #include + class BMailSettings; namespace MailInternal { - status_t WriteMessageFile(const BMessage& archive, const BPath& path, const char* name); + status_t WriteMessageFile(const BMessage& archive, const BPath& path, + const char* name); } -#include + +// #pragma mark - Chain methods + +// +// To do +// +BMailChain* +NewMailChain() +{ + // attempted solution: use time(NULL) and hope it's unique. Is there a better idea? + // note that two chains in two second is quite possible. how to fix this? + // maybe we could | in some bigtime_t as well. hrrm... + + // This is to fix a problem with generating the correct id for chains. + // Basically if the chains dir does not exist, the first time you create + // an account both the inbound and outbound chains will be called 0. + create_directory("/boot/home/config/settings/Mail/chains",0777); + + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY, &path); + path.Append("Mail/chains"); + BDirectory chain_dir(path.Path()); + BDirectory outbound_dir(&chain_dir,"outbound"), inbound_dir(&chain_dir,"inbound"); + + chain_dir.Lock(); //---------Try to lock the directory + + int32 id = -1; //-----When inc'ed, we start with 0---- + chain_dir.ReadAttr("last_issued_chain_id",B_INT32_TYPE,0,&id,sizeof(id)); + + BString string_id; + + do { + id++; + string_id = ""; + string_id << id; + } while ((outbound_dir.Contains(string_id.String())) + || (inbound_dir.Contains(string_id.String()))); + + chain_dir.WriteAttr("last_issued_chain_id",B_INT32_TYPE,0,&id,sizeof(id)); + + return new BMailChain(id); +} + + +BMailChain* +GetMailChain(uint32 id) +{ + return new BMailChain(id); +} + + +status_t +GetInboundMailChains(BList *list) +{ + BPath path; + status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + if (status != B_OK) { + fprintf(stderr, "Couldn't find user settings directory: %s\n", + strerror(status)); + return status; + } + + path.Append("Mail/chains/inbound"); + BDirectory chainDirectory(path.Path()); + entry_ref ref; + + while (chainDirectory.GetNextRef(&ref) == B_OK) { + char *end; + uint32 id = strtoul(ref.name, &end, 10); + + if (!end || *end == '\0') + list->AddItem((void*)new BMailChain(id)); + } + + return B_OK; +} + + +status_t +GetOutboundMailChains(BList *list) +{ + BPath path; + status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + if (status != B_OK) { + fprintf(stderr, "Couldn't find user settings directory: %s\n", + strerror(status)); + return status; + } + + path.Append("Mail/chains/outbound"); + BDirectory chainDirectory(path.Path()); + entry_ref ref; + + while (chainDirectory.GetNextRef(&ref) == B_OK) { + char *end; + uint32 id = strtoul(ref.name, &end, 10); + if (!end || *end == '\0') + list->AddItem((void*)new BMailChain(id)); + } + + return B_OK; +} + + +// #pragma mark - BMailSettings + BMailSettings::BMailSettings() { Reload(); } + BMailSettings::~BMailSettings() { } -status_t BMailSettings::InitCheck() const + +status_t +BMailSettings::InitCheck() const { return B_OK; } -status_t BMailSettings::Save(bigtime_t /*timeout*/) +status_t +BMailSettings::Save(bigtime_t /*timeout*/) { status_t ret; // // Find chain-saving directory // - + BPath path; ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (ret != B_OK) - { + if (ret != B_OK) { fprintf(stderr, "Couldn't find user settings directory: %s\n", strerror(ret)); return ret; } - + path.Append("Mail"); - + status_t result = MailInternal::WriteMessageFile(data,path,"new_mail_daemon"); if (result < B_OK) return result; - + BMessenger("application/x-vnd.Be-POST").SendMessage('mrrs'); - + return B_OK; } -status_t BMailSettings::Reload() + +status_t +BMailSettings::Reload() { status_t ret; BPath path; ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (ret != B_OK) - { + if (ret != B_OK) { fprintf(stderr, "Couldn't find user settings directory: %s\n", strerror(ret)); return ret; @@ -85,8 +202,7 @@ status_t BMailSettings::Reload() // open BFile settings(path.Path(),B_READ_ONLY); ret = settings.InitCheck(); - if (ret != B_OK) - { + if (ret != B_OK) { fprintf(stderr, "Couldn't open settings file '%s': %s\n", path.Path(), strerror(ret)); return ret; @@ -95,8 +211,7 @@ status_t BMailSettings::Reload() // read settings BMessage tmp; ret = tmp.Unflatten(&settings); - if (ret != B_OK) - { + if (ret != B_OK) { fprintf(stderr, "Couldn't read settings from '%s': %s\n", path.Path(), strerror(ret)); return ret; @@ -108,169 +223,97 @@ status_t BMailSettings::Reload() } -// Chain methods - -// -// To do -// -_EXPORT BMailChain* NewMailChain() -{ - // attempted solution: use time(NULL) and hope it's unique. Is there a better idea? - // note that two chains in two second is quite possible. how to fix this? - // maybe we could | in some bigtime_t as well. hrrm... - - // This is to fix a problem with generating the correct id for chains. - // Basically if the chains dir does not exist, the first time you create - // an account both the inbound and outbound chains will be called 0. - create_directory("/boot/home/config/settings/Mail/chains",0777); - - BPath path; - find_directory(B_USER_SETTINGS_DIRECTORY, &path); - path.Append("Mail/chains"); - BDirectory chain_dir(path.Path()); - BDirectory outbound_dir(&chain_dir,"outbound"), inbound_dir(&chain_dir,"inbound"); - - chain_dir.Lock(); //---------Try to lock the directory - - int32 id = -1; //-----When inc'ed, we start with 0---- - chain_dir.ReadAttr("last_issued_chain_id",B_INT32_TYPE,0,&id,sizeof(id)); - - BString string_id; - - do { - id++; - string_id = ""; - string_id << id; - } while ((outbound_dir.Contains(string_id.String())) || (inbound_dir.Contains(string_id.String()))); - - - chain_dir.WriteAttr("last_issued_chain_id",B_INT32_TYPE,0,&id,sizeof(id)); - - return new BMailChain(id); -} -// -// Done -// - -_EXPORT BMailChain* GetMailChain(uint32 id) -{ - return new BMailChain(id); -} - -_EXPORT status_t GetInboundMailChains(BList *list) -{ - BPath path; - status_t ret = B_OK; - - ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (ret != B_OK) - { - fprintf(stderr, "Couldn't find user settings directory: %s\n", - strerror(ret)); - return ret; - } - - path.Append("Mail/chains/inbound"); - BDirectory chain_dir(path.Path()); - entry_ref ref; - - while (chain_dir.GetNextRef(&ref)==B_OK) - { - char *end; - uint32 id = strtoul(ref.name, &end, 10); - - if (!end || *end == '\0') - list->AddItem((void*)new BMailChain(id)); - } - - return ret; -} - -_EXPORT status_t GetOutboundMailChains(BList *list) -{ - BPath path; - status_t ret = B_OK; - - ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (ret != B_OK) - { - fprintf(stderr, "Couldn't find user settings directory: %s\n", - strerror(ret)); - return ret; - } - - path.Append("Mail/chains/outbound"); - BDirectory chain_dir(path.Path()); - entry_ref ref; - - while (chain_dir.GetNextRef(&ref)==B_OK) - { - char *end; - uint32 id = strtoul(ref.name, &end, 10); - if (!end || *end == '\0') - list->AddItem((void*)new BMailChain(id)); - } - - return ret; -} +// # pragma mark - Global settings -// Global settings -int32 BMailSettings::WindowFollowsCorner() +int32 +BMailSettings::WindowFollowsCorner() { return data.FindInt32("WindowFollowsCorner"); } -void BMailSettings::SetWindowFollowsCorner(int32 which_corner) + + +void +BMailSettings::SetWindowFollowsCorner(int32 which_corner) { if (data.ReplaceInt32("WindowFollowsCorner",which_corner)) data.AddInt32("WindowFollowsCorner",which_corner); } -uint32 BMailSettings::ShowStatusWindow() + +uint32 +BMailSettings::ShowStatusWindow() { return data.FindInt32("ShowStatusWindow"); } -void BMailSettings::SetShowStatusWindow(uint32 mode) + + +void +BMailSettings::SetShowStatusWindow(uint32 mode) { if (data.ReplaceInt32("ShowStatusWindow",mode)) data.AddInt32("ShowStatusWindow",mode); } -bool BMailSettings::DaemonAutoStarts() + +bool +BMailSettings::DaemonAutoStarts() { return data.FindBool("DaemonAutoStarts"); } -void BMailSettings::SetDaemonAutoStarts(bool does_it) + + +void +BMailSettings::SetDaemonAutoStarts(bool does_it) { if (data.ReplaceBool("DaemonAutoStarts",does_it)) data.AddBool("DaemonAutoStarts",does_it); } -BRect BMailSettings::ConfigWindowFrame() + +BRect +BMailSettings::ConfigWindowFrame() { return data.FindRect("ConfigWindowFrame"); } -void BMailSettings::SetConfigWindowFrame(BRect frame) + + +void +BMailSettings::SetConfigWindowFrame(BRect frame) { if (data.ReplaceRect("ConfigWindowFrame",frame)) data.AddRect("ConfigWindowFrame",frame); } -BRect BMailSettings::StatusWindowFrame() + +BRect +BMailSettings::StatusWindowFrame() { - return data.FindRect("StatusWindowFrame"); + BRect frame; + if (data.FindRect("StatusWindowFrame", &frame) != B_OK) + return BRect(100, 100, 200, 120); + + return frame; } -void BMailSettings::SetStatusWindowFrame(BRect frame) + + +void +BMailSettings::SetStatusWindowFrame(BRect frame) { if (data.ReplaceRect("StatusWindowFrame",frame)) data.AddRect("StatusWindowFrame",frame); } -int32 BMailSettings::StatusWindowWorkspaces() + +int32 +BMailSettings::StatusWindowWorkspaces() { return data.FindInt32("StatusWindowWorkSpace"); } -void BMailSettings::SetStatusWindowWorkspaces(int32 workspace) + + +void +BMailSettings::SetStatusWindowWorkspaces(int32 workspace) { if (data.ReplaceInt32("StatusWindowWorkSpace",workspace)) data.AddInt32("StatusWindowWorkSpace",workspace); @@ -280,11 +323,16 @@ void BMailSettings::SetStatusWindowWorkspaces(int32 workspace) BMessenger("application/x-vnd.Be-POST").SendMessage(&msg); } -int32 BMailSettings::StatusWindowLook() + +int32 +BMailSettings::StatusWindowLook() { return data.FindInt32("StatusWindowLook"); } -void BMailSettings::SetStatusWindowLook(int32 look) + + +void +BMailSettings::SetStatusWindowLook(int32 look) { if (data.ReplaceInt32("StatusWindowLook",look)) data.AddInt32("StatusWindowLook",look); @@ -294,40 +342,64 @@ void BMailSettings::SetStatusWindowLook(int32 look) BMessenger("application/x-vnd.Be-POST").SendMessage(&msg); } -bigtime_t BMailSettings::AutoCheckInterval() { + +bigtime_t +BMailSettings::AutoCheckInterval() +{ bigtime_t value = B_INFINITE_TIMEOUT; data.FindInt64("AutoCheckInterval",&value); return value; } -void BMailSettings::SetAutoCheckInterval(bigtime_t interval) { + +void +BMailSettings::SetAutoCheckInterval(bigtime_t interval) +{ if (data.ReplaceInt64("AutoCheckInterval",interval)) data.AddInt64("AutoCheckInterval",interval); } -bool BMailSettings::CheckOnlyIfPPPUp() { + +bool +BMailSettings::CheckOnlyIfPPPUp() +{ return data.FindBool("CheckOnlyIfPPPUp"); } -void BMailSettings::SetCheckOnlyIfPPPUp(bool yes) { + +void +BMailSettings::SetCheckOnlyIfPPPUp(bool yes) +{ if (data.ReplaceBool("CheckOnlyIfPPPUp",yes)) data.AddBool("CheckOnlyIfPPPUp",yes); } -bool BMailSettings::SendOnlyIfPPPUp() { + +bool +BMailSettings::SendOnlyIfPPPUp() +{ return data.FindBool("SendOnlyIfPPPUp"); } -void BMailSettings::SetSendOnlyIfPPPUp(bool yes) { + +void +BMailSettings::SetSendOnlyIfPPPUp(bool yes) +{ if (data.ReplaceBool("SendOnlyIfPPPUp",yes)) data.AddBool("SendOnlyIfPPPUp",yes); } -uint32 BMailSettings::DefaultOutboundChainID() { + +uint32 +BMailSettings::DefaultOutboundChainID() +{ return data.FindInt32("DefaultOutboundChainID"); } -void BMailSettings::SetDefaultOutboundChainID(uint32 to) { + +void +BMailSettings::SetDefaultOutboundChainID(uint32 to) +{ if (data.ReplaceInt32("DefaultOutboundChainID",to)) data.AddInt32("DefaultOutboundChainID",to); } diff --git a/src/kits/mail/StatusWindow.cpp b/src/kits/mail/StatusWindow.cpp index b23a7fc506..70ecb16305 100644 --- a/src/kits/mail/StatusWindow.cpp +++ b/src/kits/mail/StatusWindow.cpp @@ -1,58 +1,58 @@ -/* BMailStatusWindow - the status window while fetching/sending mails -** -** Copyright (c) 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. -*/ +/* + * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. + * Copyright 2004-2007, Haiku Inc. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ +//! The status window while fetching/sending mails -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -class _EXPORT BMailStatusWindow; -class _EXPORT BMailStatusView; #include "status.h" #include "MailSettings.h" #include -/*------------------------------------------------ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -BMailStatusWindow +#include +#include -------------------------------------------------*/ static BLocker sLock; -BMailStatusWindow::BMailStatusWindow(BRect rect, const char *name, uint32 s) +BMailStatusWindow::BMailStatusWindow(BRect rect, const char *name, uint32 showMode) : BWindow(rect, name, B_MODAL_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_NOT_CLOSABLE | B_NO_WORKSPACE_ACTIVATION | B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE), - fShowMode(s), + B_NOT_CLOSABLE | B_NO_WORKSPACE_ACTIVATION | B_NOT_V_RESIZABLE + | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE), + fShowMode(showMode), fWindowMoved(0L) { BRect frame(Bounds()); frame.InsetBy(90.0 + 5.0, 5.0); - BButton *button = new BButton(frame, "check_mail", - MDR_DIALECT_CHOICE ("Check Mail Now","メールチェック"), - new BMessage('mbth'), B_FOLLOW_LEFT_RIGHT, - B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE); - button->ResizeToPreferred(); - frame = button->Frame(); + fCheckNowButton = new BButton(frame, "check_mail", + MDR_DIALECT_CHOICE ("Check Mail Now","メールチェック"), + new BMessage('mbth'), B_FOLLOW_LEFT_RIGHT, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE); + fCheckNowButton->ResizeToPreferred(); + frame = fCheckNowButton->Frame(); - button->ResizeTo(button->Bounds().Width(),25); - button->SetTarget(be_app_messenger); + fCheckNowButton->SetTarget(be_app_messenger); frame.OffsetBy(0.0, frame.Height()); frame.InsetBy(-90.0, 0.0); @@ -63,17 +63,17 @@ BMailStatusWindow::BMailStatusWindow(BRect rect, const char *name, uint32 s) fMessageView->SetText(MDR_DIALECT_CHOICE ("No new messages.","未読メッセージはありません")); float framewidth = frame.Width(); fMessageView->ResizeToPreferred(); - fMessageView->ResizeTo(framewidth,fMessageView->Bounds().Height()); + fMessageView->ResizeTo(framewidth, fMessageView->Bounds().Height()); frame = fMessageView->Frame(); frame.InsetBy(-5.0, -5.0); frame.top = 0.0; - fDefaultView = new BBox(frame, "default_view", B_FOLLOW_LEFT_RIGHT, - B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP, B_PLAIN_BORDER); + fDefaultView = new BView(frame, "default_view", B_FOLLOW_LEFT_RIGHT, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP); fDefaultView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fDefaultView->AddChild(button); + fDefaultView->AddChild(fCheckNowButton); fDefaultView->AddChild(fMessageView); fMinWidth = fDefaultView->Bounds().Width(); @@ -95,7 +95,7 @@ BMailStatusWindow::BMailStatusWindow(BRect rect, const char *name, uint32 s) ResizeBy(x_off_set, y_off_set); fDefaultView->ResizeBy(x_off_set, y_off_set); - button->ResizeBy(x_off_set, y_off_set); + fCheckNowButton->ResizeBy(x_off_set, y_off_set); fMessageView->ResizeBy(x_off_set, y_off_set); } } @@ -115,8 +115,22 @@ BMailStatusWindow::BMailStatusWindow(BRect rect, const char *name, uint32 s) fFrame = Frame(); + BPath path; + status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + if (status == B_OK) { + path.Append("Mail/chains/inbound"); + create_directory(path.Path(), 0755); + BDirectory chainDirectory(path.Path()); + if (chainDirectory.GetNodeRef(&fChainDirectory) == B_OK) { + // Watch this directory for changes + watch_node(&fChainDirectory, B_WATCH_DIRECTORY, this); + _CheckChains(); + } + } + if (fShowMode != B_MAIL_SHOW_STATUS_WINDOW_ALWAYS) Hide(); + Show(); } @@ -134,6 +148,21 @@ BMailStatusWindow::~BMailStatusWindow() general.SetStatusWindowWorkspaces((int32)Workspaces()); general.Save(); } + + stop_watching(this); +} + + +//! Activate the "Check Now" button only if there are inbound accounts +void +BMailStatusWindow::_CheckChains() +{ + BDirectory directory(&fChainDirectory); + + entry_ref ref; + bool isEmpty = directory.GetNextRef(&ref) != B_OK; + + fCheckNowButton->SetEnabled(!isEmpty); } @@ -190,6 +219,10 @@ BMailStatusWindow::MessageReceived(BMessage *msg) be_roster->Launch(B_MAIL_TYPE, msg); break; + case B_NODE_MONITOR: + _CheckChains(); + break; + default: BWindow::MessageReceived(msg); } diff --git a/src/servers/mail/deskbarview.cpp b/src/servers/mail/deskbarview.cpp index 6f95c5bded..00f35cdcfc 100644 --- a/src/servers/mail/deskbarview.cpp +++ b/src/servers/mail/deskbarview.cpp @@ -1,7 +1,7 @@ /* DeskbarView - main_daemon's deskbar menu and view -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ + * + * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. + */ #include @@ -279,23 +279,25 @@ DeskbarView::MessageReceived(BMessage *message) } } -void DeskbarView::ChangeIcon(int32 icon) + +void +DeskbarView::ChangeIcon(int32 icon) { - if(fCurrentIconState == icon) + if (fCurrentIconState == icon) return; - + BBitmap *newIcon(NULL); image_info info; - if (our_image(&info) == B_OK) - { - BFile file(info.name,B_READ_ONLY); + if (our_image(&info) == B_OK) { + BFile file(info.name, B_READ_ONLY); if (file.InitCheck() < B_OK) goto err; BResources rsrc(&file); size_t len; - const void *data = rsrc.LoadResource('BBMP',icon == NEW_MAIL ? "New" : "Read",&len); + const void *data = rsrc.LoadResource('BBMP', icon == NEW_MAIL + ? "New" : "Read",&len); if (len == 0) goto err; @@ -305,8 +307,7 @@ void DeskbarView::ChangeIcon(int32 icon) if (archive.Unflatten(&stream) != B_OK) goto err; newIcon = new BBitmap(&archive); - } - else + } else fputs("no image!", stderr); err: @@ -316,12 +317,16 @@ err: Invalidate(); } -void DeskbarView::Pulse() + +void +DeskbarView::Pulse() { - // Check if mail_daemon is still running + // TODO: Check if mail_daemon is still running } -void DeskbarView::MouseUp(BPoint pos) + +void +DeskbarView::MouseUp(BPoint pos) { if (fLastButtons & B_PRIMARY_MOUSE_BUTTON) { if (OpenFolder("mail/mailbox") != B_OK) @@ -334,22 +339,27 @@ void DeskbarView::MouseUp(BPoint pos) BMailDaemon::CheckMail(true); } -void DeskbarView::MouseDown(BPoint pos) + +void +DeskbarView::MouseDown(BPoint pos) { Looper()->CurrentMessage()->FindInt32("buttons",&fLastButtons); Looper()->CurrentMessage()->PrintToStream(); - if (fLastButtons & B_SECONDARY_MOUSE_BUTTON) - { + if (fLastButtons & B_SECONDARY_MOUSE_BUTTON) { ConvertToScreen(&pos); - + BPopUpMenu *menu = BuildMenu(); - if (menu) - menu->Go(pos,true,true,BRect(pos.x - 2, pos.y - 2, pos.x + 2, pos.y + 2),true); + if (menu) { + menu->Go(pos, true, true, BRect(pos.x - 2, pos.y - 2, + pos.x + 2, pos.y + 2), true); + } } } -bool DeskbarView::CreateMenuLinks(BDirectory &directory,BPath &path) + +bool +DeskbarView::CreateMenuLinks(BDirectory &directory,BPath &path) { status_t status = directory.SetTo(path.Path()); if (status == B_OK) @@ -366,23 +376,23 @@ bool DeskbarView::CreateMenuLinks(BDirectory &directory,BPath &path) || directory.CreateDirectory(path.Leaf(), NULL) < B_OK || directory.SetTo(path.Path()) < B_OK) return false; - + BPath targetPath; find_directory(B_USER_DIRECTORY, &targetPath); targetPath.Append("mail/in"); - - directory.CreateSymLink("Open Inbox Folder",targetPath.Path(),NULL); + + directory.CreateSymLink("Open Inbox Folder", targetPath.Path(), NULL); targetPath.GetParent(&targetPath); - directory.CreateSymLink("Open Mail Folder",targetPath.Path(),NULL); + directory.CreateSymLink("Open Mail Folder", targetPath.Path(), NULL); // create the draft query - + BFile file; - if (directory.CreateFile("Open Draft",&file) < B_OK) + if (directory.CreateFile("Open Draft", &file) < B_OK) return true; BString string("MAIL:draft==1"); - file.WriteAttrString("_trk/qrystr",&string); + file.WriteAttrString("_trk/qrystr", &string); string = "E-mail"; file.WriteAttrString("_trk/qryinitmime", &string); BNodeInfo(&file).SetType("application/x-vnd.Be-query"); @@ -390,14 +400,17 @@ bool DeskbarView::CreateMenuLinks(BDirectory &directory,BPath &path) return true; } -void DeskbarView::CreateNewMailQuery(BEntry &query) + +void +DeskbarView::CreateNewMailQuery(BEntry &query) { BFile file(&query, B_READ_WRITE | B_CREATE_FILE); - if(file.InitCheck() != B_OK) + if (file.InitCheck() != B_OK) return; - BString string("((" B_MAIL_ATTR_STATUS "==\"[nN][eE][wW]\")&&((BEOS:TYPE==\"text/x-email\")||(BEOS:TYPE==\"text/x-partial-email\")))"); - file.WriteAttrString("_trk/qrystr",&string); + BString string("((" B_MAIL_ATTR_STATUS "==\"[nN][eE][wW]\")&&((BEOS:TYPE==" + "\"text/x-email\")||(BEOS:TYPE==\"text/x-partial-email\")))"); + file.WriteAttrString("_trk/qrystr", &string); string = "E-mail"; file.WriteAttrString("_trk/qryinitmime", &string); BNodeInfo(&file).SetType("application/x-vnd.Be-query"); @@ -407,9 +420,9 @@ void DeskbarView::CreateNewMailQuery(BEntry &query) BPopUpMenu * DeskbarView::BuildMenu() { - BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING,false,false); + BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); menu->SetFont(be_plain_font); - + menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( "Create New Message","N) 新規メッセージ作成")B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_NEW))); @@ -424,14 +437,12 @@ DeskbarView::BuildMenu() BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); - + BDirectory directory; - if (CreateMenuLinks(directory,path)) - { + if (CreateMenuLinks(directory, path)) { int32 count = 0; - while (directory.GetNextRef(&ref) == B_OK) - { + while (directory.GetNextRef(&ref) == B_OK) { count++; path.SetTo(&ref); @@ -442,12 +453,10 @@ DeskbarView::BuildMenu() // we are using the NavMenu only for directories and queries bool useNavMenu = false; - if (entry.InitCheck() == B_OK) - { + if (entry.InitCheck() == B_OK) { if (entry.IsDirectory()) useNavMenu = true; - else if (entry.IsFile()) - { + else if (entry.IsFile()) { // Files should use the BMenuItem unless they are queries char mimeString[B_MIME_TYPE_LENGTH]; BNode node(&entry); @@ -456,20 +465,19 @@ DeskbarView::BuildMenu() && strcmp(mimeString, "application/x-vnd.Be-query") == 0) useNavMenu = true; } - //clobber the existing ref only if the symlink derefernces completely, - //otherwise we'll stick with what we have + // clobber the existing ref only if the symlink derefernces completely, + // otherwise we'll stick with what we have entry.GetRef(&ref); } msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs", &ref); - - if (useNavMenu) - { - item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(),B_REFS_RECEIVED,tracker), msg); + + if (useNavMenu) { + item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(), + B_REFS_RECEIVED, tracker), msg); navMenu->SetNavDir(&ref); - } - else + } else item = new BMenuItem(path.Leaf(), msg); menu->AddItem(item); @@ -490,12 +498,12 @@ DeskbarView::BuildMenu() // The New E-mail query - if (fNewMessages > 0) - { + if (fNewMessages > 0) { BString string; - MDR_DIALECT_CHOICE ( - string << fNewMessages << " new message" << ((fNewMessages != 1) ? "s" : B_EMPTY_STRING), - string << fNewMessages << " 通の未読メッセージ"); + MDR_DIALECT_CHOICE( + string << fNewMessages << " new message" + << (fNewMessages != 1 ? "s" : B_EMPTY_STRING), + string << fNewMessages << " 通の未読メッセージ"); find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/New E-mail"); @@ -505,75 +513,76 @@ DeskbarView::BuildMenu() CreateNewMailQuery(query); query.GetRef(&ref); - item = new BMenuItem( - navMenu = new BNavMenu(string.String(),B_REFS_RECEIVED,BMessenger(kTrackerSignature)), + item = new BMenuItem(navMenu = new BNavMenu(string.String(), + B_REFS_RECEIVED, BMessenger(kTrackerSignature)), msg = new BMessage(B_REFS_RECEIVED)); msg->AddRef("refs", &ref); navMenu->SetNavDir(&ref); menu->AddItem(item); - } - else - { + } else { menu->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("No new messages","未読メッセージなし"), NULL)); item->SetEnabled(false); } - - if (modifiers() & B_SHIFT_KEY) - { - BList list; - GetInboundMailChains(&list); + BList list; + GetInboundMailChains(&list); + + if (modifiers() & B_SHIFT_KEY) { BMenu *chainMenu = new BMenu( MDR_DIALECT_CHOICE ("Check For Mails Only","R) メール受信のみ")); BFont font; menu->GetFont(&font); chainMenu->SetFont(&font); - for (int32 i = 0;i < list.CountItems();i++) { + for (int32 i = 0; i < list.CountItems(); i++) { BMailChain *chain = (BMailChain *)list.ItemAt(i); BMessage *message = new BMessage(MD_CHECK_FOR_MAILS); - message->AddString("account",chain->Name()); + message->AddString("account", chain->Name()); - chainMenu->AddItem(new BMenuItem(chain->Name(),message)); + chainMenu->AddItem(new BMenuItem(chain->Name(), message)); delete chain; } + if (list.IsEmpty()) { + item = new BMenuItem("", NULL); + item->SetEnabled(false); + chainMenu->AddItem(item); + } chainMenu->SetTargetForItems(this); - menu->AddItem(new BMenuItem(chainMenu,new BMessage(MD_CHECK_FOR_MAILS))); + menu->AddItem(new BMenuItem(chainMenu, new BMessage(MD_CHECK_FOR_MAILS))); // Not used: // menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE ( // "Check For Mails Only","メール受信のみ"), new BMessage(MD_CHECK_FOR_MAILS))); menu->AddItem(new BMenuItem( - MDR_DIALECT_CHOICE ("Send Pending Mails","M) 保留メールを送信"), + MDR_DIALECT_CHOICE ("Send Pending Mails", "M) 保留メールを送信"), new BMessage(MD_SEND_MAILS))); - } - else - menu->AddItem(new BMenuItem( - MDR_DIALECT_CHOICE ("Check For Mail Now","C) メールチェック"), + } else { + menu->AddItem(item = new BMenuItem( + MDR_DIALECT_CHOICE ("Check For Mail Now", "C) メールチェック"), new BMessage(MD_CHECK_SEND_NOW))); + if (list.IsEmpty()) + item->SetEnabled(false); + } menu->AddSeparatorItem(); menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Edit Preferences","P) メール環境設定") B_UTF8_ELLIPSIS, new BMessage(MD_OPEN_PREFS))); - if (modifiers() & B_SHIFT_KEY) - { + if (modifiers() & B_SHIFT_KEY) { menu->AddItem(new BMenuItem( MDR_DIALECT_CHOICE ("Shutdown Mail Services","Q) 終了"), new BMessage(B_QUIT_REQUESTED))); } - + // Reset Item Targets (only those which aren't already set) - for (int32 i = menu->CountItems();i-- > 0;) - { + for (int32 i = menu->CountItems(); i-- > 0;) { item = menu->ItemAt(i); - if (item && (msg = item->Message()) != NULL) - { + if (item && (msg = item->Message()) != NULL) { if (msg->what == B_REFS_RECEIVED) item->SetTarget(tracker); else