From 9917e1a6b2e90de417e2bd3310fefbe7553af46a Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 8 Apr 2010 20:38:53 +0000 Subject: [PATCH] Style changes. No functional changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36095 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/mail/MailChain.cpp | 311 ++++++++++++++++++++++-------------- 1 file changed, 194 insertions(+), 117 deletions(-) diff --git a/src/kits/mail/MailChain.cpp b/src/kits/mail/MailChain.cpp index fa6d707940..516b9a9949 100644 --- a/src/kits/mail/MailChain.cpp +++ b/src/kits/mail/MailChain.cpp @@ -15,70 +15,89 @@ #include #include -class _EXPORT BMailChain; +class BMailChain; 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 #include #include + BMailChain::BMailChain(uint32 i) - : id(i), meta_data(NULL), _err(B_OK), direction(inbound), settings_ct(0), addons_ct(0) + : + id(i), + meta_data(NULL), + _err(B_OK), + direction(inbound), + settings_ct(0), + addons_ct(0) { name[0] = 0; Reload(); } + BMailChain::BMailChain(BMessage* settings) - : id(settings->FindInt32("id")), meta_data(NULL), _err(B_OK), direction(inbound), settings_ct(0), addons_ct(0) + : + id(settings->FindInt32("id")), + meta_data(NULL), + _err(B_OK), + direction(inbound), + settings_ct(0), + addons_ct(0) { name[0] = 0; Load(settings); } -BMailChain::~BMailChain() { +BMailChain::~BMailChain() +{ delete meta_data; for (int32 i = 0; filter_settings.ItemAt(i); i++) - delete (BMessage *)filter_settings.ItemAt(i); + delete (BMessage*)filter_settings.ItemAt(i); for (int32 i = 0; filter_addons.ItemAt(i); i++) - delete (entry_ref *)filter_addons.ItemAt(i); + delete (entry_ref*)filter_addons.ItemAt(i); } -status_t BMailChain::Load(BMessage* settings) + +status_t +BMailChain::Load(BMessage* settings) { delete meta_data; meta_data = new BMessage; if (settings->HasMessage("meta_data")) - settings->FindMessage("meta_data",meta_data); + settings->FindMessage("meta_data", meta_data); const char* n; - status_t ret = settings->FindString("name",&n); - if (ret == B_OK) strncpy(name,n,sizeof(name)); - else name[0]='\0'; + status_t ret = settings->FindString("name", &n); + if (ret == B_OK) + strncpy(name, n, sizeof(name)); + else + name[0] = '\0'; type_code t; - settings->GetInfo("filter_settings",&t,(int32 *)(&settings_ct)); - settings->GetInfo("filter_addons",&t,(int32 *)(&addons_ct)); - if (settings_ct!=addons_ct) return B_MISMATCHED_VALUES; + settings->GetInfo("filter_settings", &t, (int32*)(&settings_ct)); + settings->GetInfo("filter_addons", &t, (int32*)(&addons_ct)); + if (settings_ct != addons_ct) + return B_MISMATCHED_VALUES; - for (int i = 0;;i++) - { - BMessage *filter = new BMessage(); - entry_ref *ref = new entry_ref(); - char *addon_path; + for (int i = 0;;i++) { + BMessage* filter = new BMessage(); + entry_ref* ref = new entry_ref(); + char* addon_path; - if (settings->FindMessage("filter_settings",i,filter) < B_OK - || (settings->FindString("filter_addons",i,(const char **)&addon_path) < B_OK - || get_ref_for_path(addon_path,ref) < B_OK) - && settings->FindRef("filter_addons",i,ref) < B_OK) - { + if (settings->FindMessage("filter_settings", i, filter) < B_OK + || (settings->FindString("filter_addons", i, (const char**)&addon_path) < B_OK + || get_ref_for_path(addon_path, ref) < B_OK) + && settings->FindRef("filter_addons", i, ref) < B_OK) { delete filter; delete ref; break; @@ -88,19 +107,21 @@ status_t BMailChain::Load(BMessage* settings) break; } - if (filter_settings.CountItems()!=settings_ct - || filter_addons.CountItems()!=addons_ct) + if (filter_settings.CountItems() != settings_ct + || filter_addons.CountItems() != addons_ct) return B_NO_MEMORY; - else - return B_OK; + + return B_OK; } -status_t BMailChain::InitCheck() const + +status_t +BMailChain::InitCheck() const { - if (settings_ct!=addons_ct) + if (settings_ct != addons_ct) return B_MISMATCHED_VALUES; - if (filter_settings.CountItems()!=settings_ct - || filter_addons.CountItems()!=addons_ct) + if (filter_settings.CountItems() != settings_ct + || filter_addons.CountItems() != addons_ct) return B_NO_MEMORY; if (_err < B_OK) return _err; @@ -109,47 +130,50 @@ status_t BMailChain::InitCheck() const } -status_t BMailChain::Archive(BMessage* archive, bool deep) const +status_t +BMailChain::Archive(BMessage* archive, bool deep) const { - status_t ret = B_OK; + status_t ret = InitCheck(); - ret = InitCheck(); - if ((ret!=B_OK) && (ret != B_FILE_ERROR)) return ret; + if (ret != B_OK && ret != B_FILE_ERROR) + return ret; - ret = BArchivable::Archive(archive,deep); - if (ret!=B_OK) return ret; + ret = BArchivable::Archive(archive, deep); + if (ret != B_OK) + return ret; - ret = archive->AddString("class","BMailChain"); - if (ret!=B_OK) return ret; + ret = archive->AddString("class", "BMailChain"); + if (ret != B_OK) + return ret; + ret = archive->AddInt32("id", id); + if (ret != B_OK) + return ret; - ret = archive->AddInt32("id",id); - if (ret!=B_OK) return ret; + ret = archive->AddString("name", name); + if (ret != B_OK) + return ret; - ret = archive->AddString("name",name); - if (ret!=B_OK) return ret; + ret = archive->AddMessage("meta_data", meta_data); + if (ret != B_OK) + return ret; - ret = archive->AddMessage("meta_data",meta_data); - if (ret!=B_OK) return ret; - - if (ret==B_OK && deep) - { + if (ret == B_OK && deep) { BMessage* settings; entry_ref* ref; int32 i; for (i = 0;((settings = (BMessage*)filter_settings.ItemAt(i)) != NULL) && ((ref = (entry_ref*)filter_addons.ItemAt(i)) != NULL); - ++i) - { - ret = archive->AddMessage("filter_settings",settings); + ++i) { + ret = archive->AddMessage("filter_settings", settings); if (ret < B_OK) return ret; BPath path(ref); if ((ret = path.InitCheck()) < B_OK) return ret; - ret = archive->AddString("filter_addons",path.Path()); + ret = archive->AddString("filter_addons", path.Path()); if (ret < B_OK) return ret; } @@ -160,17 +184,20 @@ status_t BMailChain::Archive(BMessage* archive, bool deep) const return B_OK; } -BArchivable* BMailChain::Instantiate(BMessage* archive) + +BArchivable* +BMailChain::Instantiate(BMessage* archive) { - return validate_instantiation(archive, "BMailChain")? + return validate_instantiation(archive, "BMailChain") ? new BMailChain(archive) : NULL; } -status_t BMailChain::Path(BPath *path) const + +status_t +BMailChain::Path(BPath* path) const { status_t status = find_directory(B_USER_SETTINGS_DIRECTORY,path); - if (status < B_OK) - { + if (status < B_OK) { fprintf(stderr, "Couldn't find user settings directory: %s\n", strerror(status)); return status; @@ -190,14 +217,15 @@ status_t BMailChain::Path(BPath *path) const return B_OK; } -status_t BMailChain::Save(bigtime_t /*timeout*/) + +status_t +BMailChain::Save(bigtime_t /*timeout*/) { status_t ret; BMessage archive; ret = Archive(&archive,true); - if (ret != B_OK) - { + if (ret != B_OK) { fprintf(stderr, "Couldn't archive chain %ld: %s\n", id, strerror(ret)); return ret; @@ -214,7 +242,9 @@ status_t BMailChain::Save(bigtime_t /*timeout*/) return MailInternal::WriteMessageFile(archive,directory,path.Leaf()/*,timeout*/); } -status_t BMailChain::Delete() const + +status_t +BMailChain::Delete() const { status_t status; BPath path; @@ -228,22 +258,27 @@ status_t BMailChain::Delete() const return entry.Remove(); } -b_mail_chain_direction BMailChain::ChainDirection() const { + +b_mail_chain_direction +BMailChain::ChainDirection() const +{ return direction; } -void BMailChain::SetChainDirection(b_mail_chain_direction dir) { + +void +BMailChain::SetChainDirection(b_mail_chain_direction dir) +{ direction = dir; } -status_t BMailChain::Reload() + +status_t +BMailChain::Reload() { - status_t ret; - BPath path; - ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (ret != B_OK) - { + status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + if (ret != B_OK) { fprintf(stderr, "Couldn't find user settings directory: %s\n", strerror(ret)); _err = ret; @@ -284,8 +319,7 @@ status_t BMailChain::Reload() BFile settings(path.Path(),B_READ_ONLY); ret = settings.InitCheck(); - if (ret != B_OK) - { + if (ret != B_OK) { BMessage empty; fprintf(stderr, "Couldn't open chain settings file '%s': %s\n", path.Path(), strerror(ret)); @@ -297,8 +331,7 @@ status_t BMailChain::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)); Load(&tmp); @@ -311,70 +344,104 @@ status_t BMailChain::Reload() return ret; } -uint32 BMailChain::ID() const { return id; } -const char *BMailChain::Name() const { return name; } -status_t BMailChain::SetName(const char* n) +uint32 +BMailChain::ID() const { - if (n) strncpy(name,n,sizeof(name)); - else name[0]='\0'; + return id; +} + + +const char* +BMailChain::Name() const +{ + return name; +} + + +status_t +BMailChain::SetName(const char* n) +{ + if (n) + strncpy(name, n, sizeof(name)); + else + name[0] = '\0'; return B_OK; } -BMessage *BMailChain::MetaData() const { + +BMessage* +BMailChain::MetaData() const +{ return meta_data; } -int32 BMailChain::CountFilters() const + +int32 +BMailChain::CountFilters() const { return filter_settings.CountItems(); } -status_t BMailChain::GetFilter(int32 index, BMessage* out_settings, entry_ref *addon) const + +status_t +BMailChain::GetFilter(int32 index, BMessage* out_settings, + entry_ref* addon) const { if (index >= filter_settings.CountItems()) return B_BAD_INDEX; - BMessage *settings = (BMessage *)filter_settings.ItemAt(index); - if (settings) *out_settings = *settings; - else return B_BAD_INDEX; + BMessage* settings = (BMessage*)filter_settings.ItemAt(index); + if (settings) + *out_settings = *settings; + else + return B_BAD_INDEX; - if (addon) - { - entry_ref* ref = (entry_ref* )filter_addons.ItemAt(index); - if (ref) *addon = *ref; - else return B_BAD_INDEX; + if (addon) { + entry_ref* ref = (entry_ref*)filter_addons.ItemAt(index); + if (ref) + *addon = *ref; + else + return B_BAD_INDEX; } return B_OK; } -status_t BMailChain::SetFilter(int32 index, const BMessage& s, const entry_ref& addon) + +status_t +BMailChain::SetFilter(int32 index, const BMessage& s, + const entry_ref& addon) { - BMessage *settings = (BMessage *)filter_settings.ItemAt(index); - if (settings) *settings = s; - else return B_BAD_INDEX; + BMessage* settings = (BMessage*)filter_settings.ItemAt(index); + if (settings) + *settings = s; + else + return B_BAD_INDEX; - entry_ref* ref = (entry_ref* )filter_addons.ItemAt(index); - if (ref) *ref = addon; - else return B_BAD_INDEX; + entry_ref* ref = (entry_ref*)filter_addons.ItemAt(index); + if (ref) + *ref = addon; + else + return B_BAD_INDEX; return B_OK; } -status_t BMailChain::AddFilter(const BMessage& settings, const entry_ref& addon) + +status_t +BMailChain::AddFilter(const BMessage& settings, const entry_ref& addon) { - BMessage *s = new BMessage(settings); - entry_ref*a = new entry_ref(addon); + BMessage* s = new BMessage(settings); + entry_ref* a = new entry_ref(addon); - if (!filter_settings.AddItem(s)) - { + if (!filter_settings.AddItem(s)) { delete s; delete a; return B_BAD_INDEX; } - else if (!filter_addons.AddItem(a)) - { + + if (!filter_addons.AddItem(a)) { filter_settings.RemoveItem(settings_ct); delete s; delete a; @@ -387,19 +454,22 @@ status_t BMailChain::AddFilter(const BMessage& settings, const entry_ref& addon) return B_OK; } -status_t BMailChain::AddFilter(int32 index, const BMessage& settings, const entry_ref& addon) + + +status_t +BMailChain::AddFilter(int32 index, const BMessage& settings, + const entry_ref& addon) { - BMessage *s = new BMessage(settings); - entry_ref*a = new entry_ref(addon); + BMessage*s = new BMessage(settings); + entry_ref* a = new entry_ref(addon); - if (!filter_settings.AddItem(s,index)) - { + if (!filter_settings.AddItem(s, index)) { delete s; delete a; return B_BAD_INDEX; } - else if (!filter_addons.AddItem(a,index)) - { + + if (!filter_addons.AddItem(a, index)) { filter_settings.RemoveItem(index); delete s; delete a; @@ -411,20 +481,27 @@ status_t BMailChain::AddFilter(int32 index, const BMessage& settings, const entr return B_OK; } -status_t BMailChain::RemoveFilter(int32 index) + +status_t +BMailChain::RemoveFilter(int32 index) { BMessage* s = (BMessage*)filter_settings.RemoveItem(index); delete s; - entry_ref*a = (entry_ref*)filter_addons.RemoveItem(index); + entry_ref* a = (entry_ref*)filter_addons.RemoveItem(index); delete a; --settings_ct; --addons_ct; - return s||a?B_OK:B_BAD_INDEX; + return s || a ? B_OK : B_BAD_INDEX; } -void BMailChain::RunChain(BMailStatusWindow *window, bool async, bool save_when_done, bool delete_when_done) { - (new BMailChainRunner(this,window,true,save_when_done,delete_when_done))->RunChain(async); + +void +BMailChain::RunChain(BMailStatusWindow *window, bool async, + bool save_when_done, bool delete_when_done) +{ + (new BMailChainRunner(this, window, true, save_when_done, + delete_when_done))->RunChain(async); }