From 9f05ce11368138438285351ea0f45df8a8343fc5 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 1 Aug 2021 06:37:25 -0500 Subject: [PATCH] Misc. tweaks, no functional change --- application/ChatCommand.h | 2 -- application/ImageCache.cpp | 9 +++++---- application/ProtocolLooper.cpp | 19 +++++++++++++------ application/ProtocolTemplate.cpp | 2 +- application/Role.h | 2 +- application/Server.cpp | 10 ++++++---- application/TheApp.cpp | 1 - application/User.cpp | 10 +++++----- application/User.h | 1 - application/Utils.cpp | 19 ++++++------------- application/Utils.h | 2 +- application/views/ReplicantMenuItem.cpp | 8 +++----- application/views/ReplicantStatusView.cpp | 3 +-- application/views/ReplicantStatusView.h | 2 +- application/views/StatusMenuItem.cpp | 8 +++----- 15 files changed, 46 insertions(+), 52 deletions(-) diff --git a/application/ChatCommand.h b/application/ChatCommand.h index 4b7a5af..c18b83e 100644 --- a/application/ChatCommand.h +++ b/application/ChatCommand.h @@ -59,6 +59,4 @@ private: typedef KeyMap CommandMap; - #endif // CHAT_COMMAND_H - diff --git a/application/ImageCache.cpp b/application/ImageCache.cpp index 4216a08..5344a9a 100644 --- a/application/ImageCache.cpp +++ b/application/ImageCache.cpp @@ -52,9 +52,8 @@ ImageCache::~ImageCache() ImageCache* ImageCache::Get() { - if (fInstance == NULL) { + if (fInstance == NULL) fInstance = new ImageCache(); - } return fInstance; } @@ -103,8 +102,10 @@ ImageCache::Release() void ImageCache::_LoadResource(int identifier, const char* key) { - BResources* res = ChatResources(); - BBitmap* bitmap = IconFromResources(res, identifier, B_LARGE_ICON); + BResources res = ChatResources(); + if (res.InitCheck() != B_OK) + return; + BBitmap* bitmap = IconFromResources(&res, identifier, B_LARGE_ICON); if (bitmap != NULL && bitmap->IsValid() == true) fBitmaps.AddItem(BString(key), bitmap); } diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index fab72e2..cafa399 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -89,14 +89,16 @@ ProtocolLooper::ConversationById(BString id) void ProtocolLooper::AddConversation(Conversation* chat) { - fChatMap.AddItem(chat->GetId(), chat); + if (chat != NULL) + fChatMap.AddItem(chat->GetId(), chat); } void ProtocolLooper::RemoveConversation(Conversation* chat) { - fChatMap.RemoveItemFor(chat->GetId()); + if (chat != NULL) + fChatMap.RemoveItemFor(chat->GetId()); } @@ -118,13 +120,16 @@ ProtocolLooper::ContactById(BString id) void ProtocolLooper::AddContact(Contact* contact) { - fRosterMap.AddItem(contact->GetId(), contact); + if (contact != NULL) + fRosterMap.AddItem(contact->GetId(), contact); } void ProtocolLooper::RemoveContact(Contact* contact) { + if (contact == NULL) + return; fRosterMap.RemoveItemFor(contact->GetId()); fUserMap.AddItem(contact->GetId(), (User*)contact); } @@ -159,7 +164,8 @@ ProtocolLooper::UserById(BString id) void ProtocolLooper::AddUser(User* user) { - fUserMap.AddItem(user->GetId(), user); + if (user != NULL) + fUserMap.AddItem(user->GetId(), user); } @@ -187,7 +193,8 @@ ProtocolLooper::GetOwnContact() void ProtocolLooper::SetOwnContact(Contact* contact) { - fMySelf = contact; + if (contact != NULL) + fMySelf = contact; } @@ -203,7 +210,7 @@ ProtocolLooper::GetListItem() { if (fListItem == NULL) fListItem = new ConversationAccountItem(fProtocol->GetName(), - fInstance); + fInstance); return fListItem; } diff --git a/application/ProtocolTemplate.cpp b/application/ProtocolTemplate.cpp index 0588b68..a05747f 100644 --- a/application/ProtocolTemplate.cpp +++ b/application/ProtocolTemplate.cpp @@ -42,7 +42,7 @@ ProtocolTemplate::ProtocolTemplate(ChatProtocol* protocol, const char* type) if (settingsTemplate.IsEmpty() == true) { size_t size; const void* buff = - ChatResources()->LoadResource(B_MESSAGE_TYPE, type, &size); + ChatResources().LoadResource(B_MESSAGE_TYPE, type, &size); if (buff != NULL) settingsTemplate.Unflatten((const char*)buff); diff --git a/application/Role.h b/application/Role.h index ee6cf72..1ed0d0d 100644 --- a/application/Role.h +++ b/application/Role.h @@ -29,7 +29,7 @@ public: { } - BString fTitle; + const char* fTitle; int32 fPerms; // Permissions afforded to role, as described above. int32 fPriority; // 'Rank' of role, with higher being greater priority. // I.E., a user with a priority of 11 can't kick a user diff --git a/application/Server.cpp b/application/Server.cpp index 0973c4a..7c8ecb4 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -55,13 +55,15 @@ Server::Server() || fCommands.CountItems() > 0) return; - BResources* res = ChatResources(); + BResources res = ChatResources(); + if (res.InitCheck() != B_OK) + return; // Loading user pop-up items for (int i = 0; i < 6; i++) { size_t size; BMessage temp; - const void* buff = res->LoadResource(B_MESSAGE_TYPE, 1100 + i, &size); + const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1100 + i, &size); temp.Unflatten((const char*)buff); fUserItems.AddItem(new BMessage(temp)); } @@ -69,7 +71,7 @@ Server::Server() // Loading room pop-up items BMessage leave; size_t leaveSize; - const void* leaveBuff = res->LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize); + const void* leaveBuff = res.LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize); leave.Unflatten((const char*)leaveBuff); fChatItems.AddItem(new BMessage(leave)); @@ -77,7 +79,7 @@ Server::Server() for (int i = 0; i < 9; i++) { size_t size; BMessage temp; - const void* buff = res->LoadResource(B_MESSAGE_TYPE, 1140 + i, &size); + const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1140 + i, &size); temp.Unflatten((const char*)buff); ChatCommand* cmd = new ChatCommand(&temp); fCommands.AddItem(cmd->GetName(), cmd); diff --git a/application/TheApp.cpp b/application/TheApp.cpp index e588030..d01519c 100644 --- a/application/TheApp.cpp +++ b/application/TheApp.cpp @@ -95,7 +95,6 @@ TheApp::ReadyToRun() return; } } - fMainWin->Start(); fMainWin->Show(); } diff --git a/application/User.cpp b/application/User.cpp index 14a1fda..cefcf1f 100644 --- a/application/User.cpp +++ b/application/User.cpp @@ -264,18 +264,18 @@ User::_SetCachedAvatar(BBitmap* bitmap) { _EnsureCachePath(); BFile cacheFile(fCachePath.Path(), B_WRITE_ONLY | B_CREATE_FILE); + if (cacheFile.InitCheck() != B_OK) + return; - BBitmapStream* stream = new BBitmapStream(bitmap); + BBitmapStream stream(bitmap); BTranslatorRoster* roster = BTranslatorRoster::Default(); int32 format_count; translator_info info; const translation_format* formats = NULL; - roster->Identify(stream, new BMessage(), &info, 0, "image"); + roster->Identify(&stream, new BMessage(), &info, 0, "image"); roster->GetOutputFormats(info.translator, &formats, &format_count); - roster->Translate(info.translator, stream, new BMessage(), &cacheFile, + roster->Translate(info.translator, &stream, NULL, &cacheFile, formats[0].type); } - - diff --git a/application/User.h b/application/User.h index c31b593..129b49d 100644 --- a/application/User.h +++ b/application/User.h @@ -79,7 +79,6 @@ protected: UserItem* fListItem; BString fID; - bigtime_t fInstance; BString fName; BString fPersonalStatus; BBitmap* fAvatarBitmap; diff --git a/application/Utils.cpp b/application/Utils.cpp index 709493f..b2fdaba 100644 --- a/application/Utils.cpp +++ b/application/Utils.cpp @@ -91,23 +91,16 @@ CommandArgs(BString line) } -BResources* +BResources ChatResources() { + BResources res; image_info info; - if (our_image(info) != B_OK) - return NULL; - - BFile file(info.name, B_READ_ONLY); - if (file.InitCheck() != B_OK) - return NULL; - - BResources* res = new BResources(&file); - if (res->InitCheck() != B_OK) { - delete res; - return NULL; + if (our_image(info) == B_OK) { + BFile file(info.name, B_READ_ONLY); + if (file.InitCheck() == B_OK) + res.SetTo(&file); } - return res; } diff --git a/application/Utils.h b/application/Utils.h index a6d4556..ec88b82 100644 --- a/application/Utils.h +++ b/application/Utils.h @@ -29,7 +29,7 @@ bool IsCommand(BString line); BString CommandName(BString line); BString CommandArgs(BString line); -BResources* ChatResources(); +BResources ChatResources(); const char* SettingsPath(); diff --git a/application/views/ReplicantMenuItem.cpp b/application/views/ReplicantMenuItem.cpp index 8097ec2..1966fc1 100644 --- a/application/views/ReplicantMenuItem.cpp +++ b/application/views/ReplicantMenuItem.cpp @@ -57,8 +57,8 @@ ReplicantMenuItem::IsCustom() const void ReplicantMenuItem::SetIcon() { - BResources* res = ChatResources(); - if (!res) + BResources res = ChatResources(); + if (res.InitCheck() != B_OK) return; int32 num = 0; @@ -84,8 +84,6 @@ ReplicantMenuItem::SetIcon() break; } - BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON); + BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON); SetBitmap(bitmap); - - delete res; } diff --git a/application/views/ReplicantStatusView.cpp b/application/views/ReplicantStatusView.cpp index c75c88f..35124ba 100644 --- a/application/views/ReplicantStatusView.cpp +++ b/application/views/ReplicantStatusView.cpp @@ -97,7 +97,6 @@ ReplicantStatusView::ReplicantStatusView(BMessage* archive) ReplicantStatusView::~ReplicantStatusView() { - delete fResources; delete fCayaMsg; delete fReplicantHandler; delete fReplicantMenu; @@ -300,7 +299,7 @@ ReplicantStatusView::_Init() BBitmap* ReplicantStatusView::_GetIcon(const uint32 id) { - BBitmap* icon = IconFromResources(fResources, id, B_MINI_ICON); + BBitmap* icon = IconFromResources(&fResources, id, B_MINI_ICON); return icon; } diff --git a/application/views/ReplicantStatusView.h b/application/views/ReplicantStatusView.h index 0eb2a12..2d2d9fe 100644 --- a/application/views/ReplicantStatusView.h +++ b/application/views/ReplicantStatusView.h @@ -63,7 +63,7 @@ private: BBitmap* fExitMenuIcon; BBitmap* fPreferencesIcon; - BResources* fResources; + BResources fResources; BPopUpMenu* fReplicantMenu; diff --git a/application/views/StatusMenuItem.cpp b/application/views/StatusMenuItem.cpp index 324512d..47859e5 100644 --- a/application/views/StatusMenuItem.cpp +++ b/application/views/StatusMenuItem.cpp @@ -54,8 +54,8 @@ StatusMenuItem::IsCustom() const void StatusMenuItem::SetIcon() { - BResources* res = ChatResources(); - if (!res) + BResources res = ChatResources(); + if (res.InitCheck() != B_OK) return; int32 num = 0; @@ -81,8 +81,6 @@ StatusMenuItem::SetIcon() break; } - BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON); + BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON); SetBitmap(bitmap); - - delete res; }